toolroll 0.9.97 → 0.9.98

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/approval-authority.d.ts +10 -1
  3. package/dist/approval-authority.js +18 -2
  4. package/dist/browser/workspace.js +1 -1
  5. package/dist/browser-workspace.d.ts +4 -3
  6. package/dist/chat-actions.d.ts +40 -5
  7. package/dist/chat-actions.js +124 -13
  8. package/dist/chat-card.js +4 -1
  9. package/dist/chat-channel.d.ts +3 -0
  10. package/dist/chat-channel.js +24 -7
  11. package/dist/chat-decide.js +4 -2
  12. package/dist/chat-task-actions.js +1 -1
  13. package/dist/chat-terms.d.ts +8 -0
  14. package/dist/chat-terms.js +14 -0
  15. package/dist/chat-voice.js +1 -1
  16. package/dist/contracts/chat-actions.d.ts +6 -0
  17. package/dist/contracts/chat-actions.js +2 -0
  18. package/dist/contracts/cli.d.ts +6 -0
  19. package/dist/contracts/cli.js +3 -0
  20. package/dist/contracts/lead-tools.d.ts +17 -0
  21. package/dist/contracts/lead-tools.js +4 -1
  22. package/dist/contracts/store-json.d.ts +1 -0
  23. package/dist/desktop-update.d.ts +1 -1
  24. package/dist/fast-start.d.ts +83 -6
  25. package/dist/fast-start.js +112 -15
  26. package/dist/home-groups.d.ts +39 -0
  27. package/dist/home-groups.js +33 -0
  28. package/dist/lead-answer-eval.d.ts +7 -0
  29. package/dist/lead-answer-eval.js +6 -2
  30. package/dist/lead-capabilities.js +1 -1
  31. package/dist/lead-context.js +2 -2
  32. package/dist/lead-contract.d.ts +1 -1
  33. package/dist/lead-contract.js +10 -7
  34. package/dist/lead-doors.d.ts +32 -0
  35. package/dist/lead-doors.js +80 -14
  36. package/dist/lead-status.d.ts +3 -0
  37. package/dist/lead-status.js +8 -3
  38. package/dist/lead-tools.d.ts +20 -0
  39. package/dist/lead-tools.js +66 -3
  40. package/dist/lead-voice.js +1 -1
  41. package/dist/lead.js +18 -2
  42. package/dist/local-owner.js +2 -0
  43. package/dist/one-step-chat-schema.d.ts +22 -0
  44. package/dist/one-step-chat-schema.js +37 -0
  45. package/dist/operate.d.ts +27 -1
  46. package/dist/operate.js +206 -32
  47. package/dist/project-delete.js +9 -0
  48. package/dist/project-knowledge.d.ts +7 -7
  49. package/dist/publish.d.ts +2 -0
  50. package/dist/publish.js +1 -1
  51. package/dist/pull-request-flow.d.ts +4 -0
  52. package/dist/pull-request-flow.js +16 -1
  53. package/dist/reply-voice.d.ts +23 -0
  54. package/dist/reply-voice.js +37 -0
  55. package/dist/scope.d.ts +6 -1
  56. package/dist/scope.js +3 -2
  57. package/dist/server/chat.js +4 -4
  58. package/dist/server/chrome.js +2 -2
  59. package/dist/server/home.d.ts +4 -3
  60. package/dist/server/home.js +33 -28
  61. package/dist/server/render-chat.js +11 -6
  62. package/dist/server/render-pages.js +2 -2
  63. package/dist/setup-guide.d.ts +2 -2
  64. package/dist/store.d.ts +4 -2
  65. package/dist/store.js +35 -12
  66. package/dist/telegram-lead.js +69 -5
  67. package/dist/telegram-status.js +9 -4
  68. package/dist/telegram.d.ts +10 -0
  69. package/dist/telegram.js +92 -8
  70. package/dist/toolroll-update.js +3 -1
  71. package/dist/tui-contract.d.ts +2 -0
  72. package/dist/tui-source.js +3 -0
  73. package/dist/tui.js +41 -41
  74. package/dist/typed-start.d.ts +51 -0
  75. package/dist/typed-start.js +98 -0
  76. package/dist/wake-hub.d.ts +72 -0
  77. package/dist/wake-hub.js +151 -0
  78. package/package.json +1 -1
@@ -756,6 +756,10 @@ export declare const LEAD_TOOL_INPUTS: {
756
756
  report: z.ZodOptional<z.ZodBoolean>;
757
757
  checks: z.ZodOptional<z.ZodString>;
758
758
  }, z.core.$strict>;
