Implements ADR-1411 P2 / #1415, closing #1366. Part 1 — config-loader.cts: - Adds `loadConfigResolved(cwd, options) → ConfigResolution { config, source, degraded }` with six tagged branch return paths: A1 ws+wsconfig → source:'workstream', degraded:false A2 no-ws+config → source:'root', degraded:false B ws requested, wsconfig absent → source:'root', degraded:true (intercepts recursive call) C .planning/ exists, no config → source:'builtin-defaults', degraded:false D no .planning/, global defaults readable → source:'global-defaults', degraded:false E no .planning/, no global → source:'builtin-defaults', degraded:false - `loadConfigResolved` calls `findProjectRoot` at entry to anchor resolution to the nearest .planning/ ancestor (cwd-drift fix, heuristic 4 from P1) - `loadConfig` becomes a one-line delegation: `return loadConfigResolved(cwd, options).config` - Exports `loadConfigResolved` in the `export =` block Part 2 — init.cts cmdAgentSkills: - Imports `findProjectRoot` from `./project-root.cjs` - Anchors to project root before loading config (fixes #1366 cwd-drift) - Uses `loadConfigResolved` for provenance; passes projectRoot to buildAgentSkillsBlock - Computes `configured` + `reason` (AgentSkillsReason enum): 'resolved' | 'not_configured' | 'configured_empty' | 'configured_unresolved' - configured_empty and configured_unresolved emit stderr WARNING; not_configured is silent - --json IR gains: configured, reason, source, degraded (in addition to existing agent_type, block, skills_count, warnings) Tests (TDD): - tests/config-loader.test.cjs: 8 new provenance tests (RED before impl, GREEN after) - tests/agent-skills.test.cjs: 7 new diagnostic tests (RED before impl, GREEN after) - All 306 tests across 4 suites pass (config-loader:33, agent-skills:72, init:105, workstream:96) Docs: - CONTEXT.md: Config Loader Module entry updated with loadConfigResolved interface; Resolution Provenance entry notes P2 is now implemented - docs/CLI-TOOLS.md: --json field reference table added for agent-skills Closes #1366 Part of #1411 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
69
src/init.cts
69
src/init.cts
@@ -14,6 +14,7 @@ import { execGit, platformWriteSync, platformReadSync } from './shell-command-pr
|
||||
import io = require('./io.cjs');
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- config-loader.cjs is an export= CommonJS module
|
||||
import configLoader = require('./config-loader.cjs');
|
||||
import { findProjectRoot } from './project-root.cjs';
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- model-resolver.cjs is an export= CommonJS module
|
||||
import modelResolver = require('./model-resolver.cjs');
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- phase-locator.cjs is an export= CommonJS module
|
||||
@@ -47,7 +48,7 @@ import gitBaseBranch = require('./git-base-branch.cjs');
|
||||
const { gitWorktreeInfoInternal } = gitBaseBranch;
|
||||
|
||||
const { output, error } = io;
|
||||
const { loadConfig } = configLoader;
|
||||
const { loadConfig, loadConfigResolved } = configLoader;
|
||||
const { resolveModelInternal, resolveGranularityInternal, assertValidGranularityOverride } = modelResolver;
|
||||
const { findPhaseInternal } = phaseLocator;
|
||||
const {
|
||||
@@ -2015,6 +2016,9 @@ function buildAgentSkillsBlock(
|
||||
return `<agent_skills>\nRead these user-configured skills:\n${lines}\n</agent_skills>`;
|
||||
}
|
||||
|
||||
/** Reason enum for agent-skills diagnostic (#1415, ADR-1411 P2). */
|
||||
type AgentSkillsReason = 'resolved' | 'not_configured' | 'configured_empty' | 'configured_unresolved';
|
||||
|
||||
function cmdAgentSkills(
|
||||
cwd: string,
|
||||
agentType: string | undefined,
|
||||
@@ -2026,24 +2030,67 @@ function cmdAgentSkills(
|
||||
return;
|
||||
}
|
||||
|
||||
const config = loadConfig(cwd);
|
||||
// Anchor to project root before loading config (#1415/#1366 cwd-drift fix).
|
||||
const projectRoot = findProjectRoot(cwd);
|
||||
const { config, source, degraded } = loadConfigResolved(projectRoot);
|
||||
const diagnostics = { warnings: [] as string[] };
|
||||
const block = buildAgentSkillsBlock(
|
||||
config,
|
||||
agentType,
|
||||
cwd,
|
||||
projectRoot,
|
||||
diagnostics,
|
||||
);
|
||||
|
||||
// Compute configured + reason for diagnostic output.
|
||||
const agentSkillsMap = (config && config['agent_skills'] && typeof config['agent_skills'] === 'object')
|
||||
? config['agent_skills'] as Record<string, unknown>
|
||||
: {};
|
||||
const configured = Object.prototype.hasOwnProperty.call(agentSkillsMap, agentType);
|
||||
|
||||
let reason: AgentSkillsReason;
|
||||
let skillPaths: unknown = configured ? agentSkillsMap[agentType] : [];
|
||||
if (!configured) {
|
||||
reason = 'not_configured';
|
||||
skillPaths = [];
|
||||
} else {
|
||||
// Normalize paths to array
|
||||
if (typeof skillPaths === 'string') skillPaths = [skillPaths];
|
||||
if (!Array.isArray(skillPaths)) skillPaths = [];
|
||||
const pathsArr = skillPaths as unknown[];
|
||||
// Fix 3: treat "" (empty string) as configured_empty — all-blank entries = no meaningful paths.
|
||||
// An array of all empty/blank strings has length > 0 but zero meaningful paths.
|
||||
const nonBlankPaths = pathsArr.filter(p => typeof p === 'string' && p.trim().length > 0);
|
||||
if (pathsArr.length === 0 || nonBlankPaths.length === 0) {
|
||||
// configured with empty array / "" / all-blank entries
|
||||
reason = 'configured_empty';
|
||||
// Reflect zero meaningful paths in the normalized array used for skills_count
|
||||
skillPaths = [];
|
||||
try {
|
||||
process.stderr.write(
|
||||
`[agent-skills] WARNING: Agent "${agentType}" is configured in agent_skills but has no skill paths — skills_count will be 0\n`
|
||||
);
|
||||
} catch { /* stderr might be closed */ }
|
||||
} else if (!block) {
|
||||
// configured with paths but all failed to resolve (warnings already emitted by buildAgentSkillsBlock)
|
||||
reason = 'configured_unresolved';
|
||||
} else {
|
||||
reason = 'resolved';
|
||||
}
|
||||
}
|
||||
|
||||
const normalizedPaths = Array.isArray(skillPaths) ? skillPaths : [];
|
||||
|
||||
if (jsonMode) {
|
||||
const skillPaths =
|
||||
(config && config.agent_skills && (config.agent_skills as Record<string, unknown>)[agentType]) || [];
|
||||
const normalizedPaths = Array.isArray(skillPaths)
|
||||
? skillPaths
|
||||
: skillPaths
|
||||
? [skillPaths]
|
||||
: [];
|
||||
output({ agent_type: agentType, block: block || '', skills_count: normalizedPaths.length, warnings: diagnostics.warnings }, raw);
|
||||
output({
|
||||
agent_type: agentType,
|
||||
block: block || '',
|
||||
skills_count: normalizedPaths.length,
|
||||
warnings: diagnostics.warnings,
|
||||
configured,
|
||||
reason,
|
||||
source,
|
||||
degraded,
|
||||
}, raw);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user