@lumenflow/core 1.0.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.
- package/LICENSE +190 -0
- package/README.md +119 -0
- package/dist/active-wu-detector.d.ts +33 -0
- package/dist/active-wu-detector.js +106 -0
- package/dist/adapters/filesystem-metrics.adapter.d.ts +108 -0
- package/dist/adapters/filesystem-metrics.adapter.js +519 -0
- package/dist/adapters/terminal-renderer.adapter.d.ts +106 -0
- package/dist/adapters/terminal-renderer.adapter.js +337 -0
- package/dist/arg-parser.d.ts +63 -0
- package/dist/arg-parser.js +560 -0
- package/dist/backlog-editor.d.ts +98 -0
- package/dist/backlog-editor.js +179 -0
- package/dist/backlog-generator.d.ts +111 -0
- package/dist/backlog-generator.js +381 -0
- package/dist/backlog-parser.d.ts +45 -0
- package/dist/backlog-parser.js +102 -0
- package/dist/backlog-sync-validator.d.ts +78 -0
- package/dist/backlog-sync-validator.js +294 -0
- package/dist/branch-drift.d.ts +34 -0
- package/dist/branch-drift.js +51 -0
- package/dist/cleanup-install-config.d.ts +33 -0
- package/dist/cleanup-install-config.js +37 -0
- package/dist/cleanup-lock.d.ts +139 -0
- package/dist/cleanup-lock.js +313 -0
- package/dist/code-path-validator.d.ts +146 -0
- package/dist/code-path-validator.js +537 -0
- package/dist/code-paths-overlap.d.ts +55 -0
- package/dist/code-paths-overlap.js +245 -0
- package/dist/commands-logger.d.ts +77 -0
- package/dist/commands-logger.js +254 -0
- package/dist/commit-message-utils.d.ts +25 -0
- package/dist/commit-message-utils.js +41 -0
- package/dist/compliance-parser.d.ts +150 -0
- package/dist/compliance-parser.js +507 -0
- package/dist/constants/backlog-patterns.d.ts +20 -0
- package/dist/constants/backlog-patterns.js +23 -0
- package/dist/constants/dora-constants.d.ts +49 -0
- package/dist/constants/dora-constants.js +53 -0
- package/dist/constants/gate-constants.d.ts +15 -0
- package/dist/constants/gate-constants.js +15 -0
- package/dist/constants/linter-constants.d.ts +16 -0
- package/dist/constants/linter-constants.js +16 -0
- package/dist/constants/tokenizer-constants.d.ts +15 -0
- package/dist/constants/tokenizer-constants.js +15 -0
- package/dist/core/scope-checker.d.ts +97 -0
- package/dist/core/scope-checker.js +163 -0
- package/dist/core/tool-runner.d.ts +161 -0
- package/dist/core/tool-runner.js +393 -0
- package/dist/core/tool.constants.d.ts +105 -0
- package/dist/core/tool.constants.js +101 -0
- package/dist/core/tool.schemas.d.ts +226 -0
- package/dist/core/tool.schemas.js +226 -0
- package/dist/core/worktree-guard.d.ts +130 -0
- package/dist/core/worktree-guard.js +242 -0
- package/dist/coverage-gate.d.ts +108 -0
- package/dist/coverage-gate.js +196 -0
- package/dist/date-utils.d.ts +75 -0
- package/dist/date-utils.js +140 -0
- package/dist/dependency-graph.d.ts +142 -0
- package/dist/dependency-graph.js +550 -0
- package/dist/dependency-guard.d.ts +54 -0
- package/dist/dependency-guard.js +142 -0
- package/dist/dependency-validator.d.ts +105 -0
- package/dist/dependency-validator.js +154 -0
- package/dist/docs-path-validator.d.ts +36 -0
- package/dist/docs-path-validator.js +95 -0
- package/dist/domain/orchestration.constants.d.ts +99 -0
- package/dist/domain/orchestration.constants.js +97 -0
- package/dist/domain/orchestration.schemas.d.ts +280 -0
- package/dist/domain/orchestration.schemas.js +211 -0
- package/dist/domain/orchestration.types.d.ts +133 -0
- package/dist/domain/orchestration.types.js +12 -0
- package/dist/error-handler.d.ts +116 -0
- package/dist/error-handler.js +136 -0
- package/dist/file-classifiers.d.ts +62 -0
- package/dist/file-classifiers.js +108 -0
- package/dist/gates-agent-mode.d.ts +81 -0
- package/dist/gates-agent-mode.js +94 -0
- package/dist/generate-traceability.d.ts +107 -0
- package/dist/generate-traceability.js +411 -0
- package/dist/git-adapter.d.ts +395 -0
- package/dist/git-adapter.js +649 -0
- package/dist/git-staged-validator.d.ts +32 -0
- package/dist/git-staged-validator.js +48 -0
- package/dist/hardcoded-strings.d.ts +61 -0
- package/dist/hardcoded-strings.js +270 -0
- package/dist/incremental-lint.d.ts +78 -0
- package/dist/incremental-lint.js +129 -0
- package/dist/incremental-test.d.ts +39 -0
- package/dist/incremental-test.js +61 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +61 -0
- package/dist/invariants/check-automated-tests.d.ts +50 -0
- package/dist/invariants/check-automated-tests.js +166 -0
- package/dist/invariants-runner.d.ts +103 -0
- package/dist/invariants-runner.js +527 -0
- package/dist/lane-checker.d.ts +50 -0
- package/dist/lane-checker.js +319 -0
- package/dist/lane-inference.d.ts +39 -0
- package/dist/lane-inference.js +195 -0
- package/dist/lane-lock.d.ts +211 -0
- package/dist/lane-lock.js +474 -0
- package/dist/lane-validator.d.ts +48 -0
- package/dist/lane-validator.js +114 -0
- package/dist/logs-lib.d.ts +104 -0
- package/dist/logs-lib.js +207 -0
- package/dist/lumenflow-config-schema.d.ts +272 -0
- package/dist/lumenflow-config-schema.js +207 -0
- package/dist/lumenflow-config.d.ts +95 -0
- package/dist/lumenflow-config.js +236 -0
- package/dist/manual-test-validator.d.ts +80 -0
- package/dist/manual-test-validator.js +200 -0
- package/dist/merge-lock.d.ts +115 -0
- package/dist/merge-lock.js +251 -0
- package/dist/micro-worktree.d.ts +159 -0
- package/dist/micro-worktree.js +427 -0
- package/dist/migration-deployer.d.ts +69 -0
- package/dist/migration-deployer.js +151 -0
- package/dist/orchestration-advisory-loader.d.ts +28 -0
- package/dist/orchestration-advisory-loader.js +87 -0
- package/dist/orchestration-advisory.d.ts +58 -0
- package/dist/orchestration-advisory.js +94 -0
- package/dist/orchestration-di.d.ts +48 -0
- package/dist/orchestration-di.js +57 -0
- package/dist/orchestration-rules.d.ts +57 -0
- package/dist/orchestration-rules.js +201 -0
- package/dist/orphan-detector.d.ts +131 -0
- package/dist/orphan-detector.js +226 -0
- package/dist/path-classifiers.d.ts +57 -0
- package/dist/path-classifiers.js +93 -0
- package/dist/piped-command-detector.d.ts +34 -0
- package/dist/piped-command-detector.js +64 -0
- package/dist/ports/dashboard-renderer.port.d.ts +112 -0
- package/dist/ports/dashboard-renderer.port.js +25 -0
- package/dist/ports/metrics-collector.port.d.ts +132 -0
- package/dist/ports/metrics-collector.port.js +26 -0
- package/dist/process-detector.d.ts +84 -0
- package/dist/process-detector.js +172 -0
- package/dist/prompt-linter.d.ts +72 -0
- package/dist/prompt-linter.js +312 -0
- package/dist/prompt-monitor.d.ts +15 -0
- package/dist/prompt-monitor.js +205 -0
- package/dist/rebase-artifact-cleanup.d.ts +145 -0
- package/dist/rebase-artifact-cleanup.js +433 -0
- package/dist/retry-strategy.d.ts +189 -0
- package/dist/retry-strategy.js +283 -0
- package/dist/risk-detector.d.ts +108 -0
- package/dist/risk-detector.js +252 -0
- package/dist/rollback-utils.d.ts +76 -0
- package/dist/rollback-utils.js +104 -0
- package/dist/section-headings.d.ts +43 -0
- package/dist/section-headings.js +49 -0
- package/dist/spawn-escalation.d.ts +90 -0
- package/dist/spawn-escalation.js +253 -0
- package/dist/spawn-monitor.d.ts +229 -0
- package/dist/spawn-monitor.js +672 -0
- package/dist/spawn-recovery.d.ts +82 -0
- package/dist/spawn-recovery.js +298 -0
- package/dist/spawn-registry-schema.d.ts +98 -0
- package/dist/spawn-registry-schema.js +108 -0
- package/dist/spawn-registry-store.d.ts +146 -0
- package/dist/spawn-registry-store.js +273 -0
- package/dist/spawn-tree.d.ts +121 -0
- package/dist/spawn-tree.js +285 -0
- package/dist/stamp-status-validator.d.ts +84 -0
- package/dist/stamp-status-validator.js +134 -0
- package/dist/stamp-utils.d.ts +100 -0
- package/dist/stamp-utils.js +229 -0
- package/dist/state-machine.d.ts +26 -0
- package/dist/state-machine.js +83 -0
- package/dist/system-map-validator.d.ts +80 -0
- package/dist/system-map-validator.js +272 -0
- package/dist/telemetry.d.ts +80 -0
- package/dist/telemetry.js +213 -0
- package/dist/token-counter.d.ts +51 -0
- package/dist/token-counter.js +145 -0
- package/dist/usecases/get-dashboard-data.usecase.d.ts +52 -0
- package/dist/usecases/get-dashboard-data.usecase.js +61 -0
- package/dist/usecases/get-suggestions.usecase.d.ts +100 -0
- package/dist/usecases/get-suggestions.usecase.js +153 -0
- package/dist/user-normalizer.d.ts +41 -0
- package/dist/user-normalizer.js +141 -0
- package/dist/validators/phi-constants.d.ts +97 -0
- package/dist/validators/phi-constants.js +152 -0
- package/dist/validators/phi-scanner.d.ts +58 -0
- package/dist/validators/phi-scanner.js +215 -0
- package/dist/worktree-ownership.d.ts +50 -0
- package/dist/worktree-ownership.js +74 -0
- package/dist/worktree-scanner.d.ts +103 -0
- package/dist/worktree-scanner.js +168 -0
- package/dist/worktree-symlink.d.ts +99 -0
- package/dist/worktree-symlink.js +359 -0
- package/dist/wu-backlog-updater.d.ts +17 -0
- package/dist/wu-backlog-updater.js +37 -0
- package/dist/wu-checkpoint.d.ts +124 -0
- package/dist/wu-checkpoint.js +233 -0
- package/dist/wu-claim-helpers.d.ts +26 -0
- package/dist/wu-claim-helpers.js +63 -0
- package/dist/wu-claim-resume.d.ts +106 -0
- package/dist/wu-claim-resume.js +276 -0
- package/dist/wu-consistency-checker.d.ts +95 -0
- package/dist/wu-consistency-checker.js +567 -0
- package/dist/wu-constants.d.ts +1275 -0
- package/dist/wu-constants.js +1382 -0
- package/dist/wu-create-validators.d.ts +42 -0
- package/dist/wu-create-validators.js +93 -0
- package/dist/wu-done-branch-only.d.ts +63 -0
- package/dist/wu-done-branch-only.js +191 -0
- package/dist/wu-done-messages.d.ts +119 -0
- package/dist/wu-done-messages.js +185 -0
- package/dist/wu-done-pr.d.ts +72 -0
- package/dist/wu-done-pr.js +174 -0
- package/dist/wu-done-retry-helpers.d.ts +85 -0
- package/dist/wu-done-retry-helpers.js +172 -0
- package/dist/wu-done-ui.d.ts +37 -0
- package/dist/wu-done-ui.js +69 -0
- package/dist/wu-done-validators.d.ts +411 -0
- package/dist/wu-done-validators.js +1229 -0
- package/dist/wu-done-worktree.d.ts +182 -0
- package/dist/wu-done-worktree.js +1097 -0
- package/dist/wu-helpers.d.ts +128 -0
- package/dist/wu-helpers.js +248 -0
- package/dist/wu-lint.d.ts +70 -0
- package/dist/wu-lint.js +234 -0
- package/dist/wu-paths.d.ts +171 -0
- package/dist/wu-paths.js +178 -0
- package/dist/wu-preflight-validators.d.ts +86 -0
- package/dist/wu-preflight-validators.js +251 -0
- package/dist/wu-recovery.d.ts +138 -0
- package/dist/wu-recovery.js +341 -0
- package/dist/wu-repair-core.d.ts +131 -0
- package/dist/wu-repair-core.js +669 -0
- package/dist/wu-schema-normalization.d.ts +17 -0
- package/dist/wu-schema-normalization.js +82 -0
- package/dist/wu-schema.d.ts +793 -0
- package/dist/wu-schema.js +881 -0
- package/dist/wu-spawn-helpers.d.ts +121 -0
- package/dist/wu-spawn-helpers.js +271 -0
- package/dist/wu-spawn.d.ts +158 -0
- package/dist/wu-spawn.js +1306 -0
- package/dist/wu-state-schema.d.ts +213 -0
- package/dist/wu-state-schema.js +156 -0
- package/dist/wu-state-store.d.ts +264 -0
- package/dist/wu-state-store.js +691 -0
- package/dist/wu-status-transition.d.ts +63 -0
- package/dist/wu-status-transition.js +382 -0
- package/dist/wu-status-updater.d.ts +25 -0
- package/dist/wu-status-updater.js +116 -0
- package/dist/wu-transaction-collectors.d.ts +116 -0
- package/dist/wu-transaction-collectors.js +272 -0
- package/dist/wu-transaction.d.ts +170 -0
- package/dist/wu-transaction.js +273 -0
- package/dist/wu-validation-constants.d.ts +60 -0
- package/dist/wu-validation-constants.js +66 -0
- package/dist/wu-validation.d.ts +118 -0
- package/dist/wu-validation.js +243 -0
- package/dist/wu-validator.d.ts +62 -0
- package/dist/wu-validator.js +325 -0
- package/dist/wu-yaml-fixer.d.ts +97 -0
- package/dist/wu-yaml-fixer.js +264 -0
- package/dist/wu-yaml.d.ts +86 -0
- package/dist/wu-yaml.js +222 -0
- package/package.json +114 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DORA Metrics Constants
|
|
3
|
+
*
|
|
4
|
+
* Thresholds based on "Accelerate" research by Nicole Forsgren, Jez Humble, Gene Kim.
|
|
5
|
+
* Used by calculate-dora-metrics.mjs.
|
|
6
|
+
*/
|
|
7
|
+
/** Deployment frequency classification thresholds (deploys per week) */
|
|
8
|
+
export declare const DEPLOYMENT_FREQUENCY: {
|
|
9
|
+
/** Elite: >5 deploys per week */
|
|
10
|
+
ELITE: number;
|
|
11
|
+
/** High: 1-5 deploys per week */
|
|
12
|
+
HIGH: number;
|
|
13
|
+
/** Medium: ~1 deploy per month (0.25/week) */
|
|
14
|
+
MEDIUM: number;
|
|
15
|
+
};
|
|
16
|
+
/** Lead time classification thresholds (hours) */
|
|
17
|
+
export declare const LEAD_TIME_HOURS: {
|
|
18
|
+
/** Elite: <24 hours (<1 day) */
|
|
19
|
+
ELITE: number;
|
|
20
|
+
/** High: <168 hours (<7 days) */
|
|
21
|
+
HIGH: number;
|
|
22
|
+
/** Medium: <720 hours (<30 days) */
|
|
23
|
+
MEDIUM: number;
|
|
24
|
+
};
|
|
25
|
+
/** Change failure rate classification thresholds (percentage) */
|
|
26
|
+
export declare const CFR_PERCENT: {
|
|
27
|
+
/** Elite: <15% failures */
|
|
28
|
+
ELITE: number;
|
|
29
|
+
/** High: 15-30% failures */
|
|
30
|
+
HIGH: number;
|
|
31
|
+
/** Medium: 30-45% failures */
|
|
32
|
+
MEDIUM: number;
|
|
33
|
+
};
|
|
34
|
+
/** Mean time to recovery classification thresholds (hours) */
|
|
35
|
+
export declare const MTTR_HOURS: {
|
|
36
|
+
/** Elite: <1 hour */
|
|
37
|
+
ELITE: number;
|
|
38
|
+
/** High: <24 hours (<1 day) */
|
|
39
|
+
HIGH: number;
|
|
40
|
+
/** Medium: <168 hours (<7 days) */
|
|
41
|
+
MEDIUM: number;
|
|
42
|
+
};
|
|
43
|
+
/** Statistical constants */
|
|
44
|
+
export declare const STATISTICS: {
|
|
45
|
+
/** 90th percentile for p90Hours calculation */
|
|
46
|
+
P90_PERCENTILE: number;
|
|
47
|
+
/** Decimal places for rounding (10 = 1 decimal place) */
|
|
48
|
+
ROUNDING_FACTOR: number;
|
|
49
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DORA Metrics Constants
|
|
3
|
+
*
|
|
4
|
+
* Thresholds based on "Accelerate" research by Nicole Forsgren, Jez Humble, Gene Kim.
|
|
5
|
+
* Used by calculate-dora-metrics.mjs.
|
|
6
|
+
*/
|
|
7
|
+
/** Deployment frequency classification thresholds (deploys per week) */
|
|
8
|
+
export const DEPLOYMENT_FREQUENCY = {
|
|
9
|
+
/** Elite: >5 deploys per week */
|
|
10
|
+
ELITE: 5,
|
|
11
|
+
/** High: 1-5 deploys per week */
|
|
12
|
+
HIGH: 1,
|
|
13
|
+
/** Medium: ~1 deploy per month (0.25/week) */
|
|
14
|
+
MEDIUM: 0.25,
|
|
15
|
+
// Low: <0.25 deploys per week (implicit)
|
|
16
|
+
};
|
|
17
|
+
/** Lead time classification thresholds (hours) */
|
|
18
|
+
export const LEAD_TIME_HOURS = {
|
|
19
|
+
/** Elite: <24 hours (<1 day) */
|
|
20
|
+
ELITE: 24,
|
|
21
|
+
/** High: <168 hours (<7 days) */
|
|
22
|
+
HIGH: 168,
|
|
23
|
+
/** Medium: <720 hours (<30 days) */
|
|
24
|
+
MEDIUM: 720,
|
|
25
|
+
// Low: >720 hours (implicit)
|
|
26
|
+
};
|
|
27
|
+
/** Change failure rate classification thresholds (percentage) */
|
|
28
|
+
export const CFR_PERCENT = {
|
|
29
|
+
/** Elite: <15% failures */
|
|
30
|
+
ELITE: 15,
|
|
31
|
+
/** High: 15-30% failures */
|
|
32
|
+
HIGH: 30,
|
|
33
|
+
/** Medium: 30-45% failures */
|
|
34
|
+
MEDIUM: 45,
|
|
35
|
+
// Low: >45% failures (implicit)
|
|
36
|
+
};
|
|
37
|
+
/** Mean time to recovery classification thresholds (hours) */
|
|
38
|
+
export const MTTR_HOURS = {
|
|
39
|
+
/** Elite: <1 hour */
|
|
40
|
+
ELITE: 1,
|
|
41
|
+
/** High: <24 hours (<1 day) */
|
|
42
|
+
HIGH: 24,
|
|
43
|
+
/** Medium: <168 hours (<7 days) */
|
|
44
|
+
MEDIUM: 168,
|
|
45
|
+
// Low: >168 hours (implicit)
|
|
46
|
+
};
|
|
47
|
+
/** Statistical constants */
|
|
48
|
+
export const STATISTICS = {
|
|
49
|
+
/** 90th percentile for p90Hours calculation */
|
|
50
|
+
P90_PERCENTILE: 0.9,
|
|
51
|
+
/** Decimal places for rounding (10 = 1 decimal place) */
|
|
52
|
+
ROUNDING_FACTOR: 10,
|
|
53
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate Configuration Constants
|
|
3
|
+
*
|
|
4
|
+
* Centralizes magic numbers for pre-commit and local gates.
|
|
5
|
+
* Used by gates-pre-commit.mjs and gates-local.mjs.
|
|
6
|
+
*/
|
|
7
|
+
/** Gate execution configuration */
|
|
8
|
+
export declare const GATE_CONFIG: {
|
|
9
|
+
/** Maximum execution time per gate step (ms) */
|
|
10
|
+
TIMEOUT_MS: number;
|
|
11
|
+
/** Maximum file size allowed in commits (bytes) - 5MB */
|
|
12
|
+
MAX_FILE_SIZE_BYTES: number;
|
|
13
|
+
/** Total number of gates (for progress display) */
|
|
14
|
+
TOTAL_GATES: number;
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate Configuration Constants
|
|
3
|
+
*
|
|
4
|
+
* Centralizes magic numbers for pre-commit and local gates.
|
|
5
|
+
* Used by gates-pre-commit.mjs and gates-local.mjs.
|
|
6
|
+
*/
|
|
7
|
+
/** Gate execution configuration */
|
|
8
|
+
export const GATE_CONFIG = {
|
|
9
|
+
/** Maximum execution time per gate step (ms) */
|
|
10
|
+
TIMEOUT_MS: 180000,
|
|
11
|
+
/** Maximum file size allowed in commits (bytes) - 5MB */
|
|
12
|
+
MAX_FILE_SIZE_BYTES: 5 * 1024 * 1024,
|
|
13
|
+
/** Total number of gates (for progress display) */
|
|
14
|
+
TOTAL_GATES: 14,
|
|
15
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linter Configuration Constants
|
|
3
|
+
*
|
|
4
|
+
* Centralizes magic numbers for spec-linter and related validation tools.
|
|
5
|
+
* Used by packages/linters/spec-linter.mjs.
|
|
6
|
+
*/
|
|
7
|
+
/** Spec linter configuration */
|
|
8
|
+
export declare const LINTER_CONFIG: {
|
|
9
|
+
/** Watchdog timeout for long-running linter operations (ms) */
|
|
10
|
+
WATCHDOG_TIMEOUT_MS: number;
|
|
11
|
+
/**
|
|
12
|
+
* Maximum allowed glass surfaces in UI components.
|
|
13
|
+
* Per Beacon spec glass cap artifacts rule.
|
|
14
|
+
*/
|
|
15
|
+
MAX_GLASS_SURFACES: number;
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linter Configuration Constants
|
|
3
|
+
*
|
|
4
|
+
* Centralizes magic numbers for spec-linter and related validation tools.
|
|
5
|
+
* Used by packages/linters/spec-linter.mjs.
|
|
6
|
+
*/
|
|
7
|
+
/** Spec linter configuration */
|
|
8
|
+
export const LINTER_CONFIG = {
|
|
9
|
+
/** Watchdog timeout for long-running linter operations (ms) */
|
|
10
|
+
WATCHDOG_TIMEOUT_MS: 55000,
|
|
11
|
+
/**
|
|
12
|
+
* Maximum allowed glass surfaces in UI components.
|
|
13
|
+
* Per Beacon spec glass cap artifacts rule.
|
|
14
|
+
*/
|
|
15
|
+
MAX_GLASS_SURFACES: 6,
|
|
16
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokenizer Constants
|
|
3
|
+
*
|
|
4
|
+
* Configuration for token estimation in documentation files.
|
|
5
|
+
* Used by token-count.mjs.
|
|
6
|
+
*/
|
|
7
|
+
/** Token estimation configuration */
|
|
8
|
+
export declare const TOKENIZER: {
|
|
9
|
+
/**
|
|
10
|
+
* Word to token ratio for estimation.
|
|
11
|
+
* Industry standard approximation for GPT-family models.
|
|
12
|
+
* Anthropic's Claude uses similar tokenization.
|
|
13
|
+
*/
|
|
14
|
+
WORD_TO_TOKEN_RATIO: number;
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokenizer Constants
|
|
3
|
+
*
|
|
4
|
+
* Configuration for token estimation in documentation files.
|
|
5
|
+
* Used by token-count.mjs.
|
|
6
|
+
*/
|
|
7
|
+
/** Token estimation configuration */
|
|
8
|
+
export const TOKENIZER = {
|
|
9
|
+
/**
|
|
10
|
+
* Word to token ratio for estimation.
|
|
11
|
+
* Industry standard approximation for GPT-family models.
|
|
12
|
+
* Anthropic's Claude uses similar tokenization.
|
|
13
|
+
*/
|
|
14
|
+
WORD_TO_TOKEN_RATIO: 1.33,
|
|
15
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file scope-checker.mjs
|
|
3
|
+
* @description WU scope validation and code_paths enforcement (WU-1397)
|
|
4
|
+
*
|
|
5
|
+
* Provides runtime validation that file modifications stay within WU code_paths.
|
|
6
|
+
* Prevents scope creep and ensures agents only modify authorized files.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Load code_paths from active WU YAML
|
|
10
|
+
* - Validate file paths against glob patterns
|
|
11
|
+
* - Throw descriptive errors for scope violations
|
|
12
|
+
* - Support both exact paths and glob patterns
|
|
13
|
+
*
|
|
14
|
+
* Used by wu- scripts and future file operation guards.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link tools/lib/core/worktree-guard.mjs} - WU context detection
|
|
17
|
+
* @see {@link tools/lib/wu-schema.mjs} - WU YAML parsing
|
|
18
|
+
*/
|
|
19
|
+
import { getWUContext } from './worktree-guard.js';
|
|
20
|
+
/**
|
|
21
|
+
* Load WU YAML data for a given WU ID
|
|
22
|
+
*
|
|
23
|
+
* Wrapper around readWU that constructs the path.
|
|
24
|
+
* Exported for testing injection.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} wuId - WU identifier
|
|
27
|
+
* @returns {Object} Parsed WU YAML
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
declare function loadWUYaml(wuId: any): any;
|
|
31
|
+
/**
|
|
32
|
+
* Options for getActiveScope
|
|
33
|
+
*/
|
|
34
|
+
interface GetActiveScopeOptions {
|
|
35
|
+
/** WU context getter (for testing) */
|
|
36
|
+
getWUContext?: typeof getWUContext;
|
|
37
|
+
/** WU YAML loader (for testing) */
|
|
38
|
+
loadWUYaml?: typeof loadWUYaml;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get active WU scope (WU ID + code_paths)
|
|
42
|
+
*
|
|
43
|
+
* Retrieves the current WU context and loads code_paths from WU YAML.
|
|
44
|
+
* Returns null if not in a WU workspace.
|
|
45
|
+
*
|
|
46
|
+
* @param {GetActiveScopeOptions} [options] - Options
|
|
47
|
+
* @returns {Promise<Object|null>} Scope object {wuId, code_paths} or null
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const scope = await getActiveScope();
|
|
51
|
+
* if (scope) {
|
|
52
|
+
* console.log(`WU ${scope.wuId} code_paths:`, scope.code_paths);
|
|
53
|
+
* }
|
|
54
|
+
*/
|
|
55
|
+
export declare function getActiveScope(options?: GetActiveScopeOptions): Promise<{
|
|
56
|
+
wuId: string;
|
|
57
|
+
code_paths: any;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a file path is within WU scope
|
|
61
|
+
*
|
|
62
|
+
* Validates a file path against the WU's code_paths using glob matching.
|
|
63
|
+
* Supports exact paths and glob patterns (*, **, {a,b}, etc.).
|
|
64
|
+
*
|
|
65
|
+
* Empty code_paths = no restrictions (documentation/process WUs).
|
|
66
|
+
*
|
|
67
|
+
* @param {string} filePath - File path to check
|
|
68
|
+
* @param {Object|null} scope - Scope object from getActiveScope()
|
|
69
|
+
* @param {string} scope.wuId - WU identifier
|
|
70
|
+
* @param {string[]} scope.code_paths - Allowed file paths/patterns
|
|
71
|
+
* @returns {boolean} True if path is in scope, false otherwise
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const scope = await getActiveScope();
|
|
75
|
+
* if (isPathInScope('apps/web/src/Header.tsx', scope)) {
|
|
76
|
+
* console.log('Path is in scope');
|
|
77
|
+
* }
|
|
78
|
+
*/
|
|
79
|
+
export declare function isPathInScope(filePath: any, scope: any): any;
|
|
80
|
+
/**
|
|
81
|
+
* Assert that a file path is within WU scope
|
|
82
|
+
*
|
|
83
|
+
* Throws descriptive error if path is outside WU code_paths.
|
|
84
|
+
* Use this for write operations that must enforce scope boundaries.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} filePath - File path to check
|
|
87
|
+
* @param {Object|null} scope - Scope object from getActiveScope()
|
|
88
|
+
* @param {string} [operation] - Operation name for error message context
|
|
89
|
+
* @throws {Error} If path is outside scope or no scope available
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const scope = await getActiveScope();
|
|
93
|
+
* assertPathInScope('apps/web/src/Header.tsx', scope, 'file write');
|
|
94
|
+
* // Throws if path not in WU code_paths
|
|
95
|
+
*/
|
|
96
|
+
export declare function assertPathInScope(filePath: any, scope: any, operation?: string): void;
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file scope-checker.mjs
|
|
3
|
+
* @description WU scope validation and code_paths enforcement (WU-1397)
|
|
4
|
+
*
|
|
5
|
+
* Provides runtime validation that file modifications stay within WU code_paths.
|
|
6
|
+
* Prevents scope creep and ensures agents only modify authorized files.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Load code_paths from active WU YAML
|
|
10
|
+
* - Validate file paths against glob patterns
|
|
11
|
+
* - Throw descriptive errors for scope violations
|
|
12
|
+
* - Support both exact paths and glob patterns
|
|
13
|
+
*
|
|
14
|
+
* Used by wu- scripts and future file operation guards.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link tools/lib/core/worktree-guard.mjs} - WU context detection
|
|
17
|
+
* @see {@link tools/lib/wu-schema.mjs} - WU YAML parsing
|
|
18
|
+
*/
|
|
19
|
+
import micromatch from 'micromatch';
|
|
20
|
+
import { getWUContext } from './worktree-guard.js';
|
|
21
|
+
import { readWU } from '../wu-yaml.js';
|
|
22
|
+
import { WU_PATHS } from '../wu-paths.js';
|
|
23
|
+
/**
|
|
24
|
+
* Normalize path separators to forward slashes
|
|
25
|
+
*
|
|
26
|
+
* Handles both Unix and Windows path separators for cross-platform compatibility.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} p - Path to normalize
|
|
29
|
+
* @returns {string} Path with forward slashes
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
function normalizePath(p) {
|
|
33
|
+
return p.replace(/\\/g, '/');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Load WU YAML data for a given WU ID
|
|
37
|
+
*
|
|
38
|
+
* Wrapper around readWU that constructs the path.
|
|
39
|
+
* Exported for testing injection.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} wuId - WU identifier
|
|
42
|
+
* @returns {Object} Parsed WU YAML
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
function loadWUYaml(wuId) {
|
|
46
|
+
const wuPath = WU_PATHS.WU(wuId);
|
|
47
|
+
return readWU(wuPath, wuId);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get active WU scope (WU ID + code_paths)
|
|
51
|
+
*
|
|
52
|
+
* Retrieves the current WU context and loads code_paths from WU YAML.
|
|
53
|
+
* Returns null if not in a WU workspace.
|
|
54
|
+
*
|
|
55
|
+
* @param {GetActiveScopeOptions} [options] - Options
|
|
56
|
+
* @returns {Promise<Object|null>} Scope object {wuId, code_paths} or null
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const scope = await getActiveScope();
|
|
60
|
+
* if (scope) {
|
|
61
|
+
* console.log(`WU ${scope.wuId} code_paths:`, scope.code_paths);
|
|
62
|
+
* }
|
|
63
|
+
*/
|
|
64
|
+
export async function getActiveScope(options = {}) {
|
|
65
|
+
const getContextFn = options.getWUContext || getWUContext;
|
|
66
|
+
const loadYamlFn = options.loadWUYaml || loadWUYaml;
|
|
67
|
+
// Get current WU context from worktree path or git branch
|
|
68
|
+
const context = await getContextFn();
|
|
69
|
+
if (!context) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
// Load WU YAML to get code_paths
|
|
73
|
+
const wuData = loadYamlFn(context.wuId);
|
|
74
|
+
return {
|
|
75
|
+
wuId: context.wuId,
|
|
76
|
+
code_paths: wuData.code_paths || [],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if a file path is within WU scope
|
|
81
|
+
*
|
|
82
|
+
* Validates a file path against the WU's code_paths using glob matching.
|
|
83
|
+
* Supports exact paths and glob patterns (*, **, {a,b}, etc.).
|
|
84
|
+
*
|
|
85
|
+
* Empty code_paths = no restrictions (documentation/process WUs).
|
|
86
|
+
*
|
|
87
|
+
* @param {string} filePath - File path to check
|
|
88
|
+
* @param {Object|null} scope - Scope object from getActiveScope()
|
|
89
|
+
* @param {string} scope.wuId - WU identifier
|
|
90
|
+
* @param {string[]} scope.code_paths - Allowed file paths/patterns
|
|
91
|
+
* @returns {boolean} True if path is in scope, false otherwise
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const scope = await getActiveScope();
|
|
95
|
+
* if (isPathInScope('apps/web/src/Header.tsx', scope)) {
|
|
96
|
+
* console.log('Path is in scope');
|
|
97
|
+
* }
|
|
98
|
+
*/
|
|
99
|
+
export function isPathInScope(filePath, scope) {
|
|
100
|
+
if (!scope) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
// Empty code_paths = no restrictions (documentation/process WUs)
|
|
104
|
+
if (!scope.code_paths || scope.code_paths.length === 0) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
// Normalize path separators for cross-platform compatibility
|
|
108
|
+
const normalizedPath = normalizePath(filePath);
|
|
109
|
+
// Check exact match first (fast path)
|
|
110
|
+
if (scope.code_paths.includes(normalizedPath)) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
// Check glob patterns using micromatch
|
|
114
|
+
return micromatch.isMatch(normalizedPath, scope.code_paths);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Assert that a file path is within WU scope
|
|
118
|
+
*
|
|
119
|
+
* Throws descriptive error if path is outside WU code_paths.
|
|
120
|
+
* Use this for write operations that must enforce scope boundaries.
|
|
121
|
+
*
|
|
122
|
+
* @param {string} filePath - File path to check
|
|
123
|
+
* @param {Object|null} scope - Scope object from getActiveScope()
|
|
124
|
+
* @param {string} [operation] - Operation name for error message context
|
|
125
|
+
* @throws {Error} If path is outside scope or no scope available
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const scope = await getActiveScope();
|
|
129
|
+
* assertPathInScope('apps/web/src/Header.tsx', scope, 'file write');
|
|
130
|
+
* // Throws if path not in WU code_paths
|
|
131
|
+
*/
|
|
132
|
+
export function assertPathInScope(filePath, scope, operation = 'this operation') {
|
|
133
|
+
if (!scope) {
|
|
134
|
+
throw new Error(`❌ SCOPE VIOLATION: No active WU context.
|
|
135
|
+
|
|
136
|
+
Operation: ${operation}
|
|
137
|
+
File path: ${filePath}
|
|
138
|
+
|
|
139
|
+
You must claim a WU before performing operations.
|
|
140
|
+
Run: pnpm wu:claim --id WU-XXX --lane "<lane>"
|
|
141
|
+
`);
|
|
142
|
+
}
|
|
143
|
+
if (!isPathInScope(filePath, scope)) {
|
|
144
|
+
const normalizedPath = normalizePath(filePath);
|
|
145
|
+
throw new Error(`❌ SCOPE VIOLATION: File path outside WU code_paths.
|
|
146
|
+
|
|
147
|
+
Operation: ${operation}
|
|
148
|
+
WU ID: ${scope.wuId}
|
|
149
|
+
File path: ${normalizedPath}
|
|
150
|
+
|
|
151
|
+
Allowed code_paths:
|
|
152
|
+
${scope.code_paths.map((p) => ` - ${p}`).join('\n')}
|
|
153
|
+
|
|
154
|
+
This file is not authorized for modification in this WU.
|
|
155
|
+
Either:
|
|
156
|
+
1. Add this path to code_paths in WU YAML (if legitimately needed)
|
|
157
|
+
2. Create a separate WU for this change
|
|
158
|
+
3. Choose a different file within scope
|
|
159
|
+
|
|
160
|
+
See: CLAUDE.md §2 (Worktree Discipline)
|
|
161
|
+
`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file tool-runner.mjs
|
|
3
|
+
* @description Unified tool execution layer integrating all core components (WU-1398)
|
|
4
|
+
*
|
|
5
|
+
* This module provides a higher-order function pattern for executing tools with:
|
|
6
|
+
* - Input validation via Zod schemas (tool.schemas.ts)
|
|
7
|
+
* - Worktree context detection (worktree-guard.mjs)
|
|
8
|
+
* - Scope validation against code_paths (scope-checker.mjs)
|
|
9
|
+
* - Audit logging for telemetry (.beacon/telemetry/tools.ndjson)
|
|
10
|
+
* - Consistent error handling with agent-friendly messages
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* import { runTool, ToolRunner, createToolConfig } from './tool-runner.js';
|
|
14
|
+
*
|
|
15
|
+
* // Direct invocation
|
|
16
|
+
* const result = await runTool(toolDefinition, { arg: 'value' });
|
|
17
|
+
*
|
|
18
|
+
* // Registry-based invocation
|
|
19
|
+
* const runner = new ToolRunner();
|
|
20
|
+
* runner.register(myTool);
|
|
21
|
+
* const result = await runner.run('tool:name', { arg: 'value' });
|
|
22
|
+
*
|
|
23
|
+
* @see tools/lib/core/tool.schemas.ts - Zod schemas for tool I/O
|
|
24
|
+
* @see tools/lib/core/worktree-guard.mjs - WU context detection
|
|
25
|
+
* @see tools/lib/core/scope-checker.mjs - Code path validation
|
|
26
|
+
*/
|
|
27
|
+
interface ToolMetadata {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
domain?: string;
|
|
31
|
+
permission: string;
|
|
32
|
+
version?: string;
|
|
33
|
+
}
|
|
34
|
+
interface ToolDefinition {
|
|
35
|
+
metadata: ToolMetadata;
|
|
36
|
+
inputSchema?: unknown;
|
|
37
|
+
outputSchema?: unknown;
|
|
38
|
+
execute: (input: unknown, context?: unknown) => Promise<unknown>;
|
|
39
|
+
}
|
|
40
|
+
interface ToolConfigOptions {
|
|
41
|
+
requiresWorktree?: boolean;
|
|
42
|
+
requiresScope?: boolean;
|
|
43
|
+
enableAuditLog?: boolean;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}
|
|
46
|
+
interface ToolConfig {
|
|
47
|
+
requiresWorktree: boolean;
|
|
48
|
+
requiresScope: boolean;
|
|
49
|
+
enableAuditLog: boolean;
|
|
50
|
+
timeoutMs: number;
|
|
51
|
+
}
|
|
52
|
+
interface RunToolOptions {
|
|
53
|
+
dependencies?: Record<string, unknown>;
|
|
54
|
+
config?: ToolConfigOptions;
|
|
55
|
+
context?: unknown;
|
|
56
|
+
}
|
|
57
|
+
interface ToolRunnerOptions {
|
|
58
|
+
enableAuditLog?: boolean;
|
|
59
|
+
timeoutMs?: number;
|
|
60
|
+
dependencies?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
interface ListToolsOptions {
|
|
63
|
+
domain?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Default configuration values for tool runner
|
|
67
|
+
*/
|
|
68
|
+
export declare const RUNNER_DEFAULTS: {
|
|
69
|
+
/** Default timeout for tool execution in milliseconds */
|
|
70
|
+
TIMEOUT_MS: number;
|
|
71
|
+
/** Enable audit logging by default */
|
|
72
|
+
ENABLE_AUDIT_LOG: boolean;
|
|
73
|
+
/** Default: read tools don't require worktree */
|
|
74
|
+
REQUIRES_WORKTREE: boolean;
|
|
75
|
+
/** Default: read tools don't require scope check */
|
|
76
|
+
REQUIRES_SCOPE: boolean;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Create tool configuration with sensible defaults
|
|
80
|
+
*
|
|
81
|
+
* @param {object} tool - Tool definition
|
|
82
|
+
* @param {object} options - Configuration overrides
|
|
83
|
+
* @returns {object} Merged configuration
|
|
84
|
+
*/
|
|
85
|
+
export declare function createToolConfig(tool: ToolDefinition, options?: ToolConfigOptions): ToolConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Run a tool with full validation and guards
|
|
88
|
+
*
|
|
89
|
+
* @param {object} tool - Tool definition (metadata, inputSchema, execute)
|
|
90
|
+
* @param {object} input - Tool input arguments
|
|
91
|
+
* @param {object} options - Execution options
|
|
92
|
+
* @param {object} options.dependencies - Injected dependencies (for testing)
|
|
93
|
+
* @param {object} options.config - Configuration overrides
|
|
94
|
+
* @param {object} options.context - Execution context (sessionId, etc.)
|
|
95
|
+
* @returns {Promise<object>} Tool output (success/failure with data/error)
|
|
96
|
+
*/
|
|
97
|
+
export declare function runTool(tool: ToolDefinition, input: unknown, options?: RunToolOptions): Promise<unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* Tool registry and runner class
|
|
100
|
+
*
|
|
101
|
+
* Provides a registry for tool definitions and a unified execution interface.
|
|
102
|
+
*/
|
|
103
|
+
export declare class ToolRunner {
|
|
104
|
+
#private;
|
|
105
|
+
/**
|
|
106
|
+
* Create a new ToolRunner instance
|
|
107
|
+
*
|
|
108
|
+
* @param {object} options - Runner options
|
|
109
|
+
* @param {boolean} options.enableAuditLog - Enable audit logging
|
|
110
|
+
* @param {number} options.timeoutMs - Default timeout
|
|
111
|
+
* @param {object} options.dependencies - Injected dependencies
|
|
112
|
+
*/
|
|
113
|
+
constructor(options?: ToolRunnerOptions);
|
|
114
|
+
/**
|
|
115
|
+
* Register a tool definition
|
|
116
|
+
*
|
|
117
|
+
* @param {object} tool - Tool definition
|
|
118
|
+
* @throws {Error} If tool with same name already registered
|
|
119
|
+
*/
|
|
120
|
+
register(tool: ToolDefinition): void;
|
|
121
|
+
/**
|
|
122
|
+
* Check if a tool is registered
|
|
123
|
+
*
|
|
124
|
+
* @param {string} name - Tool name
|
|
125
|
+
* @returns {boolean} True if tool exists
|
|
126
|
+
*/
|
|
127
|
+
hasTool(name: string): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Run a registered tool by name
|
|
130
|
+
*
|
|
131
|
+
* @param {string} name - Tool name
|
|
132
|
+
* @param {object} input - Tool input
|
|
133
|
+
* @param {object} options - Execution options
|
|
134
|
+
* @returns {Promise<object>} Tool output
|
|
135
|
+
*/
|
|
136
|
+
run(name: string, input: unknown, options?: RunToolOptions): Promise<unknown>;
|
|
137
|
+
/**
|
|
138
|
+
* Get runner configuration
|
|
139
|
+
*
|
|
140
|
+
* @returns {object} Current configuration
|
|
141
|
+
*/
|
|
142
|
+
getConfig(): {
|
|
143
|
+
enableAuditLog: boolean;
|
|
144
|
+
timeoutMs: number;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* List all registered tools
|
|
148
|
+
*
|
|
149
|
+
* @param {object} options - Filter options
|
|
150
|
+
* @param {string} options.domain - Filter by domain
|
|
151
|
+
* @returns {object[]} Array of tool metadata
|
|
152
|
+
*/
|
|
153
|
+
listTools(options?: ListToolsOptions): Array<{
|
|
154
|
+
name: string;
|
|
155
|
+
description: string;
|
|
156
|
+
domain?: string;
|
|
157
|
+
permission: string;
|
|
158
|
+
version?: string;
|
|
159
|
+
}>;
|
|
160
|
+
}
|
|
161
|
+
export {};
|