@opengsd/gsd-core 1.7.0-rc.3 → 1.7.0-rc.4

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.
Files changed (45) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.ja-JP.md +4 -3
  4. package/README.ko-KR.md +4 -3
  5. package/README.md +4 -3
  6. package/README.pt-BR.md +4 -3
  7. package/README.zh-CN.md +4 -3
  8. package/bin/install.js +33 -15
  9. package/commands/gsd/map-codebase.md +4 -4
  10. package/commands/gsd/ns-project.md +2 -1
  11. package/commands/gsd/onboard.md +46 -0
  12. package/gsd-core/bin/gsd-tools.cjs +47 -2
  13. package/gsd-core/bin/lib/capability-registry.cjs +467 -49
  14. package/gsd-core/bin/lib/capability-state.cjs +117 -18
  15. package/gsd-core/bin/lib/capability-writer.cjs +11 -1
  16. package/gsd-core/bin/lib/claude-orchestration-command-router.cjs +136 -0
  17. package/gsd-core/bin/lib/claude-orchestration.cjs +404 -0
  18. package/gsd-core/bin/lib/clusters.cjs +1 -0
  19. package/gsd-core/bin/lib/command-aliases.cjs +8 -0
  20. package/gsd-core/bin/lib/init-command-router.cjs +4 -0
  21. package/gsd-core/bin/lib/init.cjs +25 -69
  22. package/gsd-core/bin/lib/install-engine.cjs +8 -5
  23. package/gsd-core/bin/lib/install-profiles.cjs +2 -0
  24. package/gsd-core/bin/lib/loop-resolver.cjs +7 -1
  25. package/gsd-core/bin/lib/model-resolver.cjs +69 -4
  26. package/gsd-core/bin/lib/onboard-projection.cjs +309 -0
  27. package/gsd-core/bin/lib/runtime-name-policy.cjs +3 -1
  28. package/gsd-core/bin/lib/surface.cjs +51 -30
  29. package/gsd-core/bin/shared/model-catalog.json +5 -0
  30. package/gsd-core/references/gsd-run-resolver.md +8 -0
  31. package/gsd-core/templates/project.md +1 -1
  32. package/gsd-core/workflows/do.md +4 -3
  33. package/gsd-core/workflows/help/modes/brief.md +2 -1
  34. package/gsd-core/workflows/help/modes/default.md +2 -1
  35. package/gsd-core/workflows/help/modes/full.md +11 -1
  36. package/gsd-core/workflows/help/modes/topic.md +1 -1
  37. package/gsd-core/workflows/onboard.md +277 -0
  38. package/gsd-core/workflows/quick.md +20 -0
  39. package/package.json +1 -1
  40. package/scripts/gen-golden-install-parity-zcode.cjs +77 -0
  41. package/scripts/run-tests.cjs +5 -3
  42. package/scripts/sync-runtime-launcher.cjs +20 -2
  43. package/skills/gsd-map-codebase/SKILL.md +3 -3
  44. package/skills/gsd-ns-project/SKILL.md +1 -0
  45. package/skills/gsd-onboard/SKILL.md +46 -0
