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,71 @@
|
|
|
1
|
+
import type { CodingHandoff } from './handoff.js';
|
|
2
|
+
import type { CodingState, PlanItem } from './state.js';
|
|
3
|
+
import type { VerificationOutcome } from './stages.js';
|
|
4
|
+
/** 文档最大字符数;超出后截断到最后一个完整行。 */
|
|
5
|
+
export declare const MEMORY_LIMIT = 20000;
|
|
6
|
+
/** 交接文档在项目根下的目录。 */
|
|
7
|
+
export declare const MEMORY_DIR: string;
|
|
8
|
+
/** 交接文档的输入:只取状态机与 handoff 的有界数据,不含 I/O 与对话正文。 */
|
|
9
|
+
export interface MemoryInput {
|
|
10
|
+
readonly sessionId: string;
|
|
11
|
+
readonly cwd?: string;
|
|
12
|
+
readonly mode: string;
|
|
13
|
+
readonly stage: string;
|
|
14
|
+
readonly turn: number;
|
|
15
|
+
readonly blocked: boolean;
|
|
16
|
+
readonly handoff?: CodingHandoff;
|
|
17
|
+
readonly plan: readonly PlanItem[];
|
|
18
|
+
readonly verification?: VerificationOutcome;
|
|
19
|
+
readonly files: readonly string[];
|
|
20
|
+
readonly transitions: readonly {
|
|
21
|
+
readonly from: string;
|
|
22
|
+
readonly to: string;
|
|
23
|
+
readonly at: number;
|
|
24
|
+
readonly reason: string;
|
|
25
|
+
}[];
|
|
26
|
+
readonly now: number;
|
|
27
|
+
}
|
|
28
|
+
/** 写盘结果:成功给出文件名与展示路径;失败给出原因与处理办法,从不抛错。 */
|
|
29
|
+
export type MemoryWriteResult = {
|
|
30
|
+
readonly ok: true;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly displayPath: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly ok: false;
|
|
35
|
+
readonly reason: string;
|
|
36
|
+
readonly action: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* 生成一篇交接文档的文件名:`<清洗后的 sessionId>-<YYYYMMDD-HHmmss>.md`。
|
|
40
|
+
*
|
|
41
|
+
* sessionId 只保留 `[A-Za-z0-9._-]`,其余字符换成 `-`,清洗后为空则退回 `session`;
|
|
42
|
+
* 时间戳取 UTC,非法 `at` 按 epoch 处理而不抛错。
|
|
43
|
+
* @param sessionId - 会话 id。
|
|
44
|
+
* @param at - 时间戳(毫秒)。
|
|
45
|
+
* @returns 文件名,不含目录。
|
|
46
|
+
*/
|
|
47
|
+
export declare function memoryFileName(sessionId: string, at: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* 组装整篇交接文档。
|
|
50
|
+
*
|
|
51
|
+
* 纯字符串拼接:不读文件、不取时钟(时间来自 {@link MemoryInput.now}),因此可以直接单测。
|
|
52
|
+
* 空数组与缺失字段对应的整节省略,不输出「无」。
|
|
53
|
+
* @param input - 状态机与 handoff 的有界快照。
|
|
54
|
+
* @returns 文档正文,超过 {@link MEMORY_LIMIT} 时截断并标注。
|
|
55
|
+
*/
|
|
56
|
+
export declare function composeMemoryDocument(input: MemoryInput): string;
|
|
57
|
+
/**
|
|
58
|
+
* 写出本轮的任务交接文档,返回一条可回报给用户的收据。
|
|
59
|
+
*
|
|
60
|
+
* 写盘只走注入的 fs 服务:`resolve` 解析 `.agents/memory` 下的目标,`writeText` 以
|
|
61
|
+
* `createIfAbsent` 语义写入,因此重复点击生成新文件而不覆盖旧文档;目录缺失由 Host 的
|
|
62
|
+
* 原子写入自动创建。任何一步抛错都收成 `{ ok:false, … }` 收据,绝不外泄异常。
|
|
63
|
+
* @param ctx - 插件作用域。
|
|
64
|
+
* @param agent - 触发写入的 lead agent(`agent.ctx` 的作用域优先级更高)。
|
|
65
|
+
* @param state - 本轮结束时的状态机快照。
|
|
66
|
+
* @param options - 取消信号。
|
|
67
|
+
* @returns 成功时给出文件名与展示路径,失败时给出原因与处理办法。
|
|
68
|
+
*/
|
|
69
|
+
export declare function writeMemoryDocument(ctx: any, agent: any, state: CodingState, options?: {
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
}): Promise<MemoryWriteResult>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ContextFormed, UserMessage } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
declare module '@deepseek-ai/dsh-llm' {
|
|
3
|
+
interface MessageSourceMap {
|
|
4
|
+
/** Per-step stage contract injected by the Coding runtime. */
|
|
5
|
+
'dsh-coding-stage': {
|
|
6
|
+
kind: 'dsh-coding-stage';
|
|
7
|
+
} & ContextFormed;
|
|
8
|
+
/** A control notice produced by `/coding` and by the stage machine. */
|
|
9
|
+
'dsh-coding-control': {
|
|
10
|
+
kind: 'dsh-coding-control';
|
|
11
|
+
} & ContextFormed;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Build the per-step stage context message.
|
|
16
|
+
* @param text - complete stage fragment.
|
|
17
|
+
* @param summary - one-line account shown without expanding the row.
|
|
18
|
+
* @returns an immutable user-role context message.
|
|
19
|
+
*/
|
|
20
|
+
export declare function stageMessage(text: string, summary: string): UserMessage;
|
|
21
|
+
/**
|
|
22
|
+
* Build a control notice delivered by `agent.followup()` or `agent.steer()`.
|
|
23
|
+
* @param text - what the runtime decided and what the model should do.
|
|
24
|
+
* @param summary - one-line account for the conversation row.
|
|
25
|
+
* @returns an immutable user-role context message.
|
|
26
|
+
*/
|
|
27
|
+
export declare function controlMessage(text: string, summary: string): UserMessage;
|
|
@@ -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,193 @@
|
|
|
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
|
+
* `bash` and `pwsh` are both listed because only one exists per platform;
|
|
67
|
+
* `syncTable` drops the absent one, since `tools.restrict` rejects names the
|
|
68
|
+
* scope does not register.
|
|
69
|
+
*/
|
|
70
|
+
export declare const IMPLEMENT_TABLE: readonly string[];
|
|
71
|
+
/** The worker presets this package declares and dispatches to. */
|
|
72
|
+
export declare const WORKER_PRESETS: {
|
|
73
|
+
readonly planner: "dsh-coding-planner";
|
|
74
|
+
readonly implement: "dsh-coding-implement";
|
|
75
|
+
readonly verify: "dsh-coding-verify";
|
|
76
|
+
readonly verifyWithInstructions: "dsh-coding-verify-instructions";
|
|
77
|
+
};
|
|
78
|
+
/** 触发 verify 注入仓库指令的最小子任务数:多个子任务意味着跨任务依赖。 */
|
|
79
|
+
export declare const VERIFY_INSTRUCTION_TASK_THRESHOLD = 2;
|
|
80
|
+
/** 触发 verify 注入仓库指令的最小改动文件数:改动面大时需要仓库规则。 */
|
|
81
|
+
export declare const VERIFY_INSTRUCTION_FILE_THRESHOLD = 3;
|
|
82
|
+
/** 决定 verify worker 是否加载仓库指令的输入。 */
|
|
83
|
+
export interface WorkspaceInstructionDemand {
|
|
84
|
+
readonly mode: CodingMode;
|
|
85
|
+
readonly taskCount: number;
|
|
86
|
+
readonly changedFiles: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* verify 是否应加载仓库指令:仅 codex 模式,且(多子任务)或(改动文件多)。
|
|
90
|
+
* 单任务单文件的核查不注入,避免为一次检查付出整份 AGENTS.md 的上下文。
|
|
91
|
+
*/
|
|
92
|
+
export declare function needsWorkspaceInstructions(demand: WorkspaceInstructionDemand): boolean;
|
|
93
|
+
/** The stable route identity a session's coding run is checkpointed under. */
|
|
94
|
+
export declare const CHECKPOINT_VERSION = 1;
|
|
95
|
+
/** One stage transition recorded by the state machine. */
|
|
96
|
+
export interface StageTransition {
|
|
97
|
+
readonly from: CodingStage;
|
|
98
|
+
readonly to: CodingStage;
|
|
99
|
+
readonly at: number;
|
|
100
|
+
readonly reason: string;
|
|
101
|
+
}
|
|
102
|
+
/** A verification outcome, reduced to what a gate and the UI need. */
|
|
103
|
+
export interface VerificationOutcome {
|
|
104
|
+
readonly passed: boolean;
|
|
105
|
+
readonly kind: 'test' | 'build' | 'lint' | 'typecheck';
|
|
106
|
+
readonly scope: 'targeted' | 'package' | 'full';
|
|
107
|
+
/** `lead` ran it directly; `worker` came back through `delegate_verify`. */
|
|
108
|
+
readonly source: 'lead' | 'worker';
|
|
109
|
+
readonly command: string;
|
|
110
|
+
readonly exitCode: number | null;
|
|
111
|
+
readonly durationMs: number;
|
|
112
|
+
readonly failedTests: readonly string[];
|
|
113
|
+
readonly errors: readonly string[];
|
|
114
|
+
readonly ranAt: number;
|
|
115
|
+
}
|
|
116
|
+
/** A worker delegation the lead has started or finished. */
|
|
117
|
+
export interface WorkerRecord {
|
|
118
|
+
readonly role: 'plan' | 'implement' | 'verify';
|
|
119
|
+
readonly status: 'running' | 'completed' | 'failed';
|
|
120
|
+
readonly childId?: string;
|
|
121
|
+
readonly summary?: string;
|
|
122
|
+
readonly files?: readonly string[];
|
|
123
|
+
readonly startedAt: number;
|
|
124
|
+
readonly finishedAt?: number;
|
|
125
|
+
}
|
|
126
|
+
/** 一次 planner 派发尝试:失败也算尝试,避免 worker 路由不可用时把 codex 流程锁死。 */
|
|
127
|
+
export interface PlannerAttempt {
|
|
128
|
+
/** 本次尝试使用的配置路由 `provider/model`。 */
|
|
129
|
+
readonly route: string;
|
|
130
|
+
/** 只有 worker 完成并回报 ok 才是 `completed`;失败的尝试同样打开门禁。 */
|
|
131
|
+
readonly outcome: 'completed' | 'failed';
|
|
132
|
+
readonly at: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Whole-value checkpoint emitted with every Coding tool result. The Web
|
|
136
|
+
* projection stores exactly this shape, so a history page that starts in the
|
|
137
|
+
* middle of a run can still render the current stage: the newest checkpoint
|
|
138
|
+
* carries the complete state and never depends on an earlier event.
|
|
139
|
+
*/
|
|
140
|
+
export interface CodingCheckpoint {
|
|
141
|
+
readonly v: typeof CHECKPOINT_VERSION;
|
|
142
|
+
/** Stable identity of the session's coding run. */
|
|
143
|
+
readonly runId: string;
|
|
144
|
+
readonly turn: number;
|
|
145
|
+
readonly step: number;
|
|
146
|
+
readonly mode: CodingMode;
|
|
147
|
+
readonly stage: CodingStage;
|
|
148
|
+
readonly allowedStages: readonly CodingStage[];
|
|
149
|
+
readonly planItems: number;
|
|
150
|
+
readonly openPlanItems: number;
|
|
151
|
+
readonly edits: number;
|
|
152
|
+
/**
|
|
153
|
+
* Distinct paths the implement workers reported, sorted. Absent on
|
|
154
|
+
* checkpoints written before this field existed; `edits` stays the count.
|
|
155
|
+
*/
|
|
156
|
+
readonly files?: readonly string[];
|
|
157
|
+
readonly verification?: VerificationOutcome;
|
|
158
|
+
/** Bounded handoff record the stages pass forward; absent on checkpoints written before it existed. */
|
|
159
|
+
readonly handoff?: CodingHandoff;
|
|
160
|
+
/** Failed verifications this session spent against the retry budget. */
|
|
161
|
+
readonly verifyAttempts?: number;
|
|
162
|
+
/** Set once the retry budget is exhausted: the run must deliver blocked, not retry. */
|
|
163
|
+
readonly verifyBlocked?: {
|
|
164
|
+
readonly attempts: number;
|
|
165
|
+
readonly reason: string;
|
|
166
|
+
readonly at: number;
|
|
167
|
+
};
|
|
168
|
+
readonly worker?: WorkerRecord;
|
|
169
|
+
/** planner 派发尝试;旧 checkpoint 没有该字段,读取时视为“未尝试”。 */
|
|
170
|
+
readonly planner?: PlannerAttempt;
|
|
171
|
+
readonly refusal?: {
|
|
172
|
+
readonly target: CodingStage;
|
|
173
|
+
readonly reason: string;
|
|
174
|
+
readonly at: number;
|
|
175
|
+
};
|
|
176
|
+
/** The most recent blocking exception; absent on checkpoints written before it existed. */
|
|
177
|
+
readonly failure?: CodingFailure;
|
|
178
|
+
readonly updatedAt: number;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Validate one untyped value as a {@link CodingCheckpoint}. The client reads
|
|
182
|
+
* checkpoints out of `tool/result.meta`, which is durable JSON written by an
|
|
183
|
+
* arbitrary earlier build of this plugin, so every field is re-checked here.
|
|
184
|
+
*/
|
|
185
|
+
export declare function asCheckpoint(value: unknown): CodingCheckpoint | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Read one stage value, accepting the ids an earlier build persisted. The
|
|
188
|
+
* durable projection and checkpoints store stages as strings, so a rename must
|
|
189
|
+
* keep old sessions readable.
|
|
190
|
+
* @param value - raw persisted value.
|
|
191
|
+
* @returns the current stage id, mapping legacy ids, or undefined when unknown.
|
|
192
|
+
*/
|
|
193
|
+
export declare function asStage(value: unknown): CodingStage | undefined;
|