dsh-coding 0.0.1 → 0.1.1-rc1
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/README.md +65 -58
- package/cordis.patch.yml +231 -4
- package/docs/DETAIL.md +183 -0
- package/docs/DEVELOPMENT.md +189 -0
- package/icon.svg +4 -4
- package/lib/apply-patch.js +268 -0
- package/lib/client/capsule.js +120 -0
- package/lib/client/card.js +220 -0
- package/lib/client/command-row.js +76 -0
- package/lib/client/config-page.js +392 -0
- package/lib/client/definition.js +164 -0
- package/lib/client/index.js +129 -0
- package/lib/client/locales.js +156 -0
- package/lib/client/mode-picker.js +77 -0
- package/lib/client/styles.js +283 -0
- package/lib/client.js +1691 -0
- package/lib/coding-projection.js +349 -0
- package/lib/config.js +204 -0
- package/lib/contract.js +124 -0
- package/lib/editor.js +23 -0
- package/lib/failures.js +142 -0
- package/lib/handoff.js +312 -0
- package/lib/index.js +109 -7
- package/lib/language.js +136 -0
- package/lib/messages.js +43 -0
- package/lib/models.js +154 -0
- package/lib/patch.js +235 -0
- package/lib/preset.js +1488 -0
- package/lib/reasoning-levels.js +28 -0
- package/lib/reasoning-projection.js +178 -0
- package/lib/reasoning.js +585 -0
- package/lib/stages.js +306 -0
- package/lib/state.js +550 -0
- package/lib/system-language.js +56 -0
- package/lib/types/apply-patch.d.ts +13 -0
- package/lib/types/client/capsule.d.ts +9 -0
- package/lib/types/client/card.d.ts +72 -0
- package/lib/types/client/command-row.d.ts +42 -0
- package/lib/types/client/config-page.d.ts +136 -0
- package/lib/types/client/definition.d.ts +51 -0
- package/lib/types/client/index.d.ts +10 -0
- package/lib/types/client/locales.d.ts +18 -0
- package/lib/types/client/mode-picker.d.ts +25 -0
- package/lib/types/client/styles.d.ts +28 -0
- package/lib/types/coding-projection.d.ts +116 -0
- package/lib/types/config.d.ts +193 -0
- package/lib/types/contract.d.ts +33 -0
- package/lib/types/editor.d.ts +9 -0
- package/lib/types/failures.d.ts +62 -0
- package/lib/types/handoff.d.ts +112 -0
- package/lib/types/index.d.ts +144 -0
- package/lib/types/language.d.ts +56 -0
- package/lib/types/messages.d.ts +27 -0
- package/lib/types/models.d.ts +82 -0
- package/lib/types/patch.d.ts +37 -0
- package/lib/types/preset.d.ts +22 -0
- package/lib/types/reasoning-levels.d.ts +20 -0
- package/lib/types/reasoning-projection.d.ts +64 -0
- package/lib/types/reasoning.d.ts +141 -0
- package/lib/types/stages.d.ts +164 -0
- package/lib/types/state.d.ts +261 -0
- package/lib/types/system-language.d.ts +10 -0
- package/lib/types/verification-tool.d.ts +32 -0
- package/lib/types/verification.d.ts +77 -0
- package/lib/types/verifier.d.ts +9 -0
- package/lib/types/volatile.d.ts +17 -0
- package/lib/verification-tool.js +176 -0
- package/lib/verification.js +337 -0
- package/lib/verifier.js +25 -0
- package/lib/volatile.js +20 -0
- package/locale/en.json +3 -2
- package/locale/zh.json +3 -2
- package/package.json +83 -9
- package/lib/index.d.ts +0 -11
package/lib/stages.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The enforced coding stages and the deterministic tool policy that belongs to
|
|
3
|
+
* each one. This module is deliberately dependency-free: the Host preset, the
|
|
4
|
+
* worker presets, and the Web client all import it, so it must never pull in a
|
|
5
|
+
* Node-only or React-only module.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-coding/stages
|
|
8
|
+
*/
|
|
9
|
+
import { asFailure } from './failures.js';
|
|
10
|
+
import { asHandoff } from './handoff.js';
|
|
11
|
+
/** Every stage, in forward order. */
|
|
12
|
+
export const CODING_STAGES = ['requirements', 'plan', 'implement', 'verify', 'deliver'];
|
|
13
|
+
/** Every mode, in roster order. */
|
|
14
|
+
export const CODING_MODES = ['auto', 'consult', 'review', 'codex'];
|
|
15
|
+
/**
|
|
16
|
+
* The stages a mode opens. A mode never gains a stage at runtime: the set is
|
|
17
|
+
* fixed here and is the first thing `coding_stage` checks.
|
|
18
|
+
*/
|
|
19
|
+
export const STAGES_BY_MODE = {
|
|
20
|
+
// Auto opens only requirements because the requirements stage chooses a concrete workflow
|
|
21
|
+
// with `coding_mode`; the chosen mode then supplies its own stage set.
|
|
22
|
+
auto: ['requirements'],
|
|
23
|
+
consult: ['requirements', 'plan', 'deliver'],
|
|
24
|
+
review: ['requirements', 'verify', 'deliver'],
|
|
25
|
+
codex: ['requirements', 'plan', 'implement', 'verify', 'deliver'],
|
|
26
|
+
};
|
|
27
|
+
/** Stage at which a session of this mode starts. */
|
|
28
|
+
export function entryStage(mode) {
|
|
29
|
+
return STAGES_BY_MODE[mode][0];
|
|
30
|
+
}
|
|
31
|
+
/** Whether `stage` belongs to `mode`. */
|
|
32
|
+
export function stageInMode(mode, stage) {
|
|
33
|
+
return STAGES_BY_MODE[mode].includes(stage);
|
|
34
|
+
}
|
|
35
|
+
/** Model-facing explanation of the mode's stage set, e.g. `requirements → plan → deliver`. */
|
|
36
|
+
export function stagePath(mode) {
|
|
37
|
+
return STAGES_BY_MODE[mode].join(' → ');
|
|
38
|
+
}
|
|
39
|
+
/** The workflow and control verbs this package registers by name. */
|
|
40
|
+
export const TOOL = {
|
|
41
|
+
stage: 'coding_stage',
|
|
42
|
+
mode: 'coding_mode',
|
|
43
|
+
reasoning: 'coding_reasoning',
|
|
44
|
+
handoff: 'coding_handoff',
|
|
45
|
+
implement: 'delegate_implement',
|
|
46
|
+
verify: 'delegate_verify',
|
|
47
|
+
plan: 'delegate_plan',
|
|
48
|
+
verification: 'run_verification',
|
|
49
|
+
};
|
|
50
|
+
/** Every tool name this package owns; the Web Definition matches on exactly these. */
|
|
51
|
+
export const CODING_TOOLS = Object.values(TOOL);
|
|
52
|
+
/** Whether a model-facing tool name belongs to this package. */
|
|
53
|
+
export function isCodingTool(name) {
|
|
54
|
+
return CODING_TOOLS.includes(name);
|
|
55
|
+
}
|
|
56
|
+
const TOOL_CLASSES = {
|
|
57
|
+
read: 'read',
|
|
58
|
+
read_image: 'read',
|
|
59
|
+
glob: 'read',
|
|
60
|
+
grep: 'read',
|
|
61
|
+
web_search: 'read',
|
|
62
|
+
web_fetch: 'read',
|
|
63
|
+
job_output: 'read',
|
|
64
|
+
job_list: 'read',
|
|
65
|
+
skill: 'read',
|
|
66
|
+
list_agents: 'read',
|
|
67
|
+
list_subagent_models: 'read',
|
|
68
|
+
todo_write: 'plan',
|
|
69
|
+
write: 'write',
|
|
70
|
+
edit: 'write',
|
|
71
|
+
apply_patch: 'write',
|
|
72
|
+
bash: 'exec',
|
|
73
|
+
pwsh: 'exec',
|
|
74
|
+
job_kill: 'exec',
|
|
75
|
+
terminal_open: 'exec',
|
|
76
|
+
terminal_read: 'exec',
|
|
77
|
+
terminal_signal: 'exec',
|
|
78
|
+
run_verification: 'verify',
|
|
79
|
+
delegate_verify: 'verify',
|
|
80
|
+
delegate_implement: 'delegate',
|
|
81
|
+
delegate_plan: 'delegate',
|
|
82
|
+
coding_stage: 'stage',
|
|
83
|
+
coding_mode: 'mode',
|
|
84
|
+
coding_reasoning: 'reasoning',
|
|
85
|
+
coding_handoff: 'stage',
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Classify a tool. Unknown (third-party) tools stay `undefined`: the gate owns
|
|
89
|
+
* the coding toolset it can reason about and never silently blocks an
|
|
90
|
+
* extension whose semantics it does not know.
|
|
91
|
+
*/
|
|
92
|
+
export function toolClass(name) {
|
|
93
|
+
return TOOL_CLASSES[name];
|
|
94
|
+
}
|
|
95
|
+
/** Classes each stage admits for the lead agent. */
|
|
96
|
+
const STAGE_CLASSES = {
|
|
97
|
+
// Requirements is observation: no file mutation, no plan authoring, no verification.
|
|
98
|
+
requirements: ['read', 'exec', 'stage', 'mode', 'reasoning'],
|
|
99
|
+
// Planning may inspect and must author the structured task list.
|
|
100
|
+
plan: ['read', 'exec', 'plan', 'delegate', 'stage', 'mode', 'reasoning'],
|
|
101
|
+
// Implementation is delegated: the lead keeps only the task list and the verbs.
|
|
102
|
+
implement: ['delegate', 'plan', 'stage', 'mode', 'reasoning'],
|
|
103
|
+
// Verification is read + a structured check; delegation stays available, and
|
|
104
|
+
// the task list must be closable so a finished check does not stay running.
|
|
105
|
+
verify: ['read', 'verify', 'plan', 'stage', 'mode', 'reasoning'],
|
|
106
|
+
// Delivery reports and closes the task list; nothing may mutate source or
|
|
107
|
+
// start a fresh verification.
|
|
108
|
+
deliver: ['read', 'plan', 'stage', 'mode', 'reasoning'],
|
|
109
|
+
};
|
|
110
|
+
/** Whether `stage` admits the tool class `kind`. */
|
|
111
|
+
export function stageAdmits(stage, kind) {
|
|
112
|
+
return STAGE_CLASSES[stage].includes(kind);
|
|
113
|
+
}
|
|
114
|
+
/** Human-readable list of the classes a stage admits, for a denial message. */
|
|
115
|
+
export function stageAdmissions(stage) {
|
|
116
|
+
return STAGE_CLASSES[stage].join(', ');
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The lead's tool table during `implement`: exactly these names remain visible.
|
|
120
|
+
* Naming the allow-list (rather than denying individual tools) is what makes the
|
|
121
|
+
* trim total, including tools a later plugin registers.
|
|
122
|
+
*/
|
|
123
|
+
export const IMPLEMENT_TABLE = [
|
|
124
|
+
TOOL.implement,
|
|
125
|
+
TOOL.handoff,
|
|
126
|
+
'todo_write',
|
|
127
|
+
TOOL.stage,
|
|
128
|
+
TOOL.mode,
|
|
129
|
+
TOOL.reasoning,
|
|
130
|
+
];
|
|
131
|
+
/** The worker presets this package declares and dispatches to. */
|
|
132
|
+
export const WORKER_PRESETS = {
|
|
133
|
+
planner: 'dsh-coding-planner',
|
|
134
|
+
implement: 'dsh-coding-implement',
|
|
135
|
+
verify: 'dsh-coding-verify',
|
|
136
|
+
};
|
|
137
|
+
/** The stable route identity a session's coding run is checkpointed under. */
|
|
138
|
+
export const CHECKPOINT_VERSION = 1;
|
|
139
|
+
/**
|
|
140
|
+
* Validate one untyped value as a {@link CodingCheckpoint}. The client reads
|
|
141
|
+
* checkpoints out of `tool/result.meta`, which is durable JSON written by an
|
|
142
|
+
* arbitrary earlier build of this plugin, so every field is re-checked here.
|
|
143
|
+
*/
|
|
144
|
+
export function asCheckpoint(value) {
|
|
145
|
+
if (typeof value !== 'object' || value === null)
|
|
146
|
+
return undefined;
|
|
147
|
+
const v = value;
|
|
148
|
+
if (v['v'] !== CHECKPOINT_VERSION)
|
|
149
|
+
return undefined;
|
|
150
|
+
if (typeof v['runId'] !== 'string' || v['runId'] === '')
|
|
151
|
+
return undefined;
|
|
152
|
+
if (!isFiniteNumber(v['turn']) || !isFiniteNumber(v['step']))
|
|
153
|
+
return undefined;
|
|
154
|
+
if (!isMode(v['mode']))
|
|
155
|
+
return undefined;
|
|
156
|
+
const stage = asStage(v['stage']);
|
|
157
|
+
if (stage === undefined)
|
|
158
|
+
return undefined;
|
|
159
|
+
const allowedStages = Array.isArray(v['allowedStages'])
|
|
160
|
+
? v['allowedStages'].map(asStage)
|
|
161
|
+
: undefined;
|
|
162
|
+
if (allowedStages === undefined || allowedStages.some(item => item === undefined))
|
|
163
|
+
return undefined;
|
|
164
|
+
if (!isFiniteNumber(v['planItems']) || !isFiniteNumber(v['openPlanItems']))
|
|
165
|
+
return undefined;
|
|
166
|
+
if (!isFiniteNumber(v['edits']) || !isFiniteNumber(v['updatedAt']))
|
|
167
|
+
return undefined;
|
|
168
|
+
const files = v['files'];
|
|
169
|
+
if (files !== undefined && (!Array.isArray(files) || !files.every(item => typeof item === 'string' && item !== '')))
|
|
170
|
+
return undefined;
|
|
171
|
+
const verification = asVerification(v['verification']);
|
|
172
|
+
const worker = asWorker(v['worker']);
|
|
173
|
+
const refusal = asRefusal(v['refusal']);
|
|
174
|
+
// A handoff that is missing, stale, or malformed reads as "no handoff": a
|
|
175
|
+
// history page must not lose the whole card to junk from an earlier build.
|
|
176
|
+
const handoff = asHandoff(v['handoff']);
|
|
177
|
+
// A failure that is missing or malformed reads as "no failure", by the same
|
|
178
|
+
// tolerance: one junk field must not drop the whole card.
|
|
179
|
+
const failure = asFailure(v['failure']);
|
|
180
|
+
// The retry counters are newer fields, so absent means an older checkpoint;
|
|
181
|
+
// a present value that does not validate is a corrupt checkpoint.
|
|
182
|
+
const attemptsValue = v['verifyAttempts'];
|
|
183
|
+
const verifyAttempts = isFiniteNumber(attemptsValue) && attemptsValue >= 0 ? attemptsValue : undefined;
|
|
184
|
+
if (attemptsValue !== undefined && verifyAttempts === undefined)
|
|
185
|
+
return undefined;
|
|
186
|
+
const blockedValue = v['verifyBlocked'];
|
|
187
|
+
const verifyBlocked = asVerifyBlocked(blockedValue);
|
|
188
|
+
if (blockedValue !== undefined && verifyBlocked === undefined)
|
|
189
|
+
return undefined;
|
|
190
|
+
return {
|
|
191
|
+
v: CHECKPOINT_VERSION,
|
|
192
|
+
runId: v['runId'],
|
|
193
|
+
turn: v['turn'],
|
|
194
|
+
step: v['step'],
|
|
195
|
+
mode: v['mode'],
|
|
196
|
+
stage,
|
|
197
|
+
allowedStages: allowedStages,
|
|
198
|
+
planItems: v['planItems'],
|
|
199
|
+
openPlanItems: v['openPlanItems'],
|
|
200
|
+
edits: v['edits'],
|
|
201
|
+
...files === undefined ? {} : { files: files },
|
|
202
|
+
...verification === undefined ? {} : { verification },
|
|
203
|
+
...handoff === undefined ? {} : { handoff },
|
|
204
|
+
...verifyAttempts === undefined ? {} : { verifyAttempts },
|
|
205
|
+
...verifyBlocked === undefined ? {} : { verifyBlocked },
|
|
206
|
+
...worker === undefined ? {} : { worker },
|
|
207
|
+
...refusal === undefined ? {} : { refusal },
|
|
208
|
+
...failure === undefined ? {} : { failure },
|
|
209
|
+
updatedAt: v['updatedAt'],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/** Stage ids persisted by earlier builds, read back as their renamed current value. */
|
|
213
|
+
const LEGACY_STAGES = { recon: 'requirements' };
|
|
214
|
+
/**
|
|
215
|
+
* Read one stage value, accepting the ids an earlier build persisted. The
|
|
216
|
+
* durable projection and checkpoints store stages as strings, so a rename must
|
|
217
|
+
* keep old sessions readable.
|
|
218
|
+
* @param value - raw persisted value.
|
|
219
|
+
* @returns the current stage id, mapping legacy ids, or undefined when unknown.
|
|
220
|
+
*/
|
|
221
|
+
export function asStage(value) {
|
|
222
|
+
if (typeof value !== 'string')
|
|
223
|
+
return undefined;
|
|
224
|
+
if (CODING_STAGES.includes(value))
|
|
225
|
+
return value;
|
|
226
|
+
return LEGACY_STAGES[value];
|
|
227
|
+
}
|
|
228
|
+
function isFiniteNumber(value) {
|
|
229
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
230
|
+
}
|
|
231
|
+
function isMode(value) {
|
|
232
|
+
return typeof value === 'string' && CODING_MODES.includes(value);
|
|
233
|
+
}
|
|
234
|
+
function isStage(value) {
|
|
235
|
+
return asStage(value) !== undefined;
|
|
236
|
+
}
|
|
237
|
+
function asVerification(value) {
|
|
238
|
+
if (typeof value !== 'object' || value === null)
|
|
239
|
+
return undefined;
|
|
240
|
+
const v = value;
|
|
241
|
+
if (typeof v['passed'] !== 'boolean')
|
|
242
|
+
return undefined;
|
|
243
|
+
if (typeof v['kind'] !== 'string' || typeof v['scope'] !== 'string')
|
|
244
|
+
return undefined;
|
|
245
|
+
if (v['source'] !== 'lead' && v['source'] !== 'worker')
|
|
246
|
+
return undefined;
|
|
247
|
+
if (typeof v['command'] !== 'string' || typeof v['durationMs'] !== 'number')
|
|
248
|
+
return undefined;
|
|
249
|
+
if (!isFiniteNumber(v['ranAt']))
|
|
250
|
+
return undefined;
|
|
251
|
+
const exitCode = v['exitCode'];
|
|
252
|
+
if (exitCode !== null && typeof exitCode !== 'number')
|
|
253
|
+
return undefined;
|
|
254
|
+
return {
|
|
255
|
+
passed: v['passed'],
|
|
256
|
+
kind: v['kind'],
|
|
257
|
+
scope: v['scope'],
|
|
258
|
+
source: v['source'],
|
|
259
|
+
command: v['command'],
|
|
260
|
+
exitCode,
|
|
261
|
+
durationMs: v['durationMs'],
|
|
262
|
+
failedTests: stringArray(v['failedTests']),
|
|
263
|
+
errors: stringArray(v['errors']),
|
|
264
|
+
ranAt: v['ranAt'],
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function asWorker(value) {
|
|
268
|
+
if (typeof value !== 'object' || value === null)
|
|
269
|
+
return undefined;
|
|
270
|
+
const v = value;
|
|
271
|
+
if (v['role'] !== 'plan' && v['role'] !== 'implement' && v['role'] !== 'verify')
|
|
272
|
+
return undefined;
|
|
273
|
+
if (v['status'] !== 'running' && v['status'] !== 'completed' && v['status'] !== 'failed')
|
|
274
|
+
return undefined;
|
|
275
|
+
if (!isFiniteNumber(v['startedAt']))
|
|
276
|
+
return undefined;
|
|
277
|
+
return {
|
|
278
|
+
role: v['role'],
|
|
279
|
+
status: v['status'],
|
|
280
|
+
...typeof v['childId'] === 'string' ? { childId: v['childId'] } : {},
|
|
281
|
+
...typeof v['summary'] === 'string' ? { summary: v['summary'] } : {},
|
|
282
|
+
...Array.isArray(v['files']) ? { files: stringArray(v['files']) } : {},
|
|
283
|
+
startedAt: v['startedAt'],
|
|
284
|
+
...isFiniteNumber(v['finishedAt']) ? { finishedAt: v['finishedAt'] } : {},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function asRefusal(value) {
|
|
288
|
+
if (typeof value !== 'object' || value === null)
|
|
289
|
+
return undefined;
|
|
290
|
+
const v = value;
|
|
291
|
+
const target = asStage(v['target']);
|
|
292
|
+
if (target === undefined || typeof v['reason'] !== 'string' || !isFiniteNumber(v['at']))
|
|
293
|
+
return undefined;
|
|
294
|
+
return { target, reason: v['reason'], at: v['at'] };
|
|
295
|
+
}
|
|
296
|
+
function asVerifyBlocked(value) {
|
|
297
|
+
if (typeof value !== 'object' || value === null)
|
|
298
|
+
return undefined;
|
|
299
|
+
const v = value;
|
|
300
|
+
if (!isFiniteNumber(v['attempts']) || typeof v['reason'] !== 'string' || !isFiniteNumber(v['at']))
|
|
301
|
+
return undefined;
|
|
302
|
+
return { attempts: v['attempts'], reason: v['reason'], at: v['at'] };
|
|
303
|
+
}
|
|
304
|
+
function stringArray(value) {
|
|
305
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
|
|
306
|
+
}
|