fwdloop 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
1
+ /**
2
+ * The one spec hash. sha256 over the four canonical parts, JSON-array framed so no part can
3
+ * bleed into the next. Never throws.
4
+ * @param {{proseText:string, declarationText:string, inputFactsText:string, readoutText:string, targetText:string}} p
5
+ * @returns {{ok:true, hash:string}|{ok:false, red:string}}
6
+ */
7
+ export function specHash({ proseText, declarationText, inputFactsText, readoutText, targetText, }: {
8
+ proseText: string;
9
+ declarationText: string;
10
+ inputFactsText: string;
11
+ readoutText: string;
12
+ targetText: string;
13
+ }): {
14
+ ok: true;
15
+ hash: string;
16
+ } | {
17
+ ok: false;
18
+ red: string;
19
+ };
20
+ /** Literal (never RegExp) key scrub; a secret under 8 chars is skipped so it can't blank ordinary text. */
21
+ export function scrub(text: any, secrets: any): any;
22
+ /** Count files directly inside `dir` that contain a secret literally. */
23
+ export function sweepForSecrets(dir: any, secrets: any): number;
24
+ /** Exact signed TTL with its unit, never rounded: 2h / 30m / 20s / 1500ms (the largest unit that divides it exactly). */
25
+ export function fmtTtl(ms: any): string;
26
+ /** Plain-text readout of what the human is about to sign. Pure. */
27
+ export function buildReadout({ declaration, arbiter, lines, name, modelId, costUsd, rounds, spendComplete }: {
28
+ declaration: any;
29
+ arbiter: any;
30
+ lines: any;
31
+ name: any;
32
+ modelId: any;
33
+ costUsd: any;
34
+ rounds: any;
35
+ spendComplete: any;
36
+ }): string;
37
+ /** Read the prose file. Refuses (a red, never a throw) on unreadable or blank. */
38
+ export function readProseFile(file: any): {
39
+ ok: boolean;
40
+ red: string;
41
+ text?: undefined;
42
+ } | {
43
+ ok: boolean;
44
+ text: string;
45
+ red?: undefined;
46
+ };
47
+ /**
48
+ * Draft into `dir`. $0 refusals (return {ok:false, wrote:false}, nothing on disk): bad key,
49
+ * unreadable/blank prose, prose that contains the key, missing inputs / bad signed text, dir
50
+ * already exists. After a paid round the dir is ALWAYS written — green (spec.hash present) or
51
+ * red (reds, no spec.hash). Spend is booked in `<dir>/spend.jsonl` with the runner's own
52
+ * writer (appendSpendRow); an unpriced round books null, never 0.
53
+ *
54
+ * Test seam: `provider`/`rates`/`modelId` are injected; without them a live provider is built.
55
+ */
56
+ export function draftToDir({ proseFile, dir, root, name, slot, model, budgetUsd, env, provider, rates, modelId, }: {
57
+ proseFile: any;
58
+ dir: any;
59
+ root: any;
60
+ name: any;
61
+ slot?: string | undefined;
62
+ model: any;
63
+ budgetUsd?: number | undefined;
64
+ env?: NodeJS.ProcessEnv | undefined;
65
+ provider: any;
66
+ rates: any;
67
+ modelId: any;
68
+ }): Promise<{
69
+ ok: boolean;
70
+ wrote: boolean;
71
+ reds: any;
72
+ costUsd: number;
73
+ } | {
74
+ ok: boolean;
75
+ wrote: boolean;
76
+ dir: any;
77
+ reds: any[];
78
+ costUsd: number | null;
79
+ spendComplete: boolean;
80
+ stop: string;
81
+ rounds: number;
82
+ calls: number;
83
+ leaks: number;
84
+ } | {
85
+ ok: boolean;
86
+ wrote: boolean;
87
+ reds: string[];
88
+ costUsd: number | null;
89
+ spendComplete: boolean;
90
+ leaks: number;
91
+ dir?: undefined;
92
+ hash?: undefined;
93
+ stop?: undefined;
94
+ rounds?: undefined;
95
+ calls?: undefined;
96
+ } | {
97
+ ok: boolean;
98
+ wrote: boolean;
99
+ dir: any;
100
+ hash: string | null;
101
+ reds: string[];
102
+ costUsd: number | null;
103
+ spendComplete: boolean;
104
+ stop: string | null;
105
+ rounds: number;
106
+ calls: number;
107
+ leaks: number;
108
+ }>;
109
+ /**
110
+ * The human step, $0. Every refusal returns reds and writes NO flow.
111
+ * `signedBy` must come from the human's own invocation (the CLI's --signed-by/username).
112
+ */
113
+ export function signDraft({ dir, approve, signedBy, signedAt, env, }: {
114
+ dir: any;
115
+ approve: any;
116
+ signedBy: any;
117
+ signedAt?: string | undefined;
118
+ env?: NodeJS.ProcessEnv | undefined;
119
+ }): {
120
+ ok: boolean;
121
+ reds: any[];
122
+ } | {
123
+ ok: boolean;
124
+ flowDir: string;
125
+ signature: import("./types.js").Signature;
126
+ };
127
+ export const DRAFT_BUDGET_USD: 0.1;
128
+ export const SPEC_HASH_FILE: "spec.hash";
129
+ /** Written when the end sweep finds a key in the draft dir; sign refuses a dir that has it. */
130
+ export const LEAK_MARKER_FILE: "scrub-leak.red";
131
+ export function SIGN_LINE(dir: any, hash: any): string;
132
+ export function costText(n: any, spendComplete?: boolean): string;
@@ -27,13 +27,19 @@ export function checkShapes(declaration: any): {
27
27
  * exception.
28
28
  *
29
29
  * @param {unknown} declaration
30
- * @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown }} [context]
30
+ * `wired` (optional Set of verbs): when given, a granted verb outside it is a red
31
+ * by name, even if the catalogue lists it. Omitted = no wired check (existing callers).
32
+ * `verbatimGoals` (optional boolean; M6a amendment 1): when true, a step naming a signed line must carry that line's
33
+ * text as its goal, exactly. Off by default so already-signed flows keep running; draft and sign turn it on.
34
+ * @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown, wired?: Set<string>, verbatimGoals?: boolean }} [context]
31
35
  * @returns {ValidateDeclarationResult}
