dsh-coding 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +91 -2
- package/cordis.patch.yml +233 -0
- package/docs/DETAIL.md +183 -0
- package/docs/DEVELOPMENT.md +189 -0
- package/icon.svg +6 -0
- 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 +115 -0
- 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 +7 -0
- package/locale/zh.json +7 -0
- package/package.json +129 -3
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker model routing: one place that names the configured route of a worker
|
|
3
|
+
* role, resolves it, and proves it usable before dispatch.
|
|
4
|
+
*
|
|
5
|
+
* A worker must never fall back to the lead's own model, so the route is read
|
|
6
|
+
* from the configuration field named by the role, validated as `provider/model`,
|
|
7
|
+
* and checked against the live provider registry and model catalog before the
|
|
8
|
+
* subagent starts. Every lookup here goes to the live service: configuration is
|
|
9
|
+
* volatile and may change between two dispatches, so nothing is cached.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-coding/models
|
|
12
|
+
*/
|
|
13
|
+
import { type CodingConfig, type WorkerRoute } from './config.js';
|
|
14
|
+
/** The worker roles this package dispatches. */
|
|
15
|
+
export type WorkerRole = 'plan' | 'implement' | 'verify';
|
|
16
|
+
/** Every worker role, in dispatch order. */
|
|
17
|
+
export declare const WORKER_ROLES: readonly WorkerRole[];
|
|
18
|
+
/** One worker route with the configuration field and role it came from. */
|
|
19
|
+
export interface ResolvedWorkerRoute extends WorkerRoute {
|
|
20
|
+
readonly role: WorkerRole;
|
|
21
|
+
/** Configuration field the route was read from, for an actionable failure. */
|
|
22
|
+
readonly field: string;
|
|
23
|
+
/** The route as `provider/model`, safe to quote in a message. */
|
|
24
|
+
readonly text: string;
|
|
25
|
+
}
|
|
26
|
+
/** Why a worker route cannot be dispatched. */
|
|
27
|
+
export type WorkerModelErrorCode = 'PROVIDER_MISSING' | 'MODEL_UNAVAILABLE';
|
|
28
|
+
/** The configuration field holding one role's route. */
|
|
29
|
+
export declare function workerField(role: WorkerRole): 'plannerWorkerModel' | 'implementWorkerModel' | 'verifyWorkerModel';
|
|
30
|
+
/** The preset id a worker role is dispatched with. */
|
|
31
|
+
export declare function workerPreset(role: WorkerRole): string;
|
|
32
|
+
/**
|
|
33
|
+
* Read, validate, and describe one role's configured route.
|
|
34
|
+
* @param config - verified configuration.
|
|
35
|
+
* @param role - worker about to be dispatched.
|
|
36
|
+
* @returns the parsed route plus its role, field, and rendered text.
|
|
37
|
+
* @throws when the field is not exactly `provider/model`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveWorkerRoute(config: CodingConfig, role: WorkerRole): ResolvedWorkerRoute;
|
|
40
|
+
/** A refused worker route: the configured value, and what the runtime offers instead. */
|
|
41
|
+
export declare class WorkerModelError extends Error {
|
|
42
|
+
readonly code: WorkerModelErrorCode;
|
|
43
|
+
readonly role: WorkerRole;
|
|
44
|
+
readonly field: string;
|
|
45
|
+
readonly route: string;
|
|
46
|
+
readonly available: readonly string[];
|
|
47
|
+
constructor(message: string, details: {
|
|
48
|
+
code: WorkerModelErrorCode;
|
|
49
|
+
role: WorkerRole;
|
|
50
|
+
field: string;
|
|
51
|
+
route: string;
|
|
52
|
+
available: readonly string[];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The provider ids the runtime currently registers, sorted.
|
|
57
|
+
* @param ctx - plugin context (or any object exposing the `llm` service).
|
|
58
|
+
* @returns the ids, or [] when the registry cannot be read.
|
|
59
|
+
*/
|
|
60
|
+
export declare function describeProviders(ctx: any): string[];
|
|
61
|
+
/**
|
|
62
|
+
* The model ids one provider advertises, deduplicated and sorted.
|
|
63
|
+
* @param ctx - plugin context (or any object exposing the `llm` service).
|
|
64
|
+
* @param provider - provider id being inspected.
|
|
65
|
+
* @param signal - caller's abort signal; an aborted call lists nothing.
|
|
66
|
+
* @returns the ids, or [] when the catalog is unavailable.
|
|
67
|
+
*/
|
|
68
|
+
export declare function listModelIds(ctx: any, provider: string, signal?: AbortSignal): Promise<string[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Refuse a worker dispatch whose configured route cannot be honoured.
|
|
71
|
+
*
|
|
72
|
+
* The check is deliberately narrow: an unreachable catalog defers to the
|
|
73
|
+
* dispatch instead of blocking it, because listing models may need credentials
|
|
74
|
+
* that the worker itself will supply. A registered-provider mismatch and a
|
|
75
|
+
* failing `resolveModelInfo` are both refusals, with the available alternatives
|
|
76
|
+
* named in the message.
|
|
77
|
+
* @param ctx - plugin context (or any object exposing the `llm` service).
|
|
78
|
+
* @param route - resolved route of the worker about to run.
|
|
79
|
+
* @param signal - caller's abort signal; an abort is rethrown untouched.
|
|
80
|
+
* @throws {WorkerModelError} when the provider is missing or the model unusable.
|
|
81
|
+
*/
|
|
82
|
+
export declare function assertWorkerModel(ctx: any, route: ResolvedWorkerRoute, signal?: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser and line-oriented applicator for the Codex `apply_patch` language.
|
|
3
|
+
*
|
|
4
|
+
* The format is a small, strict contract on purpose: it keeps edits reviewable,
|
|
5
|
+
* lets one call update several files, and gives a precise mismatch report when
|
|
6
|
+
* the model's context is stale.
|
|
7
|
+
*/
|
|
8
|
+
export type PatchLineKind = 'context' | 'add' | 'delete';
|
|
9
|
+
export interface PatchLine {
|
|
10
|
+
kind: PatchLineKind;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PatchHunk {
|
|
14
|
+
/** Optional @@ context label from the patch header. */
|
|
15
|
+
context?: string;
|
|
16
|
+
lines: PatchLine[];
|
|
17
|
+
/** Anchor this hunk to the end of the file instead of searching from the cursor. */
|
|
18
|
+
endOfFile: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type PatchFile = {
|
|
21
|
+
kind: 'add';
|
|
22
|
+
path: string;
|
|
23
|
+
content: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'delete';
|
|
26
|
+
path: string;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'update';
|
|
29
|
+
path: string;
|
|
30
|
+
moveTo?: string;
|
|
31
|
+
hunks: PatchHunk[];
|
|
32
|
+
};
|
|
33
|
+
export declare const APPLY_PATCH_DESCRIPTION: string;
|
|
34
|
+
/** Parse one complete Codex patch after normalizing CRLF input to LF. */
|
|
35
|
+
export declare function parsePatch(input: string): PatchFile[];
|
|
36
|
+
/** Apply parsed update hunks and return LF-normalized text. */
|
|
37
|
+
export declare function applyHunks(original: string, hunks: readonly PatchHunk[], label?: string): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
2
|
+
export declare const name = "dsh-coding-preset";
|
|
3
|
+
/**
|
|
4
|
+
* Hard dependencies: this preset cannot honour its own gates without the
|
|
5
|
+
* delegation backend or the structured verifier, so it fails loudly instead of
|
|
6
|
+
* silently downgrading to advice. The preset registry is deliberately NOT a
|
|
7
|
+
* dependency: the worker preset is selected through `ctx.subagents`, and a
|
|
8
|
+
* preset-scope plugin should not need the registry that mounted it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const inject: string[];
|
|
11
|
+
/**
|
|
12
|
+
* One-line catalog label for a dispatched worker: the role plus the brief's
|
|
13
|
+
* first non-empty line, collapsed and capped. The catalog keeps every child for
|
|
14
|
+
* the life of the session, so the label is what lets a reader tell two runs
|
|
15
|
+
* apart.
|
|
16
|
+
* @param role - worker role.
|
|
17
|
+
* @param task - the brief the lead handed the worker.
|
|
18
|
+
* @returns a single-line label no longer than the cap plus its role prefix.
|
|
19
|
+
*/
|
|
20
|
+
export declare function workerLabel(role: 'plan' | 'implement' | 'verify', task: string): string;
|
|
21
|
+
/** The Coding runtime plugin body. */
|
|
22
|
+
export declare function apply(ctx: any): Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three Coding reasoning levels and the pure mapping between a level and a
|
|
3
|
+
* provider effort id.
|
|
4
|
+
*
|
|
5
|
+
* Dependency-free on purpose: the Host controller and the browser card both
|
|
6
|
+
* import this module, so it must never pull in a Node-only package.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-coding/reasoning-levels
|
|
9
|
+
*/
|
|
10
|
+
/** The three Coding levels a decision can name. */
|
|
11
|
+
export type ReasoningLevel = 'low' | 'high' | 'max';
|
|
12
|
+
/** Rank a level so plan growth can only escalate inside one turn. */
|
|
13
|
+
export declare function rank(level: ReasoningLevel): number;
|
|
14
|
+
export declare function higher(a: ReasoningLevel, b: ReasoningLevel): ReasoningLevel;
|
|
15
|
+
/**
|
|
16
|
+
* Map a provider effort id back to the Coding level it stands for. The chat
|
|
17
|
+
* box reports provider ids (`minimal`, `medium`, `xhigh`), while this preset
|
|
18
|
+
* reasons in `low`/`high`/`max`; unknown ids stay at the conservative default.
|
|
19
|
+
*/
|
|
20
|
+
export declare function levelForEffort(effort: string): ReasoningLevel;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ReasoningLevel } from './reasoning-levels.js';
|
|
2
|
+
/** Projection key shared by the Host fold and the Web card. */
|
|
3
|
+
export declare const REASONING_PROJECTION_KEY: "dshCodingReasoning";
|
|
4
|
+
/** The reasoning state one closed turn ran under, for its own card. */
|
|
5
|
+
export interface ReasoningTurn {
|
|
6
|
+
readonly turn: number;
|
|
7
|
+
/** Level pinned via `coding_reasoning`; null when automatic. */
|
|
8
|
+
readonly override: ReasoningLevel | null;
|
|
9
|
+
/** Effort the user picked in the chat box, verbatim. */
|
|
10
|
+
readonly userEffort: string | null;
|
|
11
|
+
/** Provider effort id from the most recent request header, verbatim. */
|
|
12
|
+
readonly effort: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** The durable reasoning choice of one session. */
|
|
15
|
+
export interface ReasoningProjectionState {
|
|
16
|
+
/** Level pinned by `coding_reasoning`; null when automatic. */
|
|
17
|
+
readonly override: ReasoningLevel | null;
|
|
18
|
+
/**
|
|
19
|
+
* Effort the user picked in the chat box (`model/selection`), verbatim. It
|
|
20
|
+
* wins over the automatic classifier until the user changes it again or a
|
|
21
|
+
* `coding_reasoning` call replaces it.
|
|
22
|
+
*/
|
|
23
|
+
readonly userEffort: string | null;
|
|
24
|
+
/** Provider effort id from the most recent request header, verbatim. */
|
|
25
|
+
readonly effort: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* True while a turn is open. This plugin writes its automatic level through
|
|
28
|
+
* `model/selection`, the same event the chat box uses; an effort-bearing
|
|
29
|
+
* selection folded while a turn is running is that automatic write, not a
|
|
30
|
+
* user pick. A selection without an effort is always an explicit hand-back
|
|
31
|
+
* to automatic — this plugin never writes one — so it folds even mid-turn.
|
|
32
|
+
*/
|
|
33
|
+
readonly running: boolean;
|
|
34
|
+
/** Highest turn the log has reached; its card reads the live state. */
|
|
35
|
+
readonly latest: number;
|
|
36
|
+
/** Reasoning state as of each completed turn, oldest first. */
|
|
37
|
+
readonly turns: readonly ReasoningTurn[];
|
|
38
|
+
}
|
|
39
|
+
declare module '@deepseek-ai/dsh-session-projection/types' {
|
|
40
|
+
interface SessionProjectionMap {
|
|
41
|
+
dshCodingReasoning: SessionProjectionSummaryExcluded<ReasoningProjectionState>;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Read a session override from a `coding_reasoning` tool call's JSON arguments. */
|
|
45
|
+
export declare function overrideFromToolArguments(raw: unknown): ReasoningLevel | 'auto' | undefined;
|
|
46
|
+
/** Validate one persisted or wire value as {@link ReasoningProjectionState}. */
|
|
47
|
+
declare function parseState(value: unknown): ReasoningProjectionState;
|
|
48
|
+
export declare const reasoningProjection: {
|
|
49
|
+
key: "dshCodingReasoning";
|
|
50
|
+
stateVersion: number;
|
|
51
|
+
stateSchema: {
|
|
52
|
+
parse: typeof parseState;
|
|
53
|
+
};
|
|
54
|
+
init: () => ReasoningProjectionState;
|
|
55
|
+
apply: (state: ReasoningProjectionState, event: unknown) => ReasoningProjectionState;
|
|
56
|
+
wire: {
|
|
57
|
+
viewSchema: {
|
|
58
|
+
parse: typeof parseState;
|
|
59
|
+
};
|
|
60
|
+
view: (state: ReasoningProjectionState) => ReasoningProjectionState;
|
|
61
|
+
summary: boolean;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { CodingConfig } from './config.js';
|
|
2
|
+
import { type ReasoningLevel } from './reasoning-levels.js';
|
|
3
|
+
export { higher, levelForEffort, rank, type ReasoningLevel } from './reasoning-levels.js';
|
|
4
|
+
/** One classification decision, kept for the tool and the status line. */
|
|
5
|
+
export interface ReasoningChoice {
|
|
6
|
+
level: ReasoningLevel;
|
|
7
|
+
score: number;
|
|
8
|
+
reason: string;
|
|
9
|
+
/** Provider effort id picked in the chat box; overrides `level`. */
|
|
10
|
+
effort?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Where the current level came from, for `coding_reasoning`. */
|
|
13
|
+
export interface ReasoningSummary {
|
|
14
|
+
readonly source: 'auto' | 'manual';
|
|
15
|
+
readonly level?: ReasoningLevel;
|
|
16
|
+
readonly reason?: string;
|
|
17
|
+
}
|
|
18
|
+
/** What the controller needs from the session state machine. */
|
|
19
|
+
export interface ReasoningHooks {
|
|
20
|
+
/** Latest observed turn number for one lead agent. */
|
|
21
|
+
turnOf(agent: any): number;
|
|
22
|
+
/** Latest durable task list for one lead agent. */
|
|
23
|
+
planOf(agent: any): readonly {
|
|
24
|
+
status: string;
|
|
25
|
+
}[];
|
|
26
|
+
}
|
|
27
|
+
/** Latest direct user message in a message batch, excluding injected context. */
|
|
28
|
+
export declare function latestUserTextIn(messages: unknown): string;
|
|
29
|
+
/** Latest direct user message, excluding injected context and skill catalogs. */
|
|
30
|
+
export declare function latestUserText(session: any): string;
|
|
31
|
+
/**
|
|
32
|
+
* Classify one user turn with a deliberately low-biased policy.
|
|
33
|
+
*
|
|
34
|
+
* Low is the default. Max is reserved for four rare cases: creative project
|
|
35
|
+
* setup, project-wide refactor, project-level review, and a bug that cannot be
|
|
36
|
+
* fixed in one pass. High exists for multi-file work and a feature-module
|
|
37
|
+
* review/refactor. Questions, advice, simple fixes, and single-file reviews
|
|
38
|
+
* stay Low.
|
|
39
|
+
*/
|
|
40
|
+
export declare function classifyTask(rawText: unknown, todos?: unknown): ReasoningChoice;
|
|
41
|
+
/**
|
|
42
|
+
* Pick the closest supported provider effort. Providers differ in which effort
|
|
43
|
+
* ids they accept, and a rejected id aborts the turn before any I/O.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mapEffort(desired: ReasoningLevel, supported: readonly string[]): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Owns the per-session reasoning decision and applies it through the entry
|
|
48
|
+
* point's model-selection reference. Exported for focused tests.
|
|
49
|
+
*/
|
|
50
|
+
export declare class ReasoningController {
|
|
51
|
+
private readonly ctx;
|
|
52
|
+
private readonly options;
|
|
53
|
+
private readonly hooks;
|
|
54
|
+
private readonly states;
|
|
55
|
+
private readonly overrides;
|
|
56
|
+
private readonly userChoices;
|
|
57
|
+
private readonly applied;
|
|
58
|
+
private readonly support;
|
|
59
|
+
/**
|
|
60
|
+
* Resolved effort ids per route, readable synchronously. The inbox hook has
|
|
61
|
+
* to choose an effort before the Host snapshots the step's selection and
|
|
62
|
+
* cannot await `resolveModelInfo`, so the asynchronous lookup fills this map
|
|
63
|
+
* ahead of time and a cold entry simply defers to the pre-step path.
|
|
64
|
+
*/
|
|
65
|
+
private readonly resolved;
|
|
66
|
+
/** Latest direct user text per turn; a continuation step reuses it. */
|
|
67
|
+
private readonly latestTexts;
|
|
68
|
+
constructor(ctx: any, options: () => CodingConfig, hooks: ReasoningHooks);
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a Host or Agent service from the Agent scope first. Preset child
|
|
71
|
+
* plugins sit above the Agent scope, so Host-level services such as the
|
|
72
|
+
* session controller and LLM registry are not always visible from `ctx`.
|
|
73
|
+
*/
|
|
74
|
+
private service;
|
|
75
|
+
/** Durable reasoning state, folded from the Session log by this preset. */
|
|
76
|
+
private projectionState;
|
|
77
|
+
/** Explicit override and chat-box pick, projection-first. */
|
|
78
|
+
private effective;
|
|
79
|
+
/**
|
|
80
|
+
* Fold the projection back into this controller. A chat-box pick lands as a
|
|
81
|
+
* `model/selection` event, a `coding_reasoning` call as a tool event, and the
|
|
82
|
+
* projection is what survives a Host restart.
|
|
83
|
+
*/
|
|
84
|
+
syncProjection(agent: any): void;
|
|
85
|
+
/**
|
|
86
|
+
* The step's model selection. DSH 0.2.2 owns it on `agent.model`; every read
|
|
87
|
+
* and write goes through that service.
|
|
88
|
+
*/
|
|
89
|
+
private selection;
|
|
90
|
+
/** Resolve a route's supported efforts in the background; failures stay unknown. */
|
|
91
|
+
prewarm(agent: any): Promise<void>;
|
|
92
|
+
private effortsFor;
|
|
93
|
+
/** Latest direct user message for one turn, derived at most once per turn. */
|
|
94
|
+
private textFor;
|
|
95
|
+
private supported;
|
|
96
|
+
/**
|
|
97
|
+
* Prefer the effort the user picked in the chat box, but only while the route
|
|
98
|
+
* still accepts it; otherwise fall back to the level's closest effort.
|
|
99
|
+
*/
|
|
100
|
+
private resolveEffort;
|
|
101
|
+
/**
|
|
102
|
+
* Record the effort as the session's model selection. The Host fixes a
|
|
103
|
+
* step's selection before prompt assembly and refuses an `agent/request`
|
|
104
|
+
* rewrite, so `agent.model.select()` is the only supported write; it applies
|
|
105
|
+
* from the next step, which is why the inbox hook runs it before `preStep`
|
|
106
|
+
* captures the selection for the incoming turn.
|
|
107
|
+
*/
|
|
108
|
+
private selectEffort;
|
|
109
|
+
/** Treat a malformed runtime value as the safe automatic mode. */
|
|
110
|
+
private mode;
|
|
111
|
+
/** Classify one request; the caller decides when to write the selection. */
|
|
112
|
+
private classify;
|
|
113
|
+
/**
|
|
114
|
+
* Choose for a message claimed by the inbox. The Host emits this hook before
|
|
115
|
+
* it snapshots the step's model selection, so a synchronous capability cache
|
|
116
|
+
* lets the automatic level reach the turn's first step instead of the next
|
|
117
|
+
* one. A cold cache writes nothing and leaves the pre-step path to catch up.
|
|
118
|
+
*/
|
|
119
|
+
applySync(agent: any, message: unknown, turn?: number): ReasoningChoice | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Recompute the decision for the current step. When the caller supplies the
|
|
122
|
+
* admitted message batch, classify the request itself; otherwise fall back
|
|
123
|
+
* to the session's latest direct user message.
|
|
124
|
+
*/
|
|
125
|
+
apply(agent: any, signal?: AbortSignal, messages?: unknown, turn?: number): Promise<ReasoningChoice | undefined>;
|
|
126
|
+
/** Current selector value without resolving provider capabilities. */
|
|
127
|
+
currentEffort(agent: any): string | undefined;
|
|
128
|
+
/** Explicit in-session override; `auto` clears it. */
|
|
129
|
+
override(agent: any, value: ReasoningLevel | 'auto', turn?: number): ReasoningChoice;
|
|
130
|
+
describe(agent: any): {
|
|
131
|
+
options: CodingConfig;
|
|
132
|
+
choice: ReasoningChoice | undefined;
|
|
133
|
+
effort: string | undefined;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Where the level comes from, for `coding_reasoning`. The settings pin wins
|
|
137
|
+
* over an in-session override because it already suppresses the classifier.
|
|
138
|
+
* Without an agent the answer falls back to the settings alone.
|
|
139
|
+
*/
|
|
140
|
+
summary(agent?: any): ReasoningSummary;
|
|
141
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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 { type CodingFailure } from './failures.js';
|
|
10
|
+
import { type CodingHandoff } from './handoff.js';
|
|
11
|
+
/** Workflow mode selected for one Coding session. */
|
|
12
|
+
export type CodingMode = 'auto' | 'consult' | 'review' | 'codex';
|
|
13
|
+
/** One enforced phase of a Coding turn sequence. */
|
|
14
|
+
export type CodingStage = 'requirements' | 'plan' | 'implement' | 'verify' | 'deliver';
|
|
15
|
+
/** Every stage, in forward order. */
|
|
16
|
+
export declare const CODING_STAGES: readonly CodingStage[];
|
|
17
|
+
/** Every mode, in roster order. */
|
|
18
|
+
export declare const CODING_MODES: readonly CodingMode[];
|
|
19
|
+
/**
|
|
20
|
+
* The stages a mode opens. A mode never gains a stage at runtime: the set is
|
|
21
|
+
* fixed here and is the first thing `coding_stage` checks.
|
|
22
|
+
*/
|
|
23
|
+
export declare const STAGES_BY_MODE: Readonly<Record<CodingMode, readonly CodingStage[]>>;
|
|
24
|
+
/** Stage at which a session of this mode starts. */
|
|
25
|
+
export declare function entryStage(mode: CodingMode): CodingStage;
|
|
26
|
+
/** Whether `stage` belongs to `mode`. */
|
|
27
|
+
export declare function stageInMode(mode: CodingMode, stage: CodingStage): boolean;
|
|
28
|
+
/** Model-facing explanation of the mode's stage set, e.g. `requirements → plan → deliver`. */
|
|
29
|
+
export declare function stagePath(mode: CodingMode): string;
|
|
30
|
+
/** The workflow and control verbs this package registers by name. */
|
|
31
|
+
export declare const TOOL: {
|
|
32
|
+
readonly stage: "coding_stage";
|
|
33
|
+
readonly mode: "coding_mode";
|
|
34
|
+
readonly reasoning: "coding_reasoning";
|
|
35
|
+
readonly handoff: "coding_handoff";
|
|
36
|
+
readonly implement: "delegate_implement";
|
|
37
|
+
readonly verify: "delegate_verify";
|
|
38
|
+
readonly plan: "delegate_plan";
|
|
39
|
+
readonly verification: "run_verification";
|
|
40
|
+
};
|
|
41
|
+
/** Every tool name this package owns; the Web Definition matches on exactly these. */
|
|
42
|
+
export declare const CODING_TOOLS: readonly string[];
|
|
43
|
+
/** Whether a model-facing tool name belongs to this package. */
|
|
44
|
+
export declare function isCodingTool(name: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* How the gate reads one tool. `read` and `exec` are non-mutating observation,
|
|
47
|
+
* `write` mutates a file, `plan` owns the structured task list, `verify` runs a
|
|
48
|
+
* check, `delegate` hands implementation to a worker, and `stage`/`mode`/
|
|
49
|
+
* `reasoning` are the control verbs this plugin owns.
|
|
50
|
+
*/
|
|
51
|
+
export type ToolClass = 'read' | 'exec' | 'write' | 'plan' | 'verify' | 'delegate' | 'stage' | 'mode' | 'reasoning';
|
|
52
|
+
/**
|
|
53
|
+
* Classify a tool. Unknown (third-party) tools stay `undefined`: the gate owns
|
|
54
|
+
* the coding toolset it can reason about and never silently blocks an
|
|
55
|
+
* extension whose semantics it does not know.
|
|
56
|
+
*/
|
|
57
|
+
export declare function toolClass(name: string): ToolClass | undefined;
|
|
58
|
+
/** Whether `stage` admits the tool class `kind`. */
|
|
59
|
+
export declare function stageAdmits(stage: CodingStage, kind: ToolClass): boolean;
|
|
60
|
+
/** Human-readable list of the classes a stage admits, for a denial message. */
|
|
61
|
+
export declare function stageAdmissions(stage: CodingStage): string;
|
|
62
|
+
/**
|
|
63
|
+
* The lead's tool table during `implement`: exactly these names remain visible.
|
|
64
|
+
* Naming the allow-list (rather than denying individual tools) is what makes the
|
|
65
|
+
* trim total, including tools a later plugin registers.
|
|
66
|
+
*/
|
|
67
|
+
export declare const IMPLEMENT_TABLE: readonly string[];
|
|
68
|
+
/** The worker presets this package declares and dispatches to. */
|
|
69
|
+
export declare const WORKER_PRESETS: {
|
|
70
|
+
readonly planner: "dsh-coding-planner";
|
|
71
|
+
readonly implement: "dsh-coding-implement";
|
|
72
|
+
readonly verify: "dsh-coding-verify";
|
|
73
|
+
};
|
|
74
|
+
/** The stable route identity a session's coding run is checkpointed under. */
|
|
75
|
+
export declare const CHECKPOINT_VERSION = 1;
|
|
76
|
+
/** One stage transition recorded by the state machine. */
|
|
77
|
+
export interface StageTransition {
|
|
78
|
+
readonly from: CodingStage;
|
|
79
|
+
readonly to: CodingStage;
|
|
80
|
+
readonly at: number;
|
|
81
|
+
readonly reason: string;
|
|
82
|
+
}
|
|
83
|
+
/** A verification outcome, reduced to what a gate and the UI need. */
|
|
84
|
+
export interface VerificationOutcome {
|
|
85
|
+
readonly passed: boolean;
|
|
86
|
+
readonly kind: 'test' | 'build' | 'lint' | 'typecheck';
|
|
87
|
+
readonly scope: 'targeted' | 'package' | 'full';
|
|
88
|
+
/** `lead` ran it directly; `worker` came back through `delegate_verify`. */
|
|
89
|
+
readonly source: 'lead' | 'worker';
|
|
90
|
+
readonly command: string;
|
|
91
|
+
readonly exitCode: number | null;
|
|
92
|
+
readonly durationMs: number;
|
|
93
|
+
readonly failedTests: readonly string[];
|
|
94
|
+
readonly errors: readonly string[];
|
|
95
|
+
readonly ranAt: number;
|
|
96
|
+
}
|
|
97
|
+
/** A worker delegation the lead has started or finished. */
|
|
98
|
+
export interface WorkerRecord {
|
|
99
|
+
readonly role: 'plan' | 'implement' | 'verify';
|
|
100
|
+
readonly status: 'running' | 'completed' | 'failed';
|
|
101
|
+
readonly childId?: string;
|
|
102
|
+
readonly summary?: string;
|
|
103
|
+
readonly files?: readonly string[];
|
|
104
|
+
readonly startedAt: number;
|
|
105
|
+
readonly finishedAt?: number;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whole-value checkpoint emitted with every Coding tool result. The Web
|
|
109
|
+
* projection stores exactly this shape, so a history page that starts in the
|
|
110
|
+
* middle of a run can still render the current stage: the newest checkpoint
|
|
111
|
+
* carries the complete state and never depends on an earlier event.
|
|
112
|
+
*/
|
|
113
|
+
export interface CodingCheckpoint {
|
|
114
|
+
readonly v: typeof CHECKPOINT_VERSION;
|
|
115
|
+
/** Stable identity of the session's coding run. */
|
|
116
|
+
readonly runId: string;
|
|
117
|
+
readonly turn: number;
|
|
118
|
+
readonly step: number;
|
|
119
|
+
readonly mode: CodingMode;
|
|
120
|
+
readonly stage: CodingStage;
|
|
121
|
+
readonly allowedStages: readonly CodingStage[];
|
|
122
|
+
readonly planItems: number;
|
|
123
|
+
readonly openPlanItems: number;
|
|
124
|
+
readonly edits: number;
|
|
125
|
+
/**
|
|
126
|
+
* Distinct paths the implement workers reported, sorted. Absent on
|
|
127
|
+
* checkpoints written before this field existed; `edits` stays the count.
|
|
128
|
+
*/
|
|
129
|
+
readonly files?: readonly string[];
|
|
130
|
+
readonly verification?: VerificationOutcome;
|
|
131
|
+
/** Bounded handoff record the stages pass forward; absent on checkpoints written before it existed. */
|
|
132
|
+
readonly handoff?: CodingHandoff;
|
|
133
|
+
/** Failed verifications this session spent against the retry budget. */
|
|
134
|
+
readonly verifyAttempts?: number;
|
|
135
|
+
/** Set once the retry budget is exhausted: the run must deliver blocked, not retry. */
|
|
136
|
+
readonly verifyBlocked?: {
|
|
137
|
+
readonly attempts: number;
|
|
138
|
+
readonly reason: string;
|
|
139
|
+
readonly at: number;
|
|
140
|
+
};
|
|
141
|
+
readonly worker?: WorkerRecord;
|
|
142
|
+
readonly refusal?: {
|
|
143
|
+
readonly target: CodingStage;
|
|
144
|
+
readonly reason: string;
|
|
145
|
+
readonly at: number;
|
|
146
|
+
};
|
|
147
|
+
/** The most recent blocking exception; absent on checkpoints written before it existed. */
|
|
148
|
+
readonly failure?: CodingFailure;
|
|
149
|
+
readonly updatedAt: number;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Validate one untyped value as a {@link CodingCheckpoint}. The client reads
|
|
153
|
+
* checkpoints out of `tool/result.meta`, which is durable JSON written by an
|
|
154
|
+
* arbitrary earlier build of this plugin, so every field is re-checked here.
|
|
155
|
+
*/
|
|
156
|
+
export declare function asCheckpoint(value: unknown): CodingCheckpoint | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Read one stage value, accepting the ids an earlier build persisted. The
|
|
159
|
+
* durable projection and checkpoints store stages as strings, so a rename must
|
|
160
|
+
* keep old sessions readable.
|
|
161
|
+
* @param value - raw persisted value.
|
|
162
|
+
* @returns the current stage id, mapping legacy ids, or undefined when unknown.
|
|
163
|
+
*/
|
|
164
|
+
export declare function asStage(value: unknown): CodingStage | undefined;
|