dsh-coding 0.0.1 → 0.1.1-rc2
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/AGENTS.md +80 -0
- package/LICENSE +21 -21
- package/README.md +120 -54
- package/cordis.patch.yml +274 -4
- package/docs/CHANGELOG.md +47 -0
- package/docs/DETAIL.md +272 -0
- package/icon.svg +6 -6
- package/lib/apply-patch.js +268 -0
- package/lib/client/capsule.js +120 -0
- package/lib/client/card.js +308 -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 +170 -0
- package/lib/client/mode-picker.js +77 -0
- package/lib/client/styles.js +283 -0
- package/lib/client.js +1802 -0
- package/lib/coding-projection.js +349 -0
- package/lib/config.js +218 -0
- package/lib/contract.js +138 -0
- package/lib/editor.js +23 -0
- package/lib/failures.js +142 -0
- package/lib/handoff.js +347 -0
- package/lib/index.js +110 -7
- package/lib/language.js +136 -0
- package/lib/memory.js +336 -0
- package/lib/messages.js +43 -0
- package/lib/models.js +154 -0
- package/lib/patch.js +235 -0
- package/lib/preset.js +1552 -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 +344 -0
- package/lib/state.js +585 -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 +76 -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 +208 -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 +132 -0
- package/lib/types/index.d.ts +150 -0
- package/lib/types/language.d.ts +56 -0
- package/lib/types/memory.d.ts +71 -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 +193 -0
- package/lib/types/state.d.ts +273 -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 +84 -9
- package/lib/index.d.ts +0 -11
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-agent Coding session state: the stage machine, its gates, and the
|
|
3
|
+
* deterministic tool policy derived from them.
|
|
4
|
+
*
|
|
5
|
+
* The state is a derived cache, never the source of truth: every transition is
|
|
6
|
+
* also emitted as a whole-value checkpoint inside a Coding tool result, which
|
|
7
|
+
* the Session log keeps. A Host restart loses this object, but a resumed
|
|
8
|
+
* session reseeds it from the durable projection instead of restarting the run
|
|
9
|
+
* at the entry stage, so the card and the stage machine stay in agreement.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-coding/state
|
|
12
|
+
*/
|
|
13
|
+
import type { CodingConfig } from './config.js';
|
|
14
|
+
import type { CodingFailure } from './failures.js';
|
|
15
|
+
import { type CodingHandoff } from './handoff.js';
|
|
16
|
+
import { type CodingCheckpoint, type CodingMode, type CodingStage, type PlannerAttempt, type StageTransition, type VerificationOutcome, type WorkerRecord } from './stages.js';
|
|
17
|
+
/** One structured task-list entry, as `todo_write` records it. */
|
|
18
|
+
export interface PlanItem {
|
|
19
|
+
readonly content: string;
|
|
20
|
+
readonly status: 'pending' | 'in_progress' | 'completed';
|
|
21
|
+
}
|
|
22
|
+
/** Live state of one Coding session. */
|
|
23
|
+
export interface CodingState {
|
|
24
|
+
/** Stable identity reported with every checkpoint. */
|
|
25
|
+
runId: string;
|
|
26
|
+
readonly sessionId: string;
|
|
27
|
+
readonly startedAt: number;
|
|
28
|
+
mode: CodingMode;
|
|
29
|
+
stage: CodingStage;
|
|
30
|
+
updatedAt: number;
|
|
31
|
+
/** Latest observed turn/step, copied into every checkpoint. */
|
|
32
|
+
turn: number;
|
|
33
|
+
step: number;
|
|
34
|
+
/** Successful read/executing observations during requirements. */
|
|
35
|
+
requirementsObserved: number;
|
|
36
|
+
/** Latest `todo_write` snapshot, or undefined before the first write. */
|
|
37
|
+
plan?: {
|
|
38
|
+
readonly items: readonly PlanItem[];
|
|
39
|
+
readonly at: number;
|
|
40
|
+
};
|
|
41
|
+
/** Files the implement worker reported writing. */
|
|
42
|
+
edits: number;
|
|
43
|
+
/** Distinct paths the implement workers reported across this session. */
|
|
44
|
+
files: Set<string>;
|
|
45
|
+
/** Edit count inherited from a checkpoint that carried no `files` list. */
|
|
46
|
+
baseEdits: number;
|
|
47
|
+
worker?: WorkerRecord;
|
|
48
|
+
/** planner 派发尝试;有值即表示这个会话已经尝试过 planner(成功或失败)。 */
|
|
49
|
+
planner?: PlannerAttempt;
|
|
50
|
+
verification?: VerificationOutcome;
|
|
51
|
+
refusal?: {
|
|
52
|
+
readonly target: CodingStage;
|
|
53
|
+
readonly reason: string;
|
|
54
|
+
readonly at: number;
|
|
55
|
+
};
|
|
56
|
+
/** Bounded handoff record: the only context the planner and implement workers receive. */
|
|
57
|
+
handoff?: CodingHandoff;
|
|
58
|
+
/** Failed verifications this session spent against the retry budget. */
|
|
59
|
+
verificationAttempts: number;
|
|
60
|
+
/** Consecutive failures whose signature matched the previous one. */
|
|
61
|
+
sameFailureCount: number;
|
|
62
|
+
/** Signature of the last failed verification, for the repeat detector. */
|
|
63
|
+
lastFailureSignature?: string;
|
|
64
|
+
/** Set once the retry budget is exhausted; cleared only by a passing verification. */
|
|
65
|
+
verifyBlocked?: {
|
|
66
|
+
attempts: number;
|
|
67
|
+
reason: string;
|
|
68
|
+
at: number;
|
|
69
|
+
};
|
|
70
|
+
/** The most recent blocking exception this session has not recovered from. */
|
|
71
|
+
failure?: CodingFailure;
|
|
72
|
+
/** A blocking exception the user has not been told about yet; cleared once shown. */
|
|
73
|
+
failureNotice?: CodingFailure;
|
|
74
|
+
/** This delivery reports blocked work instead of a completed change. */
|
|
75
|
+
deliveryBlocked: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The last refusal already delivered to the model as a blocked step. It is
|
|
78
|
+
* re-injected with the next step's contract, because a rejected step keeps
|
|
79
|
+
* none of its own messages in the Inbox.
|
|
80
|
+
*/
|
|
81
|
+
lastRefusal?: string;
|
|
82
|
+
readonly transitions: StageTransition[];
|
|
83
|
+
/** Disposer of the current `allow` restriction on the lead's tool table. */
|
|
84
|
+
tableRestriction?: () => void;
|
|
85
|
+
}
|
|
86
|
+
/** Outcome of one attempted stage advance. */
|
|
87
|
+
export interface AdvanceCheck {
|
|
88
|
+
readonly ok: boolean;
|
|
89
|
+
/** A refusal that reports the next move without blocking the step (auto mode's workflow choice). */
|
|
90
|
+
readonly soft?: boolean;
|
|
91
|
+
/** The move is granted, but the run must deliver a BLOCKED report. */
|
|
92
|
+
readonly blocked?: boolean;
|
|
93
|
+
readonly reason?: string;
|
|
94
|
+
}
|
|
95
|
+
/** A denial produced by the stage policy, with the guidance the model needs. */
|
|
96
|
+
export interface ToolVerdict {
|
|
97
|
+
readonly deny?: string;
|
|
98
|
+
}
|
|
99
|
+
/** Build the initial state of a session in one mode. */
|
|
100
|
+
export declare function createState(sessionId: string, mode: CodingMode): CodingState;
|
|
101
|
+
/** The durable projection slice a resume reads; structural so the client view can be passed directly. */
|
|
102
|
+
export interface RestoreView {
|
|
103
|
+
readonly mode: CodingMode;
|
|
104
|
+
readonly stage: CodingStage;
|
|
105
|
+
readonly plan: readonly PlanItem[];
|
|
106
|
+
readonly checkpoint?: CodingCheckpoint | null;
|
|
107
|
+
readonly updatedAt: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Seed the live state from the durable projection. A resumed session must keep
|
|
111
|
+
* the stage, plan, verification, and edit evidence its Session log recorded,
|
|
112
|
+
* or the runtime would silently restart the run while the card still shows it.
|
|
113
|
+
* A refusal is deliberately not restored: an old gate rejection must not block
|
|
114
|
+
* the first step after a restart. The verification retry budget is restored
|
|
115
|
+
* from the checkpoint, while the repeat detector starts over: the signature of
|
|
116
|
+
* the failure that exhausted it is not part of the checkpoint.
|
|
117
|
+
* @param state - live state of the resumed agent (mutated).
|
|
118
|
+
* @param view - validated projection value for the same session.
|
|
119
|
+
*/
|
|
120
|
+
export declare function restoreFromView(state: CodingState, view: RestoreView): void;
|
|
121
|
+
/** Stage at which this mode's own gates can be satisfied, one line. */
|
|
122
|
+
export declare function stageGuidance(mode: CodingMode): string;
|
|
123
|
+
/** 强制 planner 的任务单阈值:严格大于三条即为“复杂任务”。 */
|
|
124
|
+
export declare const PLANNER_TODO_THRESHOLD = 3;
|
|
125
|
+
/** 调用方提供的运行时事实:纯函数拿不到主 Agent 的模型与配置。 */
|
|
126
|
+
export interface AdvanceOptions {
|
|
127
|
+
/** 主 Agent 自身模型就是配置的 planner 路由,planner 因此是多余的。 */
|
|
128
|
+
readonly leadIsPlanner?: boolean;
|
|
129
|
+
/** 配置 `requirePlanner: 'off'` 时整条门禁关闭。 */
|
|
130
|
+
readonly plannerGate?: boolean;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Decide whether the model may move to `target` now. Conditions are checked by
|
|
134
|
+
* plugin code, never taken from the model's assertion.
|
|
135
|
+
* @param state - live session state.
|
|
136
|
+
* @param target - requested stage.
|
|
137
|
+
* @param options - 调用方提供的运行时事实(主 Agent 是否即 planner 路由、门禁是否开启)。
|
|
138
|
+
* @returns whether the move is allowed, and why not when it is refused.
|
|
139
|
+
*/
|
|
140
|
+
export declare function checkAdvance(state: CodingState, target: CodingStage, options?: AdvanceOptions): AdvanceCheck;
|
|
141
|
+
/**
|
|
142
|
+
* Apply one granted stage transition.
|
|
143
|
+
* @param state - live session state (mutated).
|
|
144
|
+
* @param target - granted stage.
|
|
145
|
+
* @param reason - why the move happened, kept in the transition log.
|
|
146
|
+
*/
|
|
147
|
+
export declare function applyStage(state: CodingState, target: CodingStage, reason: string): void;
|
|
148
|
+
/** How many failures one session may spend before it must deliver blocked. */
|
|
149
|
+
export interface VerificationBudget {
|
|
150
|
+
/** Failed verifications allowed in total; `0` means no limit. */
|
|
151
|
+
readonly maxAttempts: number;
|
|
152
|
+
/** Repeats of the identical failure allowed; `0` means no limit. */
|
|
153
|
+
readonly maxSameFailure: number;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Reduce one failed verification to a comparable signature. The signature is
|
|
157
|
+
* what decides whether the lead is fixing the failure or repeating the same
|
|
158
|
+
* attempt, so it keeps only the stable parts: failing test names (sorted, the
|
|
159
|
+
* order they were reported in means nothing), the first three error lines, and
|
|
160
|
+
* the exit code.
|
|
161
|
+
* @param outcome - the verification result to fingerprint.
|
|
162
|
+
* @returns a deterministic signature string.
|
|
163
|
+
*/
|
|
164
|
+
export declare function failureSignature(outcome: VerificationOutcome): string;
|
|
165
|
+
/**
|
|
166
|
+
* Record one verification result and spend or refund the retry budget.
|
|
167
|
+
*
|
|
168
|
+
* A pass ends the loop: every counter is cleared, so the next edit starts from
|
|
169
|
+
* a clean budget. A failure increments the attempt counter and the repeat
|
|
170
|
+
* counter, and once either budget is spent it sets {@link CodingState.verifyBlocked},
|
|
171
|
+
* which is the state `checkAdvance` reads to allow the blocked delivery. A
|
|
172
|
+
* failure never clears that flag: only a passing verification does.
|
|
173
|
+
* @param state - live session state (mutated).
|
|
174
|
+
* @param outcome - the verification result.
|
|
175
|
+
* @param budget - the configured retry budget.
|
|
176
|
+
*/
|
|
177
|
+
export declare function recordVerification(state: CodingState, outcome: VerificationOutcome, budget: VerificationBudget): void;
|
|
178
|
+
/**
|
|
179
|
+
* Forget the retry budget of a run, keeping its last verification as evidence.
|
|
180
|
+
* Used by an explicit reset: the counters belong to the current fix/verify loop,
|
|
181
|
+
* not to the session's history.
|
|
182
|
+
* @param state - live session state (mutated).
|
|
183
|
+
*/
|
|
184
|
+
export declare function resetVerification(state: CodingState): void;
|
|
185
|
+
/**
|
|
186
|
+
* Record a refused advance. The next `agent/pre-step` rejects once with this
|
|
187
|
+
* reason, which is the documented penalty for skipping a gate.
|
|
188
|
+
* @param state - live session state (mutated).
|
|
189
|
+
* @param target - stage the model tried to enter.
|
|
190
|
+
* @param reason - the gate that refused it.
|
|
191
|
+
*/
|
|
192
|
+
export declare function recordRefusal(state: CodingState, target: CodingStage, reason: string): void;
|
|
193
|
+
/** Clear the one-shot refusal after the blocking step has run. */
|
|
194
|
+
export declare function clearRefusal(state: CodingState): string | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Read and clear the refusal text that rides the next step's contract. The
|
|
197
|
+
* blocked turn itself carries no messages, so this is the only way the model
|
|
198
|
+
* learns why its step was rejected.
|
|
199
|
+
* @param state - live session state.
|
|
200
|
+
* @returns the refusal text, once.
|
|
201
|
+
*/
|
|
202
|
+
export declare function takeLastRefusal(state: CodingState): string | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Record one blocking exception. It becomes the session's current failure, and
|
|
205
|
+
* is remembered as a notice the next step delivers once.
|
|
206
|
+
* @param state - live session state (mutated).
|
|
207
|
+
* @param failure - the report built at the failing dispatch point.
|
|
208
|
+
*/
|
|
209
|
+
export declare function recordFailure(state: CodingState, failure: CodingFailure): void;
|
|
210
|
+
/**
|
|
211
|
+
* Read and clear the notice that rides the next step's contract. A failure is
|
|
212
|
+
* reported to the user exactly once, so the same mechanism cannot flood the
|
|
213
|
+
* conversation with a repeated card.
|
|
214
|
+
* @param state - live session state (mutated).
|
|
215
|
+
* @returns the failure to announce, once.
|
|
216
|
+
*/
|
|
217
|
+
export declare function takeFailureNotice(state: CodingState): CodingFailure | undefined;
|
|
218
|
+
/**
|
|
219
|
+
* Forget a failure once its subsystem works again. Only the matching point is
|
|
220
|
+
* cleared, so recovering one subsystem cannot hide a different, still-current
|
|
221
|
+
* interruption.
|
|
222
|
+
* @param state - live session state (mutated).
|
|
223
|
+
* @param point - the dispatch point whose retry just succeeded.
|
|
224
|
+
*/
|
|
225
|
+
export declare function clearFailure(state: CodingState, point: CodingFailure['point']): void;
|
|
226
|
+
/**
|
|
227
|
+
* Switch mode. A stage the new mode does not open resets to that mode's entry
|
|
228
|
+
* stage, so a mode switch can never leave the session in a stage its mode
|
|
229
|
+
* forbids.
|
|
230
|
+
* @param state - live session state (mutated).
|
|
231
|
+
* @param mode - requested mode.
|
|
232
|
+
* @returns the resulting stage.
|
|
233
|
+
*/
|
|
234
|
+
export declare function applyMode(state: CodingState, mode: CodingMode): CodingStage;
|
|
235
|
+
/**
|
|
236
|
+
* The single policy decision shared by the friendly waterfall listener and the
|
|
237
|
+
* monotonic guard. Both evaluate this function, so they can never disagree.
|
|
238
|
+
* @param state - live session state of the calling agent.
|
|
239
|
+
* @param toolName - tool being dispatched.
|
|
240
|
+
* @returns a denial message, or an empty verdict when the call may proceed.
|
|
241
|
+
*/
|
|
242
|
+
export declare function checkTool(state: CodingState, toolName: string): ToolVerdict;
|
|
243
|
+
/**
|
|
244
|
+
* Whether the lead's tool table must be trimmed to the delegation set. In the
|
|
245
|
+
* implement stage the model keeps only the delegation verbs: the edit tools are
|
|
246
|
+
* removed from the presentation table, not merely denied at dispatch.
|
|
247
|
+
* @param stage - current stage.
|
|
248
|
+
* @returns the allow-list to apply, or undefined when the table stays whole.
|
|
249
|
+
*/
|
|
250
|
+
export declare function tableTrim(stage: CodingStage): readonly string[] | undefined;
|
|
251
|
+
/** Render the model-facing status line injected before every step. */
|
|
252
|
+
export declare function statusLine(state: CodingState): string;
|
|
253
|
+
/** Build the whole-value checkpoint published with a Coding tool result. */
|
|
254
|
+
export declare function checkpointOf(state: CodingState): CodingCheckpoint;
|
|
255
|
+
/** Per-session state store keyed by the live Agent, with a session-id index. */
|
|
256
|
+
export declare class CodingStateStore {
|
|
257
|
+
private readonly config;
|
|
258
|
+
private readonly byAgent;
|
|
259
|
+
private readonly bySession;
|
|
260
|
+
constructor(config: () => CodingConfig);
|
|
261
|
+
/** Read an agent's state without creating one. */
|
|
262
|
+
peek(agent: object | undefined): CodingState | undefined;
|
|
263
|
+
/** Read the live state for a session id, for `session/event` folds. */
|
|
264
|
+
bySessionId(sessionId: string): CodingState | undefined;
|
|
265
|
+
/** Read or create the state of one lead agent. */
|
|
266
|
+
ensure(agent: object, sessionId: string): CodingState;
|
|
267
|
+
/** Forget one agent's state, releasing its tool-table restriction. */
|
|
268
|
+
release(agent: object, sessionId: string | undefined): void;
|
|
269
|
+
}
|
|
270
|
+
/** Read a session id from a live Agent without importing the runtime class. */
|
|
271
|
+
export declare function sessionIdOf(agent: object | undefined): string | undefined;
|
|
272
|
+
/** Whether the agent is the lead of its own conversation (never a delegated child). */
|
|
273
|
+
export declare function isLeadAgent(agent: object | undefined): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse `defaults read -g AppleLanguages`, a NeXTSTEP property-list array of
|
|
3
|
+
* quoted BCP 47 tags such as `("zh-Hans-CN", "en-US")`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseAppleLanguages(output: string): readonly string[];
|
|
6
|
+
/**
|
|
7
|
+
* OS interface languages in preference order. Empty on platforms whose Node
|
|
8
|
+
* runtime already follows the system locale.
|
|
9
|
+
*/
|
|
10
|
+
export declare function systemLanguages(): readonly string[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type CodingConfig, type VerificationKind, type VerificationScope } from './config.js';
|
|
2
|
+
import { type VerificationRun } from './verification.js';
|
|
3
|
+
/** The tool's JSON value: the structured outcome the model and the gate read. */
|
|
4
|
+
export interface VerificationToolValue {
|
|
5
|
+
readonly passed: boolean;
|
|
6
|
+
readonly kind: VerificationKind;
|
|
7
|
+
readonly scope: VerificationScope;
|
|
8
|
+
readonly command: string;
|
|
9
|
+
readonly exitCode: number | null;
|
|
10
|
+
readonly durationMs: number;
|
|
11
|
+
readonly ranAt: number;
|
|
12
|
+
readonly failedTests: readonly string[];
|
|
13
|
+
readonly errors: readonly string[];
|
|
14
|
+
readonly output: string;
|
|
15
|
+
/** Whole-value coding checkpoint, attached only by the lead wrapper. */
|
|
16
|
+
readonly checkpoint?: unknown;
|
|
17
|
+
}
|
|
18
|
+
/** Registration options for {@link registerVerificationTool}. */
|
|
19
|
+
export interface VerificationToolOptions {
|
|
20
|
+
/** Read the live plugin configuration. */
|
|
21
|
+
readonly config: () => CodingConfig;
|
|
22
|
+
/** Record a completed run (the lead's stage machine); the worker omits it. */
|
|
23
|
+
readonly onRun?: (run: VerificationRun, exec: any) => void;
|
|
24
|
+
/** Attach the whole-value checkpoint to the tool value. */
|
|
25
|
+
readonly decorate?: (exec: any) => unknown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Register `run_verification` in one scope.
|
|
29
|
+
* @param ctx - scope that owns the registration (and therefore its disposal).
|
|
30
|
+
* @param options - configuration access and the optional state recorder.
|
|
31
|
+
*/
|
|
32
|
+
export declare function registerVerificationTool(ctx: any, options: VerificationToolOptions): void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type CodingConfig, type VerificationKind, type VerificationScope } from './config.js';
|
|
2
|
+
import type { VerificationOutcome } from './stages.js';
|
|
3
|
+
/** Package managers this resolver understands. */
|
|
4
|
+
export type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
|
|
5
|
+
/** One resolved verification command and where it runs. */
|
|
6
|
+
export interface ResolvedCommand {
|
|
7
|
+
readonly command: string;
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
readonly script?: string;
|
|
10
|
+
readonly packageManager?: PackageManager;
|
|
11
|
+
}
|
|
12
|
+
/** Full result of one verification run: the gate outcome plus model-facing text. */
|
|
13
|
+
export interface VerificationRun extends VerificationOutcome {
|
|
14
|
+
/** Bounded combined output, for the model-facing result. */
|
|
15
|
+
readonly output: string;
|
|
16
|
+
}
|
|
17
|
+
/** Failure raised before or during a verification run, with an actionable message. */
|
|
18
|
+
export declare class VerificationError extends Error {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the concrete command for a verification request.
|
|
23
|
+
* @param config - plugin configuration, whose overrides win over detection.
|
|
24
|
+
* @param cwd - session working directory.
|
|
25
|
+
* @param kind - requested verification kind.
|
|
26
|
+
* @param scope - requested scope; `full` runs from the repository root.
|
|
27
|
+
* @returns the resolved command and directory.
|
|
28
|
+
* @throws {VerificationError} when neither configuration nor the project can supply a command.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveVerification(config: CodingConfig, cwd: string, kind: VerificationKind, scope: VerificationScope): Promise<ResolvedCommand>;
|
|
31
|
+
/** Parse runner output into failing test names and the most useful error lines. */
|
|
32
|
+
export declare function parseFailure(kind: VerificationKind, stdout: string, stderr: string): {
|
|
33
|
+
failedTests: string[];
|
|
34
|
+
errors: string[];
|
|
35
|
+
};
|
|
36
|
+
/** Narrow a service-shaped value to the subprocess surface this module needs. */
|
|
37
|
+
export interface SubprocessLike {
|
|
38
|
+
spawn(spec: unknown): {
|
|
39
|
+
readonly done: Promise<{
|
|
40
|
+
exitCode: number | null;
|
|
41
|
+
signal: string | null;
|
|
42
|
+
}>;
|
|
43
|
+
readonly collected: {
|
|
44
|
+
readonly stdout?: {
|
|
45
|
+
readFrom(offset: number): {
|
|
46
|
+
text: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
readonly stderr?: {
|
|
50
|
+
readFrom(offset: number): {
|
|
51
|
+
text: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The seam's termination verb (synchronous, idempotent). Optional here so a
|
|
57
|
+
* narrow fake or an older provider still satisfies the contract.
|
|
58
|
+
*/
|
|
59
|
+
terminate?(): void;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Run one verification through the mounted subprocess provider.
|
|
64
|
+
* @param subprocess - the `ctx.subprocess` Service Definition.
|
|
65
|
+
* @param resolved - resolved command and directory.
|
|
66
|
+
* @param kind - requested kind, recorded in the outcome and used for parsing.
|
|
67
|
+
* @param scope - requested scope, recorded in the outcome.
|
|
68
|
+
* @param source - which agent asked for the check, recorded in the outcome.
|
|
69
|
+
* @param signal - caller cancellation; aborts the managed process range.
|
|
70
|
+
* @param timeoutMs - hard deadline of the command in milliseconds; once it
|
|
71
|
+
* elapses the managed range is terminated and the run is reported as a failed
|
|
72
|
+
* verification. `0` disables the deadline.
|
|
73
|
+
* @returns the structured outcome.
|
|
74
|
+
*/
|
|
75
|
+
export declare function executeVerification(subprocess: SubprocessLike, resolved: ResolvedCommand, kind: VerificationKind, scope: VerificationScope, source: 'lead' | 'worker', signal: AbortSignal | undefined, timeoutMs: number): Promise<VerificationRun>;
|
|
76
|
+
/** Render the model-facing result of one verification. */
|
|
77
|
+
export declare function renderVerification(run: VerificationRun): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
2
|
+
export declare const name = "dsh-coding-verifier";
|
|
3
|
+
/** The registry and the shared bundle settings are required; `subprocess` is awaited. */
|
|
4
|
+
export declare const inject: string[];
|
|
5
|
+
/**
|
|
6
|
+
* Register `run_verification` in the verify worker's scope.
|
|
7
|
+
* @param ctx - the worker preset's scope context.
|
|
8
|
+
*/
|
|
9
|
+
export declare function apply(ctx: any): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small helper for reading Schemastery volatile values.
|
|
3
|
+
*
|
|
4
|
+
* It lives in its own module on purpose: a plugin reload after editing a shared
|
|
5
|
+
* module can keep the old generation of that module cached, so a newly exported
|
|
6
|
+
* symbol must come from a new file to be importable without a full restart.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-coding/volatile
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Read one configured value through a Schemastery volatile accessor, or use it
|
|
12
|
+
* directly when the caller passed a plain object (direct `apply()` in tests, or
|
|
13
|
+
* a schema generation that did not mark the field volatile).
|
|
14
|
+
* @param value - schema-resolved value or `Volatile` wrapper.
|
|
15
|
+
* @returns the current raw value.
|
|
16
|
+
*/
|
|
17
|
+
export declare function volatileValue(value: unknown): unknown;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `run_verification` tool, shared by the lead preset and the verify worker.
|
|
3
|
+
*
|
|
4
|
+
* The lead wrapper records the outcome in the stage machine; the worker wrapper
|
|
5
|
+
* reports it back through `structured_output`. Both call the same resolver and
|
|
6
|
+
* the same `ctx.subprocess` execution, so a swap of the subprocess provider
|
|
7
|
+
* changes neither contract.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-coding/verification-tool
|
|
10
|
+
*/
|
|
11
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
12
|
+
import { VERIFICATION_KINDS, VERIFICATION_SCOPES, } from './config.js';
|
|
13
|
+
import { TOOL } from './stages.js';
|
|
14
|
+
import { VerificationError, executeVerification, renderVerification, resolveVerification, } from './verification.js';
|
|
15
|
+
/** Resolve the session's working directory, falling back to its header. */
|
|
16
|
+
async function sessionCwd(ctx, agent, signal) {
|
|
17
|
+
const workingDirectory = ctx.get?.('workingDirectory');
|
|
18
|
+
if (typeof workingDirectory?.ensure === 'function') {
|
|
19
|
+
try {
|
|
20
|
+
const value = await workingDirectory.ensure(agent, signal);
|
|
21
|
+
if (typeof value === 'string' && value !== '')
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// The session header remains the fallback.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const cwd = agent?.session?.header?.cwd;
|
|
29
|
+
return typeof cwd === 'string' && cwd !== '' ? cwd : process.cwd();
|
|
30
|
+
}
|
|
31
|
+
/** The tool description, kept short enough to ride in every request. */
|
|
32
|
+
const DESCRIPTION = [
|
|
33
|
+
'Run one verification through the project\'s own tooling and record the structured result.',
|
|
34
|
+
'Resolve the command from the package scripts (or the plugin\'s verificationCommands override),',
|
|
35
|
+
'execute it through the subprocess provider, and return pass/fail, failing tests, key errors, exit code, and duration.',
|
|
36
|
+
'Use the narrowest scope that proves the change: targeted, then package, then full.',
|
|
37
|
+
'A failing result blocks the deliver stage until a later run passes.',
|
|
38
|
+
'Each command is bounded by the plugin\'s verificationTimeoutMs.',
|
|
39
|
+
].join(' ');
|
|
40
|
+
/** Author-facing output schema: requiredness is a per-property annotation here. */
|
|
41
|
+
const OUTPUT_SCHEMA = {
|
|
42
|
+
type: 'object',
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
properties: {
|
|
45
|
+
passed: { type: 'boolean', required: true },
|
|
46
|
+
kind: { type: 'string', required: true },
|
|
47
|
+
scope: { type: 'string', required: true },
|
|
48
|
+
command: { type: 'string', required: true },
|
|
49
|
+
exitCode: { oneOf: [{ type: 'number' }, { type: 'null' }] },
|
|
50
|
+
durationMs: { type: 'number', required: true },
|
|
51
|
+
ranAt: { type: 'number', required: true },
|
|
52
|
+
failedTests: { type: 'array', items: { type: 'string' } },
|
|
53
|
+
errors: { type: 'array', items: { type: 'string' } },
|
|
54
|
+
output: { type: 'string', required: true },
|
|
55
|
+
checkpoint: { type: 'json' },
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Register `run_verification` in one scope.
|
|
60
|
+
* @param ctx - scope that owns the registration (and therefore its disposal).
|
|
61
|
+
* @param options - configuration access and the optional state recorder.
|
|
62
|
+
*/
|
|
63
|
+
export function registerVerificationTool(ctx, options) {
|
|
64
|
+
const tool = defineTool({
|
|
65
|
+
name: TOOL.verification,
|
|
66
|
+
description: DESCRIPTION,
|
|
67
|
+
parameters: {
|
|
68
|
+
kind: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
enum: [...VERIFICATION_KINDS],
|
|
71
|
+
required: true,
|
|
72
|
+
description: 'test | build | lint | typecheck',
|
|
73
|
+
},
|
|
74
|
+
scope: {
|
|
75
|
+
type: 'string',
|
|
76
|
+
enum: [...VERIFICATION_SCOPES],
|
|
77
|
+
required: true,
|
|
78
|
+
description: 'targeted/package (nearest package root) | full (repository root)',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
output: {
|
|
82
|
+
schema: OUTPUT_SCHEMA,
|
|
83
|
+
render: (_args, value) => [{
|
|
84
|
+
type: 'text',
|
|
85
|
+
text: renderVerification({
|
|
86
|
+
passed: value.passed,
|
|
87
|
+
kind: value.kind,
|
|
88
|
+
scope: value.scope,
|
|
89
|
+
source: 'lead',
|
|
90
|
+
command: value.command,
|
|
91
|
+
exitCode: value.exitCode,
|
|
92
|
+
durationMs: value.durationMs,
|
|
93
|
+
failedTests: value.failedTests,
|
|
94
|
+
errors: value.errors,
|
|
95
|
+
ranAt: value.ranAt,
|
|
96
|
+
output: value.output,
|
|
97
|
+
}),
|
|
98
|
+
}],
|
|
99
|
+
...options.decorate === undefined ? {} : {
|
|
100
|
+
presentationMeta: (_args, value) => (value.checkpoint === undefined ? null : value.checkpoint),
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
timeoutMs: 1_800_000,
|
|
104
|
+
async execute(args, exec) {
|
|
105
|
+
if (exec.agent === undefined)
|
|
106
|
+
throw new Error('run_verification requires an owning agent session');
|
|
107
|
+
const kind = args?.kind;
|
|
108
|
+
const scope = args?.scope;
|
|
109
|
+
if (kind === undefined || !VERIFICATION_KINDS.includes(kind)) {
|
|
110
|
+
throw new VerificationError(`kind must be one of ${VERIFICATION_KINDS.join(', ')}`);
|
|
111
|
+
}
|
|
112
|
+
if (scope === undefined || !VERIFICATION_SCOPES.includes(scope)) {
|
|
113
|
+
throw new VerificationError(`scope must be one of ${VERIFICATION_SCOPES.join(', ')}`);
|
|
114
|
+
}
|
|
115
|
+
const subprocess = ctx.get?.('subprocess');
|
|
116
|
+
if (subprocess === undefined || typeof subprocess.spawn !== 'function') {
|
|
117
|
+
throw new VerificationError('the `subprocess` service is unavailable in this deployment');
|
|
118
|
+
}
|
|
119
|
+
const cwd = await sessionCwd(ctx, exec.agent, exec.signal);
|
|
120
|
+
const startedAt = Date.now();
|
|
121
|
+
let resolved;
|
|
122
|
+
try {
|
|
123
|
+
resolved = await resolveVerification(options.config(), cwd, kind, scope);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
// A missing command is still evidence: record why the check could not
|
|
127
|
+
// run, so a review-mode delivery can disclose it instead of dead-locking.
|
|
128
|
+
options.onRun?.(unavailableRun(kind, scope, error, startedAt), exec);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
let run;
|
|
132
|
+
try {
|
|
133
|
+
run = await executeVerification(subprocess, resolved, kind, scope, 'lead', exec.signal, options.config().verificationTimeoutMs);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
options.onRun?.(unavailableRun(kind, scope, error, startedAt), exec);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
options.onRun?.(run, exec);
|
|
140
|
+
const value = {
|
|
141
|
+
passed: run.passed,
|
|
142
|
+
kind: run.kind,
|
|
143
|
+
scope: run.scope,
|
|
144
|
+
command: run.command,
|
|
145
|
+
exitCode: run.exitCode,
|
|
146
|
+
durationMs: run.durationMs,
|
|
147
|
+
ranAt: run.ranAt,
|
|
148
|
+
failedTests: run.failedTests,
|
|
149
|
+
errors: run.errors,
|
|
150
|
+
output: run.output,
|
|
151
|
+
...options.decorate === undefined ? {} : { checkpoint: options.decorate(exec) },
|
|
152
|
+
};
|
|
153
|
+
return value;
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
ctx.effect(() => ctx.tools.register(tool), 'dsh-coding: run_verification');
|
|
157
|
+
}
|
|
158
|
+
/** A recorded outcome for a check that could not even start or run. */
|
|
159
|
+
function unavailableRun(kind, scope, error, startedAt) {
|
|
160
|
+
return {
|
|
161
|
+
passed: false,
|
|
162
|
+
kind,
|
|
163
|
+
scope,
|
|
164
|
+
source: 'lead',
|
|
165
|
+
command: '',
|
|
166
|
+
exitCode: null,
|
|
167
|
+
durationMs: Date.now() - startedAt,
|
|
168
|
+
failedTests: [],
|
|
169
|
+
errors: [messageOf(error)],
|
|
170
|
+
ranAt: startedAt,
|
|
171
|
+
output: '',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function messageOf(error) {
|
|
175
|
+
return error instanceof Error ? error.message : String(error);
|
|
176
|
+
}
|