@planu/cli 5.7.21 → 5.7.23

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 (92) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/.planu-build.json +1 -1
  3. package/dist/cli/commands/release.js +23 -10
  4. package/dist/cli/commands/spec.js +2 -32
  5. package/dist/config/registries/error-recovery.json +18 -18
  6. package/dist/config/registries/legacy-guidance.json +33 -1
  7. package/dist/config/server-instructions.js +16 -20
  8. package/dist/config/skill-templates/planu-release.md +3 -3
  9. package/dist/config/token-waste-autopilot.json +1 -1
  10. package/dist/core/shared/object.d.ts +3 -0
  11. package/dist/core/shared/object.js +12 -0
  12. package/dist/engine/config-loader.js +24 -32
  13. package/dist/engine/conventions-ttl.d.ts +2 -0
  14. package/dist/engine/conventions-ttl.js +1 -1
  15. package/dist/engine/detectors/library-detector-langs3b.d.ts +0 -5
  16. package/dist/engine/detectors/library-detector-langs3b.js +2 -16
  17. package/dist/engine/detectors/library-detector-langs5.d.ts +0 -1
  18. package/dist/engine/detectors/library-detector-langs5.js +2 -16
  19. package/dist/engine/detectors/otel-detector.js +4 -3
  20. package/dist/engine/detectors/otel-ecosystem-detectors.d.ts +0 -4
  21. package/dist/engine/detectors/otel-ecosystem-detectors.js +2 -14
  22. package/dist/engine/detectors/toml-dependencies.d.ts +2 -0
  23. package/dist/engine/detectors/toml-dependencies.js +16 -0
  24. package/dist/engine/drift-detection/release-status-drift.js +2 -17
  25. package/dist/engine/errors/registry-loader.js +3 -2
  26. package/dist/engine/evidence-gates/artifact-reader.d.ts +78 -0
  27. package/dist/engine/evidence-gates/artifact-reader.js +19 -7
  28. package/dist/engine/health/auto-fixer.js +2 -2
  29. package/dist/engine/minimality/policy-loader.js +1 -11
  30. package/dist/engine/model-tier-resolver.js +3 -11
  31. package/dist/engine/platform-detector/desktop.js +3 -13
  32. package/dist/engine/platform-detector/games.js +3 -13
  33. package/dist/engine/release-pipeline/release-spec-closer.d.ts +1 -0
  34. package/dist/engine/release-pipeline/release-spec-closer.js +1 -1
  35. package/dist/engine/safety/cross-process-lock.js +6 -21
  36. package/dist/engine/safety/lock-scavenger.d.ts +3 -1
  37. package/dist/engine/safety/lock-scavenger.js +3 -3
  38. package/dist/engine/score-to-grade.d.ts +2 -0
  39. package/dist/engine/score-to-grade.js +16 -0
  40. package/dist/engine/spec-grounding/contract.js +2 -1
  41. package/dist/engine/spec-grounding/grounding-entry-parser.d.ts +0 -1
  42. package/dist/engine/spec-grounding/grounding-entry-parser.js +1 -3
  43. package/dist/engine/telemetry/health-checker.js +2 -20
  44. package/dist/engine/telemetry/telemetry-client.d.ts +1 -0
  45. package/dist/engine/telemetry/telemetry-client.js +1 -1
  46. package/dist/engine/test-scaffold-generator/advanced-scaffold.js +1 -24
  47. package/dist/engine/token-optimizer/analytics.d.ts +1 -1
  48. package/dist/engine/token-optimizer/analytics.js +2 -22
  49. package/dist/engine/token-optimizer/policy-loader.js +1 -11
  50. package/dist/engine/validation-evidence-ledger.d.ts +1 -0
  51. package/dist/engine/validation-evidence-ledger.js +44 -3
  52. package/dist/engine/workers/handlers/code-map.js +4 -46
  53. package/dist/engine/workers/handlers/collect-files.d.ts +3 -0
  54. package/dist/engine/workers/handlers/collect-files.js +53 -0
  55. package/dist/engine/workers/handlers/documentation.js +4 -49
  56. package/dist/engine/workers/handlers/optimization.js +4 -46
  57. package/dist/engine/workers/handlers/security-audit.js +4 -45
  58. package/dist/hosts/codex/config-scaffold.js +1 -1
  59. package/dist/hosts/gemini/config-scaffold.js +1 -1
  60. package/dist/storage/spec-index.js +8 -3
  61. package/dist/storage/token-ledger-store.d.ts +1 -1
  62. package/dist/storage/token-ledger-store.js +2 -22
  63. package/dist/tools/audit.js +1 -15
  64. package/dist/tools/claude-settings-file.d.ts +3 -0
  65. package/dist/tools/claude-settings-file.js +19 -0
  66. package/dist/tools/create-spec/post-creation.d.ts +1 -1
  67. package/dist/tools/create-spec/post-creation.js +7 -49
  68. package/dist/tools/create-spec.js +1 -1
  69. package/dist/tools/facilitate.js +6 -6
  70. package/dist/tools/init-project/result-builder.js +4 -4
  71. package/dist/tools/reconcile-interactive-question-hooks.js +3 -18
  72. package/dist/tools/reconcile-session-safeguard-hook.js +3 -18
  73. package/dist/tools/reconcile-spec-sanctity-hook.js +4 -19
  74. package/dist/tools/safe-handler.js +1 -1
  75. package/dist/tools/status-handler.js +1 -1
  76. package/dist/tools/tool-registry/core-tools.js +3 -1
  77. package/dist/tools/update-status/evidence-payload.d.ts +180 -0
  78. package/dist/tools/update-status/evidence-payload.js +76 -0
  79. package/dist/tools/update-status/index.js +30 -0
  80. package/dist/tools/validate.js +2 -16
  81. package/dist/types/evidence-gates.d.ts +9 -0
  82. package/dist/types/lifecycle.d.ts +1 -10
  83. package/dist/types/spec/inputs.d.ts +2 -1
  84. package/dist/types/token-ledger.d.ts +1 -0
  85. package/dist/types/token-ledger.js +21 -1
  86. package/package.json +1 -1
  87. package/planu-plugin.json +14 -4
  88. package/src/i18n/messages/en.json +2 -2
  89. package/src/i18n/messages/es.json +2 -2
  90. package/src/i18n/messages/pt.json +2 -2
  91. package/dist/engine/detectors/cicd-detector.d.ts +0 -7
  92. package/dist/engine/detectors/cicd-detector.js +0 -170
