@treeseed/dsh-chapters 0.1.16 → 0.1.17

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.
@@ -0,0 +1,191 @@
1
+ /**
2
+ * The `chapters` agent preset: its composition, and the ONLY sanctioned way this
3
+ * plugin makes a preset EXIST on a host that composes presets from declaration
4
+ * rows (>= 0.1.7-alpha.1; "Nothing reads $DSH_HOME/.agent-presets any more").
5
+ *
6
+ * WHY THIS FILE IS CODE AND NOT A SHIPPED PATCH LAYER
7
+ * ---------------------------------------------------
8
+ * The host's idiom is a `@deepseek-ai/dsh-agent-preset` row carried by a bundle
9
+ * patch layer, listed in `package.json` `dsh.bundle.patch`. Shipping that row as
10
+ * a SECOND layer means `dsh.bundle.patch` becomes an ARRAY, and both halves of
11
+ * that are fatal on a pre-0.1.7 host — measured on the pinned e2e closure
12
+ * (0.1.5-rc.1), not reasoned about:
13
+ *
14
+ * - array `patch`: `TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must
15
+ * be of type string. Received an instance of Array` at
16
+ * `dsh-app-boot/lib/index.js:853` (`join(packageDir, declared)`) — the host
17
+ * never boots.
18
+ * - the row itself, in ANY layer a legacy host reads:
19
+ * `dsh: plugin tree failed to load: ... failed to import loader entry
20
+ * preset-chapters (@deepseek-ai/dsh-agent-preset): Cannot find package` — a
21
+ * legacy host's plugin tree aborts the boot on one unresolvable row.
22
+ * - gating it with `disabled: !!js get('agentPresets')?.register === undefined`
23
+ * does not work either: the Loader evaluates `disabled` BEFORE services are
24
+ * mounted, so the expression is truthy on a 0.2.x host too and the row never
25
+ * registers (measured: `preset-v2 … failed to import`, roster without it).
26
+ *
27
+ * Registering through `ctx.get('agentPresets').register(definition)` is the same
28
+ * call the host's own declaration-row plugin makes
29
+ * (`dsh-agent-preset/lib/index.js`: `[Service.init]` → `this.ctx.agentPresets.register(this.config)`),
30
+ * made from a row that resolves on EVERY host: this package. The tradeoff is
31
+ * honest and stated in docs/contract.md: the composition is not visible in a
32
+ * patch-layer dump, so the roster (not a file) is the evidence — which is the
33
+ * rule this module enforces anyway.
34
+ *
35
+ * WHY ROWS ARE PRUNED AGAINST THE INSTALLED HOST
36
+ * ----------------------------------------------
37
+ * The host's standard plugin list is not stable across the versions this package
38
+ * must serve. Measured against published `@deepseek-ai/dsh-web-app` presets:
39
+ * 0.2.0-rc.1/rc.2 lack `dsh-time-context` and `dsh-tool-schedule`;
40
+ * `dsh-tool-schedule` is not published at 0.2.0-rc.x AT ALL (first real version
41
+ * 0.2.1-alpha.1), and `dsh-plugin-market` exists only at 0.2.1-alpha.4. One
42
+ * unresolvable row does not degrade: `mountPreset` throws on any failed row, the
43
+ * registry stores it as `record.broken`, and `retain()` then refuses with
44
+ * `agent-preset/invalid` — every session choosing `chapters` stops composing,
45
+ * while its durable log sits there intact. So a row whose package does not
46
+ * resolve is DROPPED here and reported, instead of taking the preset down.
47
+ *
48
+ * @module dsh-chapters/src/preset
49
+ */
50
+ /** One mounted plugin row of a preset composition (the Loader's own shape).
51
+ * A group row carries its children in `config`; an ordinary row carries a
52
+ * config map — the Loader accepts both under the same key. */
53
+ export interface PresetRow {
54
+ id: string;
55
+ name: string;
56
+ config?: Record<string, unknown> | PresetRow[];
57
+ disabled?: boolean;
58
+ group?: boolean;
59
+ isolate?: Record<string, boolean>;
60
+ }
61
+ /** The `AgentPreset` Config the host registers (`dsh-agent-preset/lib/index.js:13-20`). */
62
+ export interface PresetDefinition {
63
+ id: string;
64
+ name: string;
65
+ description: string;
66
+ order: number;
67
+ plugins: PresetRow[];
68
+ }
69
+ /**
70
+ * WHY THE DELEGATION ROWS CARRY NO `toolFilter`, although the host's own alpha.1/alpha.2
71
+ * list denied `schedule_*` there.
72
+ *
73
+ * Measured on a real 0.2.1-alpha.4 boot: `tool-subagent` does NOT strip an unknown key —
74
+ * it rejects the removed one outright, and the WHOLE preset goes broken:
75
+ * `tool-subagent: toolFilter is no longer supported; configure persona and tool plugins
76
+ * in an Agent Preset and select it with agentPreset (spawn only)`
77
+ * while the same composition on 0.2.0-rc.2 (which still accepts `toolFilter`) mounts. So a
78
+ * key that one supported host accepts and the next one THROWS on is worse than dropping it:
79
+ * the deny list protected nothing on rc.2 (no schedule tools exist there at all) and would
80
+ * break every chapters session on the alpha. The general rule this incident writes down:
81
+ * carry only config keys EVERY supported host accepts, and let the roster line — not a
82
+ * file on disk — be the evidence that the composition is usable.
83
+ */
84
+ /**
85
+ * The chapters preset: the host's standard coding-agent composition with EXACTLY
86
+ * four deltas, each one a product decision of ours.
87
+ *
88
+ * 1. `compaction-basic` → `@treeseed/dsh-chapters/engine` (thresholdRatio 0.9):
89
+ * the zero-inference `summarize()` — chapters from the log, no model tokens.
90
+ * 2. `tool-result-pruner.thresholdChars` 8192 → 1000000, deliberately dormant:
91
+ * chapters defer oversized results at ARCHIVE time (verbatim bodies +
92
+ * artifact references), never in-surface, where a prune is a prefix cliff on
93
+ * local hardware.
94
+ * 3. the persona gains the PLOT: suffix (plot carriage through in-place
95
+ * checkpoints) and keeps no `{{cwd}}` (see PLOT_SUFFIX).
96
+ * 4. `tool-ralph` mounted ENABLED — the bounded goal loop the continuation
97
+ * children run. The host ships it disabled; enabling it here is ours.
98
+ *
99
+ * @param platform the platform the shell-gated rows are decided against; a
100
+ * parameter so the rows are testable on any machine.
101
+ */
102
+ export declare function chaptersPresetRows(platform?: NodeJS.Platform, thresholdRatio?: number): PresetRow[];
103
+ /** The preset identity. `config.id` is DURABLE STATE: every continuation child's
104
+ * log records it as `agent-preset/selected`, so renaming it orphans those
105
+ * sessions (`agent-preset/not-found` on open). */
106
+ export declare const CHAPTERS_PRESET_ID = "chapters";
107
+ export declare function chaptersPresetDefinition(platform?: NodeJS.Platform, thresholdRatio?: number): PresetDefinition;
108
+ /** A row whose own module cannot be imported would activate as failed, and one
109
+ * failed row makes the WHOLE preset broken (`mountPreset` throws) — so it is
110
+ * dropped, with the reason, instead of taking every chapters session down.
111
+ *
112
+ * The probe is asked with the row's FULL specifier, so a package that exists but
113
+ * no longer exports the subpath (`.../tools`, `.../list-agents`) is caught too —
114
+ * those are the renames that eat presets.
115
+ *
116
+ * @param rows the composition, groups included.
117
+ * @param resolvable asked with each row's module specifier. MUST NOT throw.
118
+ */
119
+ export declare function pruneResolvableRows(rows: PresetRow[], resolvable: (specifier: string) => boolean): {
120
+ kept: PresetRow[];
121
+ dropped: string[];
122
+ };
123
+ /** What registering a preset can end up as. Every arm has its own log line and
124
+ * its own remedy, because the silent case is the one that cost a human hours. */
125
+ export type RegisterOutcome = {
126
+ state: 'registered';
127
+ }
128
+ /** config.installChaptersPreset=false: the operator owns the preset, we do not register. */
129
+ | {
130
+ state: 'disabled';
131
+ } | {
132
+ state: 'already-declared';
133
+ } | {
134
+ state: 'pruned';
135
+ dropped: string[];
136
+ } | {
137
+ state: 'unsupported';
138
+ } | {
139
+ state: 'failed';
140
+ reason: string;
141
+ };
142
+ /** The narrow surface of `ctx.get('agentPresets')` this module uses. */
143
+ export interface PresetRegistryLike {
144
+ register?: (definition: PresetDefinition) => Promise<() => Promise<void>>;
145
+ list?: () => Promise<unknown>;
146
+ /** Host-side inventory of every declared preset and its mounted rows —
147
+ * `compositionInventory()` in `@deepseek-ai/dsh-agent-preset-registry`. */
148
+ compositionInventory?: () => Promise<unknown>;
149
+ }
150
+ /** One mounted row of a live preset composition, as the host's own inventory reports it.
151
+ * `fiberState` is the Loader's state for that row; an enabled row that is not `active`
152
+ * cannot serve a session, and the roster's `broken` flag reports that only for the whole
153
+ * mount — which is why the witness asks for the rows too. */
154
+ export interface InventoryRow {
155
+ entryId?: string;
156
+ moduleName?: string;
157
+ enabled?: boolean;
158
+ fiberState?: string;
159
+ }
160
+ /** One preset's entry in a `compositionInventory()` response. */
161
+ export interface InventoryEntry {
162
+ id?: string;
163
+ broken?: string;
164
+ rows?: InventoryRow[];
165
+ }
166
+ /** Find one preset in an inventory response, tolerating a missing or odd shape. */
167
+ export declare function inventoryEntry(raw: unknown, presetId: string): InventoryEntry | undefined;
168
+ /** Enabled rows of one preset that are not active. A row `pending` a host service can
169
+ * still activate later, so this is reported apart from `broken`, never as a refusal. */
170
+ export declare function unusableRows(entry: InventoryEntry | undefined): string[];
171
+ /**
172
+ * Make the `chapters` preset exist on a host that composes presets from
173
+ * declaration rows, and say what happened.
174
+ *
175
+ * @param presets the host's `agentPresets` service, or undefined on a host that
176
+ * has no preset registry at all (then the legacy directory copy is the
177
+ * delivery, and this returns 'unsupported').
178
+ * @param dispose owner for the disposer the registry hands back — registering
179
+ * without it would leave a standing preset mount after unmount.
180
+ */
181
+ export declare function registerChaptersPreset(presets: PresetRegistryLike | undefined, opts: {
182
+ resolvable: (specifier: string) => boolean;
183
+ platform?: NodeJS.Platform;
184
+ /** Engine pressure threshold for the realm row; the host plane's
185
+ * `config.compactionThresholdRatio` is what feeds it (no hardcoded tunables). */
186
+ thresholdRatio?: number;
187
+ dispose: (disposer: () => Promise<void>) => void;
188
+ }): Promise<{
189
+ outcome: RegisterOutcome;
190
+ definition: PresetDefinition;
191
+ }>;
package/lib/preset.js ADDED
@@ -0,0 +1,282 @@
1
+ /**
2
+ * The `chapters` agent preset: its composition, and the ONLY sanctioned way this
3
+ * plugin makes a preset EXIST on a host that composes presets from declaration
4
+ * rows (>= 0.1.7-alpha.1; "Nothing reads $DSH_HOME/.agent-presets any more").
5
+ *
6
+ * WHY THIS FILE IS CODE AND NOT A SHIPPED PATCH LAYER
7
+ * ---------------------------------------------------
8
+ * The host's idiom is a `@deepseek-ai/dsh-agent-preset` row carried by a bundle
9
+ * patch layer, listed in `package.json` `dsh.bundle.patch`. Shipping that row as
10
+ * a SECOND layer means `dsh.bundle.patch` becomes an ARRAY, and both halves of
11
+ * that are fatal on a pre-0.1.7 host — measured on the pinned e2e closure
12
+ * (0.1.5-rc.1), not reasoned about:
13
+ *
14
+ * - array `patch`: `TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must
15
+ * be of type string. Received an instance of Array` at
16
+ * `dsh-app-boot/lib/index.js:853` (`join(packageDir, declared)`) — the host
17
+ * never boots.
18
+ * - the row itself, in ANY layer a legacy host reads:
19
+ * `dsh: plugin tree failed to load: ... failed to import loader entry
20
+ * preset-chapters (@deepseek-ai/dsh-agent-preset): Cannot find package` — a
21
+ * legacy host's plugin tree aborts the boot on one unresolvable row.
22
+ * - gating it with `disabled: !!js get('agentPresets')?.register === undefined`
23
+ * does not work either: the Loader evaluates `disabled` BEFORE services are
24
+ * mounted, so the expression is truthy on a 0.2.x host too and the row never
25
+ * registers (measured: `preset-v2 … failed to import`, roster without it).
26
+ *
27
+ * Registering through `ctx.get('agentPresets').register(definition)` is the same
28
+ * call the host's own declaration-row plugin makes
29
+ * (`dsh-agent-preset/lib/index.js`: `[Service.init]` → `this.ctx.agentPresets.register(this.config)`),
30
+ * made from a row that resolves on EVERY host: this package. The tradeoff is
31
+ * honest and stated in docs/contract.md: the composition is not visible in a
32
+ * patch-layer dump, so the roster (not a file) is the evidence — which is the
33
+ * rule this module enforces anyway.
34
+ *
35
+ * WHY ROWS ARE PRUNED AGAINST THE INSTALLED HOST
36
+ * ----------------------------------------------
37
+ * The host's standard plugin list is not stable across the versions this package
38
+ * must serve. Measured against published `@deepseek-ai/dsh-web-app` presets:
39
+ * 0.2.0-rc.1/rc.2 lack `dsh-time-context` and `dsh-tool-schedule`;
40
+ * `dsh-tool-schedule` is not published at 0.2.0-rc.x AT ALL (first real version
41
+ * 0.2.1-alpha.1), and `dsh-plugin-market` exists only at 0.2.1-alpha.4. One
42
+ * unresolvable row does not degrade: `mountPreset` throws on any failed row, the
43
+ * registry stores it as `record.broken`, and `retain()` then refuses with
44
+ * `agent-preset/invalid` — every session choosing `chapters` stops composing,
45
+ * while its durable log sits there intact. So a row whose package does not
46
+ * resolve is DROPPED here and reported, instead of taking the preset down.
47
+ *
48
+ * @module dsh-chapters/src/preset
49
+ */
50
+ /** The plan-mode prompt section, verbatim from the host's own standard preset.
51
+ * Reword it with the host and the drift test says so; it is prompt bytes every
52
+ * chapters session pays, so it is not ours to invent. */
53
+ const PLAN_MODE_SECTION = `You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
54
+
55
+ Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.
56
+
57
+ The tool catalog stays the same across modes for request-cache stability. These plan-mode rules override any later tool description or guidance that suggests using mutation tools; those tools remain listed to keep the tool catalog unchanged. Do not use todo_write to track this planning phase: it tracks implementation after an approved plan, while the plan itself belongs in exit_plan_mode.
58
+
59
+ Resolve discoverable facts by inspection. Use ask_user_question only for user-owned choices or material ambiguity that inspection cannot answer. Do not ask the user where code lives or how current behavior works when you can find out.
60
+
61
+ Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions.
62
+
63
+ When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable or aborted, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation.
64
+ `;
65
+ /**
66
+ * The PLOT: discipline. Two facts are load-bearing in this string and a test pins
67
+ * both by BEHAVIOUR, not by text equality:
68
+ * - no `{{cwd}}`: `dsh-agent-loop` registers `provider`/`model`/`cwd` up to
69
+ * 0.2.0-rc.2 and only `provider`/`model` from 0.2.1-alpha.2, and an
70
+ * unregistered reference THROWS at prompt assembly (`dsh-system-prompt`
71
+ * `interpolate`), killing every turn of every chapters session. The working
72
+ * directory already reaches the model from `dsh-working-directory` (host plane).
73
+ * - the wording `src/engine-core.ts`'s PLOT_TEMPLATE_ECHO matches, so a model
74
+ * quoting our own instruction back is not inherited as a "plot".
75
+ */
76
+ const PLOT_SUFFIX = "When a task spans multiple turns, end each reply with one line beginning 'PLOT:' (max 60 words — objective, current hypothesis, immediate next step). A checkpoint carries this plot forward; if it looks stale, revise it on your next plot line.";
77
+ /**
78
+ * WHY THE DELEGATION ROWS CARRY NO `toolFilter`, although the host's own alpha.1/alpha.2
79
+ * list denied `schedule_*` there.
80
+ *
81
+ * Measured on a real 0.2.1-alpha.4 boot: `tool-subagent` does NOT strip an unknown key —
82
+ * it rejects the removed one outright, and the WHOLE preset goes broken:
83
+ * `tool-subagent: toolFilter is no longer supported; configure persona and tool plugins
84
+ * in an Agent Preset and select it with agentPreset (spawn only)`
85
+ * while the same composition on 0.2.0-rc.2 (which still accepts `toolFilter`) mounts. So a
86
+ * key that one supported host accepts and the next one THROWS on is worse than dropping it:
87
+ * the deny list protected nothing on rc.2 (no schedule tools exist there at all) and would
88
+ * break every chapters session on the alpha. The general rule this incident writes down:
89
+ * carry only config keys EVERY supported host accepts, and let the roster line — not a
90
+ * file on disk — be the evidence that the composition is usable.
91
+ */
92
+ /**
93
+ * The chapters preset: the host's standard coding-agent composition with EXACTLY
94
+ * four deltas, each one a product decision of ours.
95
+ *
96
+ * 1. `compaction-basic` → `@treeseed/dsh-chapters/engine` (thresholdRatio 0.9):
97
+ * the zero-inference `summarize()` — chapters from the log, no model tokens.
98
+ * 2. `tool-result-pruner.thresholdChars` 8192 → 1000000, deliberately dormant:
99
+ * chapters defer oversized results at ARCHIVE time (verbatim bodies +
100
+ * artifact references), never in-surface, where a prune is a prefix cliff on
101
+ * local hardware.
102
+ * 3. the persona gains the PLOT: suffix (plot carriage through in-place
103
+ * checkpoints) and keeps no `{{cwd}}` (see PLOT_SUFFIX).
104
+ * 4. `tool-ralph` mounted ENABLED — the bounded goal loop the continuation
105
+ * children run. The host ships it disabled; enabling it here is ours.
106
+ *
107
+ * @param platform the platform the shell-gated rows are decided against; a
108
+ * parameter so the rows are testable on any machine.
109
+ */
110
+ export function chaptersPresetRows(platform = process.platform, thresholdRatio = 0.9) {
111
+ return [
112
+ {
113
+ id: 'persona',
114
+ name: '@deepseek-ai/dsh-persona',
115
+ config: { prefix: 'You are a coding agent powered by the {{model}} model.', suffix: PLOT_SUFFIX },
116
+ },
117
+ { id: 'agent-instructions', name: '@deepseek-ai/dsh-agent-instructions', config: { maxBytes: 65536 } },
118
+ { id: 'time-context', name: '@deepseek-ai/dsh-time-context' },
119
+ { id: 'tool-bash', name: '@deepseek-ai/dsh-tool-bash', disabled: platform === 'win32' },
120
+ { id: 'tool-pwsh', name: '@deepseek-ai/dsh-tool-pwsh', disabled: platform !== 'win32' },
121
+ { id: 'tool-fs', name: '@deepseek-ai/dsh-tool-fs' },
122
+ { id: 'tool-fs-search', name: '@deepseek-ai/dsh-tool-fs-search', config: { sampleOverCapGlobResults: false } },
123
+ { id: 'tool-jobs', name: '@deepseek-ai/dsh-tool-jobs' },
124
+ { id: 'tool-schedule', name: '@deepseek-ai/dsh-tool-schedule' },
125
+ { id: 'skill-filesystem', name: '@deepseek-ai/dsh-skill-filesystem' },
126
+ { id: 'tool-skill', name: '@deepseek-ai/dsh-tool-skill' },
127
+ { id: 'command-goal', name: '@deepseek-ai/dsh-command-goal' },
128
+ { id: 'tool-goal', name: '@deepseek-ai/dsh-tool-goal' },
129
+ {
130
+ id: 'planning',
131
+ name: 'cordis:group',
132
+ group: true,
133
+ isolate: { planMode: true },
134
+ config: [{ id: 'plan-mode', name: '@deepseek-ai/dsh-plan-mode', config: { section: PLAN_MODE_SECTION } }],
135
+ },
136
+ {
137
+ id: 'compaction',
138
+ name: 'cordis:group',
139
+ group: true,
140
+ isolate: { compaction: true, toolResultPruner: true },
141
+ config: [
142
+ { id: 'chapters-engine', name: '@treeseed/dsh-chapters/engine', config: { thresholdRatio } },
143
+ { id: 'command-compact', name: '@deepseek-ai/dsh-command-compact' },
144
+ // Delta 2: dormant by choice, not by accident. Keep the key set exactly
145
+ // {thresholdChars, headChars, tailChars} — this plugin rejects unknown keys.
146
+ { id: 'tool-result-pruner', name: '@deepseek-ai/dsh-compaction-tool-result-pruner', config: { thresholdChars: 1000000, headChars: 4096, tailChars: 1024 } },
147
+ ],
148
+ },
149
+ {
150
+ id: 'delegation',
151
+ name: 'cordis:group',
152
+ group: true,
153
+ isolate: { workflowEngine: true },
154
+ config: [
155
+ { id: 'tool-subagent-control', name: '@deepseek-ai/dsh-tool-subagent-control' },
156
+ { id: 'tool-subagent-list-agents', name: '@deepseek-ai/dsh-tool-subagent-control/list-agents' },
157
+ {
158
+ id: 'tool-subagent',
159
+ name: '@deepseek-ai/dsh-tool-subagent',
160
+ config: { provider: 'spawn', toolName: 'subagent', modelSelectionSettings: true, backgroundMode: 'continuable' },
161
+ },
162
+ {
163
+ id: 'tool-subagent-fork',
164
+ name: '@deepseek-ai/dsh-tool-subagent',
165
+ config: { provider: 'fork', toolName: 'subagent_fork', backgroundMode: 'continuable' },
166
+ },
167
+ {
168
+ id: 'workflow-ptc',
169
+ name: '@deepseek-ai/dsh-workflow-ptc',
170
+ config: { provider: 'spawn' },
171
+ },
172
+ { id: 'tool-workflow', name: '@deepseek-ai/dsh-tool-workflow' },
173
+ // Delta 4: enabled, where the host standard list mounts it disabled.
174
+ { id: 'tool-ralph', name: '@deepseek-ai/dsh-tool-ralph', config: { subagentProvider: 'spawn', maxRounds: 64 } },
175
+ ],
176
+ },
177
+ { id: 'tool-ask-user', name: '@deepseek-ai/dsh-tool-ask-user' },
178
+ { id: 'tool-todo', name: '@deepseek-ai/dsh-tool-todo', config: { allowParallelInProgress: true } },
179
+ { id: 'tool-web', name: '@deepseek-ai/dsh-tool-web', config: { fetch: true, searchTimeoutMs: 60000 } },
180
+ { id: 'present', name: '@deepseek-ai/dsh-tool-present' },
181
+ // Disabled by host policy; the row stays so a profile `override` can switch it.
182
+ { id: 'tool-plugin-manager', name: '@deepseek-ai/dsh-plugin-manager/tools', disabled: true },
183
+ ];
184
+ }
185
+ /** The preset identity. `config.id` is DURABLE STATE: every continuation child's
186
+ * log records it as `agent-preset/selected`, so renaming it orphans those
187
+ * sessions (`agent-preset/not-found` on open). */
188
+ export const CHAPTERS_PRESET_ID = 'chapters';
189
+ export function chaptersPresetDefinition(platform = process.platform, thresholdRatio = 0.9) {
190
+ return {
191
+ id: CHAPTERS_PRESET_ID,
192
+ name: 'Chapters',
193
+ description: 'Full coding agent; context relief via zero-inference chapter compaction.',
194
+ order: 0,
195
+ plugins: chaptersPresetRows(platform, thresholdRatio),
196
+ };
197
+ }
198
+ /** Whether a row names something a resolver must answer for. `cordis:` rows are
199
+ * pseudo-modules the Loader always provides; our own package is by definition
200
+ * present (its realm row is the point of the preset). */
201
+ function needsProbe(row) {
202
+ return !row.name.startsWith('cordis:') && !row.name.startsWith('@treeseed/dsh-chapters');
203
+ }
204
+ /** A row whose own module cannot be imported would activate as failed, and one
205
+ * failed row makes the WHOLE preset broken (`mountPreset` throws) — so it is
206
+ * dropped, with the reason, instead of taking every chapters session down.
207
+ *
208
+ * The probe is asked with the row's FULL specifier, so a package that exists but
209
+ * no longer exports the subpath (`.../tools`, `.../list-agents`) is caught too —
210
+ * those are the renames that eat presets.
211
+ *
212
+ * @param rows the composition, groups included.
213
+ * @param resolvable asked with each row's module specifier. MUST NOT throw.
214
+ */
215
+ export function pruneResolvableRows(rows, resolvable) {
216
+ const dropped = [];
217
+ const keep = (row) => {
218
+ if (!needsProbe(row))
219
+ return true;
220
+ if (resolvable(row.name))
221
+ return true;
222
+ dropped.push(`${row.id} (${row.name})`);
223
+ return false;
224
+ };
225
+ const visit = (list) => list.flatMap((row) => {
226
+ if (row.group !== true || !Array.isArray(row.config))
227
+ return keep(row) ? [row] : [];
228
+ const children = row.config.filter(keep);
229
+ if (children.length === 0) {
230
+ dropped.push(`${row.id} (group emptied)`);
231
+ return [];
232
+ }
233
+ return [{ ...row, config: children }];
234
+ });
235
+ return { kept: visit(rows), dropped };
236
+ }
237
+ /** Find one preset in an inventory response, tolerating a missing or odd shape. */
238
+ export function inventoryEntry(raw, presetId) {
239
+ return Array.isArray(raw) ? raw.find((entry) => entry?.id === presetId) : undefined;
240
+ }
241
+ /** Enabled rows of one preset that are not active. A row `pending` a host service can
242
+ * still activate later, so this is reported apart from `broken`, never as a refusal. */
243
+ export function unusableRows(entry) {
244
+ if (!Array.isArray(entry?.rows))
245
+ return [];
246
+ return entry.rows
247
+ .filter((row) => row.enabled !== false && typeof row.fiberState === 'string' && row.fiberState !== 'active')
248
+ .map((row) => `${row.entryId ?? '?'} (${row.moduleName ?? '?'}) ${row.fiberState}`);
249
+ }
250
+ /**
251
+ * Make the `chapters` preset exist on a host that composes presets from
252
+ * declaration rows, and say what happened.
253
+ *
254
+ * @param presets the host's `agentPresets` service, or undefined on a host that
255
+ * has no preset registry at all (then the legacy directory copy is the
256
+ * delivery, and this returns 'unsupported').
257
+ * @param dispose owner for the disposer the registry hands back — registering
258
+ * without it would leave a standing preset mount after unmount.
259
+ */
260
+ export async function registerChaptersPreset(presets, opts) {
261
+ const definition = chaptersPresetDefinition(opts.platform, opts.thresholdRatio ?? 0.9);
262
+ if (typeof presets?.register !== 'function')
263
+ return { outcome: { state: 'unsupported' }, definition };
264
+ const { kept, dropped } = pruneResolvableRows(definition.plugins, opts.resolvable);
265
+ const pruned = { ...definition, plugins: kept };
266
+ try {
267
+ const disposer = await presets.register(pruned);
268
+ opts.dispose(disposer);
269
+ }
270
+ catch (error) {
271
+ const reason = String(error?.message ?? error);
272
+ // A duplicate is not our failure: someone declared `chapters` in a patch
273
+ // layer (the documented 0.2.x remedy before this shipped). Their row wins;
274
+ // ours must not throw, or this plugin's own row fails to activate and the
275
+ // tools disappear with it.
276
+ if (/duplicate agent preset/i.test(reason))
277
+ return { outcome: { state: 'already-declared' }, definition: pruned };
278
+ return { outcome: { state: 'failed', reason }, definition: pruned };
279
+ }
280
+ return { outcome: dropped.length > 0 ? { state: 'pruned', dropped } : { state: 'registered' }, definition: pruned };
281
+ }
282
+ //# sourceMappingURL=preset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset.js","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAuBH;;yDAEyD;AACzD,MAAM,iBAAiB,GAAG;;;;;;;;;;;CAWzB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,GAAG,oPAAoP,CAAA;AAExQ;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAA4B,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,GAAG;IACnG,OAAO;QACL;YACE,EAAE,EAAE,SAAS;YACb,IAAI,EAAE,0BAA0B;YAChC,MAAM,EAAE,EAAE,MAAM,EAAE,wDAAwD,EAAE,MAAM,EAAE,WAAW,EAAE;SAClG;QACD,EAAE,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,qCAAqC,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtG,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,+BAA+B,EAAE;QAC7D,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,4BAA4B,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,EAAE;QACvF,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,4BAA4B,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,EAAE;QACvF,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,0BAA0B,EAAE;QACnD,EAAE,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,iCAAiC,EAAE,MAAM,EAAE,EAAE,wBAAwB,EAAE,KAAK,EAAE,EAAE;QAC9G,EAAE,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O,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;IACrE,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;AACrH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/dsh-chapters",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "dsh plugin: verbatim chapter archive + zero-token index for small-context models",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -13,7 +13,6 @@
13
13
  "./cordis.patch.yml": "./cordis.patch.yml",
14
14
  "./package.json": "./package.json",
15
15
  "./engine": "./lib/engine.js",
16
- "./presets/*": "./presets/*",
17
16
  "./tools": "./lib/tools.js",
18
17
  "./store": "./lib/store.js",
19
18
  "./registry": "./lib/registry.js",
@@ -21,7 +20,6 @@
21
20
  },
22
21
  "files": [
23
22
  "lib",
24
- "presets",
25
23
  "cordis.patch.yml",
26
24
  "docs",
27
25
  "README.md"