@planu/cli 5.1.1 → 5.2.0

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 (60) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/cli/commands/doctor.d.ts +22 -0
  3. package/dist/cli/commands/doctor.js +176 -2
  4. package/dist/engine/autopilot/bootstrap.js +27 -0
  5. package/dist/engine/core-bridge.d.ts +28 -0
  6. package/dist/engine/core-bridge.js +67 -0
  7. package/dist/engine/drift-monitor.js +16 -18
  8. package/dist/engine/living-spec/hash-tracker.js +26 -28
  9. package/dist/engine/planu-core.darwin-arm64.node.manifest.json +7 -7
  10. package/dist/engine/planu-core.darwin-arm64.node.sbom.json +4 -4
  11. package/dist/engine/planu-core.darwin-x64.node.manifest.json +7 -7
  12. package/dist/engine/planu-core.darwin-x64.node.sbom.json +4 -4
  13. package/dist/engine/planu-core.linux-arm64-gnu.node.manifest.json +7 -7
  14. package/dist/engine/planu-core.linux-arm64-gnu.node.sbom.json +4 -4
  15. package/dist/engine/planu-core.linux-arm64-musl.node.manifest.json +7 -7
  16. package/dist/engine/planu-core.linux-arm64-musl.node.sbom.json +4 -4
  17. package/dist/engine/planu-core.linux-x64-gnu.node.manifest.json +7 -7
  18. package/dist/engine/planu-core.linux-x64-gnu.node.sbom.json +4 -4
  19. package/dist/engine/planu-core.linux-x64-musl.node.manifest.json +7 -7
  20. package/dist/engine/planu-core.linux-x64-musl.node.sbom.json +4 -4
  21. package/dist/engine/planu-core.win32-arm64-msvc.node.manifest.json +7 -7
  22. package/dist/engine/planu-core.win32-arm64-msvc.node.sbom.json +4 -4
  23. package/dist/engine/planu-core.win32-x64-msvc.node.manifest.json +7 -7
  24. package/dist/engine/planu-core.win32-x64-msvc.node.sbom.json +4 -4
  25. package/dist/engine/spec-language/english-only.d.ts +14 -0
  26. package/dist/engine/spec-language/english-only.js +58 -0
  27. package/dist/engine/spec-migrator/criteria-scanner.js +11 -13
  28. package/dist/engine/spec-migrator/drift-detector.js +10 -12
  29. package/dist/engine/vector-store/tfidf.d.ts +13 -9
  30. package/dist/engine/vector-store/tfidf.js +26 -0
  31. package/dist/engine/worker-config-loader.d.ts +1 -1
  32. package/dist/engine/worker-config-loader.js +1 -11
  33. package/dist/engine/workers/schema.d.ts +0 -8
  34. package/dist/engine/workers/schema.js +0 -1
  35. package/dist/i18n/index.d.ts +18 -0
  36. package/dist/i18n/index.js +40 -1
  37. package/dist/storage/global-store.d.ts +9 -0
  38. package/dist/storage/global-store.js +23 -0
  39. package/dist/storage/semantic-index-store.d.ts +23 -0
  40. package/dist/storage/semantic-index-store.js +105 -0
  41. package/dist/storage/status-store/self-healing.js +15 -17
  42. package/dist/tools/challenge-spec/scenarios-utils.js +5 -1
  43. package/dist/tools/create-spec.js +60 -15
  44. package/dist/tools/init-project/handler.js +78 -25
  45. package/dist/tools/learn.js +10 -8
  46. package/dist/tools/registry/auth.js +1 -11
  47. package/dist/tools/semantic-search-handler.js +5 -6
  48. package/dist/tools/status-handler.js +19 -6
  49. package/dist/tools/validation-loop-handler.js +16 -15
  50. package/dist/types/spec-language-translation.d.ts +18 -0
  51. package/dist/types/spec-language-translation.js +5 -0
  52. package/dist/types/spec-registry.d.ts +0 -2
  53. package/dist/types/status.d.ts +2 -0
  54. package/dist/types/vector-store.d.ts +18 -0
  55. package/dist/types/workers.d.ts +0 -3
  56. package/package.json +9 -9
  57. package/planu-native.json +8 -29
  58. package/planu-plugin.json +1 -1
  59. package/dist/engine/security/cve-refresher.d.ts +0 -12
  60. package/dist/engine/security/cve-refresher.js +0 -128