32
36
  */
33
37
  export function validateDeclaration(declaration: unknown, context?: {
34
38
  arbiter?: unknown;
35
39
  lines?: unknown;
36
40
  catalogue?: unknown;
41
+ wired?: Set<string>;
42
+ verbatimGoals?: boolean;
37
43
  }): ValidateDeclarationResult;
38
44
  /** @typedef {import('./types.js').Arbiter} Arbiter */
39
45
  /** @typedef {import('./types.js').SignedLine} SignedLine */
package/types/docx.d.ts CHANGED
@@ -7,4 +7,12 @@ export function readDocxText(path: string): {
7
7
  ok: false;
8
8
  red: string;
9
9
  };
10
+ /** @param {string} path @returns {{ok:true,headings:string[]}|{ok:false,red:string}} */
11
+ export function readDocxHeadings(path: string): {
12
+ ok: true;
13
+ headings: string[];
14
+ } | {
15
+ ok: false;
16
+ red: string;
17
+ };
10
18
  export const DOCX_MAX_UNCOMPRESSED_BYTES: number;
@@ -0,0 +1,164 @@
1
+ /** The forced tool's parameter schema. `menu` = wiredMenu(). */
2
+ export function buildDeclarationSchema(menu: any): {
3
+ type: string;
4
+ properties: {
5
+ steps: {
6
+ type: string;
7
+ minItems: number;
8
+ items: {
9
+ type: string;
10
+ properties: {
11
+ primitives: {
12
+ type: string;
13
+ items: {
14
+ type: string;
15
+ enum: any;
16
+ };
17
+ description: string;
18
+ };
19
+ reads: {
20
+ type: string;
21
+ items: {
22
+ type: string;
23
+ };
24
+ description: string;
25
+ };
26
+ emits: {
27
+ type: string;
28
+ minLength: number;
29
+ description: string;
30
+ };
31
+ fromLine: {
32
+ type: string[];
33
+ description: string;
34
+ };
35
+ picks: {
36
+ type: string;
37
+ additionalProperties: {
38
+ type: string;
39
+ items: {
40
+ type: string;
41
+ };
42
+ };
43
+ description: string;
44
+ };
45
+ close: {
46
+ type: string;
47
+ properties: {
48
+ class: {
49
+ type: string;
50
+ enum: string[];
51
+ description: string;
52
+ };
53
+ shape: {
54
+ type: string;
55
+ properties: {};
56
+ additionalProperties: boolean;
57
+ description: string;
58
+ };
59
+ };
60
+ required: string[];
61
+ additionalProperties: boolean;
62
+ };
63
+ };
64
+ required: string[];
65
+ additionalProperties: boolean;
66
+ };
67
+ };
68
+ guardrailClasses: {
69
+ type: string;
70
+ additionalProperties: {
71
+ type: string;
72
+ enum: string[];
73
+ };
74
+ description: string;
75
+ };
76
+ unjudgeable: {
77
+ type: string;
78
+ additionalProperties: {
79
+ type: string;
80
+ };
81
+ description: string;
82
+ };
83
+ refused: {
84
+ type: string;
85
+ items: {
86
+ type: string;
87
+ properties: {
88
+ line: {
89
+ type: string;
90
+ };
91
+ reason: {
92
+ type: string;
93
+ minLength: number;
94
+ };
95
+ };
96
+ required: string[];
97
+ additionalProperties: boolean;
98
+ };
99
+ description: string;
100
+ };
101
+ };
102
+ required: string[];
103
+ additionalProperties: boolean;
104
+ };
105
+ export function buildSystemPrompt({ menu, lines, arbiter, factsInfo }: {
106
+ menu: any;
107
+ lines: any;
108
+ arbiter: any;
109
+ factsInfo: any;
110
+ }): string;
111
+ /**
112
+ * A step's goal = its signed line's text, exactly as parseSignedText's `lines` gives it: the words after
113
+ * "N. " (trailing comma kept; on an ask line the mark is stripped, leaving the question). Continuation
114
+ * lines do not exist in the grammar. A step naming no signed line gets a fixed placeholder, never model prose.
115
+ */
116
+ export function goalForLine(fromLine: any, lines: any): any;
117
+ /**
118
+ * Draft one declaration. `provider`/`rates`/`modelId` may be injected (tests,
119
+ * the batch); otherwise a live provider is built from `slot` (throws on a bad
120
+ * key — the batch preflights first). `budgetUsd` is this draft's hard cap.
121
+ * `makeProviderFn` is a test seam: the live-provider factory (default `makeProvider`).
122
+ *
123
+ * @returns {Promise<{ok:boolean, declaration:object|null, reds:string[], rounds:number, calls:number, spendComplete:boolean,
124
+ * costUsd:number|null, modelReturned:string|null, modelId?:string, tokens?:object|null, structureRetries:number, revisions:number, stop:string|null, log:object[]}>}
125
+ */
126
+ export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, budgetUsd, skills, makeProviderFn, }: {
127
+ proseText: any;
128
+ slot?: string | undefined;
129
+ model: any;
130
+ provider: any;
131
+ rates: any;
132
+ modelId: any;
133
+ budgetUsd?: number | undefined;
134
+ skills?: readonly string[] | undefined;
135
+ makeProviderFn?: typeof makeProvider | undefined;
136
+ }): Promise<{
137
+ ok: boolean;
138
+ declaration: object | null;
139
+ reds: string[];
140
+ rounds: number;
141
+ calls: number;
142
+ spendComplete: boolean;
143
+ costUsd: number | null;
144
+ modelReturned: string | null;
145
+ modelId?: string;
146
+ tokens?: object | null;
147
+ structureRetries: number;
148
+ revisions: number;
149
+ stop: string | null;
150
+ log: object[];
151
+ }>;
152
+ export const MAX_STRUCTURE_RETRIES: 2;
153
+ export const MAX_REVISIONS: 2;
154
+ export const DRAFT_MAX_TOKENS: 16000;
155
+ export const DRAFT_SKILLS: readonly string[];
156
+ export const CLASSES: readonly string[];
157
+ export const DRAFT_PROVIDER_OPTIONS: Readonly<{
158
+ thinking: Readonly<{
159
+ type: "disabled";
160
+ }>;
161
+ timeoutMs: 300000;
162
+ deadlineMs: 240000;
163
+ }>;
164
+ import { makeProvider } from './provider.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @param {Array<{kind?:string, role:string, path:string}>} sources arbiter.sources
3
+ * @returns {{ok:boolean, inputFacts:Record<string,string[]>, info:string[], reds:string[]}}
4
+ */
5
+ export function readInputFacts(sources: Array<{
6
+ kind?: string;
7
+ role: string;
8
+ path: string;
9
+ }>): {
10
+ ok: boolean;
11
+ inputFacts: Record<string, string[]>;
12
+ info: string[];
13
+ reds: string[];
14
+ };
@@ -3,6 +3,10 @@
3
3
  * `.csv` belongs to `addressCells`, anything else has no text primitive.
