@planu/cli 5.7.21 → 5.7.22

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 (58) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/.planu-build.json +1 -1
  3. package/dist/cli/commands/spec.js +2 -32
  4. package/dist/core/shared/object.d.ts +3 -0
  5. package/dist/core/shared/object.js +12 -0
  6. package/dist/engine/config-loader.js +24 -32
  7. package/dist/engine/conventions-ttl.d.ts +2 -0
  8. package/dist/engine/conventions-ttl.js +1 -1
  9. package/dist/engine/detectors/library-detector-langs3b.d.ts +0 -5
  10. package/dist/engine/detectors/library-detector-langs3b.js +2 -16
  11. package/dist/engine/detectors/library-detector-langs5.d.ts +0 -1
  12. package/dist/engine/detectors/library-detector-langs5.js +2 -16
  13. package/dist/engine/detectors/otel-detector.js +4 -3
  14. package/dist/engine/detectors/otel-ecosystem-detectors.d.ts +0 -4
  15. package/dist/engine/detectors/otel-ecosystem-detectors.js +2 -14
  16. package/dist/engine/detectors/toml-dependencies.d.ts +2 -0
  17. package/dist/engine/detectors/toml-dependencies.js +16 -0
  18. package/dist/engine/drift-detection/release-status-drift.js +2 -17
  19. package/dist/engine/minimality/policy-loader.js +1 -11
  20. package/dist/engine/model-tier-resolver.js +3 -11
  21. package/dist/engine/platform-detector/desktop.js +3 -13
  22. package/dist/engine/platform-detector/games.js +3 -13
  23. package/dist/engine/release-pipeline/release-spec-closer.d.ts +1 -0
  24. package/dist/engine/release-pipeline/release-spec-closer.js +1 -1
  25. package/dist/engine/safety/cross-process-lock.js +6 -21
  26. package/dist/engine/safety/lock-scavenger.d.ts +3 -1
  27. package/dist/engine/safety/lock-scavenger.js +3 -3
  28. package/dist/engine/score-to-grade.d.ts +2 -0
  29. package/dist/engine/score-to-grade.js +16 -0
  30. package/dist/engine/spec-grounding/contract.js +2 -1
  31. package/dist/engine/spec-grounding/grounding-entry-parser.d.ts +0 -1
  32. package/dist/engine/spec-grounding/grounding-entry-parser.js +1 -3
  33. package/dist/engine/telemetry/health-checker.js +1 -19
  34. package/dist/engine/telemetry/telemetry-client.d.ts +1 -0
  35. package/dist/engine/telemetry/telemetry-client.js +1 -1
  36. package/dist/engine/test-scaffold-generator/advanced-scaffold.js +1 -24
  37. package/dist/engine/token-optimizer/analytics.d.ts +1 -1
  38. package/dist/engine/token-optimizer/analytics.js +2 -22
  39. package/dist/engine/token-optimizer/policy-loader.js +1 -11
  40. package/dist/engine/workers/handlers/code-map.js +4 -46
  41. package/dist/engine/workers/handlers/collect-files.d.ts +3 -0
  42. package/dist/engine/workers/handlers/collect-files.js +53 -0
  43. package/dist/engine/workers/handlers/documentation.js +4 -49
  44. package/dist/engine/workers/handlers/optimization.js +4 -46
  45. package/dist/engine/workers/handlers/security-audit.js +4 -45
  46. package/dist/storage/token-ledger-store.d.ts +1 -1
  47. package/dist/storage/token-ledger-store.js +2 -22
  48. package/dist/tools/audit.js +1 -15
  49. package/dist/tools/claude-settings-file.d.ts +3 -0
  50. package/dist/tools/claude-settings-file.js +19 -0
  51. package/dist/tools/reconcile-interactive-question-hooks.js +3 -18
  52. package/dist/tools/reconcile-session-safeguard-hook.js +3 -18
  53. package/dist/tools/reconcile-spec-sanctity-hook.js +4 -19
  54. package/dist/tools/validate.js +1 -15
  55. package/dist/types/token-ledger.d.ts +1 -0
  56. package/dist/types/token-ledger.js +21 -1
  57. package/package.json +1 -1
  58. package/planu-plugin.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ ## [5.7.22] - 2026-09-09