package/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ ## [5.2.0] - 2026-08-04
2
+
3
+ ### Features
4
+ - feat(autopilot): refresh semantic index fire-and-forget on spec:created (SPEC-1345)
5
+ - feat(i18n): auto-detect and persist user locale (SPEC-1347)
6
+ - feat(spec-language): offer translation instead of rejecting non-English specs (SPEC-1342)
7
+ - feat(semantic-search): persist index with incremental updates (SPEC-1345)
8
+
9
+ ### Bug Fixes
10
+ - fix(storage): classify non-ENOENT failures in sync global-config read
11
+ - fix(status): prefer implementing work over review work in compact status (SPEC-1228)
12
+ - fix(challenge): stop handler names activating event scenarios across clauses (SPEC-1262)
13
+
14
+ ### Performance
15
+ - perf(core-bridge): route main-thread hot paths through native dispatch (SPEC-1344)
16
+ - perf(init-project): parallelize independent pipeline stages (SPEC-1343)
17
+
18
+ ### Chores
19
+ - chore(website): regenerate deterministic product proof
20
+ - chore(planu): close lifecycle for 8 specs done + SPEC-1368 bug spec + session checkpoint
21
+ - chore(planu): file SPEC-1367 dogfood bug spec (validate false-negative on test-only criteria)
22
+ - chore(planu): file SPEC-1366 dogfood bug spec and refresh session context
23
+ - chore(doctor): remove commercial remnants and deepen diagnostics (SPEC-1346)
24
+ - chore(planu): file SPEC-1365 dogfood bug spec (teamSuggestion recommends unregistered tools)
25
+ - chore(planu): session checkpoint after v5.1.1 release
26
+
27
+
1
28
  ## [5.1.1] - 2026-08-04
2
29
 
3
30
  ### Bug Fixes
@@ -10,7 +10,29 @@ interface ToolCheck {
10
10
  paths: string[];
11
11
  format: 'standard' | 'zed';
12
12
  }
13
+ interface DeepCheckResult {
14
+ name: string;
15
+ /** 'warn' is a degraded-but-working state (e.g. TS fallback active); 'fail' blocks usage. */
16
+ status: 'ok' | 'warn' | 'fail';
17
+ detail: string;
18
+ }
13
19
  declare function checkTool(check: ToolCheck): ToolReport[];
20
+ /** Check (1): the running Node version satisfies the `engines.node` field in package.json. */
21
+ declare function checkNodeVersion(): DeepCheckResult;
22
+ /**
23
+ * Check (2): the native Rust module loads, with a remediation hint when it doesn't.
24
+ * Missing native is a supported degraded mode (TypeScript fallback stays correct), so
25
+ * this reports 'warn' rather than 'fail' — it never blocks `planu doctor`'s exit code.
26
+ */
27
+ declare function checkNativeModule(): DeepCheckResult;
28
+ /** Check (3): PLANU_HOME / the resolved data directory is writable. */
29
+ declare function checkDataDirWritable(): DeepCheckResult;
30
+ /** Check (4): the runtime SQLite database opens without corruption. */
31
+ declare function checkRuntimeDatabase(): DeepCheckResult;
32
+ /** Check (5): the active locale resolves to a real translated message. */
33
+ declare function checkLocaleResolution(): DeepCheckResult;
34
+ declare function runDeepChecks(): DeepCheckResult[];
35
+ export { checkNodeVersion, checkNativeModule, checkDataDirWritable, checkRuntimeDatabase, checkLocaleResolution, runDeepChecks, };
14
36
  export { checkTool };
15
37
  export declare const doctorCommand: CliCommand;
16
38
  //# sourceMappingURL=doctor.d.ts.map
@@ -1,9 +1,16 @@
1
1
  // cli/commands/doctor.ts — planu doctor: verify MCP installations health (SPEC-236)
2
- import { existsSync } from 'node:fs';
2
+ // Deep diagnostics (Node version, native engine, storage writability, runtime DB,
3
+ // locale resolution) added by SPEC-1346 / SPEC-1344.
4
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
3
5
  import { homedir } from 'node:os';
4
- import { join } from 'node:path';
6
+ import { dirname, join } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
5
8
  import { bold, cyan, green, yellow, red, dim } from '../colors.js';
6
9
  import { readJsonFile, hasPlanuEntry } from './install.js';
10
+ import { resolveStorageLayout } from '../../storage/storage-layout.js';
11
+ import { RuntimeDatabase } from '../../storage/runtime-db.js';
12
+ import { probeNativeLoad } from '../../engine/core-bridge.js';
13
+ import { getLocale, t } from '../../i18n/index.js';
7
14
  // ---------------------------------------------------------------------------
8
15
  // Constants
9
16
  // ---------------------------------------------------------------------------
@@ -86,6 +93,166 @@ function checkTool(check) {
86
93
  }
87
94
  return reports;
88
95
  }
