peaks-loop-mut 0.1.52 → 0.1.53

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 (43) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/services/agent/ecc-archive-safety.d.ts +25 -0
  5. package/dist/services/agent/ecc-archive-safety.d.ts.map +1 -0
  6. package/dist/services/agent/ecc-archive-safety.js +131 -0
  7. package/dist/services/agent/ecc-cache-cleanup.d.ts +26 -0
  8. package/dist/services/agent/ecc-cache-cleanup.d.ts.map +1 -0
  9. package/dist/services/agent/ecc-cache-cleanup.js +90 -0
  10. package/dist/services/agent/ecc-cache-config.d.ts +66 -0
  11. package/dist/services/agent/ecc-cache-config.d.ts.map +1 -0
  12. package/dist/services/agent/ecc-cache-config.js +72 -0
  13. package/dist/services/agent/ecc-cache-manifest.d.ts +22 -0
  14. package/dist/services/agent/ecc-cache-manifest.d.ts.map +1 -0
  15. package/dist/services/agent/ecc-cache-manifest.js +136 -0
  16. package/dist/services/agent/ecc-cache-service.d.ts +6 -113
  17. package/dist/services/agent/ecc-cache-service.d.ts.map +1 -1
  18. package/dist/services/agent/ecc-cache-service.js +28 -645
  19. package/dist/services/agent/ecc-fetch.d.ts +31 -0
  20. package/dist/services/agent/ecc-fetch.d.ts.map +1 -0
  21. package/dist/services/agent/ecc-fetch.js +95 -0
  22. package/dist/services/agent/ecc-materialize.d.ts +35 -0
  23. package/dist/services/agent/ecc-materialize.d.ts.map +1 -0
  24. package/dist/services/agent/ecc-materialize.js +110 -0
  25. package/dist/services/agent/ecc-materialized-readers.d.ts +31 -0
  26. package/dist/services/agent/ecc-materialized-readers.d.ts.map +1 -0
  27. package/dist/services/agent/ecc-materialized-readers.js +107 -0
  28. package/dist/services/mut/assert-scanner.d.ts.map +1 -1
  29. package/dist/services/mut/assert-scanner.js +8 -4
  30. package/dist/services/mut/index.d.ts +3 -3
  31. package/dist/services/mut/index.d.ts.map +1 -1
  32. package/dist/services/mut/index.js +2 -2
  33. package/dist/services/mut/mut-runner.js +4 -4
  34. package/dist/services/mut/production-stryker.d.ts.map +1 -1
  35. package/dist/services/mut/production-stryker.js +17 -13
  36. package/dist/services/mut/report-builder.d.ts.map +1 -1
  37. package/dist/services/mut/report-builder.js +6 -6
  38. package/dist/services/mut/report-loader.d.ts.map +1 -1
  39. package/dist/services/mut/report-loader.js +2 -1
  40. package/dist/services/mut/thresholds.js +4 -4
  41. package/dist/services/mut/types.d.ts.map +1 -1
  42. package/dist/services/mut/types.js +14 -10
  43. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -11,5 +11,5 @@
11
11
  * import { cleanupStaleCache } from 'peaks-loop-mut/services/agent/ecc-cache-service';
12
12
  */
13
13
  export * from './services/mut/index.js';
14
- export { setCacheDirPermissions, downloadToCache, readCacheManifest, listCachedAgents, readAgentSkill, cleanupStaleCache, resolveEccMaterializedDir, resolveEccMaterializedManifestPath, materializeEccAgents, readEccMaterializeManifest, listMaterializedAgents, hasMaterializedEccAgents, resolveMaterializedAgentName, readMaterializedAgent, ECC_REPO_OWNER, ECC_REPO_NAME, type CacheManifest, type DownloadResult, type EccMaterializeManifest, } from './services/agent/ecc-cache-service.js';
14
+ export { setCacheDirPermissions, downloadToCache, readCacheManifest, listCachedAgents, readAgentSkill, cleanupStaleCache, resolveEccMaterializedDir, resolveEccMaterializedManifestPath, materializeEccAgents, readEccMaterializeManifest, listMaterializedAgents, hasMaterializedEccAgents, resolveMaterializedAgentName, readMaterializedAgent, ECC_REPO_OWNER, ECC_REPO_NAME, type CacheManifest, type DownloadResult, type EccMaterializeManifest } from './services/agent/ecc-cache-service.js';
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,yBAAyB,CAAC;AAExC,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,yBAAyB,EACzB,kCAAkC,EAClC,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,sBAAsB,GAC5B,MAAM,uCAAuC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,yBAAyB,CAAC;AAExC,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,yBAAyB,EACzB,kCAAkC,EAClC,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,uCAAuC,CAAC"}
package/dist/index.js CHANGED
@@ -11,4 +11,4 @@
11
11
  * import { cleanupStaleCache } from 'peaks-loop-mut/services/agent/ecc-cache-service';
12
12
  */
13
13
  export * from './services/mut/index.js';
