devflow-kit 3.1.0 → 3.2.0

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 (86) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +1 -1
  3. package/dist/cli/agents-view/render.js +69 -15
  4. package/dist/cli/agents-view/state.js +40 -14
  5. package/dist/cli/commands/agents.js +135 -45
  6. package/dist/cli/commands/init.js +128 -53
  7. package/dist/cli/commands/learning.js +36 -8
  8. package/dist/cli/commands/memory.js +35 -14
  9. package/dist/cli/commands/uninstall.js +163 -39
  10. package/dist/commands/code-review.md +0 -2
  11. package/dist/commands/debug.md +14 -11
  12. package/dist/commands/dynamic-build.md +33 -43
  13. package/dist/commands/dynamic-plan.md +8 -2
  14. package/dist/commands/explore.md +9 -3
  15. package/dist/commands/implement.md +20 -16
  16. package/dist/commands/plan.md +13 -9
  17. package/dist/commands/release.md +8 -2
  18. package/dist/commands/research.md +8 -2
  19. package/dist/commands/resolve.md +1 -3
  20. package/dist/commands/self-review.md +0 -2
  21. package/dist/core/agent-frontmatter.js +25 -0
  22. package/dist/core/agent-models.js +198 -36
  23. package/dist/core/agent-state.js +27 -5
  24. package/dist/core/assets.js +1 -1
  25. package/dist/core/feature-config.js +68 -10
  26. package/dist/core/flags.js +24 -0
  27. package/dist/core/learning-queue-cleanup.js +10 -11
  28. package/dist/core/linked-path.js +46 -0
  29. package/dist/core/plugins.js +9 -3
  30. package/dist/core/queue-drain.js +31 -0
  31. package/dist/hud/components/learning-counts.js +54 -8
  32. package/dist/skills/git/references/tracker/github/create-release.md +2 -2
  33. package/dist/skills/git/references/tracker/jira/create-release.md +2 -2
  34. package/dist/skills/git/references/tracker/linear/create-release.md +2 -2
  35. package/dist/targets/claude-code/installer.js +36 -9
  36. package/dist/targets/claude-code/post-install.js +128 -38
  37. package/package.json +1 -1
  38. package/src/assets/agents/code.md +14 -17
  39. package/src/assets/agents/design.md +2 -0
  40. package/src/assets/agents/diagnose.md +2 -0
  41. package/src/assets/agents/evaluate.md +4 -0
  42. package/src/assets/agents/knowledge.md +2 -0
  43. package/src/assets/agents/research.md +2 -0
  44. package/src/assets/agents/review.md +2 -0
  45. package/src/assets/agents/scrutinize.md +4 -0
  46. package/src/assets/agents/simplify.md +4 -0
  47. package/src/assets/agents/skim.md +3 -1
  48. package/src/assets/agents/synthesize.md +6 -0
  49. package/src/assets/agents/test.md +18 -10
  50. package/src/assets/agents/triage.md +2 -0
  51. package/src/assets/agents/validate.md +14 -10
  52. package/src/assets/commands/_partials/_engine.mds +15 -31
  53. package/src/assets/commands/_partials/_knowledge.mds +0 -2
  54. package/src/assets/commands/_partials/_tracker.mds +1 -1
  55. package/src/assets/commands/code-review.mds +0 -2
  56. package/src/assets/commands/debug.mds +13 -8
  57. package/src/assets/commands/dynamic-build.mds +17 -11
  58. package/src/assets/commands/dynamic-plan.mds +7 -1
  59. package/src/assets/commands/explore.mds +9 -1
  60. package/src/assets/commands/implement.mds +19 -13
  61. package/src/assets/commands/plan.mds +12 -8
  62. package/src/assets/commands/release.md +8 -2
  63. package/src/assets/commands/research.mds +8 -2
  64. package/src/assets/commands/resolve.mds +1 -1
  65. package/src/assets/mds/tracker/_github.mds +2 -2
  66. package/src/assets/mds/tracker/_jira.mds +2 -2
  67. package/src/assets/mds/tracker/_linear.mds +2 -2
  68. package/src/assets/scripts/hooks/assets/orchestrator-charter.md +3 -2
  69. package/src/assets/scripts/hooks/background-memory-update +69 -11
  70. package/src/assets/scripts/hooks/capture-prompt +4 -3
  71. package/src/assets/scripts/hooks/capture-question +4 -3
  72. package/src/assets/scripts/hooks/capture-turn +4 -3
  73. package/src/assets/scripts/hooks/ensure-devflow-init +13 -1
  74. package/src/assets/scripts/hooks/ensure-root-gitignore +122 -10
  75. package/src/assets/scripts/hooks/git-marker +71 -0
  76. package/src/assets/scripts/hooks/json-helper.cjs +12 -145
  77. package/src/assets/scripts/hooks/json-parse +24 -129
  78. package/src/assets/scripts/hooks/lib/learning-store.cjs +169 -64
  79. package/src/assets/scripts/hooks/lib/render-decisions.cjs +1 -1
  80. package/src/assets/scripts/hooks/memory-worker +10 -0
  81. package/src/assets/scripts/hooks/pre-compact-memory +66 -14
  82. package/src/assets/scripts/hooks/preamble +9 -1
  83. package/src/assets/scripts/hooks/queue-append +53 -21
  84. package/src/assets/scripts/hooks/session-start-context +108 -29
  85. package/src/assets/scripts/hooks/session-start-memory +33 -11
  86. package/src/assets/skills/test-driven-development/SKILL.md +6 -4
