Skip to content
Myr

drafted.ts

This file

Path

packages/drafting/src/drafted.ts

116 lines · 3.2 KiB · TypeScript

Last changed by

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

History of this file

Take it

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

line 1why, one step back
1/** `DraftFailed` stays inside the run: it is no public refusal. */

Merge branch 'build/908-drafter-workers-ai'oscabrielbefore adoption004e40e

line 2why, one step back
2import { Brand } from "@repo/brand";

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 3–4why, one step back
3import { AtLeastOne } from "@repo/protocol/domain/common";
4import { AskId, LandedSha, ProjectName, RepoPath } from "@repo/protocol/ids";

Take one sentence where a draft's list is asked for, so kimi's drafts decodeoscabrielbefore adoptionecc2107

line 5why, one step back
5import { Schema, SchemaTransformation } from "effect";

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 6why, one step back
6

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

line 7why, one step back
7/** Bounded so no reply fills the Worker. */

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 8–9why, one step back
8const Text = Schema.NonEmptyString.check(Schema.isMaxLength(4000));
9

Merge branch 'build/908-drafter-workers-ai'oscabrielbefore adoption004e40e

lines 10–24why, one step back
10const TreePath = RepoPath.check(
11 Schema.makeFilter(12 (path: string) =>13 path14 .split("/")15 .every(16 (segment) => segment !== "" && segment !== "." && segment !== ".."17 )18 ? true19 : `${path} is not a path inside the tree`,20 { expected: "a relative path inside the tree" }21 )22);2324/**

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

lines 25–26why, one step back
25 * Anywhere in the tree but the config folder: the test is the model's own
26 * text, so a test path there would land model text as an ask file or policy.

Merge branch 'build/908-drafter-workers-ai'oscabrielbefore adoption004e40e

lines 27–37why, one step back
27 */
28const TestPath = TreePath.check(29 Schema.makeFilter(30 (path: string) =>31 path.startsWith(`${Brand.configDir}/`)32 ? `${path} is in ${Brand.configDir}/, which only code writes`33 : true,34 { expected: `a path outside ${Brand.configDir}/` }35 )36);37

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 38–43why, one step back
38export const DraftedAsk = Schema.Struct({
39 context: Schema.optionalKey(Schema.Array(Text)),40 current: Schema.optionalKey(Text),41 id: AskId,42 kind: Schema.Literal("fix"),43 outOfScope: Schema.optionalKey(Schema.Array(Text)),

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 44why, one step back
44 /** Shown to the maintainer as evidence; never landed. */

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 45why, one step back
45 rationale: Schema.String.check(Schema.isMaxLength(4000)),

Merge branch 'build/908-drafter-workers-ai'oscabrielbefore adoption004e40e

line 46why, one step back
46 territory: Schema.NonEmptyArray(TreePath),

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 47why, one step back
47 test: Schema.Struct({

Merge branch 'build/908-drafter-workers-ai'oscabrielbefore adoption004e40e

line 48why, one step back
48 path: TestPath,

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 49–54why, one step back
49 source: Schema.NonEmptyString.check(Schema.isMaxLength(100_000)),
50 }),51 want: Text,52});5354export type DraftedAsk = typeof DraftedAsk.Type;

Take one sentence where a draft's list is asked for, so kimi's drafts decodeoscabrielbefore adoptionecc2107

lines 55–56why, one step back
55
56/**

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

lines 57–58why, one step back
57 * A list, or one sentence alone, which decodes as a list of one: Workers AI
58 * does not hold a model to the JSON Schema it is asked for.

Take one sentence where a draft's list is asked for, so kimi's drafts decodeoscabrielbefore adoptionecc2107

lines 59–77why, one step back
59 */
60const Sentences = Schema.Union([61 Schema.Array(Text),62 Text.pipe(63 Schema.decodeTo(64 Schema.Array(Text),65 SchemaTransformation.transform({66 decode: (one: string): readonly string[] => [one],67 encode: (all) => all.join("\n"),68 })69 )70 ),71]);7273export const DraftedReply = Schema.Struct({74 ...DraftedAsk.fields,75 context: Schema.optionalKey(Sentences),76 outOfScope: Schema.optionalKey(Sentences),77});

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 78–116why, one step back
78
79export const ContextFile = Schema.Struct({80 content: Schema.String,81 path: RepoPath,82});8384export type ContextFile = typeof ContextFile.Type;8586export const DraftContext = Schema.Struct({87 at: LandedSha,88 files: Schema.Array(ContextFile),89 policy: Schema.String,90 project: ProjectName,91});9293export type DraftContext = typeof DraftContext.Type;9495export const DraftInput = Schema.Struct({96 attempt: AtLeastOne,97 context: DraftContext,98 feedback: Schema.optionalKey(Schema.String),99 note: Schema.optionalKey(Schema.String),100 territory: Schema.optionalKey(Schema.NonEmptyString),101 want: Schema.NonEmptyString,102});103104export type DraftInput = typeof DraftInput.Type;105106export class DraftFailed extends Schema.TaggedError<DraftFailed>()(107 "DraftFailed",108 {109 reason: Schema.Literals([110 "unparseable",111 "schema",112 "rate-limited",113 "model-error",114 ]),115 }116) {}