14
- export { setCacheDirPermissions, downloadToCache, readCacheManifest, listCachedAgents, readAgentSkill, cleanupStaleCache, resolveEccMaterializedDir, resolveEccMaterializedManifestPath, materializeEccAgents, readEccMaterializeManifest, listMaterializedAgents, hasMaterializedEccAgents, resolveMaterializedAgentName, readMaterializedAgent, ECC_REPO_OWNER, ECC_REPO_NAME, } from './services/agent/ecc-cache-service.js';
14
+ export { setCacheDirPermissions, downloadToCache, readCacheManifest, listCachedAgents, readAgentSkill, cleanupStaleCache, resolveEccMaterializedDir, resolveEccMaterializedManifestPath, materializeEccAgents, readEccMaterializeManifest, listMaterializedAgents, hasMaterializedEccAgents, resolveMaterializedAgentName, readMaterializedAgent, ECC_REPO_OWNER, ECC_REPO_NAME } from './services/agent/ecc-cache-service.js';
@@ -0,0 +1,25 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,131 @@
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 };
@@ -0,0 +1,26 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,90 @@
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
+ }
@@ -0,0 +1,66 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,72 @@
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 };
@@ -0,0 +1,22 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,136 @@
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 { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
13
+ import { join } from 'node:path';
14
+ import { parseFrontmatter } from '../../shared/frontmatter.js';
15
+ import { resolveManifestPath, resolveAgentsDir } from './ecc-cache-config.js';
16
+ import { isSafeAgentName } from './ecc-archive-safety.js';
17
+ function writeManifest(manifest) {
18
+ const path = resolveManifestPath();
19
+ writeFileSync(path, JSON.stringify(manifest, null, 2));
20
+ }
21
+ export function readCacheManifest() {
22
+ return readManifestAt();
23
+ }
24
+ function readManifestAt(dirOverride) {
25
+ const path = resolveManifestPath(dirOverride);
26
+ if (!existsSync(path))
27
+ return null;
28
+ try {
29
+ const raw = readFileSync(path, 'utf8');
30
+ const parsed = JSON.parse(raw);
31
+ if (typeof parsed.version === 'string' &&
32
+ typeof parsed.sha === 'string' &&
33
+ typeof parsed.fetchedAt === 'string' &&
34
+ Array.isArray(parsed.agents)) {
35
+ return parsed;
36
+ }
37
+ return null;
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
43
+ let warnedAboutFallback = false;
44
+ function fallbackMetadata(fileName) {
45
+ const base = fileName.replace(/\.md$/i, '');
46
+ let description = '';
47
+ try {
48
+ const body = readFileSync(join(resolveManifestDirForAgents(), fileName), 'utf8');
49
+ const lines = body.split(/\r?\n/);
50
+ let inFrontmatter = false;
51
+ let seenClosing = false;
52
+ for (const raw of lines) {
53
+ const line = raw.trim();
54
+ if (!seenClosing) {
55
+ if (!inFrontmatter && line === '---') {
56
+ inFrontmatter = true;
57
+ continue;
58
+ }
59
+ if (inFrontmatter && line === '---') {
60
+ seenClosing = true;
61
+ continue;
62
+ }
63
+ continue;
64
+ }
65
+ if (line.length === 0)
66
+ continue;
67
+ description = line;
68
+ break;
69
+ }
70
+ }
71
+ catch {
72
+ /* best-effort */
73
+ }
74
+ if (description.length > 80)
75
+ description = `${description.slice(0, 77)}...`;
76
+ if (!warnedAboutFallback) {
77
+ try {
78
+ process.stderr.write(`warning: cached agent "${base}" has malformed frontmatter; falling back to filename + first body line\n`);
79
+ }
80
+ catch {
81
+ /* best-effort */
82
+ }
83
+ warnedAboutFallback = true;
84
+ }
85
+ return { name: base, description };
86
+ }
87
+ function resolveManifestDirForAgents() {
88
+ const manifest = readCacheManifest();
89
+ if (manifest === null)
90
+ return '';
91
+ return resolveAgentsDir(manifest.sha);
92
+ }
93
+ export function listCachedAgents() {
94
+ const manifest = readCacheManifest();
95
+ if (manifest === null)
96
+ return [];
97
+ const agentsDir = resolveAgentsDir(manifest.sha);
98
+ if (!existsSync(agentsDir))
99
+ return [];
100
+ const out = [];
101
+ for (const file of readdirSync(agentsDir).sort()) {
102
+ if (!file.endsWith('.md'))
103
+ continue;
104
+ const fullPath = join(agentsDir, file);
105
+ let meta;
106
+ try {
107
+ const raw = readFileSync(fullPath, 'utf8');
108
+ const fm = parseFrontmatter(raw);
109
+ meta = { name: fm.name, description: fm.description };
110
+ }
111
+ catch {
112
+ // D-009 fallback — name from filename, description from first body line.
113
+ meta = fallbackMetadata(file);
114
+ }
115
+ out.push(meta);
116
+ }
117
+ return out;
118
+ }
119
+ export function readAgentSkill(name) {
120
+ if (!isSafeAgentName(name))
121
+ return null;
122
+ const manifest = readCacheManifest();
123
+ if (manifest === null)
124
+ return null;
125
+ const file = join(resolveAgentsDir(manifest.sha), `${name}.md`);
126
+ if (!existsSync(file))
127
+ return null;
128
+ try {
129
+ return readFileSync(file, 'utf8');
130
+ }
131
+ catch {
132
+ return null;
133
+ }
134
+ }
135
+ // Cross-module glue: private inside ecc-cache-service.ts before the split.
136
+ export { writeManifest, readManifestAt };