2
+
3
+ ### Features
4
+ - feat(tests): require an assertion in every vitest project
5
+
6
+ ### Bug Fixes
7
+ - fix(tools): stop exporting the internal-only claude settings path constant
8
+
9
+ ### Refactoring
10
+ - refactor: extract shared isRecord and mergeDeep into core/shared/object.ts
11
+ - refactor: export readConventionsFile and reuse it in model tier resolver
12
+ - refactor: reuse readFileOrNull instead of duplicate tryReadFile helper
13
+ - refactor: share validate and loadSystem bodies between config loaders
14
+ - refactor: reuse shared getFrameworkExt and getFrameworkRunCommand helpers
15
+ - refactor: export resolveSpecDir and reuse it in release status drift
16
+ - refactor: extract shared scoreToGrade helper for audit and validate
17
+ - refactor: rename lock-scavenger metadata builder to shared lockMetadata
18
+ - refactor: extract shared parseTomlDependencies for gleam and alire toml
19
+ - refactor: reuse readPackageJson instead of the duplicate readPackageDeps
20
+ - refactor: share isValidTelemetryEndpoint between telemetry client and health checker
21
+ - refactor: extract shared claude settings file read/write helpers
22
+ - refactor: share emptyLedgerAggregation between analytics and ledger store
23
+ - refactor: route spec list subcommand through the shared list command
24
+ - refactor: extract shared collectFiles helper for worker handlers
25
+ - refactor(tests): rename type-only test files to test-d suffix
26
+
27
+
1
28
  ## [5.7.21] - 2026-09-09
2
29
 
3
30
  ### Bug Fixes
@@ -1 +1 @@
1
- {"schemaVersion":1,"commit":"97372664ad3437cbae1a1e5b6f2b043c16bb5559"}
1
+ {"schemaVersion":1,"commit":"7da5da1293b997c72492696106fd3eb613196ce9"}
@@ -9,7 +9,6 @@
9
9
  import { parseArgs } from 'node:util';
10
10
  import { resolve } from 'node:path';
11
11
  import { handleCreateSpec } from '../../tools/create-spec.js';
12
- import { handleListSpecs } from '../../tools/list-specs.js';
13
12
  import { handleUpdateStatus } from '../../tools/update-status.js';
14
13
  import { handleUpdateStatusBatch } from '../../tools/update-status/batch.js';
15
14
  import { handleValidate } from '../../tools/validate.js';
@@ -17,6 +16,7 @@ import { formatToolResult, writeCliResult } from '../formatter.js';
17
16
  import { detectProjectId } from '../project-detector.js';
18
17
  import { bold, cyan, red, dim } from '../colors.js';
19
18
  import { SINGLE_STATUS_PARSE_OPTIONS, buildSingleStatusInput } from './status.js';
19
+ import { listCommand } from './list.js';
20
20
  // ---------------------------------------------------------------------------
21
21
  // Helpers
22
22
  // ---------------------------------------------------------------------------
@@ -110,36 +110,6 @@ async function runCreate(args, flags) {
110
110
  writeCliResult(result, flags, 'Spec created!');
111
111
  }
112
112
  // ---------------------------------------------------------------------------
113
- // Subcommand: spec list
114
- // ---------------------------------------------------------------------------
115
- async function runList(args, flags) {
116
- const { values } = parseArgs({
117
- args,
118
- options: {
119
- status: { type: 'string', short: 's' },
120
- type: { type: 'string', short: 't' },
121
- 'project-id': { type: 'string' },
122
- },
123
- strict: false,
124
- allowPositionals: true,
125
- });
126
- const projectId = values['project-id'] ?? detectProjectId();
127
- const result = await handleListSpecs({
128
- projectId,
129
- status: values.status,
130
- type: values.type,
131
- });
132
- if (result.isError) {
133
- process.stderr.write(`${red(formatToolResult(result, flags))}\n`);
134
- process.exitCode = 1;
135
- return;
136
- }
137
- const output = formatToolResult(result, flags);
138
- if (output) {
139
- process.stdout.write(output + '\n');
140
- }
141
- }
142
- // ---------------------------------------------------------------------------
143
113
  // Subcommand: spec show
