@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
@@ -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;
@@ -3,7 +3,7 @@
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
5
  import { isTelemetryEnabled } from './telemetry-store.js';
6
- import { sendTelemetryEvent } from './telemetry-client.js';
6
+ import { sendTelemetryEvent, isValidTelemetryEndpoint } from './telemetry-client.js';
7
7
  // eslint-disable-next-line no-restricted-imports -- grandfathered layer violation, remediation SPEC-1661 SPEC-1662 SPEC-1663
8
8
  import { hashProjectPath, projectDataDir } from '../../storage/base-store.js';
9
9
  import { networkFetch, withNetworkConsent } from '../network-policy.js';
@@ -47,24 +47,6 @@ function checkEndpointConfigured(endpoint) {
47
47
  detail: 'Telemetry endpoint configured',
48
48
  };
49
49
  }
50
- function isLoopbackHost(hostname) {
51
- return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
52
- }
53
- function isValidTelemetryEndpoint(endpoint) {
54
- if (!endpoint || endpoint.trim() === '') {
55
- return false;
56
- }
57
- try {
58
- const parsed = new URL(endpoint.trim());
59
- return (parsed.username === '' &&
60
- parsed.password === '' &&
61
- (parsed.protocol === 'https:' ||
62
- (parsed.protocol === 'http:' && isLoopbackHost(parsed.hostname))));
63
- }
64
- catch {
65
- return false;
66
- }
67
- }
68
50
  function checkTokenConfigured(token) {
69
51
  return token?.trim()
70
52
  ? { name: 'token-configured', status: 'ok', detail: 'Telemetry token configured' }
@@ -1,4 +1,5 @@
1
1
  import type { TelemetryEvent, TelemetryEnvelopeEventName, TelemetryEnvelopeInput } from '../../types/index.js';
2
+ export declare function isValidTelemetryEndpoint(endpoint: string | undefined): endpoint is string;
2
3
  /** Fire-and-forget; absence or staleness of opt-in prevents any network access. */
3
4
  export declare function sendTelemetryEvent(event: TelemetryEvent): void;
4
5
  /**
@@ -6,7 +6,7 @@ import { buildTelemetryEnvelope, TELEMETRY_SESSION_ID } from './event-envelope.j
6
6
  function isLoopbackHost(hostname) {
7
7
  return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
8
8
  }
9
- function isValidTelemetryEndpoint(endpoint) {
9
+ export function isValidTelemetryEndpoint(endpoint) {
10
10
  if (!endpoint || endpoint.trim() === '') {
11
11
  return false;
12
12
  }
@@ -1,5 +1,5 @@
1
1
  import { technologyValue } from '../technology-registry.js';
2
- import { toSnake } from './helpers.js';
2
+ import { toSnake, getFrameworkExt, getFrameworkRunCommand } from './helpers.js';
3
3
  // === E2E test scaffold ===
4
4
  /**
5
5
  * Generate an E2E test scaffold (Playwright by default).
@@ -15,29 +15,6 @@ export function generateE2ETestScaffold(specTitle, framework) {
15
15
  runCommand,
16
16
  };
17
17
  }
18
- function getFrameworkExt(framework) {
19
- const extMap = {
20
- pytest: 'py',
21
- junit: 'java',
22
- xunit: 'cs',
23
- rspec: 'rb',
24
- 'go-test': 'go',
25
- };
26
- return extMap[framework] ?? 'ts';
27
- }
28
- function getFrameworkRunCommand(framework) {
29
- const commandMap = {
30
- vitest: 'npx vitest run',
31
- jest: 'npx jest',
32
- mocha: 'npx mocha',
33
- pytest: 'python -m pytest',
34
- junit: 'mvn test',
35
- xunit: 'dotnet test',
36
- rspec: 'bundle exec rspec',
37
- 'go-test': 'go test ./...',
38
- };
39
- return commandMap[framework];
40
- }
41
18
  function buildE2EContent(title) {
42
19
  return [
43
20
  "import { test, expect } from '@playwright/test';",
@@ -1,4 +1,4 @@
1
- import type { LedgerEntry, LedgerAggregation, BudgetConfig, LedgerBudgetStatus, DailyBreakdown, TrendResult, Anomaly, TopConsumer, OptimizationSavings } from '../../types/index.js';
1
+ import { type LedgerEntry, type LedgerAggregation, type BudgetConfig, type LedgerBudgetStatus, type DailyBreakdown, type TrendResult, type Anomaly, type TopConsumer, type OptimizationSavings } from '../../types/index.js';
2
2
  export type { DailyBreakdown, TrendResult, Anomaly, TopConsumer, OptimizationSavings };
3
3
  export declare function aggregateEntries(entries: LedgerEntry[]): LedgerAggregation;
4
4
  export declare function computeDailyBreakdown(entries: LedgerEntry[]): DailyBreakdown[];
@@ -1,5 +1,6 @@
1
1
  // Cost Analytics Engine (SPEC-182)
2
2
  // Aggregations, trends, anomaly detection, and projections from token ledger data
3
+ import { emptyLedgerAggregation, } from '../../types/index.js';
3
4
  // ---------------------------------------------------------------------------
4
5
  // Constants
5
6
  // ---------------------------------------------------------------------------
@@ -55,33 +56,12 @@ function computeEstimationAccuracy(estimatedCount, actualForEstimated, estimated
55
56
  overEstimationPercent: ((estimatedSum - actualForEstimated) / actualForEstimated) * 100,
56
57
  };
57
58
  }
58
- function buildEmptyAggregation() {
59
- return {
60
- totalTokens: 0,
61
- totalInputTokens: 0,
62
- totalOutputTokens: 0,
63
- totalCostUsd: 0,
64
- totalEstimatedCostUsd: 0,
65
- entryCount: 0,
66
- uniqueTools: 0,
67
- uniqueModels: 0,
68
- uniqueSessions: 0,
69
- avgTokensPerCall: 0,
70
- avgCostPerCall: 0,
71
- tokensByTool: {},
72
- costByTool: {},
73
- tokensByModel: {},
74
- costByModel: {},
75
- estimationAccuracy: 100,
76
- overEstimationPercent: 0,
77
- };
78
- }
79
59
  function incrementRecord(rec, key, val) {
80
60
  return { ...rec, [key]: (rec[key] ?? 0) + val };
81
61
  }
82
62
  export function aggregateEntries(entries) {
83
63
  if (entries.length === 0) {
84
- return buildEmptyAggregation();
64
+ return emptyLedgerAggregation();
85
65
  }
86
66
  const result = entries.reduce((a, e) => {
87
67
  const hasEst = e.estimatedTokens !== undefined;
@@ -1,20 +1,10 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { isRecord, mergeDeep } from '../../core/shared/object.js';
4
5
  function configPath() {
5
6
  return join(dirname(fileURLToPath(import.meta.url)), '../../config/token-waste-autopilot.json');
6
7
  }
7
- function isRecord(value) {
8
- return typeof value === 'object' && value !== null && !Array.isArray(value);
9
- }
10
- function mergeDeep(base, override) {
11
- const result = { ...base };
12
- for (const [key, value] of Object.entries(override)) {
13
- const current = result[key];
14
- result[key] = isRecord(current) && isRecord(value) ? mergeDeep(current, value) : value;
15
- }
16
- return result;
17
- }
18
8
  function assertStringArray(value, path) {
19
9
  if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {
20
10
  throw new Error(`Invalid token waste policy at ${path}: expected string[]`);
@@ -1,21 +1,10 @@
1
1
  // engine/workers/handlers/code-map.ts — Builds codebase structure map (SPEC-078 AC-08)
2
- import { readFile, readdir, stat } from 'node:fs/promises';
3
- import { join, extname, relative } from 'node:path';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { extname, relative } from 'node:path';
4
+ import { collectFiles, DEFAULT_CODE_EXTS } from './collect-files.js';
4
5
  // ---------------------------------------------------------------------------
5
6
  // Constants
6
7
  // ---------------------------------------------------------------------------
7
- const IGNORE_DIRS = new Set([
8
- 'node_modules',
9
- '.git',
10
- 'dist',
11
- 'build',
12
- '__pycache__',
13
- 'target',
14
- '.venv',
15
- 'vendor',
16
- 'coverage',
17
- ]);
18
- const CODE_EXTS = new Set(['.ts', '.tsx', '.js', '.jsx', '.py', '.go', '.rs', '.java', '.kt']);
19
8
  const ENTRY_POINT_NAMES = new Set([
20
9
  'main',
21
10
  'index',
@@ -35,37 +24,6 @@ const ENTRY_POINT_NAMES = new Set([
35
24
  'lib.rs',
36
25
  ]);
37
26
  // ---------------------------------------------------------------------------
38
- // File collection
39
- // ---------------------------------------------------------------------------
40
- async function collectFiles(dir, files) {
41
- let entries;
42
- try {
43
- entries = await readdir(dir);
44
- }
45
- catch {
46
- return;
47
- }
48
- for (const entry of entries) {
49
- if (IGNORE_DIRS.has(entry)) {
50
- continue;
51
- }
52
- const fullPath = join(dir, entry);
53
- let st;
54
- try {
55
- st = await stat(fullPath);
56
- }
57
- catch {
58
- continue;
59
- }
60
- if (st.isDirectory()) {
61
- await collectFiles(fullPath, files);
62
- }
63
- else if (st.isFile() && CODE_EXTS.has(extname(fullPath))) {
64
- files.push(fullPath);
65
- }
66
- }
67
- }
68
- // ---------------------------------------------------------------------------
69
27
  // Export detection — pattern-table approach to keep complexity low
70
28
  // ---------------------------------------------------------------------------
71
29
  const TS_EXPORT_PATTERNS = [
@@ -159,7 +117,7 @@ export async function runCodeMap(projectDir, _changedFiles) {
159
117
  const start = Date.now();
160
118
  const findings = [];
161
119
  const allFiles = [];
162
- await collectFiles(projectDir, allFiles);
120
+ await collectFiles(projectDir, allFiles, DEFAULT_CODE_EXTS);
163
121
  // Count files by extension
164
122
  const extCounts = new Map();
165
123
  const entryPoints = [];
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_CODE_EXTS: ReadonlySet<string>;
2
+ export declare function collectFiles(dir: string, files: string[], codeExts: ReadonlySet<string>): Promise<void>;
3
+ //# sourceMappingURL=collect-files.d.ts.map
@@ -0,0 +1,53 @@
1
+ import { readdir, stat } from 'node:fs/promises';
2
+ import { join, extname } from 'node:path';
3
+ const IGNORE_DIRS = new Set([
4
+ 'node_modules',
5
+ '.git',
6
+ 'dist',
7
+ 'build',
8
+ '__pycache__',
9
+ 'target',
10
+ '.venv',
11
+ 'vendor',
12
+ 'coverage',
13
+ ]);
14
+ export const DEFAULT_CODE_EXTS = new Set([
15
+ '.ts',
16
+ '.tsx',
17
+ '.js',
18
+ '.jsx',
19
+ '.py',
20
+ '.go',
21
+ '.rs',
22
+ '.java',
23
+ '.kt',
24
+ ]);
25
+ export async function collectFiles(dir, files, codeExts) {
26
+ let entries;
27
+ try {
28
+ entries = await readdir(dir);
29
+ }
30
+ catch {
31
+ return;
32
+ }
33
+ for (const entry of entries) {
34
+ if (IGNORE_DIRS.has(entry)) {
35
+ continue;
36
+ }
37
+ const fullPath = join(dir, entry);
38
+ let st;
39
+ try {
40
+ st = await stat(fullPath);
41
+ }
42
+ catch {
43
+ continue;
44
+ }
45
+ if (st.isDirectory()) {
46
+ await collectFiles(fullPath, files, codeExts);
47
+ }
48
+ else if (st.isFile() && codeExts.has(extname(fullPath))) {
49
+ files.push(fullPath);
50
+ }
51
+ }
52
+ }
53
+ //# sourceMappingURL=collect-files.js.map
@@ -1,52 +1,7 @@
1
1
  // engine/workers/handlers/documentation.ts — Finds undocumented exports (SPEC-078 AC-09)
2
- import { readFile, readdir, stat } from 'node:fs/promises';
3
- import { join, extname, relative } from 'node:path';
4
- // ---------------------------------------------------------------------------
5
- // Constants
6
- // ---------------------------------------------------------------------------
7
- const IGNORE_DIRS = new Set([
8
- 'node_modules',
9
- '.git',
10
- 'dist',
11
- 'build',
12
- '__pycache__',
13
- 'target',
14
- '.venv',
15
- 'vendor',
16
- 'coverage',
17
- ]);
18
- const CODE_EXTS = new Set(['.ts', '.tsx', '.js', '.jsx', '.py', '.go', '.rs', '.java', '.kt']);
19
- // ---------------------------------------------------------------------------
20
- // File collection
21
- // ---------------------------------------------------------------------------
22
- async function collectFiles(dir, files) {
23
- let entries;
24
- try {
25
- entries = await readdir(dir);
26
- }
27
- catch {
28
- return;
29
- }
30
- for (const entry of entries) {
31
- if (IGNORE_DIRS.has(entry)) {
32
- continue;
33
- }
34
- const fullPath = join(dir, entry);
35
- let st;
36
- try {
37
- st = await stat(fullPath);
38
- }
39
- catch {
40
- continue;
41
- }
42
- if (st.isDirectory()) {
43
- await collectFiles(fullPath, files);
44
- }
45
- else if (st.isFile() && CODE_EXTS.has(extname(fullPath))) {
46
- files.push(fullPath);
47
- }
48
- }
49
- }
2
+ import { readFile } from 'node:fs/promises';
3
+ import { extname, relative } from 'node:path';
4
+ import { collectFiles, DEFAULT_CODE_EXTS } from './collect-files.js';
50
5
  // ---------------------------------------------------------------------------
51
6
  // Documentation checks per language
52
7
  // ---------------------------------------------------------------------------
@@ -143,7 +98,7 @@ export async function runDocumentation(projectDir, _changedFiles) {
143
98
  const start = Date.now();
144
99
  const findings = [];
145
100
  const allFiles = [];
146
- await collectFiles(projectDir, allFiles);
101
+ await collectFiles(projectDir, allFiles, DEFAULT_CODE_EXTS);
147
102
  let totalExports = 0;
148
103
  let undocumentedExports = 0;
149
104
  for (const file of allFiles) {
@@ -1,22 +1,11 @@
1
1
  // engine/workers/handlers/optimization.ts — Detects perf anti-patterns (SPEC-078 AC-07)
2
- import { readFile, readdir, stat } from 'node:fs/promises';
3
- import { join, extname, relative } from 'node:path';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { extname, relative } from 'node:path';
4
+ import { collectFiles, DEFAULT_CODE_EXTS } from './collect-files.js';
4
5
  // ---------------------------------------------------------------------------
5
6
  // Config
6
7
  // ---------------------------------------------------------------------------
7
8
  const MAX_FILE_LINES = 400;
8
- const IGNORE_DIRS = new Set([
9
- 'node_modules',
10
- '.git',
11
- 'dist',
12
- 'build',
13
- '__pycache__',
14
- 'target',
15
- '.venv',
16
- 'vendor',
17
- 'coverage',
18
- ]);
19
- const CODE_EXTS = new Set(['.ts', '.tsx', '.js', '.jsx', '.py', '.go', '.rs', '.java', '.kt']);
20
9
  // ---------------------------------------------------------------------------
21
10
  // Complexity keywords per language
22
11
  // ---------------------------------------------------------------------------
@@ -32,37 +21,6 @@ const COMPLEXITY_KEYWORDS = {
32
21
  '.kt': [/\bif\b/, /\belse\b/, /\bfor\b/, /\bwhile\b/, /\bwhen\b/, /\bcatch\b/],
33
22
  };
34
23
  // ---------------------------------------------------------------------------
35
- // File collection
36
- // ---------------------------------------------------------------------------
37
- async function collectFiles(dir, files) {
38
- let entries;
39
- try {
40
- entries = await readdir(dir);
41
- }
42
- catch {
43
- return;
44
- }
45
- for (const entry of entries) {
46
- if (IGNORE_DIRS.has(entry)) {
47
- continue;
48
- }
49
- const fullPath = join(dir, entry);
50
- let st;
51
- try {
52
- st = await stat(fullPath);
53
- }
54
- catch {
55
- continue;
56
- }
57
- if (st.isDirectory()) {
58
- await collectFiles(fullPath, files);
59
- }
60
- else if (st.isFile() && CODE_EXTS.has(extname(fullPath))) {
61
- files.push(fullPath);
62
- }
63
- }
64
- }
65
- // ---------------------------------------------------------------------------
66
24
  // Analysis helpers
67
25
  // ---------------------------------------------------------------------------
68
26
  function countComplexity(lines, ext) {
@@ -109,7 +67,7 @@ export async function runOptimization(projectDir, _changedFiles) {
109
67
  const start = Date.now();
110
68
  const findings = [];
111
69
  const allFiles = [];
112
- await collectFiles(projectDir, allFiles);
70
+ await collectFiles(projectDir, allFiles, DEFAULT_CODE_EXTS);
113
71
  // Track imports for circular dependency detection
114
72
  const importGraph = new Map();
115
73
  for (const file of allFiles) {
@@ -1,6 +1,7 @@
1
1
  // engine/workers/handlers/security-audit.ts — Detects security vulnerabilities (SPEC-078 AC-06)
2
- import { readFile, readdir, stat } from 'node:fs/promises';
3
- import { join, extname, basename, relative } from 'node:path';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { extname, basename, relative } from 'node:path';
4
+ import { collectFiles } from './collect-files.js';
4
5
  const PATTERNS = [
5
6
  // Hardcoded secrets
6
7
  {
@@ -97,17 +98,6 @@ const PATTERNS = [
97
98
  // ---------------------------------------------------------------------------
98
99
  // Ignore patterns
99
100
  // ---------------------------------------------------------------------------
100
- const IGNORE_DIRS = new Set([
101
- 'node_modules',
102
- '.git',
103
- 'dist',
104
- 'build',
105
- '__pycache__',
106
- 'target',
107
- '.venv',
108
- 'vendor',
109
- 'coverage',
110
- ]);
111
101
  const SKIP_FILES = new Set(['.env.example', '.env.template', '.env.sample']);
112
102
  const CODE_EXTS = new Set([
113
103
  '.ts',
@@ -125,37 +115,6 @@ const CODE_EXTS = new Set([
125
115
  '.toml',
126
116
  '.cfg',
127
117
  ]);
128
- // ---------------------------------------------------------------------------
129
- // File scanning
130
- // ---------------------------------------------------------------------------
131
- async function collectFiles(dir, files) {
132
- let entries;
133
- try {
134
- entries = await readdir(dir);
135
- }
136
- catch {
137
- return;
138
- }
139
- for (const entry of entries) {
140
- if (IGNORE_DIRS.has(entry)) {
141
- continue;
142
- }
143
- const fullPath = join(dir, entry);
144
- let st;
145
- try {
146
- st = await stat(fullPath);
147
- }
148
- catch {
149
- continue;
150
- }
151
- if (st.isDirectory()) {
152
- await collectFiles(fullPath, files);
153
- }
154
- else if (st.isFile() && CODE_EXTS.has(extname(fullPath))) {
155
- files.push(fullPath);
156
- }
157
- }
158
- }
159
118
  function isTestOrExample(filePath) {
160
119
  const base = basename(filePath);
161
120
  return (SKIP_FILES.has(base) ||
@@ -175,7 +134,7 @@ export async function runSecurityAudit(projectDir, _changedFiles) {
175
134
  const start = Date.now();
176
135
  const findings = [];
177
136
  const allFiles = [];
178
- await collectFiles(projectDir, allFiles);
137
+ await collectFiles(projectDir, allFiles, CODE_EXTS);
179
138
  const filesToScan = allFiles.filter((f) => !isTestOrExample(f));
180
139
  for (const file of filesToScan) {
181
140
  let content;
@@ -1,4 +1,4 @@
1
- import type { LedgerEntry, LedgerFilter, LedgerAggregation, MonthlyLedger } from '../types/index.js';
1
+ import { type LedgerEntry, type LedgerFilter, type LedgerAggregation, type MonthlyLedger } from '../types/index.js';
2
2
  /**
3
3
  * Append a new entry to the current month's ledger file.
4
4
  */