@@ -96,6 +96,31 @@ export function readFrontmatterModel(content) {
96
96
  const m = MODEL_RE.exec(parts.value.fmBody);
97
97
  return Ok(m ? m[1] : '');
98
98
  }
99
+ // ---------------------------------------------------------------------------
100
+ // readFrontmatterEffort
101
+ // ---------------------------------------------------------------------------
102
+ /**
103
+ * Read the `effort:` value from the first frontmatter block.
104
+ *
105
+ * D-SHIPPED-EFFORT: an agent's shipped effort is part of its shipped default,
106
+ * the same as its model, so the reader that answers "what did devflow ship?"
107
+ * must see both. This is the effort twin of readFrontmatterModel and has the
108
+ * same contract: it reads only the leading frontmatter block (an `effort:`
109
+ * line in the body is ignored), returns Ok('') when no `effort:` line exists,
110
+ * and returns an error for missing or unterminated frontmatter.
111
+ *
112
+ * The value is returned as written. Whether it is a valid effort level is the
113
+ * caller's decision (loadShippedAgentDefaults owns that check against
114
+ * EFFORT_LEVELS), so a typo in a shipped file is reported rather than hidden here.
115
+ */
116
+ export function readFrontmatterEffort(content) {
117
+ const parts = parseFrontmatter(content);
118
+ if (!parts.ok)
119
+ return Err(parts.error);
120
+ const EFFORT_RE = /^effort:[ \t]*(.*?)[ \t]*$/m;
121
+ const m = EFFORT_RE.exec(parts.value.fmBody);
122
+ return Ok(m ? m[1] : '');
123
+ }
99
124
  /**
100
125
  * Rewrite the `model:` and optionally `effort:` lines in the first
101
126
  * frontmatter block of `content`.
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Mapping file: ~/.devflow/agent-models.json
9
9
  * { version: 1, agents: { [name]: { model?, effort? } } }
10
- * Deviations-only: omit an agent to inherit its shipped default.
10
+ * Deviations-only: omit an agent to inherit its shipped default (model AND effort).
11
11
  * Unknown agent names are tolerated and preserved on save (plugin may not be installed).
12
12
  * Invalid effort values are dropped with a warning.
13
13
  *
@@ -25,8 +25,8 @@
25
25
  import { promises as fs } from 'fs';
26
26
  import * as path from 'path';
27
27
  import { writeFileAtomicExclusive } from './fs-atomic.js';
28
- import { isDormantExternalModel } from './external-models.js';
29
- import { rewriteAgentFrontmatter, readFrontmatterModel, isValidModelName } from './agent-frontmatter.js';
28
+ import { isDormantExternalModel, CLAUDE_MODEL_ALIASES } from './external-models.js';
29
+ import { rewriteAgentFrontmatter, readFrontmatterModel, readFrontmatterEffort, isValidModelName, } from './agent-frontmatter.js';
30
30
  import { agentSourceDirs } from './assets.js';
31
31
  import { getAllAgentNames } from './plugins.js';
32
32
  import { mdEntryName, mdFileName } from './orphan-sweep.js';
@@ -51,6 +51,90 @@ export const EFFORT_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max'];
51
51
  * EFFORT_LEVELS[number] is a literal union, not string.
52
52
  */
53
53
  const EFFORT_LEVELS_SET = new Set(EFFORT_LEVELS);