759
+ readonly propose_start: z.ZodObject<{
760
+ repo: z.ZodString;
761
+ title: z.ZodString;
762
+ }, z.core.$strict>;
759
763
  readonly propose_sweep: z.ZodObject<{
760
764
  repo: z.ZodString;
761
765
  title: z.ZodString;
@@ -1567,6 +1571,10 @@ export declare const LEAD_TOOL_READ_INPUTS: {
1567
1571
  report: z.ZodOptional<z.ZodBoolean>;
1568
1572
  checks: z.ZodOptional<z.ZodString>;
1569
1573
  }, z.core.$strict>;
1574
+ readonly propose_start: z.ZodObject<{
1575
+ repo: z.ZodString;
1576
+ title: z.ZodString;
1577
+ }, z.core.$strict>;
1570
1578
  readonly propose_sweep: z.ZodObject<{
1571
1579
  repo: z.ZodString;
1572
1580
  title: z.ZodString;
@@ -2212,6 +2220,15 @@ export declare const LEAD_TOOL_OUTPUTS: {
2212
2220
  kind: z.ZodLiteral<"task">;
2213
2221
  awaiting: z.ZodString;
2214
2222
  }, z.core.$loose>;
2223
+ readonly propose_start: z.ZodObject<{
2224
+ proposal: z.ZodNumber;
2225
+ kind: z.ZodEnum<{
2226
+ action: "action";
2227
+ task: "task";
2228
+ }>;
2229
+ startsNow: z.ZodBoolean;
2230
+ awaiting: z.ZodString;
2231
+ }, z.core.$loose>;
2215
2232
  readonly propose_sweep: z.ZodObject<{
2216
2233
  proposal: z.ZodNumber;
2217
2234
  label: z.ZodString;
@@ -52,7 +52,7 @@ export const CODE_MAP_VIEWS = ["overview", "area", "file", "search"];
52
52
  /** Task states a list filters by. */
53
53
  export const LISTED_TASK_STATES = ["queued", "running", "done", "failed", "cancelled"];
54
54
  /** The shared actions the lead proposes with propose_action; flows and subagents have their own tools. */
55
- const ACTION_OPERATIONS = Object.keys(CHAT_ACTIONS).filter(one => !one.startsWith("flow_") && !one.startsWith("subagent_"));
55
+ const ACTION_OPERATIONS = Object.keys(CHAT_ACTIONS).filter(one => !one.startsWith("flow_") && !one.startsWith("subagent_") && one !== "task_start");
56
56
  /** A card's spec as the lead sees it: one flat props object. Each element's own props are read strictly by card-catalog.ts. */
57
57
  const cardProps = z.strictObject({
58
58
  source: z.enum(CARD_SOURCES).optional(), chart: z.enum(CARD_CHART_TYPES).optional(), columns: z.array(z.string().max(40)).max(CARD_LIMITS.columns).optional(), facts: z.array(z.string().max(40)).max(CARD_LIMITS.facts).optional(),
@@ -147,6 +147,8 @@ export const LEAD_TOOL_INPUTS = {
147
147
  not: scopeText.nullable().optional(), touches: touches.optional(), acceptance,
148
148
  planning: z.enum(["auto", "required", "skip"]).optional(), report: z.boolean().optional(), checks: text("checksWords").optional(),
149
149
  }),
150
+ // One-step start from chat (docs/plans/one-step-chat.md C3): one small change the person asked to be done now.
151
+ propose_start: z.strictObject({ repo: repoId, title: text("taskTitle") }),
150
152
  // Lead fan-out (docs/plans/lead-fan-out.md): 2 to 20 independent items under one shared brief and one success test.
151
153
  propose_sweep: z.strictObject({
152
154
  repo: repoId, title: text("taskTitle"), brief: scopeText,
@@ -286,6 +288,7 @@ export const LEAD_TOOL_OUTPUTS = {
286
288
  get_decision: decisionOutput,
287
289
  queue: z.looseObject({ repo: str, queueRevision: int, ...queueColumnsOutput }),
288
290
  propose_task: proposed("task", { repo: str, deliverable: z.enum(["branch", "report"]), planning: str }),
291
+ propose_start: z.looseObject({ proposal: int, kind: z.enum(["action", "task"]), startsNow: z.boolean(), awaiting: str }),
289
292
  propose_sweep: cardDrafted,
290
293
  get_sweep: z.looseObject({ sweep: int, title: str, line: str, table: str, maxParallel: int, items: z.array(z.looseObject({ item: int, label: str, task: str, state: str })) }),
291
294
  propose_sweep_cancel: cardDrafted,
@@ -232,6 +232,7 @@ declare const STORE_COLUMN_VALUES: {
232
232
  task_reopen: "task_reopen";
233
233
  task_restore: "task_restore";
234
234
  task_resume: "task_resume";
235
+ task_start: "task_start";
235
236
  tool_add: "tool_add";
236
237
  tool_remove: "tool_remove";
237
238
  trial_stop: "trial_stop";
@@ -97,7 +97,6 @@ export declare function sqliteLock(file: string, busyTimeoutMs?: number): Databa
97
97
  export declare function lockHeld(file: string): boolean;
98
98
  export declare const installationLock: (j: UpdateJournal) => DatabaseSync | null;
99
99
  export declare function desktopUpdateStatus(stateDir: string): {
100
- version?: never;
101
100
  active: boolean;
102
101
  phase: string;
103
102
  detail: string;
@@ -111,6 +110,7 @@ export declare function desktopUpdateStatus(stateDir: string): {
111
110
  wasRunning?: never;
112
111
  backupPath?: never;
113
112
  updateId?: never;
113
+ version?: never;
114
114
  buildId?: never;
115
115
  workDir?: never;
116
116
  } | {
@@ -1,4 +1,5 @@
1
1
  import { type ApprovalPasswordFacts } from "./approval-password.js";
2
+ import type { ChatApprovalLimits } from "./chat-approval.js";
2
3
  import { type TaskSizing } from "./phase-routing.js";
3
4
  import { type ApproveResult, type Scope } from "./scope.js";
4
5
  import { type Store } from "./store.js";
@@ -9,9 +10,10 @@ export declare const FAST_MAX_FILES = 3;
9
10
  export declare const FAST_MAX_LINES = 150;
10
11
  /** How long a rendered form may still be pressed. */
11
12
  export declare const FAST_PREVIEW_MS: number;
12
- /** Which person surface is filing. A chat, a flow, a token or an agent has no entry here. */
13
- export type FastVia = "console" | "terminal-ui" | "cli";
14
- export type FastRefusal = "setting" | "size" | "classifier" | "plan" | "quality" | "rules" | "protected" | "password" | "release" | "trial" | "chain" | "monthly" | "policy" | "agents" | "machine" | "mode";
13
+ /** Which person surface is filing. `chat` is a Start card a person taps or answers yes to (one-step-chat.md); a flow, a
14
+ * token or an agent has no entry here. */
15
+ export type FastVia = "console" | "terminal-ui" | "cli" | "chat";
16
+ export type FastRefusal = "setting" | "size" | "classifier" | "plan" | "quality" | "rules" | "protected" | "password" | "release" | "trial" | "chain" | "monthly" | "policy" | "agents" | "machine" | "mode" | "limit";
15
17
  export declare const fastRefusalWords: (reason: FastRefusal) => string;
16
18
  /** Small tasks start right away: a project's own choice, else on for single-approver installs and off once there's more
17
19
  * than one approver. */
@@ -32,10 +34,34 @@ export type FastInput = {
32
34
  permissionMode?: "auto" | "bypassPermissions" | undefined;
33
35
  };
34
36
  export type PasswordFacts = Pick<ApprovalPasswordFacts, "passwordless" | "localOwner" | "freshAt" | "returnTo">;
37
+ /** How the person is proved at the one step that differs by surface: the password rule the form reads, or (a chat
38
+ * start) the person's own chat approval limits. */
39
+ export type FastProof = {
40
+ password: PasswordFacts;
41
+ } | {
42
+ chat: ChatApprovalLimits;
43
+ };
44
+ /** Every person surface's eligibility: the rules, then a machine is refused. */
35
45
  export declare function fastStartEligible(store: Store, input: FastInput & {
36
46
  taskId: string;
37
47
  sizing: TaskSizing;
48
+ } & ({
38
49
  password: PasswordFacts;
50
+ } | {
51
+ proof: FastProof;
52
+ }), now: Date): {
53
+ ok: true;
54
+ scope: Scope;
55
+ } | {
56
+ ok: false;
57
+ reason: FastRefusal;
58
+ };
59
+ /** The rules alone, the same for every surface: only the person-proof step has two forms (FastProof). A preview reads
60
+ * these as any caller; Build reads them again behind the machine check (fastStartEligible). */
61
+ export declare function fastStartRules(store: Store, input: FastInput & {
62
+ taskId: string;
63
+ sizing: TaskSizing;
64
+ proof: FastProof;
39
65
  }, now: Date): {
40
66
  ok: true;
41
67
  scope: Scope;
@@ -59,7 +85,7 @@ export type FastPreview = {
59
85
  * files exactly this, whatever is posted.
60
86
  */
61
87
  export declare function prepareFastStart(store: Store, input: FastInput & {
62
- via: FastVia;
88
+ via: Exclude<FastVia, "chat">;
63
89
  password: PasswordFacts;
64
90
  }, now: Date): Promise<FastPreview>;
65
91
  export type FastBuild = {
@@ -84,9 +110,14 @@ export declare function fastStartBuild(store: Store, input: {
84
110
  digest: string;
85
111
  actor: string;
86
112
  via: FastVia;
87
- password: PasswordFacts;
88
113
  approveNow: FastApprove;
89
- }, now: Date): FastBuild;
114
+ /** A chat start: the lead turn its card was drafted in. Its preview must have been prepared in that same turn. */
115
+ turn?: number;
116
+ } & ({
117
+ password: PasswordFacts;
118
+ } | {
119
+ proof: FastProof;
120
+ }), now: Date): FastBuild;
90
121
  /**
91
122
  * A fast start that didn't start in time: its seal is cleared, in a logged transaction, and the task shows the ordinary
92
123
  * Approve plan. A task with a build running or a result to read is left to that.
@@ -134,3 +165,49 @@ export declare function keepGrownChange(store: Store, taskId: string, now: Date)
134
165
  ok: false;
135
166
  message: string;
136
167
  };
168
+ /** What a chat start's preview is for: who asked, where, the lead's one-line title, and the lead turn it is prepared in. */
169
+ export type ChatStartInput = {
170
+ actor: string;
171
+ repo: string;
172
+ title: string;
173
+ turn: number;
174
+ };
175
+ /**
176
+ * A chat start's preview, prepared by the lead's turn loop before the Start card is drafted: the classifier asked (at
177
+ * most its budget), the filing dry-run, and the rules read. It refuses no machine caller, because a preview grants
178
+ * nothing (the lead's turn runs as the lead): Build refuses a machine (fastStartBuild), and only a person's own tap or
179
+ * typed yes reaches Build. The row is bound to the person, `via = 'chat'` and the turn; a preview without a turn is
180
+ * unusable. The person's own chat limits are read again at the tap, for the chat it comes from; here only the loosest
181
+ * limit that still means something applies (no full access, no cap), so a card is never drafted for terms no chat
182
+ * approval could allow.
183
+ */
184
+ export declare function prepareChatStart(store: Store, input: ChatStartInput, now: Date): Promise<FastPreview>;
185
+ /** A chat start's preview, as the Start card reads it again: this person's, `via = 'chat'`, prepared in this turn,
186
+ * unexpired and unused. Null otherwise. */
187
+ export declare function chatStartPreview(store: Store, preview: string, actor: string, turn: number, now: Date): {
188
+ taskId: string;
189
+ repo: string;
190
+ title: string;
191
+ sizing: TaskSizing;
192
+ digest: string;
193
+ } | null;
194
+ /** A dismissed Start card's preview can't be used: consumed, in the dismissal's transaction. */
195
+ export declare function consumeChatStartPreview(store: Store, preview: string, now: Date): void;
196
+ /**
197
+ * A chat start's filing dry-run, for its card: the scope filing would make, read in a savepoint that is always rolled
198
+ * back, with the rules read on it (any proof form; the card shows the terms, the tap proves the person). The card is made
199
+ * from these words; the tap files again and compares.
200
+ */
201
+ export declare function chatStartDryRun(store: Store, input: {
202
+ actor: string;
203
+ repo: string;
204
+ title: string;
205
+ taskId: string;
206
+ sizing: TaskSizing;
207
+ }, now: Date): {
208
+ ok: true;
209
+ scope: Scope;
210
+ } | {
211
+ ok: false;
212
+ reason: FastRefusal;
213
+ };
@@ -11,11 +11,18 @@
11
11
  * - **the Accept backstop**: a machine can't complete it, the project's grant doesn't push it until a person accepted it,
12
12
  * and completion, publication and merge all read one verified measure of the whole change (verifiedChange).
13
13
  *
14
- * Only a person's own surfaces reach here (the browser, the terminal UI as the local owner, interactive `task new`).
15
- * Every machine is refused in the writer from trusted context. `task add` never comes this way.
14
+ * Only a person's own surfaces reach here (the browser, the terminal UI as the local owner, interactive `task new`, and
15
+ * a person's own tap or typed yes on a chat's Start card: docs/plans/one-step-chat.md). Every machine is refused in the
16
+ * writer from trusted context. `task add` never comes this way.
17
+ *
18
+ * A chat start (`via: "chat"`) runs the same rules (fastStartRules). Its words are the lead's, so it is filed as the
19
+ * lead's text (`proposedVia: "mate"`, quarantined), and only its person-proof step differs: chat has no password, so
20
+ * instead of the password field it passes only within the person's own chat approval limits (chatLimitProblem), and
21
+ * quarantined text is approvable in chat only on a card that showed every term whole (store.ts sealScopeApproval).
16
22
  */
17
23
  import { randomBytes } from "node:crypto";
18
24
  import { approvalPasswordField } from "./approval-password.js";
25
+ import { chatLimitProblem } from "./chat-terms.js";
19
26
  import { isProtectedWork, protectedChanges } from "./approval-policy.js";
20
27
  import { originalTaskBase } from "./observations.js";
21
28
  import { legOf, makesNoPlan, routeFromJson } from "./phase-routing.js";
@@ -53,6 +60,7 @@ const FAST_WORDS = {
53
60
  agents: "Choose an agent first.",
54
61
  machine: "Only a person starts work this way.",
55
62
  mode: "This project's mode approves it.",
63
+ limit: "This is more than your chat approval setting allows.",
56
64
  };
57
65
  export const fastRefusalWords = (reason) => FAST_WORDS[reason];
58
66
  // ---- the project setting ---------------------------------------------------------------------------------------------
@@ -78,10 +86,16 @@ export function setFastStart(store, repo, on, by, now) {
78
86
  // ---- eligibility: one function, read by the form and again inside the transaction ------------------------------------
79
87
  /** Filed this way, the plan's words are the person's words, and they inspect the result. */
80
88
  export const fastAcceptance = (title) => [{ id: "c1", statement: title, how: null, evidence: ["manual-review"] }];
89
+ /** Every person surface's eligibility: the rules, then a machine is refused. */
81
90
  export function fastStartEligible(store, input, now) {
82
- const no = (reason) => ({ ok: false, reason });
83
91
  if (machineActing())
84
- return no("machine");
92
+ return { ok: false, reason: "machine" };
93
+ return fastStartRules(store, { ...input, proof: "proof" in input ? input.proof : { password: input.password } }, now);
94
+ }
95
+ /** The rules alone, the same for every surface: only the person-proof step has two forms (FastProof). A preview reads
96
+ * these as any caller; Build reads them again behind the machine check (fastStartEligible). */
97
+ export function fastStartRules(store, input, now) {
98
+ const no = (reason) => ({ ok: false, reason });
85
99
  if (!fastStartOn(store, input.repo))
86
100
  return no("setting");
87
101
  const account = store.accountOf(input.actor);
@@ -126,9 +140,13 @@ export function fastStartEligible(store, input, now) {
126
140
  const profile = scope.profile;
127
141
  if (levelOfProfile(scope.profile) === "escalated" || profile["checkAccess"] !== undefined || profile["machLookup"] !== undefined)
128
142
  return no("password");
129
- const field = approvalPasswordField(store, { name: input.actor, taskId: input.taskId, scope, ...input.password });
130
- if (field.field === "required" || field.field === "local-refused")
131
- return no("password");
143
+ if ("password" in input.proof) {
144
+ const field = approvalPasswordField(store, { name: input.actor, taskId: input.taskId, scope, ...input.proof.password });
145
+ if (field.field === "required" || field.field === "local-refused")
146
+ return no("password");
147
+ }
148
+ else if (chatLimitProblem(scope, input.proof.chat, "your chat approval setting") !== null)
149
+ return no("limit");
132
150
  const ref = store.lookupRef(input.taskId);
133
151
  if (ref === null || store.budgetGate(now)({ ...store.budgetSubject(ref.id), agents: store.agentsFor([scope.profile.provider]) }).over !== null)
134
152
  return no("monthly");
@@ -136,12 +154,14 @@ export function fastStartEligible(store, input, now) {
136
154
  return no("policy");
137
155
  return { ok: true, scope };
138
156
  }
139
- /** File the task, inside the caller's transaction, exactly as Build will. */
157
+ /** File the task, inside the caller's transaction, exactly as Build will. A chat start's words are the lead's: its text
158
+ * stays quarantined (`proposedVia: "mate"`), as every lead-written scope is. */
140
159
  function fileIt(store, id, input, now) {
141
160
  const filed = fileTaskProposal(store, {
142
161
  id, title: titleWithin(input.title), repo: input.repo, goal: input.title, acceptance: fastAcceptance(input.title), planning: "skip", sizing: input.sizing,
143
162
  ...(input.permissionMode === undefined ? {} : { permissionMode: input.permissionMode }),
144
- filedVia: input.via === "console" ? "console" : input.via === "terminal-ui" ? "tui" : "cli", filedBy: { name: input.actor, kind: "person" },
163
+ filedVia: input.via === "console" ? "console" : input.via === "terminal-ui" ? "tui" : input.via === "chat" ? "chat" : "cli", filedBy: { name: input.actor, kind: "person" },
164
+ ...(input.via === "chat" ? { proposedVia: "mate" } : {}),
145
165
  }, now);
146
166
  return filed.ok ? { ok: true } : { ok: false, message: filed.message };
147
167
  }
@@ -152,10 +172,11 @@ class RolledBack extends Error {
152
172
  this.answer = answer;
153
173
  }
154
174
  }
155
- /** Run `body` in a transaction that never commits: a preview writes nothing. */
175
+ /** Run `body` in a savepoint that never commits: a preview writes nothing, at any nesting depth (a nested transact runs
176
+ * in place, so only the savepoint undoes the writes when a caller already holds a transaction). */
156
177
  function dryRun(store, body) {
157
178
  try {
158
- store.transact(() => { throw new RolledBack(body()); });
179
+ store.transact(() => store.savepoint(() => { throw new RolledBack(body()); }));
159
180
  }
160
181
  catch (error) {
161
182
  if (error instanceof RolledBack)
@@ -172,6 +193,9 @@ function dryRun(store, body) {
172
193
  export async function prepareFastStart(store, input, now) {
173
194
  if (machineActing())
174
195
  return { eligible: false, reason: "machine" };
196
+ // A chat start is prepared in the lead's turn (prepareChatStart), bound to it.
197
+ if (input.via === "chat")
198
+ return { eligible: false, reason: "rules" };
175
199
  if (!fastStartOn(store, input.repo))
176
200
  return { eligible: false, reason: "setting" };
177
201
  if (heuristicSizing({ title: input.title, goal: input.title }).size !== "small")
@@ -203,6 +227,10 @@ export async function prepareFastStart(store, input, now) {
203
227
  export function fastStartBuild(store, input, now) {
204
228
  if (machineActing())
205
229
  return { ok: false, reason: "machine", message: FAST_WORDS.machine };
230
+ const proof = "proof" in input ? input.proof : { password: input.password };
231
+ // The chat form of the proof is a chat start's alone; the form's surfaces keep the password rule.
232
+ if ("chat" in proof && input.via !== "chat")
233
+ return { ok: false, reason: "rules", message: FAST_WORDS.rules };
206
234
  class Refused extends Error {
207
235
  answer;
208
236
  constructor(answer) {
@@ -212,29 +240,37 @@ export function fastStartBuild(store, input, now) {
212
240
  }
213
241
  const refuse = (answer) => { throw new Refused(answer); };
214
242
  try {
215
- return store.transact(() => {
243
+ // A savepoint inside the transaction: a refusal undoes the filing even when the caller already holds a transaction
244
+ // (a nested transact runs in place, and this function catches its own refusal).
245
+ return store.transact(() => store.savepoint(() => {
216
246
  const row = store.handle.prepare("SELECT * FROM fast_preview WHERE id = ? AND consumed_at IS NULL AND expires_at > ?").get(input.preview, now.toISOString());
217
247
  if (row === undefined || row["actor"] !== input.actor || row["via"] !== input.via)
218
248
  return refuse({ ok: false, reason: "gone", message: "This form has expired. Start again." });
249
+ // A chat preview without a turn, or from another turn than its card's, is nobody's card.
250
+ if (input.via === "chat" && (row["turn"] === null || row["turn"] === undefined || input.turn === undefined || Number(row["turn"]) !== input.turn))
251
+ return refuse({ ok: false, reason: "gone", message: "This card has expired. Ask again." });
219
252
  const sizing = JSON.parse(String(row["sizing_json"]));
220
253
  const taskId = String(row["task_id"]);
221
254
  const filing = { actor: input.actor, repo: String(row["repo"]), title: String(row["title"]), ...(row["permission"] === null ? {} : { permissionMode: row["permission"] }) };
222
255
  const filed = fileIt(store, taskId, { ...filing, via: input.via, sizing }, now);
223
256
  if (!filed.ok)
224
257
  return refuse({ ok: false, reason: "changed", message: filed.message });
225
- const eligible = fastStartEligible(store, { ...filing, taskId, sizing, password: input.password }, now);
258
+ const eligible = fastStartEligible(store, { ...filing, taskId, sizing, proof }, now);
226
259
  if (!eligible.ok)
227
260
  return refuse({ ok: false, reason: eligible.reason, message: FAST_WORDS[eligible.reason] });
228
261
  const at = now.toISOString();
229
262
  // approve() compares the digest the person saw with the plan just filed: changed terms refuse "changed".
230
263
  const approved = input.approveNow(taskId, input.digest, { rule: FAST_START_RULE, at });
264
+ if (!approved.ok && approved.reason === "changed")
265
+ return refuse({ ok: false, reason: "changed", message: "This changed since you read it. Read it again." });
266
+ // Chat has no password: a refusal there says the rule, not "takes your password".
231
267
  if (!approved.ok)
232
- return refuse({ ok: false, reason: approved.reason === "changed" ? "changed" : "password", message: approved.reason === "changed" ? "This changed since you read it. Read it again." : FAST_WORDS.password });
268
+ return refuse(input.via === "chat" ? { ok: false, reason: "rules", message: approved.reason === "policy" ? approved.message : FAST_WORDS.rules } : { ok: false, reason: "password", message: FAST_WORDS.password });
233
269
  store.handle.prepare("UPDATE fast_preview SET consumed_at = ? WHERE id = ?").run(at, input.preview);
234
270
  store.handle.prepare("UPDATE task_ref SET fast_start_at = ?, fast_start_until = ? WHERE backend = ? AND external_id = ?").run(at, new Date(now.getTime() + FAST_WINDOW_MS).toISOString(), BUILT_IN, taskId);
235
271
  store.bumpWake();
236
272
  return { ok: true, taskId };
237
- });
273
+ }));
238
274
  }
239
275
  catch (error) {
240
276
  if (error instanceof Refused)
@@ -429,3 +465,64 @@ export function keepGrownChange(store, taskId, now) {
429
465
  return { ok: true, digest: proposed.digest };
430
466
  });
431
467
  }
468
+ /**
469
+ * A chat start's preview, prepared by the lead's turn loop before the Start card is drafted: the classifier asked (at
470
+ * most its budget), the filing dry-run, and the rules read. It refuses no machine caller, because a preview grants
471
+ * nothing (the lead's turn runs as the lead): Build refuses a machine (fastStartBuild), and only a person's own tap or
472
+ * typed yes reaches Build. The row is bound to the person, `via = 'chat'` and the turn; a preview without a turn is
473
+ * unusable. The person's own chat limits are read again at the tap, for the chat it comes from; here only the loosest
474
+ * limit that still means something applies (no full access, no cap), so a card is never drafted for terms no chat
475
+ * approval could allow.
476
+ */
477
+ export async function prepareChatStart(store, input, now) {
478
+ if (!Number.isSafeInteger(input.turn) || input.turn < 1)
479
+ return { eligible: false, reason: "rules" };
480
+ if (!fastStartOn(store, input.repo))
481
+ return { eligible: false, reason: "setting" };
482
+ if (heuristicSizing({ title: input.title, goal: input.title }).size !== "small")
483
+ return { eligible: false, reason: "size" };
484
+ const mode = store.activeMode(input.repo, now);
485
+ if (mode !== null && /"autoApproveFiling":true/.test(mode.termsJson))
486
+ return { eligible: false, reason: "mode" };
487
+ const sizer = filingSizer();
488
+ const sizing = await classifyTask({ title: input.title, goal: input.title }, sizer.sizer, sizer.budget);
489
+ const taskId = `task-${randomBytes(8).toString("hex")}`;
490
+ const filing = { actor: input.actor, repo: input.repo, title: input.title };
491
+ const read = dryRun(store, () => {
492
+ const filed = fileIt(store, taskId, { ...filing, via: "chat", sizing }, now);
493
+ if (!filed.ok)
494
+ return { ok: false, reason: "plan" };
495
+ return fastStartRules(store, { ...filing, taskId, sizing, proof: { chat: { fullAccess: false, capMicrousd: null } } }, now);
496
+ });
497
+ if (!read.ok)
498
+ return { eligible: false, reason: read.reason };
499
+ const preview = randomBytes(16).toString("hex");
500
+ store.handle.prepare(`INSERT INTO fast_preview (id, actor, via, task_id, repo, title, permission, sizing_json, digest, created_at, expires_at, turn) VALUES (?, ?, 'chat', ?, ?, ?, NULL, ?, ?, ?, ?, ?)`)
501
+ .run(preview, input.actor, taskId, input.repo, input.title, JSON.stringify(sizing), read.scope.digest, now.toISOString(), new Date(now.getTime() + FAST_PREVIEW_MS).toISOString(), input.turn);
502
+ return { eligible: true, preview, digest: read.scope.digest, scope: read.scope, taskId };
503
+ }
504
+ /** A chat start's preview, as the Start card reads it again: this person's, `via = 'chat'`, prepared in this turn,
505
+ * unexpired and unused. Null otherwise. */
506
+ export function chatStartPreview(store, preview, actor, turn, now) {
507
+ const row = store.handle.prepare("SELECT * FROM fast_preview WHERE id = ? AND consumed_at IS NULL AND expires_at > ?").get(preview, now.toISOString());
508
+ if (row === undefined || row["actor"] !== actor || row["via"] !== "chat" || row["turn"] === null || Number(row["turn"]) !== turn)
509
+ return null;
510
+ return { taskId: String(row["task_id"]), repo: String(row["repo"]), title: String(row["title"]), sizing: JSON.parse(String(row["sizing_json"])), digest: String(row["digest"]) };
511
+ }
512
+ /** A dismissed Start card's preview can't be used: consumed, in the dismissal's transaction. */
513
+ export function consumeChatStartPreview(store, preview, now) {
514
+ store.handle.prepare("UPDATE fast_preview SET consumed_at = ? WHERE id = ? AND via = 'chat' AND consumed_at IS NULL").run(now.toISOString(), preview);
515
+ }
516
+ /**
517
+ * A chat start's filing dry-run, for its card: the scope filing would make, read in a savepoint that is always rolled
518
+ * back, with the rules read on it (any proof form; the card shows the terms, the tap proves the person). The card is made
519
+ * from these words; the tap files again and compares.
520
+ */
521
+ export function chatStartDryRun(store, input, now) {
522
+ return dryRun(store, () => {
523
+ const filed = fileIt(store, input.taskId, { actor: input.actor, repo: input.repo, title: input.title, via: "chat", sizing: input.sizing }, now);
524
+ if (!filed.ok)
525
+ return { ok: false, reason: "plan" };
526
+ return fastStartRules(store, { actor: input.actor, repo: input.repo, title: input.title, taskId: input.taskId, sizing: input.sizing, proof: { chat: { fullAccess: false, capMicrousd: null } } }, now);
527
+ });
528
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Home's three groups (docs/plans/one-step-chat.md H1): what waits on you, what is working, what is done. One rule for
3
+ * every surface that groups work this way (Home in the browser, the terminal UI), so they never disagree. Pure: no
4
+ * server, store or rendering imports, so the terminal UI's source can use it too.
5
+ */
6
+ export type HomeGroup = "you" | "working" | "done";
7
+ /** The groups in the order every surface shows them. */
8
+ export declare const HOME_GROUPS: readonly HomeGroup[];
9
+ /** Each group's heading. */
10
+ export declare const HOME_GROUP_LABEL: Readonly<Record<HomeGroup, string>>;
11
+ /** What the rule reads of a work index item (work-index.ts WorkIndexItem): the Tasks views that list it. */
12
+ export type HomeGroupFacts = {
13
+ readonly status: {
14
+ readonly views: readonly string[];
15
+ };
16
+ };
17
+ /**
18
+ * Which group a work index item belongs to, in this order: it waits on you when the Needs you view lists it; it is
19
+ * working when the Running or the Queued view lists it (it runs, or it waits its turn or on Toolroll or another task:
20
+ * nobody is asked), so Working is exactly what the Running and Queued figures count; it is done when it is complete.
21
+ * Null for anything else: cancelled, replaced, put away.
22
+ */
23
+ export declare function homeGroupOf(item: HomeGroupFacts): HomeGroup | null;
24
+ /** The work index totals Home's figures show, each the count of the Tasks list its figure opens. */
25
+ export type HomeFigures = {
26
+ readonly waitingOnYou: number;
27
+ readonly running: number;
28
+ readonly queued: number;
29
+ readonly done: number;
30
+ };
31
+ /** Home's figures from work index totals (work-index.ts WorkIndexCounts): Done is the whole Completed list. */
32
+ export declare function homeFiguresOf(totals: {
33
+ readonly "needs-you": number;
34
+ readonly running: number;
35
+ readonly queued: number;
36
+ readonly completed: number;
37
+ }): HomeFigures;
38
+ /** "Waiting on you 2 · Running 1 · Queued 0 · Done 14": the opening line of `toolroll status` and chat /status. */
39
+ export declare function homeFiguresLine(figures: HomeFigures): string;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Home's three groups (docs/plans/one-step-chat.md H1): what waits on you, what is working, what is done. One rule for
3
+ * every surface that groups work this way (Home in the browser, the terminal UI), so they never disagree. Pure: no
4
+ * server, store or rendering imports, so the terminal UI's source can use it too.
5
+ */
6
+ /** The groups in the order every surface shows them. */
7
+ export const HOME_GROUPS = ["you", "working", "done"];
8
+ /** Each group's heading. */
9
+ export const HOME_GROUP_LABEL = { you: "Waiting on you", working: "Working", done: "Done" };
10
+ /**
11
+ * Which group a work index item belongs to, in this order: it waits on you when the Needs you view lists it; it is
12
+ * working when the Running or the Queued view lists it (it runs, or it waits its turn or on Toolroll or another task:
13
+ * nobody is asked), so Working is exactly what the Running and Queued figures count; it is done when it is complete.
14
+ * Null for anything else: cancelled, replaced, put away.
15
+ */
16
+ export function homeGroupOf(item) {
17
+ const views = item.status.views;
18
+ if (views.includes("needs-you"))
19
+ return "you";
20
+ if (views.includes("running") || views.includes("queued"))
21
+ return "working";
22
+ if (views.includes("completed"))
23
+ return "done";
24
+ return null;
25
+ }
26
+ /** Home's figures from work index totals (work-index.ts WorkIndexCounts): Done is the whole Completed list. */
27
+ export function homeFiguresOf(totals) {
28
+ return { waitingOnYou: totals["needs-you"], running: totals.running, queued: totals.queued, done: totals.completed };
29
+ }
30
+ /** "Waiting on you 2 · Running 1 · Queued 0 · Done 14": the opening line of `toolroll status` and chat /status. */
31
+ export function homeFiguresLine(figures) {
32
+ return `Waiting on you ${figures.waitingOnYou} · Running ${figures.running} · Queued ${figures.queued} · Done ${figures.done}`;
33
+ }
@@ -1,5 +1,6 @@
1
1
  import { type ChatConfig, type Store } from "./store.js";
2
2
  import { type VerifiedApprover } from "./principal.js";
3
+ import { type ReplyVoice, type VoiceSummary } from "./reply-voice.js";
3
4
  import type { SubscriptionLeadRunner } from "./subscription-chat.js";
4
5
  export declare const LEAD_ANSWER_K = 3;
5
6
  type Seeded = {
@@ -47,6 +48,7 @@ type Run = {
47
48
  named: boolean;
48
49
  falseClaims: number;
49
50
  failed: string | null;
51
+ voice: ReplyVoice;
50
52
  };
51
53
  export type LeadAnswerReport = {
52
54
  mode: "scripted" | "real";
@@ -70,6 +72,11 @@ export type LeadAnswerReport = {
70
72
  total: number;
71
73
  failures: string[];
72
74
  };
75
+ /** How the read answers read, per model (docs/plans/lead-voice.md, V3). Reported; `pass` does not depend on it. */
76
+ voice: {
77
+ main: VoiceSummary;
78
+ quick: VoiceSummary;
79
+ };
73
80
  speedup: number;
74
81
  pass: boolean;
75
82
  reasons: string[];
@@ -32,6 +32,7 @@ import { verifyApproverStanding } from "./principal.js";
32
32
  import { subscriptionCredentialKey } from "./converse.js";
33
33
  import { runLeadTurn } from "./lead.js";
34
34
  import { quickLeadModel, quickRoute } from "./lead-route.js";
35
+ import { replyVoice, summarizeVoice } from "./reply-voice.js";
35
36
  export const LEAD_ANSWER_K = 3;
36
37
  const T0 = new Date("2026-11-08T12:00:00.000Z");
37
38
  const REPO = "/eval/shop";
@@ -191,10 +192,10 @@ export async function runLeadAnswerEval(options) {
191
192
  const answer = outcome.ok && !outcome.replayed ? outcome.reply : "";
192
193
  const graded = gradeAnswer(question, answer);
193
194
  const failed = outcome.ok ? null : "refused" in outcome ? `refused: ${outcome.refused}` : `failed: ${outcome.failed}`;
194
- return { model, route: turn?.route ?? null, answer, ms, named: failed === null && graded.named, falseClaims: graded.falseClaims, failed };
195
+ return { model, route: turn?.route ?? null, answer, ms, named: failed === null && graded.named, falseClaims: graded.falseClaims, failed, voice: replyVoice(answer) };
195
196
  };
196
197
  const read = questions.filter(one => one.kind === "read");
197
- const tally = { main: { passK: 0, falseClaims: 0, ms: [] }, quick: { passK: 0, falseClaims: 0, ms: [] } };
198
+ const tally = { main: { passK: 0, falseClaims: 0, ms: [], voices: [] }, quick: { passK: 0, falseClaims: 0, ms: [], voices: [] } };
198
199
  for (const question of read) {
199
200
  for (const model of ["main", "quick"]) {
200
201
  let all = true;
@@ -206,6 +207,8 @@ export async function runLeadAnswerEval(options) {
206
207
  all = false;
207
208
  tally[model].falseClaims += one.falseClaims;
208
209
  tally[model].ms.push(one.ms);
210
+ if (one.answer !== "")
211
+ tally[model].voices.push(one.voice);
209
212
  }
210
213
  if (all)
211
214
  tally[model].passK++;
@@ -250,6 +253,7 @@ export async function runLeadAnswerEval(options) {
250
253
  mode: options.mode, k, quickModel,
251
254
  read: { main: { passK: tally.main.passK, falseClaims: tally.main.falseClaims, medianMs: mainMs }, quick: { passK: tally.quick.passK, falseClaims: tally.quick.falseClaims, medianMs: quickMs }, questions: read.length },
252
255
  act: { kept, total: acts.length, failures: actFailures },
256
+ voice: { main: summarizeVoice(tally.main.voices), quick: summarizeVoice(tally.quick.voices) },
253
257
  speedup, pass: reasons.length === 0, reasons, runs,
254
258
  };
255
259
  }
@@ -200,7 +200,7 @@ export function capabilitiesOf(store, input) {
200
200
  * report on a task, attempt or check does (crew work must run), and a timed one does when it is reported on a chat app. */
201
201
  const FLOW_WORK = new Set(["create", "edit", "kit", "starter", "add_trigger", "resume_trigger", "add_card"]);
202
202
  export function needsCapabilities(name, args, channel) {
203
- if (name === "propose_task" || name === "propose_sweep")
203
+ if (name === "propose_task" || name === "propose_start" || name === "propose_sweep")
204
204
  return true;
205
205
  if (name === "propose_flow")
206
206
  return FLOW_WORK.has(String(args["operation"]));
@@ -58,8 +58,8 @@ export const LEAD_REPLY_LIMITS = {
58
58
  };
59
59
  const within = (channel) => { const limit = LEAD_REPLY_LIMITS[channel]; return limit === null ? '' : ` Keep each reply within ${limit.toLocaleString('en-US')} characters, one message; a longer one is split across messages.`; };
60
60
  const CHANNEL_WORDS = {
61
- console: 'The Toolroll console in a browser: cards and links show beside your reply.',
62
- terminal: 'The Toolroll CLI in a terminal: plain text only.',
61
+ console: "The Toolroll console in a browser: a few short lines. Cards and links show beside your reply, so don't repeat what a card shows.",
62
+ terminal: 'The Toolroll CLI in a terminal: a few short lines of plain text.',
63
63
  telegram: `Telegram on their phone: a few short lines, the most important first.${within('telegram')}`,
64
64
  slack: `A Slack thread: a few short lines; teammates may read it.${within('slack')}`,
65
65
  discord: `A Discord thread: a few short lines; teammates may read it.${within('discord')}`,
@@ -6,5 +6,5 @@
6
6
  * recommendations never reach the model — the tools already hide them —
7
7
  * so the contract need not forbid repeating what it cannot see.
8
8
  */
9
- export declare const LEAD_CONTRACT_VERSION = 51;
9
+ export declare const LEAD_CONTRACT_VERSION = 53;
10
10
  export declare const LEAD_CONTRACT: string;