peaks-loop 4.1.18 → 4.1.20
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 +256 -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 +26 -18
- 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/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/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-profile.d.ts +23 -0
- package/dist/services/code/auto-compact-profile.js +51 -0
- 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/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 +2 -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/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/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/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-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 +9 -9
- package/schemas/doctor-report.schema.json +1 -1
- package/scripts/canonical-store-report.mjs +84 -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 +4 -4
- 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 +3 -1
- 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 +3 -1
- 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
|
@@ -4,11 +4,16 @@
|
|
|
4
4
|
* helper, and the synthetic-lookup refusal renderer. Later additions (the
|
|
5
5
|
* refusal write-path rule, the fragments-free refusal) live here for the same
|
|
6
6
|
* file-size reason.
|
|
7
|
+
*
|
|
8
|
+
* The artifact PATH and the record of which intent owns it moved to
|
|
9
|
+
* `best-practice-scan-collision.ts` in the same campaign: the §12.3 collision
|
|
10
|
+
* check needed more room than this file had under the 300-line cap.
|
|
7
11
|
*/
|
|
8
12
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
9
13
|
import { dirname, join, parse } from 'node:path';
|
|
10
14
|
import { fail } from 'peaks-loop-shared/result';
|
|
11
15
|
import { printResult } from '../cli-helpers.js';
|
|
16
|
+
import { intentIdLine, scanArtifactPath } from './best-practice-scan-collision.js';
|
|
12
17
|
export const CATCH_GATE_PROMPT = [
|
|
13
18
|
'⚠️ 任何跟你真实业务不一样,改 — LLM 推荐可能错。',
|
|
14
19
|
'回应 (默认 = 接受): 接受 / 接受方案 A|接受方案 B|接受方案 C / 拒绝 + 原因'
|
|
@@ -19,20 +24,32 @@ export const INTENT_REQUIRED_MESSAGE = 'best-practice-scan requires --intent <te
|
|
|
19
24
|
export const SYNTHETIC_SOURCE_MESSAGE = 'best-practice-scan: SKIPPED — the Context7 / WebSearch lookups in this build are stubs ' +
|
|
20
25
|
'(synthetic fragments), so no real documentation was consulted and there is nothing to ' +
|
|
21
26
|
'recommend. No recommendation, no comparison table and no ⚠️ catch gate were produced.';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
27
|
+
/**
|
|
28
|
+
* The catch-gate reply: the `PEAKS_BEST_PRACTICE_STDIN` seam in tests, the
|
|
29
|
+
* real stdin in production.
|
|
30
|
+
*
|
|
31
|
+
* Moved here from the command file: that file had three lines of headroom
|
|
32
|
+
* under the 300-line cap, and the collision check needed more than that.
|
|
33
|
+
*/
|
|
34
|
+
export async function readUserInput() {
|
|
35
|
+
const override = process.env.PEAKS_BEST_PRACTICE_STDIN;
|
|
36
|
+
if (override !== undefined)
|
|
37
|
+
return override;
|
|
38
|
+
if (process.stdin.isTTY)
|
|
39
|
+
return '';
|
|
40
|
+
return new Promise((resolveStdin) => {
|
|
41
|
+
let data = '';
|
|
42
|
+
process.stdin.setEncoding('utf8');
|
|
43
|
+
process.stdin.on('data', (chunk) => {
|
|
44
|
+
// `setEncoding('utf8')` above makes every chunk a string at runtime, but
|
|
45
|
+
// the declared type of the 'data' event is still a Buffer, so the `+`
|
|
46
|
+
// needs a string operand. `String(chunk)` is the same ToString the `+`
|
|
47
|
+
// operator applies, so the bytes accumulated are unchanged.
|
|
48
|
+
data += String(chunk);
|
|
49
|
+
});
|
|
50
|
+
process.stdin.on('end', () => resolveStdin(data.trim()));
|
|
51
|
+
process.stdin.on('error', () => resolveStdin(data.trim()));
|
|
52
|
+
});
|
|
36
53
|
}
|
|
37
54
|
/** Refusal body for a synthetic scan. It is written to the artifact path so
|
|
38
55
|
* the skip survives the fire-and-forget caller (`best-practice-auto-trigger`
|
|
@@ -74,7 +91,7 @@ export function writeRefusal(projectRoot, intent, refusal) {
|
|
|
74
91
|
? join(dirname(primary), 'skipped', parse(primary).base)
|
|
75
92
|
: primary;
|
|
76
93
|
mkdirSync(dirname(target), { recursive: true });
|
|
77
|
-
writeFileSync(target, refusal + '\n', 'utf8');
|
|
94
|
+
writeFileSync(target, intentIdLine(intent) + '\n' + refusal + '\n', 'utf8');
|
|
78
95
|
return target;
|
|
79
96
|
}
|
|
80
97
|
/**
|
|
@@ -84,11 +101,14 @@ export function writeRefusal(projectRoot, intent, refusal) {
|
|
|
84
101
|
* payload is proved to serialise *before* anything is written: a payload the
|
|
85
102
|
* printer cannot render must not leave behind an artifact claiming a scan that
|
|
86
103
|
* never reported.
|
|
104
|
+
*
|
|
105
|
+
* The first line is the intent-id marker, so a later scan can tell which
|
|
106
|
+
* intent owns this artifact.
|
|
87
107
|
*/
|
|
88
|
-
export function writeRenderedArtifact(artifactPath, table, payload) {
|
|
108
|
+
export function writeRenderedArtifact(artifactPath, table, payload, intent) {
|
|
89
109
|
JSON.stringify(payload);
|
|
90
110
|
mkdirSync(dirname(artifactPath), { recursive: true });
|
|
91
|
-
writeFileSync(artifactPath, table + '\n', 'utf8');
|
|
111
|
+
writeFileSync(artifactPath, intentIdLine(intent) + '\n' + table + '\n', 'utf8');
|
|
92
112
|
}
|
|
93
113
|
export const NO_FRAGMENTS_MESSAGE = 'best-practice-scan: NO FRAGMENTS — the lookups this scan resolved against returned no ' +
|
|
94
114
|
'documentation at all, so there is nothing to compare and no recommendation to make. ' +
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { addJsonOption, getErrorMessage, printResult } from '../cli-helpers.js';
|
|
2
2
|
import { fail } from 'peaks-loop-shared/result';
|
|
3
3
|
import { runAutoCompact } from '../../services/code/auto-compact-orchestrator.js';
|
|
4
|
+
import { normalizeAutoCompactMode } from '../../services/code/auto-compact-modes.js';
|
|
5
|
+
import { resolveAutoCompactProfile } from '../../services/code/auto-compact-profile.js';
|
|
4
6
|
import { probeInFlightBatch } from '../../services/workflow/workflow-inflight-probe.js';
|
|
5
7
|
import { readDispatchLedgerFacts } from '../../services/dispatch/dispatch-ledger-reader.js';
|
|
6
8
|
import { readActiveSid } from './code-runtime-session.js';
|
|
@@ -17,11 +19,13 @@ const AUTO_COMPACT_DESCRIPTION = 'v2.13.0 AC-4: zero-human-intervention auto-com
|
|
|
17
19
|
'command acts on. This command is also fired by the installed ' +
|
|
18
20
|
'PreToolUse hook, which passes `--project .` — without that argument ' +
|
|
19
21
|
'the hook could never run at all. rid-027 ' +
|
|
20
|
-
'adds `--mode <mode>`: `standard` (0.85/0.95)
|
|
21
|
-
'
|
|
22
|
+
'adds `--mode <mode>`: `standard` (pre-compact 0.85 / red-line 0.95) ' +
|
|
23
|
+
'or `eager` (pre-compact 0.70 / red-line 0.85 — fires earlier than ' +
|
|
24
|
+
'`standard`). With no `--mode`, the project setting `autoCompactProfile` ' +
|
|
25
|
+
'decides (default `standard`).';
|
|
22
26
|
/** The invalid-`--mode` branch, lifted verbatim out of the action body. */
|
|
23
27
|
function reportInvalidAutoCompactMode(io, modeName, json) {
|
|
24
|
-
printResult(io, fail('code.auto-compact', 'AUTO_COMPACT_INVALID_MODE', `Invalid --mode '${modeName}'. Valid values: standard | partial.`, null, ['Re-run with --mode standard or --mode
|
|
28
|
+
printResult(io, fail('code.auto-compact', 'AUTO_COMPACT_INVALID_MODE', `Invalid --mode '${modeName}'. Valid values: standard | eager. The legacy alias 'partial' is also accepted and means 'eager'.`, null, ['Re-run with --mode standard or --mode eager.']), json);
|
|
25
29
|
process.exitCode = 1;
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
@@ -67,11 +71,12 @@ function buildAutoCompactInput(opts, modeName, capture) {
|
|
|
67
71
|
: {}),
|
|
68
72
|
force: opts.force === true,
|
|
69
73
|
bypassRedLine: opts.bypassRedLine === true,
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
|
|
74
|
+
// The profile is resolved ONCE, by the resolver, and handed down
|
|
75
|
+
// explicitly: the CLI flag beats the project setting, and the project
|
|
76
|
+
// setting beats the default. The orchestrator's own fallback reads the
|
|
77
|
+
// same resolver, so the two cannot disagree about which profile is in
|
|
78
|
+
// force.
|
|
79
|
+
mode: modeName
|
|
75
80
|
};
|
|
76
81
|
}
|
|
77
82
|
/** The catch branch, lifted verbatim out of the action body. */
|
|
@@ -99,14 +104,17 @@ function deferralDetail(result, probe) {
|
|
|
99
104
|
/** The action body, lifted to a module-level function so both it and the registrar fit in 50 lines. */
|
|
100
105
|
async function runAutoCompactAction(opts, io) {
|
|
101
106
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
// `--mode` is normalized ONCE, here: the legacy alias `partial` becomes
|
|
108
|
+
// `eager` before anything is stored, reported or logged, so the alias
|
|
109
|
+
// never reaches the runtime state.
|
|
110
|
+
const cliMode = opts.mode === undefined ? null : normalizeAutoCompactMode(opts.mode);
|
|
111
|
+
if (opts.mode !== undefined && cliMode === null) {
|
|
112
|
+
reportInvalidAutoCompactMode(io, opts.mode, opts.json);
|
|
106
113
|
return;
|
|
107
114
|
}
|
|
115
|
+
const selection = resolveAutoCompactProfile({ projectRoot: opts.project, cliMode });
|
|
108
116
|
const capture = { last: null };
|
|
109
|
-
const result = await runAutoCompact(buildAutoCompactInput(opts,
|
|
117
|
+
const result = await runAutoCompact(buildAutoCompactInput(opts, selection.profile, capture));
|
|
110
118
|
const code = result.code;
|
|
111
119
|
const exitOk = result.ok || code === 'AUTO_COMPACT_SKIP' || code === 'AUTO_COMPACT_WAIT';
|
|
112
120
|
// Adapt AutoCompactResult → ResultEnvelope so printResult's
|
|
@@ -139,9 +147,9 @@ export function registerCodeAutoCompactCommand(code, io) {
|
|
|
139
147
|
// advertising it, not to change its meaning.
|
|
140
148
|
.option('--bypass-red-line', 'no-op: the 95% red line no longer gates dispatch, so there is nothing to bypass (accepted for backward compatibility)')
|
|
141
149
|
// No commander default here, deliberately. A declared default makes
|
|
142
|
-
// `opts.mode` permanently defined, which
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
.option('--mode <mode>', 'auto-compact mode
|
|
150
|
+
// `opts.mode` permanently defined, which would defeat the resolver's
|
|
151
|
+
// "project setting → default" fallback — the help text below promises
|
|
152
|
+
// that the project setting decides when no `--mode` is named.
|
|
153
|
+
// Absence must stay absent.
|
|
154
|
+
.option('--mode <mode>', 'auto-compact mode for THIS call: standard | eager (the legacy alias `partial` is accepted and means `eager`). Default: the project setting `autoCompactProfile`, else standard.')).action((opts) => runAutoCompactAction(opts, io));
|
|
147
155
|
}
|
|
@@ -34,6 +34,11 @@ export declare function canonicalizeProjectOption(project: string | undefined):
|
|
|
34
34
|
* The field is additive and present only when stale, so no existing consumer
|
|
35
35
|
* of the envelope changes shape. `null` projectRoot means the caller had no
|
|
36
36
|
* project to inspect — skipped, not assumed stale.
|
|
37
|
+
*
|
|
38
|
+
* WHAT THE WARNING SAYS. It names the FILE that no longer matches and WHAT
|
|
39
|
+
* about it, because "the version numbers differ" does not tell a reader which
|
|
40
|
+
* file to open. The remedy (`peaks workspace init`) is in the message: the
|
|
41
|
+
* reader is an LLM that must be able to act without guessing a command.
|
|
37
42
|
*/
|
|
38
43
|
export declare function generatedConfigNotice(projectRoot: string | undefined): {
|
|
39
44
|
field: Record<string, unknown>;
|
|
@@ -48,6 +48,11 @@ export function canonicalizeProjectOption(project) {
|
|
|
48
48
|
* The field is additive and present only when stale, so no existing consumer
|
|
49
49
|
* of the envelope changes shape. `null` projectRoot means the caller had no
|
|
50
50
|
* project to inspect — skipped, not assumed stale.
|
|
51
|
+
*
|
|
52
|
+
* WHAT THE WARNING SAYS. It names the FILE that no longer matches and WHAT
|
|
53
|
+
* about it, because "the version numbers differ" does not tell a reader which
|
|
54
|
+
* file to open. The remedy (`peaks workspace init`) is in the message: the
|
|
55
|
+
* reader is an LLM that must be able to act without guessing a command.
|
|
51
56
|
*/
|
|
52
57
|
export function generatedConfigNotice(projectRoot) {
|
|
53
58
|
if (projectRoot === undefined)
|
|
@@ -55,21 +60,50 @@ export function generatedConfigNotice(projectRoot) {
|
|
|
55
60
|
const staleness = detectStaleGeneratedArtifacts(projectRoot);
|
|
56
61
|
if (!staleness.stale)
|
|
57
62
|
return { field: {}, warnings: [] };
|
|
58
|
-
const onDiskVersion = staleness.onDisk?.packageVersion ?? '(unstamped)';
|
|
59
63
|
return {
|
|
60
64
|
field: {
|
|
61
65
|
generatedArtifacts: {
|
|
62
66
|
stale: true,
|
|
63
67
|
reasons: staleness.reasons,
|
|
64
68
|
onDiskPackageVersion: staleness.onDisk?.packageVersion ?? null,
|
|
65
|
-
installedPackageVersion: staleness.expected.packageVersion
|
|
69
|
+
installedPackageVersion: staleness.expected.packageVersion,
|
|
70
|
+
drift: staleness.drift
|
|
66
71
|
}
|
|
67
72
|
},
|
|
68
|
-
warnings: [
|
|
69
|
-
`Generated config at '${projectRoot}' was produced by peaks-loop ${onDiskVersion} ` +
|
|
70
|
-
`but ${staleness.expected.packageVersion} is installed (${staleness.reasons.join(', ')}). ` +
|
|
71
|
-
`Re-run \`peaks workspace init\` ` +
|
|
72
|
-
`to regenerate .claude/settings.local.json and the offline template copy.`
|
|
73
|
-
]
|
|
73
|
+
warnings: [stalenessWarning(projectRoot, staleness)]
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The one sentence the reader gets.
|
|
78
|
+
*
|
|
79
|
+
* The drift detail is appended only when there IS one: a verdict driven by the
|
|
80
|
+
* stamp alone (`unstamped`, `stamp-unreadable`, `template-changed`) has no
|
|
81
|
+
* file to point at, and inventing one would be a claim about a file nobody
|
|
82
|
+
* compared.
|
|
83
|
+
*
|
|
84
|
+
* The details are GROUPED per artifact, so a file that differs in two ways is
|
|
85
|
+
* named once with both of its differences — a warning that repeats the same
|
|
86
|
+
* path twice reads as two files.
|
|
87
|
+
*/
|
|
88
|
+
function stalenessWarning(projectRoot, staleness) {
|
|
89
|
+
const onDiskVersion = staleness.onDisk?.packageVersion ?? '(unstamped)';
|
|
90
|
+
const head = `Generated config at '${projectRoot}' was produced by peaks-loop ${onDiskVersion} ` +
|
|
91
|
+
`but ${staleness.expected.packageVersion} is installed (${staleness.reasons.join(', ')}). ` +
|
|
92
|
+
`Re-run \`peaks workspace init\` ` +
|
|
93
|
+
`to regenerate .claude/settings.local.json and the offline template copy.`;
|
|
94
|
+
if (staleness.drift.length === 0)
|
|
95
|
+
return head;
|
|
96
|
+
return `${head} Inconsistent: ${groupDriftDetails(staleness.drift)}.`;
|
|
97
|
+
}
|
|
98
|
+
/** The drift details, one clause per artifact. */
|
|
99
|
+
function groupDriftDetails(drift) {
|
|
100
|
+
const grouped = new Map();
|
|
101
|
+
for (const entry of drift) {
|
|
102
|
+
const details = grouped.get(entry.artifact) ?? [];
|
|
103
|
+
details.push(entry.detail);
|
|
104
|
+
grouped.set(entry.artifact, details);
|
|
105
|
+
}
|
|
106
|
+
return [...grouped.entries()]
|
|
107
|
+
.map(([artifact, details]) => `${artifact}: ${details.join('; ')}`)
|
|
108
|
+
.join(' | ');
|
|
109
|
+
}
|
|
@@ -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
|
+
}
|