54
+ /** True when `value` is one of EFFORT_LEVELS (narrows string to EffortLevel). */
55
+ export function isEffortLevel(value) {
56
+ return EFFORT_LEVELS_SET.has(value);
57
+ }
58
+ /**
59
+ * D-SHIPPED-EFFORT: the stored effort value that drops an agent's effort line
60
+ * altogether. A mapping `inherit` yields no `effort:` line and does NOT fall
61
+ * back to the shipped effort, so the agent follows the session's effort. It is
62
+ * a stored value, unlike `default` (which deletes the key so the shipped
63
+ * effort applies again), and it is effort-only: model-side inherit semantics
64
+ * are a separate decision.
65
+ */
66
+ export const EFFORT_INHERIT = 'inherit';
67
+ // ---------------------------------------------------------------------------
68
+ // Workers
69
+ // ---------------------------------------------------------------------------
70
+ /**
71
+ * D-WORKER-AGENTS: background workers whose model and effort are settable in
72
+ * `devflow agents` although they are not agents. A worker runs as its own
73
+ * `claude -p` process outside any session and has no installed agent file, so
74
+ * there is nothing for a reapply to rewrite.
75
+ *
76
+ * Worker entries are stored under `agents.<name>` in agent-models.json, in the
77
+ * same map as agent entries; an absent entry means the default declared here.
78
+ * Because the map is shared, every agent-only path (the reapply walk, the init
79
+ * reapply gate, countExternalMappedAgents, the list and TUI agent sets) goes
80
+ * through agentOnlyMapping, the one definition of the agent-only subset.
81
+ *
82
+ * A worker is not a DEVFLOW_PLUGINS agent: getAllAgentNames() and the roster
83
+ * count are unaffected.
84
+ *
85
+ * Shipped value of `memory`: `claude-sonnet-5-5` at `high` effort. User decision
86
+ * 2026-10-08: memory quality is worth more than the cost saving of Haiku, which
87
+ * replaces the plan's Haiku default. The worker does not read `agents.memory`
88
+ * yet. Until it does, background-memory-update names this model as a literal in
89
+ * its `claude -p --model` argument, and tests/agent-models-worker.test.ts holds
90
+ * that literal equal to this row so the two cannot drift apart. Wiring the
91
+ * worker to this map, and `--effort` behind a CLI version probe, is a separate
92
+ * change.
93
+ */
94
+ export const WORKER_AGENTS = {
95
+ memory: { model: 'claude-sonnet-5-5', effort: 'high' },
96
+ };
97
+ /**
98
+ * True when `name` is a worker key. Own-property check, so a hostile key such as
99
+ * `constructor` or `__proto__` is never answered from the prototype chain.
100
+ */
101
+ export function isWorkerAgent(name) {
102
+ return Object.hasOwn(WORKER_AGENTS, name);
103
+ }
104
+ /** A full Claude model identifier: the `claude-` prefix and at least one more character. */
105
+ const CLAUDE_FULL_ID_RE = /^claude-.+$/;
106
+ /**
107
+ * D-WORKER-AGENTS: the worker value domain, owned here once and shared by
108
+ * `validateSetArgs` (the write boundary) and `readAgentMapping` (the read
109
+ * boundary), so a hand-edited file and a CLI argument are held to one rule.
110
+ *
111
+ * - model: `default`, a CLAUDE_MODEL_ALIASES alias, or a full identifier
112
+ * starting `claude-`. Anything else is rejected, `inherit` included
113
+ * (a worker has no session model to inherit). External models are
114
+ * rejected too: the worker runs `claude -p` outside a session and
115
+ * nothing here verifies it routes through the proxy, so allowing
116
+ * them later is a deliberate change to this function.
117
+ * - effort: `default` or an EFFORT_LEVELS level. `inherit` is rejected because
118
+ * a worker has no session effort to inherit.
119
+ *
120
+ * Pure function — no catalog lookup, no I/O.
121
+ */
122
+ export function validateWorkerValue(field, value) {
123
+ if (field === 'effort') {
124
+ if (value === 'default' || isEffortLevel(value))
125
+ return Ok(undefined);
126
+ return Err(`Invalid effort "${value}" for a worker. Valid: default, ${EFFORT_LEVELS.join(', ')} ` +
127
+ `(a worker has no session effort to inherit)`);
128
+ }
129
+ const inDomain = isValidModelName(value) &&
130
+ (value === 'default' ||
131
+ CLAUDE_MODEL_ALIASES.includes(value) ||
132
+ CLAUDE_FULL_ID_RE.test(value));
133
+ if (inDomain)
134
+ return Ok(undefined);
135
+ return Err(`Invalid model "${value}" for a worker. Valid: default, ${CLAUDE_MODEL_ALIASES.join(', ')}, ` +
136
+ `or a full claude- identifier (external models are not supported for workers)`);
137
+ }
54
138
  // ---------------------------------------------------------------------------
55
139
  // Key migration
56
140
  // ---------------------------------------------------------------------------
@@ -216,6 +300,34 @@ export async function parseAgentMappingEnvelope(filePath) {
216
300
  }
217
301
  return { kind: 'ok', envelope, rawAgents: rawAgents };
218
302
  }