@@ -0,0 +1,404 @@
1
+ "use strict";
2
+ /**
3
+ * Claude Orchestration Capability — Workflow-tool backend detection + emitter
4
+ *
5
+ * #1143 — adopts Claude Code's Workflow tool (the engine behind `/effort ultracode`)
6
+ * as an optional, runtime-gated parallel-execution backend for the GSD loop.
7
+ *
8
+ * This module is the pure, testable core of the capability. It owns two seams:
9
+ *
10
+ * detectWorkflowBackend({ runtimeId, hostIntegration, config, agentSdkVersion })
11
+ * → { available: boolean, backend: 'workflow'|'inline', reason: string }
12
+ * Fail-closed: every miss degrades to `inline` (today's behaviour), so the
13
+ * core loop is byte-identical unless every gate opens. This is criteria 3 + 6.
14
+ *
15
+ * emitWorkflowScript({ phaseDir, waves, runId, budgetTokens? })
16
+ * → { ok:true, script, summary } | { ok:false, reason }
17
+ * Maps GSD's wave/plan model 1:1 onto Workflow primitives:
18
+ * wave → sequential `parallel()` stage barriers,
19
+ * plan → `agent(brief, { agentType:'gsd-executor', isolation:'worktree' })`,
20
+ * files_modified overlap → forces plans into separate sequential stages
21
+ * (the same overlap rule execute-phase already applies inline),
22
+ * resumeFromRunId → wired to the phase run id,
23
+ * budgetTokens → a shared token pool.
24
+ * The emitted script composes the SAME gsd-executor agent and worktree
25
+ * isolation the inline path uses, so it produces the same artifacts/commits
26
+ * (criterion 2). It is a generated string consumed by the orchestrator; this
27
+ * module never invokes the Workflow tool itself.
28
+ *
29
+ * Design laws:
30
+ * - Gall's Law: ship a small working slice that composes existing primitives
31
+ * (gsd-executor + worktree isolation) rather than reinventing them.
32
+ * - Greenspun's Tenth Rule (cited in #1143): adopt the Workflow tool's
33
+ * barrier/pipeline/budget/resume semantics instead of hand-rolling them.
34
+ * - Postel's Law: liberal in input (missing fields → inline), conservative in
35
+ * output (workflow only when every gate opens).
36
+ * - Fail-closed: an unknown version, a missing descriptor, or a disabled
37
+ * toggle all resolve to `inline`, never to `workflow`.
38
+ *
39
+ * Zero external dependencies. Pure functions. Never throws on bad input.
40
+ */
41
+ // ─── Constants ────────────────────────────────────────────────────────────────
42
+ /**
43
+ * The Agent SDK version that introduced the Workflow tool (#1143 prior art).
44
+ * Used as the default floor when config does not override it. A runtime reporting
45
+ * an agentSdkVersion below this cannot host the Workflow backend.
46
+ */
47
+ const WORKFLOW_TOOL_FLOOR_VERSION = '0.3.149';
48
+ /** Closed enum for the `claude_orchestration.execution_backend` config key. */
49
+ const BACKEND_VALUES = new Set(['auto', 'workflow', 'inline']);
50
+ /** Only this runtime can host the Workflow tool (Claude Code / Agent SDK). */
51
+ const WORKFLOW_RUNTIME = 'claude';
52
+ // ─── Semver helpers ───────────────────────────────────────────────────────────
53
+ /** Official-ish strict SemVer 2.0.0 numeric triple (+ optional pre/build). */
54
+ const SEMVER_RE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
55
+ /** True for a syntactically valid semver string. */
56
+ function isValidSemver(s) {
57
+ return typeof s === 'string' && SEMVER_RE.test(s);
58
+ }
59
+ /**
60
+ * Compare two semver strings.
61
+ * Returns -1/0/1 in the usual sense. Garbage in either position → -1 (fail-closed:
62
+ * an unparseable version is treated as "less than" any real floor, so detection
63
+ * never accidentally enables the preview backend on an unknown SDK).
64
+ *
65
+ * Pre-release/build metadata are ignored for the comparison — only the numeric
66
+ * major.minor.patch triple participates, matching how the Workflow-tool floor is
67
+ * specified (a plain "0.3.149").
68
+ */
69
+ function compareSemver(a, b) {
70
+ if (!isValidSemver(a) || !isValidSemver(b))
71
+ return -1;
72
+ // Split numeric triple from pre-release/build metadata.
73
+ const parseTriple = (s) => {
74
+ const core = s.split('-')[0].split('+')[0].split('.');
75
+ return [parseInt(core[0], 10), parseInt(core[1], 10), parseInt(core[2], 10)];
76
+ };
77
+ const hasPre = (s) => s.indexOf('-') !== -1;
78
+ const preIdentifiers = (s) => (s.split('-')[1] || '').split('+')[0].split('.').filter((x) => x.length > 0);
79
+ const am = parseTriple(a);
80
+ const bm = parseTriple(b);
81
+ for (let i = 0; i < 3; i++) {
82
+ if (am[i] < bm[i])
83
+ return -1;
84
+ if (am[i] > bm[i])
85
+ return 1;
86
+ }
87
+ // Numeric triple is equal. SemVer 2.0.0 §11 precedence:
88
+ // - a version WITH a pre-release tag is LOWER than the same triple WITHOUT one
89
+ // (keeps the floor fail-closed for pre-release builds of the GA floor);
90
+ // - two pre-releases of the same triple are ordered by their dot-separated
91
+ // identifiers (numeric < alphanumeric; numeric compared numerically,
92
+ // alphanumeric lexically; fewer identifiers < more).
93
+ const aPre = hasPre(a);
94
+ const bPre = hasPre(b);
95
+ if (aPre && !bPre)
96
+ return -1;
97
+ if (!aPre && bPre)
98
+ return 1;
99
+ if (aPre && bPre) {
100
+ const ai = preIdentifiers(a);
101
+ const bi = preIdentifiers(b);
102
+ const len = Math.min(ai.length, bi.length);
103
+ for (let i = 0; i < len; i++) {
104
+ const ax = ai[i];
105
+ const bx = bi[i];
106
+ const aNum = /^\d+$/.test(ax);
107
+ const bNum = /^\d+$/.test(bx);
108
+ if (aNum && bNum) {
109
+ const an = parseInt(ax, 10);
110
+ const bn = parseInt(bx, 10);
111
+ if (an < bn)
112
+ return -1;
113
+ if (an > bn)
114
+ return 1;
115
+ }
116
+ else if (aNum && !bNum) {
117
+ return -1; // numeric identifiers always lower than alphanumeric
118
+ }
119
+ else if (!aNum && bNum) {
120
+ return 1;
121
+ }
122
+ else {
123
+ if (ax < bx)
124
+ return -1;
125
+ if (ax > bx)
126
+ return 1;
127
+ }
128
+ }
129
+ if (ai.length < bi.length)
130
+ return -1;
131
+ if (ai.length > bi.length)
132
+ return 1;
133
+ }
134
+ return 0;
135
+ }
136
+ /** Inline result shorthand. */
137
+ function inline(reason, available = false) {
138
+ return { available, backend: 'inline', reason };
139
+ }
140
+ /**
141
+ * Resolve whether the Workflow-tool backend should activate.
142
+ *
143
+ * Gate ladder (all must pass for `workflow`; first miss wins, fail-closed):
144
+ * 1. capability enabled (claude_orchestration.enabled truthy)
145
+ * 2. runtime is Claude (the only runtime that exposes the Workflow tool)
146
+ * 3. execution_backend !== 'inline'
147
+ * 4. host descriptor signals nested+background dispatch (Workflow-tool capable)
148
+ * 5. agentSdkVersion is a known, valid semver
149
+ * 6. agentSdkVersion >= the configured floor (default WORKFLOW_TOOL_FLOOR_VERSION)
150
+ * 7. execution_backend === 'workflow' OR 'auto' (both reach here; 'inline' exited at 3)
151
+ *
152
+ * Never throws. Destructures defensively.
153
+ */
154
+ function detectWorkflowBackend(input) {
155
+ if (input === null || input === undefined || typeof input !== 'object') {
156
+ return inline('capability_disabled');
157
+ }
158
+ const cfg = (input.config !== null && input.config !== undefined && typeof input.config === 'object')
159
+ ? input.config
160
+ : {};
161
+ // 1. capability must be opted in (default-off — ships disabled).
162
+ if (!cfg['claude_orchestration.enabled']) {
163
+ return inline('capability_disabled');
164
+ }
165
+ // 2. only Claude can host the Workflow tool.
166
+ if (input.runtimeId !== WORKFLOW_RUNTIME) {
167
+ return inline('runtime_not_claude');
168
+ }
169
+ // 3. explicit inline opt-out short-circuits.
170
+ let backendRaw = cfg['claude_orchestration.execution_backend'];
171
+ if (typeof backendRaw !== 'string' || !BACKEND_VALUES.has(backendRaw)) {
172
+ backendRaw = 'auto';
173
+ }
174
+ if (backendRaw === 'inline') {
175
+ return inline('backend_inline');
176
+ }
177
+ // 4. the host dispatch descriptor must be the nesting-capable Claude-Code shape
178
+ // (a proxy for Workflow-tool presence). This is Claude-specific and already
179
+ // gated at step 2; `background:true` alone is true on several non-Claude hosts,
180
+ // so the proxy is only meaningful after the runtime check above. Note: this is
181
+ // NOT the canonical `shouldFlattenDispatch` rule (which keys on
182
+ // `backgroundDispatch`); the Workflow backend works precisely because a single
183
+ // tool-call orchestrates internally, sidestepping the backgroundDispatch:false
184
+ // limitation. Missing/false/foreign descriptor → fail-closed.
185
+ const hi = input.hostIntegration;
186
+ if (hi === null || hi === undefined || typeof hi !== 'object' || Array.isArray(hi)) {
187
+ return inline('workflow_tool_unavailable');
188
+ }
189
+ const dispatch = hi.dispatch;
190
+ if (typeof dispatch !== 'object' || dispatch === null || Array.isArray(dispatch)) {
191
+ return inline('workflow_tool_unavailable');
192
+ }
193
+ const nested = dispatch['nested'];
194
+ const background = dispatch['background'];
195
+ if (nested !== true || background !== true) {
196
+ return inline('workflow_tool_unavailable');
197
+ }
198
+ // 5. an unknown agentSdkVersion cannot be trusted to meet the floor.
199
+ if (!isValidSemver(input.agentSdkVersion)) {
200
+ return inline('agent_sdk_version_unknown');
201
+ }
202
+ // 6. version floor (config override > default constant).
203
+ const floorRaw = cfg['claude_orchestration.min_agent_sdk_version'];
204
+ const floor = typeof floorRaw === 'string' && isValidSemver(floorRaw) ? floorRaw : WORKFLOW_TOOL_FLOOR_VERSION;
205
+ if (compareSemver(input.agentSdkVersion, floor) < 0) {
206
+ return inline('agent_sdk_version_below_floor');
207
+ }
208
+ // 7. auto/workflow both reach the workflow backend once every gate passes.
209
+ return { available: true, backend: 'workflow', reason: 'workflow_backend_active' };
210
+ }
211
+ /**
212
+ * Partition a wave's plans into a near-minimal number of sequential stages (via
213
+ * greedy first-fit — not guaranteed optimal for arbitrary overlap graphs, but
214
+ * correct: no two plans sharing a file ever cohabit a stage) such that no two
215
+ * plans in the same stage share a modified file. Each plan goes into the earliest
216
+ * stage where it does not overlap any plan already there.
217
+ *
218
+ * A plan with an EMPTY files_modified set declares no files; it overlaps nothing
219
+ * and coalesces into stage 0 (same behavior as the inline path, which also cannot
220
+ * guard against undeclared concurrent writes — declare filesModified accurately).
221
+ *
222
+ * This is the same overlap rule execute-phase applies inline — the only difference
223
+ * is the execution vehicle (Workflow `parallel()` vs one-agent-per-message).
224
+ */
225
+ function partitionStages(plans) {
226
+ const stages = [];
227
+ for (const plan of plans) {
228
+ const fileSet = new Set(plan.files_modified);
229
+ let placed = false;
230
+ for (const stage of stages) {
231
+ let overlap = false;
232
+ for (const f of fileSet) {
233
+ if (stage.files.has(f)) {
234
+ overlap = true;
235
+ break;
236
+ }
237
+ }
238
+ if (!overlap) {
239
+ stage.plans.push(plan);
240
+ for (const f of fileSet)
241
+ stage.files.add(f);
242
+ placed = true;
243
+ break;
244
+ }
245
+ }
246
+ if (!placed) {
247
+ stages.push({ plans: [plan], files: new Set(fileSet) });
248
+ }
249
+ }
250
+ return stages.map((s) => s.plans.map((p) => p.id));
251
+ }
252
+ /**
253
+ * Quote a free-text value for safe embedding as a JavaScript/Workflow double-quoted
254
+ * string literal. Uses JSON.stringify so every JS-relevant escape (backslash, quote,
255
+ * newline, tab, NUL, U+2028/U+2029, all control chars) is handled by the language
256
+ * itself — there is no hand-rolled escape table to drift. Returns the value already
257
+ * wrapped in its surrounding quotes.
258
+ */
259
+ function quoteString(s) {
260
+ return JSON.stringify(s);
261
+ }
262
+ /**
263
+ * True if `s` is a safe identifier/path token to interpolate into the generated
264
+ * script WITHOUT requiring a string-literal context — i.e. it contains no
265
+ * character that could terminate a comment line (`\n`/`\r`), break out of a
266
+ * string literal (`"` / `\`), or smuggle a NUL/control sequence. Used for
267
+ * `phaseDir`, `runId`, `wave.id`, and `plan.id`, which are identifiers/paths and
268
+ * must never legitimately contain such characters. Rejecting them at validation
269
+ * (rather than silently flattening) keeps the emitted script faithful to input.
270
+ */
271
+ const UNSCRIPTABLE_CHAR_RE = /[\r\n"\\\x00-\x1f\x7f\u2028\u2029]/;
272
+ function isScriptableIdentifier(s) {
273
+ if (typeof s !== 'string' || s.length === 0)
274
+ return false;
275
+ return !UNSCRIPTABLE_CHAR_RE.test(s);
276
+ }
277
+ /**
278
+ * Emit a Workflow script mapping the phase's wave/plan model onto Workflow
279
+ * primitives. Pure and deterministic: identical input yields an identical string.
280
+ *
281
+ * Returns ok:false (never throws) on invalid input — empty waves, missing runId,
282
+ * a wave with no plans, etc.
283
+ */
284
+ function emitWorkflowScript(input) {
285
+ if (input === null || input === undefined || typeof input !== 'object') {
286
+ return { ok: false, reason: 'invalid_input' };
287
+ }
288
+ const { phaseDir, waves, runId } = input;
289
+ // Identifiers/paths interpolated into the generated script must be free of any
290
+ // character that could terminate a comment, break out of a string literal, or
291
+ // smuggle control bytes — reject up front (security: #1143 review Finding 1).
292
+ if (!isScriptableIdentifier(phaseDir)) {
293
+ return { ok: false, reason: 'phaseDir must be a non-empty string without newlines/quotes/backslash/control chars' };
294
+ }
295
+ if (!isScriptableIdentifier(runId)) {
296
+ return { ok: false, reason: 'runId must be a non-empty string without newlines/quotes/backslash/control chars' };
297
+ }
298
+ if (!Array.isArray(waves) || waves.length === 0) {
299
+ return { ok: false, reason: 'waves must be a non-empty array' };
300
+ }
301
+ for (let i = 0; i < waves.length; i++) {
302
+ const w = waves[i];
303
+ if (w === null || typeof w !== 'object' || typeof w.id !== 'string') {
304
+ return { ok: false, reason: 'waves[' + i + '] must be { id, plans: non-empty[] }' };
305
+ }
306
+ if (!isScriptableIdentifier(w.id)) {
307
+ return { ok: false, reason: 'waves[' + i + '].id must not contain newlines/quotes/backslash/control chars' };
308
+ }
309
+ if (!Array.isArray(w.plans) || w.plans.length === 0) {
310
+ return { ok: false, reason: 'waves[' + i + '] must have a non-empty plans array' };
311
+ }
312
+ const seenIds = new Set();
313
+ for (let j = 0; j < w.plans.length; j++) {
314
+ const p = w.plans[j];
315
+ if (p === null || typeof p !== 'object' || typeof p.id !== 'string' || typeof p.brief !== 'string' || !Array.isArray(p.files_modified)) {
316
+ return { ok: false, reason: 'waves[' + i + '].plans[' + j + '] must be { id, brief, files_modified[] }' };
317
+ }
318
+ if (!isScriptableIdentifier(p.id)) {
319
+ return { ok: false, reason: 'waves[' + i + '].plans[' + j + '].id must not contain newlines/quotes/backslash/control chars' };
320
+ }
321
+ if (seenIds.has(p.id)) {
322
+ return { ok: false, reason: 'waves[' + i + '] has duplicate plan id "' + p.id + '"' };
323
+ }
324
+ seenIds.add(p.id);
325
+ for (const f of p.files_modified) {
326
+ if (typeof f !== 'string' || f.length === 0) {
327
+ return { ok: false, reason: 'waves[' + i + '].plans[' + j + '].files_modified entries must be non-empty strings' };
328
+ }
329
+ }
330
+ }
331
+ }
332
+ const budgetTokens = (typeof input.budgetTokens === 'number' && Number.isFinite(input.budgetTokens) && input.budgetTokens > 0)
333
+ ? Math.floor(input.budgetTokens)
334
+ : null;
335
+ const lines = [];
336
+ lines.push('// GSD Workflow script — generated by the claude-orchestration capability (#1143)');
337
+ lines.push('// phase: ' + phaseDir);
338
+ lines.push('// BETA: preview-grade; on any failure the orchestrator falls back to inline dispatch.');
339
+ lines.push('// Composes the SAME gsd-executor agent + worktree isolation as the inline path,');
340
+ lines.push('// so artifacts (SUMMARY.md) and commits are produced identically.');
341
+ lines.push('resumeFromRunId(' + quoteString(runId) + ')');
342
+ if (budgetTokens !== null) {
343
+ lines.push('budget(' + budgetTokens + ')');
344
+ }
345
+ lines.push('');
346
+ const stagesByWave = [];
347
+ let totalPlans = 0;
348
+ for (let wi = 0; wi < waves.length; wi++) {
349
+ const wave = waves[wi];
350
+ const stages = partitionStages(wave.plans);
351
+ stagesByWave.push(stages);
352
+ totalPlans += wave.plans.length;
353
+ lines.push('// Wave ' + wave.id);
354
+ for (let si = 0; si < stages.length; si++) {
355
+ const stagePlanIds = stages[si];
356
+ // Resolve back to plan objects for briefs (ids are unique within a wave — validated above).
357
+ const stagePlans = stagePlanIds.map((id) => wave.plans.find((p) => p.id === id));
358
+ if (stages.length > 1) {
359
+ lines.push('// Stage ' + si + (si > 0 ? ' (sequential — files_modified overlap)' : ''));
360
+ }
361
+ if (stagePlans.length === 1) {
362
+ const p = stagePlans[0];
363
+ lines.push('parallel(');
364
+ lines.push(' agent(' + quoteString(p.brief) + ', { agentType: "gsd-executor", isolation: "worktree" })');
365
+ lines.push(')');
366
+ }
367
+ else {
368
+ lines.push('parallel(');
369
+ for (const p of stagePlans) {
370
+ lines.push(' agent(' + quoteString(p.brief) + ', { agentType: "gsd-executor", isolation: "worktree" }),');
371
+ }
372
+ // Replace trailing comma on the last agent line with nothing.
373
+ const lastIdx = lines.length - 1;
374
+ lines[lastIdx] = lines[lastIdx].replace(/,$/, '');
375
+ lines.push(')');
376
+ }
377
+ }
378
+ if (wi < waves.length - 1)
379
+ lines.push('');
380
+ }
381
+ lines.push('// Each agent writes SUMMARY.md on its worktree branch; commits land there');
382
+ lines.push('// and are merged by the orchestrator exactly as in inline wave dispatch.');
383
+ const script = lines.join('\n');
384
+ return {
385
+ ok: true,
386
+ script,
387
+ summary: {
388
+ waves: waves.length,
389
+ plans: totalPlans,
390
+ stagesByWave,
391
+ resumeRunId: runId,
392
+ budgetTokens,
393
+ },
394
+ };
395
+ }
396
+ module.exports = {
397
+ detectWorkflowBackend,
398
+ emitWorkflowScript,
399
+ compareSemver,
400
+ isValidSemver,
401
+ WORKFLOW_TOOL_FLOOR_VERSION,
402
+ BACKEND_VALUES,
403
+ WORKFLOW_RUNTIME,
404
+ };
@@ -22,6 +22,7 @@ exports.CLUSTERS = Object.freeze({
22
22
  core_loop: Object.freeze([
23
23
  'next',
24
24
  'new-project',
25
+ 'onboard',
25
26
  'discuss-phase',
26
27
  'plan-phase',
27
28
  'execute-phase',
@@ -283,6 +283,14 @@ exports.INIT_COMMAND_ALIASES = [
283
283
  "subcommand": "new-milestone",
284
284
  "mutation": false
285
285
  },
286
+ {
287
+ "canonical": "init.onboard",
288
+ "aliases": [
289
+ "init onboard"
290
+ ],
291
+ "subcommand": "onboard",
292
+ "mutation": false
293
+ },
286
294
  {
287
295
  "canonical": "init.quick",
288
296
  "aliases": [
@@ -39,6 +39,10 @@ function routeInitCommand({ init, args, cwd, raw, error }) {
39
39
  },
40
40
  'new-project': () => init.cmdInitNewProject(cwd, raw),
41
41
  'new-milestone': () => init.cmdInitNewMilestone(cwd, raw),
42
+ onboard: () => {
43
+ const namedArgs = (0, command_arg_projection_cjs_1.parseNamedArgs)(args, [], ['fast', 'text']);
44
+ init.cmdInitOnboard(cwd, raw, { fast: namedArgs['fast'], text: namedArgs['text'] });
45
+ },
42
46
  quick: () => init.cmdInitQuick(cwd, args.slice(2).join(' '), raw),
43
47
  'ingest-docs': () => init.cmdInitIngestDocs(cwd, raw),
44
48
  resume: () => init.cmdInitResume(cwd, raw),
@@ -54,6 +54,9 @@ const { checkAgentsInstalled } = agentInstallCheck;
54
54
  const gitBaseBranch = require("./git-base-branch.cjs");
55
55
  const { gitWorktreeInfoInternal } = gitBaseBranch;
56
56
  const resolution_cjs_1 = require("./resolution.cjs");
57
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- onboard-projection.cjs is an export= CommonJS module
58
+ const onboardProjection = require("./onboard-projection.cjs");
59
+ const { REQUIRED_CODEBASE_MAP_FILES, buildOnboardProjection, hasCodeFilesInternal, hasPackageFileInternal, listCodebaseMapFiles, } = onboardProjection;
57
60
  const { output, error } = io;
58
61
  const { loadConfig, loadConfigResolved } = configLoader;
59
62
  const { resolveModelInternal, resolveGranularityInternal, assertValidGranularityOverride } = modelResolver;
@@ -479,84 +482,23 @@ function cmdInitNewProject(cwd, raw) {
479
482
  const hasFirecrawl = !!(process.env['FIRECRAWL_API_KEY'] || node_fs_1.default.existsSync(firecrawlKeyFile));
480
483
  const exaKeyFile = node_path_1.default.join(homedir, '.gsd', 'exa_api_key');
481
484
  const hasExaSearch = !!(process.env['EXA_API_KEY'] || node_fs_1.default.existsSync(exaKeyFile));
482
- let hasCode = false;
483
- let hasPackageFile = false;
484
- try {
485
- const codeExtensions = new Set([
486
- '.ts', '.js', '.py', '.go', '.rs', '.swift', '.java',
487
- '.kt', '.kts',
488
- '.c', '.cpp', '.h',
489
- '.cs',
490
- '.rb',
491
- '.php',
492
- '.dart',
493
- '.m', '.mm',
494
- '.scala',
495
- '.groovy',
496
- '.lua',
497
- '.r', '.R',
498
- '.zig',
499
- '.ex', '.exs',
500
- '.clj',
501
- ]);
502
- const skipDirs = new Set([
503
- 'node_modules', '.git', '.planning', '.claude', '.codex',
504
- '__pycache__', 'target', 'dist', 'build',
505
- ]);
506
- function findCodeFiles(dir, depth) {
507
- if (depth > 3)
508
- return false;
509
- let entries;
510
- try {
511
- entries = node_fs_1.default.readdirSync(dir, { withFileTypes: true });
512
- }
513
- catch {
514
- return false;
515
- }
516
- for (const entry of entries) {
517
- if (entry.isFile() && codeExtensions.has(node_path_1.default.extname(entry.name)))
518
- return true;
519
- if (entry.isDirectory() && !skipDirs.has(entry.name)) {
520
- if (findCodeFiles(node_path_1.default.join(dir, entry.name), depth + 1))
521
- return true;
522
- }
523
- }
524
- return false;
525
- }
526
- hasCode = findCodeFiles(cwd, 0);
527
- }
528
- catch {
529
- /* intentionally empty — best-effort detection */
530
- }
531
- hasPackageFile =
532
- pathExistsInternal(cwd, 'package.json') ||
533
- pathExistsInternal(cwd, 'requirements.txt') ||
534
- pathExistsInternal(cwd, 'Cargo.toml') ||
535
- pathExistsInternal(cwd, 'go.mod') ||
536
- pathExistsInternal(cwd, 'Package.swift') ||
537
- pathExistsInternal(cwd, 'build.gradle') ||
538
- pathExistsInternal(cwd, 'build.gradle.kts') ||
539
- pathExistsInternal(cwd, 'pom.xml') ||
540
- pathExistsInternal(cwd, 'Gemfile') ||
541
- pathExistsInternal(cwd, 'composer.json') ||
542
- pathExistsInternal(cwd, 'pubspec.yaml') ||
543
- pathExistsInternal(cwd, 'CMakeLists.txt') ||
544
- pathExistsInternal(cwd, 'Makefile') ||
545
- pathExistsInternal(cwd, 'build.zig') ||
546
- pathExistsInternal(cwd, 'mix.exs') ||
547
- pathExistsInternal(cwd, 'project.clj');
485
+ const hasCode = hasCodeFilesInternal(cwd);
486
+ const hasPackageFile = hasPackageFileInternal(cwd);
487
+ const isBrownfield = hasCode || hasPackageFile;
488
+ const codebaseMapFiles = listCodebaseMapFiles(cwd);
489
+ const hasCodebaseMap = codebaseMapFiles.length === REQUIRED_CODEBASE_MAP_FILES.length;
548
490
  const result = {
549
491
  researcher_model: resolveModelInternal(cwd, 'gsd-project-researcher'),
550
492
  synthesizer_model: resolveModelInternal(cwd, 'gsd-research-synthesizer'),
551
493
  roadmapper_model: resolveModelInternal(cwd, 'gsd-roadmapper'),
552
494
  commit_docs: config.commit_docs,
553
495
  project_exists: pathExistsInternal(cwd, '.planning/PROJECT.md'),
554
- has_codebase_map: pathExistsInternal(cwd, '.planning/codebase'),
496
+ has_codebase_map: hasCodebaseMap,
555
497
  planning_exists: pathExistsInternal(cwd, '.planning'),
556
498
  has_existing_code: hasCode,
557
499
  has_package_file: hasPackageFile,
558
- is_brownfield: hasCode || hasPackageFile,
559
- needs_codebase_map: (hasCode || hasPackageFile) && !pathExistsInternal(cwd, '.planning/codebase'),
500
+ is_brownfield: isBrownfield,
501
+ needs_codebase_map: isBrownfield && !hasCodebaseMap,
560
502
  ...getInitGitState(cwd),
561
503
  brave_search_available: hasBraveSearch,
562
504
  firecrawl_available: hasFirecrawl,
@@ -656,6 +598,19 @@ function cmdInitIngestDocs(cwd, raw) {
656
598
  };
657
599
  output(withProjectRoot(cwd, result), raw);
658
600
  }
601
+ function cmdInitOnboard(cwd, raw, options = {}) {
602
+ const config = loadConfig(cwd);
603
+ const workflowConfig = (config.workflow ?? {});
604
+ const result = {
605
+ ...buildOnboardProjection(cwd, {
606
+ commitDocs: !!config.commit_docs,
607
+ fast: options['fast'] === true,
608
+ textMode: options['text'] === true || !!config.text_mode || !!workflowConfig['text_mode'],
609
+ }),
610
+ ...getInitGitState(cwd),
611
+ };
612
+ output(withProjectRoot(cwd, result), raw);
613
+ }
659
614
  function cmdInitResume(cwd, raw) {
660
615
  const config = loadConfig(cwd);
661
616
  let interruptedAgentId = null;
@@ -2099,6 +2054,7 @@ module.exports = {
2099
2054
  cmdInitNewMilestone,
2100
2055
  cmdInitQuick,
2101
2056
  cmdInitIngestDocs,
2057
+ cmdInitOnboard,
2102
2058
  cmdInitResume,
2103
2059
  cmdInitVerifyWork,
2104
2060
  cmdInitPhaseOp,
@@ -222,7 +222,7 @@ function migrateLegacyDevPreferencesToSkill(targetDir, saved, runtime, scope = '
222
222
  * - agents: write as-is (files already carry their own `gsd-` prefix).
223
223
  * For kimi-agents kind: recursively copy generated YAML/prompt files.
224
224
  */
225
- function _copyStaged(stagedDir, destDir, kind, configDir) {
225
+ function _copyStaged(stagedDir, destDir, kind, configDir, runtime) {
226
226
  // Defense-in-depth: verify destDir is within the install root even if the
227
227
  // upstream assertDestWithinConfigHome check was somehow bypassed. This guards
228
228
  // the actual write site against any future call-site drift.
@@ -275,8 +275,11 @@ function _copyStaged(stagedDir, destDir, kind, configDir) {
275
275
  const stem = entry.name.slice(0, -3); // strip .md
276
276
  let destName;
277
277
  if (kind.kind === 'agents') {
278
- // Agent files already carry the gsd- prefix in the source dir
279
- destName = entry.name;
278
+ // Agent files already carry the gsd- prefix in the source dir.
279
+ // #1575: copilot agents get .agent.md suffix (mirrors inline loop line ~9118).
280
+ destName = runtime === 'copilot'
281
+ ? entry.name.replace(/\.md$/, '.agent.md')
282
+ : entry.name;
280
283
  }
281
284
  else if (namespacedByDir) {
282
285
  // Directory is the namespace; don't double-prefix the filename
@@ -571,7 +574,7 @@ function installRuntimeArtifacts(runtime, configDir, scope, resolvedProfile, res
571
574
  }
572
575
  }
573
576
  _removeGsdEntries(dest, kind);
574
- _copyStaged(item.sourceDir, dest, kind, configDir);
577
+ _copyStaged(item.sourceDir, dest, kind, configDir, runtime);
575
578
  // Restore user-owned dirs after the prune+copy
576
579
  for (const [dirName, snap] of toPreserve) {
577
580
  _restoreDir(node_path_1.default.join(dest, dirName), snap);
@@ -581,7 +584,7 @@ function installRuntimeArtifacts(runtime, configDir, scope, resolvedProfile, res
581
584
  // For non-skills kinds (commands, agents): no user content to preserve;
582
585
  // just prune stale gsd-* entries and copy new ones.
583
586
  _removeGsdEntries(dest, kind);
584
- _copyStaged(item.sourceDir, dest, kind, configDir);
587
+ _copyStaged(item.sourceDir, dest, kind, configDir, runtime);
585
588
  }
586
589
  }
587
590
  }
@@ -42,6 +42,7 @@ const PROFILES = Object.freeze({
42
42
  standard: Object.freeze([
43
43
  // Core loop
44
44
  'new-project',
45
+ 'onboard',
45
46
  'discuss-phase',
46
47
  'plan-phase',
47
48
  'execute-phase',
@@ -819,6 +820,7 @@ module.exports = {
819
820
  writeActiveProfile,
820
821
  // Shared internals
821
822
  parseRequires,
823
+ parseCallsAgents,
822
824
  cleanupStagedSkills,
823
825
  // Back-compat / deprecated
824
826
  MINIMAL_SKILL_ALLOWLIST,
@@ -415,6 +415,12 @@ function cmdLoopRenderHooks(cwd, point, raw, options = {}) {
415
415
  const runtimeConfigDir = typeof options['configDir'] === 'string'
416
416
  ? options['configDir']
417
417
  : undefined;
418
+ // #2003: thread an explicit --runtime override into the capability-state
419
+ // resolver so the config-dir resolution bypasses the persisted-runtime
420
+ // fallback (GSD_RUNTIME → config.runtime). Without this, a repo with persisted
421
+ // runtime:"codex" resolves the config dir to ~/.codex and execute:post /
422
+ // verify:post hooks silently no-op when the operator drives from Claude Code.
423
+ const runtimeOverride = typeof options['runtime'] === 'string' ? options['runtime'] : undefined;
418
424
  // Load the config snapshot ONCE and share it with both the capability-state
419
425
  // resolver (via configOverride) and loop-hook resolution, so federated keys
420
426
  // present in loadConfig resolve identically for `active` and for hook when/
@@ -429,7 +435,7 @@ function cmdLoopRenderHooks(cwd, point, raw, options = {}) {
429
435
  catch {
430
436
  config = {};
431
437
  }
432
- const state = resolveCapabilityRuntimeState(cwd, runtimeConfigDir, config);
438
+ const state = resolveCapabilityRuntimeState(cwd, runtimeConfigDir, config, runtimeOverride);
433
439
  // Load overlay-aware registry (ADR-1244 D2 wiring) so installed third-party
434
440
  // capabilities are visible to loop rendering exactly like first-party ones.
435
441
  // eslint-disable-next-line @typescript-eslint/no-require-imports