@@ -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
  // ---------------------------------------------------------------------------
@@ -1,7 +1,8 @@
1
1
  // engine/errors/registry-loader.ts — SPEC-902: Singleton error recovery registry
2
- import { join } from 'node:path';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
3
4
  import { RecoveryRegistry } from './recovery-registry.js';
4
- const PACKAGE_REGISTRY_PATH = join(process.cwd(), 'src', 'config', 'registries', 'error-recovery.json');
5
+ const PACKAGE_REGISTRY_PATH = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'config', 'registries', 'error-recovery.json');
5
6
  let cachedRegistry;
6
7
  let loadPromise;
7
8
  function getErrorRecoveryRegistry() {
@@ -30,6 +30,84 @@ export declare const DiscoverySchema: z.ZodObject<{
30
30
  }, z.core.$strict>>;
31
31
  }, z.core.$strict>;
32
32
  export declare const DISCOVERY_TEMPLATE_OVERRIDES: Record<string, unknown>;
33
+ export declare const TaskPlanSchema: z.ZodObject<{
34
+ version: z.ZodLiteral<1>;
35
+ provenance: z.ZodOptional<z.ZodObject<{
36
+ receiptId: z.ZodString;
37
+ artifactDigest: z.ZodString;
38
+ specId: z.ZodString;
39
+ issuerId: z.ZodString;
40
+ }, z.core.$strict>>;
41
+ generatedBy: z.ZodOptional<z.ZodLiteral<"planu-evidence-skeleton">>;
42
+ tasks: z.ZodArray<z.ZodObject<{
43
+ id: z.ZodString;
44
+ title: z.ZodString;
45
+ acceptanceCriteria: z.ZodArray<z.ZodString>;
46
+ status: z.ZodEnum<{
47
+ doing: "doing";
48
+ done: "done";
49
+ pending: "pending";
50
+ }>;
51
+ }, z.core.$strict>>;
52
+ }, z.core.$strict>;
53
+ export declare const TraceabilityMatrixSchema: z.ZodObject<{
54
+ version: z.ZodLiteral<1>;
55
+ provenance: z.ZodOptional<z.ZodObject<{
56
+ receiptId: z.ZodString;
57
+ artifactDigest: z.ZodString;
58
+ specId: z.ZodString;
59
+ issuerId: z.ZodString;
60
+ }, z.core.$strict>>;
61
+ rows: z.ZodArray<z.ZodObject<{
62
+ acceptanceCriterion: z.ZodString;
63
+ scenario: z.ZodOptional<z.ZodString>;
64
+ testEvidence: z.ZodOptional<z.ZodArray<z.ZodString>>;
65
+ contractEvidence: z.ZodOptional<z.ZodArray<z.ZodString>>;
66
+ manualEvidence: z.ZodOptional<z.ZodString>;
67
+ changedFiles: z.ZodArray<z.ZodString>;
68
+ validationEvidence: z.ZodOptional<z.ZodString>;
69
+ reviewerEvidence: z.ZodOptional<z.ZodString>;
70
+ commandEvidence: z.ZodOptional<z.ZodObject<{
71
+ capability: z.ZodEnum<{
72
+ contract: "contract";
73
+ coverage: "coverage";
74
+ "fault-injection": "fault-injection";
75
+ lint: "lint";
76
+ migration: "migration";
77
+ native: "native";
78
+ reproducibility: "reproducibility";
79
+ security: "security";
80
+ "test-full": "test-full";
81
+ "test-related": "test-related";
82
+ typecheck: "typecheck";
83
+ website: "website";
84
+ }>;
85
+ command: z.ZodString;
86
+ scope: z.ZodArray<z.ZodString>;
87
+ relevantPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
88
+ evidenceKey: z.ZodString;
89
+ }, z.core.$strict>>;
90
+ }, z.core.$strict>>;
91
+ }, z.core.$strict>;
92
+ export declare const ContractValidationSchema: z.ZodObject<{
93
+ version: z.ZodLiteral<1>;
94
+ provenance: z.ZodOptional<z.ZodObject<{
95
+ receiptId: z.ZodString;
96
+ artifactDigest: z.ZodString;
97
+ specId: z.ZodString;
98
+ issuerId: z.ZodString;
99
+ }, z.core.$strict>>;
100
+ kind: z.ZodEnum<{
101
+ api: "api";
102
+ event: "event";
103
+ graphql: "graphql";
104
+ mcp: "mcp";
105
+ ui: "ui";
106
+ }>;
107
+ passed: z.ZodBoolean;
108
+ reportPath: z.ZodOptional<z.ZodString>;
109
+ summary: z.ZodOptional<z.ZodString>;
110
+ }, z.core.$strict>;
33
111
  /** Digest of canonical artifact content; the provenance envelope is excluded. */
