peaks-cli 1.3.8 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/dist/src/cli/commands/core-artifact-commands.js +27 -0
  2. package/dist/src/cli/commands/project-commands.js +58 -1
  3. package/dist/src/cli/commands/request-commands.js +93 -3
  4. package/dist/src/cli/commands/retrospective-commands.d.ts +3 -0
  5. package/dist/src/cli/commands/retrospective-commands.js +113 -0
  6. package/dist/src/cli/commands/skill-scope-commands.d.ts +49 -0
  7. package/dist/src/cli/commands/skill-scope-commands.js +305 -0
  8. package/dist/src/cli/commands/workflow-commands.js +1 -1
  9. package/dist/src/cli/commands/workflow-plan-commands.d.ts +39 -0
  10. package/dist/src/cli/commands/workflow-plan-commands.js +163 -0
  11. package/dist/src/cli/program.js +8 -0
  12. package/dist/src/services/doctor/doctor-service.d.ts +40 -0
  13. package/dist/src/services/doctor/doctor-service.js +160 -0
  14. package/dist/src/services/hooks/presence-marker-detector.d.ts +16 -0
  15. package/dist/src/services/hooks/presence-marker-detector.js +105 -0
  16. package/dist/src/services/memory/project-memory-service.d.ts +19 -0
  17. package/dist/src/services/memory/project-memory-service.js +33 -0
  18. package/dist/src/services/retrospective/migrate-from-md.d.ts +37 -0
  19. package/dist/src/services/retrospective/migrate-from-md.js +528 -0
  20. package/dist/src/services/retrospective/retrospective-index.d.ts +37 -0
  21. package/dist/src/services/retrospective/retrospective-index.js +110 -0
  22. package/dist/src/services/retrospective/retrospective-show.d.ts +40 -0
  23. package/dist/src/services/retrospective/retrospective-show.js +109 -0
  24. package/dist/src/services/skill-scope/adapters/_stub-helper.d.ts +39 -0
  25. package/dist/src/services/skill-scope/adapters/_stub-helper.js +98 -0
  26. package/dist/src/services/skill-scope/adapters/claude-code.d.ts +59 -0
  27. package/dist/src/services/skill-scope/adapters/claude-code.js +304 -0
  28. package/dist/src/services/skill-scope/adapters/codex.d.ts +2 -0
  29. package/dist/src/services/skill-scope/adapters/codex.js +12 -0
  30. package/dist/src/services/skill-scope/adapters/cursor.d.ts +2 -0
  31. package/dist/src/services/skill-scope/adapters/cursor.js +13 -0
  32. package/dist/src/services/skill-scope/adapters/qoder.d.ts +2 -0
  33. package/dist/src/services/skill-scope/adapters/qoder.js +13 -0
  34. package/dist/src/services/skill-scope/adapters/tongyi.d.ts +2 -0
  35. package/dist/src/services/skill-scope/adapters/tongyi.js +13 -0
  36. package/dist/src/services/skill-scope/adapters/trae.d.ts +2 -0
  37. package/dist/src/services/skill-scope/adapters/trae.js +12 -0
  38. package/dist/src/services/skill-scope/detect.d.ts +75 -0
  39. package/dist/src/services/skill-scope/detect.js +480 -0
  40. package/dist/src/services/skill-scope/registry.d.ts +41 -0
  41. package/dist/src/services/skill-scope/registry.js +83 -0
  42. package/dist/src/services/skill-scope/source-of-truth.d.ts +44 -0
  43. package/dist/src/services/skill-scope/source-of-truth.js +118 -0
  44. package/dist/src/services/skill-scope/types.d.ts +176 -0
  45. package/dist/src/services/skill-scope/types.js +74 -0
  46. package/dist/src/services/standards/migrate-service.d.ts +63 -0
  47. package/dist/src/services/standards/migrate-service.js +193 -0
  48. package/dist/src/services/standards/project-standards-service.js +1 -23
  49. package/dist/src/services/workflow/artifact-paths.d.ts +59 -0
  50. package/dist/src/services/workflow/artifact-paths.js +127 -0
  51. package/dist/src/services/workflow/pipeline-verify-service.d.ts +6 -0
  52. package/dist/src/services/workflow/pipeline-verify-service.js +49 -4
  53. package/dist/src/services/workflow/plan-reader.d.ts +29 -0
  54. package/dist/src/services/workflow/plan-reader.js +158 -0
  55. package/dist/src/services/workflow/plan-refresher.d.ts +32 -0
  56. package/dist/src/services/workflow/plan-refresher.js +353 -0
  57. package/dist/src/services/workflow/plan-trigger-detector.d.ts +55 -0
  58. package/dist/src/services/workflow/plan-trigger-detector.js +142 -0
  59. package/dist/src/shared/format-md-compact.d.ts +32 -0
  60. package/dist/src/shared/format-md-compact.js +297 -0
  61. package/dist/src/shared/stale-policy.d.ts +67 -0
  62. package/dist/src/shared/stale-policy.js +85 -0
  63. package/dist/src/shared/version.d.ts +1 -1
  64. package/dist/src/shared/version.js +1 -1
  65. package/package.json +3 -2
  66. package/schemas/doctor-report.schema.json +2 -2
  67. package/skills/peaks-qa/SKILL.md +103 -507
  68. package/skills/peaks-qa/references/artifact-per-request.md +7 -79
  69. package/skills/peaks-qa/references/browser-validation-contracts.md +51 -0
  70. package/skills/peaks-qa/references/codegraph-regression-focus.md +5 -0
  71. package/skills/peaks-qa/references/external-capability-guidance.md +9 -0
  72. package/skills/peaks-qa/references/qa-compact-handoff.md +3 -0
  73. package/skills/peaks-qa/references/qa-context-governance.md +24 -0
  74. package/skills/peaks-qa/references/qa-fanout-contract.md +8 -0
  75. package/skills/peaks-qa/references/qa-gstack-integration.md +7 -0
  76. package/skills/peaks-qa/references/qa-local-artifacts.md +3 -0
  77. package/skills/peaks-qa/references/qa-matt-pocock-integration.md +9 -0
  78. package/skills/peaks-qa/references/qa-perf-test-plan.md +67 -0
  79. package/skills/peaks-qa/references/qa-refactor-role.md +3 -0
  80. package/skills/peaks-qa/references/qa-runbook.md +74 -0
  81. package/skills/peaks-qa/references/qa-security-test-plan.md +73 -0
  82. package/skills/peaks-qa/references/qa-skill-presence.md +22 -0
  83. package/skills/peaks-qa/references/qa-standards-preflight.md +8 -0
  84. package/skills/peaks-qa/references/qa-sub-agent-dispatch.md +38 -0
  85. package/skills/peaks-qa/references/qa-transition-gates.md +83 -0
  86. package/skills/peaks-qa/references/requirement-boundary-recheck.md +9 -0
  87. package/skills/peaks-qa/references/test-case-generation.md +27 -0
  88. package/skills/peaks-qa/references/test-report-output.md +14 -0
  89. package/skills/peaks-rd/SKILL.md +85 -612
  90. package/skills/peaks-rd/references/artifact-and-standards-output.md +9 -0
  91. package/skills/peaks-rd/references/artifact-per-request.md +20 -0
  92. package/skills/peaks-rd/references/browser-self-test-contracts.md +29 -0
  93. package/skills/peaks-rd/references/codegraph-project-analysis.md +5 -0
  94. package/skills/peaks-rd/references/compact-handoff.md +3 -0
  95. package/skills/peaks-rd/references/external-references.md +11 -0
  96. package/skills/peaks-rd/references/frontend-project-generation.md +11 -0
  97. package/skills/peaks-rd/references/library-version-awareness.md +30 -0
  98. package/skills/peaks-rd/references/mandatory-perf-baseline.md +42 -0
  99. package/skills/peaks-rd/references/mandatory-tech-doc.md +18 -0
  100. package/skills/peaks-rd/references/matt-pocock-integration.md +11 -0
  101. package/skills/peaks-rd/references/mock-data-placement.md +40 -0
  102. package/skills/peaks-rd/references/parallel-review-fanout.md +81 -0
  103. package/skills/peaks-rd/references/rd-context-governance.md +36 -0
  104. package/skills/peaks-rd/references/rd-gstack-integration.md +16 -0
  105. package/skills/peaks-rd/references/rd-runbook.md +125 -0
  106. package/skills/peaks-rd/references/rd-standards-preflight.md +8 -0
  107. package/skills/peaks-rd/references/rd-sub-agent-dispatch.md +39 -0
  108. package/skills/peaks-rd/references/rd-transition-gates.md +1 -1
  109. package/skills/peaks-rd/references/skill-presence-and-title.md +22 -0
  110. package/skills/peaks-solo/SKILL.md +87 -595
  111. package/skills/peaks-solo/references/anchoring-and-session-info.md +25 -0
  112. package/skills/peaks-solo/references/boundaries.md +21 -0
  113. package/skills/peaks-solo/references/codegraph-orchestration.md +5 -0
  114. package/skills/peaks-solo/references/completion-handoff.md +16 -0
  115. package/skills/peaks-solo/references/context-governance.md +51 -0
  116. package/skills/peaks-solo/references/external-references.md +17 -0
  117. package/skills/peaks-solo/references/frontend-only-mode.md +14 -0
  118. package/skills/peaks-solo/references/gstack-integration.md +7 -0
  119. package/skills/peaks-solo/references/local-artifact-workspace.md +79 -0
  120. package/skills/peaks-solo/references/micro-cycle.md +68 -0
  121. package/skills/peaks-solo/references/mode-selection.md +21 -0
  122. package/skills/peaks-solo/references/openspec-workflow.md +43 -0
  123. package/skills/peaks-solo/references/project-memory-loading.md +17 -0
  124. package/skills/peaks-solo/references/quality-gate-cheatsheet.md +13 -0
  125. package/skills/peaks-solo/references/resume-detection.md +63 -0
  126. package/skills/peaks-solo/references/runbook.md +1 -1
  127. package/skills/peaks-solo/references/skill-presence-and-title.md +31 -0
  128. package/skills/peaks-solo/references/standards-preflight.md +23 -0
  129. package/skills/peaks-solo/references/sub-agent-dispatch.md +46 -0
  130. package/skills/peaks-solo/references/swarm-dispatch-contract.md +56 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * retrospective-show — load one retrospective entry by id, synthesize the
