dsh-coding 0.0.1 → 0.1.1-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -58
- package/cordis.patch.yml +231 -4
- package/docs/DETAIL.md +183 -0
- package/docs/DEVELOPMENT.md +189 -0
- package/icon.svg +4 -4
- package/lib/apply-patch.js +268 -0
- package/lib/client/capsule.js +120 -0
- package/lib/client/card.js +220 -0
- package/lib/client/command-row.js +76 -0
- package/lib/client/config-page.js +392 -0
- package/lib/client/definition.js +164 -0
- package/lib/client/index.js +129 -0
- package/lib/client/locales.js +156 -0
- package/lib/client/mode-picker.js +77 -0
- package/lib/client/styles.js +283 -0
- package/lib/client.js +1691 -0
- package/lib/coding-projection.js +349 -0
- package/lib/config.js +204 -0
- package/lib/contract.js +124 -0
- package/lib/editor.js +23 -0
- package/lib/failures.js +142 -0
- package/lib/handoff.js +312 -0
- package/lib/index.js +109 -7
- package/lib/language.js +136 -0
- package/lib/messages.js +43 -0
- package/lib/models.js +154 -0
- package/lib/patch.js +235 -0
- package/lib/preset.js +1488 -0
- package/lib/reasoning-levels.js +28 -0
- package/lib/reasoning-projection.js +178 -0
- package/lib/reasoning.js +585 -0
- package/lib/stages.js +306 -0
- package/lib/state.js +550 -0
- package/lib/system-language.js +56 -0
- package/lib/types/apply-patch.d.ts +13 -0
- package/lib/types/client/capsule.d.ts +9 -0
- package/lib/types/client/card.d.ts +72 -0
- package/lib/types/client/command-row.d.ts +42 -0
- package/lib/types/client/config-page.d.ts +136 -0
- package/lib/types/client/definition.d.ts +51 -0
- package/lib/types/client/index.d.ts +10 -0
- package/lib/types/client/locales.d.ts +18 -0
- package/lib/types/client/mode-picker.d.ts +25 -0
- package/lib/types/client/styles.d.ts +28 -0
- package/lib/types/coding-projection.d.ts +116 -0
- package/lib/types/config.d.ts +193 -0
- package/lib/types/contract.d.ts +33 -0
- package/lib/types/editor.d.ts +9 -0
- package/lib/types/failures.d.ts +62 -0
- package/lib/types/handoff.d.ts +112 -0
- package/lib/types/index.d.ts +144 -0
- package/lib/types/language.d.ts +56 -0
- package/lib/types/messages.d.ts +27 -0
- package/lib/types/models.d.ts +82 -0
- package/lib/types/patch.d.ts +37 -0
- package/lib/types/preset.d.ts +22 -0
- package/lib/types/reasoning-levels.d.ts +20 -0
- package/lib/types/reasoning-projection.d.ts +64 -0
- package/lib/types/reasoning.d.ts +141 -0
- package/lib/types/stages.d.ts +164 -0
- package/lib/types/state.d.ts +261 -0
- package/lib/types/system-language.d.ts +10 -0
- package/lib/types/verification-tool.d.ts +32 -0
- package/lib/types/verification.d.ts +77 -0
- package/lib/types/verifier.d.ts +9 -0
- package/lib/types/volatile.d.ts +17 -0
- package/lib/verification-tool.js +176 -0
- package/lib/verification.js +337 -0
- package/lib/verifier.js +25 -0
- package/lib/volatile.js +20 -0
- package/locale/en.json +3 -2
- package/locale/zh.json +3 -2
- package/package.json +83 -9
- package/lib/index.d.ts +0 -11
package/lib/editor.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Codex `apply_patch` editor as a preset entry.
|
|
3
|
+
*
|
|
4
|
+
* It is mounted by the Coding preset (so the stage gate has an edit tool to
|
|
5
|
+
* refuse, and so the `implement` table trim has something to remove) **and** by
|
|
6
|
+
* the implement worker preset (where it is the core editing tool). The parser
|
|
7
|
+
* and the expected-excerpt mismatch report are the original Codex dialect,
|
|
8
|
+
* unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-coding/editor
|
|
11
|
+
*/
|
|
12
|
+
import { registerApplyPatch } from './apply-patch.js';
|
|
13
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
14
|
+
export const name = 'dsh-coding-editor';
|
|
15
|
+
/** The editor needs the tool registry and the composed filesystem. */
|
|
16
|
+
export const inject = ['tools', 'fs'];
|
|
17
|
+
/**
|
|
18
|
+
* Register `apply_patch` in this preset's scope.
|
|
19
|
+
* @param ctx - preset scope that owns the registration.
|
|
20
|
+
*/
|
|
21
|
+
export function apply(ctx) {
|
|
22
|
+
registerApplyPatch(ctx);
|
|
23
|
+
}
|
package/lib/failures.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured failure reports: the reason a blocking step could not finish, and
|
|
3
|
+
* what the operator can do about it.
|
|
4
|
+
*
|
|
5
|
+
* The runtime catches its own blocking exceptions at a small, fixed set of
|
|
6
|
+
* dispatch points. Catching them silently would leave the user watching a card
|
|
7
|
+
* that stopped moving, so each one becomes a {@link CodingFailure} that travels
|
|
8
|
+
* with the checkpoint and reaches the next step as a one-shot notice. The note
|
|
9
|
+
* never becomes a Turn and never adds a Session event: it rides the message
|
|
10
|
+
* channel the Host already injects into.
|
|
11
|
+
*
|
|
12
|
+
* This module is pure and browser safe: no I/O, no dependencies, and no clock
|
|
13
|
+
* other than the timestamp default, so the Host preset, the worker presets, and
|
|
14
|
+
* the Web client can all import it.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-coding/failures
|
|
17
|
+
*/
|
|
18
|
+
/** Longest reason or action kept in a report. */
|
|
19
|
+
const FAILURE_TEXT_LIMIT = 600;
|
|
20
|
+
/** Every failure point, in report order. */
|
|
21
|
+
export const FAILURE_POINTS = [
|
|
22
|
+
'projection',
|
|
23
|
+
'restore',
|
|
24
|
+
'tool-table',
|
|
25
|
+
'reasoning',
|
|
26
|
+
'delegate',
|
|
27
|
+
'verification',
|
|
28
|
+
'handoff',
|
|
29
|
+
'command',
|
|
30
|
+
];
|
|
31
|
+
/** Human-readable name of each point, for the notice heading. */
|
|
32
|
+
const FAILURE_LABEL = {
|
|
33
|
+
projection: { zh: '会话投影', en: 'Session projection' },
|
|
34
|
+
restore: { zh: '会话恢复', en: 'Session restore' },
|
|
35
|
+
'tool-table': { zh: '工具表裁剪', en: 'Tool table' },
|
|
36
|
+
reasoning: { zh: '推理等级', en: 'Reasoning level' },
|
|
37
|
+
delegate: { zh: '子代理派发', en: 'Worker dispatch' },
|
|
38
|
+
verification: { zh: '验证执行', en: 'Verification' },
|
|
39
|
+
handoff: { zh: '交接记录', en: 'Handoff' },
|
|
40
|
+
command: { zh: '控制命令', en: 'Command' },
|
|
41
|
+
};
|
|
42
|
+
/** The concrete next move for each point, so a notice never only reports. */
|
|
43
|
+
const FAILURE_ACTION = {
|
|
44
|
+
projection: {
|
|
45
|
+
zh: '会话仍可继续,但卡片和阶段胶囊可能缺失。确认 sessionProjections 服务可用后重启 DSH。',
|
|
46
|
+
en: 'The session can continue, but the card and stage capsule may be missing. Confirm the sessionProjections service is available, then restart DSH.',
|
|
47
|
+
},
|
|
48
|
+
restore: {
|
|
49
|
+
zh: '会话可能从 requirements 重新开始,已记录的阶段和任务单可能丢失。确认投影插件可用后重启 DSH;仍失败请新建会话并重新描述需求。',
|
|
50
|
+
en: 'The session may restart at requirements and lose its recorded stage or task list. Confirm the projection plugin is available and restart DSH; if it still fails, start a new session and restate the request.',
|
|
51
|
+
},
|
|
52
|
+
'tool-table': {
|
|
53
|
+
zh: '阶段工具表无法裁剪,编辑工具仍会被门禁拒绝。确认 delegate_implement 已注册并重启 DSH;必要时用 /coding stage 控制阶段。',
|
|
54
|
+
en: 'The stage tool table could not be trimmed; edits are still denied by the gate. Confirm delegate_implement is registered and restart DSH; use /coding stage to control the stage if needed.',
|
|
55
|
+
},
|
|
56
|
+
reasoning: {
|
|
57
|
+
zh: '本轮沿用当前推理等级。检查模型是否支持 reasoning effort,或在插件配置中把 reasoning 设为 auto。',
|
|
58
|
+
en: 'This turn keeps the current reasoning level. Check that the model supports reasoning effort, or set reasoning to auto in the plugin configuration.',
|
|
59
|
+
},
|
|
60
|
+
delegate: {
|
|
61
|
+
zh: '按错误中的字段检查 worker 模型路由和 provider,修好后重试同一派发。worker 不会回退主代理模型;必要时在插件页更换模型。',
|
|
62
|
+
en: 'Check the worker model route and provider named in the error, fix them, then retry the same dispatch. A worker never falls back to the lead model; change the model on the plugin page if needed.',
|
|
63
|
+
},
|
|
64
|
+
verification: {
|
|
65
|
+
zh: '检查 verificationCommands 与 verificationTimeoutMs,也可手动运行命令定位。启动失败或超时会计入验证预算。',
|
|
66
|
+
en: 'Check verificationCommands and verificationTimeoutMs, or run the command manually to diagnose. A start failure or timeout counts against the verification budget.',
|
|
67
|
+
},
|
|
68
|
+
handoff: {
|
|
69
|
+
zh: '重试 coding_handoff;仍失败用 /coding 查看状态,必要时新建会话。',
|
|
70
|
+
en: 'Retry coding_handoff; if it still fails, inspect /coding and start a new session if needed.',
|
|
71
|
+
},
|
|
72
|
+
command: {
|
|
73
|
+
zh: '按错误信息处理;命令持续失败时重启 DSH 后重试。',
|
|
74
|
+
en: 'Follow the error message; if the command keeps failing, restart DSH and retry.',
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Build a report for one blocking exception.
|
|
79
|
+
* @param point - dispatch point that threw.
|
|
80
|
+
* @param error - the caught value, usually an `Error`.
|
|
81
|
+
* @param language - conversation language of the session.
|
|
82
|
+
* @param at - timestamp to stamp, defaults to now.
|
|
83
|
+
* @returns the report; its action is drawn from {@link FAILURE_ACTION}.
|
|
84
|
+
*/
|
|
85
|
+
export function makeFailure(point, error, language, at) {
|
|
86
|
+
const reason = (error instanceof Error ? error.message : String(error)).trim().slice(0, FAILURE_TEXT_LIMIT);
|
|
87
|
+
return {
|
|
88
|
+
point,
|
|
89
|
+
reason: reason === '' ? 'unknown error' : reason,
|
|
90
|
+
action: FAILURE_ACTION[point][language],
|
|
91
|
+
at: at ?? Date.now(),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Validate one untyped value as a {@link CodingFailure}. The report is persisted
|
|
96
|
+
* in checkpoints and restored from durable JSON written by an arbitrary earlier
|
|
97
|
+
* build, so every field is re-checked here rather than trusted.
|
|
98
|
+
* @param value - decoded JSON or any other untyped value.
|
|
99
|
+
* @returns the normalized report, or undefined when it is not one.
|
|
100
|
+
*/
|
|
101
|
+
export function asFailure(value) {
|
|
102
|
+
if (typeof value !== 'object' || value === null)
|
|
103
|
+
return undefined;
|
|
104
|
+
const raw = value;
|
|
105
|
+
const point = raw['point'];
|
|
106
|
+
if (typeof point !== 'string' || !FAILURE_POINTS.includes(point))
|
|
107
|
+
return undefined;
|
|
108
|
+
const reason = raw['reason'];
|
|
109
|
+
const action = raw['action'];
|
|
110
|
+
const at = raw['at'];
|
|
111
|
+
if (typeof reason !== 'string' || typeof action !== 'string')
|
|
112
|
+
return undefined;
|
|
113
|
+
if (typeof at !== 'number' || !Number.isFinite(at))
|
|
114
|
+
return undefined;
|
|
115
|
+
return {
|
|
116
|
+
point: point,
|
|
117
|
+
reason: reason.trim().slice(0, FAILURE_TEXT_LIMIT),
|
|
118
|
+
action: action.trim().slice(0, FAILURE_TEXT_LIMIT),
|
|
119
|
+
at,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Render the user-facing notice for one report: what broke and what to do.
|
|
124
|
+
* @param failure - the report to render.
|
|
125
|
+
* @param language - conversation language of the session.
|
|
126
|
+
* @returns the notice as a short Markdown block.
|
|
127
|
+
*/
|
|
128
|
+
export function failureNotice(failure, language) {
|
|
129
|
+
const label = FAILURE_LABEL[failure.point][language];
|
|
130
|
+
if (language === 'zh') {
|
|
131
|
+
return [`## dsh-coding 运行中断(${label})`, `原因:${failure.reason}`, `处理:${failure.action}`].join('\n');
|
|
132
|
+
}
|
|
133
|
+
return [`## dsh-coding runtime failure (${label})`, `Reason: ${failure.reason}`, `What to do: ${failure.action}`].join('\n');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Render the one-fragment form used by the status line.
|
|
137
|
+
* @param failure - the report to render.
|
|
138
|
+
* @returns `failure <point>`.
|
|
139
|
+
*/
|
|
140
|
+
export function failureStatus(failure) {
|
|
141
|
+
return `failure ${failure.point}`;
|
|
142
|
+
}
|
package/lib/handoff.js
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-stage handoff: the bounded record one stage gives the next.
|
|
3
|
+
*
|
|
4
|
+
* The record is a summary, never a transcript: every list and every free-text
|
|
5
|
+
* value has a fixed cap, so a long run cannot flood the next worker's prompt. A
|
|
6
|
+
* patch is merged into the previous record instead of replacing it, because the
|
|
7
|
+
* planner, implementer, and verifier each contribute their own section.
|
|
8
|
+
*
|
|
9
|
+
* This module is pure and browser safe: no I/O, no dependencies, no clock other
|
|
10
|
+
* than the timestamp default. The Host runtime, the worker presets, and the Web
|
|
11
|
+
* client can therefore import it directly.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-coding/handoff
|
|
14
|
+
*/
|
|
15
|
+
/** Version of the persisted {@link CodingHandoff} shape. */
|
|
16
|
+
export const HANDOFF_VERSION = 1;
|
|
17
|
+
/** Longest single free-text value (goal, one list item, acceptance, avoid note). */
|
|
18
|
+
export const HANDOFF_TEXT_LIMIT = 600;
|
|
19
|
+
/** Most entries kept per bullet section (`constraints`, `findings`, …). */
|
|
20
|
+
export const HANDOFF_ITEMS_LIMIT = 10;
|
|
21
|
+
/** Most plan tasks the handoff carries. */
|
|
22
|
+
export const HANDOFF_TASKS_LIMIT = 8;
|
|
23
|
+
/** Most changed-file entries the handoff carries. */
|
|
24
|
+
export const HANDOFF_CHANGES_LIMIT = 20;
|
|
25
|
+
/** Default length of {@link handoffDigest}. */
|
|
26
|
+
export const HANDOFF_DIGEST_LIMIT = 1200;
|
|
27
|
+
/** Longest worker-facing rendering of the handoff. */
|
|
28
|
+
export const HANDOFF_WORKER_LIMIT = 2000;
|
|
29
|
+
/**
|
|
30
|
+
* Sections each role receives, in order. The planner needs the problem, the
|
|
31
|
+
* implementer needs the decisions and the task list, and the verifier needs the
|
|
32
|
+
* definition of done plus what already changed.
|
|
33
|
+
*/
|
|
34
|
+
const WORKER_SECTIONS = {
|
|
35
|
+
plan: ['goal', 'constraints', 'done', 'findings', 'open'],
|
|
36
|
+
implement: ['goal', 'constraints', 'done', 'decisions', 'findings', 'tasks', 'open'],
|
|
37
|
+
verify: ['goal', 'done', 'changes', 'decisions', 'findings'],
|
|
38
|
+
};
|
|
39
|
+
/** An empty handoff stamped at `at`, defaulting to now. */
|
|
40
|
+
export function emptyHandoff(at) {
|
|
41
|
+
return {
|
|
42
|
+
version: HANDOFF_VERSION,
|
|
43
|
+
constraints: [],
|
|
44
|
+
acceptance: [],
|
|
45
|
+
findings: [],
|
|
46
|
+
decisions: [],
|
|
47
|
+
open: [],
|
|
48
|
+
tasks: [],
|
|
49
|
+
changes: [],
|
|
50
|
+
updatedAt: at ?? Date.now(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Merge one patch into a handoff. A list patch appends (dropping exact
|
|
55
|
+
* duplicates, keeping the newest {@link HANDOFF_ITEMS_LIMIT} entries); a task
|
|
56
|
+
* patch replaces the list; a change patch refines entries by `file`.
|
|
57
|
+
* @param base - the record being updated, or undefined to start empty.
|
|
58
|
+
* @param patch - the sections this stage contributes.
|
|
59
|
+
* @param at - timestamp to stamp, defaults to now.
|
|
60
|
+
* @returns a new record; the inputs are not mutated.
|
|
61
|
+
*/
|
|
62
|
+
export function mergeHandoff(base, patch, at) {
|
|
63
|
+
const previous = base ?? emptyHandoff(at);
|
|
64
|
+
const goal = boundedText(patch.goal === undefined ? previous.goal : patch.goal, HANDOFF_TEXT_LIMIT);
|
|
65
|
+
return {
|
|
66
|
+
version: HANDOFF_VERSION,
|
|
67
|
+
...goal === '' ? {} : { goal },
|
|
68
|
+
constraints: mergeItems(previous.constraints, listOf(patch.constraints)),
|
|
69
|
+
acceptance: mergeItems(previous.acceptance, listOf(patch.acceptance)),
|
|
70
|
+
findings: mergeItems(previous.findings, listOf(patch.findings)),
|
|
71
|
+
decisions: mergeItems(previous.decisions, listOf(patch.decisions)),
|
|
72
|
+
open: mergeItems(previous.open, listOf(patch.open)),
|
|
73
|
+
tasks: patch.tasks === undefined ? cleanTasks(previous.tasks) : boundedTasks(listOf(patch.tasks)),
|
|
74
|
+
changes: patch.changes === undefined ? cleanChanges(previous.changes) : mergeChanges(previous.changes, listOf(patch.changes)),
|
|
75
|
+
updatedAt: at ?? Date.now(),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validate one untyped value as a {@link CodingHandoff}. The record is persisted
|
|
80
|
+
* in checkpoints and restored from durable JSON, so every field is re-checked
|
|
81
|
+
* here rather than trusted from the writer's build.
|
|
82
|
+
* @param value - decoded JSON or any other untyped value.
|
|
83
|
+
* @returns the normalized record, or undefined when it is not version 1.
|
|
84
|
+
*/
|
|
85
|
+
export function asHandoff(value) {
|
|
86
|
+
if (typeof value !== 'object' || value === null)
|
|
87
|
+
return undefined;
|
|
88
|
+
const raw = value;
|
|
89
|
+
if (raw['version'] !== HANDOFF_VERSION)
|
|
90
|
+
return undefined;
|
|
91
|
+
const goal = boundedText(raw['goal'], HANDOFF_TEXT_LIMIT);
|
|
92
|
+
const updatedAt = raw['updatedAt'];
|
|
93
|
+
return {
|
|
94
|
+
version: HANDOFF_VERSION,
|
|
95
|
+
...goal === '' ? {} : { goal },
|
|
96
|
+
constraints: mergeItems([], listOf(raw['constraints'])),
|
|
97
|
+
acceptance: mergeItems([], listOf(raw['acceptance'])),
|
|
98
|
+
findings: mergeItems([], listOf(raw['findings'])),
|
|
99
|
+
decisions: mergeItems([], listOf(raw['decisions'])),
|
|
100
|
+
open: mergeItems([], listOf(raw['open'])),
|
|
101
|
+
tasks: boundedTasks(listOf(raw['tasks'])),
|
|
102
|
+
changes: mergeChanges([], listOf(raw['changes'])),
|
|
103
|
+
updatedAt: typeof updatedAt === 'number' && Number.isFinite(updatedAt) ? updatedAt : Date.now(),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Render the handoff as a compact multi-line digest for logs and status text.
|
|
108
|
+
* Only the sections carrying content are rendered, one short line each.
|
|
109
|
+
* @param handoff - record to render, or undefined.
|
|
110
|
+
* @param limit - maximum length, whole lines preferred.
|
|
111
|
+
* @returns the digest, or '' when the record is empty.
|
|
112
|
+
*/
|
|
113
|
+
export function handoffDigest(handoff, limit = HANDOFF_DIGEST_LIMIT) {
|
|
114
|
+
if (handoff === undefined)
|
|
115
|
+
return '';
|
|
116
|
+
const lines = [];
|
|
117
|
+
const goal = boundedText(handoff.goal, HANDOFF_TEXT_LIMIT);
|
|
118
|
+
if (goal !== '')
|
|
119
|
+
lines.push(`goal: ${goal}`);
|
|
120
|
+
pushItems(lines, 'constraints', handoff.constraints);
|
|
121
|
+
pushItems(lines, 'done', handoff.acceptance);
|
|
122
|
+
pushItems(lines, 'decisions', handoff.decisions);
|
|
123
|
+
pushItems(lines, 'findings', handoff.findings);
|
|
124
|
+
pushItems(lines, 'open', handoff.open);
|
|
125
|
+
const tasks = cleanTasks(handoff.tasks);
|
|
126
|
+
if (tasks.length > 0) {
|
|
127
|
+
lines.push('tasks:');
|
|
128
|
+
tasks.forEach((task, index) => {
|
|
129
|
+
const files = task.files.length === 0 ? '(none)' : task.files.join(', ');
|
|
130
|
+
const avoid = task.avoid === undefined ? '' : `; avoid: ${task.avoid}`;
|
|
131
|
+
lines.push(`${index + 1}. ${task.goal} — files: ${files}; done: ${task.acceptance}${avoid}`);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const changes = cleanChanges(handoff.changes);
|
|
135
|
+
if (changes.length > 0) {
|
|
136
|
+
lines.push(`changes: ${changes.map(change => `${change.file}: ${change.summary}`).join('; ')}`);
|
|
137
|
+
}
|
|
138
|
+
return truncateText(lines.join('\n'), limit);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Render the sections one worker role receives, as a prompt fragment.
|
|
142
|
+
* @param handoff - record to render, or undefined.
|
|
143
|
+
* @param role - worker about to run.
|
|
144
|
+
* @returns the fragment, or '' when nothing applies to this role.
|
|
145
|
+
*/
|
|
146
|
+
export function handoffForWorker(handoff, role) {
|
|
147
|
+
if (handoff === undefined)
|
|
148
|
+
return '';
|
|
149
|
+
const sections = {
|
|
150
|
+
goal: goalSection(handoff.goal),
|
|
151
|
+
constraints: bulletSection('Constraints:', cleanItems(handoff.constraints)),
|
|
152
|
+
done: bulletSection('Definition of done:', cleanItems(handoff.acceptance)),
|
|
153
|
+
decisions: bulletSection('Decisions:', cleanItems(handoff.decisions)),
|
|
154
|
+
findings: bulletSection('Findings:', cleanItems(handoff.findings)),
|
|
155
|
+
open: bulletSection('Open questions:', cleanItems(handoff.open)),
|
|
156
|
+
tasks: taskSection(cleanTasks(handoff.tasks)),
|
|
157
|
+
changes: changeSection(cleanChanges(handoff.changes)),
|
|
158
|
+
};
|
|
159
|
+
const parts = WORKER_SECTIONS[role]
|
|
160
|
+
.map(section => sections[section])
|
|
161
|
+
.filter((part) => part !== undefined);
|
|
162
|
+
return parts.length === 0 ? '' : truncateText(parts.join('\n\n'), HANDOFF_WORKER_LIMIT);
|
|
163
|
+
}
|
|
164
|
+
/** Whether the handoff states a goal, which `plan` requires before planning. */
|
|
165
|
+
export function hasGoal(handoff) {
|
|
166
|
+
return boundedText(handoff.goal, HANDOFF_TEXT_LIMIT) !== '';
|
|
167
|
+
}
|
|
168
|
+
/** Whether the handoff states at least one acceptance criterion, which `verify` and `deliver` require. */
|
|
169
|
+
export function hasDefinitionOfDone(handoff) {
|
|
170
|
+
return cleanItems(handoff.acceptance).length > 0;
|
|
171
|
+
}
|
|
172
|
+
/** Read one array-valued field, ignoring anything that is not an array. */
|
|
173
|
+
function listOf(value) {
|
|
174
|
+
return Array.isArray(value) ? value : [];
|
|
175
|
+
}
|
|
176
|
+
/** Trim one value to `limit` characters; anything that is not a string becomes ''. */
|
|
177
|
+
function boundedText(value, limit) {
|
|
178
|
+
return typeof value === 'string' ? value.trim().slice(0, limit) : '';
|
|
179
|
+
}
|
|
180
|
+
/** Cut `text` to `limit` characters, preferring the last whole line. */
|
|
181
|
+
function truncateText(text, limit) {
|
|
182
|
+
if (limit <= 0)
|
|
183
|
+
return '';
|
|
184
|
+
if (text.length <= limit)
|
|
185
|
+
return text;
|
|
186
|
+
const cut = text.slice(0, limit);
|
|
187
|
+
const lastBreak = cut.lastIndexOf('\n');
|
|
188
|
+
return lastBreak > 0 ? cut.slice(0, lastBreak) : cut;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Cleaned items of one bullet section: trimmed, empty dropped, exact duplicates
|
|
192
|
+
* collapsed in insertion order, oldest entries cut past the limit.
|
|
193
|
+
*/
|
|
194
|
+
function mergeItems(base, added) {
|
|
195
|
+
const seen = new Set();
|
|
196
|
+
for (const raw of [...base, ...added]) {
|
|
197
|
+
const value = boundedText(raw, HANDOFF_TEXT_LIMIT);
|
|
198
|
+
if (value !== '')
|
|
199
|
+
seen.add(value);
|
|
200
|
+
}
|
|
201
|
+
const items = [...seen];
|
|
202
|
+
return items.slice(Math.max(0, items.length - HANDOFF_ITEMS_LIMIT));
|
|
203
|
+
}
|
|
204
|
+
/** Clean every item of a bullet section, for rendering only. */
|
|
205
|
+
function cleanItems(values) {
|
|
206
|
+
return mergeItems([], values);
|
|
207
|
+
}
|
|
208
|
+
/** Clean one task, or undefined when it names no goal. */
|
|
209
|
+
function cleanTask(value) {
|
|
210
|
+
if (typeof value !== 'object' || value === null)
|
|
211
|
+
return undefined;
|
|
212
|
+
const raw = value;
|
|
213
|
+
const goal = boundedText(raw['goal'], HANDOFF_TEXT_LIMIT);
|
|
214
|
+
if (goal === '')
|
|
215
|
+
return undefined;
|
|
216
|
+
const avoid = boundedText(raw['avoid'], HANDOFF_TEXT_LIMIT);
|
|
217
|
+
return {
|
|
218
|
+
goal,
|
|
219
|
+
files: mergeItems([], listOf(raw['files'])),
|
|
220
|
+
acceptance: boundedText(raw['acceptance'], HANDOFF_TEXT_LIMIT),
|
|
221
|
+
...avoid === '' ? {} : { avoid },
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/** Clean every task, dropping the ones without a goal. */
|
|
225
|
+
function cleanTasks(values) {
|
|
226
|
+
const tasks = [];
|
|
227
|
+
for (const value of values) {
|
|
228
|
+
const task = cleanTask(value);
|
|
229
|
+
if (task !== undefined)
|
|
230
|
+
tasks.push(task);
|
|
231
|
+
}
|
|
232
|
+
return tasks;
|
|
233
|
+
}
|
|
234
|
+
/** Clean a task list, keeping one task per goal in order, up to the limit. */
|
|
235
|
+
function boundedTasks(values) {
|
|
236
|
+
const byGoal = new Map();
|
|
237
|
+
for (const value of values) {
|
|
238
|
+
const task = cleanTask(value);
|
|
239
|
+
if (task !== undefined && !byGoal.has(task.goal))
|
|
240
|
+
byGoal.set(task.goal, task);
|
|
241
|
+
}
|
|
242
|
+
const tasks = [...byGoal.values()];
|
|
243
|
+
return tasks.slice(Math.max(0, tasks.length - HANDOFF_TASKS_LIMIT));
|
|
244
|
+
}
|
|
245
|
+
/** Clean one change entry, or undefined when it names no file. */
|
|
246
|
+
function cleanChange(value) {
|
|
247
|
+
if (typeof value !== 'object' || value === null)
|
|
248
|
+
return undefined;
|
|
249
|
+
const raw = value;
|
|
250
|
+
const file = boundedText(raw['file'], HANDOFF_TEXT_LIMIT);
|
|
251
|
+
if (file === '')
|
|
252
|
+
return undefined;
|
|
253
|
+
return { file, summary: boundedText(raw['summary'], HANDOFF_TEXT_LIMIT) };
|
|
254
|
+
}
|
|
255
|
+
/** Clean every change entry, dropping the ones without a file. */
|
|
256
|
+
function cleanChanges(values) {
|
|
257
|
+
const changes = [];
|
|
258
|
+
for (const value of values) {
|
|
259
|
+
const change = cleanChange(value);
|
|
260
|
+
if (change !== undefined)
|
|
261
|
+
changes.push(change);
|
|
262
|
+
}
|
|
263
|
+
return changes;
|
|
264
|
+
}
|
|
265
|
+
/** Merge change lists by file: the newest summary wins, in first-seen order. */
|
|
266
|
+
function mergeChanges(base, added) {
|
|
267
|
+
const byFile = new Map();
|
|
268
|
+
for (const raw of [...base, ...added]) {
|
|
269
|
+
const change = cleanChange(raw);
|
|
270
|
+
if (change !== undefined)
|
|
271
|
+
byFile.set(change.file, change);
|
|
272
|
+
}
|
|
273
|
+
const changes = [...byFile.values()];
|
|
274
|
+
return changes.slice(Math.max(0, changes.length - HANDOFF_CHANGES_LIMIT));
|
|
275
|
+
}
|
|
276
|
+
/** `label: a; b` for one non-empty bullet section, or nothing. */
|
|
277
|
+
function pushItems(lines, label, values) {
|
|
278
|
+
const items = cleanItems(values);
|
|
279
|
+
if (items.length > 0)
|
|
280
|
+
lines.push(`${label}: ${items.join('; ')}`);
|
|
281
|
+
}
|
|
282
|
+
/** The `Goal:` fragment, or nothing when no goal is stated. */
|
|
283
|
+
function goalSection(goal) {
|
|
284
|
+
const text = boundedText(goal, HANDOFF_TEXT_LIMIT);
|
|
285
|
+
return text === '' ? undefined : `Goal:\n${text}`;
|
|
286
|
+
}
|
|
287
|
+
/** A titled list, one `- item` per line, or nothing when the list is empty. */
|
|
288
|
+
function bulletSection(title, values) {
|
|
289
|
+
if (values.length === 0)
|
|
290
|
+
return undefined;
|
|
291
|
+
return `${title}\n${values.map(value => `- ${value}`).join('\n')}`;
|
|
292
|
+
}
|
|
293
|
+
/** The `Plan tasks:` fragment, three lines per task plus an avoid note. */
|
|
294
|
+
function taskSection(tasks) {
|
|
295
|
+
if (tasks.length === 0)
|
|
296
|
+
return undefined;
|
|
297
|
+
const lines = ['Plan tasks:'];
|
|
298
|
+
tasks.forEach((task, index) => {
|
|
299
|
+
lines.push(`${index + 1}. ${task.goal}`);
|
|
300
|
+
lines.push(` files: ${task.files.length === 0 ? '(none)' : task.files.join(', ')}`);
|
|
301
|
+
lines.push(` done: ${task.acceptance}`);
|
|
302
|
+
if (task.avoid !== undefined)
|
|
303
|
+
lines.push(` avoid: ${task.avoid}`);
|
|
304
|
+
});
|
|
305
|
+
return lines.join('\n');
|
|
306
|
+
}
|
|
307
|
+
/** The `Changes:` fragment, one `- file — summary` line per entry. */
|
|
308
|
+
function changeSection(changes) {
|
|
309
|
+
if (changes.length === 0)
|
|
310
|
+
return undefined;
|
|
311
|
+
return `Changes:\n${changes.map(change => `- ${change.file} — ${change.summary}`).join('\n')}`;
|
|
312
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-side settings service of the `dsh-coding` bundle.
|
|
3
|
+
*
|
|
4
|
+
* This row is the bundle's only Host contribution: it owns the verified
|
|
5
|
+
* configuration the Coding preset and its three worker presets read, and it
|
|
6
|
+
* performs no agent work by itself. Installing the bundle therefore changes no
|
|
7
|
+
* existing session; only a session that selects the Coding preset runs the
|
|
8
|
+
* enforced runtime.
|
|
9
|
+
*
|
|
10
|
+
* It also filters this bundle's three internal worker presets out of the exported
|
|
11
|
+
* preset roster: no client offers them, while the Host roster keeps resolving
|
|
12
|
+
* the compositions `delegate_implement` and `delegate_verify` dispatch to.
|
|
13
|
+
*
|
|
14
|
+
* The configuration is validated twice on purpose: {@link Config} (Schemastery)
|
|
15
|
+
* rejects a malformed row at activation, and {@link normalizeConfig} parses both
|
|
16
|
+
* worker routes so a missing model fails the mount instead of silently
|
|
17
|
+
* inheriting the lead's own model at dispatch.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-coding
|
|
20
|
+
*/
|
|
1
21
|
import { Service } from '@deepseek-ai/cordis';
|
|
22
|
+
import { Config as CodingConfigSchema, configJsonSchema, normalizeConfig, } from './config.js';
|
|
23
|
+
import { WORKER_PRESETS } from './stages.js';
|
|
24
|
+
// `Config` carries both meanings: the Schemastery schema (value) and the
|
|
25
|
+
// configuration type (interface) it validates.
|
|
26
|
+
export { Config, configJsonSchema, parseWorkerRoute } from './config.js';
|
|
27
|
+
/** The same JSON Schema under the name non-Loader consumers expect. */
|
|
28
|
+
export const configSchema = configJsonSchema;
|
|
29
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
30
|
+
export const name = 'dsh-coding';
|
|
31
|
+
/** Preset ids this bundle reserves for its subagents, never offered to a user. */
|
|
32
|
+
const WORKER_PRESET_IDS = [
|
|
33
|
+
WORKER_PRESETS.planner,
|
|
34
|
+
WORKER_PRESETS.implement,
|
|
35
|
+
WORKER_PRESETS.verify,
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* The client-facing roster without this bundle's worker presets. The Host
|
|
39
|
+
* roster keeps them: `delegate_implement` / `delegate_verify` resolve their
|
|
40
|
+
* compositions from it, and only the exported list is a user-facing surface.
|
|
41
|
+
* @param roster - `remoteExportList()` result.
|
|
42
|
+
* @returns the same roster minus the worker rows.
|
|
43
|
+
*/
|
|
44
|
+
export function filterWorkerPresets(roster) {
|
|
45
|
+
return { ...roster, presets: roster.presets.filter(row => !WORKER_PRESET_IDS.includes(row.id)) };
|
|
46
|
+
}
|
|
2
47
|
/**
|
|
3
|
-
*
|
|
48
|
+
* Filter the preset registry's client-facing export for this deployment.
|
|
4
49
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
50
|
+
* DSH has no hidden-preset flag, and a browser-side replacement of the shipped
|
|
51
|
+
* picker costs the product's own chip, copy, and interaction. The registry
|
|
52
|
+
* exports its roster through one Remote method, and the gateway resolves that
|
|
53
|
+
* method per call, so wrapping it here hides the workers from every client
|
|
54
|
+
* surface while the Host keeps dispatching to them.
|
|
55
|
+
* @param ctx - owning host context.
|
|
8
56
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
57
|
+
export function installWorkerPresetFilter(ctx) {
|
|
58
|
+
ctx.inject(['agentPresets'], (child) => {
|
|
59
|
+
child.effect(() => {
|
|
60
|
+
const registry = child.agentPresets;
|
|
61
|
+
const original = registry?.remoteExportList;
|
|
62
|
+
if (registry === undefined || typeof original !== 'function')
|
|
63
|
+
return;
|
|
64
|
+
const wrapped = async (...args) => filterWorkerPresets(await original.apply(registry, args));
|
|
65
|
+
registry.remoteExportList = wrapped;
|
|
66
|
+
return () => {
|
|
67
|
+
// Only undo our own wrapper: a later generation may have re-wrapped it.
|
|
68
|
+
if (registry.remoteExportList === wrapped)
|
|
69
|
+
registry.remoteExportList = original;
|
|
70
|
+
};
|
|
71
|
+
}, 'dsh-coding: preset roster filter');
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Bundle settings surface (`ctx.dshCodingRuntime`).
|
|
76
|
+
*
|
|
77
|
+
* The service exposes only immutable, already-verified options: consumers never
|
|
78
|
+
* re-validate, and no agent behavior depends on an unvalidated value.
|
|
79
|
+
*/
|
|
80
|
+
export default class DshCodingSettings extends Service {
|
|
81
|
+
/** Schemastery schema the Loader validates the bundle row's `config` with. */
|
|
82
|
+
static Config = CodingConfigSchema;
|
|
83
|
+
raw;
|
|
84
|
+
/**
|
|
85
|
+
* @param ctx - owning host context.
|
|
86
|
+
* @param config - Loader-validated row configuration. The page-editable fields
|
|
87
|
+
* arrive as Schemastery volatile accessors, so every read below observes the
|
|
88
|
+
* value currently saved on the plugin page.
|
|
89
|
+
* @throws when a worker route is absent or not a `provider/model` pair.
|
|
90
|
+
*/
|
|
91
|
+
constructor(ctx, config) {
|
|
92
|
+
super(ctx, 'dshCodingRuntime');
|
|
93
|
+
this.raw = config;
|
|
94
|
+
// Validate once at activation so a bad row fails loudly; later edits are
|
|
95
|
+
// validated again on every read. `normalizeConfig` reads every field through
|
|
96
|
+
// `volatileValue`, so the row must be passed through unchanged: a hand-copied
|
|
97
|
+
// field map drops any route added later (a missing `plannerWorkerModel` threw
|
|
98
|
+
// here and took the whole bundle's presets down with it).
|
|
99
|
+
normalizeConfig(this.raw);
|
|
100
|
+
// The plugin manager page renders our own configuration form, so the
|
|
101
|
+
// automatic settings page is switched off for this entry.
|
|
102
|
+
ctx.inject(['settings'], (child) => {
|
|
103
|
+
child.effect(() => child.settings.configure({ auto: false }, ctx.fiber));
|
|
104
|
+
});
|
|
105
|
+
// Hide this bundle's internal worker presets from the exported roster.
|
|
106
|
+
installWorkerPresetFilter(ctx);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Verified configuration, re-read from the volatile fields on every access.
|
|
110
|
+
* @throws when a page-edited worker route is not a usable `provider/model` pair.
|
|
111
|
+
*/
|
|
112
|
+
get options() {
|
|
113
|
+
return normalizeConfig(this.raw);
|
|
12
114
|
}
|
|
13
115
|
}
|