4
4
  * Pure and exported so tests can hit the four cases directly (F41 item 3). */
5
5
  export function rolePrimitiveFor(frozenPath: any): "read" | "readDocx" | "addressCells" | null;
6
+ /** The wired menu, one place: the catalogue entries whose verb is in
7
+ * WIRED_VERBS (and, when `skills` is given, in a signed skill). Absence,
8
+ * not refusal. Throws only if catalogue.json itself is unreadable. */
9
+ export function wiredMenu(skills: any): import("./types.js").CatalogueEntry[];
6
10
  /**
7
11
  * Resolve the granted tools for one step's model call. Never throws —
8
12
  * a verb absent from the catalogue, or present but unimplemented here, is
@@ -281,13 +281,15 @@ export function checkKeyPreflight(slotName: string, env?: Record<string, string
281
281
  * values this project uses.
282
282
  *
283
283
  * @param {string} slotName
284
- * @param {{ model?: string, timeoutMs?: number, deadlineMs?: number }} [options]
284
+ * @param {{ model?: string, timeoutMs?: number, deadlineMs?: number, thinking?: object|null }} [options]
285
+ * `thinking` (bare-agent >=0.49) is sent verbatim as body.thinking; unset/null leaves the body unchanged.
285
286
  * @returns {{ provider: any, rates: {in:number, out:number}, modelId: string, suffix: string, slot: string }}
286
287
  */
