peaks-loop-mut 0.1.53 → 0.1.56
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/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/services/agent/ecc-materialize.d.ts +24 -27
- package/dist/services/agent/ecc-materialize.d.ts.map +1 -1
- package/dist/services/agent/ecc-materialize.js +42 -77
- package/dist/services/agent/ecc-materialized-readers.d.ts +23 -5
- package/dist/services/agent/ecc-materialized-readers.d.ts.map +1 -1
- package/dist/services/agent/ecc-materialized-readers.js +80 -18
- package/dist/services/agent/ecc-package-service.d.ts +38 -0
- package/dist/services/agent/ecc-package-service.d.ts.map +1 -0
- package/dist/services/agent/ecc-package-service.js +41 -0
- package/dist/services/agent/ecc-package-source.d.ts +97 -0
- package/dist/services/agent/ecc-package-source.d.ts.map +1 -0
- package/dist/services/agent/ecc-package-source.js +130 -0
- package/package.json +2 -1
- package/dist/services/agent/ecc-archive-safety.d.ts +0 -25
- package/dist/services/agent/ecc-archive-safety.d.ts.map +0 -1
- package/dist/services/agent/ecc-archive-safety.js +0 -131
- package/dist/services/agent/ecc-cache-cleanup.d.ts +0 -26
- package/dist/services/agent/ecc-cache-cleanup.d.ts.map +0 -1
- package/dist/services/agent/ecc-cache-cleanup.js +0 -90
- package/dist/services/agent/ecc-cache-config.d.ts +0 -66
- package/dist/services/agent/ecc-cache-config.d.ts.map +0 -1
- package/dist/services/agent/ecc-cache-config.js +0 -72
- package/dist/services/agent/ecc-cache-manifest.d.ts +0 -22
- package/dist/services/agent/ecc-cache-manifest.d.ts.map +0 -1
- package/dist/services/agent/ecc-cache-manifest.js +0 -136
- package/dist/services/agent/ecc-cache-service.d.ts +0 -65
- package/dist/services/agent/ecc-cache-service.d.ts.map +0 -1
- package/dist/services/agent/ecc-cache-service.js +0 -118
- package/dist/services/agent/ecc-fetch.d.ts +0 -31
- package/dist/services/agent/ecc-fetch.d.ts.map +0 -1
- package/dist/services/agent/ecc-fetch.js +0 -95
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where ECC's agent definitions come from: the installed `ecc-universal`
|
|
3
|
+
* npm package.
|
|
4
|
+
*
|
|
5
|
+
* THIS REPLACED A NETWORK ACQUISITION LAYER. Until 2026-10-04 peaks-loop
|
|
6
|
+
* downloaded ECC at runtime — `api.github.com/repos/affaan-m/ECC/releases/latest`
|
|
7
|
+
* → `codeload` tarball → selective extract into `~/.peaks/cache/ecc-<sha>/`
|
|
8
|
+
* — guarded by a tarball-safety module, a cache manifest, a sha-directory
|
|
9
|
+
* cleanup sweep and a log-retention leg that swept it. Every one of those
|
|
10
|
+
* existed to make up for a premise that turned out to be false: three places in
|
|
11
|
+
* this repository asserted that `affaan-m/ECC` was NOT on npm
|
|
12
|
+
* (`src/services/audit/static-service.ts`, `CHANGELOG.md:1630`,
|
|
13
|
+
* `src/services/code-review/ecc-bridge.ts`), and `ecc-universal` IS that
|
|
14
|
+
* repository — `npm view ecc-universal repository.url` answers
|
|
15
|
+
* `git+https://github.com/affaan-m/ECC.git`. A dependency ships its own files,
|
|
16
|
+
* so there is nothing left to fetch, verify, extract, cache or sweep.
|
|
17
|
+
*
|
|
18
|
+
* WHAT REMAINS AND WHY: `ecc-universal` is a normal dependency of
|
|
19
|
+
* `peaks-loop-mut`, its `agents/*.md` are read here, and the plugin-free copy
|
|
20
|
+
* under `~/.peaks/agents/ecc/` (see `ecc-materialize.ts`) is kept because that
|
|
21
|
+
* path is what the RD fan-out and Gate B3 read, what the skill docs tell the LLM
|
|
22
|
+
* to open, and it survives a peaks-loop upgrade that changes the version-pinned
|
|
23
|
+
* path below.
|
|
24
|
+
*
|
|
25
|
+
* The resolved path is version-PINNED under pnpm
|
|
26
|
+
* (`.../.pnpm/ecc-universal@2.2.3/node_modules/ecc-universal`), which is exactly
|
|
27
|
+
* why it is not a stable read target for a human opening a path by hand — hence
|
|
28
|
+
* materialize, and hence this module never hands out its own directory except to
|
|
29
|
+
* the copy step.
|
|
30
|
+
*/
|
|
31
|
+
import { chmodSync, existsSync, readFileSync } from 'node:fs';
|
|
32
|
+
import { homedir } from 'node:os';
|
|
33
|
+
import { dirname, join } from 'node:path';
|
|
34
|
+
import { createRequire } from 'node:module';
|
|
35
|
+
export const ECC_PACKAGE_NAME = 'ecc-universal';
|
|
36
|
+
export const ECC_AGENTS_SUBDIR = 'agents';
|
|
37
|
+
/** Manifest shape for the plugin-free copy. */
|
|
38
|
+
export const ECC_MATERIALIZE_VERSION = '2';
|
|
39
|
+
export class EccSourceError extends Error {
|
|
40
|
+
failure;
|
|
41
|
+
constructor(failure, detail) {
|
|
42
|
+
super(`ecc-universal: ${failure} — ${detail}`);
|
|
43
|
+
this.name = 'EccSourceError';
|
|
44
|
+
this.failure = failure;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The package root, resolved through Node's own algorithm rather than a
|
|
49
|
+
* hand-built `node_modules` path.
|
|
50
|
+
*
|
|
51
|
+
* `require.resolve('ecc-universal/package.json')` is the join point: it honors
|
|
52
|
+
* the pnpm store layout, an npm flat install, a global install of peaks-loop,
|
|
53
|
+
* and a linked workspace alike. A hardcoded `../../node_modules/ecc-universal`
|
|
54
|
+
* would resolve in exactly one of those and fail in the others with an error
|
|
55
|
+
* that looks like "ECC is not installed".
|
|
56
|
+
*/
|
|
57
|
+
export function resolveEccPackageRoot() {
|
|
58
|
+
let packageJson;
|
|
59
|
+
try {
|
|
60
|
+
packageJson = createRequire(import.meta.url).resolve(`${ECC_PACKAGE_NAME}/package.json`);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
64
|
+
throw new EccSourceError('not-installed', `cannot resolve ${ECC_PACKAGE_NAME}/package.json from peaks-loop-mut (${message}). ` +
|
|
65
|
+
'Reinstall peaks-loop; the ECC agents ship with that dependency.');
|
|
66
|
+
}
|
|
67
|
+
return dirname(packageJson);
|
|
68
|
+
}
|
|
69
|
+
/** The `version` the package declares — the identity a materialized copy records. */
|
|
70
|
+
export function readEccPackageVersion(root = resolveEccPackageRoot()) {
|
|
71
|
+
try {
|
|
72
|
+
const parsed = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
73
|
+
return typeof parsed.version === 'string' ? parsed.version : 'unknown';
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return 'unknown';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** `<package>/agents` — the flat `*.md` definitions the LLM consumes. */
|
|
80
|
+
export function resolveEccAgentsDir(root = resolveEccPackageRoot()) {
|
|
81
|
+
const agentsDir = join(root, ECC_AGENTS_SUBDIR);
|
|
82
|
+
if (!existsSync(agentsDir)) {
|
|
83
|
+
throw new EccSourceError('no-agents-dir', `${agentsDir} does not exist; this ${ECC_PACKAGE_NAME} build ships no agents/ subtree`);
|
|
84
|
+
}
|
|
85
|
+
return agentsDir;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Plugin-free materialize target: `~/.peaks/agents/ecc/`.
|
|
89
|
+
*
|
|
90
|
+
* Deliberately NOT under `~/.claude/` — peaks-loop must never write into the
|
|
91
|
+
* user's Claude Code tree (user direction 2026-09-09). The LLM reads
|
|
92
|
+
* `<target>/<agent-name>.md` directly when the ECC Claude Code plugin is
|
|
93
|
+
* absent, then dispatches a generic sub-agent with that body.
|
|
94
|
+
*/
|
|
95
|
+
export function resolveEccMaterializedDir() {
|
|
96
|
+
return join(homedir(), '.peaks', 'agents', 'ecc');
|
|
97
|
+
}
|
|
98
|
+
export function resolveEccMaterializedManifestPath(dirOverride) {
|
|
99
|
+
return join(dirOverride ?? resolveEccMaterializedDir(), 'ecc-agents.json');
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Agent names are used to build filenames, so the whitelist is the escape
|
|
103
|
+
* check. Kept as a positive allowlist rather than a denylist: anything outside
|
|
104
|
+
* `^[a-z][a-z0-9-]*$` never reaches a path, whatever upstream adds later.
|
|
105
|
+
*/
|
|
106
|
+
export function isSafeAgentName(name) {
|
|
107
|
+
return /^[a-z][a-z0-9-]*$/.test(name);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Owner-only mode for the peaks-owned dirs this writes. `0o700` is a POSIX mode
|
|
111
|
+
* literal, not a tunable: anything wider lets another local user read the agent
|
|
112
|
+
* definitions the LLM is about to be handed.
|
|
113
|
+
*/
|
|
114
|
+
// eslint-disable-next-line no-magic-numbers -- POSIX mode bits are notation, not a quantity
|
|
115
|
+
const PEAKS_DIR_MODE = 0o700;
|
|
116
|
+
/**
|
|
117
|
+
* Best-effort chmod 0o700 on POSIX; no-op on Windows (NTFS uses ACLs, not POSIX
|
|
118
|
+
* mode bits). Errors are swallowed with WARN so a permissions failure never
|
|
119
|
+
* blocks the CLI — the files are public agent definitions, not secrets.
|
|
120
|
+
*/
|
|
121
|
+
export function setPeaksDirPermissions(dir) {
|
|
122
|
+
if (process.platform === 'win32')
|
|
123
|
+
return;
|
|
124
|
+
try {
|
|
125
|
+
chmodSync(dir, PEAKS_DIR_MODE);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
/* best-effort */
|
|
129
|
+
}
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peaks-loop-mut",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.56",
|
|
4
4
|
"description": "Mutation testing + assertion scanning + ECC cache for peaks-loop (workspace-internal)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"peaks-loop",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"node": ">=20.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"ecc-universal": "^2.2.3",
|
|
31
32
|
"zod": "^4.4.3"
|
|
32
33
|
},
|
|
33
34
|
"publishConfig": {
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ECC archive safety — agent-name allowlist and tar entry validation.
|
|
3
|
-
*
|
|
4
|
-
* This is the security-relevant seam: path traversal (`..`), absolute
|
|
5
|
-
* paths and drive letters, the synthetic GitHub root, symlink/dir type
|
|
6
|
-
* flags, and the `agents/<name>.md` allowlist are all rejected here before
|
|
7
|
-
* anything is written to disk. Split verbatim out of
|
|
8
|
-
* `ecc-cache-service.ts` (wave 11 slice A, 2026-10-03); no behaviour
|
|
9
|
-
* changed.
|
|
10
|
-
*/
|
|
11
|
-
declare function isSafeAgentName(name: string): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Tiny tar.gz extractor. Public-domain-compatible tar parser:
|
|
14
|
-
* - reads 512-byte header blocks
|
|
15
|
-
* - validates name + size
|
|
16
|
-
* - rejects anything that is not a regular file at a safe path
|
|
17
|
-
* - filters to the `agents/*.md` allowlist via isSafeArchiveEntry
|
|
18
|
-
*
|
|
19
|
-
* We do NOT decompress gzip via a third-party lib; Node's
|
|
20
|
-
* `node:zlib` ships with `gunzip` so the implementation is
|
|
21
|
-
* self-contained.
|
|
22
|
-
*/
|
|
23
|
-
declare function extractAgentsFromTarGz(buffer: Uint8Array, outDir: string): Promise<string[]>;
|
|
24
|
-
export { isSafeAgentName, extractAgentsFromTarGz };
|
|
25
|
-
//# sourceMappingURL=ecc-archive-safety.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ecc-archive-safety.d.ts","sourceRoot":"","sources":["../../../src/services/agent/ecc-archive-safety.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,iBAAS,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9C;AAgCD;;;;;;;;;;GAUG;AACH,iBAAe,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA8C3F;AAqBD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ECC archive safety — agent-name allowlist and tar entry validation.
|
|
3
|
-
*
|
|
4
|
-
* This is the security-relevant seam: path traversal (`..`), absolute
|
|
5
|
-
* paths and drive letters, the synthetic GitHub root, symlink/dir type
|
|
6
|
-
* flags, and the `agents/<name>.md` allowlist are all rejected here before
|
|
7
|
-
* anything is written to disk. Split verbatim out of
|
|
8
|
-
* `ecc-cache-service.ts` (wave 11 slice A, 2026-10-03); no behaviour
|
|
9
|
-
* changed.
|
|
10
|
-
*/
|
|
11
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
12
|
-
import { join } from 'node:path';
|
|
13
|
-
function isSafeAgentName(name) {
|
|
14
|
-
return /^[a-z][a-z0-9-]*$/.test(name);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* GitHub prefixes every tarball entry with a synthetic root dir —
|
|
18
|
-
* `<repo>-<sha>` on codeload, `<owner>-<repo>-<sha>` on the API tarball
|
|
19
|
-
* endpoint. Match on shape, not on the repo name, so a rename (or either
|
|
20
|
-
* endpoint) cannot silently zero out the extraction.
|
|
21
|
-
*/
|
|
22
|
-
function stripTarballRootSegments(entryName) {
|
|
23
|
-
const segments = entryName.split('/');
|
|
24
|
-
if (segments.length >= 3 && segments[0] !== 'agents')
|
|
25
|
-
segments.shift();
|
|
26
|
-
return segments;
|
|
27
|
-
}
|
|
28
|
-
function isSafeArchiveEntry(entryName) {
|
|
29
|
-
if (entryName.length === 0)
|
|
30
|
-
return false;
|
|
31
|
-
if (entryName.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(entryName))
|
|
32
|
-
return false;
|
|
33
|
-
if (entryName.includes('..'))
|
|
34
|
-
return false;
|
|
35
|
-
// After dropping the synthetic root, everything must be exactly
|
|
36
|
-
// "agents/<name>.md" at a single level.
|
|
37
|
-
const segments = stripTarballRootSegments(entryName);
|
|
38
|
-
if (segments.length !== 2)
|
|
39
|
-
return false;
|
|
40
|
-
return segments[0] === 'agents' && segments[1]?.endsWith('.md') === true;
|
|
41
|
-
}
|
|
42
|
-
function safeAgentNameFromEntry(entryName) {
|
|
43
|
-
const segments = stripTarballRootSegments(entryName);
|
|
44
|
-
const file = segments[segments.length - 1] ?? '';
|
|
45
|
-
const base = file.replace(/\.md$/i, '');
|
|
46
|
-
return isSafeAgentName(base) ? base : null;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Tiny tar.gz extractor. Public-domain-compatible tar parser:
|
|
50
|
-
* - reads 512-byte header blocks
|
|
51
|
-
* - validates name + size
|
|
52
|
-
* - rejects anything that is not a regular file at a safe path
|
|
53
|
-
* - filters to the `agents/*.md` allowlist via isSafeArchiveEntry
|
|
54
|
-
*
|
|
55
|
-
* We do NOT decompress gzip via a third-party lib; Node's
|
|
56
|
-
* `node:zlib` ships with `gunzip` so the implementation is
|
|
57
|
-
* self-contained.
|
|
58
|
-
*/
|
|
59
|
-
async function extractAgentsFromTarGz(buffer, outDir) {
|
|
60
|
-
if (!existsSync(outDir))
|
|
61
|
-
mkdirSync(outDir, { recursive: true });
|
|
62
|
-
const extracted = [];
|
|
63
|
-
// Lazy import to keep the cold path cheap.
|
|
64
|
-
const { gunzipSync } = await import('node:zlib');
|
|
65
|
-
let tar;
|
|
66
|
-
try {
|
|
67
|
-
tar = gunzipSync(buffer);
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
const BLOCK = 512;
|
|
73
|
-
let offset = 0;
|
|
74
|
-
while (offset + BLOCK <= tar.length) {
|
|
75
|
-
const header = tar.subarray(offset, offset + BLOCK);
|
|
76
|
-
// Two consecutive zero blocks mark end-of-archive.
|
|
77
|
-
if (header.every((b) => b === 0))
|
|
78
|
-
break;
|
|
79
|
-
const name = readCString(header, 0, 100);
|
|
80
|
-
if (name === null || name.length === 0)
|
|
81
|
-
break;
|
|
82
|
-
const sizeOctal = readCString(header, 124, 12);
|
|
83
|
-
if (sizeOctal === null)
|
|
84
|
-
break;
|
|
85
|
-
const size = parseOctal(sizeOctal);
|
|
86
|
-
if (size === null)
|
|
87
|
-
break;
|
|
88
|
-
const typeFlag = String.fromCharCode(header[156] ?? 0);
|
|
89
|
-
// '0' or '\0' = regular file. Reject symlinks (2), dirs (5), etc.
|
|
90
|
-
if (typeFlag !== '0' && typeFlag !== '\0') {
|
|
91
|
-
offset += BLOCK + Math.ceil(size / BLOCK) * BLOCK;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (!isSafeArchiveEntry(name)) {
|
|
95
|
-
offset += BLOCK + Math.ceil(size / BLOCK) * BLOCK;
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const safeName = safeAgentNameFromEntry(name);
|
|
99
|
-
if (safeName === null) {
|
|
100
|
-
offset += BLOCK + Math.ceil(size / BLOCK) * BLOCK;
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const data = tar.subarray(offset + BLOCK, offset + BLOCK + size);
|
|
104
|
-
writeFileSync(join(outDir, `${safeName}.md`), data);
|
|
105
|
-
extracted.push(safeName);
|
|
106
|
-
offset += BLOCK + Math.ceil(size / BLOCK) * BLOCK;
|
|
107
|
-
}
|
|
108
|
-
return extracted;
|
|
109
|
-
}
|
|
110
|
-
function readCString(buf, start, len) {
|
|
111
|
-
let end = start;
|
|
112
|
-
while (end < start + len && buf[end] !== 0)
|
|
113
|
-
end += 1;
|
|
114
|
-
if (end === start)
|
|
115
|
-
return '';
|
|
116
|
-
try {
|
|
117
|
-
return Buffer.from(buf.subarray(start, end)).toString('utf8');
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function parseOctal(value) {
|
|
124
|
-
const trimmed = value.trim().replace(/\0+$/g, '');
|
|
125
|
-
if (trimmed.length === 0)
|
|
126
|
-
return 0;
|
|
127
|
-
const n = Number.parseInt(trimmed, 8);
|
|
128
|
-
return Number.isFinite(n) && n >= 0 ? n : null;
|
|
129
|
-
}
|
|
130
|
-
// Cross-module glue: private inside ecc-cache-service.ts before the split.
|
|
131
|
-
export { isSafeAgentName, extractAgentsFromTarGz };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 7-day TTL sweep over the ECC sha cache (`cleanupStaleCache`, used by
|
|
3
|
-
* `src/services/log/retention.ts` through the package barrel).
|
|
4
|
-
*
|
|
5
|
-
* Split verbatim out of `ecc-cache-service.ts` (wave 11 slice A,
|
|
6
|
-
* 2026-10-03); no behaviour changed.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* 7-day TTL sweep over `ecc-<sha>/` directories.
|
|
10
|
-
*
|
|
11
|
-
* - Active cache (per manifest `sha`): use `fetchedAt` as the
|
|
12
|
-
* age source; remove if older than `retentionDays`.
|
|
13
|
-
* - Orphan caches (any other `ecc-<40hex>` directory): use
|
|
14
|
-
* directory `mtimeMs` as the age source.
|
|
15
|
-
* - If the active cache is removed, invalidate the manifest.
|
|
16
|
-
*
|
|
17
|
-
* Returns the absolute paths of the removed directories.
|
|
18
|
-
*/
|
|
19
|
-
export declare function cleanupStaleCache({ retentionDays, nowMs, dirOverride }: {
|
|
20
|
-
retentionDays: number;
|
|
21
|
-
nowMs: number;
|
|
22
|
-
dirOverride?: string;
|
|
23
|
-
}): {
|
|
24
|
-
removed: string[];
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=ecc-cache-cleanup.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ecc-cache-cleanup.d.ts","sourceRoot":"","sources":["../../../src/services/agent/ecc-cache-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,aAAa,EACb,KAAK,EACL,WAAW,EACZ,EAAE;IACD,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CA2CxB"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 7-day TTL sweep over the ECC sha cache (`cleanupStaleCache`, used by
|
|
3
|
-
* `src/services/log/retention.ts` through the package barrel).
|
|
4
|
-
*
|
|
5
|
-
* Split verbatim out of `ecc-cache-service.ts` (wave 11 slice A,
|
|
6
|
-
* 2026-10-03); no behaviour changed.
|
|
7
|
-
*/
|
|
8
|
-
import { existsSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
9
|
-
import { join } from 'node:path';
|
|
10
|
-
import { resolveEccCacheDir, resolveManifestPath } from './ecc-cache-config.js';
|
|
11
|
-
import { readCacheManifest } from './ecc-cache-manifest.js';
|
|
12
|
-
/**
|
|
13
|
-
* 7-day TTL sweep over `ecc-<sha>/` directories.
|
|
14
|
-
*
|
|
15
|
-
* - Active cache (per manifest `sha`): use `fetchedAt` as the
|
|
16
|
-
* age source; remove if older than `retentionDays`.
|
|
17
|
-
* - Orphan caches (any other `ecc-<40hex>` directory): use
|
|
18
|
-
* directory `mtimeMs` as the age source.
|
|
19
|
-
* - If the active cache is removed, invalidate the manifest.
|
|
20
|
-
*
|
|
21
|
-
* Returns the absolute paths of the removed directories.
|
|
22
|
-
*/
|
|
23
|
-
export function cleanupStaleCache({ retentionDays, nowMs, dirOverride }) {
|
|
24
|
-
const cacheDir = dirOverride ?? resolveEccCacheDir();
|
|
25
|
-
if (!existsSync(cacheDir))
|
|
26
|
-
return { removed: [] };
|
|
27
|
-
const dayMs = 24 * 60 * 60 * 1000;
|
|
28
|
-
const cutoff = nowMs - retentionDays * dayMs;
|
|
29
|
-
const manifest = readCacheManifest();
|
|
30
|
-
const activeSha = manifest?.sha ?? null;
|
|
31
|
-
const activeFetchedAt = manifest?.fetchedAt ? Date.parse(manifest.fetchedAt) : NaN;
|
|
32
|
-
const removed = [];
|
|
33
|
-
let names;
|
|
34
|
-
try {
|
|
35
|
-
names = readdirSync(cacheDir);
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return { removed: [] };
|
|
39
|
-
}
|
|
40
|
-
for (const name of names) {
|
|
41
|
-
const match = /^ecc-([0-9a-f]{40})$/.exec(name);
|
|
42
|
-
if (match === null)
|
|
43
|
-
continue;
|
|
44
|
-
const sha = match[1] ?? '';
|
|
45
|
-
const fullPath = join(cacheDir, name);
|
|
46
|
-
let stat;
|
|
47
|
-
try {
|
|
48
|
-
stat = statSync(fullPath);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (!stat.isDirectory())
|
|
54
|
-
continue;
|
|
55
|
-
let ageMs;
|
|
56
|
-
if (sha === activeSha && Number.isFinite(activeFetchedAt)) {
|
|
57
|
-
ageMs = nowMs - activeFetchedAt;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
ageMs = nowMs - stat.mtimeMs;
|
|
61
|
-
}
|
|
62
|
-
removeExpiredCacheDir({ ageMs, retentionDays, dayMs, fullPath, removed });
|
|
63
|
-
}
|
|
64
|
-
invalidateManifestIfActiveRemoved({ activeSha, removed, cacheDir });
|
|
65
|
-
return { removed };
|
|
66
|
-
}
|
|
67
|
-
function removeExpiredCacheDir(ctx) {
|
|
68
|
-
const { ageMs, retentionDays, dayMs, fullPath, removed } = ctx;
|
|
69
|
-
if (ageMs > retentionDays * dayMs) {
|
|
70
|
-
try {
|
|
71
|
-
rmSync(fullPath, { recursive: true, force: true });
|
|
72
|
-
removed.push(fullPath);
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
/* best-effort */
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function invalidateManifestIfActiveRemoved(ctx) {
|
|
80
|
-
const { activeSha, removed, cacheDir } = ctx;
|
|
81
|
-
// Invalidate manifest if active cache was removed.
|
|
82
|
-
if (activeSha !== null && removed.some((p) => p.includes(`ecc-${activeSha}`))) {
|
|
83
|
-
try {
|
|
84
|
-
rmSync(resolveManifestPath(cacheDir), { force: true });
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
/* best-effort */
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ECC cache constants, public types and path resolution — the single source
|
|
3
|
-
* of truth for the cache layout (`~/.peaks/cache`) and the plugin-free
|
|
4
|
-
* materialize target (`~/.peaks/agents/ecc`).
|
|
5
|
-
*
|
|
6
|
-
* Split verbatim out of `ecc-cache-service.ts` (wave 11 slice A,
|
|
7
|
-
* 2026-10-03); no behaviour changed. `homedir()` is called per resolution,
|
|
8
|
-
* so the `node:os` mock in the ecc tests takes effect through this module
|
|
9
|
-
* as long as it is loaded via the facade's delayed import (T2).
|
|
10
|
-
*/
|
|
11
|
-
export declare const ECC_REPO_OWNER = "affaan-m";
|
|
12
|
-
export declare const ECC_REPO_NAME = "ECC";
|
|
13
|
-
declare const ECC_CACHE_VERSION = "1";
|
|
14
|
-
declare const ECC_MATERIALIZE_VERSION = "1";
|
|
15
|
-
declare const ECC_TARBALL_BASENAME = "ecc.tar.gz";
|
|
16
|
-
declare const GITHUB_API_ACCEPT = "application/vnd.github+json";
|
|
17
|
-
export type CacheManifest = {
|
|
18
|
-
version: string;
|
|
19
|
-
sha: string;
|
|
20
|
-
fetchedAt: string;
|
|
21
|
-
agents: string[];
|
|
22
|
-
};
|
|
23
|
-
export type DownloadResult = {
|
|
24
|
-
sha: string;
|
|
25
|
-
agents: number;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Peaks-owned materialize manifest. Written next to the normalized
|
|
29
|
-
* agent copies under `~/.peaks/agents/ecc/`. Unlike the cache manifest
|
|
30
|
-
* (which points at a sha dir), this one records the *stable* copy the
|
|
31
|
-
* plugin-free dispatch path reads when no ECC Claude Code plugin is
|
|
32
|
-
* installed.
|
|
33
|
-
*/
|
|
34
|
-
export type EccMaterializeManifest = {
|
|
35
|
-
version: string;
|
|
36
|
-
sha: string;
|
|
37
|
-
materializedAt: string;
|
|
38
|
-
agents: string[];
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Cache dir resolution — single source of truth. Tests inject
|
|
42
|
-
* via `dirOverride` on the functions that take one.
|
|
43
|
-
*/
|
|
44
|
-
export declare function resolveEccCacheDir(): string;
|
|
45
|
-
export declare function resolveManifestPath(dirOverride?: string): string;
|
|
46
|
-
export declare function resolveShaDir(sha: string, dirOverride?: string): string;
|
|
47
|
-
export declare function resolveAgentsDir(sha: string, dirOverride?: string): string;
|
|
48
|
-
/**
|
|
49
|
-
* Plugin-free materialize target: `~/.peaks/agents/ecc/`.
|
|
50
|
-
*
|
|
51
|
-
* Deliberately NOT under `~/.claude/` — peaks-loop must never write into
|
|
52
|
-
* the user's Claude Code tree (user direction 2026-09-09). The LLM reads
|
|
53
|
-
* `<target>/<agent-name>.md` directly when the ECC Claude Code plugin is
|
|
54
|
-
* absent, then dispatches a generic sub-agent with that body.
|
|
55
|
-
*/
|
|
56
|
-
export declare function resolveEccMaterializedDir(): string;
|
|
57
|
-
export declare function resolveEccMaterializedManifestPath(dirOverride?: string): string;
|
|
58
|
-
/**
|
|
59
|
-
* Best-effort chmod 0o700 on POSIX; no-op on Windows (NTFS uses
|
|
60
|
-
* ACLs, not POSIX mode bits). Swallows errors with WARN so a
|
|
61
|
-
* permissions failure never blocks the CLI.
|
|
62
|
-
*/
|
|
63
|
-
export declare function setCacheDirPermissions(cacheDir: string): void;
|
|
64
|
-
declare function asSha(value: string): string;
|
|
65
|
-
export { asSha, ECC_CACHE_VERSION, ECC_MATERIALIZE_VERSION, ECC_TARBALL_BASENAME, GITHUB_API_ACCEPT };
|
|
66
|
-
//# sourceMappingURL=ecc-cache-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ecc-cache-config.d.ts","sourceRoot":"","sources":["../../../src/services/agent/ecc-cache-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,eAAO,MAAM,cAAc,aAAa,CAAC;AAGzC,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,QAAA,MAAM,iBAAiB,MAAM,CAAC;AAC9B,QAAA,MAAM,uBAAuB,MAAM,CAAC;AACpC,QAAA,MAAM,oBAAoB,eAAe,CAAC;AAE1C,QAAA,MAAM,iBAAiB,gCAAgC,CAAC;AAExD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAgB,mBAAmB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAED,wBAAgB,kCAAkC,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/E;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAO7D;AAED,iBAAS,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpC;AAGD,OAAO,EACL,KAAK,EACL,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EAClB,CAAC"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ECC cache constants, public types and path resolution — the single source
|
|
3
|
-
* of truth for the cache layout (`~/.peaks/cache`) and the plugin-free
|
|
4
|
-
* materialize target (`~/.peaks/agents/ecc`).
|
|
5
|
-
*
|
|
6
|
-
* Split verbatim out of `ecc-cache-service.ts` (wave 11 slice A,
|
|
7
|
-
* 2026-10-03); no behaviour changed. `homedir()` is called per resolution,
|
|
8
|
-
* so the `node:os` mock in the ecc tests takes effect through this module
|
|
9
|
-
* as long as it is loaded via the facade's delayed import (T2).
|
|
10
|
-
*/
|
|
11
|
-
import { chmodSync } from 'node:fs';
|
|
12
|
-
import { join } from 'node:path';
|
|
13
|
-
import { homedir } from 'node:os';
|
|
14
|
-
export const ECC_REPO_OWNER = 'affaan-m';
|
|
15
|
-
// Upstream renamed `everything-claude-code` -> `ECC` on 2026-09; GitHub
|
|
16
|
-
// 301-redirects the old name but we keep the current one to avoid the hop.
|
|
17
|
-
export const ECC_REPO_NAME = 'ECC';
|
|
18
|
-
const ECC_CACHE_VERSION = '1';
|
|
19
|
-
const ECC_MATERIALIZE_VERSION = '1';
|
|
20
|
-
const ECC_TARBALL_BASENAME = 'ecc.tar.gz';
|
|
21
|
-
// GitHub's API tarball endpoint 415s on `application/octet-stream`.
|
|
22
|
-
const GITHUB_API_ACCEPT = 'application/vnd.github+json';
|
|
23
|
-
/**
|
|
24
|
-
* Cache dir resolution — single source of truth. Tests inject
|
|
25
|
-
* via `dirOverride` on the functions that take one.
|
|
26
|
-
*/
|
|
27
|
-
export function resolveEccCacheDir() {
|
|
28
|
-
return join(homedir(), '.peaks', 'cache');
|
|
29
|
-
}
|
|
30
|
-
export function resolveManifestPath(dirOverride) {
|
|
31
|
-
return join(dirOverride ?? resolveEccCacheDir(), 'ecc-installed.json');
|
|
32
|
-
}
|
|
33
|
-
export function resolveShaDir(sha, dirOverride) {
|
|
34
|
-
return join(dirOverride ?? resolveEccCacheDir(), `ecc-${sha}`);
|
|
35
|
-
}
|
|
36
|
-
export function resolveAgentsDir(sha, dirOverride) {
|
|
37
|
-
return join(resolveShaDir(sha, dirOverride), 'agents');
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Plugin-free materialize target: `~/.peaks/agents/ecc/`.
|
|
41
|
-
*
|
|
42
|
-
* Deliberately NOT under `~/.claude/` — peaks-loop must never write into
|
|
43
|
-
* the user's Claude Code tree (user direction 2026-09-09). The LLM reads
|
|
44
|
-
* `<target>/<agent-name>.md` directly when the ECC Claude Code plugin is
|
|
45
|
-
* absent, then dispatches a generic sub-agent with that body.
|
|
46
|
-
*/
|
|
47
|
-
export function resolveEccMaterializedDir() {
|
|
48
|
-
return join(homedir(), '.peaks', 'agents', 'ecc');
|
|
49
|
-
}
|
|
50
|
-
export function resolveEccMaterializedManifestPath(dirOverride) {
|
|
51
|
-
return join(dirOverride ?? resolveEccMaterializedDir(), 'ecc-agents.json');
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Best-effort chmod 0o700 on POSIX; no-op on Windows (NTFS uses
|
|
55
|
-
* ACLs, not POSIX mode bits). Swallows errors with WARN so a
|
|
56
|
-
* permissions failure never blocks the CLI.
|
|
57
|
-
*/
|
|
58
|
-
export function setCacheDirPermissions(cacheDir) {
|
|
59
|
-
if (process.platform === 'win32')
|
|
60
|
-
return;
|
|
61
|
-
try {
|
|
62
|
-
chmodSync(cacheDir, 0o700);
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
/* best-effort */
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function asSha(value) {
|
|
69
|
-
return /^[0-9a-f]{40}$/.test(value) ? value : value;
|
|
70
|
-
}
|
|
71
|
-
// Cross-module glue: private inside ecc-cache-service.ts before the split.
|
|
72
|
-
export { asSha, ECC_CACHE_VERSION, ECC_MATERIALIZE_VERSION, ECC_TARBALL_BASENAME, GITHUB_API_ACCEPT };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ECC cache manifest + cache reads (writeManifest / readManifestAt /
|
|
3
|
-
* listCachedAgents / readAgentSkill and the D-009 `fallbackMetadata`).
|
|
4
|
-
*
|
|
5
|
-
* The warn-once latch `warnedAboutFallback` lives HERE with its only
|
|
6
|
-
* reader `fallbackMetadata` — they move as one unit, so the D-009
|
|
7
|
-
* warning stays single-fire across repeated calls.
|
|
8
|
-
*
|
|
9
|
-
* Split verbatim out of `ecc-cache-service.ts` (wave 11 slice A,
|
|
10
|
-
* 2026-10-03); no behaviour changed.
|
|
11
|
-
*/
|
|
12
|
-
import { type CacheManifest } from './ecc-cache-config.js';
|
|
13
|
-
declare function writeManifest(manifest: CacheManifest): void;
|
|
14
|
-
export declare function readCacheManifest(): CacheManifest | null;
|
|
15
|
-
declare function readManifestAt(dirOverride?: string): CacheManifest | null;
|
|
16
|
-
export declare function listCachedAgents(): {
|
|
17
|
-
name: string;
|
|
18
|
-
description: string;
|
|
19
|
-
}[];
|
|
20
|
-
export declare function readAgentSkill(name: string): string | null;
|
|
21
|
-
export { writeManifest, readManifestAt };
|
|
22
|
-
//# sourceMappingURL=ecc-cache-manifest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ecc-cache-manifest.d.ts","sourceRoot":"","sources":["../../../src/services/agent/ecc-cache-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,EAAyC,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGlG,iBAAS,aAAa,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAGpD;AAED,wBAAgB,iBAAiB,IAAI,aAAa,GAAG,IAAI,CAExD;AAED,iBAAS,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAkBlE;AAoDD,wBAAgB,gBAAgB,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAAE,CAqB1E;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAW1D;AAGD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC"}
|