@ordewell/core 0.5.5 → 0.5.6
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.
- package/dist/IFileSystem-BkPX7mLD.d.mts +76 -0
- package/dist/IFileSystem-C0l-4MGT.d.ts +76 -0
- package/dist/{ModeResolver-D3XO0fT9.d.ts → ModeResolver--16lh7dS.d.mts} +1 -1
- package/dist/{ModeResolver-D-SUFRNF.d.mts → ModeResolver-CjpG5Wli.d.ts} +1 -1
- package/dist/Task-Dyxp67s2.d.mts +2086 -0
- package/dist/Task-Dyxp67s2.d.ts +2086 -0
- package/dist/{chunk-T2S5O36I.mjs → chunk-C44UWIAD.mjs} +6 -6
- package/dist/chunk-C44UWIAD.mjs.map +1 -0
- package/dist/{chunk-HD2FWPRV.mjs → chunk-EDGUFCIR.mjs} +6 -1
- package/dist/chunk-EDGUFCIR.mjs.map +1 -0
- package/dist/{chunk-UUBGVCGJ.mjs → chunk-JBEFAJ2W.mjs} +2 -2
- package/dist/{chunk-KLN7ELXO.mjs → chunk-ROVYWEBI.mjs} +1560 -1269
- package/dist/chunk-ROVYWEBI.mjs.map +1 -0
- package/dist/index.d.mts +1414 -785
- package/dist/index.d.ts +1414 -785
- package/dist/index.js +7008 -4389
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6075 -3767
- package/dist/index.mjs.map +1 -1
- package/dist/order-labels.d.mts +3 -1
- package/dist/order-labels.d.ts +3 -1
- package/dist/{parsing-CDtRSxBY.d.mts → parsing-DPEpAszP.d.mts} +2 -2
- package/dist/{parsing-BTP4bwkk.d.ts → parsing-EcmCsF1y.d.ts} +2 -2
- package/dist/parsing.d.mts +5 -3
- package/dist/parsing.d.ts +5 -3
- package/dist/parsing.js.map +1 -1
- package/dist/parsing.mjs +2 -2
- package/dist/{plan-utils-pE4TBwxl.d.mts → plan-utils-BAvW3hvl.d.mts} +212 -43
- package/dist/{plan-utils-BFaPo-IT.d.ts → plan-utils-BMyEiDKv.d.ts} +212 -43
- package/dist/plan-utils.d.mts +5 -4
- package/dist/plan-utils.d.ts +5 -4
- package/dist/plan-utils.js +351 -64
- package/dist/plan-utils.js.map +1 -1
- package/dist/plan-utils.mjs +11 -5
- package/dist/testing.d.mts +54 -4
- package/dist/testing.d.ts +54 -4
- package/dist/testing.js +93 -2
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +91 -2
- package/dist/testing.mjs.map +1 -1
- package/package.json +2 -1
- package/skills/grilling/SKILL.md +6 -16
- package/skills/improve-codebase-architecture/SKILL.md +1 -1
- package/dist/ApprovalPolicy-BVhGdECT.d.mts +0 -79
- package/dist/ApprovalPolicy-BVhGdECT.d.ts +0 -79
- package/dist/ITerminalRunner-BV9Rd2o9.d.ts +0 -563
- package/dist/ITerminalRunner-C77ZNZS9.d.mts +0 -563
- package/dist/Task-Vl5Zq_D-.d.mts +0 -825
- package/dist/Task-Vl5Zq_D-.d.ts +0 -825
- package/dist/chunk-HD2FWPRV.mjs.map +0 -1
- package/dist/chunk-KLN7ELXO.mjs.map +0 -1
- package/dist/chunk-T2S5O36I.mjs.map +0 -1
- /package/dist/{chunk-UUBGVCGJ.mjs.map → chunk-JBEFAJ2W.mjs.map} +0 -0
|
@@ -0,0 +1,2086 @@
|
|
|
1
|
+
import { ChildProcess } from 'child_process';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Why isolated execution is unavailable for a workspace. The orchestrator needs
|
|
6
|
+
* the reason, not just a boolean: `dirty` is offered a stash or an explicit
|
|
7
|
+
* "run without isolation", while the others fall back to the shared
|
|
8
|
+
* workspace root with a one-line notice.
|
|
9
|
+
*/
|
|
10
|
+
type IsolationInactiveReason = 'disabled' | 'git-missing' | 'not-git' | 'no-commits' | 'dirty' | 'nested-repos';
|
|
11
|
+
/**
|
|
12
|
+
* `repos` names, relative to the workspace, the repositories behind the answer:
|
|
13
|
+
* when active, the ones that will isolate, with `shared` the paths every task
|
|
14
|
+
* will share live; otherwise the nested ones `nested-repos` refuses, the dirty
|
|
15
|
+
* ones of a `dirty` group, or the commitless ones of a `no-commits` group. A
|
|
16
|
+
* group of one names none.
|
|
17
|
+
*/
|
|
18
|
+
type IsolationAvailability = {
|
|
19
|
+
active: true;
|
|
20
|
+
repos?: string[];
|
|
21
|
+
shared?: string[];
|
|
22
|
+
} | {
|
|
23
|
+
active: false;
|
|
24
|
+
reason: IsolationInactiveReason;
|
|
25
|
+
repos?: string[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Where a run's tasks work, as the planner is told it: the repos of the group
|
|
29
|
+
* and the paths shared live between tasks. A lone repository is `['.']` with
|
|
30
|
+
* nothing shared.
|
|
31
|
+
*/
|
|
32
|
+
interface RepoGroupLayout {
|
|
33
|
+
repos: string[];
|
|
34
|
+
shared: string[];
|
|
35
|
+
}
|
|
36
|
+
type IsolationOutcome = 'merged' | 'conflict' | 'failed';
|
|
37
|
+
/**
|
|
38
|
+
* `active` — worktree exists, a runner may be writing to it.
|
|
39
|
+
* `kept` — released with its worktree and branch preserved for inspection.
|
|
40
|
+
* `conflict` — integration stopped on a merge conflict; worktree and refs kept.
|
|
41
|
+
* `repairing` — a conflict repair (ADR-0015) is working in the kept worktree;
|
|
42
|
+
* one that ends without landing leaves the task `conflict` again.
|
|
43
|
+
* `failed` — integration hit a git error other than a conflict; refs kept.
|
|
44
|
+
* `merged` — landed on the integration branch; worktree and task branch removed.
|
|
45
|
+
*/
|
|
46
|
+
type IsolationTaskStatus = 'active' | 'kept' | 'conflict' | 'repairing' | 'failed' | 'merged';
|
|
47
|
+
/** One repo's share of a task: its worktree inside the task workspace. */
|
|
48
|
+
interface IsolationTaskRepo {
|
|
49
|
+
/** Absolute path of this repo's worktree: the task workspace joined with the repo's path. */
|
|
50
|
+
worktree: string;
|
|
51
|
+
/**
|
|
52
|
+
* Paths bootstrapped from the real repo (symlinks, junctions, copies).
|
|
53
|
+
* Recorded so the commit step can leave them out — a symlink is not matched
|
|
54
|
+
* by a `node_modules/` ignore rule and would otherwise be committed.
|
|
55
|
+
*/
|
|
56
|
+
linked: string[];
|
|
57
|
+
/** Whether the task brought commits to this repo; unknown until it first integrates. */
|
|
58
|
+
changed?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface IsolationTaskRecord {
|
|
61
|
+
taskId: string;
|
|
62
|
+
order: number;
|
|
63
|
+
title: string;
|
|
64
|
+
/** One branch name, the same in every repo, so a task is one name to look up across the group. */
|
|
65
|
+
branch: string;
|
|
66
|
+
/**
|
|
67
|
+
* Absolute path of the task workspace, holding one worktree per repo at the
|
|
68
|
+
* repo's path. The Runner's cwd is inside it when the workspace is a repo
|
|
69
|
+
* subdirectory; for a group of one it is the worktree.
|
|
70
|
+
*/
|
|
71
|
+
workspace: string;
|
|
72
|
+
/** For the task as a whole: landing is atomic across the repos it changed. */
|
|
73
|
+
status: IsolationTaskStatus;
|
|
74
|
+
/** Keyed by repo path. */
|
|
75
|
+
repos: Record<string, IsolationTaskRepo>;
|
|
76
|
+
/** The repo whose merge stopped the task from landing, while `status` is `conflict` or `failed`. */
|
|
77
|
+
conflictRepo?: string;
|
|
78
|
+
/**
|
|
79
|
+
* What a `failed` landing stopped on, in words a surface can repeat — a
|
|
80
|
+
* missing worktree is the common one. Cleared by the next landing attempt,
|
|
81
|
+
* so a stale reason cannot outlive the failure it explains.
|
|
82
|
+
*/
|
|
83
|
+
landingError?: string;
|
|
84
|
+
/** Repo-relative paths, in `conflictRepo`, that conflicted; set only while `status` is `conflict` or `repairing`. */
|
|
85
|
+
conflictFiles?: string[];
|
|
86
|
+
/**
|
|
87
|
+
* Conflict repairs started for this task (ADR-0015). Counted when one starts,
|
|
88
|
+
* so a crash cannot hand the spent attempt back; absent reads as none.
|
|
89
|
+
*/
|
|
90
|
+
repairs?: number;
|
|
91
|
+
/**
|
|
92
|
+
* Keyed by repo path: each changed repo's integration tip when the repair in
|
|
93
|
+
* flight started — what the task branch must contain before it may land.
|
|
94
|
+
* Set only while `status` is `repairing`.
|
|
95
|
+
*/
|
|
96
|
+
repairBase?: Record<string, string>;
|
|
97
|
+
/**
|
|
98
|
+
* Every file a repair was started for, across all of them: as `conflictFiles`
|
|
99
|
+
* names it in a group of one, prefixed with its repo's path in a group.
|
|
100
|
+
*/
|
|
101
|
+
repairedFiles?: string[];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A task's landing in flight: each changed repo's integration tip from before
|
|
105
|
+
* the task's merge. On the run rather than the task record because it must
|
|
106
|
+
* outlive that record — a retry drops and recreates it — until every repo is
|
|
107
|
+
* back at its tip or the task has landed.
|
|
108
|
+
*/
|
|
109
|
+
interface IsolationLanding {
|
|
110
|
+
taskId: string;
|
|
111
|
+
/** Keyed by repo path. */
|
|
112
|
+
tips: Record<string, string>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* One repository of the group (ADR-0014). Every git operation on it runs in
|
|
116
|
+
* `root`, never in the workspace root.
|
|
117
|
+
*/
|
|
118
|
+
interface IsolationRepo {
|
|
119
|
+
/** Relative to the workspace root; `.` when the workspace is itself the repository. */
|
|
120
|
+
path: string;
|
|
121
|
+
/**
|
|
122
|
+
* Absolute: the workspace root joined with `path`. For a group of one that is
|
|
123
|
+
* the workspace root, which may be a subdirectory of the repository.
|
|
124
|
+
*/
|
|
125
|
+
root: string;
|
|
126
|
+
/** The commit checked out at run start. Switching branches mid-run does not retarget it. */
|
|
127
|
+
baseRef: string;
|
|
128
|
+
/** Branch name checked out at run start; absent on a detached HEAD. */
|
|
129
|
+
baseBranch?: string;
|
|
130
|
+
integrationBranch: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* One Execute-Plan click or one manual task run over the workspace's repo
|
|
134
|
+
* group. Plain JSON on purpose: the orchestrator persists it with the plan
|
|
135
|
+
* state so a resumed session can find its integration branches again. The
|
|
136
|
+
* module mutates `tasks` in place.
|
|
137
|
+
*/
|
|
138
|
+
interface IsolationRun {
|
|
139
|
+
id: string;
|
|
140
|
+
workspaceRoot: string;
|
|
141
|
+
repos: IsolationRepo[];
|
|
142
|
+
/**
|
|
143
|
+
* Workspace paths outside every isolated repo, linked live into each task
|
|
144
|
+
* workspace: loose entries of the workspace root, the entries beside a deeper
|
|
145
|
+
* repo, and `sharedRepos`. Empty for a group of one.
|
|
146
|
+
*/
|
|
147
|
+
shared: string[];
|
|
148
|
+
/** Repos of the group that could not be isolated — no commits, or git refused a worktree — and are among `shared`. */
|
|
149
|
+
sharedRepos: string[];
|
|
150
|
+
/** Keyed by task id — ids are unique within one plan and a run belongs to one plan. */
|
|
151
|
+
tasks: Record<string, IsolationTaskRecord>;
|
|
152
|
+
/**
|
|
153
|
+
* Set before a task's first merge and cleared once it has landed or been
|
|
154
|
+
* rolled back. One found set — after a crash, or a rollback git refused —
|
|
155
|
+
* names exactly what to return each repo's integration branch to.
|
|
156
|
+
*/
|
|
157
|
+
landing?: IsolationLanding;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* What a plan persists of isolated execution (`LegacyPlanState.isolation`): its
|
|
161
|
+
* run, and which added tasks resolve which conflicts. Belongs to that plan and
|
|
162
|
+
* its branches alone, so a copy of the plan (a fork) must not carry it.
|
|
163
|
+
*/
|
|
164
|
+
interface PlanIsolation {
|
|
165
|
+
run: IsolationRun;
|
|
166
|
+
/** Resolver task id → the conflicted task whose branch it merges. */
|
|
167
|
+
resolvers: Record<string, string>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* A task's isolation as a surface shows it. `kept` covers every record whose
|
|
171
|
+
* worktree stays for inspection — a failed verdict, an interrupted attempt, an
|
|
172
|
+
* integration git refused — because to the user they are one thing: work that
|
|
173
|
+
* did not land and can be looked at. `none` is a task with no worktree in a plan
|
|
174
|
+
* that has an isolation run.
|
|
175
|
+
*/
|
|
176
|
+
type TaskIsolationState = 'none' | 'active' | 'integrated' | 'conflict' | 'repairing' | 'kept';
|
|
177
|
+
type TaskIsolation = {
|
|
178
|
+
state: 'none';
|
|
179
|
+
} | {
|
|
180
|
+
state: Exclude<TaskIsolationState, 'none'>;
|
|
181
|
+
branch: string;
|
|
182
|
+
/** The task workspace; for a group of one, the task's worktree. */
|
|
183
|
+
worktree: string;
|
|
184
|
+
/** Paths of the repos the task changed. */
|
|
185
|
+
repos: string[];
|
|
186
|
+
conflictRepo?: string;
|
|
187
|
+
/** Repo-relative paths, in `conflictRepo`, that conflicted. */
|
|
188
|
+
conflictFiles?: string[];
|
|
189
|
+
/** The conflict repair running or last run, of the most a task may have; absent before its first. */
|
|
190
|
+
repair?: {
|
|
191
|
+
attempt: number;
|
|
192
|
+
limit: number;
|
|
193
|
+
};
|
|
194
|
+
/** What {@link IsolationTaskRecord.repairedFiles} says. */
|
|
195
|
+
repairedFiles?: string[];
|
|
196
|
+
};
|
|
197
|
+
interface IsolationLandedTask {
|
|
198
|
+
taskId: string;
|
|
199
|
+
order: number;
|
|
200
|
+
title: string;
|
|
201
|
+
/** Set when the task landed only after a conflict repair (ADR-0015): the files it was started for. */
|
|
202
|
+
repairedFiles?: string[];
|
|
203
|
+
}
|
|
204
|
+
interface IsolationHandoffRepo {
|
|
205
|
+
path: string;
|
|
206
|
+
integrationBranch: string;
|
|
207
|
+
baseRef: string;
|
|
208
|
+
/** Tasks whose work landed in this repo, in plan order. */
|
|
209
|
+
landed: IsolationLandedTask[];
|
|
210
|
+
}
|
|
211
|
+
interface IsolationHandoff {
|
|
212
|
+
repos: IsolationHandoffRepo[];
|
|
213
|
+
/** Tasks that landed on the integration branches, in plan order. */
|
|
214
|
+
landed: IsolationLandedTask[];
|
|
215
|
+
}
|
|
216
|
+
/** A plan's isolation as a surface shows it: a mark for each task the run touched, and its handoff. */
|
|
217
|
+
interface IsolationView {
|
|
218
|
+
tasks: Record<string, TaskIsolation>;
|
|
219
|
+
handoff: IsolationHandoff;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Why "Merge all" would not touch a repo. `partial-landing`: a task's landing
|
|
223
|
+
* was interrupted and could not be rolled back there, so its integration
|
|
224
|
+
* branch holds part of a task.
|
|
225
|
+
*/
|
|
226
|
+
type IsolationMergeBlockReason = 'merge-in-progress' | 'conflict' | 'uncommitted-changes' | 'partial-landing' | 'git-error';
|
|
227
|
+
interface IsolationMergeBlock {
|
|
228
|
+
repo: string;
|
|
229
|
+
reason: IsolationMergeBlockReason;
|
|
230
|
+
/** The files that would conflict, or the user's uncommitted ones the merge also changes; empty for the other reasons. */
|
|
231
|
+
files: string[];
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* How "Merge all" went.
|
|
235
|
+
* - `merged`: every repo with work on its integration branch took it.
|
|
236
|
+
* - `blocked`: the preflight found repos that could not, so nothing was
|
|
237
|
+
* touched anywhere; `blocked` says which and why.
|
|
238
|
+
* - `conflict` / `failed`: a merge stopped in `repo` — on git older than 2.38,
|
|
239
|
+
* which cannot preflight, or for a reason no preflight could foresee. That
|
|
240
|
+
* merge was aborted, leaving `repo` as it was; `landed` names the repos
|
|
241
|
+
* merged before it, which stay merged, and is absent when there are none.
|
|
242
|
+
*
|
|
243
|
+
* A group of one is blocked only by a partial landing; otherwise its one merge
|
|
244
|
+
* lands or is aborted whole, so it reports as it always has.
|
|
245
|
+
*/
|
|
246
|
+
type IsolationMergeResult = {
|
|
247
|
+
outcome: 'merged';
|
|
248
|
+
} | {
|
|
249
|
+
outcome: 'blocked';
|
|
250
|
+
blocked: IsolationMergeBlock[];
|
|
251
|
+
} | {
|
|
252
|
+
outcome: 'conflict' | 'failed';
|
|
253
|
+
repo: string;
|
|
254
|
+
files?: string[];
|
|
255
|
+
landed?: string[];
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* What `discard` does with each repo's integration branch: `keep` it for review
|
|
259
|
+
* or merge, `delete` it, or delete it only in the repos whose checked-out HEAD
|
|
260
|
+
* already contains it (`delete-merged`) — the one way that can never give up
|
|
261
|
+
* landed work the user has not merged.
|
|
262
|
+
*/
|
|
263
|
+
type IntegrationDisposal = 'keep' | 'delete' | 'delete-merged';
|
|
264
|
+
/**
|
|
265
|
+
* Whether a conflict repair's work may land. `not-merged`: the task branch in
|
|
266
|
+
* `repo` does not contain the tip the repair started from. `conflict-markers`:
|
|
267
|
+
* it adds leftover conflict markers to `files`. `failed`: git could not tell.
|
|
268
|
+
*/
|
|
269
|
+
type RepairEvidence = {
|
|
270
|
+
ok: true;
|
|
271
|
+
} | {
|
|
272
|
+
ok: false;
|
|
273
|
+
reason: 'not-merged' | 'conflict-markers' | 'failed';
|
|
274
|
+
repo: string;
|
|
275
|
+
files?: string[];
|
|
276
|
+
};
|
|
277
|
+
interface PreparedTask {
|
|
278
|
+
cwd: string;
|
|
279
|
+
branch: string;
|
|
280
|
+
/**
|
|
281
|
+
* Paths, relative to the task workspace, that are copies rather than links
|
|
282
|
+
* because a hard link was impossible (Windows, another volume). Edits to them
|
|
283
|
+
* stay in the task, so the user is told.
|
|
284
|
+
*/
|
|
285
|
+
copied: string[];
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* What a crash-recovery prune found and left alone: task records that were
|
|
289
|
+
* `active` yet still held unlanded work, so the prune kept them as `kept`
|
|
290
|
+
* rather than deleting work no one else has.
|
|
291
|
+
*/
|
|
292
|
+
interface IsolationPruneResult {
|
|
293
|
+
kept: Array<{
|
|
294
|
+
taskId: string;
|
|
295
|
+
order: number;
|
|
296
|
+
title: string;
|
|
297
|
+
}>;
|
|
298
|
+
}
|
|
299
|
+
interface IWorktreeIsolation {
|
|
300
|
+
/**
|
|
301
|
+
* A repo group with at least one repo to isolate, a clean tracked tree in
|
|
302
|
+
* each, and the config enabled; otherwise the reason it is not.
|
|
303
|
+
*/
|
|
304
|
+
isActive(workspaceRoot: string): Promise<IsolationAvailability>;
|
|
305
|
+
/**
|
|
306
|
+
* Put the tracked changes of every dirty repo of the group on its git stash,
|
|
307
|
+
* the user's way out of a `dirty` refusal. Untracked files stay: they never
|
|
308
|
+
* block isolation.
|
|
309
|
+
*/
|
|
310
|
+
stash(workspaceRoot: string): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Mint a run: resolve each repo's base ref to a commit now, and share the
|
|
313
|
+
* repos that cannot be isolated. Only meaningful after `isActive` said yes;
|
|
314
|
+
* throws when no repo of the group can be isolated after all.
|
|
315
|
+
*/
|
|
316
|
+
startRun(workspaceRoot: string): Promise<IsolationRun>;
|
|
317
|
+
/**
|
|
318
|
+
* Create the task workspace — one worktree per isolated repo from its
|
|
319
|
+
* integration tip, the shared paths linked in — and return the cwd to spawn
|
|
320
|
+
* the Runner into. A second `prepare` for the same task is a retry: the old
|
|
321
|
+
* attempt is discarded and the workspace recreated from the tips, so the
|
|
322
|
+
* task sees everything its predecessors have integrated.
|
|
323
|
+
*/
|
|
324
|
+
prepare(task: Task, run: IsolationRun): Promise<PreparedTask>;
|
|
325
|
+
/**
|
|
326
|
+
* Hand a conflicted task's kept workspace to a conflict repair (ADR-0015)
|
|
327
|
+
* as it is — nothing is re-cut — and return the same cwd. Records each
|
|
328
|
+
* changed repo's integration tip as `repairBase`, counts the repair, and
|
|
329
|
+
* moves the task to `repairing`. Throws for a task that is not `conflict`.
|
|
330
|
+
*/
|
|
331
|
+
reopen(task: Task, run: IsolationRun): Promise<PreparedTask>;
|
|
332
|
+
/**
|
|
333
|
+
* The evidence a repair must show before it lands: its work committed, and
|
|
334
|
+
* in each repo of `repairBase` the task branch containing that tip
|
|
335
|
+
* (`git merge-base --is-ancestor`) and adding no leftover conflict markers
|
|
336
|
+
* (`git diff --check`; whitespace warnings do not count). Changes nothing
|
|
337
|
+
* else: a task that fails stays `repairing` until released.
|
|
338
|
+
*/
|
|
339
|
+
verifyRepair(task: Task, run: IsolationRun): Promise<RepairEvidence>;
|
|
340
|
+
/**
|
|
341
|
+
* Land the task atomically across the repos it changed: commit each
|
|
342
|
+
* worktree, then `git merge --no-ff` the task branch into each changed
|
|
343
|
+
* repo's integration branch. If any merge conflicts or fails, it is aborted
|
|
344
|
+
* and the merges already made for the task are reset away, so `merged`
|
|
345
|
+
* always means the whole task landed. Serialized inside the module; among
|
|
346
|
+
* tasks waiting at once the lowest plan order goes first. On anything but
|
|
347
|
+
* `merged` the worktrees and refs stay, and nothing is resolved here: a
|
|
348
|
+
* conflict is repaired, if at all, by a new attempt of the task in its own
|
|
349
|
+
* worktree (ADR-0015), never inside this queue.
|
|
350
|
+
*
|
|
351
|
+
* `persist` is called once `run.landing` is set and before the first
|
|
352
|
+
* merge; the caller saves the run there, synchronously, which is what
|
|
353
|
+
* lets `pruneOrphans` finish a landing a crash interrupted.
|
|
354
|
+
*/
|
|
355
|
+
integrate(task: Task, run: IsolationRun, persist?: () => void): Promise<IsolationOutcome>;
|
|
356
|
+
/**
|
|
357
|
+
* `keep: false` removes the task's worktree, branch and record (retry, task
|
|
358
|
+
* removal). `keep: true` leaves the worktree and branch exactly as they are
|
|
359
|
+
* for inspection — a failed verdict, a stop, a cancel — and only moves the task off `active`,
|
|
360
|
+
* so a crash-recovery prune does not sweep it away; a repair it ends leaves
|
|
361
|
+
* the task `conflict`, as it was before the repair. Takes the run rather than
|
|
362
|
+
* a bare task id: ids are only unique within one plan, and one daemon serves
|
|
363
|
+
* many (ADR-0007).
|
|
364
|
+
*/
|
|
365
|
+
release(run: IsolationRun, taskId: string, opts: {
|
|
366
|
+
keep: boolean;
|
|
367
|
+
}): Promise<void>;
|
|
368
|
+
/** End of run: park the integration branch for review and report what landed. */
|
|
369
|
+
handoff(run: IsolationRun): Promise<IsolationHandoff>;
|
|
370
|
+
/**
|
|
371
|
+
* Drop what a crash left behind: a landing it interrupted is rolled back in
|
|
372
|
+
* every repo, a repair it interrupted leaves its task `conflict`, then stale
|
|
373
|
+
* active worktrees and directories no record owns go. An `active` record
|
|
374
|
+
* that still holds unlanded work — commits its branch alone carries, or
|
|
375
|
+
* edits in its worktree — is not a crash orphan: it may belong to a runner
|
|
376
|
+
* another host is still driving, so it is kept as `kept` and named in the
|
|
377
|
+
* result.
|
|
378
|
+
*/
|
|
379
|
+
pruneOrphans(run: IsolationRun): Promise<IsolationPruneResult>;
|
|
380
|
+
/** Unified diff of each repo's integration branch against its base ref. */
|
|
381
|
+
reviewDiff(run: IsolationRun): Promise<string>;
|
|
382
|
+
/**
|
|
383
|
+
* "Merge all": merge each repo's integration branch into whatever the user
|
|
384
|
+
* has checked out there. The one irreversible step, so it only ever happens
|
|
385
|
+
* when a caller asks for it. Every repo with work is preflighted first — no
|
|
386
|
+
* merge of the user's in progress, no conflict against their HEAD, no
|
|
387
|
+
* uncommitted edit to a file the merge changes — and unless all pass,
|
|
388
|
+
* nothing is merged anywhere. Only a merge Ordewell itself just started is
|
|
389
|
+
* ever aborted; nothing of the user's is reset.
|
|
390
|
+
*/
|
|
391
|
+
mergeIntoCheckedOut(run: IsolationRun): Promise<IsolationMergeResult>;
|
|
392
|
+
/**
|
|
393
|
+
* Remove every worktree and task branch of the run, and settle each repo's
|
|
394
|
+
* integration branch as `integration` says. Anything but `keep` also clears
|
|
395
|
+
* the run's task records.
|
|
396
|
+
*/
|
|
397
|
+
discard(run: IsolationRun, opts: {
|
|
398
|
+
integration: IntegrationDisposal;
|
|
399
|
+
}): Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* Clear what other runs left in each repo of `run`'s group: every
|
|
402
|
+
* `ordewell/<run-id>/…` branch the repo's checked-out HEAD already contains.
|
|
403
|
+
* Never a branch of `run` itself, one a worktree has checked out, or any
|
|
404
|
+
* branch of a run that still has a worktree — that run may be live in
|
|
405
|
+
* another plan. Tries every repo, then throws naming those where git failed.
|
|
406
|
+
*/
|
|
407
|
+
sweep(run: IsolationRun): Promise<void>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** One source for the spawn options, so a runner built on this base cannot drift from the interface. */
|
|
411
|
+
type RunnerSpawnOptions = Parameters<ITerminalRunner['spawn']>[0];
|
|
412
|
+
declare abstract class AbstractTerminalSession implements ITerminalSession {
|
|
413
|
+
id: string;
|
|
414
|
+
taskId: string;
|
|
415
|
+
protected exited: boolean;
|
|
416
|
+
protected outputEmitter: EventEmitter<any>;
|
|
417
|
+
protected exitEmitter: EventEmitter<any>;
|
|
418
|
+
constructor(id: string, taskId: string);
|
|
419
|
+
protected baseHandleExit(code: number): void;
|
|
420
|
+
onOutput(callback: (text: string) => void): void;
|
|
421
|
+
onExit(callback: (code: number) => void): void;
|
|
422
|
+
abstract kill(): void;
|
|
423
|
+
abstract getOutput(): string;
|
|
424
|
+
abstract write(text: string): void;
|
|
425
|
+
}
|
|
426
|
+
declare abstract class AbstractRunner<S extends ITerminalSession> implements ITerminalRunner {
|
|
427
|
+
protected sessions: Map<string, S>;
|
|
428
|
+
get activeCount(): number;
|
|
429
|
+
stop(sessionId: string): void;
|
|
430
|
+
stopAll(): void;
|
|
431
|
+
protected registerSession(id: string, session: S): void;
|
|
432
|
+
abstract spawn(opts: RunnerSpawnOptions): Promise<ITerminalSession>;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
declare function stripAnsi(text: string): string;
|
|
436
|
+
declare function posixShellQuote(s: string): string;
|
|
437
|
+
/**
|
|
438
|
+
* Wrap a command for execution inside a POSIX login shell, which is what
|
|
439
|
+
* resolves runner binaries managed by nvm/volta/asdf.
|
|
440
|
+
*
|
|
441
|
+
* Deliberately POSIX-only. This used to take a `platform` and emit
|
|
442
|
+
* `powershell.exe -Command "'claude' '-p' '…'"` for Windows, which PowerShell
|
|
443
|
+
* cannot run at all: a quoted string in leading position is parsed in
|
|
444
|
+
* expression mode, so the invocation died with a parse error before the runner
|
|
445
|
+
* started — a task that failed instantly, every time, on that platform. Windows
|
|
446
|
+
* has no login-shell equivalent to emulate (its PATH comes from the registry
|
|
447
|
+
* and is already inherited), so {@link planShellLaunch} starts the runner
|
|
448
|
+
* directly there instead of routing it through a shell. Platform choice belongs
|
|
449
|
+
* to that function; this one only knows how to phrase the POSIX half.
|
|
450
|
+
*/
|
|
451
|
+
declare function buildShellInvocation(command: string, args: string[]): {
|
|
452
|
+
shellPath: string;
|
|
453
|
+
shellArgs: string[];
|
|
454
|
+
};
|
|
455
|
+
/** A terminal size in cells. */
|
|
456
|
+
interface PtySize {
|
|
457
|
+
cols: number;
|
|
458
|
+
rows: number;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Options for {@link wrapWithPty}. `size` sets the PTY's window size before the
|
|
462
|
+
* wrapped command starts. `controlChannel` makes the wrapper listen on its fd 3
|
|
463
|
+
* for `"<cols> <rows>"` lines and resize the PTY live — the caller spawns the
|
|
464
|
+
* child with an extra pipe there and writes resize requests into it.
|
|
465
|
+
*/
|
|
466
|
+
interface PtyWrapOptions {
|
|
467
|
+
size?: PtySize;
|
|
468
|
+
controlChannel?: boolean;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Wrap a command in `script` to allocate the PTY some runners require when
|
|
472
|
+
* headless; `-e` propagates the child's exit code so verification still works.
|
|
473
|
+
*
|
|
474
|
+
* POSIX-only by nature — there is no `script` on Windows, which
|
|
475
|
+
* `HeadlessRunner`'s `hasScriptCmd` probe already discovers, so this is never
|
|
476
|
+
* reached there.
|
|
477
|
+
*
|
|
478
|
+
* `script` sizes its PTY off the terminal it is attached to; spawned off a pipe
|
|
479
|
+
* (every transport here) it allocates 0x0, which a runner TUI renders as
|
|
480
|
+
* garbage. `stty` fixes the size on the PTY slave before the command starts, so
|
|
481
|
+
* the TUI reads its true dimensions via ioctl.
|
|
482
|
+
*
|
|
483
|
+
* The control channel can only live on a *separate* fd from the agent's stdin,
|
|
484
|
+
* so the wrapper saves the PTY on fd 4 first: POSIX sends an asynchronous
|
|
485
|
+
* command's stdin to `/dev/null`, so the watcher's own stdin cannot be the PTY.
|
|
486
|
+
* A background job also inherits an fd 0 that is not the terminal; `stty` names
|
|
487
|
+
* fd 4 explicitly for that reason.
|
|
488
|
+
*/
|
|
489
|
+
declare function wrapWithPty(command: string, args: string[], opts?: PtyWrapOptions): {
|
|
490
|
+
command: string;
|
|
491
|
+
args: string[];
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* cmd.exe's command-line buffer. A longer line is truncated rather than
|
|
496
|
+
* rejected, which would corrupt a planner's system prompt or a task's prompt
|
|
497
|
+
* mid-sentence and produce a confident answer to half a question — so the
|
|
498
|
+
* batch route refuses instead. See {@link CommandLineTooLongError}.
|
|
499
|
+
*/
|
|
500
|
+
declare const CMD_EXE_MAX_COMMAND_LINE = 8191;
|
|
501
|
+
/**
|
|
502
|
+
* CreateProcess's own ceiling, which the native and PowerShell routes are
|
|
503
|
+
* bounded by instead. Windows truncates here too, so the same refusal applies —
|
|
504
|
+
* it is simply four times further away.
|
|
505
|
+
*/
|
|
506
|
+
declare const WINDOWS_MAX_COMMAND_LINE = 32767;
|
|
507
|
+
interface LaunchPlan {
|
|
508
|
+
/** The executable handed to `spawn()` or `vscode.window.createTerminal`. */
|
|
509
|
+
file: string;
|
|
510
|
+
/** Arguments for `file`. Pass verbatim when {@link verbatim} is set. */
|
|
511
|
+
args: string[];
|
|
512
|
+
/**
|
|
513
|
+
* Windows batch route only: `args` is already a quoted command line and must
|
|
514
|
+
* not be re-quoted. Maps to `windowsVerbatimArguments` for `spawn`, and to
|
|
515
|
+
* the string form of `shellArgs` for a VS Code terminal.
|
|
516
|
+
*/
|
|
517
|
+
verbatim?: boolean;
|
|
518
|
+
}
|
|
519
|
+
/** Test seam: every OS touchpoint is injectable, and production uses the defaults. */
|
|
520
|
+
interface LaunchDeps {
|
|
521
|
+
platform?: NodeJS.Platform;
|
|
522
|
+
/** The PATH executables are looked up on. Defaults to the augmented PATH. */
|
|
523
|
+
resolvePath?: () => Promise<string>;
|
|
524
|
+
/** True when `candidate` names an existing file. */
|
|
525
|
+
exists?: (candidate: string) => boolean;
|
|
526
|
+
/** Absolute path to the Windows command interpreter. */
|
|
527
|
+
comSpec?: () => string;
|
|
528
|
+
/** Absolute path to Windows PowerShell. */
|
|
529
|
+
powerShell?: () => string;
|
|
530
|
+
/** PATHEXT, as the environment reports it. */
|
|
531
|
+
pathExt?: () => string;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Thrown when a command's arguments do not fit the buffer of the only
|
|
535
|
+
* interpreter that can start it. Windows truncates rather than rejecting, and a
|
|
536
|
+
* system prompt cut off mid-sentence makes the planner answer half a question
|
|
537
|
+
* confidently — the silent success this repo refuses — so this is raised
|
|
538
|
+
* instead. `TaskOrchestrator.startTask` catches it and holds the task, so the
|
|
539
|
+
* message is what the user reads: it names the fix, because they cannot infer
|
|
540
|
+
* it from a truncated prompt.
|
|
541
|
+
*/
|
|
542
|
+
declare class CommandLineTooLongError extends Error {
|
|
543
|
+
readonly command: string;
|
|
544
|
+
readonly length: number;
|
|
545
|
+
readonly limit: number;
|
|
546
|
+
constructor(command: string, length: number, limit?: number);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Thrown when only a batch shim resolved for a multi-line argument. cmd.exe
|
|
550
|
+
* reads up to the first CR/LF and discards the rest with no error and exit code
|
|
551
|
+
* 0 — quoting does not help — so the agent would get the first paragraph of its
|
|
552
|
+
* prompt without the completion marker instruction, then exit looking successful.
|
|
553
|
+
*/
|
|
554
|
+
declare class EmbeddedNewlineError extends Error {
|
|
555
|
+
readonly command: string;
|
|
556
|
+
constructor(command: string);
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Thrown when `command` cannot be resolved to a real file. Kept distinguishable
|
|
560
|
+
* from `WorkspaceNotFoundError` (utils/workspace) even though both a missing
|
|
561
|
+
* cwd and a missing binary surface as the same `spawn` ENOENT to Node — the two
|
|
562
|
+
* are checked, and named, separately so the failure names the actual cause.
|
|
563
|
+
*/
|
|
564
|
+
declare class ExecutableNotFoundError extends Error {
|
|
565
|
+
readonly command: string;
|
|
566
|
+
readonly searchedPath: string;
|
|
567
|
+
constructor(command: string, searchedPath: string);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Whether `command` actually resolves to a file, given the plan
|
|
571
|
+
* {@link planDirectLaunch} produced for it and the PATH it was resolved
|
|
572
|
+
* against.
|
|
573
|
+
*
|
|
574
|
+
* POSIX is deliberately identity in `planDirectLaunch` (execvp does its own
|
|
575
|
+
* PATH search), so the search is repeated here instead. Windows already did
|
|
576
|
+
* the search inside `planDirectLaunch` — signalled by the returned file
|
|
577
|
+
* differing from the bare command name it was given; an unresolved command
|
|
578
|
+
* comes back unchanged.
|
|
579
|
+
*/
|
|
580
|
+
declare function isExecutableResolved(command: string, plan: LaunchPlan, PATH: string, deps?: LaunchDeps): boolean;
|
|
581
|
+
/** The verbatim command line cmd.exe receives after `/d /s /c`, before wrapping. */
|
|
582
|
+
declare function windowsCommandLine(file: string, args: string[]): string;
|
|
583
|
+
/**
|
|
584
|
+
* How to start `command` with `args` through `spawn()`, with no shell.
|
|
585
|
+
*
|
|
586
|
+
* POSIX returns its input unchanged — execvp already searches PATH, and adding
|
|
587
|
+
* a resolution step there would be a new way for a working setup to break.
|
|
588
|
+
*
|
|
589
|
+
* Windows resolves the command against PATH × PATHEXT, preferring a native
|
|
590
|
+
* executable (spawned directly) over a batch shim (through cmd.exe) over a
|
|
591
|
+
* PowerShell script shim (through `powershell.exe -File`). A command that
|
|
592
|
+
* resolves to nothing is returned unchanged, so the caller's existing ENOENT —
|
|
593
|
+
* which names what the user typed — is what surfaces rather than a second,
|
|
594
|
+
* vaguer error from here.
|
|
595
|
+
*
|
|
596
|
+
* The tiers are tried in preference order and the first that *fits* wins, with
|
|
597
|
+
* one deliberate exception: an overflowing batch shim does not fall through to
|
|
598
|
+
* PowerShell. Overflow means a very large prompt, which is precisely where
|
|
599
|
+
* `-File` argument fidelity is least worth betting on, and where a clear held
|
|
600
|
+
* task beats a plausibly-mangled one. So capacity does not reorder the tiers —
|
|
601
|
+
* a `.ps1` beside a too-long `.cmd` still raises.
|
|
602
|
+
*
|
|
603
|
+
* A line break does reorder them: cmd.exe cannot carry one at any length, so a
|
|
604
|
+
* `.ps1` beside a `.cmd` wins, and a lone `.cmd` raises.
|
|
605
|
+
*
|
|
606
|
+
* @throws {CommandLineTooLongError} when the selected route's buffer cannot
|
|
607
|
+
* carry the arguments.
|
|
608
|
+
* @throws {EmbeddedNewlineError} when the arguments span lines and only the
|
|
609
|
+
* batch route resolved.
|
|
610
|
+
*/
|
|
611
|
+
declare function planDirectLaunch(command: string, args: string[], deps?: LaunchDeps): Promise<LaunchPlan>;
|
|
612
|
+
/**
|
|
613
|
+
* How to start `command` for a surface that hands an executable and arguments
|
|
614
|
+
* to a terminal — the VS Code runner today, a Windows TUI later.
|
|
615
|
+
*
|
|
616
|
+
* On POSIX this is the login shell, unchanged: `bash -lc` runs the user's
|
|
617
|
+
* profile, which is how nvm/volta/asdf-managed runner binaries resolve at all.
|
|
618
|
+
* Windows has no login-shell equivalent (its PATH comes from the registry and
|
|
619
|
+
* is already inherited), so it takes the direct route instead. That is not just
|
|
620
|
+
* a simplification: it means the runner's own exit code is the terminal's exit
|
|
621
|
+
* code, rather than a `$LASTEXITCODE` that PowerShell propagates unreliably —
|
|
622
|
+
* and the exit code is half of what {@link VerdictEngine} judges a task on.
|
|
623
|
+
*/
|
|
624
|
+
declare function planShellLaunch(command: string, args: string[], deps?: LaunchDeps): Promise<LaunchPlan>;
|
|
625
|
+
|
|
626
|
+
type SpawnFn = (command: string, args: string[], options: {
|
|
627
|
+
env: NodeJS.ProcessEnv;
|
|
628
|
+
stdio: Array<'pipe' | 'ignore'>;
|
|
629
|
+
cwd: string;
|
|
630
|
+
/** Set by the Windows batch route, where `args` is already a quoted command line. */
|
|
631
|
+
windowsVerbatimArguments?: boolean;
|
|
632
|
+
}) => ChildProcess;
|
|
633
|
+
/** Test seam: every OS touchpoint is injectable; production uses the defaults. */
|
|
634
|
+
interface HeadlessRunnerDeps {
|
|
635
|
+
spawnImpl?: SpawnFn;
|
|
636
|
+
hasScriptCmd?: () => boolean;
|
|
637
|
+
resolvePath?: () => Promise<string>;
|
|
638
|
+
/**
|
|
639
|
+
* Overrides for executable resolution ({@link planDirectLaunch}). Only the
|
|
640
|
+
* Windows branch consults them, so a POSIX test never needs to pass anything.
|
|
641
|
+
*/
|
|
642
|
+
launchDeps?: LaunchDeps;
|
|
643
|
+
}
|
|
644
|
+
declare class HeadlessSession extends AbstractTerminalSession {
|
|
645
|
+
private spawnImpl;
|
|
646
|
+
readonly interactive: boolean;
|
|
647
|
+
private process;
|
|
648
|
+
private outputBuffer;
|
|
649
|
+
private controlStream;
|
|
650
|
+
constructor(id: string, taskId: string, spawnImpl: SpawnFn, interactive?: boolean);
|
|
651
|
+
get isStarted(): boolean;
|
|
652
|
+
start(launch: LaunchPlan, cwd: string, resolvedPath: string, env?: Record<string, string>, options?: {
|
|
653
|
+
controlChannel?: boolean;
|
|
654
|
+
}): void;
|
|
655
|
+
kill(): void;
|
|
656
|
+
getOutput(): string;
|
|
657
|
+
write(text: string): void;
|
|
658
|
+
/** PTY resize requests from a surface that owns the terminal rendering the wrapper. */
|
|
659
|
+
writeControl(text: string): void;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/** Everything needed to start one runner process, resolved before any child exists. */
|
|
663
|
+
interface PreparedLaunch {
|
|
664
|
+
launch: LaunchPlan;
|
|
665
|
+
resolvedPath: string;
|
|
666
|
+
env: Record<string, string>;
|
|
667
|
+
/** True when the invocation was wrapped in `script` to allocate a PTY. */
|
|
668
|
+
pty: boolean;
|
|
669
|
+
/** True when the started process needs an explicit Enter sent to submit its pre-filled prompt. */
|
|
670
|
+
submitPromptKey: boolean;
|
|
671
|
+
}
|
|
672
|
+
declare class HeadlessRunner extends AbstractRunner<HeadlessSession> {
|
|
673
|
+
private spawnImpl;
|
|
674
|
+
private hasScriptCmd;
|
|
675
|
+
private resolvePath;
|
|
676
|
+
private launchDeps;
|
|
677
|
+
private spawnCount;
|
|
678
|
+
/**
|
|
679
|
+
* Session shape: a piped subprocess is not a terminal, so runners get their
|
|
680
|
+
* non-interactive subcommand. The VS Code runner owns a pseudoterminal and
|
|
681
|
+
* overrides this to true. Autonomy is a separate axis (see `ResolveContext`)
|
|
682
|
+
* and stays on either way — no surface has a human answering permission
|
|
683
|
+
* prompts on the orchestrator's behalf.
|
|
684
|
+
*/
|
|
685
|
+
protected readonly defaultInteractive: boolean;
|
|
686
|
+
constructor(deps?: HeadlessRunnerDeps);
|
|
687
|
+
/**
|
|
688
|
+
* Unique per spawn, not per task: a retry reuses its task id and ids often
|
|
689
|
+
* share a prefix, and a shared registry key let the old attempt's exit
|
|
690
|
+
* unregister the new one. Unlike TmuxRunner, nothing outside this process
|
|
691
|
+
* keys on the id, so a counter is enough to scope it to the attempt.
|
|
692
|
+
*/
|
|
693
|
+
protected nextSessionId(taskId: string): string;
|
|
694
|
+
protected createSession(id: string, taskId: string): HeadlessSession;
|
|
695
|
+
/** Everything up to, but not including, spawning — so a surface that owns its own child reaches the same decisions. */
|
|
696
|
+
protected prepareLaunch(opts: RunnerSpawnOptions, ptyOptions?: PtyWrapOptions): Promise<PreparedLaunch>;
|
|
697
|
+
spawn(opts: RunnerSpawnOptions): Promise<ITerminalSession>;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* What one model call consumed, as its provider or runner reported it. Shared
|
|
702
|
+
* by the planner's usage line (#49) and per-attempt task usage (#26): a record
|
|
703
|
+
* says nothing about who asked for the call, so either can hold a list of them.
|
|
704
|
+
*
|
|
705
|
+
* Every measure is optional because backends report different subsets. An
|
|
706
|
+
* absent field means "not reported" — never zero — so a total can tell the two
|
|
707
|
+
* apart.
|
|
708
|
+
*/
|
|
709
|
+
interface UsageRecord {
|
|
710
|
+
/** The provider or runner id that reported the call — `openai`, `claude-code`, … */
|
|
711
|
+
source: string;
|
|
712
|
+
model?: string;
|
|
713
|
+
inputTokens?: number;
|
|
714
|
+
outputTokens?: number;
|
|
715
|
+
/** The share of `inputTokens` served from the provider's prompt cache. */
|
|
716
|
+
cachedInputTokens?: number;
|
|
717
|
+
/**
|
|
718
|
+
* Filled only from a provider's or runner's own report, never from a price
|
|
719
|
+
* table or an estimate: prices go stale, and a subscription runner has no
|
|
720
|
+
* per-token price at all. No report means no cost, not a guessed one.
|
|
721
|
+
*/
|
|
722
|
+
reportedCost?: {
|
|
723
|
+
amount: number;
|
|
724
|
+
currency: string;
|
|
725
|
+
};
|
|
726
|
+
/** The model's context window, when the runner itself reports it. */
|
|
727
|
+
contextWindow?: number;
|
|
728
|
+
/** Set when a subagent made the call; its usage still counts toward the total. */
|
|
729
|
+
subagentId?: string;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* A running sum of {@link UsageRecord}s. A measure stays absent until some
|
|
733
|
+
* record reports it. Cost is kept per currency: two runners may bill in
|
|
734
|
+
* different ones, and there is no honest exchange rate to fold them together.
|
|
735
|
+
*/
|
|
736
|
+
interface UsageTotals {
|
|
737
|
+
inputTokens?: number;
|
|
738
|
+
outputTokens?: number;
|
|
739
|
+
cachedInputTokens?: number;
|
|
740
|
+
reportedCost?: Record<string, number>;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* The input side of a call whose provider reports its prompt in parts — the
|
|
744
|
+
* uncached tail, with cache reads and cache writes beside it rather than inside
|
|
745
|
+
* it (Anthropic, and OpenCode after it). The prompt the model saw is all three;
|
|
746
|
+
* only the reads were served from cache, since a write is billed as fresh
|
|
747
|
+
* input. A part left unreported adds nothing, and with no part reported there
|
|
748
|
+
* is no measure at all.
|
|
749
|
+
*/
|
|
750
|
+
declare function partedPromptUsage(parts: {
|
|
751
|
+
uncached?: number;
|
|
752
|
+
cacheRead?: number;
|
|
753
|
+
cacheWrite?: number;
|
|
754
|
+
}): Pick<UsageRecord, 'inputTokens' | 'cachedInputTokens'>;
|
|
755
|
+
declare function addUsage(totals: UsageTotals, record: UsageRecord): UsageTotals;
|
|
756
|
+
/**
|
|
757
|
+
* What the planner has consumed over a session (#49). `totals` includes every
|
|
758
|
+
* `bySubagent` entry. `lastPromptTokens` and `contextWindow` track the
|
|
759
|
+
* planner's own calls only — a subagent runs its own model, whose window says
|
|
760
|
+
* nothing about the planner's.
|
|
761
|
+
*/
|
|
762
|
+
interface PlannerUsage {
|
|
763
|
+
totals: UsageTotals;
|
|
764
|
+
bySubagent?: Record<string, UsageTotals>;
|
|
765
|
+
lastPromptTokens?: number;
|
|
766
|
+
contextWindow?: number;
|
|
767
|
+
}
|
|
768
|
+
declare function addPlannerUsage(usage: PlannerUsage, record: UsageRecord): PlannerUsage;
|
|
769
|
+
/** Whether any measure was reported: a token line of nothing but blanks says nothing. */
|
|
770
|
+
declare function isMeasured(totals: UsageTotals): boolean;
|
|
771
|
+
/** What the token line shows of a ledger — live from its broadcast, or reloaded from the saved one. */
|
|
772
|
+
interface UsageLine {
|
|
773
|
+
totals: UsageTotals;
|
|
774
|
+
bySubagent?: Record<string, UsageTotals>;
|
|
775
|
+
contextFill?: {
|
|
776
|
+
usedTokens: number;
|
|
777
|
+
windowTokens: number;
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
declare function usageLine(usage: PlannerUsage): UsageLine;
|
|
781
|
+
/**
|
|
782
|
+
* The last planner prompt against its window, or undefined while either is
|
|
783
|
+
* unknown. `usedTokens` is the prompt total as reported, cached tokens
|
|
784
|
+
* included: a cached token still occupies the window, so subtracting the
|
|
785
|
+
* cached share would understate how full the context is. A window of 0 is
|
|
786
|
+
* treated as unknown — never guessed.
|
|
787
|
+
*/
|
|
788
|
+
declare function plannerContextFill(usage: PlannerUsage): {
|
|
789
|
+
usedTokens: number;
|
|
790
|
+
windowTokens: number;
|
|
791
|
+
} | undefined;
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* The planner's single approval seam. Every capability that reaches beyond the
|
|
795
|
+
* default read-only, in-workspace envelope — a path outside the workspace root,
|
|
796
|
+
* a shell command outside the auto-allowed set, a URL fetch — routes through
|
|
797
|
+
* one `request()` so the policy has exactly one owner (the same "one repair
|
|
798
|
+
* owner" shape as PlanRepair).
|
|
799
|
+
*
|
|
800
|
+
* Surfaces supply the human channel. VS Code answers with a modal; the web
|
|
801
|
+
* server currently has no prompt UI, so it denies unless the scope was
|
|
802
|
+
* pre-approved through config. Denial is always a visible, actionable tool
|
|
803
|
+
* result — never a silent success.
|
|
804
|
+
*/
|
|
805
|
+
/**
|
|
806
|
+
* `runner_tool` is a task runner's own tool request (ADR-0018, A1): it waits
|
|
807
|
+
* for an answer as long as it takes, and never passes through the planner's
|
|
808
|
+
* policy — the runner's mode already decided it needed asking.
|
|
809
|
+
*/
|
|
810
|
+
type ApprovalKind = 'external_path' | 'shell_command' | 'url_fetch' | 'runner_tool';
|
|
811
|
+
interface ApprovalRequest {
|
|
812
|
+
kind: ApprovalKind;
|
|
813
|
+
/** The concrete thing being asked about: an absolute path, a command line, a URL. */
|
|
814
|
+
subject: string;
|
|
815
|
+
/**
|
|
816
|
+
* What a grant covers. Approving remembers this, not `subject`, so reading a
|
|
817
|
+
* second file from an already-approved directory does not prompt again.
|
|
818
|
+
*/
|
|
819
|
+
scope: string;
|
|
820
|
+
/** One-line context for the prompt. */
|
|
821
|
+
detail?: string;
|
|
822
|
+
/** The task whose runner asked; absent for the planner's own requests. */
|
|
823
|
+
taskId?: string;
|
|
824
|
+
/** "Allow for this task" can be offered: the runner proposed its own session-scoped grant. */
|
|
825
|
+
allowForTask?: boolean;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* An answer, from whoever gives it — a person on any surface, or later the
|
|
829
|
+
* supervisor (#28). `allowForTask` is Allow plus the runner's own grant for
|
|
830
|
+
* the rest of the task; `note` goes back to the agent with a denial.
|
|
831
|
+
*/
|
|
832
|
+
type ApprovalDecision = {
|
|
833
|
+
decision: 'allow';
|
|
834
|
+
} | {
|
|
835
|
+
decision: 'allowForTask';
|
|
836
|
+
} | {
|
|
837
|
+
decision: 'deny';
|
|
838
|
+
note?: string;
|
|
839
|
+
};
|
|
840
|
+
/** What an answer may be given as: a planner prompt's yes/no still is one. */
|
|
841
|
+
type ApprovalAnswer = boolean | ApprovalDecision;
|
|
842
|
+
declare function toApprovalDecision(answer: ApprovalAnswer): ApprovalDecision;
|
|
843
|
+
declare function isGranted(decision: ApprovalDecision): boolean;
|
|
844
|
+
declare function isRunnerApproval(request: ApprovalRequest): boolean;
|
|
845
|
+
interface IApproval {
|
|
846
|
+
request(req: ApprovalRequest): Promise<boolean>;
|
|
847
|
+
}
|
|
848
|
+
/** Denies everything. The safe default when a surface wires no approval channel. */
|
|
849
|
+
declare const DENY_ALL: IApproval;
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* The harness-planner transport contract (ADR-0009).
|
|
853
|
+
*
|
|
854
|
+
* One adapter per coding agent, each speaking that agent's own programmatic
|
|
855
|
+
* protocol and normalizing it to the event union below. Everything above this
|
|
856
|
+
* line — reply classification, the repair loop, plan validation, the four
|
|
857
|
+
* surfaces — is already provider-agnostic, so an adapter is the entire cost of
|
|
858
|
+
* teaching Ordewell to plan with another agent.
|
|
859
|
+
*/
|
|
860
|
+
/**
|
|
861
|
+
* One normalized event from a running agent turn. Deliberately smaller than
|
|
862
|
+
* any single agent's native protocol: this is the intersection Ordewell can act
|
|
863
|
+
* on, not a lossless re-encoding. Event fidelity differs by agent — `thinking`
|
|
864
|
+
* is rich on Claude Code and absent elsewhere — so consumers must tolerate a
|
|
865
|
+
* turn that emits nothing but `assistant_text` and `turn_end`.
|
|
866
|
+
*/
|
|
867
|
+
type AgentEvent =
|
|
868
|
+
/**
|
|
869
|
+
* A complete run of the assistant's reply. Concatenated in order to form the
|
|
870
|
+
* turn's text. When the same run already streamed as `assistant_text_delta`,
|
|
871
|
+
* this is the authoritative copy of it — it replaces the deltas, it is not
|
|
872
|
+
* appended after them.
|
|
873
|
+
*/
|
|
874
|
+
{
|
|
875
|
+
type: 'assistant_text';
|
|
876
|
+
text: string;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* An incremental piece of the assistant's reply, for agents that stream
|
|
880
|
+
* partial messages. The planner's own text only: a subagent's words never
|
|
881
|
+
* arrive here, so they can never become the reply.
|
|
882
|
+
*/
|
|
883
|
+
| {
|
|
884
|
+
type: 'assistant_text_delta';
|
|
885
|
+
text: string;
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Reasoning the agent chose to expose. Never contributes to the reply text.
|
|
889
|
+
* Like `assistant_text`, it supersedes deltas already streamed for it.
|
|
890
|
+
*/
|
|
891
|
+
| {
|
|
892
|
+
type: 'thinking';
|
|
893
|
+
text: string;
|
|
894
|
+
subagentId?: string;
|
|
895
|
+
} | {
|
|
896
|
+
type: 'thinking_delta';
|
|
897
|
+
text: string;
|
|
898
|
+
subagentId?: string;
|
|
899
|
+
}
|
|
900
|
+
/** `subagentId` marks a call made inside a subagent rather than by the planner itself. */
|
|
901
|
+
| {
|
|
902
|
+
type: 'tool_call';
|
|
903
|
+
id: string;
|
|
904
|
+
name: string;
|
|
905
|
+
args: Record<string, unknown>;
|
|
906
|
+
subagentId?: string;
|
|
907
|
+
} | {
|
|
908
|
+
type: 'tool_result';
|
|
909
|
+
id: string;
|
|
910
|
+
name: string;
|
|
911
|
+
output: string;
|
|
912
|
+
success: boolean;
|
|
913
|
+
subagentId?: string;
|
|
914
|
+
}
|
|
915
|
+
/** One model call's usage, as the agent reported it — never estimated. */
|
|
916
|
+
| {
|
|
917
|
+
type: 'usage';
|
|
918
|
+
record: UsageRecord;
|
|
919
|
+
}
|
|
920
|
+
/** The agent delegated `brief` to a subagent, whose events carry `subagentId` until it finishes. */
|
|
921
|
+
| {
|
|
922
|
+
type: 'subagent_started';
|
|
923
|
+
subagentId: string;
|
|
924
|
+
brief: string;
|
|
925
|
+
model?: string;
|
|
926
|
+
} | {
|
|
927
|
+
type: 'subagent_finished';
|
|
928
|
+
subagentId: string;
|
|
929
|
+
outcome: SubagentOutcome;
|
|
930
|
+
digest: string;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* The agent asked to do something its mode does not cover. A planner always
|
|
934
|
+
* auto-denies it (T1) — a planner that can mutate is not a planner — and the
|
|
935
|
+
* adapter answers so the turn does not hang. A task's request stays open
|
|
936
|
+
* until {@link TaskModeAgentAdapter.answerPermission} (ADR-0018, A1).
|
|
937
|
+
*
|
|
938
|
+
* `input` and `suggestions` are the raw request; `suggestions` are the
|
|
939
|
+
* agent's own session-scoped grants, what "Allow for this task" answers with.
|
|
940
|
+
*/
|
|
941
|
+
| {
|
|
942
|
+
type: 'permission_request';
|
|
943
|
+
id: string;
|
|
944
|
+
name: string;
|
|
945
|
+
detail: string;
|
|
946
|
+
input?: Record<string, unknown>;
|
|
947
|
+
suggestions?: unknown[];
|
|
948
|
+
toolUseId?: string;
|
|
949
|
+
}
|
|
950
|
+
/** The agent withdrew an open request — an interrupt cancels the call it was for. It takes no answer now. */
|
|
951
|
+
| {
|
|
952
|
+
type: 'permission_cancelled';
|
|
953
|
+
id: string;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* The agent delegated work to a subagent it left running in the background,
|
|
957
|
+
* and may end its turn before that work reports. Ordewell's conversation is
|
|
958
|
+
* request/response: a turn that ends hands control back to the user, and
|
|
959
|
+
* anything the agent says afterwards arrives with no turn open and is lost.
|
|
960
|
+
* Naming the launch is what lets the service ask for the results in time.
|
|
961
|
+
*/
|
|
962
|
+
| {
|
|
963
|
+
type: 'background_agent';
|
|
964
|
+
id: string;
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* The agent finished its turn and is waiting for the next user message.
|
|
968
|
+
* `interrupted` marks a turn cut short by {@link TaskModeAgentAdapter.interrupt}
|
|
969
|
+
* rather than one the agent chose to end.
|
|
970
|
+
*/
|
|
971
|
+
| {
|
|
972
|
+
type: 'turn_end';
|
|
973
|
+
interrupted?: boolean;
|
|
974
|
+
}
|
|
975
|
+
/** The turn failed. Carries the agent's own words — never a Ordewell paraphrase. */
|
|
976
|
+
| {
|
|
977
|
+
type: 'error';
|
|
978
|
+
message: string;
|
|
979
|
+
};
|
|
980
|
+
interface AgentStartCommon {
|
|
981
|
+
/** Workspace root. The agent works from here and, in read-only mode, cannot leave it. */
|
|
982
|
+
cwd: string;
|
|
983
|
+
/** Model id from the runner's own discovery catalog. Omitted means the agent's default. */
|
|
984
|
+
model?: string;
|
|
985
|
+
/**
|
|
986
|
+
* The agent's own session id from a previous run. For the planner a hint
|
|
987
|
+
* only: Ordewell's transcript is the source of truth (T4), so a failed resume
|
|
988
|
+
* degrades to a fresh session seeded from the stored history, not an error.
|
|
989
|
+
*/
|
|
990
|
+
resumeSessionId?: string;
|
|
991
|
+
}
|
|
992
|
+
/** The read-only planner (ADR-0008/0009). The only start `CliAgentAiService` can express. */
|
|
993
|
+
interface PlannerStartOptions extends AgentStartCommon {
|
|
994
|
+
kind: 'planner';
|
|
995
|
+
/** The planner system prompt, in its harness variant. */
|
|
996
|
+
systemPrompt: string;
|
|
997
|
+
/** Variant / reasoning effort id from that model's `variants` list. */
|
|
998
|
+
effort?: string;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* What a runner manifest says the task's mode and effort mean (ADR-0001),
|
|
1002
|
+
* resolved by the same code terminal tasks use — see `resolveTaskRunnerFlags`.
|
|
1003
|
+
* The adapter adds only its protocol flags around these.
|
|
1004
|
+
*/
|
|
1005
|
+
interface TaskRunnerFlags {
|
|
1006
|
+
/** The runner's own permission-mode value for the task's mode. */
|
|
1007
|
+
permissionMode: string;
|
|
1008
|
+
/** Thinking/effort arguments, already split into argv entries. */
|
|
1009
|
+
effortArgs: string[];
|
|
1010
|
+
}
|
|
1011
|
+
/** A plan task driven over the runner's programmatic protocol (ADR-0018, C1). */
|
|
1012
|
+
interface TaskStartOptions extends AgentStartCommon {
|
|
1013
|
+
kind: 'task';
|
|
1014
|
+
/** The task's runner mode id, as the plan names it. */
|
|
1015
|
+
mode: string;
|
|
1016
|
+
flags: TaskRunnerFlags;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* The explicit start switch. Discriminated so that a read-only planner and a
|
|
1020
|
+
* mutating task can never be confused by a missing field: every caller names
|
|
1021
|
+
* which one it is starting.
|
|
1022
|
+
*/
|
|
1023
|
+
type AgentStartOptions = PlannerStartOptions | TaskStartOptions;
|
|
1024
|
+
/** A runner asked to start in task mode that has no task-mode connector yet. */
|
|
1025
|
+
declare class TaskModeUnsupportedError extends Error {
|
|
1026
|
+
readonly runner: string;
|
|
1027
|
+
constructor(runner: string);
|
|
1028
|
+
}
|
|
1029
|
+
interface AgentAdapter {
|
|
1030
|
+
/** The runner id this adapter drives — `claude-code`, `codex`, `opencode`. */
|
|
1031
|
+
readonly agentId: string;
|
|
1032
|
+
/** Spawn the agent — read-only for a planner, in the task's mode for a task — ready to receive messages. */
|
|
1033
|
+
start(opts: AgentStartOptions): Promise<void>;
|
|
1034
|
+
/**
|
|
1035
|
+
* Send one user message and stream the turn's events until it ends. Resolves
|
|
1036
|
+
* when the agent yields the floor; rejects only when the transport itself
|
|
1037
|
+
* failed in a way no `error` event could describe.
|
|
1038
|
+
*
|
|
1039
|
+
* `onActivity`, when given, fires on raw transport traffic — every stdio
|
|
1040
|
+
* line or stream chunk the process produces — independent of whether that
|
|
1041
|
+
* traffic becomes an `AgentEvent`. An adapter may legitimately emit nothing
|
|
1042
|
+
* for long stretches (a subagent's filtered output, most often); a caller
|
|
1043
|
+
* using presence-of-events as a liveness signal would read that silence as
|
|
1044
|
+
* a hang. `onActivity` is the seam that keeps liveness detection from being
|
|
1045
|
+
* coupled to what each adapter chooses to surface.
|
|
1046
|
+
*/
|
|
1047
|
+
send(message: string, onEvent: (event: AgentEvent) => void, signal?: AbortSignal, onActivity?: () => void): Promise<void>;
|
|
1048
|
+
/** The agent's native session id once it has announced one. Resumption hint only. */
|
|
1049
|
+
nativeSessionId(): string | null;
|
|
1050
|
+
/** Kill the process and release its resources. Idempotent. */
|
|
1051
|
+
dispose(): void;
|
|
1052
|
+
}
|
|
1053
|
+
/** What an adapter adds to run a task rather than a planner (ADR-0018). */
|
|
1054
|
+
interface TaskModeAgentAdapter extends AgentAdapter {
|
|
1055
|
+
/**
|
|
1056
|
+
* Ask the running turn to stop, keeping the process and its session. Resolves
|
|
1057
|
+
* true once the agent acknowledged it; the turn then ends with
|
|
1058
|
+
* `turn_end { interrupted: true }`. False means the agent did not answer
|
|
1059
|
+
* within `timeoutMs`, and the caller must fall back to killing it.
|
|
1060
|
+
*/
|
|
1061
|
+
interrupt(timeoutMs: number): Promise<boolean>;
|
|
1062
|
+
/** Registers a listener for the process ending, for any reason. Fires at most once. */
|
|
1063
|
+
onProcessExit(listener: (code: number) => void): void;
|
|
1064
|
+
/**
|
|
1065
|
+
* Answer an open `permission_request`. False when the id is not open — it
|
|
1066
|
+
* was answered, cancelled, or never asked.
|
|
1067
|
+
*/
|
|
1068
|
+
answerPermission(id: string, decision: ApprovalDecision): boolean;
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* The single injected boundary between Ordewell and the operating system —
|
|
1072
|
+
* the same pattern `HeadlessRunnerDeps` uses for task execution. Tests feed
|
|
1073
|
+
* recorded agent output through `spawn` (and, for HTTP-transport agents,
|
|
1074
|
+
* `fetch`) so one test exercises adapter parsing, event mapping, reply
|
|
1075
|
+
* classification and the repair loop as a single observable behavior.
|
|
1076
|
+
*/
|
|
1077
|
+
interface AgentProcessDeps {
|
|
1078
|
+
spawn: SpawnFn;
|
|
1079
|
+
fetch: typeof globalThis.fetch;
|
|
1080
|
+
/** Resolves the PATH agents are spawned under. Defaults to the augmented PATH. */
|
|
1081
|
+
resolvePath?: () => Promise<string>;
|
|
1082
|
+
/** Host platform. Defaults to the real one; injected so OS-specific behavior is testable anywhere. */
|
|
1083
|
+
platform?: NodeJS.Platform;
|
|
1084
|
+
/** True when `workspace` names an existing directory. Defaults to a real filesystem check. */
|
|
1085
|
+
isDirectory?: (workspace: string) => boolean;
|
|
1086
|
+
/** True when `candidate` names an existing, spawnable file. Defaults to a real filesystem check. */
|
|
1087
|
+
exists?: (candidate: string) => boolean;
|
|
1088
|
+
/** The workspace's own variables for a cwd (ADR-0016). Defaults to {@link resolveWorkspaceEnv}. */
|
|
1089
|
+
workspaceEnv?: (cwd: string) => Promise<Record<string, string>>;
|
|
1090
|
+
}
|
|
1091
|
+
/** Builds the adapter for one runner id, or null when that runner cannot plan. */
|
|
1092
|
+
type AgentAdapterFactory = (runner: string, deps: AgentProcessDeps) => AgentAdapter | null;
|
|
1093
|
+
/**
|
|
1094
|
+
* Split a stream of chunks into complete lines. Every agent transport here is
|
|
1095
|
+
* newline-delimited JSON of some shape, and a chunk boundary lands mid-object
|
|
1096
|
+
* often enough that parsing per-chunk silently drops events.
|
|
1097
|
+
*/
|
|
1098
|
+
declare class LineBuffer {
|
|
1099
|
+
private buffer;
|
|
1100
|
+
push(chunk: string, onLine: (line: string) => void): void;
|
|
1101
|
+
/** Anything left unterminated when the stream closed. */
|
|
1102
|
+
flush(): string;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
interface RunnerPluginManifest {
|
|
1106
|
+
name: string;
|
|
1107
|
+
displayName: string;
|
|
1108
|
+
description: string;
|
|
1109
|
+
version: string;
|
|
1110
|
+
author?: string;
|
|
1111
|
+
homepage?: string;
|
|
1112
|
+
runner: PluginRunnerDef;
|
|
1113
|
+
features: PluginFeatures;
|
|
1114
|
+
modelDiscovery: PluginModelDiscovery;
|
|
1115
|
+
contextFile?: string;
|
|
1116
|
+
contextFileAltPath?: string;
|
|
1117
|
+
modes?: PluginMode[];
|
|
1118
|
+
}
|
|
1119
|
+
interface PluginRunnerDef {
|
|
1120
|
+
command: string;
|
|
1121
|
+
argsTemplate: string[];
|
|
1122
|
+
promptInArgs: boolean;
|
|
1123
|
+
env?: Record<string, string>;
|
|
1124
|
+
/** When true, the runner requires a PTY. HeadlessRunner wraps with `script` to allocate one. */
|
|
1125
|
+
requiresTty?: boolean;
|
|
1126
|
+
/**
|
|
1127
|
+
* True when this runner's interactive prompt flag (e.g. opencode's
|
|
1128
|
+
* `--prompt`) only pre-fills its TUI's composer instead of running it, so a
|
|
1129
|
+
* surface driving that TUI unattended must send an explicit Enter after
|
|
1130
|
+
* launch. Only takes effect while the resolved invocation is interactive —
|
|
1131
|
+
* see `RunnerInvocation.submitPromptKey`.
|
|
1132
|
+
*/
|
|
1133
|
+
submitPromptKey?: boolean;
|
|
1134
|
+
/**
|
|
1135
|
+
* Screens the agent can stop on before starting the task, waiting for a
|
|
1136
|
+
* human — a folder-trust or permission-mode confirmation. Ordewell never
|
|
1137
|
+
* answers one; seeing it, the task's user is told where to.
|
|
1138
|
+
*/
|
|
1139
|
+
blockingPrompts?: BlockingPrompt[];
|
|
1140
|
+
}
|
|
1141
|
+
interface BlockingPrompt {
|
|
1142
|
+
/** Text the prompt shows; matched ignoring case and whitespace. */
|
|
1143
|
+
phrase: string;
|
|
1144
|
+
/** Completes "<runner> is asking …", e.g. "whether to trust this folder". */
|
|
1145
|
+
asks: string;
|
|
1146
|
+
}
|
|
1147
|
+
interface PluginFeatures {
|
|
1148
|
+
modelSelection: boolean;
|
|
1149
|
+
thinkingEffort: boolean;
|
|
1150
|
+
planMode: boolean;
|
|
1151
|
+
planModeFlag: string;
|
|
1152
|
+
buildModeFlag?: string;
|
|
1153
|
+
/** Flag appended when headless mode is on, so the agent never prompts for permission (e.g. Claude's --dangerously-skip-permissions). */
|
|
1154
|
+
headlessFlag?: string;
|
|
1155
|
+
thinkingFlag?: string;
|
|
1156
|
+
thinkingValueEnabled?: string;
|
|
1157
|
+
thinkingValueDisabled?: string;
|
|
1158
|
+
thinkingValueAdaptive?: string;
|
|
1159
|
+
/** Maps mode IDs to the CLI --permission-mode value. Used by {{feature:permissionModeVal}}. */
|
|
1160
|
+
permissionModeValues?: Record<string, string>;
|
|
1161
|
+
}
|
|
1162
|
+
type PluginParser = 'claude-help' | 'opencode-models' | 'opencode-models-verbose' | 'anthropic-models' | 'line-by-line' | 'json' | 'json-table';
|
|
1163
|
+
interface DiscoveryCommand {
|
|
1164
|
+
command: string;
|
|
1165
|
+
args: string[];
|
|
1166
|
+
parser?: PluginParser;
|
|
1167
|
+
}
|
|
1168
|
+
type ApiAuthMethod = {
|
|
1169
|
+
type: 'env';
|
|
1170
|
+
varName: string;
|
|
1171
|
+
header: string;
|
|
1172
|
+
prefix?: string;
|
|
1173
|
+
} | {
|
|
1174
|
+
type: 'file';
|
|
1175
|
+
path: string;
|
|
1176
|
+
jsonPath: string;
|
|
1177
|
+
header: string;
|
|
1178
|
+
prefix?: string;
|
|
1179
|
+
};
|
|
1180
|
+
interface ApiDiscoveryConfig {
|
|
1181
|
+
url: string;
|
|
1182
|
+
headers?: Record<string, string>;
|
|
1183
|
+
auth: ApiAuthMethod[];
|
|
1184
|
+
parser: PluginParser;
|
|
1185
|
+
}
|
|
1186
|
+
interface PluginModelDiscovery {
|
|
1187
|
+
method: 'command' | 'hardcoded';
|
|
1188
|
+
command?: string;
|
|
1189
|
+
args?: string[];
|
|
1190
|
+
parser?: PluginParser;
|
|
1191
|
+
jsonPath?: string;
|
|
1192
|
+
/**
|
|
1193
|
+
* Stdio JSON-RPC discovery (Codex `app-server`): spawn the command, send
|
|
1194
|
+
* `initialize` then `model/list`, and read the catalog from the response.
|
|
1195
|
+
* Tried BEFORE apiDiscovery and command discovery. When the call fails,
|
|
1196
|
+
* `cacheFile` (the runner's own on-disk catalog cache, `~` expanded) is
|
|
1197
|
+
* read before falling through to the remaining discovery methods.
|
|
1198
|
+
*/
|
|
1199
|
+
appServer?: {
|
|
1200
|
+
command: string;
|
|
1201
|
+
args: string[];
|
|
1202
|
+
cacheFile?: string;
|
|
1203
|
+
};
|
|
1204
|
+
/**
|
|
1205
|
+
* Optional last-resort list for user plugins whose CLI cannot enumerate
|
|
1206
|
+
* models. Used only when command discovery fails entirely or the CLI is
|
|
1207
|
+
* unavailable. Built-in manifests must NOT use this: anything listed here is
|
|
1208
|
+
* shown to the user as available even when it isn't.
|
|
1209
|
+
*/
|
|
1210
|
+
fallbackModels?: {
|
|
1211
|
+
modelId: string;
|
|
1212
|
+
modelLabel: string;
|
|
1213
|
+
}[];
|
|
1214
|
+
/**
|
|
1215
|
+
* Stable `--model` aliases that the runner's CLI always accepts but its help
|
|
1216
|
+
* text may omit (e.g. Claude's 'haiku'). Merged into successful discovery
|
|
1217
|
+
* results to fill gaps — discovered models take precedence, missing aliases
|
|
1218
|
+
* are appended — and used as the last resort when discovery fails entirely.
|
|
1219
|
+
* Unlike `fallbackModels`, entries must be stable CLI-accepted aliases
|
|
1220
|
+
* (contracts that always resolve), not arbitrary model IDs.
|
|
1221
|
+
*/
|
|
1222
|
+
canonicalAliases?: {
|
|
1223
|
+
modelId: string;
|
|
1224
|
+
modelLabel: string;
|
|
1225
|
+
}[];
|
|
1226
|
+
/**
|
|
1227
|
+
* HTTP API discovery — tried BEFORE command discovery. When the runner's CLI
|
|
1228
|
+
* has no model-listing subcommand (Claude Code), an API endpoint can serve as
|
|
1229
|
+
* the authoritative source. Auth methods are tried in order; the first that
|
|
1230
|
+
* yields a token is used. If no auth method yields a token or the request
|
|
1231
|
+
* fails, discovery falls through to `discoveryCommands` + `canonicalAliases`.
|
|
1232
|
+
*/
|
|
1233
|
+
apiDiscovery?: ApiDiscoveryConfig;
|
|
1234
|
+
preferredPatterns?: {
|
|
1235
|
+
id: string;
|
|
1236
|
+
label: string;
|
|
1237
|
+
}[];
|
|
1238
|
+
variants?: {
|
|
1239
|
+
id: string;
|
|
1240
|
+
label: string;
|
|
1241
|
+
}[];
|
|
1242
|
+
discoveryCommands?: DiscoveryCommand[];
|
|
1243
|
+
}
|
|
1244
|
+
interface PluginMode {
|
|
1245
|
+
id: string;
|
|
1246
|
+
label: string;
|
|
1247
|
+
description: string;
|
|
1248
|
+
/** CLI value passed to the runner's permission/mode flag. Defaults to id if omitted. */
|
|
1249
|
+
cliValue?: string;
|
|
1250
|
+
/** Marks this mode as the runner's most permissive mode — the resolved default when autonomous mode is ON. */
|
|
1251
|
+
autonomous?: boolean;
|
|
1252
|
+
/** Marks this mode as the runner's conservative build mode — the resolved default when autonomous mode is OFF. */
|
|
1253
|
+
safe?: boolean;
|
|
1254
|
+
}
|
|
1255
|
+
interface PluginEntry {
|
|
1256
|
+
manifest: RunnerPluginManifest;
|
|
1257
|
+
source: 'builtin' | 'user';
|
|
1258
|
+
installPath?: string;
|
|
1259
|
+
}
|
|
1260
|
+
interface ResolveContext {
|
|
1261
|
+
prompt: string;
|
|
1262
|
+
model?: string;
|
|
1263
|
+
thinkingEffort?: string;
|
|
1264
|
+
/** All variant ids the assigned model offers — lets {{opencodeVariantConfig}} disable the non-chosen ones. */
|
|
1265
|
+
modelVariants?: string[];
|
|
1266
|
+
mode: string;
|
|
1267
|
+
/**
|
|
1268
|
+
* Autonomy axis: when true, resolve {{if headless}} blocks and the
|
|
1269
|
+
* {{feature:headless}} token so the agent never stops to ask for permission.
|
|
1270
|
+
* True for every orchestrated task run — nobody is watching the terminal on
|
|
1271
|
+
* Ordewell's behalf — independently of the session *shape* below.
|
|
1272
|
+
*/
|
|
1273
|
+
headless?: boolean;
|
|
1274
|
+
/**
|
|
1275
|
+
* Session-shape axis: true when the runner is launched onto a real TTY the
|
|
1276
|
+
* user can attach to (a tmux window, a VS Code pseudoterminal), so the
|
|
1277
|
+
* runner's own TUI should come up rather than its non-interactive
|
|
1278
|
+
* subcommand. Defaults to `!headless` for callers that predate the split.
|
|
1279
|
+
*/
|
|
1280
|
+
interactive?: boolean;
|
|
1281
|
+
/** The task's working directory — needed by runners whose autonomy flags name a path. */
|
|
1282
|
+
cwd?: string;
|
|
1283
|
+
}
|
|
1284
|
+
interface RunnerInvocation {
|
|
1285
|
+
command: string;
|
|
1286
|
+
args: string[];
|
|
1287
|
+
env: Record<string, string>;
|
|
1288
|
+
promptInArgs: boolean;
|
|
1289
|
+
/** True when a surface running this invocation on a real TTY must send an explicit Enter once the process starts. */
|
|
1290
|
+
submitPromptKey: boolean;
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Persistent storage seam for plugin manifests. The RunnerRegistry delegates
|
|
1294
|
+
* all filesystem operations to this interface so the plugin lifecycle is
|
|
1295
|
+
* testable without real I/O.
|
|
1296
|
+
*/
|
|
1297
|
+
interface IPluginStore {
|
|
1298
|
+
/** Path to the user plugins directory (~/.ordewell/plugins/). */
|
|
1299
|
+
getUserPluginsDir(): string;
|
|
1300
|
+
/** List subdirectory names inside the user plugins directory. */
|
|
1301
|
+
listUserPluginDirs(): string[];
|
|
1302
|
+
/** List entry names directly inside a directory. Returns [] when unreadable. */
|
|
1303
|
+
listDir(dir: string): string[];
|
|
1304
|
+
/** Read and parse a manifest.json from pluginDir. Returns null on failure. */
|
|
1305
|
+
loadManifest(pluginDir: string): RunnerPluginManifest | null;
|
|
1306
|
+
/** Recursively copy sourceDir to destDir. */
|
|
1307
|
+
copyDir(sourceDir: string, destDir: string): void;
|
|
1308
|
+
/** Recursively remove a directory. */
|
|
1309
|
+
removeDir(dir: string): void;
|
|
1310
|
+
/** Ensure a directory exists (mkdir -p). */
|
|
1311
|
+
ensureDir(dir: string): void;
|
|
1312
|
+
/** Write a text file. */
|
|
1313
|
+
writeFile(filePath: string, content: string): void;
|
|
1314
|
+
/** Read a UTF-8 text file. Returns null on ENOENT or read error. */
|
|
1315
|
+
readFile(filePath: string): string | null;
|
|
1316
|
+
/** True if path exists and is a directory. */
|
|
1317
|
+
dirExists(path: string): boolean;
|
|
1318
|
+
/** True if path exists. */
|
|
1319
|
+
exists(path: string): boolean;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Decides whether one out-of-envelope capability may run, and remembers the
|
|
1324
|
+
* answer for the rest of the session.
|
|
1325
|
+
*
|
|
1326
|
+
* Grants are keyed on {@link ApprovalRequest.scope}, never on the concrete
|
|
1327
|
+
* subject: approving a read of `/tmp/foo/a.log` grants `/tmp/foo/*`, and
|
|
1328
|
+
* approving `az group list` grants `az group`. Without that, a planner doing
|
|
1329
|
+
* real research would prompt on every single call and the feature would be
|
|
1330
|
+
* unusable.
|
|
1331
|
+
*
|
|
1332
|
+
* `mode` is the policy floor:
|
|
1333
|
+
* ask consult the human channel; no channel means deny (headless, web)
|
|
1334
|
+
* allow grant everything the tier system did not already refuse
|
|
1335
|
+
* deny grant nothing beyond `preApproved`
|
|
1336
|
+
*
|
|
1337
|
+
* Note the ordering: `preApproved` is honored under every mode including
|
|
1338
|
+
* `deny`, because it is an explicit operator decision rather than a default.
|
|
1339
|
+
*/
|
|
1340
|
+
type ApprovalMode = 'ask' | 'allow' | 'deny';
|
|
1341
|
+
interface ApprovalPolicyOptions {
|
|
1342
|
+
mode?: ApprovalMode;
|
|
1343
|
+
/** Scopes granted up front from config. A trailing `*` matches by prefix. */
|
|
1344
|
+
preApproved?: string[];
|
|
1345
|
+
/** The human channel. Absent means there is nobody to ask. */
|
|
1346
|
+
ask?: (req: ApprovalRequest) => Promise<boolean>;
|
|
1347
|
+
/** Called whenever a decision is reached, for surfacing in a UI or a log. */
|
|
1348
|
+
onDecision?: (req: ApprovalRequest, granted: boolean, source: ApprovalSource) => void;
|
|
1349
|
+
}
|
|
1350
|
+
type ApprovalSource = 'pre-approved' | 'remembered' | 'mode' | 'asked' | 'no-channel';
|
|
1351
|
+
declare class ApprovalPolicy implements IApproval {
|
|
1352
|
+
private readonly mode;
|
|
1353
|
+
private readonly preApproved;
|
|
1354
|
+
private readonly asker?;
|
|
1355
|
+
private readonly onDecision?;
|
|
1356
|
+
private readonly granted;
|
|
1357
|
+
private readonly refused;
|
|
1358
|
+
/** One in-flight ask per scope: a parallel tool round must not prompt twice for the same thing. */
|
|
1359
|
+
private readonly inFlight;
|
|
1360
|
+
private generation;
|
|
1361
|
+
constructor(opts?: ApprovalPolicyOptions);
|
|
1362
|
+
request(req: ApprovalRequest): Promise<boolean>;
|
|
1363
|
+
/** Scopes the user has granted this session — for display and for persistence. */
|
|
1364
|
+
grantedScopes(): string[];
|
|
1365
|
+
/** Drop every session-scoped decision. Called on session reset. */
|
|
1366
|
+
reset(): void;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
interface CatalogModel {
|
|
1370
|
+
id: string;
|
|
1371
|
+
name: string;
|
|
1372
|
+
description: string;
|
|
1373
|
+
pricing: {
|
|
1374
|
+
prompt: string;
|
|
1375
|
+
completion: string;
|
|
1376
|
+
};
|
|
1377
|
+
contextLength: number;
|
|
1378
|
+
}
|
|
1379
|
+
declare class ModelCatalog {
|
|
1380
|
+
static fetchModels(apiKey: string, baseUrl?: string, fetchImpl?: typeof fetch): Promise<CatalogModel[]>;
|
|
1381
|
+
/**
|
|
1382
|
+
* Delete the on-disk catalog cache for a base URL so the next fetch re-runs.
|
|
1383
|
+
* Used by the resolver's `invalidate()` in production (no injected fetch);
|
|
1384
|
+
* best-effort — a missing file or unreadable dir is a no-op.
|
|
1385
|
+
*/
|
|
1386
|
+
static clearCache(baseUrl?: string): void;
|
|
1387
|
+
private static readCache;
|
|
1388
|
+
private static writeCache;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
interface ModelShortcut {
|
|
1392
|
+
label: string;
|
|
1393
|
+
id: string;
|
|
1394
|
+
provider: string;
|
|
1395
|
+
description: string;
|
|
1396
|
+
pricing?: string;
|
|
1397
|
+
}
|
|
1398
|
+
declare const ORCHESTRATOR_SHORTCUTS: ModelShortcut[];
|
|
1399
|
+
declare function resolveModelShortcut(input: string, shortcuts: ModelShortcut[]): string | null;
|
|
1400
|
+
/**
|
|
1401
|
+
* Resolves a value to a model id ONLY when it is in the supplied catalog
|
|
1402
|
+
* option list — either directly or via a shortcut label. Free-typed, unknown,
|
|
1403
|
+
* or not-currently-available values return null, so callers never store an id
|
|
1404
|
+
* the user couldn't have selected from the list. Keeps model-setting list-only.
|
|
1405
|
+
*/
|
|
1406
|
+
declare function knownModelId(value: string, optionIds: string[], shortcuts: ModelShortcut[]): string | null;
|
|
1407
|
+
|
|
1408
|
+
type ProviderModelLists = Record<string, string[]>;
|
|
1409
|
+
interface OrchestratorOption {
|
|
1410
|
+
id: string;
|
|
1411
|
+
label: string;
|
|
1412
|
+
provider: string;
|
|
1413
|
+
apiProvider: AiProvider;
|
|
1414
|
+
description?: string;
|
|
1415
|
+
pricing?: string;
|
|
1416
|
+
/** The model's context window when the catalog reports one (#49). */
|
|
1417
|
+
contextWindow?: number;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
interface FetchAllProviderModelsOptions {
|
|
1421
|
+
apiKeys: Record<string, string>;
|
|
1422
|
+
baseUrls: Record<string, string>;
|
|
1423
|
+
fetchImpl?: typeof fetch;
|
|
1424
|
+
}
|
|
1425
|
+
type AllProviderModels = Record<string, CatalogModel[]>;
|
|
1426
|
+
/**
|
|
1427
|
+
* Result of a picker-catalog fetch fan-out: the per-provider model lists plus
|
|
1428
|
+
* the per-provider failures. `errors` is keyed by provider id and holds the
|
|
1429
|
+
* failure message for any provider whose catalog fetch rejected — the seam the
|
|
1430
|
+
* surfaces (CLI, VS Code) use to flag "this configured provider didn't work"
|
|
1431
|
+
* rather than silently showing a short list.
|
|
1432
|
+
*/
|
|
1433
|
+
interface ProviderModelsResult {
|
|
1434
|
+
models: AllProviderModels;
|
|
1435
|
+
errors: Record<string, string>;
|
|
1436
|
+
}
|
|
1437
|
+
/** The provider config fields the discovery fan-out needs. */
|
|
1438
|
+
interface ProviderCredentialSource {
|
|
1439
|
+
getProviderApiKey(provider: AiProvider): string;
|
|
1440
|
+
getProviderBaseUrl(provider: AiProvider): string;
|
|
1441
|
+
openaiCompatibleBaseUrl: string;
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Collect the API keys and base URLs the picker fan-out should probe, applying
|
|
1445
|
+
* the single "configured" policy shared by every surface (CLI + VS Code):
|
|
1446
|
+
* - a preset is discovered only when it has an API key (OpenRouter included —
|
|
1447
|
+
* its public catalog is not probed keyless, matching the product rule that
|
|
1448
|
+
* only key-configured providers appear);
|
|
1449
|
+
* - `openai_compatible` is discovered only when an explicit endpoint is set
|
|
1450
|
+
* (keyless local servers like ollama / LM Studio).
|
|
1451
|
+
* Base URLs are handed through only for providers that pass the gate, so the
|
|
1452
|
+
* fan-out never touches an unconfigured third-party endpoint.
|
|
1453
|
+
*/
|
|
1454
|
+
declare function collectProviderCredentials(config: ProviderCredentialSource): {
|
|
1455
|
+
apiKeys: Record<string, string>;
|
|
1456
|
+
baseUrls: Record<string, string>;
|
|
1457
|
+
};
|
|
1458
|
+
declare function fetchAllProviderModels(opts: FetchAllProviderModelsOptions): Promise<ProviderModelsResult>;
|
|
1459
|
+
declare function resolveProvider(modelId: string, providerModelLists: Record<string, string[]>): AiProvider | null;
|
|
1460
|
+
declare function toOrchestratorOptions(providerModels: AllProviderModels, shortcuts: ModelShortcut[]): OrchestratorOption[];
|
|
1461
|
+
|
|
1462
|
+
/**
|
|
1463
|
+
* Who plans. Mostly LLM vendors reached over HTTP; the last three are *harness
|
|
1464
|
+
* planners* (ADR-0009) — a coding agent CLI already installed on the machine,
|
|
1465
|
+
* driven as the planner over its own programmatic transport and authenticated
|
|
1466
|
+
* by the subscription the user already holds. They are runners in the provider
|
|
1467
|
+
* axis, deliberately: "what plans for me?" is one question, and it belongs in
|
|
1468
|
+
* one setting. `isCliProvider` is the single guard that tells the two kinds
|
|
1469
|
+
* apart.
|
|
1470
|
+
*/
|
|
1471
|
+
type AiProvider = 'google' | 'openrouter' | 'openai_compatible' | 'openai' | 'xai' | 'groq' | 'deepseek' | 'together' | 'mistral' | 'anthropic' | 'fireworks' | 'perplexity' | 'zhipu' | 'kimi' | 'cerebras' | 'deepinfra' | 'doubao' | 'qwen' | 'hunyuan' | 'baichuan' | 'minimax' | 'yi' | 'stepfun' | 'siliconflow' | 'cohere' | 'novita' | 'claude-code' | 'codex' | 'opencode';
|
|
1472
|
+
interface IConfig {
|
|
1473
|
+
aiProvider: AiProvider;
|
|
1474
|
+
apiKey: string;
|
|
1475
|
+
planningModel: string;
|
|
1476
|
+
enabledRunners: string[];
|
|
1477
|
+
maxParallelSessions: number;
|
|
1478
|
+
researchEnabled: boolean;
|
|
1479
|
+
researchMaxSteps: number;
|
|
1480
|
+
researchMaxFileSize: number;
|
|
1481
|
+
openAiBaseUrl: string;
|
|
1482
|
+
openAiApiKey: string;
|
|
1483
|
+
/** Provider keys + base URL the ModelResolver uses to fetch the picker catalogs. */
|
|
1484
|
+
openrouterKey: string;
|
|
1485
|
+
geminiKey: string;
|
|
1486
|
+
geminiBaseUrl?: string;
|
|
1487
|
+
/** Base URL + API key for a user-provided OpenAI-compatible endpoint (ollama, vLLM, LM Studio, etc.). */
|
|
1488
|
+
openaiCompatibleBaseUrl: string;
|
|
1489
|
+
openaiCompatibleApiKey: string;
|
|
1490
|
+
orchestratorModel: string;
|
|
1491
|
+
geminiModel: string;
|
|
1492
|
+
/** Model for research subagents (issue #34); defaults to the (cheap) planner model. */
|
|
1493
|
+
researchSubagentModel: string;
|
|
1494
|
+
/**
|
|
1495
|
+
* Thinking effort / model variant for a harness planner (ADR-0009), chosen
|
|
1496
|
+
* from the agent's own discovered variants. Separate from the per-task
|
|
1497
|
+
* efforts the plan carries — this one is the planner's own dial.
|
|
1498
|
+
*/
|
|
1499
|
+
plannerThinkingEffort?: string;
|
|
1500
|
+
planMapEnabled: boolean;
|
|
1501
|
+
autonomousMode: boolean;
|
|
1502
|
+
/**
|
|
1503
|
+
* Run each AI task in its own git worktree and integrate the results on a
|
|
1504
|
+
* per-run branch (ADR-0013). Non-git workspaces fall back to the shared
|
|
1505
|
+
* workspace root regardless of this flag.
|
|
1506
|
+
*/
|
|
1507
|
+
worktreeIsolation: boolean;
|
|
1508
|
+
/**
|
|
1509
|
+
* Shell command run in a fresh task worktree instead of symlinking ignored
|
|
1510
|
+
* artifacts from the main worktree — for repos where sharing `node_modules`
|
|
1511
|
+
* or a virtualenv is wrong.
|
|
1512
|
+
*/
|
|
1513
|
+
worktreeSetupCommand?: string;
|
|
1514
|
+
/**
|
|
1515
|
+
* Repositories of the repo group listed by hand, relative to the workspace
|
|
1516
|
+
* (ADR-0014). When non-empty the group is exactly these, replacing the
|
|
1517
|
+
* repositories auto-detected directly inside the folder; needed for ones
|
|
1518
|
+
* deeper than that, which are never auto-detected.
|
|
1519
|
+
*/
|
|
1520
|
+
workspaceRepos: string[];
|
|
1521
|
+
/**
|
|
1522
|
+
* Extra paths or globs, relative to each repo root, linked from the real repo
|
|
1523
|
+
* into its task worktree where they exist — gitignored local state such as
|
|
1524
|
+
* `*.tfstate` that a task must use, not a copy of.
|
|
1525
|
+
*/
|
|
1526
|
+
worktreeLinks: string[];
|
|
1527
|
+
/**
|
|
1528
|
+
* How many conflict repairs one task may go through before its conflict is
|
|
1529
|
+
* left for a person (ADR-0015); 0 turns repair off.
|
|
1530
|
+
*/
|
|
1531
|
+
conflictRepairAttempts: number;
|
|
1532
|
+
/**
|
|
1533
|
+
* What to do when planner research reaches outside its default envelope — an
|
|
1534
|
+
* out-of-workspace path, or a shell command beyond the auto-allowed read-only
|
|
1535
|
+
* set. `ask` prompts the user (and denies where no surface can prompt, such as
|
|
1536
|
+
* headless runs); `allow` and `deny` skip the prompt entirely.
|
|
1537
|
+
*/
|
|
1538
|
+
approvalMode: ApprovalMode;
|
|
1539
|
+
/** Scopes granted up front, so CI and power users never see a prompt. Trailing `*` matches by prefix. */
|
|
1540
|
+
approvalPreApproved: string[];
|
|
1541
|
+
/** Get the base URL for an OpenAI-compatible provider. */
|
|
1542
|
+
getProviderBaseUrl(provider: AiProvider): string;
|
|
1543
|
+
/** Get the API key for a provider. */
|
|
1544
|
+
getProviderApiKey(provider: AiProvider): string;
|
|
1545
|
+
/**
|
|
1546
|
+
* Push the canonical provider routing lists in (sole producer: ModelResolver).
|
|
1547
|
+
* Config consumes them when resolving a chosen model id to its serving API.
|
|
1548
|
+
*/
|
|
1549
|
+
setProviderModelLists(lists: ProviderModelLists): void;
|
|
1550
|
+
}
|
|
1551
|
+
declare function enabledRunners(cfg: IConfig): RunnerId[];
|
|
1552
|
+
|
|
1553
|
+
/** True when a name belongs to a built-in runner and is therefore not installable. */
|
|
1554
|
+
declare function isReservedRunnerName(name: string): boolean;
|
|
1555
|
+
/** Clone seam: takes a validated URL and a destination, or throws. */
|
|
1556
|
+
type PluginCloneFn = (url: string, destDir: string) => void;
|
|
1557
|
+
declare class RunnerRegistry {
|
|
1558
|
+
private plugins;
|
|
1559
|
+
private store;
|
|
1560
|
+
private clone;
|
|
1561
|
+
constructor(store?: IPluginStore, clone?: PluginCloneFn);
|
|
1562
|
+
private loadBuiltins;
|
|
1563
|
+
loadUserPlugins(): void;
|
|
1564
|
+
get(id: string): PluginEntry | undefined;
|
|
1565
|
+
getManifest(id: string): RunnerPluginManifest | undefined;
|
|
1566
|
+
list(): PluginEntry[];
|
|
1567
|
+
listEnabled(config: IConfig): PluginEntry[];
|
|
1568
|
+
listEnabledIds(config: IConfig): string[];
|
|
1569
|
+
isBuiltIn(id: string): boolean;
|
|
1570
|
+
installFromPath(sourcePath: string): RunnerPluginManifest;
|
|
1571
|
+
installFromGit(url: string): RunnerPluginManifest;
|
|
1572
|
+
/**
|
|
1573
|
+
* The single destination-building step both install routes share: the name is
|
|
1574
|
+
* constrained to a plain segment and the resolved destination is asserted to
|
|
1575
|
+
* be inside the plugins directory before anything is copied.
|
|
1576
|
+
*/
|
|
1577
|
+
private registerInstalled;
|
|
1578
|
+
remove(name: string): void;
|
|
1579
|
+
createSkeleton(name: string, outputDir: string): string;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
interface ITerminalSession {
|
|
1583
|
+
id: string;
|
|
1584
|
+
taskId: string;
|
|
1585
|
+
onOutput(callback: (text: string) => void): void;
|
|
1586
|
+
onExit(callback: (code: number) => void): void;
|
|
1587
|
+
kill(): void;
|
|
1588
|
+
getOutput(): string;
|
|
1589
|
+
write(text: string): void;
|
|
1590
|
+
/**
|
|
1591
|
+
* True when the session runs the agent as a raw-mode TUI (a real PTY for the
|
|
1592
|
+
* VS Code terminal, a tmux window). Such a surface submits an input line on
|
|
1593
|
+
* the Enter keystroke (`\r`), so a synchronized resume token terminated with
|
|
1594
|
+
* `\n` only types the line and never sends it. A line-oriented piped session
|
|
1595
|
+
* (`defaultInteractive = false`) leaves this false and accepts `\n`.
|
|
1596
|
+
*/
|
|
1597
|
+
readonly interactive?: boolean;
|
|
1598
|
+
/**
|
|
1599
|
+
* Optional transport-level control channel: PTY resize requests for a session
|
|
1600
|
+
* whose runner renders a TUI. Absent on transports without a resizable PTY
|
|
1601
|
+
* (a plain piped subprocess); surfaces must feature-detect before calling.
|
|
1602
|
+
*/
|
|
1603
|
+
writeControl?(text: string): void;
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* How Ordewell drives a task's runner (ADR-0018): through its screen and
|
|
1607
|
+
* keyboard, or through its programmatic protocol.
|
|
1608
|
+
*/
|
|
1609
|
+
type RunnerTransport = 'terminal' | 'structured';
|
|
1610
|
+
declare function isRunnerTransport(value: unknown): value is RunnerTransport;
|
|
1611
|
+
/** How a structured turn ended. `failed` carries the agent's own words in the preceding `error` event. */
|
|
1612
|
+
type StructuredTurnEnd = 'completed' | 'interrupted' | 'failed';
|
|
1613
|
+
/**
|
|
1614
|
+
* One normalized event from a structured task (ADR-0018, O1b): the adapter's
|
|
1615
|
+
* events, with the turn made explicit at both ends and the message queue (M1)
|
|
1616
|
+
* alongside. Subagent work carries its `subagentId`. The source for the
|
|
1617
|
+
* full-fidelity task log, never for verdicts.
|
|
1618
|
+
*/
|
|
1619
|
+
type StructuredEvent = Exclude<AgentEvent, {
|
|
1620
|
+
type: 'turn_end';
|
|
1621
|
+
} | {
|
|
1622
|
+
type: 'permission_cancelled';
|
|
1623
|
+
}>
|
|
1624
|
+
/** `text` is the user message the turn answers; `messageId` is set when it had waited in the queue. */
|
|
1625
|
+
| {
|
|
1626
|
+
type: 'turn_start';
|
|
1627
|
+
text: string;
|
|
1628
|
+
messageId?: string;
|
|
1629
|
+
} | {
|
|
1630
|
+
type: 'turn_end';
|
|
1631
|
+
reason: StructuredTurnEnd;
|
|
1632
|
+
} | {
|
|
1633
|
+
type: 'message_queued';
|
|
1634
|
+
messageId: string;
|
|
1635
|
+
text: string;
|
|
1636
|
+
} | {
|
|
1637
|
+
type: 'message_removed';
|
|
1638
|
+
messageId: string;
|
|
1639
|
+
}
|
|
1640
|
+
/** An open `permission_request` was answered, by whoever answered it (ADR-0018, A1). */
|
|
1641
|
+
| {
|
|
1642
|
+
type: 'permission_decided';
|
|
1643
|
+
id: string;
|
|
1644
|
+
decision: ApprovalDecision;
|
|
1645
|
+
}
|
|
1646
|
+
/** An open `permission_request` can no longer be answered: the runner withdrew it, or its process is gone. */
|
|
1647
|
+
| {
|
|
1648
|
+
type: 'permission_withdrawn';
|
|
1649
|
+
id: string;
|
|
1650
|
+
};
|
|
1651
|
+
interface QueuedTaskMessage {
|
|
1652
|
+
id: string;
|
|
1653
|
+
text: string;
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* What a session driven over its runner's protocol can do that a terminal
|
|
1657
|
+
* cannot (ADR-0018, S2). Optional: callers feature-detect it with
|
|
1658
|
+
* {@link isStructuredSession}, and code that does not look behaves as it did.
|
|
1659
|
+
*/
|
|
1660
|
+
interface StructuredSessionCapability {
|
|
1661
|
+
readonly transport: 'structured';
|
|
1662
|
+
/** `working` while a turn runs; `idle` between turns, waiting for a message. */
|
|
1663
|
+
turnState(): 'working' | 'idle';
|
|
1664
|
+
onTurnEnd(listener: (reason: StructuredTurnEnd) => void): void;
|
|
1665
|
+
onEvent(listener: (event: StructuredEvent) => void): void;
|
|
1666
|
+
/**
|
|
1667
|
+
* Queue a user message, delivered when the current turn ends — or at once
|
|
1668
|
+
* when idle. Returns its id, for {@link removeQueued}.
|
|
1669
|
+
*/
|
|
1670
|
+
sendMessage(text: string): string;
|
|
1671
|
+
/** Take a message back before it is delivered. False when it already was. */
|
|
1672
|
+
removeQueued(id: string): boolean;
|
|
1673
|
+
/** Messages waiting for the current turn to end, oldest first. */
|
|
1674
|
+
queued(): QueuedTaskMessage[];
|
|
1675
|
+
/**
|
|
1676
|
+
* Stop the running turn, keeping the session: a soft interrupt first, then —
|
|
1677
|
+
* if the runner does not answer in time — kill and resume. Either way the
|
|
1678
|
+
* turn ends `interrupted`. Resolves once it has.
|
|
1679
|
+
*/
|
|
1680
|
+
interrupt(): Promise<void>;
|
|
1681
|
+
/** The runner's own session id once announced — what a continue resumes (ADR-0018, K1). */
|
|
1682
|
+
nativeSessionId(): string | null;
|
|
1683
|
+
/**
|
|
1684
|
+
* Answer a `permission_request` this session emitted, by its event id. False
|
|
1685
|
+
* when it is no longer open — answered, withdrawn, or never asked.
|
|
1686
|
+
*/
|
|
1687
|
+
answerPermission(id: string, decision: ApprovalDecision): boolean;
|
|
1688
|
+
}
|
|
1689
|
+
declare function isStructuredSession(session: ITerminalSession): session is ITerminalSession & StructuredSessionCapability;
|
|
1690
|
+
|
|
1691
|
+
interface ITerminalRunner {
|
|
1692
|
+
spawn(opts: {
|
|
1693
|
+
taskId: string;
|
|
1694
|
+
runner: string;
|
|
1695
|
+
prompt: string;
|
|
1696
|
+
modelId?: string;
|
|
1697
|
+
thinkingEffort?: string;
|
|
1698
|
+
modelVariants?: string[];
|
|
1699
|
+
mode?: string;
|
|
1700
|
+
headless?: boolean;
|
|
1701
|
+
cwd: string;
|
|
1702
|
+
registry?: RunnerRegistry;
|
|
1703
|
+
/** Task order and title — surfaces use these to label task_started/output events. */
|
|
1704
|
+
order?: number;
|
|
1705
|
+
title?: string;
|
|
1706
|
+
/**
|
|
1707
|
+
* The owning plan session. Task ids are only unique within one plan, so
|
|
1708
|
+
* transports that key OS resources by task (tmux windows, log files) need
|
|
1709
|
+
* this to keep two plans' identically named tasks apart.
|
|
1710
|
+
*/
|
|
1711
|
+
planSessionId?: string;
|
|
1712
|
+
/**
|
|
1713
|
+
* The workspace's own variables (ADR-0016), under the runner's: a
|
|
1714
|
+
* manifest's env still wins over them.
|
|
1715
|
+
*/
|
|
1716
|
+
env?: Record<string, string>;
|
|
1717
|
+
/**
|
|
1718
|
+
* The transport the plan asks for (ADR-0018, S1). A router decides per
|
|
1719
|
+
* task whether the runner can honour it; any other runner ignores it.
|
|
1720
|
+
*/
|
|
1721
|
+
transport?: RunnerTransport;
|
|
1722
|
+
/**
|
|
1723
|
+
* The runner's own session to continue in (ADR-0018, K1). Only the
|
|
1724
|
+
* structured transport can honour it; a terminal session comes back fresh,
|
|
1725
|
+
* which is why a continue refuses one.
|
|
1726
|
+
*/
|
|
1727
|
+
resumeSessionId?: string;
|
|
1728
|
+
}): Promise<ITerminalSession>;
|
|
1729
|
+
stop(sessionId: string): void;
|
|
1730
|
+
stopAll(): void;
|
|
1731
|
+
activeCount: number;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
interface UserStep {
|
|
1735
|
+
order: number;
|
|
1736
|
+
instruction: string;
|
|
1737
|
+
completed: boolean;
|
|
1738
|
+
}
|
|
1739
|
+
/** One deterministic signal gathered while verifying a completed task. */
|
|
1740
|
+
interface VerificationCheck {
|
|
1741
|
+
name: 'exit_code' | 'completion_marker' | 'manual';
|
|
1742
|
+
passed: boolean;
|
|
1743
|
+
/** A check that did not apply. Skipped checks don't affect the verdict. */
|
|
1744
|
+
skipped: boolean;
|
|
1745
|
+
detail: string;
|
|
1746
|
+
}
|
|
1747
|
+
/** Evidence-based verdict for a completed task. Single end-to-end outcome produced by verification. */
|
|
1748
|
+
interface Verdict {
|
|
1749
|
+
outcome: 'pass' | 'fail';
|
|
1750
|
+
reason: string;
|
|
1751
|
+
checks: VerificationCheck[];
|
|
1752
|
+
decidedAt: string;
|
|
1753
|
+
}
|
|
1754
|
+
interface TaskOutputSummary {
|
|
1755
|
+
reviewReason: string;
|
|
1756
|
+
logTail: string;
|
|
1757
|
+
capturedAt: string;
|
|
1758
|
+
}
|
|
1759
|
+
type TaskType = 'ai' | 'user';
|
|
1760
|
+
type TaskStatus = 'pending' | 'approved' | 'in_progress' | 'completed' | 'failed' | 'blocked' | 'awaiting_user';
|
|
1761
|
+
type TaskMode = string;
|
|
1762
|
+
/**
|
|
1763
|
+
* Why an `awaiting_user` task waits (ADR-0018, W1): a structured turn that
|
|
1764
|
+
* ended without the done marker, a checkpoint question, or work that did not
|
|
1765
|
+
* land. Saved, so no surface has to guess it from whether an attempt is live.
|
|
1766
|
+
*/
|
|
1767
|
+
type AwaitingReason = 'input' | 'checkpoint' | 'conflict';
|
|
1768
|
+
declare function isAwaitingReason(value: unknown): value is AwaitingReason;
|
|
1769
|
+
interface TaskModelAssignment {
|
|
1770
|
+
modelId: string;
|
|
1771
|
+
modelLabel: string;
|
|
1772
|
+
thinkingEffort?: string;
|
|
1773
|
+
/**
|
|
1774
|
+
* All variant ids the model offered when this assignment was made. Carried
|
|
1775
|
+
* on the assignment because runners need it at spawn time (opencode's TUI
|
|
1776
|
+
* only honors an assigned variant when the others are config-disabled) and
|
|
1777
|
+
* the discovery catalog isn't available there.
|
|
1778
|
+
*/
|
|
1779
|
+
availableVariants?: string[];
|
|
1780
|
+
}
|
|
1781
|
+
type RunnerId = string;
|
|
1782
|
+
/**
|
|
1783
|
+
* How a task's latest attempt was driven (ADR-0018). Recorded only when its
|
|
1784
|
+
* plan asked for the structured transport, so a terminal plan's tasks carry
|
|
1785
|
+
* nothing new.
|
|
1786
|
+
*/
|
|
1787
|
+
interface TaskTransport {
|
|
1788
|
+
kind: RunnerTransport;
|
|
1789
|
+
/** Why a plan that asked for structured ran this task on the terminal — never a silent downgrade (S3). */
|
|
1790
|
+
fallback?: string;
|
|
1791
|
+
/** The runner's own session id of a structured attempt, once it ends: what a continue resumes (K1). */
|
|
1792
|
+
nativeSessionId?: string;
|
|
1793
|
+
}
|
|
1794
|
+
interface Task {
|
|
1795
|
+
id: string;
|
|
1796
|
+
order: number;
|
|
1797
|
+
title: string;
|
|
1798
|
+
description: string;
|
|
1799
|
+
type: TaskType;
|
|
1800
|
+
status: TaskStatus;
|
|
1801
|
+
dependencies: string[];
|
|
1802
|
+
prompt?: string;
|
|
1803
|
+
userSteps?: UserStep[];
|
|
1804
|
+
subtasks: Task[];
|
|
1805
|
+
verdict?: Verdict;
|
|
1806
|
+
outputSummary?: TaskOutputSummary;
|
|
1807
|
+
assignedModel?: TaskModelAssignment;
|
|
1808
|
+
assignedRunner: RunnerId;
|
|
1809
|
+
thinkingEffort?: string;
|
|
1810
|
+
taskMode?: TaskMode;
|
|
1811
|
+
completionMarker: string;
|
|
1812
|
+
autonomy?: 'AFK' | 'HITL';
|
|
1813
|
+
sliceType?: 'HITL' | 'AFK';
|
|
1814
|
+
userStoriesCovered?: string[];
|
|
1815
|
+
transport?: TaskTransport;
|
|
1816
|
+
/** Set only while `status` is `awaiting_user`, and not always then — a usage-limit pause has none. */
|
|
1817
|
+
awaitingReason?: AwaitingReason;
|
|
1818
|
+
}
|
|
1819
|
+
interface DiscoveredMode {
|
|
1820
|
+
id: string;
|
|
1821
|
+
label: string;
|
|
1822
|
+
description: string;
|
|
1823
|
+
}
|
|
1824
|
+
type ResearchToolType = 'read_file' | 'read_files' | 'glob' | 'grep' | 'find_symbol' | 'list_dir' | 'bash' | 'fetch' | 'web_search' | 'spawn_research_agent'
|
|
1825
|
+
/**
|
|
1826
|
+
* A tool belonging to a harness planner's own toolbox (ADR-0009) that has no
|
|
1827
|
+
* Ordewell equivalent — Edit, WebFetch, TodoWrite, whatever a coding agent
|
|
1828
|
+
* ships next. The real name travels in `toolLabel` rather than being
|
|
1829
|
+
* relabelled as a tool it is not; the union stays closed so the
|
|
1830
|
+
* exhaustiveness checks in every surface's icon/label switch survive.
|
|
1831
|
+
*/
|
|
1832
|
+
| 'agent_tool';
|
|
1833
|
+
/**
|
|
1834
|
+
* What happened when a research tool call ran, for honest per-surface
|
|
1835
|
+
* rendering. The broadcast seam carries this on every `research_step_done` so
|
|
1836
|
+
* surfaces do not have to pattern-match refusal text to tell a refused `rm`
|
|
1837
|
+
* from a successful `rm` — the old render path flipped a `✓` for both.
|
|
1838
|
+
*/
|
|
1839
|
+
type ResearchStepOutcome = 'success' | 'failure' | 'refused' | 'denied' | 'not_executed';
|
|
1840
|
+
interface ResearchStep {
|
|
1841
|
+
id: string;
|
|
1842
|
+
tool: ResearchToolType;
|
|
1843
|
+
/** The tool's own name when it came from a harness planner — always set for `agent_tool`. */
|
|
1844
|
+
toolLabel?: string;
|
|
1845
|
+
args: string;
|
|
1846
|
+
result: string;
|
|
1847
|
+
success: boolean;
|
|
1848
|
+
outcome: ResearchStepOutcome;
|
|
1849
|
+
/** The model's tool_call id, so a surface can match `tool_result` to the
|
|
1850
|
+
* pending `tool_call` it announced — robust under parallel same-tool rounds. */
|
|
1851
|
+
toolCallId?: string;
|
|
1852
|
+
/** The research subagent that ran the call, so a reload regroups it under that subagent. */
|
|
1853
|
+
subagentId?: string;
|
|
1854
|
+
timestamp: string;
|
|
1855
|
+
thinkingText?: string;
|
|
1856
|
+
}
|
|
1857
|
+
interface UserPromptEntry {
|
|
1858
|
+
id: string;
|
|
1859
|
+
type: 'user_prompt' | 'system';
|
|
1860
|
+
content: string;
|
|
1861
|
+
timestamp: string;
|
|
1862
|
+
}
|
|
1863
|
+
type SubagentOutcome = 'done' | 'failed' | 'stopped';
|
|
1864
|
+
/**
|
|
1865
|
+
* One subagent's whole run, logged when it finishes: what it was asked, how it
|
|
1866
|
+
* ended and what it reported. Its steps stay separate entries carrying the same
|
|
1867
|
+
* `subagentId`, so an older reader that knows only steps still shows them.
|
|
1868
|
+
*/
|
|
1869
|
+
interface SubagentLogEntry {
|
|
1870
|
+
id: string;
|
|
1871
|
+
type: 'subagent';
|
|
1872
|
+
subagentId: string;
|
|
1873
|
+
brief: string;
|
|
1874
|
+
model?: string;
|
|
1875
|
+
outcome: SubagentOutcome;
|
|
1876
|
+
digest: string;
|
|
1877
|
+
usage?: UsageTotals;
|
|
1878
|
+
timestamp: string;
|
|
1879
|
+
}
|
|
1880
|
+
type ResearchLogEntry = ResearchStep | UserPromptEntry | SubagentLogEntry;
|
|
1881
|
+
interface ResearchProgress {
|
|
1882
|
+
type: 'thinking' | 'tool_call' | 'tool_result' | 'plan_token' | 'interrupted' | 'liveness' | 'text_delta' | 'text_retracted' | 'usage' | 'subagent_started' | 'subagent_finished';
|
|
1883
|
+
/** Minted by whoever runs the turn and passed through untouched; absent outside a turn. */
|
|
1884
|
+
turnId?: string;
|
|
1885
|
+
/** One continuous run of model text — text before a tool call is its own segment. */
|
|
1886
|
+
segmentId?: string;
|
|
1887
|
+
text?: string;
|
|
1888
|
+
tool?: string;
|
|
1889
|
+
/** Harness planners (ADR-0009): the agent's own name for a tool Ordewell has no member for. */
|
|
1890
|
+
toolLabel?: string;
|
|
1891
|
+
toolArgs?: string;
|
|
1892
|
+
toolResult?: string;
|
|
1893
|
+
planToken?: string;
|
|
1894
|
+
step?: ResearchStep;
|
|
1895
|
+
/** The model's tool_call id, threaded on tool_call and tool_result so a
|
|
1896
|
+
* surface can match the result to its pending call — robust under parallel
|
|
1897
|
+
* same-tool rounds where LIFO-by-name matching mislabels summaries. */
|
|
1898
|
+
toolCallId?: string;
|
|
1899
|
+
/** Present when this event originates from (or reports on) one spawned research subagent (issue #34). */
|
|
1900
|
+
subagentId?: string;
|
|
1901
|
+
record?: UsageRecord;
|
|
1902
|
+
brief?: string;
|
|
1903
|
+
model?: string;
|
|
1904
|
+
outcome?: SubagentOutcome;
|
|
1905
|
+
digest?: string;
|
|
1906
|
+
usage?: UsageTotals;
|
|
1907
|
+
}
|
|
1908
|
+
interface ThinkingBlock {
|
|
1909
|
+
id: string;
|
|
1910
|
+
text: string;
|
|
1911
|
+
}
|
|
1912
|
+
interface StreamThinkingEvent {
|
|
1913
|
+
type: 'thinking';
|
|
1914
|
+
block: ThinkingBlock;
|
|
1915
|
+
}
|
|
1916
|
+
interface StreamStepEvent {
|
|
1917
|
+
type: 'step';
|
|
1918
|
+
step: ResearchStep;
|
|
1919
|
+
}
|
|
1920
|
+
type StreamEvent = StreamThinkingEvent | StreamStepEvent;
|
|
1921
|
+
interface DiscoveredModel {
|
|
1922
|
+
modelId: string;
|
|
1923
|
+
modelLabel: string;
|
|
1924
|
+
runnerProvider?: string;
|
|
1925
|
+
/**
|
|
1926
|
+
* Human-facing provider name as the runner itself reports it (e.g.
|
|
1927
|
+
* "OpenCode Zen" for `runnerProvider: 'opencode'`). Populated from the
|
|
1928
|
+
* runner's own provider catalog when available; when absent the UI derives a
|
|
1929
|
+
* label from `runnerProvider` by title-casing.
|
|
1930
|
+
*/
|
|
1931
|
+
runnerProviderLabel?: string;
|
|
1932
|
+
/**
|
|
1933
|
+
* The runner whose catalog listed this model. Stamped once, at the single
|
|
1934
|
+
* `ModelDiscovery.discover` choke point, so a flat cross-runner list can
|
|
1935
|
+
* still say where each entry came from — `runnerProvider` alone cannot:
|
|
1936
|
+
* OpenCode reports most of its catalog as `openrouter`, which names the
|
|
1937
|
+
* serving backend, not the agent Ordewell would spawn.
|
|
1938
|
+
*/
|
|
1939
|
+
runnerId?: string;
|
|
1940
|
+
/** The runner's display name (`OpenCode`), from its manifest. */
|
|
1941
|
+
runnerLabel?: string;
|
|
1942
|
+
variants: {
|
|
1943
|
+
id: string;
|
|
1944
|
+
label: string;
|
|
1945
|
+
}[];
|
|
1946
|
+
/**
|
|
1947
|
+
* The model's context window when the runner or catalog reports it (#49).
|
|
1948
|
+
* Read by the planner-model lookup so context fill can be shown; absent when
|
|
1949
|
+
* unknown rather than defaulted to zero.
|
|
1950
|
+
*/
|
|
1951
|
+
contextWindow?: number;
|
|
1952
|
+
}
|
|
1953
|
+
type PlanStatus = 'draft' | 'approved' | 'rejected' | 'running' | 'completed';
|
|
1954
|
+
/**
|
|
1955
|
+
* One entry of the planner's persisted dialogue (ADR-0002). The single source
|
|
1956
|
+
* of truth for both UI redisplay and conversational context. Tool-call results
|
|
1957
|
+
* are NOT stored here — they live in the AI service's tool-use history;
|
|
1958
|
+
* `researchLog` remains the persisted tool trace for the UI.
|
|
1959
|
+
*/
|
|
1960
|
+
interface ConversationMessage {
|
|
1961
|
+
role: 'user' | 'assistant';
|
|
1962
|
+
content: string;
|
|
1963
|
+
timestamp: string;
|
|
1964
|
+
/**
|
|
1965
|
+
* Timeline marker: 'plan_generated' records the point in the dialogue where
|
|
1966
|
+
* the plan was committed (the UI anchors the plan card there on restore);
|
|
1967
|
+
* 'system' is a host-injected notice; 'compaction' is the summary a
|
|
1968
|
+
* user-triggered compaction left in place of the earlier messages — always
|
|
1969
|
+
* the transcript's first entry. Absent for ordinary chat turns, so
|
|
1970
|
+
* sessions saved before markers existed degrade gracefully.
|
|
1971
|
+
*/
|
|
1972
|
+
kind?: 'plan_generated' | 'system' | 'compaction';
|
|
1973
|
+
}
|
|
1974
|
+
interface QueuedMessage {
|
|
1975
|
+
id: string;
|
|
1976
|
+
text: string;
|
|
1977
|
+
timestamp: string;
|
|
1978
|
+
}
|
|
1979
|
+
interface PlanModificationWarnings {
|
|
1980
|
+
deletedCompleted: string[];
|
|
1981
|
+
changedCompleted: string[];
|
|
1982
|
+
deletedInProgress: string[];
|
|
1983
|
+
modifiedInProgress: string[];
|
|
1984
|
+
brokenDependencies: string[];
|
|
1985
|
+
}
|
|
1986
|
+
declare function emptyWarnings(): PlanModificationWarnings;
|
|
1987
|
+
interface LegacyPlanState {
|
|
1988
|
+
tasks: Task[];
|
|
1989
|
+
generatedAt: string;
|
|
1990
|
+
status: PlanStatus;
|
|
1991
|
+
runners: RunnerId[];
|
|
1992
|
+
lastUpdated: string;
|
|
1993
|
+
researchLog?: ResearchLogEntry[];
|
|
1994
|
+
/** The planner dialogue — user messages and assistant messages, in order (ADR-0002). */
|
|
1995
|
+
conversationHistory?: ConversationMessage[];
|
|
1996
|
+
/** Full markdown PRD once written by the planner (PRD mode), also saved to .scratch/<slug>/PRD.md. */
|
|
1997
|
+
prdMarkdown?: string;
|
|
1998
|
+
/** Follow-ups queued while tasks execute — applied as plan modifications between batches. */
|
|
1999
|
+
queuedMessages?: QueuedMessage[];
|
|
2000
|
+
/**
|
|
2001
|
+
* The plan's isolation run (ADR-0013), written from the orchestrator at
|
|
2002
|
+
* persist time and read back only when a saved plan is adopted. It names
|
|
2003
|
+
* branches and worktrees that belong to this plan alone: a fork of the plan
|
|
2004
|
+
* must leave it behind rather than share it.
|
|
2005
|
+
*/
|
|
2006
|
+
isolation?: PlanIsolation;
|
|
2007
|
+
/**
|
|
2008
|
+
* The `runnerTransport` setting as the plan's latest run copied it when it
|
|
2009
|
+
* started (ADR-0018, S1): the plan, not the live setting, says what runs.
|
|
2010
|
+
*/
|
|
2011
|
+
runnerTransport?: RunnerTransport;
|
|
2012
|
+
/** Kept so a reopened session shows the same token line (#49). */
|
|
2013
|
+
plannerUsage?: PlannerUsage;
|
|
2014
|
+
}
|
|
2015
|
+
interface Message {
|
|
2016
|
+
id: string;
|
|
2017
|
+
role: 'user' | 'planner' | 'system';
|
|
2018
|
+
content: string;
|
|
2019
|
+
timestamp: number;
|
|
2020
|
+
}
|
|
2021
|
+
interface TaskSnapshot extends Task {
|
|
2022
|
+
completedAt: number;
|
|
2023
|
+
verdict?: Verdict;
|
|
2024
|
+
retryCount: number;
|
|
2025
|
+
finalized: boolean;
|
|
2026
|
+
}
|
|
2027
|
+
type PlanState = {
|
|
2028
|
+
phase: 'planning';
|
|
2029
|
+
history: Message[];
|
|
2030
|
+
message: string;
|
|
2031
|
+
pendingTasks: Task[];
|
|
2032
|
+
} | {
|
|
2033
|
+
phase: 'executing';
|
|
2034
|
+
history: Message[];
|
|
2035
|
+
message: string;
|
|
2036
|
+
executionLog: TaskSnapshot[];
|
|
2037
|
+
pendingTasks: Task[];
|
|
2038
|
+
goal: string;
|
|
2039
|
+
runners: string[];
|
|
2040
|
+
status: PlanStatus;
|
|
2041
|
+
};
|
|
2042
|
+
declare function migratePlanState(raw: unknown): PlanState;
|
|
2043
|
+
declare function migrateLegacyPlan(legacy: LegacyPlanState): PlanState;
|
|
2044
|
+
|
|
2045
|
+
declare function createTask(overrides?: Partial<Task>): Task;
|
|
2046
|
+
declare function createEmptyPlan(): LegacyPlanState;
|
|
2047
|
+
declare function flattenTasks(tasks: readonly Task[]): Task[];
|
|
2048
|
+
/** A flattened task with the parent it hangs under, null for a top-level task. */
|
|
2049
|
+
interface TaskWithParent {
|
|
2050
|
+
task: Task;
|
|
2051
|
+
parent: Task | null;
|
|
2052
|
+
}
|
|
2053
|
+
declare function flattenTasksWithParents(tasks: readonly Task[]): TaskWithParent[];
|
|
2054
|
+
declare function migrateTask(task: Record<string, unknown>): Task;
|
|
2055
|
+
declare function addTaskToPlan(tasks: readonly Task[], partial: Partial<Task>): Task[];
|
|
2056
|
+
declare function removeTaskFromPlan(tasks: readonly Task[], taskId: string): Task[];
|
|
2057
|
+
declare function updateTaskInPlan(tasks: readonly Task[], taskId: string, changes: Partial<Task>): Task[];
|
|
2058
|
+
declare function renumberTasks(tasks: readonly Task[]): Task[];
|
|
2059
|
+
/**
|
|
2060
|
+
* Lay a planner-written task list over the plan it rewrites without letting it
|
|
2061
|
+
* change execution state. A planner restates tasks; it never witnessed one run,
|
|
2062
|
+
* so the status it writes is not evidence. A settled task is kept exactly as
|
|
2063
|
+
* it stands wherever the rewrite names it, and put back beside its old
|
|
2064
|
+
* neighbour where the rewrite leaves it out. Every other task keeps the status
|
|
2065
|
+
* it had; a task the rewrite adds starts pending.
|
|
2066
|
+
*/
|
|
2067
|
+
declare function keepExecutionState(current: readonly Task[], rewrite: Task[]): Task[];
|
|
2068
|
+
declare function validateModifiedPlan(original: Task[], modified: Task[]): PlanModificationWarnings;
|
|
2069
|
+
interface ActiveTaskSession {
|
|
2070
|
+
id: string;
|
|
2071
|
+
taskId: string;
|
|
2072
|
+
}
|
|
2073
|
+
interface ValidationResult {
|
|
2074
|
+
valid: boolean;
|
|
2075
|
+
errors: string[];
|
|
2076
|
+
}
|
|
2077
|
+
interface ValidationContext {
|
|
2078
|
+
executionLog: TaskSnapshot[];
|
|
2079
|
+
oldPending: Task[];
|
|
2080
|
+
newPending: Task[];
|
|
2081
|
+
activeSessions: Map<string, ActiveTaskSession>;
|
|
2082
|
+
}
|
|
2083
|
+
type ValidationCheck = (ctx: ValidationContext) => ValidationResult;
|
|
2084
|
+
declare function warningsText(w: PlanModificationWarnings): string | null;
|
|
2085
|
+
|
|
2086
|
+
export { type IsolationRun as $, AbstractRunner as A, type BlockingPrompt as B, CMD_EXE_MAX_COMMAND_LINE as C, DENY_ALL as D, EmbeddedNewlineError as E, type FetchAllProviderModelsOptions as F, HeadlessSession as G, HeadlessRunner as H, type IApproval as I, type IConfig as J, type IPluginStore as K, type ITerminalRunner as L, type ITerminalSession as M, type IWorktreeIsolation as N, type IntegrationDisposal as O, type IsolationAvailability as P, type IsolationHandoff as Q, type IsolationHandoffRepo as R, type IsolationInactiveReason as S, type IsolationLandedTask as T, type IsolationLanding as U, type IsolationMergeBlock as V, type IsolationMergeBlockReason as W, type IsolationMergeResult as X, type IsolationOutcome as Y, type IsolationPruneResult as Z, type IsolationRepo as _, AbstractTerminalSession as a, type TaskOutputSummary as a$, type IsolationTaskRecord as a0, type IsolationTaskRepo as a1, type IsolationTaskStatus as a2, type IsolationView as a3, type LaunchDeps as a4, type LaunchPlan as a5, type LegacyPlanState as a6, LineBuffer as a7, type Message as a8, ModelCatalog as a9, type ResearchLogEntry as aA, type ResearchProgress as aB, type ResearchStep as aC, type ResearchStepOutcome as aD, type ResearchToolType as aE, type ResolveContext as aF, type RunnerId as aG, type RunnerInvocation as aH, type RunnerPluginManifest as aI, RunnerRegistry as aJ, type RunnerSpawnOptions as aK, type RunnerTransport as aL, type StreamEvent as aM, type StreamStepEvent as aN, type StreamThinkingEvent as aO, type StructuredEvent as aP, type StructuredSessionCapability as aQ, type StructuredTurnEnd as aR, type SubagentLogEntry as aS, type SubagentOutcome as aT, type Task as aU, type TaskIsolation as aV, type TaskIsolationState as aW, type TaskMode as aX, type TaskModeAgentAdapter as aY, TaskModeUnsupportedError as aZ, type TaskModelAssignment as a_, type ModelShortcut as aa, ORCHESTRATOR_SHORTCUTS as ab, type OrchestratorOption as ac, type PlanIsolation as ad, type PlanModificationWarnings as ae, type PlanState as af, type PlanStatus as ag, type PlannerStartOptions as ah, type PlannerUsage as ai, type PluginCloneFn as aj, type PluginEntry as ak, type PluginFeatures as al, type PluginMode as am, type PluginModelDiscovery as an, type PluginRunnerDef as ao, type PreparedLaunch as ap, type PreparedTask as aq, type ProviderCredentialSource as ar, type ProviderModelLists as as, type ProviderModelsResult as at, type PtySize as au, type PtyWrapOptions as av, type QueuedMessage as aw, type QueuedTaskMessage as ax, type RepairEvidence as ay, type RepoGroupLayout as az, type ActiveTaskSession as b, type TaskRunnerFlags as b0, type TaskSnapshot as b1, type TaskStartOptions as b2, type TaskStatus as b3, type TaskTransport as b4, type TaskType as b5, type TaskWithParent as b6, type ThinkingBlock as b7, type UsageLine as b8, type UsageRecord as b9, isRunnerApproval as bA, isRunnerTransport as bB, isStructuredSession as bC, keepExecutionState as bD, knownModelId as bE, migrateLegacyPlan as bF, migratePlanState as bG, migrateTask as bH, partedPromptUsage as bI, planDirectLaunch as bJ, planShellLaunch as bK, plannerContextFill as bL, posixShellQuote as bM, removeTaskFromPlan as bN, renumberTasks as bO, resolveModelShortcut as bP, resolveProvider as bQ, stripAnsi as bR, toApprovalDecision as bS, toOrchestratorOptions as bT, updateTaskInPlan as bU, usageLine as bV, validateModifiedPlan as bW, warningsText as bX, windowsCommandLine as bY, wrapWithPty as bZ, type UsageTotals as ba, type UserPromptEntry as bb, type UserStep as bc, type ValidationCheck as bd, type ValidationContext as be, type ValidationResult as bf, type Verdict as bg, type VerificationCheck as bh, WINDOWS_MAX_COMMAND_LINE as bi, addPlannerUsage as bj, addTaskToPlan as bk, addUsage as bl, buildShellInvocation as bm, collectProviderCredentials as bn, createEmptyPlan as bo, createTask as bp, emptyWarnings as bq, enabledRunners as br, fetchAllProviderModels as bs, flattenTasks as bt, flattenTasksWithParents as bu, isAwaitingReason as bv, isExecutableResolved as bw, isGranted as bx, isMeasured as by, isReservedRunnerName as bz, type AgentAdapter as c, type AgentAdapterFactory as d, type AgentEvent as e, type AgentProcessDeps as f, type AgentStartOptions as g, type AiProvider as h, type AllProviderModels as i, type ApprovalAnswer as j, type ApprovalDecision as k, type ApprovalKind as l, type ApprovalMode as m, ApprovalPolicy as n, type ApprovalPolicyOptions as o, type ApprovalRequest as p, type ApprovalSource as q, type AwaitingReason as r, type CatalogModel as s, CommandLineTooLongError as t, type ConversationMessage as u, type DiscoveredMode as v, type DiscoveredModel as w, type DiscoveryCommand as x, ExecutableNotFoundError as y, type HeadlessRunnerDeps as z };
|