peaks-cli 1.3.8 → 1.3.9
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/dist/src/cli/commands/project-commands.js +58 -1
- package/dist/src/cli/commands/request-commands.js +93 -3
- package/dist/src/cli/commands/retrospective-commands.d.ts +3 -0
- package/dist/src/cli/commands/retrospective-commands.js +113 -0
- package/dist/src/cli/program.js +2 -0
- package/dist/src/services/memory/project-memory-service.d.ts +19 -0
- package/dist/src/services/memory/project-memory-service.js +33 -0
- package/dist/src/services/retrospective/migrate-from-md.d.ts +37 -0
- package/dist/src/services/retrospective/migrate-from-md.js +528 -0
- package/dist/src/services/retrospective/retrospective-index.d.ts +37 -0
- package/dist/src/services/retrospective/retrospective-index.js +110 -0
- package/dist/src/services/retrospective/retrospective-show.d.ts +40 -0
- package/dist/src/services/retrospective/retrospective-show.js +109 -0
- package/dist/src/shared/format-md-compact.d.ts +32 -0
- package/dist/src/shared/format-md-compact.js +297 -0
- package/dist/src/shared/stale-policy.d.ts +67 -0
- package/dist/src/shared/stale-policy.js +85 -0
- package/dist/src/shared/version.d.ts +1 -1
- package/dist/src/shared/version.js +1 -1
- package/package.json +1 -1
- package/skills/peaks-qa/SKILL.md +86 -515
- package/skills/peaks-qa/references/artifact-per-request.md +7 -79
- package/skills/peaks-qa/references/browser-validation-contracts.md +51 -0
- package/skills/peaks-qa/references/codegraph-regression-focus.md +5 -0
- package/skills/peaks-qa/references/external-capability-guidance.md +9 -0
- package/skills/peaks-qa/references/qa-compact-handoff.md +3 -0
- package/skills/peaks-qa/references/qa-context-governance.md +24 -0
- package/skills/peaks-qa/references/qa-fanout-contract.md +8 -0
- package/skills/peaks-qa/references/qa-gstack-integration.md +7 -0
- package/skills/peaks-qa/references/qa-local-artifacts.md +3 -0
- package/skills/peaks-qa/references/qa-matt-pocock-integration.md +9 -0
- package/skills/peaks-qa/references/qa-refactor-role.md +3 -0
- package/skills/peaks-qa/references/qa-runbook.md +74 -0
- package/skills/peaks-qa/references/qa-skill-presence.md +22 -0
- package/skills/peaks-qa/references/qa-standards-preflight.md +8 -0
- package/skills/peaks-qa/references/qa-sub-agent-dispatch.md +38 -0
- package/skills/peaks-qa/references/qa-transition-gates.md +79 -0
- package/skills/peaks-qa/references/requirement-boundary-recheck.md +9 -0
- package/skills/peaks-qa/references/test-case-generation.md +27 -0
- package/skills/peaks-qa/references/test-report-output.md +14 -0
- package/skills/peaks-rd/SKILL.md +85 -612
- package/skills/peaks-rd/references/artifact-and-standards-output.md +9 -0
- package/skills/peaks-rd/references/artifact-per-request.md +20 -0
- package/skills/peaks-rd/references/browser-self-test-contracts.md +29 -0
- package/skills/peaks-rd/references/codegraph-project-analysis.md +5 -0
- package/skills/peaks-rd/references/compact-handoff.md +3 -0
- package/skills/peaks-rd/references/external-references.md +11 -0
- package/skills/peaks-rd/references/frontend-project-generation.md +11 -0
- package/skills/peaks-rd/references/library-version-awareness.md +30 -0
- package/skills/peaks-rd/references/mandatory-perf-baseline.md +40 -0
- package/skills/peaks-rd/references/mandatory-tech-doc.md +18 -0
- package/skills/peaks-rd/references/matt-pocock-integration.md +11 -0
- package/skills/peaks-rd/references/mock-data-placement.md +40 -0
- package/skills/peaks-rd/references/parallel-review-fanout.md +81 -0
- package/skills/peaks-rd/references/rd-context-governance.md +36 -0
- package/skills/peaks-rd/references/rd-gstack-integration.md +16 -0
- package/skills/peaks-rd/references/rd-runbook.md +125 -0
- package/skills/peaks-rd/references/rd-standards-preflight.md +8 -0
- package/skills/peaks-rd/references/rd-sub-agent-dispatch.md +39 -0
- package/skills/peaks-rd/references/rd-transition-gates.md +1 -1
- package/skills/peaks-rd/references/skill-presence-and-title.md +22 -0
- package/skills/peaks-solo/SKILL.md +87 -595
- package/skills/peaks-solo/references/anchoring-and-session-info.md +25 -0
- package/skills/peaks-solo/references/boundaries.md +21 -0
- package/skills/peaks-solo/references/codegraph-orchestration.md +5 -0
- package/skills/peaks-solo/references/completion-handoff.md +16 -0
- package/skills/peaks-solo/references/context-governance.md +51 -0
- package/skills/peaks-solo/references/external-references.md +17 -0
- package/skills/peaks-solo/references/frontend-only-mode.md +14 -0
- package/skills/peaks-solo/references/gstack-integration.md +7 -0
- package/skills/peaks-solo/references/local-artifact-workspace.md +79 -0
- package/skills/peaks-solo/references/micro-cycle.md +68 -0
- package/skills/peaks-solo/references/mode-selection.md +21 -0
- package/skills/peaks-solo/references/openspec-workflow.md +43 -0
- package/skills/peaks-solo/references/project-memory-loading.md +17 -0
- package/skills/peaks-solo/references/quality-gate-cheatsheet.md +13 -0
- package/skills/peaks-solo/references/resume-detection.md +63 -0
- package/skills/peaks-solo/references/runbook.md +1 -1
- package/skills/peaks-solo/references/skill-presence-and-title.md +31 -0
- package/skills/peaks-solo/references/standards-preflight.md +23 -0
- package/skills/peaks-solo/references/sub-agent-dispatch.md +46 -0
- 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,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* format-md-compact — single source of truth for whitespace / decoration
|
|
3
|
+
* normalization across every CLI body-output path.
|
|
4
|
+
*
|
|
5
|
+
* Slice 023 (R3) — `peaks project memories:show`, `peaks retrospective show`,
|
|
6
|
+
* and `peaks request show` (per-artifact) all funnel their `body` field through
|
|
7
|
+
* this helper so the LLM-consumed output is free of blank-line padding,
|
|
8
|
+
* decorative `---` rules, and frontmatter `description:` field-name repeats
|
|
9
|
+
* while preserving every semantically meaningful construct (code fences,
|
|
10
|
+
* setext heading underlines, GFM table syntax, frontmatter, list indentation,
|
|
11
|
+
* inline emphasis, code spans).
|
|
12
|
+
*
|
|
13
|
+
* Pure function: no fs, no I/O. Easy to unit-test (see
|
|
14
|
+
* `tests/unit/shared/format-md-compact.test.ts`).
|
|
15
|
+
*/
|
|
16
|
+
export interface FormatMdCompactOptions {
|
|
17
|
+
/** Preserve code-fence (``` ... ```) and frontmatter (--- ... ---) content. Default true. */
|
|
18
|
+
preserveCodeBlocks?: boolean;
|
|
19
|
+
/** Preserve setext heading underlines (===, --- under a text line). Default true. */
|
|
20
|
+
preserveSetextHeadings?: boolean;
|
|
21
|
+
/** Preserve GFM table syntax (| ... | rows). Default true. */
|
|
22
|
+
preserveTables?: boolean;
|
|
23
|
+
/** Collapse 3+ blank lines to 1. Default true. */
|
|
24
|
+
collapseBlankLines?: boolean;
|
|
25
|
+
/** Strip trailing whitespace per line. Default true. */
|
|
26
|
+
stripTrailingWhitespace?: boolean;
|
|
27
|
+
/** Strip decorative `---` lines (lines surrounded by blanks OR trailing final line). Default true. */
|
|
28
|
+
stripDecorativeHorizontalRules?: boolean;
|
|
29
|
+
/** Strip frontmatter `description:` field-name repeat when same value already in body header. Default true. */
|
|
30
|
+
stripFrontmatterDescriptionRepeat?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function formatMdCompact(input: string, options?: FormatMdCompactOptions): string;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* format-md-compact — single source of truth for whitespace / decoration
|
|
3
|
+
* normalization across every CLI body-output path.
|
|
4
|
+
*
|
|
5
|
+
* Slice 023 (R3) — `peaks project memories:show`, `peaks retrospective show`,
|
|
6
|
+
* and `peaks request show` (per-artifact) all funnel their `body` field through
|
|
7
|
+
* this helper so the LLM-consumed output is free of blank-line padding,
|
|
8
|
+
* decorative `---` rules, and frontmatter `description:` field-name repeats
|
|
9
|
+
* while preserving every semantically meaningful construct (code fences,
|
|
10
|
+
* setext heading underlines, GFM table syntax, frontmatter, list indentation,
|
|
11
|
+
* inline emphasis, code spans).
|
|
12
|
+
*
|
|
13
|
+
* Pure function: no fs, no I/O. Easy to unit-test (see
|
|
14
|
+
* `tests/unit/shared/format-md-compact.test.ts`).
|
|
15
|
+
*/
|
|
16
|
+
const FENCE_TRIPLE_BACKTICK = '```';
|
|
17
|
+
const FENCE_TRIPLE_TILDE = '~~~';
|
|
18
|
+
const FENCE_MARKER_RE = /^(```+|~~~+)/;
|
|
19
|
+
const TABLE_ROW_RE = /^\s*\|.*\|\s*$/;
|
|
20
|
+
const TABLE_ALIGN_ROW_RE = /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)+\|?\s*$/;
|
|
21
|
+
const ATX_HEADING_RE = /^#{1,6}\s/;
|
|
22
|
+
const HEADING_LINE_RE = /^\S/;
|
|
23
|
+
const SETEXT_UNDERLINE_RE = /^=+\s*$|^-{2,}\s*$/;
|
|
24
|
+
export function formatMdCompact(input, options = {}) {
|
|
25
|
+
if (input.length === 0)
|
|
26
|
+
return input;
|
|
27
|
+
const opts = {
|
|
28
|
+
preserveCodeBlocks: options.preserveCodeBlocks ?? true,
|
|
29
|
+
preserveSetextHeadings: options.preserveSetextHeadings ?? true,
|
|
30
|
+
preserveTables: options.preserveTables ?? true,
|
|
31
|
+
collapseBlankLines: options.collapseBlankLines ?? true,
|
|
32
|
+
stripTrailingWhitespace: options.stripTrailingWhitespace ?? true,
|
|
33
|
+
stripDecorativeHorizontalRules: options.stripDecorativeHorizontalRules ?? true,
|
|
34
|
+
stripFrontmatterDescriptionRepeat: options.stripFrontmatterDescriptionRepeat ?? true
|
|
35
|
+
};
|
|
36
|
+
// 1. Split frontmatter from body (if any). The YAML block lives between
|
|
37
|
+
// the first line `---` and the second line `---`. We carry it through
|
|
38
|
+
// unchanged.
|
|
39
|
+
const fm = splitFrontmatter(input);
|
|
40
|
+
const body = fm.body;
|
|
41
|
+
// 2. Walk the body line-by-line, applying the protected-zone rules.
|
|
42
|
+
const normalizedBody = normalizeBody(body, opts);
|
|
43
|
+
// 3. Optional frontmatter `description:` repeat strip. The body's
|
|
44
|
+
// first ATX heading is compared to the frontmatter `description:`
|
|
45
|
+
// value; if the description text repeats the heading, the leading
|
|
46
|
+
// paragraph is dropped. Implemented as a one-shot post-pass.
|
|
47
|
+
const finalBody = opts.stripFrontmatterDescriptionRepeat
|
|
48
|
+
? stripDescriptionRepeat(normalizedBody, fm.description)
|
|
49
|
+
: normalizedBody;
|
|
50
|
+
// 4. Re-assemble. The frontmatter stays verbatim; the body carries the
|
|
51
|
+
// normalized text. Match the original layout: if the input had
|
|
52
|
+
// frontmatter, output is `frontmatter + blank + body`; otherwise
|
|
53
|
+
// the body is the whole output.
|
|
54
|
+
if (fm.raw === '') {
|
|
55
|
+
return finalBody;
|
|
56
|
+
}
|
|
57
|
+
return fm.raw + '\n' + finalBody;
|
|
58
|
+
}
|
|
59
|
+
function splitFrontmatter(input) {
|
|
60
|
+
// Normalize line endings so Windows \r\n doesn't confuse the leading-marker check.
|
|
61
|
+
const normalized = input.replace(/\r\n/g, '\n');
|
|
62
|
+
const lines = normalized.split('\n');
|
|
63
|
+
if (lines[0] !== '---') {
|
|
64
|
+
return { raw: '', description: null, body: normalized };
|
|
65
|
+
}
|
|
66
|
+
let closeIndex = -1;
|
|
67
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
68
|
+
if (lines[index] === '---') {
|
|
69
|
+
closeIndex = index;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (closeIndex < 0) {
|
|
74
|
+
return { raw: '', description: null, body: normalized };
|
|
75
|
+
}
|
|
76
|
+
const raw = lines.slice(0, closeIndex + 1).join('\n');
|
|
77
|
+
// Body = everything after the closing `---` (preserving one optional blank line).
|
|
78
|
+
const bodyLines = lines.slice(closeIndex + 1);
|
|
79
|
+
while (bodyLines.length > 0 && bodyLines[0] === '') {
|
|
80
|
+
bodyLines.shift();
|
|
81
|
+
}
|
|
82
|
+
const body = bodyLines.join('\n');
|
|
83
|
+
// Extract the `description:` field. Walk the YAML block; pull the value
|
|
84
|
+
// as a single-line string. Multi-line (`|`) or folded (`>`) scalars are
|
|
85
|
+
// joined with a single space — the description is a short summary, the
|
|
86
|
+
// exact whitespace inside the block scalar is not preserved.
|
|
87
|
+
const frontmatterLines = lines.slice(1, closeIndex);
|
|
88
|
+
const description = extractFrontmatterDescription(frontmatterLines);
|
|
89
|
+
return { raw, description, body };
|
|
90
|
+
}
|
|
91
|
+
function extractFrontmatterDescription(frontmatterLines) {
|
|
92
|
+
for (let index = 0; index < frontmatterLines.length; index += 1) {
|
|
93
|
+
const line = frontmatterLines[index] ?? '';
|
|
94
|
+
const match = line.match(/^description:\s*(.*)$/);
|
|
95
|
+
if (match === null)
|
|
96
|
+
continue;
|
|
97
|
+
const inline = (match[1] ?? '').trim();
|
|
98
|
+
if (inline === '|' || inline === '>') {
|
|
99
|
+
const collected = [];
|
|
100
|
+
for (let inner = index + 1; inner < frontmatterLines.length; inner += 1) {
|
|
101
|
+
const innerLine = frontmatterLines[inner] ?? '';
|
|
102
|
+
if (/^[A-Za-z0-9_-]+:/.test(innerLine))
|
|
103
|
+
break;
|
|
104
|
+
collected.push(innerLine.replace(/^\s{2}/, ''));
|
|
105
|
+
}
|
|
106
|
+
return collected.join(' ').trim();
|
|
107
|
+
}
|
|
108
|
+
// Strip surrounding quotes if the value is a quoted scalar.
|
|
109
|
+
return inline.replace(/^['"]|['"]$/g, '');
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
function normalizeBody(body, opts) {
|
|
114
|
+
// Walk line-by-line, tracking the protected-zone flags and emitting a
|
|
115
|
+
// transformed line stream. We keep three flag bits:
|
|
116
|
+
// insideFence: toggled on ``` / ~~~ lines
|
|
117
|
+
// insideFrontmatterYAML: handled by splitFrontmatter; body has none.
|
|
118
|
+
// insideTable: detected by leading-pipe; carried until first non-pipe
|
|
119
|
+
// line.
|
|
120
|
+
const lines = body.split('\n');
|
|
121
|
+
// 1. Pre-pass: compute the `setextUnderlined` markers so the decorative
|
|
122
|
+
// `---` strip can know when a line is a setext H2 underline (semantic)
|
|
123
|
+
// vs a decoration.
|
|
124
|
+
const setextUnderlined = computeSetextUnderlines(lines);
|
|
125
|
+
const protection = [];
|
|
126
|
+
let insideFence = false;
|
|
127
|
+
let insideTable = false;
|
|
128
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
129
|
+
const line = lines[index] ?? '';
|
|
130
|
+
if (opts.preserveCodeBlocks && isFenceOpenLine(line) && !isFenceCloseLine(line, insideFence)) {
|
|
131
|
+
insideFence = !insideFence;
|
|
132
|
+
protection.push('fence');
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (insideFence) {
|
|
136
|
+
protection.push('fence');
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (opts.preserveSetextHeadings && setextUnderlined.has(index)) {
|
|
140
|
+
protection.push('setext');
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (opts.preserveTables && isTableLine(line)) {
|
|
144
|
+
// Entering / continuing a table — first row that looks like a table
|
|
145
|
+
// starts the table zone; the alignment row (|---|) is included.
|
|
146
|
+
insideTable = true;
|
|
147
|
+
protection.push('table');
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (insideTable && !isTableLine(line) && line.trim() !== '') {
|
|
151
|
+
insideTable = false;
|
|
152
|
+
}
|
|
153
|
+
if (insideTable) {
|
|
154
|
+
protection.push('table');
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
protection.push('plain');
|
|
158
|
+
}
|
|
159
|
+
// 3. Per-line transforms: strip trailing whitespace outside protected
|
|
160
|
+
// zones; strip decorative `---` outside setext / table / fence zones.
|
|
161
|
+
const out = [];
|
|
162
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
163
|
+
const line = lines[index] ?? '';
|
|
164
|
+
const zone = protection[index] ?? 'plain';
|
|
165
|
+
let transformed = line;
|
|
166
|
+
if (zone !== 'fence' && opts.stripTrailingWhitespace) {
|
|
167
|
+
transformed = transformed.replace(/[ \t]+$/u, '');
|
|
168
|
+
}
|
|
169
|
+
if (zone !== 'fence' &&
|
|
170
|
+
zone !== 'setext' &&
|
|
171
|
+
zone !== 'table' &&
|
|
172
|
+
opts.stripDecorativeHorizontalRules) {
|
|
173
|
+
if (isDecorativeHorizontalRule(transformed)) {
|
|
174
|
+
// Mark for removal: push a sentinel. The blank-line collapse step
|
|
175
|
+
// will merge surrounding blanks.
|
|
176
|
+
transformed = '__PEAKS_HR_REMOVED__';
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
out.push(transformed);
|
|
180
|
+
}
|
|
181
|
+
// 4. Drop the sentinel lines (decorative `---` after classification).
|
|
182
|
+
let collapsed = out.filter((line) => line !== '__PEAKS_HR_REMOVED__');
|
|
183
|
+
// 5. Collapse 3+ consecutive blank lines into 1. Two blank lines
|
|
184
|
+
// between two non-blank lines are also collapsed to 1 (matches PRD
|
|
185
|
+
// R2's "decorative `---` is redundant" rule — the original visual
|
|
186
|
+
// gap that surrounded the `---` collapses with it).
|
|
187
|
+
if (opts.collapseBlankLines) {
|
|
188
|
+
collapsed = collapseMultiBlanks(collapsed);
|
|
189
|
+
}
|
|
190
|
+
return collapsed.join('\n');
|
|
191
|
+
}
|
|
192
|
+
function isFenceOpenLine(line) {
|
|
193
|
+
return FENCE_MARKER_RE.test(line);
|
|
194
|
+
}
|
|
195
|
+
function isFenceCloseLine(line, insideFence) {
|
|
196
|
+
// The `isFenceOpenLine` already returned true for this line, so it
|
|
197
|
+
// starts with ``` or ~~~. A "close" line is one that opens a new fence
|
|
198
|
+
// of the *same* length. We approximate by treating any opener as a close
|
|
199
|
+
// when we are currently inside a fence.
|
|
200
|
+
return insideFence;
|
|
201
|
+
}
|
|
202
|
+
function isTableLine(line) {
|
|
203
|
+
return TABLE_ROW_RE.test(line) || TABLE_ALIGN_ROW_RE.test(line);
|
|
204
|
+
}
|
|
205
|
+
function computeSetextUnderlines(lines) {
|
|
206
|
+
// A `===` or `---` line is a setext heading underline ONLY when it sits
|
|
207
|
+
// directly under a non-blank, non-ATX text line (no blank line between
|
|
208
|
+
// them). The presence of a blank line between the text and the rule
|
|
209
|
+
// disqualifies it (a blank-separated `---` is decoration, not setext).
|
|
210
|
+
const result = new Set();
|
|
211
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
212
|
+
const line = lines[index] ?? '';
|
|
213
|
+
if (!SETEXT_UNDERLINE_RE.test(line))
|
|
214
|
+
continue;
|
|
215
|
+
const prev = lines[index - 1] ?? '';
|
|
216
|
+
if (prev === '')
|
|
217
|
+
continue;
|
|
218
|
+
if (ATX_HEADING_RE.test(prev))
|
|
219
|
+
continue;
|
|
220
|
+
if (!HEADING_LINE_RE.test(prev))
|
|
221
|
+
continue;
|
|
222
|
+
result.add(index);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
function isDecorativeHorizontalRule(line) {
|
|
227
|
+
// A line that is exactly `---` (or any number of `-` chars) is a
|
|
228
|
+
// candidate horizontal rule. The caller has already excluded setext
|
|
229
|
+
// and table contexts via the `protection` array.
|
|
230
|
+
return /^-+$/.test(line);
|
|
231
|
+
}
|
|
232
|
+
function collapseMultiBlanks(lines) {
|
|
233
|
+
const result = [];
|
|
234
|
+
let blankRun = 0;
|
|
235
|
+
for (const line of lines) {
|
|
236
|
+
if (line === '') {
|
|
237
|
+
blankRun += 1;
|
|
238
|
+
// 1 blank line is the cap. Drop the rest.
|
|
239
|
+
if (blankRun <= 1) {
|
|
240
|
+
result.push(line);
|
|
241
|
+
}
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
blankRun = 0;
|
|
245
|
+
result.push(line);
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
function stripDescriptionRepeat(body, description) {
|
|
250
|
+
if (description === null || description.length === 0)
|
|
251
|
+
return body;
|
|
252
|
+
// Find the first ATX heading line. If it equals the frontmatter
|
|
253
|
+
// description text, drop it. Also drop a description-matching paragraph
|
|
254
|
+
// that immediately follows the heading (PRD's "frontmatter description
|
|
255
|
+
// already in body header" case). All other content is preserved.
|
|
256
|
+
const lines = body.split('\n');
|
|
257
|
+
if (lines.length === 0)
|
|
258
|
+
return body;
|
|
259
|
+
let firstHeadingIndex = -1;
|
|
260
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
261
|
+
const line = lines[index] ?? '';
|
|
262
|
+
if (line.trim() === '')
|
|
263
|
+
continue;
|
|
264
|
+
if (ATX_HEADING_RE.test(line)) {
|
|
265
|
+
firstHeadingIndex = index;
|
|
266
|
+
}
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
if (firstHeadingIndex < 0)
|
|
270
|
+
return body;
|
|
271
|
+
const headingText = (lines[firstHeadingIndex] ?? '').replace(/^#{1,6}\s+/, '').trim();
|
|
272
|
+
if (headingText !== description)
|
|
273
|
+
return body;
|
|
274
|
+
// Walk past the heading, then past any blank lines, then past the
|
|
275
|
+
// matching description paragraph (if present). Anything after the
|
|
276
|
+
// description paragraph is the body we want to keep.
|
|
277
|
+
const tail = lines.slice(firstHeadingIndex + 1);
|
|
278
|
+
let cursor = 0;
|
|
279
|
+
// Skip blanks.
|
|
280
|
+
while (cursor < tail.length && (tail[cursor] ?? '') === '') {
|
|
281
|
+
cursor += 1;
|
|
282
|
+
}
|
|
283
|
+
// Read the first non-blank paragraph.
|
|
284
|
+
const paragraphStart = cursor;
|
|
285
|
+
while (cursor < tail.length && (tail[cursor] ?? '') !== '') {
|
|
286
|
+
cursor += 1;
|
|
287
|
+
}
|
|
288
|
+
const paragraph = tail.slice(paragraphStart, cursor);
|
|
289
|
+
if (paragraph.join(' ').trim() !== description) {
|
|
290
|
+
// The paragraph doesn't match the description — don't drop it.
|
|
291
|
+
cursor = paragraphStart;
|
|
292
|
+
}
|
|
293
|
+
const kept = tail.slice(cursor);
|
|
294
|
+
if (kept.length === 0)
|
|
295
|
+
return '';
|
|
296
|
+
return kept.join('\n');
|
|
297
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stale-policy — pure helper for stale detection and filtering on memory
|
|
3
|
+
* and (future) retrospective entries.
|
|
4
|
+
*
|
|
5
|
+
* Slice 023 (R3) applies this to memory only (`peaks project memories:show`
|
|
6
|
+
* and the underlying `readMemoryIndex` load path). The retrospective index
|
|
7
|
+
* loader shares the same shape (`updatedAt: string`) and will be wired to
|
|
8
|
+
* the same helper in a future slice.
|
|
9
|
+
*
|
|
10
|
+
* Behavior:
|
|
11
|
+
* - `isStale(updatedAt)` returns true when (now - updatedAt) >
|
|
12
|
+
* thresholdDays * 86_400_000. Strict greater-than: a 30-day-old
|
|
13
|
+
* entry is NOT stale.
|
|
14
|
+
* - `applyStalePolicy(entries)` adds `stale: boolean` and
|
|
15
|
+
* `ageDays: number` to every entry (computed at CLI load time, never
|
|
16
|
+
* persisted to source `.md` files) and filters out entries where
|
|
17
|
+
* `stale === true` unless `includeStale: true` is passed.
|
|
18
|
+
* - Missing `updatedAt` is treated as fresh (`stale: false`,
|
|
19
|
+
* `ageDays: 0`); we never throw, so older index.json entries that
|
|
20
|
+
* lack the field stay loadable.
|
|
21
|
+
*/
|
|
22
|
+
export interface StalePolicyOptions {
|
|
23
|
+
/** Reference clock (ms since epoch). Defaults to Date.now(). Injected for testability. */
|
|
24
|
+
now?: number;
|
|
25
|
+
/** Threshold in days. Default 30. */
|
|
26
|
+
thresholdDays?: number;
|
|
27
|
+
/** When true, keep stale entries in the returned array (with `stale: true` set). Default false. */
|
|
28
|
+
includeStale?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface StaleAnnotated<T> {
|
|
31
|
+
stale: boolean;
|
|
32
|
+
ageDays: number;
|
|
33
|
+
}
|
|
34
|
+
export type StaleAnnotatedEntry<T> = T & StaleAnnotated<T>;
|
|
35
|
+
export interface StalePolicyResult<T> {
|
|
36
|
+
/** Filtered array, with stale entries removed (unless includeStale=true). */
|
|
37
|
+
entries: StaleAnnotatedEntry<T>[];
|
|
38
|
+
/** Count of entries dropped as stale. */
|
|
39
|
+
droppedCount: number;
|
|
40
|
+
/** Total count before filtering. */
|
|
41
|
+
totalCount: number;
|
|
42
|
+
}
|
|
43
|
+
export declare const DAY_MS = 86400000;
|
|
44
|
+
export declare const DEFAULT_STALE_DAYS = 30;
|
|
45
|
+
/**
|
|
46
|
+
* Returns true when the entry is older than `thresholdDays`. Strict
|
|
47
|
+
* greater-than: an entry exactly at the threshold is NOT stale.
|
|
48
|
+
*
|
|
49
|
+
* A missing or unparseable `updatedAt` is treated as fresh (false). This
|
|
50
|
+
* is the "defensive — older index.json entries may lack the field" rule
|
|
51
|
+
* from PRD R4.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isStale(updatedAt: string | undefined | null, options?: StalePolicyOptions): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Age in days between `updatedAt` and `now` (default Date.now()).
|
|
56
|
+
* Returns 0 for a missing / unparseable `updatedAt`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function ageInDays(updatedAt: string | undefined | null, now?: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* Apply the stale policy to a list of entries. Each entry is augmented
|
|
61
|
+
* with `stale: boolean` and `ageDays: number` (immutably — a fresh
|
|
62
|
+
* object is returned per entry). Stale entries are dropped from
|
|
63
|
+
* `entries` unless `includeStale: true` is passed.
|
|
64
|
+
*/
|
|
65
|
+
export declare function applyStalePolicy<T extends {
|
|
66
|
+
updatedAt?: string | null;
|
|
67
|
+
}>(entries: T[], options?: StalePolicyOptions): StalePolicyResult<T>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stale-policy — pure helper for stale detection and filtering on memory
|
|
3
|
+
* and (future) retrospective entries.
|
|
4
|
+
*
|
|
5
|
+
* Slice 023 (R3) applies this to memory only (`peaks project memories:show`
|
|
6
|
+
* and the underlying `readMemoryIndex` load path). The retrospective index
|
|
7
|
+
* loader shares the same shape (`updatedAt: string`) and will be wired to
|
|
8
|
+
* the same helper in a future slice.
|
|
9
|
+
*
|
|
10
|
+
* Behavior:
|
|
11
|
+
* - `isStale(updatedAt)` returns true when (now - updatedAt) >
|
|
12
|
+
* thresholdDays * 86_400_000. Strict greater-than: a 30-day-old
|
|
13
|
+
* entry is NOT stale.
|
|
14
|
+
* - `applyStalePolicy(entries)` adds `stale: boolean` and
|
|
15
|
+
* `ageDays: number` to every entry (computed at CLI load time, never
|
|
16
|
+
* persisted to source `.md` files) and filters out entries where
|
|
17
|
+
* `stale === true` unless `includeStale: true` is passed.
|
|
18
|
+
* - Missing `updatedAt` is treated as fresh (`stale: false`,
|
|
19
|
+
* `ageDays: 0`); we never throw, so older index.json entries that
|
|
20
|
+
* lack the field stay loadable.
|
|
21
|
+
*/
|
|
22
|
+
export const DAY_MS = 86_400_000;
|
|
23
|
+
export const DEFAULT_STALE_DAYS = 30;
|
|
24
|
+
/**
|
|
25
|
+
* Returns true when the entry is older than `thresholdDays`. Strict
|
|
26
|
+
* greater-than: an entry exactly at the threshold is NOT stale.
|
|
27
|
+
*
|
|
28
|
+
* A missing or unparseable `updatedAt` is treated as fresh (false). This
|
|
29
|
+
* is the "defensive — older index.json entries may lack the field" rule
|
|
30
|
+
* from PRD R4.
|
|
31
|
+
*/
|
|
32
|
+
export function isStale(updatedAt, options = {}) {
|
|
33
|
+
const parsed = parseUpdatedAt(updatedAt);
|
|
34
|
+
if (parsed === null)
|
|
35
|
+
return false;
|
|
36
|
+
const now = options.now ?? Date.now();
|
|
37
|
+
const thresholdDays = options.thresholdDays ?? DEFAULT_STALE_DAYS;
|
|
38
|
+
return now - parsed > thresholdDays * DAY_MS;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Age in days between `updatedAt` and `now` (default Date.now()).
|
|
42
|
+
* Returns 0 for a missing / unparseable `updatedAt`.
|
|
43
|
+
*/
|
|
44
|
+
export function ageInDays(updatedAt, now = Date.now()) {
|
|
45
|
+
const parsed = parseUpdatedAt(updatedAt);
|
|
46
|
+
if (parsed === null)
|
|
47
|
+
return 0;
|
|
48
|
+
return Math.max(0, Math.floor((now - parsed) / DAY_MS));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Apply the stale policy to a list of entries. Each entry is augmented
|
|
52
|
+
* with `stale: boolean` and `ageDays: number` (immutably — a fresh
|
|
53
|
+
* object is returned per entry). Stale entries are dropped from
|
|
54
|
+
* `entries` unless `includeStale: true` is passed.
|
|
55
|
+
*/
|
|
56
|
+
export function applyStalePolicy(entries, options = {}) {
|
|
57
|
+
const now = options.now ?? Date.now();
|
|
58
|
+
const thresholdDays = options.thresholdDays ?? DEFAULT_STALE_DAYS;
|
|
59
|
+
const includeStale = options.includeStale ?? false;
|
|
60
|
+
const annotated = entries.map((entry) => {
|
|
61
|
+
const parsed = parseUpdatedAt(entry.updatedAt ?? null);
|
|
62
|
+
if (parsed === null) {
|
|
63
|
+
return { ...entry, stale: false, ageDays: 0 };
|
|
64
|
+
}
|
|
65
|
+
const stale = now - parsed > thresholdDays * DAY_MS;
|
|
66
|
+
const ageDays = Math.max(0, Math.floor((now - parsed) / DAY_MS));
|
|
67
|
+
return { ...entry, stale, ageDays };
|
|
68
|
+
});
|
|
69
|
+
const filtered = includeStale
|
|
70
|
+
? annotated
|
|
71
|
+
: annotated.filter((entry) => !entry.stale);
|
|
72
|
+
return {
|
|
73
|
+
entries: filtered,
|
|
74
|
+
droppedCount: annotated.length - filtered.length,
|
|
75
|
+
totalCount: annotated.length
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function parseUpdatedAt(value) {
|
|
79
|
+
if (value === null || value === undefined || value === '')
|
|
80
|
+
return null;
|
|
81
|
+
const parsed = Date.parse(value);
|
|
82
|
+
if (Number.isNaN(parsed))
|
|
83
|
+
return null;
|
|
84
|
+
return parsed;
|
|
85
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLI_VERSION = "1.3.
|
|
1
|
+
export declare const CLI_VERSION = "1.3.9";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "1.3.
|
|
1
|
+
export const CLI_VERSION = "1.3.9";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peaks-cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"description": "Cross-AI-IDE workflow-gating CLI + skill family (Claude Code shipped, Trae in progress; Codex / Cursor / Qoder / Tongyi Lingma on the roadmap).",
|
|
5
5
|
"author": "SquabbyZ",
|
|
6
6
|
"license": "MIT",
|