peaks-loop 4.1.17 → 4.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +269 -0
- package/README-en.md +6 -0
- package/README.md +5 -0
- package/contracts/test-style-contract.md +14 -5
- package/dist/cli/commands/audit-red-lines-runners.js +6 -1
- package/dist/cli/commands/best-practice-scan-collision.d.ts +42 -0
- package/dist/cli/commands/best-practice-scan-collision.js +115 -0
- package/dist/cli/commands/best-practice-scan-command.d.ts +5 -0
- package/dist/cli/commands/best-practice-scan-command.js +9 -18
- package/dist/cli/commands/best-practice-scan-helpers.d.ts +12 -6
- package/dist/cli/commands/best-practice-scan-helpers.js +37 -17
- package/dist/cli/commands/code-auto-compact-command.js +71 -40
- package/dist/cli/commands/code-auto-compact-deferral.d.ts +34 -0
- package/dist/cli/commands/code-auto-compact-deferral.js +59 -0
- package/dist/cli/commands/code-gate-command.d.ts +4 -4
- package/dist/cli/commands/code-gate-command.js +4 -4
- package/dist/cli/commands/core/skill-generated-config-notice.d.ts +5 -0
- package/dist/cli/commands/core/skill-generated-config-notice.js +42 -8
- package/dist/cli/commands/core/skill-presence-commands.js +42 -74
- package/dist/cli/commands/core/skill-presence-set-command.d.ts +11 -0
- package/dist/cli/commands/core/skill-presence-set-command.js +175 -0
- package/dist/cli/commands/core/skill-registry-commands.js +32 -0
- package/dist/cli/commands/core/skill-store-report.d.ts +8 -0
- package/dist/cli/commands/core/skill-store-report.js +79 -0
- package/dist/cli/commands/core/standards-init-command.js +44 -8
- package/dist/cli/commands/core/standards-migrate-command.js +5 -4
- package/dist/cli/commands/dispatch-dag-runners.d.ts +1 -0
- package/dist/cli/commands/dispatch-dag-runners.js +11 -1
- package/dist/cli/commands/dispatch-detached-branch.js +19 -1
- package/dist/cli/commands/dispatch-prompt-composition.js +7 -2
- package/dist/cli/commands/dispatch-scratch-path-block.d.ts +73 -0
- package/dist/cli/commands/dispatch-scratch-path-block.js +131 -0
- package/dist/cli/commands/hooks-commands.js +36 -7
- package/dist/cli/commands/hooks-uninstall-command.js +5 -5
- package/dist/cli/commands/mut-commands-helpers.d.ts +72 -5
- package/dist/cli/commands/mut-commands-helpers.js +197 -4
- package/dist/cli/commands/mut-commands.d.ts +9 -1
- package/dist/cli/commands/mut-commands.js +82 -154
- package/dist/cli/commands/preferences-commands.js +27 -2
- package/dist/cli/commands/scan-scope-helpers.js +2 -2
- package/dist/services/24h-mode/auto-engage.d.ts +11 -3
- package/dist/services/24h-mode/auto-engage.js +14 -6
- package/dist/services/artifacts/artifact-templates.js +10 -0
- package/dist/services/artifacts/backcompat-acceptance.d.ts +8 -1
- package/dist/services/artifacts/backcompat-acceptance.js +8 -7
- package/dist/services/artifacts/rd-transition-gates.d.ts +32 -5
- package/dist/services/artifacts/rd-transition-gates.js +96 -19
- package/dist/services/artifacts/request-artifact-service.js +6 -6
- package/dist/services/audit/enforcers/lint-output-style.js +14 -2
- package/dist/services/audit/enforcers/root-scratch-artifacts.d.ts +46 -0
- package/dist/services/audit/enforcers/root-scratch-artifacts.js +97 -0
- package/dist/services/audit/static-service.js +4 -4
- package/dist/services/code/auto-compact-history.d.ts +6 -1
- package/dist/services/code/auto-compact-history.js +6 -1
- package/dist/services/code/auto-compact-modes.d.ts +60 -14
- package/dist/services/code/auto-compact-modes.js +75 -20
- package/dist/services/code/auto-compact-orchestrator.js +7 -5
- package/dist/services/code/auto-compact-profile.d.ts +23 -0
- package/dist/services/code/auto-compact-profile.js +51 -0
- package/dist/services/code/auto-compact-run-types.d.ts +8 -4
- package/dist/services/compact-history/compact-history-service.d.ts +6 -1
- package/dist/services/compact-history/compact-history-service.js +5 -1
- package/dist/services/context/auto-compact-types.d.ts +7 -5
- package/dist/services/dispatch/dispatch-ledger-reader.d.ts +13 -0
- package/dist/services/dispatch/dispatch-ledger-reader.js +164 -0
- package/dist/services/doctor/doctor-service/checks/canonical-store-version.d.ts +57 -0
- package/dist/services/doctor/doctor-service/checks/canonical-store-version.js +190 -0
- package/dist/services/doctor/doctor-service/checks/l3-runtime-root-census.d.ts +37 -0
- package/dist/services/doctor/doctor-service/checks/l3-runtime-root-census.js +100 -0
- package/dist/services/doctor/doctor-service/checks/skill-reference-parity.d.ts +11 -3
- package/dist/services/doctor/doctor-service/checks/skill-reference-parity.js +48 -29
- package/dist/services/doctor/doctor-service/plugin-registry.js +4 -0
- package/dist/services/doctor/doctor-service/types.d.ts +12 -0
- package/dist/services/hooks/hook-payload-cwd.d.ts +11 -4
- package/dist/services/hooks/hook-payload-cwd.js +11 -4
- package/dist/services/hooks/pre-tool-code-gate.d.ts +4 -4
- package/dist/services/hooks/pre-tool-code-gate.js +4 -4
- package/dist/services/hooks/presence-marker-detector.d.ts +3 -0
- package/dist/services/hooks/presence-marker-detector.js +21 -19
- package/dist/services/ide/adapters/claude-code-adapter.js +6 -8
- package/dist/services/ide/adapters/codex-adapter.js +23 -7
- package/dist/services/ide/adapters/cursor-adapter.js +23 -7
- package/dist/services/mode/mode-status-service.d.ts +26 -27
- package/dist/services/mode/mode-status-service.js +36 -60
- package/dist/services/preferences/preferences-types.d.ts +30 -0
- package/dist/services/preferences/preferences-types.js +13 -0
- package/dist/services/scan/acceptance-coverage-service.d.ts +14 -11
- package/dist/services/scan/acceptance-coverage-service.js +157 -52
- package/dist/services/scan/rid-change-claims.d.ts +15 -0
- package/dist/services/scan/rid-change-claims.js +116 -0
- package/dist/services/session/getSessionDir.d.ts +13 -0
- package/dist/services/session/getSessionDir.js +7 -1
- package/dist/services/skills/hooks-settings-types.d.ts +17 -21
- package/dist/services/skills/presence-caller-id.d.ts +51 -0
- package/dist/services/skills/presence-caller-id.js +43 -0
- package/dist/services/skills/presence-gate.d.ts +65 -0
- package/dist/services/skills/presence-gate.js +113 -0
- package/dist/services/skills/presence-lease-resolver.d.ts +63 -0
- package/dist/services/skills/presence-lease-resolver.js +114 -0
- package/dist/services/skills/presence-lease-selection.d.ts +91 -0
- package/dist/services/skills/presence-lease-selection.js +135 -0
- package/dist/services/skills/presence-lease-service.d.ts +3 -11
- package/dist/services/skills/presence-lease-service.js +34 -87
- package/dist/services/skills/presence-lease-store.d.ts +33 -0
- package/dist/services/skills/presence-lease-store.js +94 -0
- package/dist/services/skills/presence-lease-types.d.ts +31 -0
- package/dist/services/skills/presence-lease-types.js +27 -0
- package/dist/services/skills/presence-role.d.ts +35 -0
- package/dist/services/skills/presence-role.js +72 -0
- package/dist/services/skills/skill-presence-service.d.ts +39 -9
- package/dist/services/skills/skill-presence-service.js +143 -174
- package/dist/services/skills/skill-presence-write.d.ts +60 -0
- package/dist/services/skills/skill-presence-write.js +74 -0
- package/dist/services/skills/skill-statusline-service.js +7 -7
- package/dist/services/skills/sync-service-support.d.ts +27 -0
- package/dist/services/skills/sync-service.js +1 -0
- package/dist/services/standards/ide-aware-standards-service.d.ts +35 -23
- package/dist/services/standards/ide-aware-standards-service.js +45 -20
- package/dist/services/standards/migrate-claude-rules-service.d.ts +6 -0
- package/dist/services/standards/migrate-claude-rules-service.js +18 -0
- package/dist/services/standards/migrate-service.d.ts +1 -1
- package/dist/services/standards/migrate-service.js +27 -7
- package/dist/services/standards/project-scripts.d.ts +25 -0
- package/dist/services/standards/project-scripts.js +116 -0
- package/dist/services/standards/project-standards-service.d.ts +23 -15
- package/dist/services/standards/project-standards-service.js +176 -243
- package/dist/services/standards/standards-constitution.d.ts +89 -0
- package/dist/services/standards/standards-constitution.js +199 -0
- package/dist/services/standards/standards-files.d.ts +37 -0
- package/dist/services/standards/standards-files.js +138 -0
- package/dist/services/standards/standards-pointer.d.ts +73 -0
- package/dist/services/standards/standards-pointer.js +98 -0
- package/dist/services/standards/standards-render-agents.d.ts +34 -0
- package/dist/services/standards/standards-render-agents.js +149 -0
- package/dist/services/standards/standards-render-common.d.ts +38 -1
- package/dist/services/standards/standards-render-common.js +44 -7
- package/dist/services/standards/standards-render.d.ts +1 -3
- package/dist/services/standards/standards-render.js +6 -87
- package/dist/services/workflow/workflow-graph-ensure.d.ts +77 -0
- package/dist/services/workflow/workflow-graph-ensure.js +97 -0
- package/dist/services/workflow/workflow-inflight-probe.d.ts +68 -31
- package/dist/services/workflow/workflow-inflight-probe.js +163 -75
- package/dist/services/workflow/workflow-presence-lifecycle.js +21 -6
- package/dist/services/workspace/generated-artifacts-content.d.ts +46 -0
- package/dist/services/workspace/generated-artifacts-content.js +167 -0
- package/dist/services/workspace/generated-artifacts-stamp.d.ts +36 -13
- package/dist/services/workspace/generated-artifacts-stamp.js +37 -15
- package/dist/services/workspace/runtime-layout.d.ts +64 -0
- package/dist/services/workspace/runtime-layout.js +62 -0
- package/output-styles/peaks-skill-swarm.md +18 -2
- package/package.json +10 -9
- package/schemas/doctor-report.schema.json +1 -1
- package/scripts/canonical-store-fs.mjs +112 -0
- package/scripts/canonical-store-link.mjs +13 -22
- package/scripts/canonical-store-marker.mjs +241 -0
- package/scripts/canonical-store.mjs +119 -141
- package/scripts/install-skills-bundles.mjs +56 -13
- package/scripts/install-skills-fs.mjs +73 -0
- package/scripts/install-skills-output-styles.mjs +8 -2
- package/scripts/install-skills-report.mjs +19 -0
- package/scripts/install-skills.mjs +9 -0
- package/skills/bee/peaks-perf-audit/SKILL.md +3 -1
- package/skills/bee/peaks-prd/SKILL.md +5 -3
- package/skills/bee/peaks-qa/SKILL.md +4 -2
- package/skills/bee/peaks-qa/references/qa-skill-presence.md +1 -1
- package/skills/bee/peaks-qa/references/qa-standards-preflight.md +3 -1
- package/skills/bee/peaks-qa/references/qa-sub-agent-dispatch.md +2 -2
- package/skills/bee/peaks-rd/SKILL.md +4 -2
- package/skills/bee/peaks-rd/references/artifact-and-standards-output.md +1 -1
- package/skills/bee/peaks-rd/references/rd-runbook.md +11 -2
- package/skills/bee/peaks-rd/references/rd-standards-preflight.md +3 -1
- package/skills/bee/peaks-rd/references/rd-sub-agent-dispatch.md +24 -5
- package/skills/bee/peaks-rd/references/rd-transition-gates.md +49 -5
- package/skills/bee/peaks-rd/references/skill-presence-and-title.md +1 -1
- package/skills/bee/peaks-reviewer/SKILL.md +3 -1
- package/skills/bee/peaks-sc/SKILL.md +4 -2
- package/skills/bee/peaks-security-audit/SKILL.md +3 -1
- package/skills/bee/peaks-txt/SKILL.md +5 -3
- package/skills/bee/peaks-ui/SKILL.md +6 -4
- package/skills/peaks-audit/SKILL.md +3 -1
- package/skills/peaks-code/SKILL.md +4 -2
- package/skills/peaks-code/references/a2a-artifact-mapping.md +3 -3
- package/skills/peaks-code/references/completion-handoff.md +1 -1
- package/skills/peaks-code/references/local-artifact-workspace.md +10 -11
- package/skills/peaks-code/references/micro-cycle.md +2 -2
- package/skills/peaks-code/references/mode-selection-with-stale-presence.md +3 -3
- package/skills/peaks-code/references/runbook.md +4 -4
- package/skills/peaks-code/references/skill-presence-and-title.md +4 -2
- package/skills/peaks-code/references/standards-preflight.md +7 -6
- package/skills/peaks-code/references/sub-agent-dispatch.md +1 -1
- package/skills/peaks-code/references/swarm-dispatch-contract.md +5 -5
- package/skills/peaks-code/references/workflow-gates-and-types.md +37 -11
- package/skills/peaks-content/SKILL.md +3 -1
- package/skills/peaks-doctor/SKILL.md +3 -1
- package/skills/peaks-final-review/SKILL.md +3 -1
- package/skills/peaks-ide/SKILL.md +3 -1
- package/skills/peaks-issue-fix-orchestrator/SKILL.md +5 -3
- package/skills/peaks-race-code/SKILL.md +9 -4
- package/skills/peaks-resume/SKILL.md +3 -1
- package/skills/peaks-slice-decompose/SKILL.md +3 -1
- package/skills/peaks-solo/SKILL.md +3 -1
- package/skills/peaks-sop/SKILL.md +4 -2
- package/skills/peaks-status/SKILL.md +3 -1
- package/skills/peaks-test/SKILL.md +3 -1
|
@@ -1,30 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getSkillPresence, checkStalePresence } from '../../../services/skills/skill-presence-service.js';
|
|
2
|
+
import { diagnosePresence, resolveProjectRoot } from '../../../services/skills/presence-lease-resolver.js';
|
|
2
3
|
import { findProjectRoot } from '../../../services/config/config-safety.js';
|
|
3
|
-
import {
|
|
4
|
-
import { resolveCallerProjection } from '../../../services/session/resolve-caller-id.js';
|
|
5
|
-
import { fail, ok } from 'peaks-loop-shared/result';
|
|
4
|
+
import { ok } from 'peaks-loop-shared/result';
|
|
6
5
|
import { addJsonOption, printResult } from '../../cli-helpers.js';
|
|
7
6
|
import { canonicalizeProjectOption, generatedConfigNotice } from './skill-generated-config-notice.js';
|
|
8
7
|
import { contextVerdict } from './skill-context-verdict.js';
|
|
8
|
+
import { registerSkillPresenceSetCommand } from './skill-presence-set-command.js';
|
|
9
9
|
const PRESENCE_DESCRIPTION = 'Show the currently active Peaks skill (alias: presence:get)';
|
|
10
10
|
const PRESENCE_CHECK_STALE_HELP = 'slice 002 (v2.15.0): also report whether the recorded outer session id still matches the current one. Default false (back-compat).';
|
|
11
11
|
const PRESENCE_PROJECT_HELP = 'project root (default: cwd)';
|
|
12
|
-
const PRESENCE_SET_DESCRIPTION = 'Set the currently active Peaks skill for session-wide visibility. Slice 4.0.8: requires a bound session and an adapter-resolved caller id (fail-closed); raw unlink is rejected.';
|
|
13
|
-
const PRESENCE_SET_MODE_HELP = 'execution mode';
|
|
14
|
-
const PRESENCE_SET_GATE_HELP = 'current gate';
|
|
15
|
-
const PRESENCE_SET_PROJECT_HELP = 'project root path (auto-detected from cwd when omitted)';
|
|
16
12
|
function presenceActiveData(presence, parts) {
|
|
17
13
|
return {
|
|
18
14
|
active: true,
|
|
19
15
|
...presence,
|
|
16
|
+
gate: readGateField(presence.gate),
|
|
20
17
|
...(parts.verdict.context !== null ? { context: parts.verdict.context } : {}),
|
|
21
18
|
...parts.generatedConfig.field
|
|
22
19
|
};
|
|
23
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The gate cell of the status header. `null` when the active lease records
|
|
23
|
+
* no gate (a lease written before the gate was persisted).
|
|
24
|
+
*/
|
|
25
|
+
function readGateField(value) {
|
|
26
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
27
|
+
}
|
|
24
28
|
function presenceStaleData(presence, staleness, parts) {
|
|
25
29
|
return {
|
|
26
30
|
active: true,
|
|
27
31
|
...presence,
|
|
32
|
+
gate: readGateField(presence.gate),
|
|
28
33
|
stale: staleness.stale,
|
|
29
34
|
staleReason: staleness.reason,
|
|
30
35
|
currentOuterSessionId: staleness.currentOuterSessionId,
|
|
@@ -33,91 +38,54 @@ function presenceStaleData(presence, staleness, parts) {
|
|
|
33
38
|
...parts.generatedConfig.field
|
|
34
39
|
};
|
|
35
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The INACTIVE envelope. Without `--check-stale` it stays exactly
|
|
43
|
+
* `{ active: false }` — an optimistic default is not allowed. With it, the
|
|
44
|
+
* caller asked "why is nothing active?", so the diagnostic is attached.
|
|
45
|
+
*/
|
|
46
|
+
function presenceInactiveData(generatedConfig, diagnostic) {
|
|
47
|
+
return {
|
|
48
|
+
active: false,
|
|
49
|
+
stale: true,
|
|
50
|
+
staleReason: 'no-presence',
|
|
51
|
+
presenceInactive: {
|
|
52
|
+
reason: diagnostic.reason,
|
|
53
|
+
leaseCount: diagnostic.leaseCount,
|
|
54
|
+
terminalCount: diagnostic.terminalCount,
|
|
55
|
+
staleCount: diagnostic.staleCount,
|
|
56
|
+
eligibleCount: diagnostic.eligibleCount
|
|
57
|
+
},
|
|
58
|
+
...generatedConfig.field
|
|
59
|
+
};
|
|
60
|
+
}
|
|
36
61
|
function runSkillPresence(options, io) {
|
|
37
62
|
const projectOption = canonicalizeProjectOption(options.project);
|
|
38
63
|
const generatedConfig = generatedConfigNotice(projectOption ?? findProjectRoot(process.cwd()) ?? process.cwd());
|
|
39
64
|
const presence = getSkillPresence(projectOption);
|
|
40
65
|
if (presence === null) {
|
|
41
|
-
|
|
66
|
+
// Without `--check-stale` the envelope stays exactly `{ active: false }`.
|
|
67
|
+
const data = options.checkStale === true
|
|
68
|
+
? presenceInactiveData(generatedConfig, diagnosePresence(resolveProjectRoot(projectOption)))
|
|
69
|
+
: { active: false, ...generatedConfig.field };
|
|
70
|
+
printResult(io, ok('skill.presence', data, generatedConfig.warnings), options.json);
|
|
42
71
|
return;
|
|
43
72
|
}
|
|
44
73
|
// Loop-hygiene verdict: attached to every ACTIVE read, so the
|
|
45
|
-
// zero-pause contract travels with the one call every skill
|
|
46
|
-
// makes — in every mode and every consumer project.
|
|
74
|
+
// zero-pause contract travels with the one call every skill makes.
|
|
47
75
|
const verdict = contextVerdict(projectOption ?? process.cwd());
|
|
48
76
|
const parts = { verdict, generatedConfig };
|
|
49
|
-
// `--check-stale`
|
|
50
|
-
//
|
|
51
|
-
// UNCHANGED — it is a read-only flag, not a clear.
|
|
77
|
+
// `--check-stale` gives both pieces of info in one invocation; the
|
|
78
|
+
// presence itself is returned UNCHANGED — it is a read-only flag.
|
|
52
79
|
const data = options.checkStale === true
|
|
53
80
|
? presenceStaleData(presence, checkStalePresence({ projectRootOverride: projectOption }), parts)
|
|
54
81
|
: presenceActiveData(presence, parts);
|
|
55
82
|
printResult(io, ok('skill.presence', data, generatedConfig.warnings, verdict.nextActions), options.json);
|
|
56
83
|
}
|
|
57
|
-
function printInvalidMode(io, options, name) {
|
|
58
|
-
printResult(io, fail('skill.presence:set', 'INVALID_MODE', `Invalid mode: ${options.mode} (expected one of: full-auto, assisted, strict, 24h)`, { name, mode: options.mode }, ['Use a valid mode: full-auto, assisted, strict, or 24h']), options.json);
|
|
59
|
-
process.exitCode = 1;
|
|
60
|
-
}
|
|
61
|
-
function printSessionNotBound(io, options, name, projectRoot) {
|
|
62
|
-
printResult(io, fail('skill.presence:set', 'PEAKS_SESSION_NOT_BOUND', 'No canonical peaks session is bound for this project (RD §3 D1).', { projectRoot, name }, ['Run `peaks workspace init --project <p>` first, then re-run `peaks skill presence:set`.']), options.json);
|
|
63
|
-
process.exitCode = 1;
|
|
64
|
-
}
|
|
65
|
-
function printCallerNotResolved(io, options, target, err) {
|
|
66
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
67
|
-
printResult(io, fail('skill.presence:set', 'PEAKS_CALLER_NOT_RESOLVED', `Active IDE adapter could not resolve a callerId (RD §3 D1): ${message}`, target, [
|
|
68
|
-
'Ensure the active IDE is detected by `peaks` and the IDE session variable is set.',
|
|
69
|
-
'Or set PEAKS_CALLER_ID=<id> in the environment for scripted usage.'
|
|
70
|
-
]), options.json);
|
|
71
|
-
process.exitCode = 1;
|
|
72
|
-
}
|
|
73
|
-
function runSkillPresenceSet(name, options, io) {
|
|
74
|
-
const projectOption = canonicalizeProjectOption(options.project);
|
|
75
|
-
const projectRoot = projectOption ?? findProjectRoot(process.cwd()) ?? process.cwd();
|
|
76
|
-
if (options.mode !== undefined && !isSkillPresenceMode(options.mode)) {
|
|
77
|
-
printInvalidMode(io, options, name);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
// Slice 4.0.8 (D1 + D2): `presence:set` is fail-closed. We refuse
|
|
81
|
-
// any write when (a) no peaks session is bound, or (b) the active
|
|
82
|
-
// IDE adapter cannot resolve a valid callerId. Both failures
|
|
83
|
-
// surface BEFORE any filesystem write. The legacy
|
|
84
|
-
// `setSkillPresence` wrapper is kept as a compat shim for tests
|
|
85
|
-
// and CLI flows that intentionally do not need a session — but
|
|
86
|
-
// production CLI traffic must go through this gate.
|
|
87
|
-
const boundSessionId = getSessionId(projectRoot);
|
|
88
|
-
if (boundSessionId === null) {
|
|
89
|
-
printSessionNotBound(io, options, name, projectRoot);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
resolveCallerProjection({ projectRoot });
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
printCallerNotResolved(io, options, { name, projectRoot }, err);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const presence = setSkillPresence(name, options.mode, options.gate, projectOption);
|
|
100
|
-
// Session metadata is updated when a session is bound (read-only
|
|
101
|
-
// path: `getSessionId`). We do not auto-spawn a session.
|
|
102
|
-
if (boundSessionId !== null) {
|
|
103
|
-
setSessionMeta(projectRoot, boundSessionId, {
|
|
104
|
-
skill: name,
|
|
105
|
-
...(options.mode ? { mode: options.mode } : {}),
|
|
106
|
-
...(options.gate ? { gate: options.gate } : {})
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
printResult(io, ok('skill.presence:set', { active: true, ...presence }), options.json);
|
|
110
|
-
}
|
|
111
84
|
export function registerSkillPresenceCommands(skill, io) {
|
|
112
85
|
addJsonOption(skill
|
|
113
86
|
.command('presence')
|
|
114
87
|
.description(PRESENCE_DESCRIPTION)
|
|
115
88
|
.option('--check-stale', PRESENCE_CHECK_STALE_HELP)
|
|
116
89
|
.option('--project <path>', PRESENCE_PROJECT_HELP)).action((options) => runSkillPresence(options, io));
|
|
117
|
-
|
|
118
|
-
.command('presence:set <name>')
|
|
119
|
-
.description(PRESENCE_SET_DESCRIPTION)
|
|
120
|
-
.option('--mode <mode>', PRESENCE_SET_MODE_HELP)
|
|
121
|
-
.option('--gate <gate>', PRESENCE_SET_GATE_HELP)
|
|
122
|
-
.option('--project <path>', PRESENCE_SET_PROJECT_HELP)).action((name, options) => runSkillPresenceSet(name, options, io));
|
|
90
|
+
registerSkillPresenceSetCommand(skill, io);
|
|
123
91
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { type ProgramIO } from '../../cli-helpers.js';
|
|
3
|
+
export type PresenceSetOptions = {
|
|
4
|
+
mode?: string;
|
|
5
|
+
gate?: string;
|
|
6
|
+
project?: string;
|
|
7
|
+
callerId?: string;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function runSkillPresenceSet(name: string, options: PresenceSetOptions, io: ProgramIO): Promise<void>;
|
|
11
|
+
export declare function registerSkillPresenceSetCommand(skill: Command, io: ProgramIO): void;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { setSkillPresence, isSkillPresenceMode } from '../../../services/skills/skill-presence-service.js';
|
|
2
|
+
import { resolvePresenceCallerId } from '../../../services/skills/presence-caller-id.js';
|
|
3
|
+
import { MAX_PRESENCE_GATE_LENGTH, normalizePresenceGate } from '../../../services/skills/presence-gate.js';
|
|
4
|
+
import { canonicalizeProjectOption } from './skill-generated-config-notice.js';
|
|
5
|
+
import { findProjectRoot } from '../../../services/config/config-safety.js';
|
|
6
|
+
import { getSessionId, setSessionMeta } from '../../../services/session/session-manager.js';
|
|
7
|
+
import { fail, getErrorMessage, ok } from 'peaks-loop-shared/result';
|
|
8
|
+
import { addJsonOption, printResult } from '../../cli-helpers.js';
|
|
9
|
+
const PRESENCE_SET_DESCRIPTION = 'Set the currently active Peaks skill for session-wide visibility. Slice 4.0.8: requires a bound session and a resolved caller id (fail-closed); raw unlink is rejected.';
|
|
10
|
+
const PRESENCE_SET_MODE_HELP = 'execution mode';
|
|
11
|
+
const PRESENCE_SET_GATE_HELP = 'current gate';
|
|
12
|
+
const PRESENCE_SET_PROJECT_HELP = 'project root path (auto-detected from cwd when omitted)';
|
|
13
|
+
const PRESENCE_SET_CALLER_ID_HELP = 'caller id for this invocation (priority: --caller-id flag > PEAKS_CALLER_ID env > active IDE adapter); must match ^[a-zA-Z0-9._-]{1,200}$';
|
|
14
|
+
// The `request init` exit code for a caller id that was supplied but does
|
|
15
|
+
// not match the D1 regex (EX_DATAERR). 64 is the "nothing usable" code.
|
|
16
|
+
const CALLER_ID_INVALID_EXIT_CODE = 65;
|
|
17
|
+
const CALLER_ID_UNRESOLVED_EXIT_CODE = 1;
|
|
18
|
+
/**
|
|
19
|
+
* The code a FAILED canonical write is reported under. It is the code
|
|
20
|
+
* `peaks workflow init` already uses for the same write (graph + lease +
|
|
21
|
+
* index), so the two commands report one failure one way. A typed
|
|
22
|
+
* `PEAKS_*` code the service already raised (e.g. `PEAKS_GRAPH_LOCK_HELD`)
|
|
23
|
+
* is kept as-is; a raw filesystem error (ENOTDIR, EACCES, ...) is reported
|
|
24
|
+
* as the write failure it is.
|
|
25
|
+
*/
|
|
26
|
+
const PRESENCE_WRITE_FAILED_CODE = 'PEAKS_GRAPH_WRITE_FAILED';
|
|
27
|
+
function printInvalidMode(io, options, name) {
|
|
28
|
+
printResult(io, fail('skill.presence:set', 'INVALID_MODE', `Invalid mode: ${options.mode} (expected one of: full-auto, assisted, strict, 24h)`, { name, mode: options.mode }, ['Use a valid mode: full-auto, assisted, strict, or 24h']), options.json);
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
}
|
|
31
|
+
function printInvalidGate(io, options, name) {
|
|
32
|
+
printResult(io, fail('skill.presence:set', 'INVALID_GATE', `Invalid gate: ${options.gate} (expected a non-empty gate value of at most ${MAX_PRESENCE_GATE_LENGTH} characters, without control characters)`, { name, gate: options.gate }, ['Use a short gate value such as `startup`, `qa-validation` or `swarm-fan-out`.']), options.json);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
function printSessionNotBound(io, options, name, projectRoot) {
|
|
36
|
+
printResult(io, fail('skill.presence:set', 'PEAKS_SESSION_NOT_BOUND', 'No canonical peaks session is bound for this project (RD §3 D1).', { projectRoot, name }, ['Run `peaks workspace init --project <p>` first, then re-run `peaks skill presence:set`.']), options.json);
|
|
37
|
+
process.exitCode = 1;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The caller-id refusal. `CALLER_ID_INVALID` is a shape mismatch — a value
|
|
41
|
+
* was supplied but does not match the D1 regex. `PEAKS_CALLER_NOT_RESOLVED`
|
|
42
|
+
* means nothing could be resolved at all. Both are fail-closed: no lease is
|
|
43
|
+
* written.
|
|
44
|
+
*/
|
|
45
|
+
function printCallerFailure(io, options, target, failure) {
|
|
46
|
+
const invalid = failure.code === 'CALLER_ID_INVALID';
|
|
47
|
+
printResult(io, fail('skill.presence:set', failure.code, invalid ? failure.message : `Could not resolve a callerId: ${failure.message}`, target, invalid
|
|
48
|
+
? [
|
|
49
|
+
'Use a caller id matching ^[a-zA-Z0-9._-]{1,200}$ (letters, digits, dot, underscore, hyphen).'
|
|
50
|
+
]
|
|
51
|
+
: [
|
|
52
|
+
'Pass --caller-id <id>, or set PEAKS_CALLER_ID=<id> in the environment for scripted usage.'
|
|
53
|
+
]), options.json);
|
|
54
|
+
process.exitCode = invalid ? CALLER_ID_INVALID_EXIT_CODE : CALLER_ID_UNRESOLVED_EXIT_CODE;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The mode and the gate are checked BEFORE any write. The gate is persisted
|
|
58
|
+
* with the lease (it is the middle cell of the status header); unknown but
|
|
59
|
+
* well-formed gate values are accepted on purpose — the gate vocabulary is
|
|
60
|
+
* open (see `presence-gate.ts`).
|
|
61
|
+
*/
|
|
62
|
+
function validateSetFields(io, options, name) {
|
|
63
|
+
if (options.mode !== undefined && !isSkillPresenceMode(options.mode)) {
|
|
64
|
+
printInvalidMode(io, options, name);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (options.gate !== undefined) {
|
|
68
|
+
try {
|
|
69
|
+
normalizePresenceGate(options.gate);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
printInvalidGate(io, options, name);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resolve the caller id, or print the refusal and return null. The
|
|
80
|
+
* `--caller-id` flag and `PEAKS_CALLER_ID` are the vendor-neutral escape
|
|
81
|
+
* hatches; the active IDE adapter is the fallback. The priority chain
|
|
82
|
+
* lives in `resolve-caller-id.ts` and is not restated here.
|
|
83
|
+
*/
|
|
84
|
+
function resolveSetCallerId(io, options, target) {
|
|
85
|
+
const resolved = resolvePresenceCallerId({
|
|
86
|
+
projectRoot: target.projectRoot,
|
|
87
|
+
...(options.callerId !== undefined ? { flagValue: options.callerId } : {})
|
|
88
|
+
});
|
|
89
|
+
if (resolved.ok)
|
|
90
|
+
return resolved.callerId;
|
|
91
|
+
printCallerFailure(io, options, target, resolved);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The error code a failed canonical write is reported under. A typed
|
|
96
|
+
* `PEAKS_*` code the service already raised is kept, so a graph lock
|
|
97
|
+
* (`PEAKS_GRAPH_LOCK_HELD`) does not read as a generic write failure; a raw
|
|
98
|
+
* filesystem error is reported as the write failure it is.
|
|
99
|
+
*/
|
|
100
|
+
function presenceWriteFailureCode(error) {
|
|
101
|
+
const code = error.code;
|
|
102
|
+
return typeof code === 'string' && code.startsWith('PEAKS_') ? code : PRESENCE_WRITE_FAILED_CODE;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The canonical write FAILED — the graph the lease names could not be
|
|
106
|
+
* built, or the lease itself could not be written. The command FAILS here:
|
|
107
|
+
* a presence that was not written is not a presence that was set, and
|
|
108
|
+
* reporting success would leave the operator believing the skill is active
|
|
109
|
+
* when no lease exists.
|
|
110
|
+
*
|
|
111
|
+
* This branch is distinct from the two refusals above it: those are
|
|
112
|
+
* "nothing was even attempted" (no session bound, no caller id), this one
|
|
113
|
+
* is "the write was attempted and failed". The codes say which.
|
|
114
|
+
*/
|
|
115
|
+
function printWriteFailure(io, options, target, error) {
|
|
116
|
+
printResult(io, fail('skill.presence:set', presenceWriteFailureCode(error), `Could not write the canonical presence lease (graph + lease): ${getErrorMessage(error)}`, { name: target.name, projectRoot: target.projectRoot }, [
|
|
117
|
+
'Check that the session runtime directory is writable, then re-run `peaks skill presence:set`.'
|
|
118
|
+
]), options.json);
|
|
119
|
+
process.exitCode = 1;
|
|
120
|
+
}
|
|
121
|
+
export async function runSkillPresenceSet(name, options, io) {
|
|
122
|
+
const projectOption = canonicalizeProjectOption(options.project);
|
|
123
|
+
const projectRoot = projectOption ?? findProjectRoot(process.cwd()) ?? process.cwd();
|
|
124
|
+
if (!validateSetFields(io, options, name))
|
|
125
|
+
return;
|
|
126
|
+
// `presence:set` is fail-closed. We refuse any write when (a) no peaks
|
|
127
|
+
// session is bound, or (b) no callerId could be resolved — both BEFORE
|
|
128
|
+
// any filesystem write. The escape hatch for (b) is vendor-neutral:
|
|
129
|
+
// `--caller-id` / PEAKS_CALLER_ID beat the IDE adapter, so a host that
|
|
130
|
+
// is not Claude Code can still build a lease.
|
|
131
|
+
const boundSessionId = getSessionId(projectRoot);
|
|
132
|
+
if (boundSessionId === null) {
|
|
133
|
+
printSessionNotBound(io, options, name, projectRoot);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const callerId = resolveSetCallerId(io, options, { name, projectRoot });
|
|
137
|
+
if (callerId === null)
|
|
138
|
+
return;
|
|
139
|
+
// The canonical write is AWAITED: the command has to know whether the
|
|
140
|
+
// lease (and the graph it names) actually landed BEFORE it reports
|
|
141
|
+
// success. A failure here is reported as a failure.
|
|
142
|
+
let presence;
|
|
143
|
+
try {
|
|
144
|
+
presence = await setSkillPresence(name, options.mode, options.gate, {
|
|
145
|
+
projectRootOverride: projectOption,
|
|
146
|
+
callerIdOverride: callerId
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
printWriteFailure(io, options, { name, projectRoot }, error);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// Session metadata is updated when a session is bound (read-only path:
|
|
154
|
+
// `getSessionId`). We do not auto-spawn a session. The resolved callerId
|
|
155
|
+
// is recorded as the session's outer-session id so a later read can tell
|
|
156
|
+
// the recorded presence belongs to this caller.
|
|
157
|
+
if (boundSessionId !== null) {
|
|
158
|
+
setSessionMeta(projectRoot, boundSessionId, {
|
|
159
|
+
skill: name,
|
|
160
|
+
...(options.mode ? { mode: options.mode } : {}),
|
|
161
|
+
...(options.gate ? { gate: options.gate } : {}),
|
|
162
|
+
outerSessionId: callerId
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
printResult(io, ok('skill.presence:set', { active: true, ...presence }), options.json);
|
|
166
|
+
}
|
|
167
|
+
export function registerSkillPresenceSetCommand(skill, io) {
|
|
168
|
+
addJsonOption(skill
|
|
169
|
+
.command('presence:set <name>')
|
|
170
|
+
.description(PRESENCE_SET_DESCRIPTION)
|
|
171
|
+
.option('--mode <mode>', PRESENCE_SET_MODE_HELP)
|
|
172
|
+
.option('--gate <gate>', PRESENCE_SET_GATE_HELP)
|
|
173
|
+
.option('--caller-id <id>', PRESENCE_SET_CALLER_ID_HELP)
|
|
174
|
+
.option('--project <path>', PRESENCE_SET_PROJECT_HELP)).action((name, options) => runSkillPresenceSet(name, options, io));
|
|
175
|
+
}
|
|
@@ -3,6 +3,7 @@ import { listSkills } from '../../../services/skills/skill-registry.js';
|
|
|
3
3
|
import { runSkillSync, SYNC_PLATFORMS } from '../../../services/skills/sync-service.js';
|
|
4
4
|
import { ok, fail } from 'peaks-loop-shared/result';
|
|
5
5
|
import { addJsonOption, getErrorMessage, printResult } from '../../cli-helpers.js';
|
|
6
|
+
import { renderStoreReport } from './skill-store-report.js';
|
|
6
7
|
const PLATFORM_IDS = SYNC_PLATFORMS.join(', ');
|
|
7
8
|
const LIST_DESCRIPTION = 'List skills derived from skills/*/SKILL.md';
|
|
8
9
|
const LIST_INCLUDE_INTERNAL_HELP = 'include skills with visibility: internal (default: hide them)';
|
|
@@ -74,6 +75,34 @@ function runSkillDoctor(options, io) {
|
|
|
74
75
|
}
|
|
75
76
|
});
|
|
76
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* The canonical store's state, as the install found it: which entries are behind
|
|
80
|
+
* the installed release, which ones are the user's own, and how many are current.
|
|
81
|
+
*
|
|
82
|
+
* WHY IT IS REPORTED HERE. The install's `skipped` list used to be a value in a
|
|
83
|
+
* return object nobody read — a store entry that is left alone, or a copy that
|
|
84
|
+
* is behind, both looked exactly like a successful install from the outside.
|
|
85
|
+
* A dry run is where that report belongs: it says what a repair WOULD do,
|
|
86
|
+
* before anything is written.
|
|
87
|
+
*
|
|
88
|
+
* The FIRST platform's report is the one shown. The canonical store is shared by
|
|
89
|
+
* every platform, so the first pass sees the state as it was found; the later
|
|
90
|
+
* passes see what the first one already fixed.
|
|
91
|
+
*/
|
|
92
|
+
function storeReport(result, dryRun) {
|
|
93
|
+
const entries = result.perPlatform.find((platform) => platform.entries !== undefined)?.entries;
|
|
94
|
+
return renderStoreReport(entries, dryRun);
|
|
95
|
+
}
|
|
96
|
+
/** The report, as the next action the envelope carries — or none at all. */
|
|
97
|
+
function reportAction(report) {
|
|
98
|
+
return report === null ? [] : [report];
|
|
99
|
+
}
|
|
100
|
+
/** The human line, for the non-JSON output. The JSON envelope carries it too. */
|
|
101
|
+
function printStoreReport(io, report, asJson) {
|
|
102
|
+
if (report === null || asJson === true)
|
|
103
|
+
return;
|
|
104
|
+
io.stdout(` ${report}\n`);
|
|
105
|
+
}
|
|
77
106
|
async function runSkillSyncCommand(options, io) {
|
|
78
107
|
try {
|
|
79
108
|
const projectRoot = options.project ?? process.cwd();
|
|
@@ -84,14 +113,17 @@ async function runSkillSyncCommand(options, io) {
|
|
|
84
113
|
...(options.dryRun === true ? { dryRun: true } : {}),
|
|
85
114
|
...(options.reconcileJunctions === true ? { reconcileJunctions: true } : {})
|
|
86
115
|
});
|
|
116
|
+
const report = storeReport(result, options.dryRun === true);
|
|
87
117
|
const envelope = ok('skill.sync', result, [], [
|
|
88
118
|
`syncedCount: ${result.syncedCount}/${result.perPlatform.length} platforms`,
|
|
89
119
|
`totalInstalled: ${result.totalInstalled} skill symlinks`,
|
|
120
|
+
...reportAction(report),
|
|
90
121
|
result.failedCount > 0
|
|
91
122
|
? `failedCount: ${result.failedCount} (run \`peaks skill status\` for details)`
|
|
92
123
|
: 'no failures'
|
|
93
124
|
]);
|
|
94
125
|
printResult(io, envelope, options.json);
|
|
126
|
+
printStoreReport(io, report, options.json === true);
|
|
95
127
|
if (result.failedCount > 0) {
|
|
96
128
|
process.exitCode = 1;
|
|
97
129
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StoreEntryReport } from '../../../services/skills/sync-service-support.js';
|
|
2
|
+
/**
|
|
3
|
+
* The store report line, or null when the installer reported no rows at all.
|
|
4
|
+
*
|
|
5
|
+
* @param entries the rows the installer reported, or undefined when it reported none
|
|
6
|
+
* @param dryRun whether this run wrote nothing
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderStoreReport(entries: readonly StoreEntryReport[] | undefined, dryRun: boolean): string | null;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** The states, in the order the counts are printed. */
|
|
2
|
+
const STATE_ORDER = [
|
|
3
|
+
'current',
|
|
4
|
+
'stale',
|
|
5
|
+
'unmanaged',
|
|
6
|
+
'retired',
|
|
7
|
+
'absent'
|
|
8
|
+
];
|
|
9
|
+
/** The rows in one state. */
|
|
10
|
+
function rowsIn(entries, state) {
|
|
11
|
+
return entries.filter((entry) => entry.state === state);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* What this run did about a group of rows, in words.
|
|
15
|
+
*
|
|
16
|
+
* The suffix is per STATE as well as per action: an absent entry that was installed
|
|
17
|
+
* is not an entry that was repaired.
|
|
18
|
+
*/
|
|
19
|
+
function actionSuffix(state, action) {
|
|
20
|
+
if (action === 'installed') {
|
|
21
|
+
return state === 'absent' ? 'installed by this run' : 'repaired by this run';
|
|
22
|
+
}
|
|
23
|
+
if (action === 'planned') {
|
|
24
|
+
if (state === 'absent')
|
|
25
|
+
return 'would be installed';
|
|
26
|
+
if (state === 'retired')
|
|
27
|
+
return 'would be removed';
|
|
28
|
+
return 'would be repaired';
|
|
29
|
+
}
|
|
30
|
+
if (action === 'pruned')
|
|
31
|
+
return 'removed by this run';
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The names of a group, with what the run did about it.
|
|
36
|
+
*/
|
|
37
|
+
function describeGroup(entries, state, label) {
|
|
38
|
+
const rows = rowsIn(entries, state);
|
|
39
|
+
if (rows.length === 0)
|
|
40
|
+
return null;
|
|
41
|
+
const names = rows.map((entry) => entry.name).join(', ');
|
|
42
|
+
const suffix = actionSuffix(state, rows[0]?.action);
|
|
43
|
+
return `${label}: ${names}${suffix.length > 0 ? ` (${suffix})` : ''}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The absent group, as a count.
|
|
47
|
+
*
|
|
48
|
+
* The names are not listed: on a machine that has never run the install this group
|
|
49
|
+
* holds every skill the package ships, and a line with a hundred names in it is a
|
|
50
|
+
* line nobody reads. What the group MEANT is what the count carries — that many
|
|
51
|
+
* skills were not in the store, and what this run did about them.
|
|
52
|
+
*/
|
|
53
|
+
function describeAbsent(entries) {
|
|
54
|
+
const rows = rowsIn(entries, 'absent');
|
|
55
|
+
if (rows.length === 0)
|
|
56
|
+
return null;
|
|
57
|
+
const suffix = actionSuffix('absent', rows[0]?.action);
|
|
58
|
+
const label = suffix.length > 0 ? suffix : 'not in the store';
|
|
59
|
+
return `${label}: ${rows.length} skill${rows.length === 1 ? '' : 's'}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The store report line, or null when the installer reported no rows at all.
|
|
63
|
+
*
|
|
64
|
+
* @param entries the rows the installer reported, or undefined when it reported none
|
|
65
|
+
* @param dryRun whether this run wrote nothing
|
|
66
|
+
*/
|
|
67
|
+
export function renderStoreReport(entries, dryRun) {
|
|
68
|
+
if (entries === undefined)
|
|
69
|
+
return null;
|
|
70
|
+
const counts = STATE_ORDER.map((state) => `${rowsIn(entries, state).length} ${state}`).join(', ');
|
|
71
|
+
const detail = [
|
|
72
|
+
describeGroup(entries, 'stale', 'stale'),
|
|
73
|
+
describeGroup(entries, 'retired', 'retired (this release does not ship them)'),
|
|
74
|
+
describeGroup(entries, 'unmanaged', "left alone (not peaks-loop's to replace)"),
|
|
75
|
+
describeAbsent(entries)
|
|
76
|
+
].filter((line) => line !== null);
|
|
77
|
+
const reading = dryRun ? 'state as found; dry run: nothing written' : 'state as found';
|
|
78
|
+
return `skill store: ${counts} (${reading})${detail.length > 0 ? ` — ${detail.join('; ')}` : ''}`;
|
|
79
|
+
}
|
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
import { summarizeProjectStandardsInitResult, summarizeProjectStandardsUpdateResult } from '../../../services/standards/project-standards-service.js';
|
|
2
2
|
import { executeProjectStandardsInitIdeAware, executeProjectStandardsUpdateIdeAware } from '../../../services/standards/ide-aware-standards-service.js';
|
|
3
|
+
import { listAdapterIds } from '../../../services/ide/ide-registry.js';
|
|
3
4
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
4
5
|
import { addJsonOption, getErrorMessage, printResult } from '../../cli-helpers.js';
|
|
6
|
+
/**
|
|
7
|
+
* The registered IDE ids `--ide` accepts.
|
|
8
|
+
*
|
|
9
|
+
* Read from the registry rather than re-typed here: a hand-written list of
|
|
10
|
+
* ids is a second copy of the registry, and the copy that shipped with this
|
|
11
|
+
* command was missing `hermes`, `openclaw` and `zcode` — so `--ide zcode`
|
|
12
|
+
* used to reach `getAdapter()` and throw instead of being accepted.
|
|
13
|
+
*/
|
|
14
|
+
const SUPPORTED_IDE_IDS = listAdapterIds();
|
|
5
15
|
/** The five flags `init` and `update` share, in registration order. */
|
|
6
16
|
function withWriteFlags(cmd, applyHelp) {
|
|
7
17
|
return cmd
|
|
8
18
|
.requiredOption('--project <path>', 'target project root')
|
|
9
19
|
.option('--language <language>', 'standards language pack')
|
|
10
|
-
.option('--ide <id>',
|
|
20
|
+
.option('--ide <id>', `override IDE detection; the IDE's standards profile decides which instruction files are written (${SUPPORTED_IDE_IDS.join(' | ')})`)
|
|
11
21
|
.option('--dry-run', 'preview writes without changing files')
|
|
12
22
|
.option('--apply', applyHelp);
|
|
13
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* The `--ide` value, validated against the registry.
|
|
26
|
+
*
|
|
27
|
+
* `null` means "not a registered IDE" — the caller refuses with a
|
|
28
|
+
* structured envelope instead of letting the value reach `getAdapter()`,
|
|
29
|
+
* where an unknown id throws an unhandled error.
|
|
30
|
+
*/
|
|
31
|
+
function resolveIdeId(value) {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return null;
|
|
34
|
+
return SUPPORTED_IDE_IDS.find((id) => id === value) ?? null;
|
|
35
|
+
}
|
|
14
36
|
/** The ide-aware request both verbs build from the same flag set. */
|
|
15
|
-
function buildIdeAwareRequest(options) {
|
|
37
|
+
function buildIdeAwareRequest(options, ideId) {
|
|
16
38
|
return {
|
|
17
39
|
projectRoot: options.project,
|
|
18
40
|
...(options.language !== undefined ? { language: options.language } : {}),
|
|
19
|
-
...(
|
|
41
|
+
...(ideId !== null ? { ideId } : {}),
|
|
20
42
|
apply: options.apply === true
|
|
21
43
|
};
|
|
22
44
|
}
|
|
@@ -28,6 +50,14 @@ function refuseConflictingFlags(io, options, refusal) {
|
|
|
28
50
|
process.exitCode = 1;
|
|
29
51
|
return true;
|
|
30
52
|
}
|
|
53
|
+
/** Refuse an `--ide` value no adapter is registered under. */
|
|
54
|
+
function refuseUnknownIde(io, options, command, ideId) {
|
|
55
|
+
if (options.ide === undefined || ideId !== null)
|
|
56
|
+
return false;
|
|
57
|
+
printResult(io, fail(command, 'UNKNOWN_IDE', `Unknown IDE '${options.ide}'.`, { ide: options.ide, supportedIdeIds: SUPPORTED_IDE_IDS }, [`Pass one of: ${SUPPORTED_IDE_IDS.join(', ')}.`]), options.json);
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
31
61
|
function runStandardsInit(io, options) {
|
|
32
62
|
const refused = refuseConflictingFlags(io, options, {
|
|
33
63
|
command: 'standards.init',
|
|
@@ -38,8 +68,11 @@ function runStandardsInit(io, options) {
|
|
|
38
68
|
});
|
|
39
69
|
if (refused)
|
|
40
70
|
return;
|
|
71
|
+
const ideId = resolveIdeId(options.ide);
|
|
72
|
+
if (refuseUnknownIde(io, options, 'standards.init', ideId))
|
|
73
|
+
return;
|
|
41
74
|
try {
|
|
42
|
-
const result = executeProjectStandardsInitIdeAware(buildIdeAwareRequest(options));
|
|
75
|
+
const result = executeProjectStandardsInitIdeAware(buildIdeAwareRequest(options, ideId));
|
|
43
76
|
printResult(io, ok('standards.init', summarizeProjectStandardsInitResult(result)), options.json);
|
|
44
77
|
}
|
|
45
78
|
catch (error) {
|
|
@@ -59,8 +92,11 @@ function runStandardsUpdate(io, options) {
|
|
|
59
92
|
});
|
|
60
93
|
if (refused)
|
|
61
94
|
return;
|
|
95
|
+
const ideId = resolveIdeId(options.ide);
|
|
96
|
+
if (refuseUnknownIde(io, options, 'standards.update', ideId))
|
|
97
|
+
return;
|
|
62
98
|
try {
|
|
63
|
-
const result = executeProjectStandardsUpdateIdeAware(buildIdeAwareRequest(options));
|
|
99
|
+
const result = executeProjectStandardsUpdateIdeAware(buildIdeAwareRequest(options, ideId));
|
|
64
100
|
const summary = summarizeProjectStandardsUpdateResult(result);
|
|
65
101
|
const response = summary.reviewSuggestions.length > 0
|
|
66
102
|
? fail('standards.update', 'STANDARDS_UPDATE_REVIEW_REQUIRED', 'Standards update requires manual review', summary, summary.reviewSuggestions)
|
|
@@ -72,7 +108,7 @@ function runStandardsUpdate(io, options) {
|
|
|
72
108
|
}
|
|
73
109
|
catch (error) {
|
|
74
110
|
printResult(io, fail('standards.update', 'STANDARDS_UPDATE_FAILED', getErrorMessage(error), {}, [
|
|
75
|
-
'Check the project path,
|
|
111
|
+
'Check the project path, AGENTS.md contents, and existing .claude/rules directory before retrying'
|
|
76
112
|
]), options.json);
|
|
77
113
|
process.exitCode = 1;
|
|
78
114
|
}
|
|
@@ -80,8 +116,8 @@ function runStandardsUpdate(io, options) {
|
|
|
80
116
|
export function registerStandardsInitCommands(standards, io) {
|
|
81
117
|
addJsonOption(withWriteFlags(standards
|
|
82
118
|
.command('init')
|
|
83
|
-
.description('Initialize project-local coding standards for Peaks skill preflight'), 'write missing standards into the target project')).action((options) => runStandardsInit(io, options));
|
|
119
|
+
.description('Initialize project-local coding standards for Peaks skill preflight (AGENTS.md body + the CLAUDE.md pointer that imports it)'), 'write missing standards into the target project')).action((options) => runStandardsInit(io, options));
|
|
84
120
|
addJsonOption(withWriteFlags(standards
|
|
85
121
|
.command('update')
|
|
86
|
-
.description('Append managed standards metadata to
|
|
122
|
+
.description('Append managed standards metadata to the existing AGENTS.md / CLAUDE.md without rewriting their bodies'), 'append managed metadata to the target project')).action((options) => runStandardsUpdate(io, options));
|
|
87
123
|
}
|
|
@@ -2,7 +2,7 @@ import { migrateStandards } from '../../../services/standards/migrate-service.js
|
|
|
2
2
|
import { migrateClaudeRules } from '../../../services/standards/migrate-claude-rules-service.js';
|
|
3
3
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
4
4
|
import { addJsonOption, getErrorMessage, printResult } from '../../cli-helpers.js';
|
|
5
|
-
/** `--from-claude-rules`: thin `.claude/rules/` to pointers, scaffold `.peaks/standards
|
|
5
|
+
/** `--from-claude-rules`: thin `.claude/rules/` to pointers, scaffold `.peaks/standards/` + the constitution. */
|
|
6
6
|
function runMigrateClaudeRules(io, options, projectRoot) {
|
|
7
7
|
try {
|
|
8
8
|
const result = migrateClaudeRules({ projectRoot, apply: options.apply === true });
|
|
@@ -13,6 +13,7 @@ function runMigrateClaudeRules(io, options, projectRoot) {
|
|
|
13
13
|
backupPath: null,
|
|
14
14
|
thinnedFiles: [],
|
|
15
15
|
scaffoldedFiles: [],
|
|
16
|
+
scaffoldedConstitutionFiles: [],
|
|
16
17
|
preservedFiles: [],
|
|
17
18
|
wouldChange: false,
|
|
18
19
|
applied: false,
|
|
@@ -21,7 +22,7 @@ function runMigrateClaudeRules(io, options, projectRoot) {
|
|
|
21
22
|
process.exitCode = 1;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
/** Default branch: rewrite the legacy heartbeat block in
|
|
25
|
+
/** Default branch: rewrite the legacy heartbeat block in the project's constitution file. */
|
|
25
26
|
function runMigrateLegacy(io, options, projectRoot) {
|
|
26
27
|
try {
|
|
27
28
|
const result = migrateStandards({ project: projectRoot, apply: options.apply === true });
|
|
@@ -43,10 +44,10 @@ function runMigrateLegacy(io, options, projectRoot) {
|
|
|
43
44
|
export function registerStandardsMigrateCommand(standards, io) {
|
|
44
45
|
addJsonOption(standards
|
|
45
46
|
.command('migrate')
|
|
46
|
-
.description('Rewrite a consumer project CLAUDE.md to drop the legacy heartbeat block (slice 028). Dry-run by default; pass --apply to write. With --from-claude-rules, thins the 1.x .claude/rules/ tree to 2-line pointers and scaffolds .peaks/standards/ (slice 2026-06-12-standards-migrate-claude-rules).')
|
|
47
|
+
.description('Rewrite a consumer project constitution file (AGENTS.md, or CLAUDE.md in a 1.x tree) to drop the legacy heartbeat block (slice 028). Dry-run by default; pass --apply to write. With --from-claude-rules, thins the 1.x .claude/rules/ tree to 2-line pointers and scaffolds .peaks/standards/ plus the AGENTS.md + CLAUDE.md constitution (slice 2026-06-12-standards-migrate-claude-rules).')
|
|
47
48
|
.option('--project <path>', 'target project root')
|
|
48
49
|
.option('--apply', 'rewrite the legacy block in place; default is dry-run')
|
|
49
|
-
.option('--from-claude-rules', 'thin .claude/rules/ to pointers and scaffold .peaks/standards/')).action((options) => {
|
|
50
|
+
.option('--from-claude-rules', 'thin .claude/rules/ to pointers and scaffold .peaks/standards/ + the constitution files')).action((options) => {
|
|
50
51
|
const projectRoot = options.project ?? process.cwd();
|
|
51
52
|
if (options.fromClaudeRules === true) {
|
|
52
53
|
runMigrateClaudeRules(io, options, projectRoot);
|