303
+ /**
304
+ * D-WORKER-AGENTS: the agent-only subset of the mapping — every entry whose key
305
+ * is not a worker. Unknown names stay: the file preserves entries for agents
306
+ * whose plugin is not installed.
307
+ *
308
+ * This is the one definition of "the agents in the mapping". The reapply walk,
309
+ * the init reapply gate, countExternalMappedAgents and the TUI's orphan rows all
310
+ * call it, so a worker entry can never be mistaken for an agent with no
311
+ * installed file.
312
+ *
313
+ * Pure function — returns a new record, never mutates the mapping.
314
+ */
315
+ export function agentOnlyMapping(mapping) {
316
+ const agents = {};
317
+ for (const [name, entry] of Object.entries(mapping.agents)) {
318
+ if (!isWorkerAgent(name))
319
+ agents[name] = entry;
320
+ }
321
+ return agents;
322
+ }
323
+ /**
324
+ * True when the mapping holds at least one agent entry. The `devflow init`
325
+ * reapply gate: an agents.memory-only mapping keeps it closed, because there is
326
+ * no agent file for a reapply to converge.
327
+ */
328
+ export function hasAgentMappingEntries(mapping) {
329
+ return Object.keys(agentOnlyMapping(mapping)).length > 0;
330
+ }
219
331
  /**
220
332
  * Read and tolerantly parse ~/.devflow/agent-models.json.
221
333
  * Returns an empty mapping when the file is missing.
@@ -245,24 +357,39 @@ export async function readAgentMapping(devflowDir, opts) {
245
357
  continue;
246
358
  const raw = entry;
247
359
  const mapping = {};
360
+ // D-WORKER-AGENTS: a worker key is held to the worker value domain on read,
361
+ // by the same function the CLI write boundary uses.
362
+ const worker = isWorkerAgent(name);
248
363
  if (typeof raw.model === 'string') {
249
364
  // Tighten to the same charset used by rewriteAgentFrontmatter.
250
365
  // The effort field is enum-validated below; model must be equally strict.
251
366
  // An invalid entry is dropped with a warning rather than silently
252
367
  // persisting and permanently poisoning that agent on every reapply.
253
- if (isValidModelName(raw.model)) {
254
- mapping.model = raw.model;
368
+ if (!isValidModelName(raw.model)) {
369
+ warn(`agent-models: invalid-model name for agent "${name}" — dropping entry`);
255
370
  }
256
371
  else {
257
- warn(`agent-models: invalid-model name for agent "${name}" — dropping entry`);
372
+ const workerCheck = worker ? validateWorkerValue('model', raw.model) : undefined;
373
+ if (workerCheck !== undefined && !workerCheck.ok) {
374
+ warn(`agent-models: dropping out-of-domain model "${raw.model}" for worker "${name}" — ${workerCheck.error}`);
375
+ }
376
+ else {
377
+ mapping.model = raw.model;
378
+ }
258
379
  }
259
380
  }
260
381
  if (typeof raw.effort === 'string') {
261
- if (EFFORT_LEVELS_SET.has(raw.effort)) {
262
- // Sound narrowing: has() proved membership; EffortLevel is a literal
263
- // subtype of string so the assertion is not a compensating cast.
382
+ // `inherit` is a stored agent value; a worker has no session effort to
383
+ // inherit, so for a worker it is out of domain like any other non-level.
384
+ if (isEffortLevel(raw.effort)) {
264
385
  mapping.effort = raw.effort;
265
386
  }
387
+ else if (raw.effort === EFFORT_INHERIT && !worker) {
388
+ mapping.effort = raw.effort;
389
+ }
390
+ else if (worker) {
391
+ warn(`agent-models: dropping out-of-domain effort "${raw.effort}" for worker "${name}"`);
392
+ }
266
393
  else {
267
394
  warn(`agent-models: dropping invalid effort "${raw.effort}" for agent "${name}"`);
268
395
  }
@@ -330,41 +457,49 @@ export async function saveAgentMapping(devflowDir, mapping) {
330
457
  * isDormantExternalModel) AND proxyEnabled is false → the entry is DORMANT.
331
458
  * The shipped default model is used instead. The entry remains saved.
332
459
  *
333
- * Effort is ALWAYS applied regardless of proxy state.
460
+ * D-SHIPPED-EFFORT — effort rule, in order:
461
+ * 1. a mapping effort level wins;
462
+ * 2. a mapping `inherit` yields no effort line and does NOT fall back to the
463
+ * shipped effort;
464
+ * 3. an absent mapping effort falls back to the shipped effort, which is
465
+ * undefined when the agent ships none.
466
+ * Effort is ALWAYS applied regardless of proxy state, a dormant external
467
+ * model included.
334
468
  *
335
469
  * Pure function — no I/O.
336
470
  *
337
471
  * @param agentName - The agent's short name (e.g., 'code').
338
472
  * @param mapping - The full mapping file.
339
- * @param shippedDefaults - Map of agent name → shipped default model.
473
+ * @param shippedDefaults - Map of agent name → shipped model and effort.
340
474
  * @param proxyEnabled - Whether the Devflow proxy is currently active.
341
475
  */
342
476
  export function resolveEffective(agentName, mapping, shippedDefaults, proxyEnabled) {
343
477
  const entry = mapping.agents[agentName];
478
+ const shipped = shippedDefaults[agentName];
344
479
  let model;
345
480
  if (entry?.model !== undefined) {
346
481
  // Dormant: external model configured but proxy is off → fall back to shipped default.
347
482
  model = isDormantExternalModel(entry.model, proxyEnabled)
348
- ? shippedDefaults[agentName]
483
+ ? shipped?.model
349
484
  : entry.model;
350
485
  }
351
486
  else {
352
487
  // No mapping entry → use shipped default.
353
- model = shippedDefaults[agentName];
488
+ model = shipped?.model;
354
489
  }
355
- const effort = entry?.effort;
490
+ const mapped = entry?.effort;
491
+ const effort = mapped === EFFORT_INHERIT ? undefined : (mapped ?? shipped?.effort);
356
492
  return { model, effort };
357
493
  }