96
+ // ---------------------------------------------------------------------------
97
+ // Deep diagnostics (SPEC-1346 / SPEC-1344)
98
+ // ---------------------------------------------------------------------------
99
+ /** Root of the package, resolved relative to this module so it works from src/ and dist/. */
100
+ const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '../../../package.json');
101
+ function parseVersionTuple(version) {
102
+ const match = /(\d+)\.(\d+)\.(\d+)/.exec(version);
103
+ return [Number(match?.[1] ?? 0), Number(match?.[2] ?? 0), Number(match?.[3] ?? 0)];
104
+ }
105
+ function isVersionAtLeast(actual, required) {
106
+ for (let i = 0; i < 3; i++) {
107
+ const a = actual[i] ?? 0;
108
+ const r = required[i] ?? 0;
109
+ if (a !== r) {
110
+ return a > r;
111
+ }
112
+ }
113
+ return true;
114
+ }
115
+ /** Check (1): the running Node version satisfies the `engines.node` field in package.json. */
116
+ function checkNodeVersion() {
117
+ let requiredRange;
118
+ try {
119
+ const pkg = JSON.parse(readFileSync(PACKAGE_ROOT, 'utf-8'));
120
+ requiredRange = pkg.engines?.node ?? '';
121
+ }
122
+ catch {
123
+ return {
124
+ name: 'Node version',
125
+ status: 'fail',
126
+ detail: 'Could not read package.json engines field',
127
+ };
128
+ }
129
+ if (!requiredRange) {
130
+ return { name: 'Node version', status: 'ok', detail: `Running Node ${process.version}` };
131
+ }
132
+ const required = parseVersionTuple(requiredRange);
133
+ const actual = parseVersionTuple(process.version);
134
+ if (isVersionAtLeast(actual, required)) {
135
+ return {
136
+ name: 'Node version',
137
+ status: 'ok',
138
+ detail: `${process.version} satisfies ${requiredRange}`,
139
+ };
140
+ }
141
+ return {
142
+ name: 'Node version',
143
+ status: 'fail',
144
+ detail: `${process.version} does not satisfy required range ${requiredRange}. Upgrade Node to continue.`,
145
+ };
146
+ }
147
+ /**
148
+ * Check (2): the native Rust module loads, with a remediation hint when it doesn't.
149
+ * Missing native is a supported degraded mode (TypeScript fallback stays correct), so
150
+ * this reports 'warn' rather than 'fail' — it never blocks `planu doctor`'s exit code.
151
+ */
152
+ function checkNativeModule() {
153
+ if (process.env.DISABLE_NATIVE_CORE === '1') {
154
+ return {
155
+ name: 'Native engine',
156
+ status: 'ok',
157
+ detail: 'Disabled via DISABLE_NATIVE_CORE=1 (TypeScript fallback in use)',
158
+ };
159
+ }
160
+ const diagnostic = probeNativeLoad();
161
+ if (diagnostic.loaded) {
162
+ return { name: 'Native engine', status: 'ok', detail: `Loaded (${diagnostic.loaded})` };
163
+ }
164
+ const reason = diagnostic.errors[0] ?? 'unknown failure';
165
+ return {
166
+ name: 'Native engine',
167
+ status: 'warn',
168
+ detail: `Failed to load (${reason}). Running on the TypeScript fallback. Reinstall the platform package for your OS/arch to restore native acceleration.`,
169
+ };
170
+ }
171
+ /** Check (3): PLANU_HOME / the resolved data directory is writable. */
172
+ function checkDataDirWritable() {
173
+ const layout = resolveStorageLayout();
174
+ const probePath = join(layout.data, `.doctor-write-probe-${String(process.pid)}`);
175
+ try {
176
+ mkdirSync(layout.data, { recursive: true, mode: 0o700 });
177
+ writeFileSync(probePath, 'ok', { mode: 0o600 });
178
+ unlinkSync(probePath);
179
+ return { name: 'Data directory', status: 'ok', detail: `Writable: ${layout.data}` };
180
+ }
181
+ catch (error) {
182
+ const message = error instanceof Error ? error.message : String(error);
183
+ return {
184
+ name: 'Data directory',
185
+ status: 'fail',
186
+ detail: `Cannot write to ${layout.data} (${message}). Check ownership/permissions on that path or set PLANU_HOME to a writable location.`,
187
+ };
188
+ }
189
+ }
190
+ /** Check (4): the runtime SQLite database opens without corruption. */
191
+ function checkRuntimeDatabase() {
192
+ const layout = resolveStorageLayout();
193
+ try {
194
+ const db = new RuntimeDatabase({ path: layout.runtimeDatabase });
195
+ db.close();
196
+ return {
197
+ name: 'Runtime database',
198
+ status: 'ok',
199
+ detail: `Opens correctly: ${layout.runtimeDatabase}`,
200
+ };
201
+ }
202
+ catch (error) {
203
+ const message = error instanceof Error ? error.message : String(error);
204
+ return {
205
+ name: 'Runtime database',
206
+ status: 'fail',
207
+ detail: `Cannot open ${layout.runtimeDatabase} (${message}). Move or delete the corrupted file and retry — Planu recreates it on next use.`,
208
+ };
209
+ }
210
+ }
211
+ /** Check (5): the active locale resolves to a real translated message. */
212
+ function checkLocaleResolution() {
213
+ const locale = getLocale();
214
+ const sample = t('locale.changed', locale);
215
+ if (sample === 'locale.changed') {
216
+ return {
217
+ name: 'Locale resolution',
218
+ status: 'fail',
219
+ detail: `Locale "${locale}" resolved but message bundle failed to load. Reinstall Planu to restore i18n/messages/.`,
220
+ };
221
+ }
222
+ return { name: 'Locale resolution', status: 'ok', detail: `Resolved locale: ${locale}` };
223
+ }
224
+ function runDeepChecks() {
225
+ return [
226
+ checkNodeVersion(),
227
+ checkNativeModule(),
228
+ checkDataDirWritable(),
229
+ checkRuntimeDatabase(),
230
+ checkLocaleResolution(),
231
+ ];
232
+ }
233
+ function deepCheckIcon(status) {
234
+ if (status === 'ok') {
235
+ return green('+');
236
+ }
237
+ return status === 'warn' ? yellow('!') : red('x');
238
+ }
239
+ function deepCheckLabel(status) {
240
+ if (status === 'ok') {
241
+ return green('OK');
242
+ }
243
+ return status === 'warn' ? yellow('DEGRADED') : red('FAIL');
244
+ }
245
+ function printDeepChecks(results) {
246
+ process.stdout.write(`\n${bold('Deep diagnostics')}\n\n`);
247
+ for (const result of results) {
248
+ const icon = deepCheckIcon(result.status);
249
+ const label = deepCheckLabel(result.status);
250
+ process.stdout.write(` [${icon}] ${result.name.padEnd(18)} ${label}\n`);
251
+ process.stdout.write(` ${dim(result.detail)}\n`);
252
+ }
253
+ }
254
+ // Exported for tests
255
+ export { checkNodeVersion, checkNativeModule, checkDataDirWritable, checkRuntimeDatabase, checkLocaleResolution, runDeepChecks, };
89
256
  function statusIcon(status) {
90
257
  switch (status) {
91
258
  case 'ok':
@@ -143,9 +310,16 @@ export const doctorCommand = {
143
310
  }
144
311
  }
145
312
  printReports(allReports);
313
+ const deepChecks = runDeepChecks();
314
+ printDeepChecks(deepChecks);
146
315
  const installed = allReports.filter((r) => r.status === 'ok').length;
147
316
  const invalid = allReports.filter((r) => r.status === 'invalid-config').length;
317
+ const failedDeepChecks = deepChecks.filter((c) => c.status === 'fail').length;
148
318
  process.stdout.write('\n');
319
+ if (failedDeepChecks > 0) {
320
+ process.stdout.write(`${red('Warning:')} ${String(failedDeepChecks)} deep diagnostic check(s) failed. See remediation steps above.\n`);
321
+ process.exitCode = 1;
322
+ }
149
323
  if (invalid > 0) {
150
324
  process.stdout.write(`${yellow('Warning:')} ${String(invalid)} config file(s) have invalid JSON. Run ${cyan('planu install')} to fix.\n`);
151
325
  }
@@ -99,6 +99,31 @@ function registerPluginInstalledListener() {
99
99
  })();