144
114
  // ---------------------------------------------------------------------------
145
115
  async function runShow(args, flags) {
@@ -257,7 +227,7 @@ export const specCommand = {
257
227
  await runCreate(rest, flags);
258
228
  break;
259
229
  case 'list':
260
- await runList(rest, flags);
230
+ await listCommand.run(rest, flags);
261
231
  break;
262
232
  case 'show':
263
233
  await runShow(rest, flags);
@@ -0,0 +1,3 @@
1
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
2
+ export declare function mergeDeep<T extends Record<string, unknown>>(base: T, override: Record<string, unknown>): T;
3
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1,12 @@
1
+ export function isRecord(value) {
2
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
3
+ }
4
+ export function mergeDeep(base, override) {
5
+ const result = { ...base };
6
+ for (const [key, value] of Object.entries(override)) {
7
+ const current = result[key];
8
+ result[key] = isRecord(current) && isRecord(value) ? mergeDeep(current, value) : value;
9
+ }
10
+ return result;
11
+ }
12
+ //# sourceMappingURL=object.js.map
@@ -23,6 +23,26 @@ import { join, dirname } from 'node:path';
23
23
  import { fileURLToPath } from 'node:url';
24
24
  const __dirname = dirname(fileURLToPath(import.meta.url));
25
25
  const DATA_DIR = join(__dirname, '..', '..', 'data');
26
+ function validateConfig(schema, area, data) {
27
+ const result = schema.safeParse(data);
28
+ if (result.success) {
29
+ return result.data;
30
+ }
31
+ const details = formatZodError(result.error);
32
+ throw new Error(`Invalid ${area} config: ${details}`);
33
+ }
34
+ function loadSystemConfig(require, area, validate) {
35
+ try {
36
+ const raw = require(`../config/${area}.json`);
37
+ return validate(raw);
38
+ }
39
+ catch (err) {
40
+ if (err instanceof Error && err.message.includes('Invalid')) {
41
+ throw err;
42
+ }
43
+ throw new Error(`System config not found: src/config/${area}.json`, { cause: err });
44
+ }
45
+ }
26
46
  /**
27
47
  * Canonical 3-layer configuration loader.
28
48
  *
@@ -64,27 +84,13 @@ export class ConfigLoader {
64
84
  * a descriptive error with the exact path of the invalid field.
65
85
  */
66
86
  validate(data) {
67
- const result = this.schema.safeParse(data);
68
- if (result.success) {
69
- return result.data;
70
- }
71
- const details = formatZodError(result.error);
72
- throw new Error(`Invalid ${this.area} config: ${details}`);
87
+ return validateConfig(this.schema, this.area, data);
73
88
  }
74
89
  /**
75
90
  * Load only system defaults (src/config/{area}.json).
76
91
  */
77
92
  loadSystem() {
78
- try {
79
- const raw = this.require(`../config/${this.area}.json`);
80
- return this.validate(raw);
81
- }
82
- catch (err) {
83
- if (err instanceof Error && err.message.includes('Invalid')) {
84
- throw err;
85
- }
86
- throw new Error(`System config not found: src/config/${this.area}.json`, { cause: err });
87
- }
93
+ return loadSystemConfig(this.require, this.area, (raw) => this.validate(raw));
88
94
  }
89
95
  // -----------------------------------------------------------------------
90
96
  // Private helpers
@@ -183,25 +189,11 @@ export class ObjectConfigLoader {
183
189
  }
184
190
  /** Validate raw data against the schema. */
185
191
  validate(data) {
186
- const result = this.schema.safeParse(data);
187
- if (result.success) {
188
- return result.data;
189
- }
190
- const details = formatZodError(result.error);
191
- throw new Error(`Invalid ${this.area} config: ${details}`);
192
+ return validateConfig(this.schema, this.area, data);
192
193
  }
193
194
  /** Load system defaults. */
194
195
  loadSystem() {
195
- try {
196
- const raw = this.require(`../config/${this.area}.json`);
197
- return this.validate(raw);
198
- }
199
- catch (err) {
200
- if (err instanceof Error && err.message.includes('Invalid')) {
201
- throw err;
202
- }
203
- throw new Error(`System config not found: src/config/${this.area}.json`, { cause: err });
204
- }
196
+ return loadSystemConfig(this.require, this.area, (raw) => this.validate(raw));
205
197
  }
206
198
  loadFileSync(filePath) {
207
199
  try {
@@ -1,3 +1,5 @@
1
+ import type { ScannedConventions } from '../types/index.js';
2
+ export declare function readConventionsFile(projectPath: string): Promise<ScannedConventions | null>;
1
3
  /**
2
4
  * SPEC-665: Check if conventions.json TTL is expired and trigger a background re-fetch.
3
5
  * Fire-and-forget — never blocks the caller. Silent failure on any error.
@@ -4,7 +4,7 @@ import { readFile, writeFile, mkdir, appendFile } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
5
  const TTL_DAYS = 7;
6
6
  const MS_PER_DAY = 86_400_000;
7
- async function readConventionsFile(projectPath) {
7
+ export async function readConventionsFile(projectPath) {
8
8
  try {
9
9
  const raw = await readFile(join(projectPath, 'planu', 'conventions.json'), 'utf-8');
10
10
  return JSON.parse(raw);
@@ -1,9 +1,4 @@
1
1
  import type { GleamLibraryGroups, CrystalLibraryGroups, NimLibraryGroups, ZigLibraryGroups } from '../../types/index.js';
2
- /**
3
- * Parse gleam.toml [dependencies] section.
4
- * Matches `name = "version"` lines.
5
- */
6
- export declare function parseGleamToml(content: string): Set<string>;
7
2
  /**
8
3
  * Parse shard.yml dependencies section.
9
4
  * Matches top-level package names under `dependencies:` key.
@@ -3,6 +3,7 @@
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
5
  import { glob } from 'glob';
6
+ import { parseTomlDependencies } from './toml-dependencies.js';
6
7
  // === Catalog constants ===
7
8
  const GLEAM_WEB_LIBS = ['gleam_http', 'mist', 'wisp'];
8
9
  const GLEAM_TESTING_LIBS = ['gleeunit', 'gleam_stdlib'];
@@ -24,25 +25,10 @@ function filterPresent(catalog, deps) {
24
25
  * Parse gleam.toml [dependencies] section.
25
26
  * Matches `name = "version"` lines.
26
27
  */
27
- export function parseGleamToml(content) {
28
- const deps = new Set();
29
- const sectionMatch = /\[dependencies\]([\s\S]*?)(?:\n\[|$)/s.exec(content);
30
- if (sectionMatch?.[1]) {
31
- const matches = sectionMatch[1].matchAll(/^([a-zA-Z0-9_-]+)\s*=/gm);
32
- for (const match of matches) {
33
- /* v8 ignore start */
34
- if (match[1]) {
35
- /* v8 ignore stop */
36
- deps.add(match[1]);
37
- }
38
- }
39
- }
40
- return deps;
41
- }
42
28
  async function collectGleamDeps(projectPath) {
43
29
  try {
44
30
  const content = await readFile(join(projectPath, 'gleam.toml'), 'utf-8');
45
- return parseGleamToml(content);
31
+ return parseTomlDependencies(content);
46
32
  }
47
33
  catch {
48
34
  return new Set();
@@ -8,7 +8,6 @@ export declare function parseVMod(content: string): Set<string>;
8
8
  * Parse alire.toml dependencies block.
9
9
  * Matches `name = { version = "..." }` entries.
10
10
  */
11
- export declare function parseAlireToml(content: string): Set<string>;
12
11
  /**
13
12
  * Determine ColdFusion server type by checking config filenames.
14
13
  */
@@ -3,6 +3,7 @@
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
5
  import { glob } from 'glob';
6
+ import { parseTomlDependencies } from './toml-dependencies.js';
6
7
  // === Helpers ===
7
8
  async function globFiles(pattern, projectPath) {
8
9
  try {
@@ -46,21 +47,6 @@ export function parseVMod(content) {
46
47
  * Parse alire.toml dependencies block.
47
48
  * Matches `name = { version = "..." }` entries.
48
49
  */
49
- export function parseAlireToml(content) {
50
- const deps = new Set();
51
- const sectionMatch = /\[dependencies\]([\s\S]*?)(?:\n\[|$)/s.exec(content);
52
- if (sectionMatch?.[1]) {
53
- const matches = sectionMatch[1].matchAll(/^([a-zA-Z0-9_-]+)\s*=/gm);
54
- for (const match of matches) {
55
- /* v8 ignore start */
56
- if (match[1]) {
57
- /* v8 ignore stop */
58
- deps.add(match[1]);
59
- }
60
- }
61
- }
62
- return deps;
63
- }
64
50
  // === ColdFusion server detection ===
65
51
  /**
66
52
  * Determine ColdFusion server type by checking config filenames.
@@ -109,7 +95,7 @@ export async function detectAdaProject(projectPath) {
109
95
  let packages = [];
110
96
  try {
111
97
  const alireContent = await readFile(join(projectPath, 'alire.toml'), 'utf-8');
112
- packages = [...parseAlireToml(alireContent)];
98
+ packages = [...parseTomlDependencies(alireContent)];
113
99
  }
114
100
  catch {
115
101
  // no alire.toml — that's fine
@@ -3,7 +3,8 @@ import { technologyValue } from '../technology-registry.js';
3
3
  // Detects OpenTelemetry installation, backend, SLOs, and whether OTel is needed.
4
4
  import { join } from 'node:path';
5
5
  import { glob } from 'glob';
6
- import { readFileOrNull, readPackageDeps, detectNodeOtel, detectPythonOtel, detectGoOtel, detectRustOtel, detectJavaOtel, MULTISERVICE_DEPS, } from './otel-ecosystem-detectors.js';
6
+ import { readFileOrNull, detectNodeOtel, detectPythonOtel, detectGoOtel, detectRustOtel, detectJavaOtel, MULTISERVICE_DEPS, } from './otel-ecosystem-detectors.js';
7
+ import { readPackageJson } from './llm-detector/file-readers.js';
7
8
  /** Env var pattern indicating an OTLP exporter is configured */
8
9
  const OTEL_EXPORTER_ENV_VARS = [
9
10
  'OTEL_EXPORTER_OTLP_ENDPOINT',
@@ -143,7 +144,7 @@ async function detectNeedsOtel(projectPath, isInstalled, hasMultipleServices) {
143
144
  return true;
144
145
  }
145
146
  // Check for HTTP clients or async workers in package.json
146
- const pkg = await readPackageDeps(projectPath);
147
+ const pkg = await readPackageJson(projectPath);
147
148
  if (pkg) {
148
149
  const all = { ...pkg.deps, ...pkg.devDeps };
149
150
  if (MULTISERVICE_DEPS.some((dep) => dep in all)) {
@@ -159,7 +160,7 @@ async function detectSignals(projectPath, isInstalled) {
159
160
  }
160
161
  const signals = ['traces']; // traces is always included when OTel is installed
161
162
  // Check for metrics and logs packages
162
- const pkg = await readPackageDeps(projectPath);
163
+ const pkg = await readPackageJson(projectPath);
163
164
  if (pkg) {
164
165
  const all = { ...pkg.deps, ...pkg.devDeps };
165
166
  if ('@opentelemetry/sdk-metrics' in all || '@opentelemetry/sdk-metrics-base' in all) {
@@ -4,10 +4,6 @@ export { readFileOrNull };
4
4
  export declare const OTEL_NPM_PACKAGES: string[];
5
5
  /** Dependencies that indicate a project might need OTel (async workers, HTTP clients) */
6
6
  export declare const MULTISERVICE_DEPS: string[];
7
- export declare function readPackageDeps(projectPath: string): Promise<{
8
- deps: Record<string, string>;
9
- devDeps: Record<string, string>;
10
- } | null>;
11
7
  /** Detect OTel for Node.js/TypeScript projects via package.json */
12
8
  export declare function detectNodeOtel(projectPath: string): Promise<boolean>;
13
9
  /** Detect OTel for Python projects via requirements.txt or pyproject.toml */
@@ -3,6 +3,7 @@ import { technologyValue } from '../technology-registry.js';
3
3
  // Per-ecosystem OTel detection helpers extracted from otel-detector.ts.
4
4
  import { join } from 'node:path';
5
5
  import { readFileOrNull } from '../../core/shared/fs.js';
6
+ import { readPackageJson } from './llm-detector/file-readers.js';
6
7
  export { readFileOrNull };
7
8
  // === OTel package patterns per ecosystem ===
8
9
  /** npm package names that indicate OTel is installed */
@@ -32,23 +33,10 @@ export const MULTISERVICE_DEPS = [
32
33
  'amqplib',
33
34
  'nats',
34
35
  ];
35
- export async function readPackageDeps(projectPath) {
36
- const content = await readFileOrNull(join(projectPath, 'package.json'));
37
- if (!content) {
38
- return null;
39
- }
40
- try {
41
- const pkg = JSON.parse(content);
42
- return { deps: pkg.dependencies ?? {}, devDeps: pkg.devDependencies ?? {} };
43
- }
44
- catch {
45
- return null;
46
- }
47
- }
48
36
  // === Per-ecosystem detection ===
49
37
  /** Detect OTel for Node.js/TypeScript projects via package.json */
50
38
  export async function detectNodeOtel(projectPath) {
51
- const pkg = await readPackageDeps(projectPath);
39
+ const pkg = await readPackageJson(projectPath);
52
40
  if (!pkg) {
53
41
  return false;
54
42
  }
@@ -0,0 +1,2 @@
1
+ export declare function parseTomlDependencies(content: string): Set<string>;
2
+ //# sourceMappingURL=toml-dependencies.d.ts.map
@@ -0,0 +1,16 @@
1
+ export function parseTomlDependencies(content) {
2
+ const deps = new Set();
3
+ const sectionMatch = /\[dependencies\]([\s\S]*?)(?:\n\[|$)/s.exec(content);
4
+ if (sectionMatch?.[1]) {
5
+ const matches = sectionMatch[1].matchAll(/^([a-zA-Z0-9_-]+)\s*=/gm);
6
+ for (const match of matches) {
7
+ /* v8 ignore start */
8
+ if (match[1]) {
9
+ /* v8 ignore stop */
10
+ deps.add(match[1]);
11
+ }
12
+ }
13
+ }
14
+ return deps;
15
+ }
16
+ //# sourceMappingURL=toml-dependencies.js.map
@@ -1,11 +1,11 @@
1
1
  // engine/drift-detection/release-status-drift.ts — SPEC-1012
2
2
  // Detects specs that were released on main but still have non-terminal status.
3
3
  import { execFile as execFileCb } from 'node:child_process';
4
- import { readdir, readFile } from 'node:fs/promises';
4
+ import { readFile } from 'node:fs/promises';
5
5
  import { join } from 'node:path';
6
6
  import { promisify } from 'node:util';
7
7
  import { parseSpecIdsFromCommitMessage } from '../release-pipeline/parse-spec-refs.js';
8
- import { closeSpecsOnReleasePublish } from '../release-pipeline/release-spec-closer.js';
8
+ import { closeSpecsOnReleasePublish, resolveSpecDir, } from '../release-pipeline/release-spec-closer.js';
9
9
  const execFile = promisify(execFileCb);
10
10
  const TERMINAL_STATUSES = new Set(['done', 'discarded']);
11
11
  // Require both `chore(release):` (or `chore:`) AND a `vX.Y.Z` sigil so plain
@@ -70,21 +70,6 @@ async function readSpecStatus(specDir) {
70
70
  return null;
71
71
  }
72
72
  }
73
- async function resolveSpecDir(specsRoot, specId) {
74
- let entries;
75
- try {
76
- entries = await readdir(specsRoot);
77
- }
78
- catch {
79
- return null;
80
- }
81
- for (const name of entries) {
82
- if (name.startsWith(`${specId}-`) || name === specId) {
83
- return join(specsRoot, name);
84
- }
85
- }
86
- return null;
87
- }
88
73
  // ---------------------------------------------------------------------------
89
74
  // Exports
90
75
  // ---------------------------------------------------------------------------
@@ -2,6 +2,7 @@ import { constants } from 'node:fs';
2
2
  import { lstat, open, readFile, realpath } from 'node:fs/promises';
3
3
  import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
+ import { isRecord, mergeDeep } from '../../core/shared/object.js';
5
6
  const BUNDLED_POLICY_ID = 'bundled:minimal-implementation-gate';
6
7
  const PROJECT_CONFIG_ID = 'project:planu.json#minimalImplementationGate';
7
8
  const REDACTED_POLICY_MESSAGE = 'Minimality policy source is unavailable (external:redacted).';
@@ -234,17 +235,6 @@ async function readStableJson(source) {
234
235
  throw sourceErrorFor(error);
235
236
  }
236
237
  }
237
- function isRecord(value) {
238
- return typeof value === 'object' && value !== null && !Array.isArray(value);
239
- }
240
- function mergeDeep(base, override) {
241
- const result = { ...base };
242
- for (const [key, value] of Object.entries(override)) {
243
- const current = result[key];
244
- result[key] = isRecord(current) && isRecord(value) ? mergeDeep(current, value) : value;
245
- }
246
- return result;
247
- }
248
238
  function assertString(value, path) {
249
239
  if (value === undefined) {
250
240
  throw new Error(`Invalid minimal implementation policy at ${path}: string is required`);
@@ -4,6 +4,7 @@
4
4
  // Caches provider-reported model IDs in conventions.json with a 7-day TTL.
5
5
  import { readFile, writeFile, mkdir } from 'node:fs/promises';
6
6
  import { join } from 'node:path';
7
+ import { readConventionsFile } from './conventions-ttl.js';
7
8
  const TTL_MS = 7 * 24 * 60 * 60 * 1000;
8
9
  const FETCH_TIMEOUT_MS = 5_000;
9
10
  const MODEL_MAPPING_CACHE_VERSION = 1;
@@ -141,15 +142,6 @@ async function fetchProviderModels(provider, apiKey) {
141
142
  // ---------------------------------------------------------------------------
142
143
  // conventions.json read/write
143
144
  // ---------------------------------------------------------------------------
144
- async function readConventions(projectPath) {
145
- try {
146
- const raw = await readFile(join(projectPath, 'planu', 'conventions.json'), 'utf-8');
147
- return JSON.parse(raw);
148
- }
149
- catch {
150
- return null;
151
- }
152
- }
153
145
  async function patchConventions(projectPath, modelMapping) {
154
146
  const planuDir = join(projectPath, 'planu');
155
147
  await mkdir(planuDir, { recursive: true });
@@ -257,7 +249,7 @@ export async function fetchAndCacheModelMapping(projectPath) {
257
249
  export function triggerModelMappingRefresh(projectPath) {
258
250
  void (async () => {
259
251
  try {
260
- const conventions = await readConventions(projectPath);
252
+ const conventions = await readConventionsFile(projectPath);
261
253
  const configuredProviders = detectAvailableProviders();
262
254
  if (conventions?.modelMapping &&
263
255
  isVerifiedModelMappingCache(conventions.modelMapping) &&
@@ -278,7 +270,7 @@ export function triggerModelMappingRefresh(projectPath) {
278
270
  */
279
271
  export async function resolveModelId(projectPath, tier, preferredProvider = 'anthropic') {
280
272
  try {
281
- const conventions = await readConventions(projectPath);
273
+ const conventions = await readConventionsFile(projectPath);
282
274
  const cache = conventions?.modelMapping;
283
275
  if (!cache || !isVerifiedModelMappingCache(cache) || isModelMappingStale(cache)) {
284
276
  return undefined;
@@ -1,4 +1,6 @@
1
1
  import { technologyValue } from '../technology-registry.js';
2
+ import { join } from 'node:path';
3
+ import { readFileOrNull } from '../../core/shared/fs.js';
2
4
  import { fileExists, hasAnyFile } from '../detection-utils.js';
3
5
  const DESKTOP_FW_SET = new Set([
4
6
  technologyValue('technology-electron-88b1de'),
@@ -31,7 +33,7 @@ export async function detectDesktopFramework(projectPath, framework) {
31
33
  return 'dotnet';
32
34
  }
33
35
  if (await fileExists(projectPath, 'CMakeLists.txt')) {
34
- const cmakeContent = await tryReadFile(projectPath, 'CMakeLists.txt');
36
+ const cmakeContent = await readFileOrNull(join(projectPath, 'CMakeLists.txt'));
35
37
  if (cmakeContent?.includes('Qt')) {
36
38
  return 'qt';
37
39
  }
@@ -58,16 +60,4 @@ export function getEmbeddedWebFramework(knowledge) {
58
60
  }
59
61
  return null;
60
62
  }
61
- async function tryReadFile(basePath, relativePath) {
62
- try {
63
- const fsModule = await import('node:fs/promises');
64
- const pathModule = await import('node:path');
65
- const fullPath = pathModule.join(basePath, relativePath);
66
- return await fsModule.readFile(fullPath, 'utf-8');
67
- }
68
- catch {
69
- /* v8 ignore next */
70
- return null;
71
- }
72
- }
73
63
  //# sourceMappingURL=desktop.js.map
@@ -1,4 +1,6 @@
1
1
  import { technologyValue } from '../technology-registry.js';
2
+ import { join } from 'node:path';
3
+ import { readFileOrNull } from '../../core/shared/fs.js';
2
4
  import { fileExists, hasAnyFile } from '../detection-utils.js';
3
5
  const GAME_FW_SET = new Set(['unity', 'godot', 'unreal', 'bevy', 'phaser', 'pygame']);
4
6
  /**
@@ -33,7 +35,7 @@ export async function detectGameEngine(projectPath, framework) {
33
35
  }
34
36
  // Bevy or Macroquad: Cargo.toml with bevy or macroquad dependency
35
37
  if (await fileExists(projectPath, 'Cargo.toml')) {
36
- const cargoContent = await tryReadFile(projectPath, 'Cargo.toml');
38
+ const cargoContent = await readFileOrNull(join(projectPath, 'Cargo.toml'));
37
39
  if (cargoContent !== null && /bevy|macroquad/.test(cargoContent)) {
38
40
  return 'bevy';
39
41
  }
@@ -54,16 +56,4 @@ export function getGameEngineLanguage(engine) {
54
56
  };
55
57
  return languageMap[engine];
56
58
  }
57
- async function tryReadFile(basePath, relativePath) {
58
- try {
59
- const fsModule = await import('node:fs/promises');
60
- const pathModule = await import('node:path');
61
- const fullPath = pathModule.join(basePath, relativePath);
62
- return await fsModule.readFile(fullPath, 'utf-8');
63
- }
64
- catch {
65
- /* v8 ignore next */
66
- return null;
67
- }
68
- }
69
59
  //# sourceMappingURL=games.js.map
@@ -1,4 +1,5 @@
1
1
  import type { ReleaseSpecCloseInput, SpecCloseResult } from '../../types/release-pipeline.js';
2
+ export declare function resolveSpecDir(specsRoot: string, specId: string): Promise<string | null>;
2
3
  /**
3
4
  * Close all specs referenced in the release commit message.
4
5
  *
@@ -120,7 +120,7 @@ async function isReachableFromMain(commitSha, projectPath) {
120
120
  // ---------------------------------------------------------------------------
121
121
  // Spec resolution
122
122
  // ---------------------------------------------------------------------------
123
- async function resolveSpecDir(specsRoot, specId) {
123
+ export async function resolveSpecDir(specsRoot, specId) {
124
124
  let entries;
125
125
  try {
126
126
  entries = await readdir(specsRoot);