358
- // ---------------------------------------------------------------------------
359
- // loadShippedDefaults
360
- // ---------------------------------------------------------------------------
361
494
  /**
362
- * Parse the shipped model default out of every {name}.md in one directory.
495
+ * Parse the shipped model and effort out of every {name}.md in one directory.
363
496
  *
364
497
  * A missing or unreadable directory yields an empty map — dist/agents/ does not
365
498
  * exist until a generator host does, and a source tree that produced no agents
366
499
  * is caught by the registry-completeness guard rather than by a throw here.
367
- * Unknown or malformed files are skipped individually.
500
+ * Unknown or malformed files are skipped individually. The effort is returned as
501
+ * written: only the directory that wins the merge has its effort validated, so a
502
+ * typo in a losing file is never reported.
368
503
  */
369
504
  async function readDirDefaults(dir) {
370
505
  let entries;
@@ -380,9 +515,10 @@ async function readDirDefaults(dir) {
380
515
  return null;
381
516
  try {
382
517
  const content = await fs.readFile(path.join(dir, file), 'utf-8');
383
- const result = readFrontmatterModel(content);
384
- if (result.ok && result.value) {
385
- return [agentName, result.value];
518
+ const model = readFrontmatterModel(content);
519
+ const effort = readFrontmatterEffort(content);
520
+ if (model.ok && model.value && effort.ok) {
521
+ return [agentName, { model: model.value, effort: effort.value }];
386
522
  }
387
523
  }
388
524
  catch {
@@ -399,11 +535,22 @@ async function readDirDefaults(dir) {
399
535
  return defaults;
400
536
  }
401
537
  /**
402
- * Load shipped default models from the agent files.
538
+ * Load the shipped default model and effort of every agent from the agent files.
539
+ *
540
+ * D-SHIPPED-EFFORT: this is the only production reader of shipped model and
541
+ * effort values. An agent's effort is part of its shipped default, so a reapply
542
+ * that did not see it would strip it (the mapping has no entry to say
543
+ * otherwise).
403
544
  *
404
545
  * Directories are MOST-PREFERRED FIRST — the convention owned by
405
546
  * agentSourceDirs() — and the first directory to supply a name wins, so once an
406
547
  * agent is generated into dist/agents/ its frontmatter is the shipped default.
548
+ * First-hit-wins applies to the whole record: an agent's effort is never read
549
+ * from a different file than its model.
550
+ *
551
+ * A shipped `effort:` outside EFFORT_LEVELS (`inherit` included — it is a
552
+ * mapping value, not a shipped one) is dropped with a warning naming the agent;
553
+ * its model survives.
407
554
  *
408
555
  * A registry agent that no directory supplies is reported through `onWarning`
409
556
  * as ONE aggregate message naming every missing agent and the build step. The
@@ -417,17 +564,31 @@ async function readDirDefaults(dir) {
417
564
  * prove the precedence against a temp tree; all real callers use the default.
418
565
  * @param opts - Optional warning channel; the gap is silent without one.
419
566
  */
420
- export async function loadShippedDefaults(dirs = agentSourceDirs(), opts) {
567
+ export async function loadShippedAgentDefaults(dirs = agentSourceDirs(), opts) {
421
568
  const perDir = await Promise.all(dirs.map(readDirDefaults));
422
- const defaults = {};
569
+ const winners = {};
423
570
  for (const dirDefaults of perDir) {
424
- for (const [agentName, model] of Object.entries(dirDefaults)) {
425
- if (!(agentName in defaults)) {
426
- defaults[agentName] = model;
571
+ for (const [agentName, raw] of Object.entries(dirDefaults)) {
572
+ if (!Object.hasOwn(winners, agentName)) {
573
+ winners[agentName] = raw;
427
574
  }
428
575
  }
429
576
  }
430
- const missing = getAllAgentNames().filter(name => !(name in defaults));
577
+ const defaults = {};
578
+ for (const [agentName, raw] of Object.entries(winners)) {
579
+ if (raw.effort === '') {
580
+ defaults[agentName] = { model: raw.model };
581
+ }
582
+ else if (isEffortLevel(raw.effort)) {
583
+ defaults[agentName] = { model: raw.model, effort: raw.effort };
584
+ }
585
+ else {
586
+ defaults[agentName] = { model: raw.model };
587
+ opts?.onWarning?.(`Shipped agent "${agentName}" declares effort "${raw.effort}", which is not one of ` +
588
+ `${EFFORT_LEVELS.join(', ')} — ignoring it.`);
589
+ }
590
+ }
591
+ const missing = getAllAgentNames().filter(name => !Object.hasOwn(defaults, name));
431
592
  if (missing.length > 0) {
432
593
  opts?.onWarning?.(`No shipped default found for declared agent(s): ${missing.join(', ')}. ` +
433
594
  `Run \`npm run build:mds\` if they are compiled from .mds generator hosts, otherwise ` +
@@ -439,10 +600,11 @@ export async function loadShippedDefaults(dirs = agentSourceDirs(), opts) {
439
600
  * Idempotent convergence function: walk every installed agent file and
440
601
  * rewrite frontmatter model/effort to match the effective mapping.
441
602
  *
442
- * - Reads shipped defaults LIVE from the agent sources — agentSourceDirs(),
443
- * dist/agents/ preferred over src/assets/agents/. An agent no source supplies
444
- * is reported through the warning channel rather than passing as 'unchanged'
445
- * with no explanation.
603
+ * - Reads shipped defaults (model AND effort) LIVE from the agent sources —
604
+ * agentSourceDirs(), dist/agents/ preferred over src/assets/agents/. An agent
605
+ * no source supplies is reported through the warning channel rather than
606
+ * passing as 'unchanged' with no explanation. D-SHIPPED-EFFORT: an agent that
607
+ * ships an effort keeps it across a reapply unless its mapping says otherwise.
446
608
  * - Gets the agent name list from the registry (getAllAgentNames()) plus
447
609
  * any mapping entries for agents not in the registry.
448
610
  * - Missing installed files → skip silently (recorded in skippedMissing).
@@ -461,11 +623,11 @@ export async function reapplyAgentMapping(opts) {
461
623
  return { updated: [], unchanged: [], skippedMissing: [], invalidMapping: [], warnings };
462
624
  }
463
625
  const mapping = mappingResult.value;
464
- const shippedDefaults = await loadShippedDefaults(opts.agentSourceDirs, { onWarning: warn });
626
+ const shippedDefaults = await loadShippedAgentDefaults(opts.agentSourceDirs, { onWarning: warn });
465
627
  // Build the union of: all registered agent names + all names in the mapping
466
628
  // (so agents not yet in the registry but configured are also processed).
467
629
  const registryNames = new Set(getAllAgentNames());
468
- const mappingNames = new Set(Object.keys(mapping.agents));
630
+ const mappingNames = new Set(Object.keys(agentOnlyMapping(mapping)));
469
631
  const allNames = new Set([...registryNames, ...mappingNames]);
470
632
  // Stable iteration order — Set preserves insertion order, array fixes it for the map.
471
633
  const allNamesList = [...allNames];
@@ -589,7 +751,7 @@ export async function revertExternalAgents(opts) {
589
751
  */
590
752
  export function countExternalMappedAgents(mapping) {
591
753
  let count = 0;
592
- for (const entry of Object.values(mapping.agents)) {
754
+ for (const entry of Object.values(agentOnlyMapping(mapping))) {
593
755
  if (isDormantExternalModel(entry.model, false)) {
594
756
  count++;
595
757
  }
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Agent installation-state classification.
2
+ * Agent row vocabulary shared by `devflow agents --list` and the TUI.
3
3
  *
4
- * Single source of truth for the STATE column shared by `--list` and the TUI.
5
- * Centralised here (core layer) so neither cli/commands nor
6
- * cli/agents-view owns the vocabulary.
4
+ * Single source of truth for the STATE column and the EFFORT cell, so neither
5
+ * surface can drift from the other. Centralised here (core layer) so neither
6
+ * cli/commands nor cli/agents-view owns the vocabulary.
7
7
  *
8
8
  * Pure core-layer module, no CLI-adapter concerns.
9
9
  */
@@ -22,13 +22,35 @@ export const AGENT_STATE_LABELS = {
22
22
  'saved-inactive': 'saved-inactive',
23
23
  'not-installed': 'not installed',
24
24
  'unknown': 'unknown',
25
+ 'worker': 'worker',
25
26
  };
27
+ // ---------------------------------------------------------------------------
28
+ // formatEffortDisplay
29
+ // ---------------------------------------------------------------------------
30
+ /**
31
+ * The text of an EFFORT cell, shared by `--list` and the TUI.
32
+ *
33
+ * D-SHIPPED-EFFORT: a configured level or `inherit` is shown as is. An
34
+ * unconfigured row shows `default (<shipped effort>)` when the shipped source
35
+ * carries an effort — the same `default (shippedDefault)` convention the MODEL
36
+ * cell uses — and plain `default` when it carries none.
37
+ *
38
+ * Pure function, no I/O.
39
+ *
40
+ * @param configured - The row's effort: a level, `inherit`, or `default` when unset.
41
+ * @param shippedEffort - The effort the shipped source carries, if any.
42
+ */
43
+ export function formatEffortDisplay(configured, shippedEffort) {
44
+ if (configured !== 'default')
45
+ return configured;
46
+ return shippedEffort === undefined ? 'default' : `default (${shippedEffort})`;
47
+ }
26
48
  /**
27
49
  * Classify an agent row's install state.
28
50
  *
29
51
  * Single source of truth shared by `--list` and the TUI so the two surfaces
30
52
  * cannot drift. The four-way result drives the STATE column in render.ts and
31
- * the STATE column in --list output.
53
+ * the STATE column in --list output. Worker rows never come through here.
32
54
  *
33
55
  * Pure function, no I/O.
34
56
  */
@@ -75,7 +75,7 @@ export function compiledSkillRefsDir(root = getPackageRoot()) {
75
75
  * The single owner of the dist-first agent-resolution policy: a generator
76
76
  * host's compiled artifact in dist/agents/ supersedes a hand-authored file of
77
77
  * the same name in src/assets/agents/. Every consumer reads the order from
78
- * here — the installer's first-hit-wins resolve, loadShippedDefaults's
78
+ * here — the installer's first-hit-wins resolve, loadShippedAgentDefaults's
79
79
  * first-wins merge, and the test harness's resolveAgentSource — so the
80
80
  * convention is stated once and cannot drift apart between call sites.
81
81
  *
@@ -1,5 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import { promises as fs } from 'fs';
3
+ import { firstSymbolicLink } from './linked-path.js';
3
4
  import { getFeatureConfigPath } from './project-paths.js';
4
5
  import { parseTrackerId } from './tracker.js';
5
6
  import { loadProjectConfigLib } from './evidence-policy.js';
@@ -169,17 +170,64 @@ async function readConfigBody(projectRoot, lib = loadProjectConfigLib()) {
169
170
  }
170
171
  return classifyConfigBytes(read.bytes, lib.value);
171
172
  }
173
+ /** A thrown value's message, or the value itself when it is not an Error. */
174
+ function messageOf(err) {
175
+ return err instanceof Error ? err.message : String(err);
176
+ }
172
177
  /**
173
- * Serialise a config body to a project's config file.
178
+ * Serialise a config body to a project's config file. Never throws.
174
179
  * Creates the .devflow/ directory if missing.
175
180
  * Uses an atomic temp+rename pattern to prevent partial reads under concurrent writes.
181
+ * The copy is created only where nothing stands ('wx'), so an entry a repository
182
+ * planted at its name — a symbolic link among them — is never written through
183
+ * (D-CLI-NO-SYMLINK) and, not being this run's, is left where it is; the write then
184
+ * fails and the Result says so. Once this run has created the copy, a write, close or
185
+ * rename that fails removes it again, so a failed write leaves nothing beside the
186
+ * config; the Result names the failure, and the copy too when it could not be removed.
176
187
  */
177
188
  async function writeConfigBody(projectRoot, body) {
178
189
  const configPath = getFeatureConfigPath(projectRoot);
179
- await fs.mkdir(path.join(projectRoot, '.devflow'), { recursive: true });
180
190
  const tmpPath = configPath + '.tmp.' + process.pid;
181
- await fs.writeFile(tmpPath, JSON.stringify(body, null, 2) + '\n', { encoding: 'utf-8', mode: 0o600 });
182
- await fs.rename(tmpPath, configPath);
191
+ let text;
192
+ let copy;
193
+ try {
194
+ text = JSON.stringify(body, null, 2) + '\n';
195
+ await fs.mkdir(path.join(projectRoot, '.devflow'), { recursive: true });
196
+ copy = await fs.open(tmpPath, 'wx', 0o600);
197
+ }
198
+ catch (err) {
199
+ return { ok: false, detail: messageOf(err) };
200
+ }
201
+ try {
202
+ try {
203
+ // The open handle is fs.writeFile's destination and the text its data: the same
204
+ // write as copy.writeFile(text), in the form a path-traversal scan reads right,
205
+ // since it takes a writeFile's first argument for a path.
206
+ await fs.writeFile(copy, text, 'utf-8');
207
+ }
208
+ finally {
209
+ await copy.close();
210
+ }
211
+ await fs.rename(tmpPath, configPath);
212
+ return { ok: true };
213
+ }
214
+ catch (err) {
215
+ return { ok: false, detail: await removeCopy(tmpPath, messageOf(err)) };
216
+ }
217
+ }
218
+ /**
219
+ * Remove the copy a failed config write created, and say why the write failed:
220
+ * `detail`, followed by the removal's own failure when the copy stays. A copy that
221
+ * is already gone counts as removed (`force`).
222
+ */
223
+ async function removeCopy(tmpPath, detail) {
224
+ try {
225
+ await fs.rm(tmpPath, { force: true });
226
+ return detail;
227
+ }
228
+ catch (err) {
229
+ return `${detail}; its copy ${tmpPath} could not be removed: ${messageOf(err)}`;
230
+ }
183
231
  }
184
232
  /**
185
233
  * Merge devflow's managed keys over the config body the file already holds.
@@ -227,21 +275,31 @@ export function mergeManagedConfig(existing, managed) {
227
275
  * change. Acceptable because init is a single-threaded, user-initiated command
228
276
  * and the window is milliseconds on a local filesystem; the file swap itself is
229
277
  * atomic (temp + rename), so a reader never sees a partial file.
278
+ *
279
+ * D-CLI-NO-SYMLINK (firstSymbolicLink): a `.devflow` that is a symbolic link is
280
+ * left alone, and the Result says so; the file is neither read nor written there.
230
281
  */
231
282
  export async function writeManagedConfig(projectRoot, managed, lib = loadProjectConfigLib()) {
232
283
  const configPath = getFeatureConfigPath(projectRoot);
284
+ let linked;
285
+ try {
286
+ linked = await firstSymbolicLink([path.dirname(configPath)]);
287
+ }
288
+ catch (err) {
289
+ return { ok: false, error: { kind: 'unreadable', path: configPath, detail: messageOf(err) } };
290
+ }
291
+ if (linked !== null) {
292
+ return { ok: false, error: { kind: 'unreadable', path: configPath, detail: `${linked} is a symbolic link, and devflow writes nothing through one` } };
293
+ }
233
294
  const existing = await readConfigBody(projectRoot, lib);
234
295
  if (existing.kind === 'malformed')
235
296
  return { ok: false, error: { kind: 'malformed', path: configPath } };
236
297
  if (existing.kind === 'unreadable') {
237
298
  return { ok: false, error: { kind: 'unreadable', path: configPath, detail: existing.detail } };
238
299
  }
239
- try {
240
- await writeConfigBody(projectRoot, mergeManagedConfig(objectOf(existing), managed));
241
- }
242
- catch (err) {
243
- return { ok: false, error: { kind: 'write-failed', path: configPath, detail: err instanceof Error ? err.message : String(err) } };
244
- }
300
+ const written = await writeConfigBody(projectRoot, mergeManagedConfig(objectOf(existing), managed));
301
+ if (!written.ok)
302
+ return { ok: false, error: { kind: 'write-failed', path: configPath, detail: written.detail } };
245
303
  return { ok: true };
246
304
  }
247
305
  /**
@@ -399,6 +399,30 @@ export const FLAG_REGISTRY = [
399
399
  integer: true,
400
400
  upstreamDefault: 30,
401
401
  },
402
+ {
403
+ // D-FOREGROUND-RUN: every agent runs builds and tests in the foreground under an explicit
404
+ // Bash `timeout` whose ceiling is Claude Code's 600000 ms, or this variable when set. A
405
+ // suite that cannot be split under that ceiling is reported BLOCKED with the remedy
406
+ // `devflow flags --set bash-max-timeout-ms=<ms>`, so this flag is that remedy.
407
+ // The env name was confirmed against Claude Code 2.1.294 (docs/reference/claude-code-flags-probe.md):
408
+ // the binary reads BASH_MAX_TIMEOUT_MS, ignores a non-positive or NaN value, and takes the
409
+ // larger of it and the default timeout. Neutral by default (undefined → manifest null →
410
+ // key deleted). min 600000 = upstream default, so the flag only ever raises the ceiling;
411
+ // max 7200000 (2 h) is the devflow sanity bound.
412
+ id: 'bash-max-timeout-ms',
413
+ label: 'Bash max timeout',
414
+ description: 'Ceiling in milliseconds for a foreground Bash command timeout',
415
+ hint: 'Raises the Bash timeout ceiling past 600000 ms for long-running suites',
416
+ blurb: 'Bash timeout ceiling',
417
+ kind: 'number',
418
+ target: { type: 'env', key: 'BASH_MAX_TIMEOUT_MS' },
419
+ recommended: false,
420
+ defaultValue: undefined,
421
+ min: 600000, // upstream default ceiling: lower values would only shrink it
422
+ max: 7200000, // devflow sanity bound: 2 hours
423
+ integer: true,
424
+ upstreamDefault: 600000,
425
+ },
402
426
  {
403
427
  // Writes as { command: value } per Claude Code spellcheck setting shape.
404
428
  id: 'spellcheck',
@@ -5,24 +5,23 @@
5
5
  * --clear` and `--disable` (src/cli/commands/learning.ts) and by the drain
6
6
  * `devflow init` runs when learning is switched off (src/cli/commands/init.ts).
7
7
  */
8
- import { promises as fs } from 'fs';
9
- import { getLearningClaimOwnerPath, getLearningPendingTurnsPath, getLearningPendingTurnsProcessingPath, } from './project-paths.js';
8
+ import * as path from 'path';
9
+ import { getLearningClaimOwnerPath, getLearningDir, getLearningPendingTurnsPath, getLearningPendingTurnsProcessingPath, } from './project-paths.js';
10
+ import { drainQueueFiles } from './queue-drain.js';
10
11
  /**
11
12
  * Drain the learning (decisions-detection) pending-turns queue, its claimed
12
13
  * batch and the claim's owner file so stale turns don't process later — used by
13
14
  * both `--clear` and `--disable`. A mid-run Learning agent whose claimed batch
14
15
  * vanishes aborts without changes, which is the desired outcome in both cases.
15
- * ENOENT-tolerant; other errors propagate.
16
+ * Refused, deleting nothing, when `.devflow` or `.devflow/learning` under `gitRoot`
17
+ * is a symbolic link (D-CLI-NO-SYMLINK). ENOENT-tolerant; other errors propagate.
16
18
  */
17
19
  export async function drainLearningQueue(gitRoot) {
18
- const unlinkIfPresent = (file) => fs.unlink(file).catch((e) => {
19
- if (e.code !== 'ENOENT')
20
- throw e;
21
- });
22
- await Promise.all([
23
- unlinkIfPresent(getLearningPendingTurnsPath(gitRoot)),
24
- unlinkIfPresent(getLearningPendingTurnsProcessingPath(gitRoot)),
25
- unlinkIfPresent(getLearningClaimOwnerPath(gitRoot)),
20
+ const learningDir = getLearningDir(gitRoot);
21
+ return drainQueueFiles([path.dirname(learningDir), learningDir], [
22
+ getLearningPendingTurnsPath(gitRoot),
23
+ getLearningPendingTurnsProcessingPath(gitRoot),
24
+ getLearningClaimOwnerPath(gitRoot),
26
25
  ]);
27
26
  }
28
27
  //# sourceMappingURL=learning-queue-cleanup.js.map