100
100
  });
101
101
  }
102
+ /**
103
+ * SPEC-1345 AC4: Fire-and-forget semantic index refresh on spec:created.
104
+ * Reconciles the persisted TF-IDF index against the current corpus so the next
105
+ * semantic_search call hits a warm, up-to-date index.
106
+ */
107
+ function registerSemanticIndexRefreshListener() {
108
+ onAutopilotEvent('spec:created', (event) => {
109
+ void (async () => {
110
+ try {
111
+ const { getOrCreateBackend } = await import('../../storage/vector-store/backend-factory.js');
112
+ const { SemanticIndexStore } = await import('../../storage/semantic-index-store.js');
113
+ const backend = await getOrCreateBackend(event.projectId);
114
+ const allDocs = await backend.getAll();
115
+ if (allDocs.length === 0) {
116
+ return;
117
+ }
118
+ const indexStore = new SemanticIndexStore(event.projectId, 'all');
119
+ await indexStore.loadOrBuild(allDocs.map((doc) => ({ id: doc.id, content: doc.content })));
120
+ }
121
+ catch {
122
+ /* best-effort — never surface to user */
123
+ }
124
+ })();
125
+ });
126
+ }
102
127
  const AUTOPILOT_EVENTS = [
103
128
  'spec:created',
104
129
  'spec:status:approved',
@@ -133,5 +158,7 @@ export function bootstrapAutopilotHandlers() {
133
158
  registerPluginInstalledListener();
134
159
  // SPEC-628: Register daily cron for auto_fix_health (moved from update_status cascade)
135
160
  registerDailyCronListener();
161
+ // SPEC-1345 AC4: Register semantic index refresh on spec:created
162
+ registerSemanticIndexRefreshListener();
136
163
  }
137
164
  //# sourceMappingURL=bootstrap.js.map
@@ -31,6 +31,34 @@ export declare function fastExtractTsRelations(rootPath: string, paths: string[]
31
31
  export declare function fastQueryAffectedNodes(seed: string, edges: GraphEdgeInputRs[], relationFilter: string[], policy: ProjectGraphLimitsPolicyRs, overrides?: Partial<ResolvedProjectGraphLimitsRs>): AffectedNodeRs[];
32
32
  export declare function fastQueryShortestPath(from: string, to: string, edges: GraphEdgeInputRs[], relationFilter: string[], policy: ProjectGraphLimitsPolicyRs, overrides?: Partial<ResolvedProjectGraphLimitsRs>): ShortestPathResultRs;
33
33
  export declare function fastSelectCompactGraphSlice(seeds: string[], nodes: GraphNodeInputRs[], edges: GraphEdgeInputRs[], policy: ProjectGraphLimitsPolicyRs, overrides?: Partial<ResolvedProjectGraphLimitsRs>): CompactGraphSliceRs;
34
+ /** Worker-dispatched variant of {@link fastDetectDriftParallel} for main-thread callers. */
35
+ export declare function fastDetectDriftParallelAsync(rootPath: string, keywords: string[]): Promise<{
36
+ value: DriftResult;
37
+ degradationNotice?: string;
38
+ }>;
39
+ /** Worker-dispatched variant of {@link fastScanAndHashFiles} for main-thread callers. */
40
+ export declare function fastScanAndHashFilesAsync(rootPath: string): Promise<{
41
+ value: FileHash[];
42
+ degradationNotice?: string;
43
+ }>;
44
+ /** Worker-dispatched variant of {@link fastScanProjectMetadata} for main-thread callers. */
45
+ export declare function fastScanProjectMetadataAsync(rootPath: string): Promise<{
46
+ value: FileMetadata[];
47
+ degradationNotice?: string;
48
+ }>;
49
+ /** Worker-dispatched variant of {@link fastScanSpecs} for main-thread callers. */
50
+ export declare function fastScanSpecsAsync(rootPath: string): Promise<{
51
+ value: SpecBriefRs[] | null;
52
+ degradationNotice?: string;
53
+ }>;
34
54
  export declare const isNativeActive: () => boolean;
35
55
  export declare const nativeLoadDiagnostic: () => NativeLoadDiagnostic;
56
+ /**
57
+ * Force a native load attempt regardless of the calling thread and return the
58
+ * resulting diagnostic. `nativeLoadDiagnostic()` alone only reports load state
59
+ * that some other main-thread-bypassing caller already triggered (e.g. the
60
+ * macOS Keychain port); this is the main-thread-safe way to actually probe
61
+ * native availability, used by `planu doctor`.
62
+ */
63
+ export declare const probeNativeLoad: () => NativeLoadDiagnostic;
36
64
  //# sourceMappingURL=core-bridge.d.ts.map
@@ -12,6 +12,7 @@ import { detectMusl } from './native-platform.js';
12
12
  import { findDuplicateBlocks } from './core-bridge-duplicate-blocks.js';
13
13
  import { appendGapEntry, verifyGapsChain } from './core-bridge-gaps.js';
14
14
  import { reportClassifiedDegradation } from '../errors/classified-degradation.js';
15
+ import { runNativeWorkerOperation } from './execution/native-worker-runtime.js';
15
16
  export { negotiateNativeRuntime, NATIVE_CAPABILITY_ABI, NATIVE_NODE_API_ABI, NATIVE_PROTOCOL_ABI, RUNTIME_STORAGE_SCHEMA, };
16
17
  const require = createRequire(import.meta.url);
17
18
  const reportedDegradations = new Set();
@@ -678,9 +679,75 @@ export function fastSelectCompactGraphSlice(seeds, nodes, edges, policy, overrid
678
679
  }
679
680
  return tsSelectCompactGraphSlice(seeds, nodes, edges, limits);
680
681
  }
682
+ // Main-thread dispatch strategy (SPEC-1344) -----------------------------------
683
+ // getNative() deliberately returns null on the main thread so long native FFI
684
+ // calls never block the event loop (see comment above getNative()). For hot
685
+ // paths that need acceleration anyway, dispatchViaWorker() moves the call onto
686
+ // the existing native-worker-dispatch.ts runtime (a worker thread, where
687
+ // isMainThread is false and native loads normally). If the worker fails to
688
+ // spawn, times out, or the operation isn't allowlisted, it falls back to the
689
+ // caller-supplied synchronous implementation so behavior never regresses.
690
+ const WORKER_DISPATCH_TIMEOUT_MS = 30_000;
691
+ const DEGRADATION_NOTICE_THRESHOLD_MS = 2_000;
692
+ async function dispatchViaWorker(operation, payload, projectId, syncFallback) {
693
+ const start = Date.now();
694
+ if (isMainThread && process.env.DISABLE_NATIVE_CORE !== '1') {
695
+ try {
696
+ const value = (await runNativeWorkerOperation({
697
+ operation,
698
+ payload,
699
+ projectId,
700
+ deadlineAt: start + WORKER_DISPATCH_TIMEOUT_MS,
701
+ }));
702
+ return { value };
703
+ }
704
+ catch (error) {
705
+ /* reliability-optional: NATIVE_WORKER_DISPATCH_FAILED — falls through to sync fallback */
706
+ reportOnce(`NATIVE_WORKER_DISPATCH_FAILED:${operation}`, () => {
707
+ reportClassifiedDegradation('NATIVE_WORKER_DISPATCH_FAILED', error instanceof Error ? error : FALLBACK_ERROR);
708
+ });
709
+ }
710
+ }
711
+ const value = syncFallback();
712
+ const elapsedMs = Date.now() - start;
713
+ if (elapsedMs > DEGRADATION_NOTICE_THRESHOLD_MS) {
714
+ return {
715
+ value,
716
+ degradationNotice: `native engine unavailable — run planu doctor (fallback took ${String(elapsedMs)}ms)`,
717
+ };
718
+ }
719
+ return { value };
720
+ }
721
+ /** Worker-dispatched variant of {@link fastDetectDriftParallel} for main-thread callers. */
722
+ export async function fastDetectDriftParallelAsync(rootPath, keywords) {
723
+ return dispatchViaWorker('detect-drift', { rootPath, keywords }, fastHashProjectPath(rootPath), () => fastDetectDriftParallel(rootPath, keywords));
724
+ }
725
+ /** Worker-dispatched variant of {@link fastScanAndHashFiles} for main-thread callers. */
726
+ export async function fastScanAndHashFilesAsync(rootPath) {
727
+ return dispatchViaWorker('scan-and-hash-files', { rootPath }, fastHashProjectPath(rootPath), () => fastScanAndHashFiles(rootPath));
728
+ }
729
+ /** Worker-dispatched variant of {@link fastScanProjectMetadata} for main-thread callers. */
730
+ export async function fastScanProjectMetadataAsync(rootPath) {
731
+ return dispatchViaWorker('scan-project-metadata', { rootPath }, fastHashProjectPath(rootPath), () => fastScanProjectMetadata(rootPath));
732
+ }
733
+ /** Worker-dispatched variant of {@link fastScanSpecs} for main-thread callers. */
734
+ export async function fastScanSpecsAsync(rootPath) {
735
+ return dispatchViaWorker('scan-specs', { rootPath }, fastHashProjectPath(rootPath), () => fastScanSpecs(rootPath));
736
+ }
681
737
  export const isNativeActive = () => getNative() !== null;
682
738
  export const nativeLoadDiagnostic = () => {
683
739
  refreshNativeCapabilityDiagnostic();
684
740
  return loadDiagnostic;
685
741
  };
742
+ /**
743
+ * Force a native load attempt regardless of the calling thread and return the
744
+ * resulting diagnostic. `nativeLoadDiagnostic()` alone only reports load state
745
+ * that some other main-thread-bypassing caller already triggered (e.g. the
746
+ * macOS Keychain port); this is the main-thread-safe way to actually probe
747
+ * native availability, used by `planu doctor`.
748
+ */
749
+ export const probeNativeLoad = () => {
750
+ loadNative();
751
+ return nativeLoadDiagnostic();
752
+ };
686
753
  //# sourceMappingURL=core-bridge.js.map
@@ -2,7 +2,7 @@
2
2
  import fs from 'node:fs';
3
3
  import { readFile, stat } from 'node:fs/promises';
4
4
  import path from 'node:path';
5
- import { fastScanProjectMetadata, isNativeActive, fastDetectDriftParallel, } from './core-bridge.js';
5
+ import { fastScanProjectMetadataAsync, fastDetectDriftParallelAsync, } from './core-bridge.js';
6
6
  import { readSpecTechnicalSection } from './spec-format/read-technical-section.js';
7
7
  // ---------------------------------------------------------------------------
8
8
  // Config builder
@@ -41,13 +41,11 @@ export async function computeSummaryReport(projectPath, specList, config, rules,
41
41
  const alerts = [];
42
42
  let drifted = 0;
43
43
  let clean = 0;
44
- // Layer 3 (AC coverage) Optimization:
45
- // If native is active, we can do a single parallel scan for keywords across ALL specs.
46
- // This is much faster than doing it one-by-one.
47
- const nativeActive = isNativeActive();
48
- const metadataMap = nativeActive
49
- ? new Map(fastScanProjectMetadata(projectPath).map((m) => [m.path, m]))
50
- : undefined;
44
+ // Layer 3 (AC coverage) Optimization: a single project-wide metadata scan
45
+ // (worker-dispatched when native is available) is much faster than doing it
46
+ // spec-by-spec.
47
+ const { value: projectMetadata } = await fastScanProjectMetadataAsync(projectPath);
48
+ const metadataMap = new Map(projectMetadata.map((m) => [m.path, m]));
51
49
  for (const specId of specList) {
52
50
  const technicalPath = specTechnicalPaths?.get(specId);
53
51
  const { score: healthScore } = await computeDriftScore(projectPath, specId, undefined, technicalPath, metadataMap);
@@ -272,19 +270,19 @@ async function computeAcCoverageScore(criteria, filePaths) {
272
270
  return 100;
273
271
  }
274
272
  let foundTerms;
275
- if (isNativeActive()) {
276
- // Use Rust to find which terms appear in implementation files across the WHOLE project.
277
- // Note: Rust already does parallel walking and multi-threaded search.
278
- // We pass any directory/file from the spec, but Rust will scan efficiently.
279
- const firstFile = existingFiles[0];
280
- if (!firstFile) {
281
- return 100;
282
- }
273
+ const firstFile = existingFiles[0];
274
+ if (!firstFile) {
275
+ return 100;
276
+ }
277
+ try {
278
+ // Worker-dispatched (native when available) parallel search across the WHOLE
279
+ // project rooted at the first file's dir — much faster than reading files
280
+ // one by one, and never blocks the main thread's event loop.
283
281
  const rootPath = path.dirname(firstFile); // Use first file's dir as heuristic
284
- const result = fastDetectDriftParallel(rootPath, [...allTerms]);
282
+ const { value: result } = await fastDetectDriftParallelAsync(rootPath, [...allTerms]);
285
283
  foundTerms = new Set(result.foundKeywords);
286
284
  }
287
- else {
285
+ catch {
288
286
  // Fallback: Read all implementation files once
289
287
  const fileContents = [];
290
288
  for (const filePath of existingFiles) {
@@ -3,7 +3,7 @@
3
3
  import { createHash } from 'node:crypto';
4
4
  import { readFile, stat } from 'node:fs/promises';
5
5
  import { join } from 'node:path';
6
- import { fastScanAndHashFiles, isNativeActive } from '../core-bridge.js';
6
+ import { fastScanAndHashFilesAsync } from '../core-bridge.js';
7
7
  /**
8
8
  * Compute SHA-256 hash of a file's content.
9
9
  */
@@ -34,38 +34,36 @@ export async function createFileHashEntry(projectPath, relativePath) {
34
34
  * Create hash entries for multiple files.
35
35
  */
36
36
  export async function createFileHashEntries(projectPath, relativePaths) {
37
- // Try native Rust implementation for bulk hashing
38
- if (isNativeActive()) {
39
- try {
40
- const results = fastScanAndHashFiles(projectPath);
41
- const resultMap = new Map(results.map((r) => [r.path, r.hash]));
42
- const entries = [];
43
- for (const rel of relativePaths) {
44
- const fullPath = join(projectPath, rel);
45
- const hash = resultMap.get(fullPath);
46
- if (hash) {
47
- try {
48
- const s = await stat(fullPath);
49
- entries.push({
50
- file: rel,
51
- hash,
52
- size: s.size,
53
- snapshotAt: new Date().toISOString(),
54
- });
55
- }
56
- catch {
57
- // File might have disappeared between scan and stat
58
- }
37
+ // Try the accelerated bulk-hash path (worker-dispatched native, or the TS fallback).
38
+ try {
39
+ const { value: results } = await fastScanAndHashFilesAsync(projectPath);
40
+ const resultMap = new Map(results.map((r) => [r.path, r.hash]));
41
+ const entries = [];
42
+ for (const rel of relativePaths) {
43
+ const fullPath = join(projectPath, rel);
44
+ const hash = resultMap.get(fullPath);
45
+ if (hash) {
46
+ try {
47
+ const s = await stat(fullPath);
48
+ entries.push({
49
+ file: rel,
50
+ hash,
51
+ size: s.size,
52
+ snapshotAt: new Date().toISOString(),
53
+ });
54
+ }
55
+ catch {
56
+ // File might have disappeared between scan and stat
59
57
  }
60
- }
61
- if (entries.length > 0) {
62
- return entries;
63
58
  }
64
59
  }
65
- catch (err) {
66
- console.warn('[Planu-RS] Native bulk hash failed, falling back to Node.', err);
60
+ if (entries.length > 0) {
61
+ return entries;
67
62
  }
68
63
  }
64
+ catch (err) {
65
+ console.warn('[Planu-RS] Bulk hash failed, falling back to Node.', err);
66
+ }
69
67
  const entries = [];
70
68
  for (const relativePath of relativePaths) {
71
69
  const entry = await createFileHashEntry(projectPath, relativePath);
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
- "cliVersion": "5.1.1",
4
- "engineVersion": "5.1.1",
5
- "buildId": "1-5.1.1-aarch64-apple-darwin",
3
+ "cliVersion": "5.2.0",
4
+ "engineVersion": "5.2.0",
5
+ "buildId": "1-5.2.0-aarch64-apple-darwin",
6
6
  "protocolAbi": 1,
7
7
  "capabilityAbi": 2,
8
8
  "nodeApiAbi": 4,
@@ -17,15 +17,15 @@
17
17
  "platform": "darwin",
18
18
  "arch": "arm64",
19
19
  "libc": null,
20
- "artifactSha256": "3791a7635fda74d3c0c5a226115ac4ab78c98afc366d0451a107ed1419139873",
20
+ "artifactSha256": "d651b32dc2ec3d58adc720400cab3cfd0114388d2697c861038b913cda3ad711",
21
21
  "sbom": {
22
22
  "format": "CycloneDX-1.5",
23
23
  "path": "planu-core.darwin-arm64.node.sbom.json",
24
- "sha256": "434d0491e2130ac49b7eb34989f5ae2135f3ad9f54f0042f5bb3ba660bd2c568"
24
+ "sha256": "28c7421f2ee232830c3150449c51d89a494e2a4841a39af4348dcaaccb27f6cc"
25
25
  },
26
26
  "provenance": {
27
27
  "builder": "scripts/build-rust-local.sh",
28
- "sourceCommit": "5046eff43d23641fe60bd1c01e8c34277172db16",
28
+ "sourceCommit": "121065e63e9fd2c067367e286ecba619ecc3f18a",
29
29
  "sourceTreeDirty": false,
30
30
  "sourceDateEpoch": 1,
31
31
  "rustToolchain": "rustc 1.95.0 (59807616e 2026-04-14)",
@@ -34,6 +34,6 @@
34
34
  "signature": {
35
35
  "algorithm": "Ed25519",
36
36
  "keyId": "e2ee765cb5ad9fbdc433ece332bce26d746d5e350b3acde0721a4c8c6337ff7b",
37
- "value": "7kFQj3Sq5rFuMciulVbszYysMir4sSVuTrgLv0exAYSmkfwj16xag4ldwYRCJky/EXeCn1ZYZYJvfuCNEqZ5DQ=="
37
+ "value": "9R5L33t90yHh/8SXCNpjSRbCoIJ8wooiMtvkHpCKr1ByDK13NiUuH3v0uLiquqXbf4r6mMe5K4bWQ63nm/XQBg=="
38
38
  }
39
39
  }
@@ -4,14 +4,14 @@
4
4
  "version": 1,
5
5
  "metadata": {
6
6
  "component": {
7
- "bom-ref": "pkg:cargo/planu-core@5.1.1",
7
+ "bom-ref": "pkg:cargo/planu-core@5.2.0",
8
8
  "type": "library",
9
9
  "name": "planu-core",
10
- "version": "5.1.1",
10
+ "version": "5.2.0",
11
11
  "hashes": [
12
12
  {
13
13
  "alg": "SHA-256",
14
- "content": "3791a7635fda74d3c0c5a226115ac4ab78c98afc366d0451a107ed1419139873"
14
+ "content": "d651b32dc2ec3d58adc720400cab3cfd0114388d2697c861038b913cda3ad711"
15
15
  }
16
16
  ]
17
17
  }
@@ -1106,7 +1106,7 @@
1106
1106
  "dependsOn": []
1107
1107
  },
1108
1108
  {
1109
- "ref": "pkg:cargo/planu-core@5.1.1",
1109
+ "ref": "pkg:cargo/planu-core@5.2.0",
1110
1110
  "dependsOn": [
1111
1111
  "pkg:cargo/core-foundation@0.10.1",
1112
1112
  "pkg:cargo/hmac@0.12.1",
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
- "cliVersion": "5.1.1",
4
- "engineVersion": "5.1.1",
5
- "buildId": "1-5.1.1-x86_64-apple-darwin",
3
+ "cliVersion": "5.2.0",
4
+ "engineVersion": "5.2.0",
5
+ "buildId": "1-5.2.0-x86_64-apple-darwin",
6
6
  "protocolAbi": 1,
7
7
  "capabilityAbi": 2,
8
8
  "nodeApiAbi": 4,
@@ -17,15 +17,15 @@
17
17
  "platform": "darwin",
18
18
  "arch": "x64",
19
19
  "libc": null,
20
- "artifactSha256": "339ab4dad5834869aebc0130b8c63e0863d665daf0a98d8e795f08ea51bab51c",
20
+ "artifactSha256": "931a0f6bc94744521f33e6ac46fb7293fe49b14d225d76446e27dd7117f12ad9",
21
21
  "sbom": {
22
22
  "format": "CycloneDX-1.5",
23
23
  "path": "planu-core.darwin-x64.node.sbom.json",
24
- "sha256": "d52bf3925938ed40201a07f6a0190694d9cfd924393ebba6d47f818c8ee79c17"
24
+ "sha256": "ec531e41f6e0ef14b7fb2727370f817b761d28ae510c93790555796f5e2fac19"
25
25
  },
26
26
  "provenance": {
27
27
  "builder": "scripts/build-rust-local.sh",
28
- "sourceCommit": "5046eff43d23641fe60bd1c01e8c34277172db16",
28
+ "sourceCommit": "121065e63e9fd2c067367e286ecba619ecc3f18a",
29
29
  "sourceTreeDirty": false,
30
30
  "sourceDateEpoch": 1,
31
31
  "rustToolchain": "rustc 1.95.0 (59807616e 2026-04-14)",
@@ -34,6 +34,6 @@
34
34
  "signature": {
35
35
  "algorithm": "Ed25519",
36
36
  "keyId": "e2ee765cb5ad9fbdc433ece332bce26d746d5e350b3acde0721a4c8c6337ff7b",
37
- "value": "MBGihzcPhQf/7suo2XjxUz8kuC6zpZeVnNXlIjI/a14CCARPeI1gE67dWBIvVJuJ0dMmXeLfsw39quYQQNqdCg=="
37
+ "value": "mgppJ+aunLo8AOPqEdBnmAXfDYzWQzdmehp7AASRUk8Wyk9/mQm9A22K5T5NiUN3flTqQCLPT6ZN2L9eWp5VCw=="
38
38
  }
39
39
  }