287
288
  export function makeProvider(slotName: string, options?: {
288
289
  model?: string;
289
290
  timeoutMs?: number;
290
291
  deadlineMs?: number;
292
+ thinking?: object | null;
291
293
  }): {
292
294
  provider: any;
293
295
  rates: {
@@ -0,0 +1,18 @@
1
+ /** stdin AND stdout must both be TTYs. */
2
+ export function isInteractive(stdin?: NodeJS.ReadStream & {
3
+ fd: 0;
4
+ }, stdout?: NodeJS.WriteStream & {
5
+ fd: 1;
6
+ }): boolean;
7
+ /** Show the flow name, read one line, compare exactly (trimmed). Empty answer / EOF / mismatch refuse by name. */
8
+ export function confirmTypedName({ name, input, output }: {
9
+ name: any;
10
+ input?: (NodeJS.ReadStream & {
11
+ fd: 0;
12
+ }) | undefined;
13
+ output?: (NodeJS.WriteStream & {
14
+ fd: 1;
15
+ }) | undefined;
16
+ }): Promise<any>;
17
+ export const NEEDS_TTY: "sign needs an interactive terminal \u2014 run it yourself";
18
+ export const NAME_MISMATCH: "typed name does not match";
@@ -1,3 +1,17 @@
1
+ /**
2
+ * M6a amendment 1: a NEW flow (draft, sign) may not carry an ask whose wait the human never typed. The
3
+ * parser still fills the legacy 30m default for `ask:` so flows signed before the amendment keep running;
4
+ * this names each ask that relies on it. Returns [] when every ask carries `ask <int><s|m|h>:`.
5
+ *
6
+ * @param {{ asks?: Array<{ line: number, ttlSigned?: boolean }> }} arbiter
7
+ * @returns {string[]}
8
+ */
9
+ export function unsignedAskTtls(arbiter: {
10
+ asks?: Array<{
11
+ line: number;
12
+ ttlSigned?: boolean;
13
+ }>;
14
+ }): string[];
1
15
  /**
2
16
  * Parse the human's signed text. Never throws — any input that isn't a
3
17
  * usable signed text comes back as `{ ok: false, reds }`, never an
package/types/types.d.ts CHANGED
@@ -23,6 +23,10 @@ export type AskSlot = {
23
23
  * - the ask's time-to-live in milliseconds.
24
24
  */
25
25
  ttlMs: number;
26
+ /**
27
+ * - true when the human typed the wait (`ask <int><s|m|h>:`); false on the legacy `ask:` 30m default, which draft and sign refuse (M6a amendment 1).
28
+ */
29
+ ttlSigned?: boolean | undefined;
26
30
  /**
27
31
  * - the words after the mark, trimmed — the
28
32
  * human's own question. Nothing reads this yet outside signed-text.js.
@@ -318,8 +322,8 @@ export type AuditRow = {
318
322
  ungranted?: string[] | undefined;
319
323
  /**
320
324
  * - bareguard
321
- * fs-gate refusals during this attempt; `[]` (never omitted) on every row
322
- * written by a model attempt, absent on rows with no model call.
325
+ * fs-gate refusals during this attempt; `[]` (never omitted) on every row,
326
+ * including rows with no model call (paused, cap-halt, ask, send).
323
327
  */
324
328
  refused?: {
325
329
  verb: string;