34
112
  export declare function evidenceArtifactDigest(artifact: unknown): string;
35
113
  export declare function evidenceArtifactCollectionDigest(artifacts: readonly {
@@ -6,7 +6,7 @@ import { isAbsolute, join, relative, resolve } from 'node:path';
6
6
  import { z } from 'zod';
7
7
  // eslint-disable-next-line no-restricted-imports -- grandfathered layer violation, remediation SPEC-1661 SPEC-1662 SPEC-1663
8
8
  import { projectDataDir } from '../../storage/base-store.js';
9
- import { computeValidationEvidenceIdentity, computeValidationEvidenceKey, normalizeValidationCommand, readMatchingValidationEvidence, } from '../validation-evidence-ledger.js';
9
+ import { computeValidationEvidenceIdentity, normalizeValidationCommand, readPassedValidationReceipt, } from '../validation-evidence-ledger.js';
10
10
  import { VALIDATION_COMMANDS } from '../validation-impact-planner.js';
11
11
  import { renderSchemaSkeleton } from '../handoff-artifacts/schema-skeleton.js';
12
12
  import { isExecutableTestPath } from '../spec-format/executable-test-path.js';
@@ -62,7 +62,7 @@ export const DiscoverySchema = z
62
62
  export const DISCOVERY_TEMPLATE_OVERRIDES = {
63
63
  'openQuestions[].status': 'resolved',
64
64
  };
65
- const TaskPlanSchema = z
65
+ export const TaskPlanSchema = z
66
66
  .object({
67
67
  version: z.literal(1),
68
68
  provenance: ProvenanceSchema.optional(),
@@ -81,7 +81,7 @@ const TaskPlanSchema = z
81
81
  .strict();
82
82
  const MAX_CHANGED_FILES_PER_ROW = 200;
83
83
  const CHANGED_FILES_OVERFLOW_MESSAGE = `changedFiles holds at most ${MAX_CHANGED_FILES_PER_ROW} entries per row. For a wider change, list each containing directory as a repository-relative path without a trailing slash (for example "tests") and declare that same directory path under the spec "## Files" ownership, through reconcile_spec when the spec is already approved, so the done drift check matches it.`;
84
- const TraceabilityMatrixSchema = z
84
+ export const TraceabilityMatrixSchema = z
85
85
  .object({
86
86
  version: z.literal(1),
87
87
  provenance: ProvenanceSchema.optional(),
@@ -113,7 +113,7 @@ const TraceabilityMatrixSchema = z
113
113
  .max(1000),
114
114
  })
115
115
  .strict();
116
- const ContractValidationSchema = z
116
+ export const ContractValidationSchema = z
117
117
  .object({
118
118
  version: z.literal(1),
119
119
  provenance: ProvenanceSchema.optional(),
@@ -235,10 +235,22 @@ export function traceabilityRowHasCurrentCommandEvidence(row, args) {
235
235
  scope: evidence.scope,
236
236
  ...(evidence.relevantPaths === undefined ? {} : { relevantPaths: evidence.relevantPaths }),
237
237
  };
238
- const currentKey = computeValidationEvidenceKey(computeValidationEvidenceIdentity(input));
239
- return (currentKey === evidence.evidenceKey &&
240
- readMatchingValidationEvidence(args.projectId, input)?.status === 'passed');
238
+ const receipt = readPassedValidationReceipt(args.projectId, evidence.evidenceKey);
239
+ if (!receipt) {
240
+ return false;
241
+ }
242
+ const currentIdentity = computeValidationEvidenceIdentity(input);
243
+ return REPOSITORY_IDENTITY_FIELDS.every((field) => receipt.identity[field] === currentIdentity[field]);
241
244
  }
245
+ const REPOSITORY_IDENTITY_FIELDS = [
246
+ 'schemaVersion',
247
+ 'capability',
248
+ 'normalizedCommand',
249
+ 'sourceTreeDigest',
250
+ 'lockDigest',
251
+ 'configDigest',
252
+ 'selectedScopeDigest',
253
+ ];
242
254
  const ARTIFACT_HINTS = {
243
255
  'Discovery evidence': 'Expected discovery.json with { version: 1, rules: string[], examples: [{ rule, example }], openQuestions: [{ question, status, resolution? }], outOfScope: string[], glossary: [{ term, meaning }] }.',
244
256
  'Task plan evidence': 'Expected task-plan.json with { version: 1, tasks: [{ id, title, acceptanceCriteria: string[], status: "pending"|"doing"|"done" }] }. Acceptance criteria may be full text or stable IDs such as AC1 when they map to the canonical criteria order.',
@@ -37,7 +37,7 @@ function buildSkipForIncompleteSpec(specId) {
37
37
  manualSteps: [
38
38
  `Open planu/specs/${specId}/spec.md`,
39
39
  'Add title, description, and at least one acceptance criterion',
40
- 'Re-run health_check_all to verify',
40
+ 'Re-run check_readiness to verify',
41
41
  ],
42
42
  };
43
43
  }
@@ -57,7 +57,7 @@ function buildSkipForDrift(specId) {
57
57
  issue: `drift-detected: ${specId}`,
58
58
  reason: 'Drift requires manual reconciliation between spec and implementation',
59
59
  manualSteps: [
60
- `Run detect_drift with specId: "${specId}" for a detailed report`,
60
+ `Run reconcile_spec with specId: "${specId}" to record the drift`,
61
61
  'Review which criteria are no longer implemented',
62
62
  'Either update the spec or fix the code to match',
63
63
  ],
@@ -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);
@@ -61,7 +61,7 @@ import { hashProjectPath } from '../../storage/base-store.js';
61
61
  import { resolveStorageLayout } from '../../storage/storage-layout.js';
62
62
  import { computeStaleReason, isPidDead, STALE_THRESHOLD_MS } from './lock-staleness.js';
63
63
  import { LockLeaseStore, } from './lock-lease-store.js';
64
- import { scavengeStaleLockArtifacts } from './lock-scavenger.js';
64
+ import { scavengeStaleLockArtifacts, lockMetadata } from './lock-scavenger.js';
65
65
  import { assertNoObsoleteFileLock, assertSafeLockResourceId, assertSafeLockScopeId, } from './obsolete-lock-guard.js';
66
66
  export { getLockScavengeMetrics, resetLockScavengeMetricsForTests, scavengeStaleLockArtifacts, } from './lock-scavenger.js';
67
67
  const LOCK_NAMESPACE = 'spec';
@@ -91,21 +91,6 @@ function clampTtl(ttlMs) {
91
91
  const ttl = ttlMs ?? DEFAULT_TTL_MS;
92
92
  return Math.min(Math.max(ttl, MIN_TTL_MS), MAX_TTL_MS);
93
93
  }
94
- function toMetadata(record) {
95
- return {
96
- specId: record.resourceId,
97
- scopeId: record.scopeId,
98
- pid: record.pid,
99
- sessionId: record.sessionId,
100
- hostname: record.hostname,
101
- acquiredAt: new Date(record.acquiredAtMs).toISOString(),
102
- lastHeartbeatAt: new Date(record.heartbeatAtMs).toISOString(),
103
- ttlMs: record.hardExpiresAtMs - record.acquiredAtMs,
104
- lockId: record.lockId,
105
- fencingToken: record.fencingToken,
106
- ...(record.reason === undefined ? {} : { reason: record.reason }),
107
- };
108
- }
109
94
  function candidate(key, options, nowMs) {
110
95
  const ttlMs = clampTtl(options?.ttlMs);
111
96
  return {
@@ -121,10 +106,10 @@ function candidate(key, options, nowMs) {
121
106
  };
122
107
  }
123
108
  function isRecordStale(record, nowMs) {
124
- return computeStaleReason(toMetadata(record), osHostname(), nowMs) !== undefined;
109
+ return computeStaleReason(lockMetadata(record), osHostname(), nowMs) !== undefined;
125
110
  }
126
111
  function buildHandle(record) {
127
- const metadata = toMetadata(record);
112
+ const metadata = lockMetadata(record);
128
113
  const key = {
129
114
  namespace: record.namespace,
130
115
  scopeId: record.scopeId,
@@ -197,7 +182,7 @@ export async function acquireLock(projectPath, specId, options) {
197
182
  let acquired = store.acquire(next);
198
183
  if (acquired === undefined) {
199
184
  const current = store.get(key);
200
- if (current !== undefined && isPidDead(toMetadata(current), osHostname())) {
185
+ if (current !== undefined && isPidDead(lockMetadata(current), osHostname())) {
201
186
  acquired = store.reclaim({
202
187
  ...key,
203
188
  expectedLockId: current.lockId,
@@ -248,7 +233,7 @@ export function isLocked(projectPath, specId) {
248
233
  if (record === undefined) {
249
234
  return Promise.resolve(null);
250
235
  }
251
- const metadata = toMetadata(record);
236
+ const metadata = lockMetadata(record);
252
237
  const staleReason = computeStaleReason(metadata, osHostname(), Date.now());
253
238
  return Promise.resolve({
254
239
  ...metadata,
@@ -272,7 +257,7 @@ export async function listActiveCrossProcessLocks(projectPath) {
272
257
  const nowMs = Date.now();
273
258
  return store
274
259
  .list({ namespace: LOCK_NAMESPACE, scopeId: projectId(projectPath) })
275
- .map(toMetadata)
260
+ .map(lockMetadata)
276
261
  .map((metadata) => {
277
262
  const staleReason = computeStaleReason(metadata, osHostname(), nowMs);
278
263
  return {
@@ -1,6 +1,8 @@
1
- import type { LockScavengeMetrics } from '../../types/spec-lock-v2.js';
1
+ import type { CrossProcessLockMetadata, LockScavengeMetrics } from '../../types/spec-lock-v2.js';
2
+ import { type LockLeaseRecord } from './lock-lease-store.js';
2
3
  export declare function getLockScavengeMetrics(): Readonly<LockScavengeMetrics>;
3
4
  export declare function resetLockScavengeMetricsForTests(): void;
5
+ export declare function lockMetadata(record: LockLeaseRecord): CrossProcessLockMetadata;
4
6
  /** Reclaim stale SQLite leases with CAS and remove obsolete legacy lock artifacts. */
5
7
  export declare function scavengeStaleLockArtifacts(projectPath: string, onlySpecId?: string): Promise<LockScavengeMetrics>;
6
8
  //# sourceMappingURL=lock-scavenger.d.ts.map
@@ -80,7 +80,7 @@ export function resetLockScavengeMetricsForTests() {
80
80
  function projectId(projectPathOrId) {
81
81
  return isAbsolute(projectPathOrId) ? hashProjectPath(projectPathOrId) : projectPathOrId;
82
82
  }
83
- function metadata(record) {
83
+ export function lockMetadata(record) {
84
84
  return {
85
85
  specId: record.resourceId,
86
86
  scopeId: record.scopeId,
@@ -157,12 +157,12 @@ export async function scavengeStaleLockArtifacts(projectPath, onlySpecId) {
157
157
  .list({ namespace: LOCK_NAMESPACE, scopeId })
158
158
  .filter((lease) => onlySpecId === undefined || lease.resourceId === onlySpecId);
159
159
  for (const lease of leases) {
160
- const staleReason = computeStaleReason(metadata(lease), osHostname(), nowMs);
160
+ const staleReason = computeStaleReason(lockMetadata(lease), osHostname(), nowMs);
161
161
  if (staleReason === undefined) {
162
162
  delta.preservedLive += 1;
163
163
  continue;
164
164
  }
165
- if (!isPidDead(metadata(lease), osHostname())) {
165
+ if (!isPidDead(lockMetadata(lease), osHostname())) {
166
166
  delta.preservedLive += 1;
167
167
  continue;
168
168
  }
@@ -0,0 +1,2 @@
1
+ export declare function scoreToGrade(score: number): string;
2
+ //# sourceMappingURL=score-to-grade.d.ts.map
@@ -0,0 +1,16 @@
1
+ export function scoreToGrade(score) {
2
+ if (score >= 90) {
3
+ return 'A';
4
+ }
5
+ if (score >= 80) {
6
+ return 'B';
7
+ }
8
+ if (score >= 70) {
9
+ return 'C';
10
+ }
11
+ if (score >= 60) {
12
+ return 'D';
13
+ }
14
+ return 'F';
15
+ }
16
+ //# sourceMappingURL=score-to-grade.js.map
@@ -1,6 +1,7 @@
1
1
  import YAML from 'yaml';
2
2
  import { createCriterionIdentity, normalizeCriterionText } from '../criterion-identity.js';
3
- import { isRecord, toCriterionGroundingRecord, toTechnicalReferenceGroundingRecord, } from './grounding-entry-parser.js';
3
+ import { toCriterionGroundingRecord, toTechnicalReferenceGroundingRecord, } from './grounding-entry-parser.js';
4
+ import { isRecord } from '../../core/shared/object.js';
4
5
  const GENERIC_CRITERION_PATTERNS = [
5
6
  /\bimplementation complete\b/i,
6
7
  /\bcomplete and tested\b/i,
@@ -1,5 +1,4 @@
1
1
  import type { CriterionGroundingRecord, GroundingEntryOutcome, TechnicalReferenceGroundingRecord } from '../../types/spec-grounding.js';
2
- export declare function isRecord(value: unknown): value is Record<string, unknown>;
3
2
  export declare function toCriterionGroundingRecord(entry: unknown, index: number): GroundingEntryOutcome<CriterionGroundingRecord>;
4
3
  export declare function toTechnicalReferenceGroundingRecord(entry: unknown, index: number): GroundingEntryOutcome<TechnicalReferenceGroundingRecord>;
5
4
  //# sourceMappingURL=grounding-entry-parser.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { isRecord } from '../../core/shared/object.js';
1
2
  const GROUNDING_SOURCES = [
2
3
  'user_input',
3
4
  'project_evidence',
@@ -11,9 +12,6 @@ const TECHNICAL_REFERENCE_SECTIONS = [
11
12
  'modify',
12
13
  'test',
13
14
  ];
14
- export function isRecord(value) {
15
- return typeof value === 'object' && value !== null && !Array.isArray(value);
16
- }
17
15
  function stringifyDiagnosticValue(value) {
18
16
  if (typeof value === 'string') {
19
17
  return value;