3
+ * body on-demand from `artifactPaths` (concatenate with `---` separator),
4
+ * apply `formatMdCompact` by default, return the JSON envelope.
5
+ *
6
+ * Slice 023 (R3). The on-disk MD form is gone after the G9 migration; the
7
+ * body is re-hydrated from the source PRD / RD / QA / TXT artifacts. If
8
+ * a referenced artifact is missing on disk, `show` returns a
9
+ * `ARTIFACT_MISSING` envelope (PRD R3) and does not crash.
10
+ *
11
+ * Stale policy is **not** applied to retrospective in this slice
12
+ * (per PRD G7 / R3 scope). The helper exists for a future slice.
13
+ */
14
+ import { loadRetrospectiveIndex, type RetrospectiveEntry, type RetrospectiveIndexResult } from './retrospective-index.js';
15
+ export type RetrospectiveFormat = 'compact' | 'pretty';
16
+ export interface RetrospectiveShowOptions {
17
+ projectRoot: string;
18
+ id: string;
19
+ format?: RetrospectiveFormat;
20
+ }
21
+ export interface RetrospectiveShowSuccess {
22
+ ok: true;
23
+ projectRoot: string;
24
+ format: RetrospectiveFormat;
25
+ entry: RetrospectiveEntry;
26
+ body: string;
27
+ warnings: string[];
28
+ }
29
+ export interface RetrospectiveShowError {
30
+ ok: false;
31
+ code: 'NOT_FOUND' | 'INDEX_MISSING' | 'ARTIFACT_MISSING' | 'INVALID_REQUEST';
32
+ message: string;
33
+ hint?: string;
34
+ projectRoot: string;
35
+ missingArtifacts?: string[];
36
+ }
37
+ export type RetrospectiveShowResult = RetrospectiveShowSuccess | RetrospectiveShowError;
38
+ export declare function showRetrospective(options: RetrospectiveShowOptions): RetrospectiveShowResult;
39
+ export { loadRetrospectiveIndex };
40
+ export type { RetrospectiveEntry, RetrospectiveIndexResult };
@@ -0,0 +1,109 @@
1
+ /**
2
+ * retrospective-show — load one retrospective entry by id, synthesize the
3
+ * body on-demand from `artifactPaths` (concatenate with `---` separator),
4
+ * apply `formatMdCompact` by default, return the JSON envelope.
5
+ *
6
+ * Slice 023 (R3). The on-disk MD form is gone after the G9 migration; the
7
+ * body is re-hydrated from the source PRD / RD / QA / TXT artifacts. If
8
+ * a referenced artifact is missing on disk, `show` returns a
9
+ * `ARTIFACT_MISSING` envelope (PRD R3) and does not crash.
10
+ *
11
+ * Stale policy is **not** applied to retrospective in this slice
12
+ * (per PRD G7 / R3 scope). The helper exists for a future slice.
13
+ */
14
+ import { existsSync, readFileSync } from 'node:fs';
15
+ import { join, resolve } from 'node:path';
16
+ import { formatMdCompact } from '../../shared/format-md-compact.js';
17
+ import { loadRetrospectiveIndex } from './retrospective-index.js';
18
+ export function showRetrospective(options) {
19
+ if (typeof options.id !== 'string' || options.id.trim().length === 0) {
20
+ return {
21
+ ok: false,
22
+ code: 'INVALID_REQUEST',
23
+ message: 'retrospective show requires a non-empty <id> argument',
24
+ projectRoot: resolve(options.projectRoot)
25
+ };
26
+ }
27
+ const resolvedRoot = resolve(options.projectRoot);
28
+ const index = loadRetrospectiveIndex(resolvedRoot);
29
+ if (index.source === null) {
30
+ return {
31
+ ok: false,
32
+ code: 'INDEX_MISSING',
33
+ message: index.warning ?? `retrospective index not found at ${index.indexPath}`,
34
+ hint: 'run `peaks retrospective migrate --apply` to build the index',
35
+ projectRoot: resolvedRoot
36
+ };
37
+ }
38
+ const entry = index.entries.find((e) => e.id === options.id);
39
+ if (entry === undefined) {
40
+ return {
41
+ ok: false,
42
+ code: 'NOT_FOUND',
43
+ message: `retrospective entry not found: ${options.id}`,
44
+ hint: 'run `peaks retrospective index --json` to see available ids',
45
+ projectRoot: resolvedRoot
46
+ };
47
+ }
48
+ const format = options.format ?? 'compact';
49
+ const synthesis = synthesizeBody(entry, resolvedRoot);
50
+ const body = format === 'pretty' ? synthesis.body : formatMdCompact(synthesis.body);
51
+ const warnings = synthesis.warnings;
52
+ return {
53
+ ok: true,
54
+ projectRoot: resolvedRoot,
55
+ format,
56
+ entry,
57
+ body,
58
+ warnings
59
+ };
60
+ }
61
+ function synthesizeBody(entry, projectRoot) {
62
+ if (entry.artifactPaths.length === 0) {
63
+ return { body: renderEntryHeader(entry), warnings: ['entry has no artifactPaths; body is the index summary only'] };
64
+ }
65
+ const sections = [];
66
+ const warnings = [];
67
+ for (const relativePath of entry.artifactPaths) {
68
+ const absolutePath = join(projectRoot, relativePath);
69
+ if (!existsSync(absolutePath)) {
70
+ warnings.push(`artifact missing on disk: ${relativePath}`);
71
+ continue;
72
+ }
73
+ try {
74
+ const content = readFileSync(absolutePath, 'utf8');
75
+ sections.push(`## ${relativePath}\n\n${content}`);
76
+ }
77
+ catch (error) {
78
+ const message = error instanceof Error ? error.message : String(error);
79
+ warnings.push(`failed to read ${relativePath}: ${message}`);
80
+ }
81
+ }
82
+ const header = renderEntryHeader(entry);
83
+ const body = sections.length === 0
84
+ ? `${header}\n\n_No artifacts available; only the index summary is shown._`
85
+ : `${header}\n\n${sections.join('\n\n---\n\n')}`;
86
+ return { body, warnings };
87
+ }
88
+ function renderEntryHeader(entry) {
89
+ const lines = [
90
+ `# ${entry.title}`,
91
+ '',
92
+ `- id: ${entry.id}`,
93
+ `- session: ${entry.sessionId}`,
94
+ ...(entry.sliceId !== undefined ? [`- slice: ${entry.sliceId}`] : []),
95
+ `- type: ${entry.type}`,
96
+ `- outcome: ${entry.outcome}`,
97
+ `- updatedAt: ${entry.updatedAt}`,
98
+ `- lessonsLearned: ${entry.lessonsLearned}`,
99
+ ''
100
+ ];
101
+ if (entry.keyDecisions.length > 0) {
102
+ lines.push('## Key Decisions', '', ...entry.keyDecisions.map((decision) => `- ${decision}`), '');
103
+ }
104
+ if (entry.summary.length > 0) {
105
+ lines.push('## Summary', '', entry.summary, '');
106
+ }
107
+ return lines.join('\n');
108
+ }
109
+ export { loadRetrospectiveIndex };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Shared `makeStubAdapter` helper for the 5 non-shipped IDEs (Trae, Cursor,
3
+ * Codex, Qoder, Tongyi Lingma).
4
+ *
5
+ * Each stub adapter:
6
+ * 1. Implements `SkillScopeAdapter` with `supported: false`.
7
+ * 2. In `applyScope`, ALWAYS writes the companion source-of-truth
8
+ * `.peaks/scope/<ide>-skills.json` first, then returns a NOT_SUPPORTED
9
+ * ApplyResult (the test contract asserts the source-of-truth is on disk
10
+ * even when the adapter can't apply it natively).
11
+ * 3. In `showScope`, reads from the companion source-of-truth file.
12
+ * 4. In `resetScope`, removes the companion source-of-truth file.
13
+ * 5. In `detect`, returns 0.0 (the stub does not actually probe).
14
+ *
15
+ * The TODO comment in each stub file points at the follow-up slice (025.2+).
16
+ */
17
+ import type { SkillScopeAdapter } from '../types.js';
18
+ /**
19
+ * IDE-id -> companion source-of-truth shape. The companion file is a
20
+ * parallel record so the user can see "this is what would have applied"
21
+ * even when the IDE doesn't support a real implementation.
22
+ */
23
+ export interface StubSourceOfTruth {
24
+ readonly ide: string;
25
+ readonly generatedAt: string;
26
+ readonly strict: boolean;
27
+ readonly allowlist: readonly string[];
28
+ readonly denylist: readonly string[];
29
+ readonly todoRef: string;
30
+ readonly notes: string;
31
+ }
32
+ /**
33
+ * The factory: every stub is a thin wrapper around this function. The
34
+ * `applyScope` implementation ALWAYS writes the source-of-truth, then
35
+ * returns a NOT_SUPPORTED ApplyResult (NOT a thrown error — the contract
36
+ * for stub adapters is "return ok:false, notSupported:true" so the CLI
37
+ * can keep going and surface the error to the user).
38
+ */
39
+ export declare function makeStubAdapter(ide: SkillScopeAdapter['ide'], todoRef: string, displayName: string): SkillScopeAdapter;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Shared `makeStubAdapter` helper for the 5 non-shipped IDEs (Trae, Cursor,
3
+ * Codex, Qoder, Tongyi Lingma).
4
+ *
5
+ * Each stub adapter:
6
+ * 1. Implements `SkillScopeAdapter` with `supported: false`.
7
+ * 2. In `applyScope`, ALWAYS writes the companion source-of-truth
8
+ * `.peaks/scope/<ide>-skills.json` first, then returns a NOT_SUPPORTED
9
+ * ApplyResult (the test contract asserts the source-of-truth is on disk
10
+ * even when the adapter can't apply it natively).
11
+ * 3. In `showScope`, reads from the companion source-of-truth file.
12
+ * 4. In `resetScope`, removes the companion source-of-truth file.
13
+ * 5. In `detect`, returns 0.0 (the stub does not actually probe).
14
+ *
15
+ * The TODO comment in each stub file points at the follow-up slice (025.2+).
16
+ */
17
+ import { existsSync } from 'node:fs';
18
+ import { readFile } from 'node:fs/promises';
19
+ import { ideCompanionFilePath, removeIfExists, scopeFilePath, writeJsonAtomic } from '../source-of-truth.js';
20
+ async function writeStubCompanion(ide, input, todoRef) {
21
+ const file = ideCompanionFilePath(input.projectRoot, ide);
22
+ const data = {
23
+ ide,
24
+ generatedAt: input.sourceConfig.generatedAt,
25
+ strict: input.strict,
26
+ allowlist: input.allowlist,
27
+ denylist: input.denylist,
28
+ todoRef,
29
+ notes: `Stub source-of-truth for ${ide}. The real config format has not yet been researched. ` +
30
+ `This file is written so the user's intent is captured and can be ported when ` +
31
+ `the follow-up slice (${todoRef}) lands.`,
32
+ };
33
+ await writeJsonAtomic(file, data);
34
+ return file;
35
+ }
36
+ async function readStubCompanion(ide, projectRoot) {
37
+ const file = ideCompanionFilePath(projectRoot, ide);
38
+ if (!existsSync(file))
39
+ return null;
40
+ try {
41
+ return JSON.parse(await readFile(file, 'utf8'));
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ }
47
+ /**
48
+ * The factory: every stub is a thin wrapper around this function. The
49
+ * `applyScope` implementation ALWAYS writes the source-of-truth, then
50
+ * returns a NOT_SUPPORTED ApplyResult (NOT a thrown error — the contract
51
+ * for stub adapters is "return ok:false, notSupported:true" so the CLI
52
+ * can keep going and surface the error to the user).
53
+ */
54
+ export function makeStubAdapter(ide, todoRef, displayName) {
55
+ const ideStr = String(ide);
56
+ return {
57
+ ide,
58
+ supported: false,
59
+ async detect() {
60
+ // Stubs never "win" detection; they return 0.0 so the registry falls
61
+ // back to the shipped adapter (Claude Code).
62
+ return 0.0;
63
+ },
64
+ async applyScope(input) {
65
+ // 1. Always write the source-of-truth first.
66
+ const companion = await writeStubCompanion(ideStr, input, todoRef);
67
+ // 2. Always write the canonical .peaks/scope/skills.json too.
68
+ const canonical = scopeFilePath(input.projectRoot);
69
+ await writeJsonAtomic(canonical, input.sourceConfig);
70
+ // 3. Surface NOT_SUPPORTED with a clear, IDE-named message.
71
+ const message = `${displayName} (${ideStr}) config format not yet researched — ${todoRef} follow-up. ` +
72
+ `Source-of-truth written to ${companion}.`;
73
+ return {
74
+ ide,
75
+ ok: false,
76
+ writtenFiles: [companion, canonical],
77
+ usedShadowStub: false,
78
+ notSupported: true,
79
+ error: { code: 'NOT_SUPPORTED', message },
80
+ };
81
+ },
82
+ async showScope(projectRoot) {
83
+ const native = await readStubCompanion(ideStr, projectRoot);
84
+ return { source: null, native, ide };
85
+ },
86
+ async resetScope(input) {
87
+ const removed = [];
88
+ const companion = ideCompanionFilePath(input.projectRoot, ideStr);
89
+ if (await removeIfExists(companion))
90
+ removed.push(companion);
91
+ // Also remove the canonical source-of-truth on reset.
92
+ const canonical = scopeFilePath(input.projectRoot);
93
+ if (await removeIfExists(canonical))
94
+ removed.push(canonical);
95
+ return { ide, removedFiles: removed };
96
+ },
97
+ };
98
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * `peaks skill scope` — Claude Code adapter (full impl, slice 025.1).
3
+ *
4
+ * Strategy (tech-doc-025 §3):
5
+ * 1. PRIMARY: write `.claude/settings.local.json` with
6
+ * `permissions.allow: ["Skill(name)", ...]` + `permissions.deny: [...]`.
7
+ * 2. FALLBACK (R1, `--shadow-fallback`): when the runtime probe determines
8
+ * Claude Code rejects `Skill(name)` in `permissions.deny`, write a
9
+ * shadow stub at `.claude/skills/<name>/SKILL.md` for each denylisted
10
+ * skill. Tagged with `_peaks_scope_disabled: true` (R6).
11
+ *
12
+ * Idempotency: dedupe the allow/deny arrays; shadow-stub writes skip
13
+ * when the marker is already present. AC11.
14
+ */
15
+ import type { ApplyResult, ApplyScopeInput, ResetScopeInput, ResetScopeResult, ShowScopeResult, SkillScopeAdapter } from '../types.js';
16
+ /** Format the `Skill(name)` string Claude Code's permission system uses. */
17
+ export declare function skillRef(name: string): string;
18
+ interface ClaudePermissions {
19
+ readonly allow: string[];
20
+ readonly deny: string[];
21
+ }
22
+ interface ClaudeSettings {
23
+ readonly permissions: ClaudePermissions;
24
+ readonly [key: string]: unknown;
25
+ }
26
+ /**
27
+ * Map allowlist/denylist → permissions.allow/permissions.deny. Never sorts;
28
+ * preserves input order. Always dedupes.
29
+ */
30
+ export declare function toPermissions(allowlist: readonly string[], denylist: readonly string[]): ClaudeSettings;
31
+ /**
32
+ * Strip any peaks-* name from the denylist (G6 hard constraint). Returns
33
+ * the cleaned denylist + the list of stripped names for the audit log.
34
+ */
35
+ export declare function stripPeaksFromDenylist(denylist: readonly string[]): {
36
+ readonly cleaned: readonly string[];
37
+ readonly stripped: readonly string[];
38
+ };
39
+ /**
40
+ * Runtime probe for whether Claude Code supports `Skill(name)` syntax in
41
+ * `permissions.deny` (R1). For slice 025.1 we return `unknown` and let
42
+ * the caller decide. Replace this with a real check when Claude Code's
43
+ * `permissions.deny` schema is documented.
44
+ */
45
+ export declare function probeSkillDenySupport(): Promise<'support-allow-and-deny' | 'support-allow-only' | 'unknown'>;
46
+ export declare class ClaudeCodeSkillScope implements SkillScopeAdapter {
47
+ readonly ide: "claude-code";
48
+ readonly supported = true;
49
+ constructor(_opts?: {
50
+ readonly projectRoot?: string;
51
+ });
52
+ /** detect(): returns 1.0 when the project root has a .claude/ dir. */
53
+ detect(projectRoot: string): Promise<number>;
54
+ applyScope(input: ApplyScopeInput): Promise<ApplyResult>;
55
+ showScope(projectRoot: string): Promise<ShowScopeResult>;
56
+ resetScope(input: ResetScopeInput): Promise<ResetScopeResult>;
57
+ }
58
+ export declare const CLAUDE_CODE_SKILL_SCOPE: SkillScopeAdapter;
59
+ export {};
@@ -0,0 +1,304 @@
1
+ /**
2
+ * `peaks skill scope` — Claude Code adapter (full impl, slice 025.1).
3
+ *
4
+ * Strategy (tech-doc-025 §3):
5
+ * 1. PRIMARY: write `.claude/settings.local.json` with
6
+ * `permissions.allow: ["Skill(name)", ...]` + `permissions.deny: [...]`.
7
+ * 2. FALLBACK (R1, `--shadow-fallback`): when the runtime probe determines
8
+ * Claude Code rejects `Skill(name)` in `permissions.deny`, write a
9
+ * shadow stub at `.claude/skills/<name>/SKILL.md` for each denylisted
10
+ * skill. Tagged with `_peaks_scope_disabled: true` (R6).
11
+ *
12
+ * Idempotency: dedupe the allow/deny arrays; shadow-stub writes skip
13
+ * when the marker is already present. AC11.
14
+ */
15
+ import { existsSync } from 'node:fs';
16
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
17
+ import { dirname, join } from 'node:path';
18
+ /** Adapter id. */
19
+ const IDE_ID = 'claude-code';
20
+ /** Format the `Skill(name)` string Claude Code's permission system uses. */
21
+ export function skillRef(name) {
22
+ return `Skill(${name})`;
23
+ }
24
+ /** Dedupe a list preserving the first-seen order. */
25
+ function dedupe(list) {
26
+ const seen = new Set();
27
+ const out = [];
28
+ for (const item of list) {
29
+ if (!seen.has(item)) {
30
+ seen.add(item);
31
+ out.push(item);
32
+ }
33
+ }
34
+ return out;
35
+ }
36
+ const EMPTY_SETTINGS = { permissions: { allow: [], deny: [] } };
37
+ /**
38
+ * Read the existing `.claude/settings.local.json` (returns empty settings
39
+ * if the file does not exist). On parse failure returns empty settings
40
+ * and a warning rather than throwing — the user can still write fresh
41
+ * settings.
42
+ */
43
+ async function readSettingsLocal(projectRoot) {
44
+ const file = join(projectRoot, '.claude', 'settings.local.json');
45
+ if (!existsSync(file))
46
+ return { settings: EMPTY_SETTINGS, existed: false, malformed: false };
47
+ try {
48
+ const raw = await readFile(file, 'utf8');
49
+ const parsed = JSON.parse(raw);
50
+ if (parsed === null || typeof parsed !== 'object') {
51
+ return { settings: EMPTY_SETTINGS, existed: true, malformed: true };
52
+ }
53
+ const obj = parsed;
54
+ const permsRaw = obj.permissions;
55
+ const perms = permsRaw !== null && typeof permsRaw === 'object'
56
+ ? {
57
+ allow: Array.isArray(permsRaw.allow)
58
+ ? permsRaw.allow
59
+ : [],
60
+ deny: Array.isArray(permsRaw.deny)
61
+ ? permsRaw.deny
62
+ : [],
63
+ }
64
+ : { allow: [], deny: [] };
65
+ return { settings: { ...obj, permissions: perms }, existed: true, malformed: false };
66
+ }
67
+ catch {
68
+ return { settings: EMPTY_SETTINGS, existed: true, malformed: true };
69
+ }
70
+ }
71
+ /**
72
+ * Write the JSON file atomically via `.peaks-tmp` + `rename`. Removes the
73
+ * temp file on partial failure.
74
+ */
75
+ async function writeJsonAtomic(file, data) {
76
+ await mkdir(dirname(file), { recursive: true });
77
+ const tmp = `${file}.peaks-tmp`;
78
+ try {
79
+ await writeFile(tmp, JSON.stringify(data, null, 2) + '\n', 'utf8');
80
+ await rename(tmp, file);
81
+ }
82
+ catch (error) {
83
+ if (existsSync(tmp)) {
84
+ try {
85
+ await rm(tmp, { force: true });
86
+ }
87
+ catch { /* best-effort */ }
88
+ }
89
+ throw error;
90
+ }
91
+ }
92
+ /**
93
+ * Map allowlist/denylist → permissions.allow/permissions.deny. Never sorts;
94
+ * preserves input order. Always dedupes.
95
+ */
96
+ export function toPermissions(allowlist, denylist) {
97
+ return {
98
+ permissions: {
99
+ allow: dedupe(allowlist.map(skillRef)),
100
+ deny: dedupe(denylist.map(skillRef)),
101
+ },
102
+ };
103
+ }
104
+ /**
105
+ * Strip any peaks-* name from the denylist (G6 hard constraint). Returns
106
+ * the cleaned denylist + the list of stripped names for the audit log.
107
+ */
108
+ export function stripPeaksFromDenylist(denylist) {
109
+ const cleaned = [];
110
+ const stripped = [];
111
+ for (const name of denylist) {
112
+ if (name.startsWith('peaks-')) {
113
+ stripped.push(name);
114
+ }
115
+ else {
116
+ cleaned.push(name);
117
+ }
118
+ }
119
+ return { cleaned, stripped };
120
+ }
121
+ /** Render the shadow-stub SKILL.md body (R6 marker). */
122
+ function shadowStubBody(name) {
123
+ return `---
124
+ name: ${name}
125
+ description: _peaks_scope_disabled
126
+ _peaks_scope_disabled: true
127
+ ---
128
+ # Disabled by \`peaks skill scope --apply\`
129
+
130
+ This skill is shadowed because the project has marked it as out of scope.
131
+ To restore, run \`peaks skill scope --reset\` or edit \`.peaks/scope/skills.json\`.
132
+ `;
133
+ }
134
+ async function writeShadowStub(projectRoot, name) {
135
+ const file = join(projectRoot, '.claude', 'skills', name, 'SKILL.md');
136
+ await mkdir(dirname(file), { recursive: true });
137
+ // Skip if already has the marker
138
+ if (existsSync(file)) {
139
+ try {
140
+ const existing = await readFile(file, 'utf8');
141
+ if (existing.includes('_peaks_scope_disabled: true')) {
142
+ return file;
143
+ }
144
+ }
145
+ catch { /* fall through and overwrite */ }
146
+ }
147
+ await writeFile(file, shadowStubBody(name), 'utf8');
148
+ return file;
149
+ }
150
+ /**
151
+ * Runtime probe for whether Claude Code supports `Skill(name)` syntax in
152
+ * `permissions.deny` (R1). For slice 025.1 we return `unknown` and let
153
+ * the caller decide. Replace this with a real check when Claude Code's
154
+ * `permissions.deny` schema is documented.
155
+ */
156
+ export async function probeSkillDenySupport() {
157
+ return 'unknown';
158
+ }
159
+ /**
160
+ * Decision: should the denylist use shadow stubs instead of `permissions.deny`?
161
+ * Returns true when:
162
+ * - The caller passes `shadowFallback: true`, OR
163
+ * - The runtime probe returns `support-allow-only` / `unknown`.
164
+ */
165
+ async function shouldUseShadowStubs(input) {
166
+ if (input.shadowFallback)
167
+ return true;
168
+ const probe = await probeSkillDenySupport();
169
+ return probe !== 'support-allow-and-deny';
170
+ }
171
+ /** Strip the peaks-* shadow stubs written by a previous apply. */
172
+ function shadowStubDir(projectRoot, name) {
173
+ return join(projectRoot, '.claude', 'skills', name, 'SKILL.md');
174
+ }
175
+ async function removeShadowStubIfPresent(projectRoot, name) {
176
+ const file = shadowStubDir(projectRoot, name);
177
+ if (!existsSync(file))
178
+ return false;
179
+ try {
180
+ const raw = await readFile(file, 'utf8');
181
+ if (!raw.includes('_peaks_scope_disabled: true'))
182
+ return false;
183
+ await rm(file, { force: true });
184
+ return true;
185
+ }
186
+ catch {
187
+ return false;
188
+ }
189
+ }
190
+ export class ClaudeCodeSkillScope {
191
+ ide = IDE_ID;
192
+ supported = true;
193
+ constructor(_opts) {
194
+ // projectRoot is supplied on every method call; the class is stateless.
195
+ void _opts;
196
+ }
197
+ /** detect(): returns 1.0 when the project root has a .claude/ dir. */
198
+ async detect(projectRoot) {
199
+ return existsSync(join(projectRoot, '.claude')) ? 1.0 : 0.5;
200
+ }
201
+ async applyScope(input) {
202
+ const written = [];
203
+ const removed = [];
204
+ // G6: strip peaks-* from the denylist.
205
+ const { cleaned: cleanedDeny, stripped } = stripPeaksFromDenylist(input.denylist);
206
+ if (stripped.length > 0) {
207
+ removed.push(...stripped);
208
+ }
209
+ const useShadows = await shouldUseShadowStubs(input);
210
+ // 1. Write (or skip) settings.local.json
211
+ const { settings: existing } = await readSettingsLocal(input.projectRoot);
212
+ const next = toPermissions(input.allowlist, cleanedDeny);
213
+ // Preserve existing non-permissions fields (theme, env, etc.).
214
+ const preserved = { ...existing };
215
+ delete preserved.permissions;
216
+ // Merge with the user's pre-existing allow/deny entries (deduped).
217
+ const existingAllow = (existing.permissions.allow ?? []);
218
+ const existingDeny = (existing.permissions.deny ?? []);
219
+ const merged = {
220
+ ...preserved,
221
+ permissions: {
222
+ allow: dedupe([...existingAllow, ...next.permissions.allow]),
223
+ deny: dedupe([...existingDeny, ...next.permissions.deny]),
224
+ },
225
+ };
226
+ if (input.simulateWriteFailure) {
227
+ throw new Error('simulated write failure (settings.local.json)');
228
+ }
229
+ const settingsFile = join(input.projectRoot, '.claude', 'settings.local.json');
230
+ await writeJsonAtomic(settingsFile, merged);
231
+ written.push(settingsFile);
232
+ // 2. Optionally write shadow stubs for the (stripped, cleaned) denylist
233
+ let usedShadowStub = false;
234
+ if (useShadows) {
235
+ usedShadowStub = true;
236
+ for (const name of cleanedDeny) {
237
+ const stub = await writeShadowStub(input.projectRoot, name);
238
+ written.push(stub);
239
+ }
240
+ }
241
+ return {
242
+ ide: this.ide,
243
+ ok: true,
244
+ writtenFiles: written,
245
+ usedShadowStub,
246
+ notSupported: false,
247
+ strippedFromDenylist: stripped,
248
+ };
249
+ }
250
+ async showScope(projectRoot) {
251
+ const settingsFile = join(projectRoot, '.claude', 'settings.local.json');
252
+ let native = null;
253
+ if (existsSync(settingsFile)) {
254
+ try {
255
+ native = JSON.parse(await readFile(settingsFile, 'utf8'));
256
+ }
257
+ catch {
258
+ native = null;
259
+ }
260
+ }
261
+ return { source: null, native, ide: this.ide };
262
+ }
263
+ async resetScope(input) {
264
+ const removed = [];
265
+ const settingsFile = join(input.projectRoot, '.claude', 'settings.local.json');
266
+ if (existsSync(settingsFile)) {
267
+ // Only remove if it has a permissions.allow/deny field shaped by us,
268
+ // otherwise leave the user's hand-curated file alone.
269
+ try {
270
+ const raw = await readFile(settingsFile, 'utf8');
271
+ const parsed = JSON.parse(raw);
272
+ if (parsed !== null &&
273
+ typeof parsed === 'object' &&
274
+ parsed.permissions !== undefined) {
275
+ await rm(settingsFile, { force: true });
276
+ removed.push(settingsFile);
277
+ }
278
+ }
279
+ catch {
280
+ // best-effort
281
+ }
282
+ }
283
+ // Also remove shadow stubs (we don't know which skills are stubbed, so
284
+ // we don't blindly walk .claude/skills; the caller can re-run detect +
285
+ // reset if they need a full sweep). For the explicit case we know
286
+ // about, we strip any stub whose marker is present.
287
+ const skillsDir = join(input.projectRoot, '.claude', 'skills');
288
+ if (existsSync(skillsDir)) {
289
+ // Best-effort scan: only act when the file is unmistakably a stub.
290
+ const { readdirSync } = await import('node:fs');
291
+ const entries = readdirSync(skillsDir, { withFileTypes: true });
292
+ for (const entry of entries) {
293
+ if (!entry.isDirectory())
294
+ continue;
295
+ const removedStub = await removeShadowStubIfPresent(input.projectRoot, entry.name);
296
+ if (removedStub) {
297
+ removed.push(join(input.projectRoot, '.claude', 'skills', entry.name, 'SKILL.md'));
298
+ }
299
+ }
300
+ }
301
+ return { ide: this.ide, removedFiles: removed };
302
+ }
303
+ }
304
+ export const CLAUDE_CODE_SKILL_SCOPE = new ClaudeCodeSkillScope();
@@ -0,0 +1,2 @@
1
+ import type { SkillScopeAdapter } from '../types.js';
2
+ export declare const CODEX_SKILL_SCOPE: SkillScopeAdapter;
@@ -0,0 +1,12 @@
1
+ // TODO(slice-025.4-codex): research Codex's per-project skill scoping
2
+ // config format. Codex uses `.codex/` for project-local config.
3
+ //
4
+ // Until the real format is known, this stub:
5
+ // 1. Writes `.peaks/scope/codex-skills.json` (source-of-truth) on every
6
+ // `applyScope` so the user's intent is captured on disk.
7
+ // 2. Returns NOT_SUPPORTED with a clear message pointing at this slice.
8
+ //
9
+ // When implementing, replace the makeStubAdapter call with the real
10
+ // CodexSkillScope class.
11
+ import { makeStubAdapter } from './_stub-helper.js';
12
+ export const CODEX_SKILL_SCOPE = makeStubAdapter('codex', 'slice-025.4-codex', 'Codex');
@@ -0,0 +1,2 @@
1
+ import type { SkillScopeAdapter } from '../types.js';
2
+ export declare const CURSOR_SKILL_SCOPE: SkillScopeAdapter;