devworkspace 0.4.5 → 0.5.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/CHANGELOG.md +57 -0
- package/README.md +7 -0
- package/dist/cli/args.d.ts +30 -0
- package/dist/cli/args.js +10 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.js +134 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/render.d.ts +6 -0
- package/dist/cli/render.js +106 -0
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/run.js +351 -1
- package/dist/cli/run.js.map +1 -1
- package/dist/core/contracts.d.ts +70 -0
- package/dist/core/contracts.js +88 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/discovery/commands.d.ts +1 -1
- package/dist/discovery/commands.js.map +1 -1
- package/dist/discovery/detect.d.ts +2 -70
- package/dist/discovery/detect.js.map +1 -1
- package/dist/discovery/entrypoints.d.ts +2 -11
- package/dist/discovery/entrypoints.js.map +1 -1
- package/dist/discovery/types.d.ts +79 -0
- package/dist/discovery/types.js +2 -0
- package/dist/discovery/types.js.map +1 -0
- package/dist/dx/dashboard.d.ts +21 -0
- package/dist/dx/dashboard.js +274 -0
- package/dist/dx/dashboard.js.map +1 -0
- package/dist/dx/guidance.d.ts +21 -0
- package/dist/dx/guidance.js +266 -0
- package/dist/dx/guidance.js.map +1 -0
- package/dist/dx/index.d.ts +4 -0
- package/dist/dx/index.js +5 -0
- package/dist/dx/index.js.map +1 -0
- package/dist/dx/onboarding.d.ts +23 -0
- package/dist/dx/onboarding.js +155 -0
- package/dist/dx/onboarding.js.map +1 -0
- package/dist/dx/types.d.ts +70 -0
- package/dist/dx/types.js +3 -0
- package/dist/dx/types.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/persistentPath.d.ts +2 -9
- package/dist/integrations/persistentPath.js.map +1 -1
- package/dist/integrations/types.d.ts +4 -1
- package/dist/integrations/types.js.map +1 -1
- package/dist/intelligence/agents/profiles.d.ts +2 -0
- package/dist/intelligence/agents/profiles.js +326 -0
- package/dist/intelligence/agents/profiles.js.map +1 -0
- package/dist/intelligence/agents/registry.d.ts +15 -0
- package/dist/intelligence/agents/registry.js +108 -0
- package/dist/intelligence/agents/registry.js.map +1 -0
- package/dist/intelligence/agents/types.d.ts +43 -0
- package/dist/intelligence/agents/types.js +2 -0
- package/dist/intelligence/agents/types.js.map +1 -0
- package/dist/intelligence/observability/tracer.d.ts +13 -0
- package/dist/intelligence/observability/tracer.js +129 -0
- package/dist/intelligence/observability/tracer.js.map +1 -0
- package/dist/intelligence/observability/types.d.ts +38 -0
- package/dist/intelligence/observability/types.js +2 -0
- package/dist/intelligence/observability/types.js.map +1 -0
- package/dist/intelligence/orchestration/engine.d.ts +42 -0
- package/dist/intelligence/orchestration/engine.js +418 -0
- package/dist/intelligence/orchestration/engine.js.map +1 -0
- package/dist/intelligence/orchestration/lock-manager.d.ts +21 -0
- package/dist/intelligence/orchestration/lock-manager.js +70 -0
- package/dist/intelligence/orchestration/lock-manager.js.map +1 -0
- package/dist/intelligence/orchestration/store.d.ts +11 -0
- package/dist/intelligence/orchestration/store.js +73 -0
- package/dist/intelligence/orchestration/store.js.map +1 -0
- package/dist/intelligence/orchestration/types.d.ts +100 -0
- package/dist/intelligence/orchestration/types.js +48 -0
- package/dist/intelligence/orchestration/types.js.map +1 -0
- package/dist/intelligence/routing/matcher.d.ts +7 -0
- package/dist/intelligence/routing/matcher.js +96 -0
- package/dist/intelligence/routing/matcher.js.map +1 -0
- package/dist/intelligence/routing/router.d.ts +9 -0
- package/dist/intelligence/routing/router.js +198 -0
- package/dist/intelligence/routing/router.js.map +1 -0
- package/dist/intelligence/routing/types.d.ts +64 -0
- package/dist/intelligence/routing/types.js +2 -0
- package/dist/intelligence/routing/types.js.map +1 -0
- package/dist/intelligence/runtime/adk/adapter.d.ts +7 -0
- package/dist/intelligence/runtime/adk/adapter.js +60 -0
- package/dist/intelligence/runtime/adk/adapter.js.map +1 -0
- package/dist/intelligence/runtime/adk/detector.d.ts +7 -0
- package/dist/intelligence/runtime/adk/detector.js +28 -0
- package/dist/intelligence/runtime/adk/detector.js.map +1 -0
- package/dist/intelligence/runtime/external.d.ts +9 -0
- package/dist/intelligence/runtime/external.js +102 -0
- package/dist/intelligence/runtime/external.js.map +1 -0
- package/dist/intelligence/runtime/native.d.ts +19 -0
- package/dist/intelligence/runtime/native.js +99 -0
- package/dist/intelligence/runtime/native.js.map +1 -0
- package/dist/intelligence/runtime/types.d.ts +49 -0
- package/dist/intelligence/runtime/types.js +2 -0
- package/dist/intelligence/runtime/types.js.map +1 -0
- package/dist/intelligence/security/audit.d.ts +8 -0
- package/dist/intelligence/security/audit.js +43 -0
- package/dist/intelligence/security/audit.js.map +1 -0
- package/dist/intelligence/security/policy.d.ts +12 -0
- package/dist/intelligence/security/policy.js +153 -0
- package/dist/intelligence/security/policy.js.map +1 -0
- package/dist/intelligence/security/types.d.ts +25 -0
- package/dist/intelligence/security/types.js +2 -0
- package/dist/intelligence/security/types.js.map +1 -0
- package/dist/intelligence/skills/builtins.d.ts +2 -0
- package/dist/intelligence/skills/builtins.js +379 -0
- package/dist/intelligence/skills/builtins.js.map +1 -0
- package/dist/intelligence/skills/loader.d.ts +4 -0
- package/dist/intelligence/skills/loader.js +84 -0
- package/dist/intelligence/skills/loader.js.map +1 -0
- package/dist/intelligence/skills/registry.d.ts +15 -0
- package/dist/intelligence/skills/registry.js +134 -0
- package/dist/intelligence/skills/registry.js.map +1 -0
- package/dist/intelligence/skills/types.d.ts +35 -0
- package/dist/intelligence/skills/types.js +2 -0
- package/dist/intelligence/skills/types.js.map +1 -0
- package/dist/intelligence/verification/engine.d.ts +23 -0
- package/dist/intelligence/verification/engine.js +66 -0
- package/dist/intelligence/verification/engine.js.map +1 -0
- package/dist/intelligence/verification/reviewer.d.ts +8 -0
- package/dist/intelligence/verification/reviewer.js +55 -0
- package/dist/intelligence/verification/reviewer.js.map +1 -0
- package/dist/intelligence/verification/types.d.ts +32 -0
- package/dist/intelligence/verification/types.js +2 -0
- package/dist/intelligence/verification/types.js.map +1 -0
- package/dist/mcp/setup.d.ts +2 -4
- package/dist/mcp/setup.js.map +1 -1
- package/dist/mcp/tools.js +6 -6
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +4 -0
- package/dist/mcp/types.js.map +1 -1
- package/dist/mcp/verify.d.ts +1 -1
- package/dist/mcp/verify.js.map +1 -1
- package/dist/security/redact.js +3 -2
- package/dist/security/redact.js.map +1 -1
- package/dist/services/doctor.js +4 -0
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/intelligence.d.ts +44 -0
- package/dist/services/intelligence.js +119 -0
- package/dist/services/intelligence.js.map +1 -0
- package/dist/services/standards.d.ts +85 -0
- package/dist/services/standards.js +230 -0
- package/dist/services/standards.js.map +1 -0
- package/dist/services/taskContext.js +4 -0
- package/dist/services/taskContext.js.map +1 -1
- package/dist/standards/acquisition/ingest.d.ts +12 -0
- package/dist/standards/acquisition/ingest.js +98 -0
- package/dist/standards/acquisition/ingest.js.map +1 -0
- package/dist/standards/applicability/engine.d.ts +38 -0
- package/dist/standards/applicability/engine.js +250 -0
- package/dist/standards/applicability/engine.js.map +1 -0
- package/dist/standards/builtin/code-quality.d.ts +2 -0
- package/dist/standards/builtin/code-quality.js +53 -0
- package/dist/standards/builtin/code-quality.js.map +1 -0
- package/dist/standards/builtin/database-safety.d.ts +2 -0
- package/dist/standards/builtin/database-safety.js +56 -0
- package/dist/standards/builtin/database-safety.js.map +1 -0
- package/dist/standards/builtin/index.d.ts +8 -0
- package/dist/standards/builtin/index.js +14 -0
- package/dist/standards/builtin/index.js.map +1 -0
- package/dist/standards/builtin/security-baseline.d.ts +2 -0
- package/dist/standards/builtin/security-baseline.js +64 -0
- package/dist/standards/builtin/security-baseline.js.map +1 -0
- package/dist/standards/builtin/testing-contracts.d.ts +2 -0
- package/dist/standards/builtin/testing-contracts.js +54 -0
- package/dist/standards/builtin/testing-contracts.js.map +1 -0
- package/dist/standards/builtin/undo-kit.d.ts +8 -0
- package/dist/standards/builtin/undo-kit.js +106 -0
- package/dist/standards/builtin/undo-kit.js.map +1 -0
- package/dist/standards/config/config.d.ts +12 -0
- package/dist/standards/config/config.js +110 -0
- package/dist/standards/config/config.js.map +1 -0
- package/dist/standards/distribution/cache.d.ts +57 -0
- package/dist/standards/distribution/cache.js +411 -0
- package/dist/standards/distribution/cache.js.map +1 -0
- package/dist/standards/distribution/index.d.ts +6 -0
- package/dist/standards/distribution/index.js +7 -0
- package/dist/standards/distribution/index.js.map +1 -0
- package/dist/standards/distribution/keys.d.ts +53 -0
- package/dist/standards/distribution/keys.js +269 -0
- package/dist/standards/distribution/keys.js.map +1 -0
- package/dist/standards/distribution/package.d.ts +25 -0
- package/dist/standards/distribution/package.js +248 -0
- package/dist/standards/distribution/package.js.map +1 -0
- package/dist/standards/distribution/server.d.ts +38 -0
- package/dist/standards/distribution/server.js +204 -0
- package/dist/standards/distribution/server.js.map +1 -0
- package/dist/standards/distribution/sync.d.ts +51 -0
- package/dist/standards/distribution/sync.js +212 -0
- package/dist/standards/distribution/sync.js.map +1 -0
- package/dist/standards/distribution/types.d.ts +140 -0
- package/dist/standards/distribution/types.js +26 -0
- package/dist/standards/distribution/types.js.map +1 -0
- package/dist/standards/engine/compliance.d.ts +2 -0
- package/dist/standards/engine/compliance.js +45 -0
- package/dist/standards/engine/compliance.js.map +1 -0
- package/dist/standards/engine/engine.d.ts +14 -0
- package/dist/standards/engine/engine.js +114 -0
- package/dist/standards/engine/engine.js.map +1 -0
- package/dist/standards/engine/reporter.d.ts +2 -0
- package/dist/standards/engine/reporter.js +42 -0
- package/dist/standards/engine/reporter.js.map +1 -0
- package/dist/standards/index.d.ts +18 -0
- package/dist/standards/index.js +19 -0
- package/dist/standards/index.js.map +1 -0
- package/dist/standards/registry/registry.d.ts +29 -0
- package/dist/standards/registry/registry.js +210 -0
- package/dist/standards/registry/registry.js.map +1 -0
- package/dist/standards/schema/types.d.ts +133 -0
- package/dist/standards/schema/types.js +33 -0
- package/dist/standards/schema/types.js.map +1 -0
- package/dist/standards/schema/validate.d.ts +6 -0
- package/dist/standards/schema/validate.js +131 -0
- package/dist/standards/schema/validate.js.map +1 -0
- package/dist/standards/templates/index.d.ts +11 -0
- package/dist/standards/templates/index.js +176 -0
- package/dist/standards/templates/index.js.map +1 -0
- package/dist/standards/validators/database.d.ts +5 -0
- package/dist/standards/validators/database.js +122 -0
- package/dist/standards/validators/database.js.map +1 -0
- package/dist/standards/validators/quality.d.ts +6 -0
- package/dist/standards/validators/quality.js +91 -0
- package/dist/standards/validators/quality.js.map +1 -0
- package/dist/standards/validators/registry.d.ts +11 -0
- package/dist/standards/validators/registry.js +83 -0
- package/dist/standards/validators/registry.js.map +1 -0
- package/dist/standards/validators/security.d.ts +7 -0
- package/dist/standards/validators/security.js +182 -0
- package/dist/standards/validators/security.js.map +1 -0
- package/dist/standards/validators/testing.d.ts +6 -0
- package/dist/standards/validators/testing.js +142 -0
- package/dist/standards/validators/testing.js.map +1 -0
- package/dist/standards/validators/types.d.ts +11 -0
- package/dist/standards/validators/types.js +2 -0
- package/dist/standards/validators/types.js.map +1 -0
- package/dist/standards/validators/undo-kit.d.ts +7 -0
- package/dist/standards/validators/undo-kit.js +334 -0
- package/dist/standards/validators/undo-kit.js.map +1 -0
- package/dist/tasks/routing.js +5 -3
- package/dist/tasks/routing.js.map +1 -1
- package/dist/utils/fs.d.ts +1 -1
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/lock.js +11 -3
- package/dist/utils/lock.js.map +1 -1
- package/dist/utils/paths.js +29 -0
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/proc.js +2 -0
- package/dist/utils/proc.js.map +1 -1
- package/docs/contributing.md +9 -0
- package/docs/getting-started.md +7 -0
- package/docs/security/HOME_SERVER_THREAT_MODEL.md +72 -0
- package/docs/security/THREAT_MODEL.md +101 -0
- package/docs/standards.md +143 -0
- package/package.json +1 -1
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { existsSync, promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export async function validateRollbackPlan(ctx) {
|
|
4
|
+
const ruleId = ctx.rule?.id ?? 'deployment.rollback-plan';
|
|
5
|
+
const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';
|
|
6
|
+
const title = ctx.rule?.title ?? 'Rollback Plan Documented';
|
|
7
|
+
const severity = ctx.rule?.severity ?? 'high';
|
|
8
|
+
const rollbackPath = path.join(ctx.workspaceDir, 'ROLLBACK.md');
|
|
9
|
+
if (!existsSync(rollbackPath)) {
|
|
10
|
+
return {
|
|
11
|
+
ruleId,
|
|
12
|
+
standardId,
|
|
13
|
+
title,
|
|
14
|
+
status: 'FAIL',
|
|
15
|
+
passed: false,
|
|
16
|
+
severity,
|
|
17
|
+
message: 'ROLLBACK.md is missing from project root.',
|
|
18
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
19
|
+
remediation: 'Create ROLLBACK.md at the project root using the Undo Kit template. Run "devworkspace standards apply deployment-safety-and-rollback" to generate it.',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const content = await fs.readFile(rollbackPath, 'utf8');
|
|
24
|
+
const lower = content.toLowerCase();
|
|
25
|
+
const missingSections = [];
|
|
26
|
+
if (!lower.includes('hosting') && !lower.includes('deploy'))
|
|
27
|
+
missingSections.push('Hosting Rollback (Button 1)');
|
|
28
|
+
if (!lower.includes('backup') && !lower.includes('database'))
|
|
29
|
+
missingSections.push('Database Backup (Button 2)');
|
|
30
|
+
if (!lower.includes('switch') && !lower.includes('flag'))
|
|
31
|
+
missingSections.push('Feature Switch (Button 3)');
|
|
32
|
+
if (!lower.includes('practice') && !lower.includes('rehearsal'))
|
|
33
|
+
missingSections.push('Recovery Rehearsal (Button 4)');
|
|
34
|
+
if (missingSections.length > 0) {
|
|
35
|
+
return {
|
|
36
|
+
ruleId,
|
|
37
|
+
standardId,
|
|
38
|
+
title,
|
|
39
|
+
status: 'WARN',
|
|
40
|
+
passed: false,
|
|
41
|
+
severity: 'medium',
|
|
42
|
+
message: `ROLLBACK.md is present but missing required Undo Kit sections: ${missingSections.join(', ')}.`,
|
|
43
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
44
|
+
remediation: 'Update ROLLBACK.md to cover all 4 Undo Kit buttons: Hosting Deploy, Backup First, Feature Switch, and Rehearsal.',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
ruleId,
|
|
49
|
+
standardId,
|
|
50
|
+
title,
|
|
51
|
+
status: 'PASS',
|
|
52
|
+
passed: true,
|
|
53
|
+
severity,
|
|
54
|
+
message: 'ROLLBACK.md is present and contains all required Undo Kit operational sections.',
|
|
55
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
return {
|
|
60
|
+
ruleId,
|
|
61
|
+
standardId,
|
|
62
|
+
title,
|
|
63
|
+
status: 'FAIL',
|
|
64
|
+
passed: false,
|
|
65
|
+
severity,
|
|
66
|
+
message: `Failed to read ROLLBACK.md: ${e instanceof Error ? e.message : String(e)}`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export async function validateLastGoodDeploy(ctx) {
|
|
71
|
+
const ruleId = ctx.rule?.id ?? 'deployment.last-good-deploy';
|
|
72
|
+
const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';
|
|
73
|
+
const title = ctx.rule?.title ?? 'Last Good Deploy Mechanism';
|
|
74
|
+
const severity = ctx.rule?.severity ?? 'high';
|
|
75
|
+
const rollbackPath = path.join(ctx.workspaceDir, 'ROLLBACK.md');
|
|
76
|
+
if (!existsSync(rollbackPath)) {
|
|
77
|
+
return {
|
|
78
|
+
ruleId,
|
|
79
|
+
standardId,
|
|
80
|
+
title,
|
|
81
|
+
status: 'FAIL',
|
|
82
|
+
passed: false,
|
|
83
|
+
severity,
|
|
84
|
+
message: 'Cannot verify Last Good Deploy procedure because ROLLBACK.md is missing.',
|
|
85
|
+
remediation: 'Document your hosting platform and exact instant rollback steps in ROLLBACK.md.',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const content = await fs.readFile(rollbackPath, 'utf8');
|
|
89
|
+
const lower = content.toLowerCase();
|
|
90
|
+
const hostingDetected = lower.includes('vercel') ||
|
|
91
|
+
lower.includes('netlify') ||
|
|
92
|
+
lower.includes('docker') ||
|
|
93
|
+
lower.includes('cloudflare') ||
|
|
94
|
+
lower.includes('aws') ||
|
|
95
|
+
lower.includes('render') ||
|
|
96
|
+
lower.includes('railway') ||
|
|
97
|
+
lower.includes('fly.io') ||
|
|
98
|
+
lower.includes('heroku') ||
|
|
99
|
+
lower.includes('kubernetes') ||
|
|
100
|
+
lower.includes('button 1') ||
|
|
101
|
+
lower.includes('last good deploy');
|
|
102
|
+
if (!hostingDetected) {
|
|
103
|
+
return {
|
|
104
|
+
ruleId,
|
|
105
|
+
standardId,
|
|
106
|
+
title,
|
|
107
|
+
status: 'WARN',
|
|
108
|
+
passed: false,
|
|
109
|
+
severity: 'medium',
|
|
110
|
+
message: 'ROLLBACK.md does not specify a recognized hosting platform rollback procedure.',
|
|
111
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
112
|
+
remediation: 'Document the specific hosting rollback steps (e.g. Vercel Instant Rollback, Netlify Publish Deploy) in ROLLBACK.md.',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
ruleId,
|
|
117
|
+
standardId,
|
|
118
|
+
title,
|
|
119
|
+
status: 'PASS',
|
|
120
|
+
passed: true,
|
|
121
|
+
severity,
|
|
122
|
+
message: 'Hosting rollback mechanism is documented in ROLLBACK.md.',
|
|
123
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export async function validateBackupFirst(ctx) {
|
|
127
|
+
const ruleId = ctx.rule?.id ?? 'deployment.backup-first';
|
|
128
|
+
const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';
|
|
129
|
+
const title = ctx.rule?.title ?? 'Backup First Procedure';
|
|
130
|
+
const severity = ctx.rule?.severity ?? 'high';
|
|
131
|
+
// 1. Check package.json scripts first
|
|
132
|
+
const pkgPath = path.join(ctx.workspaceDir, 'package.json');
|
|
133
|
+
if (existsSync(pkgPath)) {
|
|
134
|
+
try {
|
|
135
|
+
const raw = await fs.readFile(pkgPath, 'utf8');
|
|
136
|
+
const pkg = JSON.parse(raw);
|
|
137
|
+
const scripts = pkg.scripts || {};
|
|
138
|
+
for (const [key, val] of Object.entries(scripts)) {
|
|
139
|
+
if (key.includes('backup') || key.includes('dump') || (typeof val === 'string' && val.includes('dump'))) {
|
|
140
|
+
return {
|
|
141
|
+
ruleId,
|
|
142
|
+
standardId,
|
|
143
|
+
title,
|
|
144
|
+
status: 'PASS',
|
|
145
|
+
passed: true,
|
|
146
|
+
severity,
|
|
147
|
+
message: `Automated database backup script detected in package.json: "${key}".`,
|
|
148
|
+
evidence: { file: 'package.json', details: { script: key, command: val } },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (_err) {
|
|
154
|
+
void _err;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const rollbackPath = path.join(ctx.workspaceDir, 'ROLLBACK.md');
|
|
158
|
+
if (!existsSync(rollbackPath)) {
|
|
159
|
+
return {
|
|
160
|
+
ruleId,
|
|
161
|
+
standardId,
|
|
162
|
+
title,
|
|
163
|
+
status: 'FAIL',
|
|
164
|
+
passed: false,
|
|
165
|
+
severity,
|
|
166
|
+
message: 'Database backup procedure is not documented (ROLLBACK.md missing).',
|
|
167
|
+
remediation: 'Add a Backup First section to ROLLBACK.md with the exact dump command and test restore procedure.',
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const content = await fs.readFile(rollbackPath, 'utf8');
|
|
171
|
+
const hasBackupCommand = content.includes('dump') ||
|
|
172
|
+
content.includes('pg_dump') ||
|
|
173
|
+
content.includes('supabase db dump') ||
|
|
174
|
+
content.includes('mongodump') ||
|
|
175
|
+
content.includes('sqlite3') ||
|
|
176
|
+
content.includes('mysqldump');
|
|
177
|
+
if (!hasBackupCommand) {
|
|
178
|
+
return {
|
|
179
|
+
ruleId,
|
|
180
|
+
standardId,
|
|
181
|
+
title,
|
|
182
|
+
status: 'WARN',
|
|
183
|
+
passed: false,
|
|
184
|
+
severity: 'high',
|
|
185
|
+
message: 'ROLLBACK.md mentions backups but lacks a concrete dump command (e.g. supabase db dump, pg_dump).',
|
|
186
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
187
|
+
remediation: 'Include the exact runnable backup command in step 1 of your deploy checklist in ROLLBACK.md.',
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
ruleId,
|
|
192
|
+
standardId,
|
|
193
|
+
title,
|
|
194
|
+
status: 'PASS',
|
|
195
|
+
passed: true,
|
|
196
|
+
severity,
|
|
197
|
+
message: 'Database backup procedure and runnable command are verified in ROLLBACK.md.',
|
|
198
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
export async function validateFeatureFlags(ctx) {
|
|
202
|
+
const ruleId = ctx.rule?.id ?? 'deployment.feature-flags';
|
|
203
|
+
const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';
|
|
204
|
+
const title = ctx.rule?.title ?? 'Feature Flag Kill-Switch Capability';
|
|
205
|
+
const severity = ctx.rule?.severity ?? 'high';
|
|
206
|
+
const candidateFiles = [
|
|
207
|
+
'prisma/schema.prisma',
|
|
208
|
+
'backend/prisma/schema.prisma',
|
|
209
|
+
'src/config/features.ts',
|
|
210
|
+
'backend/src/config/features.ts',
|
|
211
|
+
'src/flags/features.ts',
|
|
212
|
+
'src/feature-flags.ts',
|
|
213
|
+
'src/features.ts',
|
|
214
|
+
'ROLLBACK.md',
|
|
215
|
+
];
|
|
216
|
+
let found = false;
|
|
217
|
+
let matchingFile;
|
|
218
|
+
for (const rel of candidateFiles) {
|
|
219
|
+
const full = path.join(ctx.workspaceDir, rel);
|
|
220
|
+
if (existsSync(full)) {
|
|
221
|
+
try {
|
|
222
|
+
const text = await fs.readFile(full, 'utf8');
|
|
223
|
+
if (text.includes('feature_flags') || text.includes('featureFlags') || text.includes('FeatureFlag')) {
|
|
224
|
+
found = true;
|
|
225
|
+
matchingFile = rel;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (_err) {
|
|
230
|
+
void _err;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Also check recursively under src/ if not found
|
|
235
|
+
if (!found) {
|
|
236
|
+
const checkDir = async (dir, depth = 0) => {
|
|
237
|
+
if (depth > 3 || found)
|
|
238
|
+
return;
|
|
239
|
+
if (!existsSync(dir))
|
|
240
|
+
return;
|
|
241
|
+
try {
|
|
242
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
243
|
+
for (const e of entries) {
|
|
244
|
+
if (found)
|
|
245
|
+
break;
|
|
246
|
+
const p = path.join(dir, e.name);
|
|
247
|
+
if (e.isDirectory() && !['node_modules', '.git', 'dist'].includes(e.name)) {
|
|
248
|
+
await checkDir(p, depth + 1);
|
|
249
|
+
}
|
|
250
|
+
else if (e.isFile() && (e.name.includes('flag') || e.name.includes('feature'))) {
|
|
251
|
+
const text = await fs.readFile(p, 'utf8');
|
|
252
|
+
if (text.includes('featureFlags') || text.includes('feature_flags') || text.includes('FeatureFlag')) {
|
|
253
|
+
found = true;
|
|
254
|
+
matchingFile = path.relative(ctx.workspaceDir, p).replace(/\\/g, '/');
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (_err) {
|
|
261
|
+
void _err;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
await checkDir(path.join(ctx.workspaceDir, 'src'));
|
|
265
|
+
}
|
|
266
|
+
if (!found) {
|
|
267
|
+
return {
|
|
268
|
+
ruleId,
|
|
269
|
+
standardId,
|
|
270
|
+
title,
|
|
271
|
+
status: 'WARN',
|
|
272
|
+
passed: false,
|
|
273
|
+
severity: 'medium',
|
|
274
|
+
message: 'No feature flag table or configuration switch (e.g. feature_flags) detected in schema or code.',
|
|
275
|
+
remediation: 'Implement an on/off feature switch (Button 3 of the Undo Kit) so new capabilities can be disabled instantly without redeploying.',
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
ruleId,
|
|
280
|
+
standardId,
|
|
281
|
+
title,
|
|
282
|
+
status: 'PASS',
|
|
283
|
+
passed: true,
|
|
284
|
+
severity,
|
|
285
|
+
message: `Feature switch capability detected in ${matchingFile}.`,
|
|
286
|
+
evidence: { file: matchingFile },
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
export async function validateRecoveryRehearsal(ctx) {
|
|
290
|
+
const ruleId = ctx.rule?.id ?? 'deployment.recovery-rehearsal';
|
|
291
|
+
const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';
|
|
292
|
+
const title = ctx.rule?.title ?? 'Documented Recovery Rehearsal';
|
|
293
|
+
const severity = ctx.rule?.severity ?? 'high';
|
|
294
|
+
const rollbackPath = path.join(ctx.workspaceDir, 'ROLLBACK.md');
|
|
295
|
+
if (!existsSync(rollbackPath)) {
|
|
296
|
+
return {
|
|
297
|
+
ruleId,
|
|
298
|
+
standardId,
|
|
299
|
+
title,
|
|
300
|
+
status: 'SKIPPED',
|
|
301
|
+
passed: false,
|
|
302
|
+
severity,
|
|
303
|
+
message: 'Cannot verify recovery rehearsal because ROLLBACK.md is missing.',
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
const content = await fs.readFile(rollbackPath, 'utf8');
|
|
307
|
+
const lower = content.toLowerCase();
|
|
308
|
+
const hasRehearsalEvidence = lower.includes('rehearsal log') &&
|
|
309
|
+
(lower.includes('pass') || lower.includes('staging') || lower.includes('202') || lower.includes('drill'));
|
|
310
|
+
if (!hasRehearsalEvidence) {
|
|
311
|
+
return {
|
|
312
|
+
ruleId,
|
|
313
|
+
standardId,
|
|
314
|
+
title,
|
|
315
|
+
status: 'WARN',
|
|
316
|
+
passed: false,
|
|
317
|
+
severity: 'medium',
|
|
318
|
+
message: 'No recorded recovery rehearsal entries found in ROLLBACK.md.',
|
|
319
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
320
|
+
remediation: 'Practice the 4 undo buttons on a quiet day: roll back once, restore once, flip the switch once, and record times in ROLLBACK.md.',
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
ruleId,
|
|
325
|
+
standardId,
|
|
326
|
+
title,
|
|
327
|
+
status: 'PASS',
|
|
328
|
+
passed: true,
|
|
329
|
+
severity,
|
|
330
|
+
message: 'Recovery rehearsal log verified in ROLLBACK.md.',
|
|
331
|
+
evidence: { file: 'ROLLBACK.md' },
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
//# sourceMappingURL=undo-kit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"undo-kit.js","sourceRoot":"","sources":["../../../src/standards/validators/undo-kit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,GAAqB;IAC9D,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,0BAA0B,CAAC;IAC1D,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,EAAE,EAAE,IAAI,gCAAgC,CAAC;IACxE,MAAM,KAAK,GAAG,G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D;YACvE,QAAQ,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;YACjC,WAAW,EACT,kIAAkI;SACrI,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM;QACN,UAAU;QACV,KAAK;QACL,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,IAAI;QACZ,QAAQ;QACR,OAAO,EAAE,iDAAiD;QAC1D,QAAQ,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;KAClC,CAAC;AACJ,CAAC","sourcesContent":["import { existsSync, promises as fs } from 'node:fs';\nimport path from 'node:path';\nimport type { ValidationResult } from '../schema/types.js';\nimport type { ValidatorContext } from './types.js';\n\nexport async function validateRollbackPlan(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'deployment.rollback-plan';\n const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';\n const title = ctx.rule?.title ?? 'Rollback Plan Documented';\n const severity = ctx.rule?.severity ?? 'high';\n\n const rollbackPath = path.join(ctx.workspaceDir, 'ROLLBACK.md');\n if (!existsSync(rollbackPath)) {\n return {\n ruleId,\n standardId,\n title,\n status: 'FAIL',\n passed: false,\n severity,\n message: 'ROLLBACK.md is missing from project root.',\n evidence: { file: 'ROLLBACK.md' },\n remediation:\n 'Create ROLLBACK.md at the project root using the Undo Kit template. Run \"devworkspace standards apply deployment-safety-and-rollback\" to generate it.',\n };\n }\n\n try {\n const content = await fs.readFile(rollbackPath, 'utf8');\n const lower = content.toLowerCase();\n\n const missingSections: string[] = [];\n if (!lower.includes('hosting') && !lower.includes('deploy')) missingSections.push('Hosting Rollback (Button 1)');\n if (!lower.includes('backup') && !lower.includes('database')) missingSections.push('Database Backup (Button 2)');\n if (!lower.includes('switch') && !lower.includes('flag')) missingSections.push('Feature Switch (Button 3)');\n if (!lower.includes('practice') && !lower.includes('rehearsal')) missingSections.push('Recovery Rehearsal (Button 4)');\n\n if (missingSections.length > 0) {\n return {\n ruleId,\n standardId,\n title,\n status: 'WARN',\n passed: false,\n severity: 'medium',\n message: `ROLLBACK.md is present but missing required Undo Kit sections: ${missingSections.join(', ')}.`,\n evidence: { file: 'ROLLBACK.md' },\n remediation: 'Update ROLLBACK.md to cover all 4 Undo Kit buttons: Hosting Deploy, Backup First, Feature Switch, and Rehearsal.',\n };\n }\n\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity,\n message: 'ROLLBACK.md is present and contains all required Undo Kit operational sections.',\n evidence: { file: 'ROLLBACK.md' },\n };\n } catch (e) {\n return {\n ruleId,\n standardId,\n title,\n status: 'FAIL',\n passed: false,\n severity,\n message: `Failed to read ROLLBACK.md: ${e instanceof Error ? e.message : String(e)}`,\n };\n }\n}\n\nexport async function validateLastGoodDeploy(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'deployment.last-good-deploy';\n const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';\n const title = ctx.rule?.title ?? 'Last Good Deploy Mechanism';\n const severity = ctx.rule?.severity ?? 'high';\n\n const rollbackPath = path.join(ctx.workspaceDir, 'ROLLBACK.md');\n if (!existsSync(rollbackPath)) {\n return {\n ruleId,\n standardId,\n title,\n status: 'FAIL',\n passed: false,\n severity,\n message: 'Cannot verify Last Good Deploy procedure because ROLLBACK.md is missing.',\n remediation: 'Document your hosting platform and exact instant rollback steps in ROLLBACK.md.',\n };\n }\n\n const content = await fs.readFile(rollbackPath, 'utf8');\n const lower = content.toLowerCase();\n\n const hostingDetected =\n lower.includes('vercel') ||\n lower.includes('netlify') ||\n lower.includes('docker') ||\n lower.includes('cloudflare') ||\n lower.includes('aws') ||\n lower.includes('render') ||\n lower.includes('railway') ||\n lower.includes('fly.io') ||\n lower.includes('heroku') ||\n lower.includes('kubernetes') ||\n lower.includes('button 1') ||\n lower.includes('last good deploy');\n\n if (!hostingDetected) {\n return {\n ruleId,\n standardId,\n title,\n status: 'WARN',\n passed: false,\n severity: 'medium',\n message: 'ROLLBACK.md does not specify a recognized hosting platform rollback procedure.',\n evidence: { file: 'ROLLBACK.md' },\n remediation: 'Document the specific hosting rollback steps (e.g. Vercel Instant Rollback, Netlify Publish Deploy) in ROLLBACK.md.',\n };\n }\n\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity,\n message: 'Hosting rollback mechanism is documented in ROLLBACK.md.',\n evidence: { file: 'ROLLBACK.md' },\n };\n}\n\nexport async function validateBackupFirst(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'deployment.backup-first';\n const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';\n const title = ctx.rule?.title ?? 'Backup First Procedure';\n const severity = ctx.rule?.severity ?? 'high';\n\n // 1. Check package.json scripts first\n const pkgPath = path.join(ctx.workspaceDir, 'package.json');\n if (existsSync(pkgPath)) {\n try {\n const raw = await fs.readFile(pkgPath, 'utf8');\n const pkg = JSON.parse(raw);\n const scripts = pkg.scripts || {};\n for (const [key, val] of Object.entries(scripts)) {\n if (key.includes('backup') || key.includes('dump') || (typeof val === 'string' && val.includes('dump'))) {\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity,\n message: `Automated database backup script detected in package.json: \"${key}\".`,\n evidence: { file: 'package.json', details: { script: key, command: val } },\n };\n }\n }\n } catch (_err) {\n void _err;\n }\n }\n\n const rollbackPath = path.join(ctx.workspaceDir, 'ROLLBACK.md');\n if (!existsSync(rollbackPath)) {\n return {\n ruleId,\n standardId,\n title,\n status: 'FAIL',\n passed: false,\n severity,\n message: 'Database backup procedure is not documented (ROLLBACK.md missing).',\n remediation: 'Add a Backup First section to ROLLBACK.md with the exact dump command and test restore procedure.',\n };\n }\n\n const content = await fs.readFile(rollbackPath, 'utf8');\n const hasBackupCommand =\n content.includes('dump') ||\n content.includes('pg_dump') ||\n content.includes('supabase db dump') ||\n content.includes('mongodump') ||\n content.includes('sqlite3') ||\n content.includes('mysqldump');\n\n if (!hasBackupCommand) {\n return {\n ruleId,\n standardId,\n title,\n status: 'WARN',\n passed: false,\n severity: 'high',\n message: 'ROLLBACK.md mentions backups but lacks a concrete dump command (e.g. supabase db dump, pg_dump).',\n evidence: { file: 'ROLLBACK.md' },\n remediation: 'Include the exact runnable backup command in step 1 of your deploy checklist in ROLLBACK.md.',\n };\n }\n\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity,\n message: 'Database backup procedure and runnable command are verified in ROLLBACK.md.',\n evidence: { file: 'ROLLBACK.md' },\n };\n}\n\nexport async function validateFeatureFlags(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'deployment.feature-flags';\n const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';\n const title = ctx.rule?.title ?? 'Feature Flag Kill-Switch Capability';\n const severity = ctx.rule?.severity ?? 'high';\n\n const candidateFiles = [\n 'prisma/schema.prisma',\n 'backend/prisma/schema.prisma',\n 'src/config/features.ts',\n 'backend/src/config/features.ts',\n 'src/flags/features.ts',\n 'src/feature-flags.ts',\n 'src/features.ts',\n 'ROLLBACK.md',\n ];\n\n let found = false;\n let matchingFile: string | undefined;\n\n for (const rel of candidateFiles) {\n const full = path.join(ctx.workspaceDir, rel);\n if (existsSync(full)) {\n try {\n const text = await fs.readFile(full, 'utf8');\n if (text.includes('feature_flags') || text.includes('featureFlags') || text.includes('FeatureFlag')) {\n found = true;\n matchingFile = rel;\n break;\n }\n } catch (_err) {\n void _err;\n }\n }\n }\n\n // Also check recursively under src/ if not found\n if (!found) {\n const checkDir = async (dir: string, depth = 0): Promise<void> => {\n if (depth > 3 || found) return;\n if (!existsSync(dir)) return;\n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n for (const e of entries) {\n if (found) break;\n const p = path.join(dir, e.name);\n if (e.isDirectory() && !['node_modules', '.git', 'dist'].includes(e.name)) {\n await checkDir(p, depth + 1);\n } else if (e.isFile() && (e.name.includes('flag') || e.name.includes('feature'))) {\n const text = await fs.readFile(p, 'utf8');\n if (text.includes('featureFlags') || text.includes('feature_flags') || text.includes('FeatureFlag')) {\n found = true;\n matchingFile = path.relative(ctx.workspaceDir, p).replace(/\\\\/g, '/');\n break;\n }\n }\n }\n } catch (_err) {\n void _err;\n }\n };\n await checkDir(path.join(ctx.workspaceDir, 'src'));\n }\n\n if (!found) {\n return {\n ruleId,\n standardId,\n title,\n status: 'WARN',\n passed: false,\n severity: 'medium',\n message: 'No feature flag table or configuration switch (e.g. feature_flags) detected in schema or code.',\n remediation:\n 'Implement an on/off feature switch (Button 3 of the Undo Kit) so new capabilities can be disabled instantly without redeploying.',\n };\n }\n\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity,\n message: `Feature switch capability detected in ${matchingFile}.`,\n evidence: { file: matchingFile },\n };\n}\n\nexport async function validateRecoveryRehearsal(ctx: ValidatorContext): Promise<ValidationResult> {\n const ruleId = ctx.rule?.id ?? 'deployment.recovery-rehearsal';\n const standardId = ctx.standard?.id ?? 'deployment-safety-and-rollback';\n const title = ctx.rule?.title ?? 'Documented Recovery Rehearsal';\n const severity = ctx.rule?.severity ?? 'high';\n\n const rollbackPath = path.join(ctx.workspaceDir, 'ROLLBACK.md');\n if (!existsSync(rollbackPath)) {\n return {\n ruleId,\n standardId,\n title,\n status: 'SKIPPED',\n passed: false,\n severity,\n message: 'Cannot verify recovery rehearsal because ROLLBACK.md is missing.',\n };\n }\n\n const content = await fs.readFile(rollbackPath, 'utf8');\n const lower = content.toLowerCase();\n\n const hasRehearsalEvidence =\n lower.includes('rehearsal log') &&\n (lower.includes('pass') || lower.includes('staging') || lower.includes('202') || lower.includes('drill'));\n\n if (!hasRehearsalEvidence) {\n return {\n ruleId,\n standardId,\n title,\n status: 'WARN',\n passed: false,\n severity: 'medium',\n message: 'No recorded recovery rehearsal entries found in ROLLBACK.md.',\n evidence: { file: 'ROLLBACK.md' },\n remediation:\n 'Practice the 4 undo buttons on a quiet day: roll back once, restore once, flip the switch once, and record times in ROLLBACK.md.',\n };\n }\n\n return {\n ruleId,\n standardId,\n title,\n status: 'PASS',\n passed: true,\n severity,\n message: 'Recovery rehearsal log verified in ROLLBACK.md.',\n evidence: { file: 'ROLLBACK.md' },\n };\n}\n"]}
|
package/dist/tasks/routing.js
CHANGED
|
@@ -155,7 +155,8 @@ const OVERRIDE_PATTERNS = [
|
|
|
155
155
|
['no-fix', /\b(?:do\s*n[o']t|don'?t|never)\s+fix\b|\bwithout\s+fixing\b|\bno[- ]fix\b/i],
|
|
156
156
|
];
|
|
157
157
|
export function detectConstraints(text) {
|
|
158
|
-
|
|
158
|
+
const str = typeof text === 'string' ? text : '';
|
|
159
|
+
return OVERRIDE_PATTERNS.filter(([, re]) => re.test(str)).map(([c]) => c);
|
|
159
160
|
}
|
|
160
161
|
const QUESTION_START = /^\s*(?:where|what|which|who|when|how\s+(?:does|do|is|are|can|should)|why|explain|describe|show\s+me|walk\s+me|is\s+there|are\s+there|can\s+you\s+(?:explain|tell|show)|tell\s+me|list|find|trace|follow|inspect)\b/i;
|
|
161
162
|
const EXPLORATION_START = /^\s*(?:investigate|examine|explore|audit)\b/i;
|
|
@@ -166,9 +167,10 @@ const DIRECT_QUESTION = /\?\s*$/;
|
|
|
166
167
|
const ACTIVE_RELEASE = /\b(?:prepare\s+release|cut\s+release|ready\s+release)\b|\b(?:release|publish|deploy|ship)\s+(?:the\s+)?(?:package|project|build|app|version|v\d+)\b|^\s*(?:release|publish|deploy|ship)\b|\brelease\s+(?:version\s+)?v?\d+/i;
|
|
167
168
|
/** Heuristic classifier used to propose a task type. The agent may override it; ambiguous input defaults to the safest (read-only) type. */
|
|
168
169
|
export function classifyRequest(text) {
|
|
169
|
-
const
|
|
170
|
+
const str = typeof text === 'string' ? text : '';
|
|
171
|
+
const constraints = detectConstraints(str);
|
|
170
172
|
// Negated phrases ("don't fix anything") describe limits, not the task itself.
|
|
171
|
-
const t = OVERRIDE_PATTERNS.reduce((acc, [, re]) => acc.replace(new RegExp(re.source, re.flags + 'g'), ' '),
|
|
173
|
+
const t = OVERRIDE_PATTERNS.reduce((acc, [, re]) => acc.replace(new RegExp(re.source, re.flags + 'g'), ' '), str).trim();
|
|
172
174
|
const make = (type, confidence) => ({
|
|
173
175
|
type,
|
|
174
176
|
confidence,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/tasks/routing.ts"],"names":[],"mappings":"AAiBA,uHAAuH;AACvH,MAAM,CAAC,MAAM,SAAS,GAAmC;IACvD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,YAAY,EAAE,CAAC;QACf,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,KAAK;QAChB,KAAK,EAAE;YACL,+FAA+F;YAC/F,4FAA4F;YAC5F,4DAA4D;SAC7D;QACD,YAAY,EAAE,yCAAyC;QACvD,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,WAAW;QACrB,eAAe,EAAE,gGAAgG;KAClH;IACD,GAAG,EAAE;QACH,IAAI,EAAE,KAAK;QACX,YAAY,EAAE,CAAC;QACf,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,IAAI;QACf,KAAK,EAAE;YACL,qDAAqD;YACrD,4CAA4C;YAC5C,+CAA+C;YAC/C,yCAAyC;YACzC,qGAAqG;YACrG,kEAAkE;SACnE;QACD,YAAY,EAAE,2GAA2G;QACzH,WAAW,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC;QACjC,QAAQ,EAAE,0DAA0D;QACpE,eAAe,EAAE,iEAAiE;KACnF;IACD,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,CAAC;QACf,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,IAAI;QACf,KAAK,EAAE;YACL,sDAAsD;YACtD,2DAA2D;YAC3D,+CAA+C;YAC/C,iEAAiE;YACjE,kBAAkB;YAClB,mFAAmF;SACpF;QACD,YAAY,EAAE,6DAA6D;QAC3E,WAAW,EAAE,CAAC,OAAO,EA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AAC,EAAE,EAAE;QAClE,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrH,OAAO,KAAK,CAAC,CAAC,IAAI,MAAM,KAAK,OAAO,CAAC,CAAC,YAAY,MAAM,CAAC,CAAC,YAAY,IAAI,CAAC;IAC7E,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,gDAAgD,EAAE,2BAA2B,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7G,CAAC","sourcesContent":["import type { TaskType } from './task.js';\n\nexport type Constraint = 'no-modify' | 'plan-only' | 'no-commit' | 'no-e2e' | 'no-tests' | 'no-fix';\n\nexport interface WorkflowSpec {\n type: TaskType;\n /** Highest context level normally needed (1 instructions … 6 tests/implementation). */\n contextDepth: 1 | 2 | 3 | 4 | 5 | 6;\n readOnly: boolean;\n trackTask: boolean;\n steps: string[];\n verification: string;\n agentSkills: string[];\n ponytail: string;\n knowledgeUpdate: string;\n}\n\n/** Single source of truth for routing. The generated Claude skill and docs/routing.md are rendered from this table. */\nexport const WORKFLOWS: Record<TaskType, WorkflowSpec> = {\n QUESTION: {\n type: 'QUESTION',\n contextDepth: 5,\n readOnly: true,\n trackTask: false,\n steps: [\n 'Read .devworkspace/context facts relevant to the topic (devworkspace context --topic <area>).',\n 'Use Graphify (if ready) or targeted search to locate the code; read only the files needed.',\n 'Answer with file references. State uncertainty explicitly.',\n ],\n verification: 'None. Do not modify files or run tests.',\n agentSkills: [],\n ponytail: 'Not used.',\n knowledgeUpdate: 'Only if you discovered a durable fact that is missing; record it with \"devworkspace fact add\".',\n },\n BUG: {\n type: 'BUG',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: [\n 'Check git status; protect uncommitted user changes.',\n 'Investigate and reproduce where practical.',\n 'Write a regression test and confirm it fails.',\n 'Fix the cause, confirm the test passes.',\n 'Run the applicable regression suite, then typecheck/lint/build as required by the testing contract.',\n 'Review the diff; record results with \"devworkspace task verify\".',\n ],\n verification: 'Regression test, applicable suite, typecheck, lint, build (whatever the testing contract marks required).',\n agentSkills: ['/test', '/review'],\n ponytail: 'Light review of the diff when review level is not \"off\".',\n knowledgeUpdate: 'Only if the bug revealed a persistent constraint or convention.',\n },\n FEATURE: {\n type: 'FEATURE',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: [\n 'Check git status. Read relevant facts and decisions.',\n 'Write acceptance criteria and a short plan (task update).',\n 'Write tests for the criteria, then implement.',\n 'Run targeted tests, then regression, then typecheck/lint/build.',\n 'Review the diff.',\n 'Update project knowledge for architecture, conventions or decisions that changed.',\n ],\n verification: 'Targeted tests, regression, typecheck, lint, build, review.',\n agentSkills: ['/spec', '/plan', '/build', '/test', '/review'],\n ponytail: 'Review for unnecessary complexity before completion.',\n knowledgeUpdate: 'Yes when the feature adds a module, integration, business rule or decision.',\n },\n REFACTOR: {\n type: 'REFACTOR',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: [\n 'Check git status. Analyse architecture, decisions and dependents (Graphify).',\n 'Record a baseline test result (devworkspace task tests --phase baseline).',\n 'Plan, then refactor in small verified steps.',\n 'Run targeted verification and the full regression suite; compare against the baseline.',\n 'Review the diff.',\n ],\n verification: 'Baseline vs after (no regressions), typecheck, lint, build, review.',\n agentSkills: ['/plan', '/code-simplify', '/review'],\n ponytail: 'Use for simplification review.',\n knowledgeUpdate: 'Yes if structure or conventions changed.',\n },\n DOCUMENTATION: {\n type: 'DOCUMENTATION',\n contextDepth: 4,\n readOnly: false,\n trackTask: false,\n steps: ['Read the code or facts being documented.', 'Edit documentation only.', 'Run documentation checks if the project has them (link or lint checks).'],\n verification: 'Only checks that apply to documentation.',\n agentSkills: [],\n ponytail: 'Not used.',\n knowledgeUpdate: 'Rarely.',\n },\n TESTING: {\n type: 'TESTING',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Check git status.', 'Find existing test conventions.', 'Add tests; confirm they fail for the right reason where applicable.', 'Run the affected suite plus typecheck and lint.'],\n verification: 'Affected tests, typecheck, lint.',\n agentSkills: ['/test'],\n ponytail: 'Optional.',\n knowledgeUpdate: 'If the testing strategy or commands changed.',\n },\n PERFORMANCE: {\n type: 'PERFORMANCE',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Measure first; record the baseline.', 'Change one thing at a time.', 'Re-measure and run the regression suite and build.', 'Review.'],\n verification: 'Before/after measurement, regression suite, build.',\n agentSkills: ['/webperf', '/review'],\n ponytail: 'Review for added complexity.',\n knowledgeUpdate: 'If a persistent constraint or decision emerged.',\n },\n SECURITY: {\n type: 'SECURITY',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Check git status.', 'Understand the threat and the affected paths.', 'Test that demonstrates the issue, then fix.', 'Regression suite, typecheck, lint, build.', 'Security-focused review. Never print secret values.'],\n verification: 'Regression and exploit test, typecheck, lint, build, review.',\n agentSkills: ['/test', '/review'],\n ponytail: 'Use for bug and security review of the diff.',\n knowledgeUpdate: 'Yes for new security conventions or decisions.',\n },\n ARCHITECTURE: {\n type: 'ARCHITECTURE',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Read facts, decisions and architecture notes; map structure with Graphify.', 'Present options and record the chosen one with \"devworkspace decision add\".', 'Plan and implement in verified steps.', 'Full verification and review.'],\n verification: 'Baseline vs after, typecheck, lint, build, review.',\n agentSkills: ['/spec', '/plan', '/build', '/review'],\n ponytail: 'Review for unnecessary abstraction.',\n knowledgeUpdate: 'Always: architecture notes and the decision record.',\n },\n RELEASE: {\n type: 'RELEASE',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Check git status and branch.', 'Run the full testing contract including integration/e2e where available.', 'Update changelog and version per project convention.', 'Do not publish or push without explicit user authorisation.'],\n verification: 'Everything in the testing contract.',\n agentSkills: ['/ship'],\n ponytail: 'Optional final review.',\n knowledgeUpdate: 'If release process facts changed.',\n },\n MAINTENANCE: {\n type: 'MAINTENANCE',\n contextDepth: 4,\n readOnly: false,\n trackTask: true,\n steps: ['Check git status.', 'Make the change.', 'Run lint and build; run tests when behaviour could change.'],\n verification: 'Lint, build, tests if behaviour could change.',\n agentSkills: [],\n ponytail: 'Optional.',\n knowledgeUpdate: 'Only for changed commands or tooling.',\n },\n};\n\nconst OVERRIDE_PATTERNS: [Constraint, RegExp][] = [\n ['no-modify', /\\b(?:only|just)\\s+(?:explain|describe|investigate|look|read|review)\\b|\\b(?:do\\s*n[o']t|don'?t|never|without)\\s+(?:modify|modifying|change|changing|edit|editing|touch|touching)\\b|\\bread[- ]only\\b|\\bno\\s+changes\\b/i],\n ['plan-only', /\\b(?:only|just)\\s+(?:make\\s+|write\\s+|give\\s+me\\s+)?a\\s+plan\\b|\\bplan\\s+only\\b|\\bwithout\\s+implementing(?:\\s+it)?\\b/i],\n ['no-commit', /\\b(?:do\\s*n[o']t|don'?t|never)\\s+commit\\b|\\bno\\s+commits?\\b/i],\n ['no-e2e', /\\b(?:do\\s*n[o']t|don'?t|skip|no)\\s+(?:run\\s+)?(?:the\\s+)?(?:e2e|end[- ]to[- ]end)\\b/i],\n ['no-tests', /\\b(?:do\\s*n[o']t|don'?t|skip)\\s+(?:run\\s+)?(?:any\\s+|the\\s+)?tests\\b(?!\\s+but)/i],\n ['no-fix', /\\b(?:do\\s*n[o']t|don'?t|never)\\s+fix\\b|\\bwithout\\s+fixing\\b|\\bno[- ]fix\\b/i],\n];\n\nexport function detectConstraints(text: string): Constraint[] {\n return OVERRIDE_PATTERNS.filter(([, re]) => re.test(text)).map(([c]) => c);\n}\n\nexport interface Classification {\n type: TaskType;\n confidence: 'high' | 'low';\n constraints: Constraint[];\n /** True when the request must not change files (question type, or an explicit user override). */\n readOnly: boolean;\n}\n\nconst QUESTION_START = /^\\s*(?:where|what|which|who|when|how\\s+(?:does|do|is|are|can|should)|why|explain|describe|show\\s+me|walk\\s+me|is\\s+there|are\\s+there|can\\s+you\\s+(?:explain|tell|show)|tell\\s+me|list|find|trace|follow|inspect)\\b/i;\nconst EXPLORATION_START = /^\\s*(?:investigate|examine|explore|audit)\\b/i;\nconst IMPERATIVE_START =\n /^\\s*(?:fix|add|implement|create|build|refactor|remove|delete|update|change|rename|write|make|migrate|upgrade|optimi[sz]e|release|publish|validate|ensure|prevent|enforce|guard|reject|restrict|handle|resolve|patch|repair|address|correct|replace|move|extract|rewrite|convert|improve|enable|disable|support|introduce|apply|configure|install|harden|secure|scope|isolate|architect|design)\\b/i;\n/** A direct yes/no or open question: it ends in a question mark and does not start like an instruction. */\nconst DIRECT_QUESTION = /\\?\\s*$/;\n/** Action-oriented release phrases where releasing is the primary engineering intent. */\nconst ACTIVE_RELEASE = /\\b(?:prepare\\s+release|cut\\s+release|ready\\s+release)\\b|\\b(?:release|publish|deploy|ship)\\s+(?:the\\s+)?(?:package|project|build|app|version|v\\d+)\\b|^\\s*(?:release|publish|deploy|ship)\\b|\\brelease\\s+(?:version\\s+)?v?\\d+/i;\n\n/** Heuristic classifier used to propose a task type. The agent may override it; ambiguous input defaults to the safest (read-only) type. */\nexport function classifyRequest(text: string): Classification {\n const constraints = detectConstraints(text);\n // Negated phrases (\"don't fix anything\") describe limits, not the task itself.\n const t = OVERRIDE_PATTERNS.reduce((acc, [, re]) => acc.replace(new RegExp(re.source, re.flags + 'g'), ' '), text).trim();\n const make = (type: TaskType, confidence: 'high' | 'low'): Classification => ({\n type,\n confidence,\n constraints,\n readOnly: WORKFLOWS[type].readOnly || constraints.includes('no-modify') || constraints.includes('plan-only') || constraints.includes('no-fix'),\n });\n if ((QUESTION_START.test(t) || DIRECT_QUESTION.test(t)) && !IMPERATIVE_START.test(t)) return make('QUESTION', 'high');\n if (/\\b(?:add|write|improve|increase)\\s+(?:\\w+\\s+)?(?:unit\\s+|e2e\\s+|integration\\s+|regression\\s+|smoke\\s+)?tests?\\b|\\btest coverage\\b|^\\s*run\\s+(?:the\\s+|all\\s+)?(?:\\w+\\s+)?tests?\\b|\\b(?:mock|stub|fixture|fake|harness)\\w*(?:\\s+\\w+)?\\s+for\\s+(?:\\w+\\s+)*tests?\\b/i.test(t)) return make('TESTING', 'high');\n if (/\\b(?:upgrade|bump|update\\s+(?:\\w+\\s+)?dependenc\\w*)\\b/i.test(t)) return make('MAINTENANCE', 'high');\n if (/\\b(?:vulnerab\\w*|csrf|xss|sql injection|cve-\\d+|cross-?tenant|tenant isolation|privilege escalation|idor)\\b/i.test(t)) return make('SECURITY', 'high');\n if (/\\b(?:fix|bug|broken|crash(?:es|ing)?|regression|not working|fails?|failing|exception|error|memory\\s+leak|resource\\s+leak|leak(?:s|ing)?|deadlock|infinite\\s+loop)\\b/i.test(t)) return make('BUG', 'high');\n if (/\\b(?:refactor|restructure|reorgani[sz]e|clean\\s?up|simplify|de-?duplicate)\\b/i.test(t)) return make('REFACTOR', 'high');\n if (/\\b(?:vulnerab\\w*|security|csrf|xss|sql injection|sanitiz\\w*|harden\\w*|cve-\\d+|cross-?tenant|tenant isolation|ownership|authori[sz]ation|privilege escalation|idor)\\b/i.test(t)) return make('SECURITY', 'high');\n if (/\\b(?:performance|slow|latency|speed up|optimi[sz]e|throughput)\\b/i.test(t)) return make('PERFORMANCE', 'high');\n if (ACTIVE_RELEASE.test(t)) return make('RELEASE', 'high');\n if (/\\b(?:document\\w*|readme|docs?|changelog|jsdoc|docstring|guide)\\b/i.test(t)) return make('DOCUMENTATION', 'high');\n if (/\\b(?:release|publish|deploy|ship|version bump)\\b/i.test(t)) return make('RELEASE', 'high');\n if (/\\b(?:upgrade|bump|update\\s+dependenc\\w*|chore|lint(?:ing)?|format(?:ting)?)\\b/i.test(t)) return make('MAINTENANCE', 'high');\n if (/\\b(?:redesign|(?:re-?)?architect\\w*|migrate\\s+to|architecture)\\b/i.test(t)) return make('ARCHITECTURE', 'high');\n if (/\\b(?:add|implement|create|build|support|introduce|enable|new)\\b/i.test(t)) return make('FEATURE', 'high');\n if (EXPLORATION_START.test(t)) return make('QUESTION', 'high');\n // An instruction we cannot place is still a request to change something. Never default it to a read-only question.\n if (IMPERATIVE_START.test(t)) return make('FEATURE', 'low');\n return make('QUESTION', 'low');\n}\n\nexport function renderRoutingTable(): string {\n const rows = (Object.values(WORKFLOWS) as WorkflowSpec[]).map((w) => {\n const flags = [w.readOnly ? 'read-only' : 'modifies code', w.trackTask ? 'tracked task' : 'no task file'].join(', ');\n return `| ${w.type} | ${flags} | L${w.contextDepth} | ${w.verification} |`;\n });\n return ['| Type | Nature | Max context | Verification |', '| --- | --- | --- | --- |', ...rows].join('\\n');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/tasks/routing.ts"],"names":[],"mappings":"AAiBA,uHAAuH;AACvH,MAAM,CAAC,MAAM,SAAS,GAAmC;IACvD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,YAAY,EAAE,CAAC;QACf,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,KAAK;QAChB,KAAK,EAAE;YACL,+FAA+F;YAC/F,4FAA4F;YAC5F,4DAA4D;SAC7D;QACD,YAAY,EAAE,yCAAyC;QACvD,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,WAAW;QACrB,eAAe,EAAE,gGAAgG;KAClH;IACD,GAAG,EAAE;QACH,IAAI,EAAE,KAAK;QACX,YAAY,EAAE,CAAC;QACf,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,IAAI;QACf,KAAK,EAAE;YACL,qDAAqD;YACrD,4CAA4C;YAC5C,+CAA+C;YAC/C,yCAAyC;YACzC,qGAAqG;YACrG,kEAAkE;SACnE;QACD,YAAY,EAAE,2GAA2G;QACzH,WAAW,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC;QACjC,QAAQ,EAAE,0DAA0D;QACpE,eAAe,EAAE,iEAA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AkE,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC/G,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC/D,mHAAmH;IACnH,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,MAAM,IAAI,GAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAClE,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrH,OAAO,KAAK,CAAC,CAAC,IAAI,MAAM,KAAK,OAAO,CAAC,CAAC,YAAY,MAAM,CAAC,CAAC,YAAY,IAAI,CAAC;IAC7E,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,gDAAgD,EAAE,2BAA2B,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7G,CAAC","sourcesContent":["import type { TaskType } from './task.js';\n\nexport type Constraint = 'no-modify' | 'plan-only' | 'no-commit' | 'no-e2e' | 'no-tests' | 'no-fix';\n\nexport interface WorkflowSpec {\n type: TaskType;\n /** Highest context level normally needed (1 instructions … 6 tests/implementation). */\n contextDepth: 1 | 2 | 3 | 4 | 5 | 6;\n readOnly: boolean;\n trackTask: boolean;\n steps: string[];\n verification: string;\n agentSkills: string[];\n ponytail: string;\n knowledgeUpdate: string;\n}\n\n/** Single source of truth for routing. The generated Claude skill and docs/routing.md are rendered from this table. */\nexport const WORKFLOWS: Record<TaskType, WorkflowSpec> = {\n QUESTION: {\n type: 'QUESTION',\n contextDepth: 5,\n readOnly: true,\n trackTask: false,\n steps: [\n 'Read .devworkspace/context facts relevant to the topic (devworkspace context --topic <area>).',\n 'Use Graphify (if ready) or targeted search to locate the code; read only the files needed.',\n 'Answer with file references. State uncertainty explicitly.',\n ],\n verification: 'None. Do not modify files or run tests.',\n agentSkills: [],\n ponytail: 'Not used.',\n knowledgeUpdate: 'Only if you discovered a durable fact that is missing; record it with \"devworkspace fact add\".',\n },\n BUG: {\n type: 'BUG',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: [\n 'Check git status; protect uncommitted user changes.',\n 'Investigate and reproduce where practical.',\n 'Write a regression test and confirm it fails.',\n 'Fix the cause, confirm the test passes.',\n 'Run the applicable regression suite, then typecheck/lint/build as required by the testing contract.',\n 'Review the diff; record results with \"devworkspace task verify\".',\n ],\n verification: 'Regression test, applicable suite, typecheck, lint, build (whatever the testing contract marks required).',\n agentSkills: ['/test', '/review'],\n ponytail: 'Light review of the diff when review level is not \"off\".',\n knowledgeUpdate: 'Only if the bug revealed a persistent constraint or convention.',\n },\n FEATURE: {\n type: 'FEATURE',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: [\n 'Check git status. Read relevant facts and decisions.',\n 'Write acceptance criteria and a short plan (task update).',\n 'Write tests for the criteria, then implement.',\n 'Run targeted tests, then regression, then typecheck/lint/build.',\n 'Review the diff.',\n 'Update project knowledge for architecture, conventions or decisions that changed.',\n ],\n verification: 'Targeted tests, regression, typecheck, lint, build, review.',\n agentSkills: ['/spec', '/plan', '/build', '/test', '/review'],\n ponytail: 'Review for unnecessary complexity before completion.',\n knowledgeUpdate: 'Yes when the feature adds a module, integration, business rule or decision.',\n },\n REFACTOR: {\n type: 'REFACTOR',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: [\n 'Check git status. Analyse architecture, decisions and dependents (Graphify).',\n 'Record a baseline test result (devworkspace task tests --phase baseline).',\n 'Plan, then refactor in small verified steps.',\n 'Run targeted verification and the full regression suite; compare against the baseline.',\n 'Review the diff.',\n ],\n verification: 'Baseline vs after (no regressions), typecheck, lint, build, review.',\n agentSkills: ['/plan', '/code-simplify', '/review'],\n ponytail: 'Use for simplification review.',\n knowledgeUpdate: 'Yes if structure or conventions changed.',\n },\n DOCUMENTATION: {\n type: 'DOCUMENTATION',\n contextDepth: 4,\n readOnly: false,\n trackTask: false,\n steps: ['Read the code or facts being documented.', 'Edit documentation only.', 'Run documentation checks if the project has them (link or lint checks).'],\n verification: 'Only checks that apply to documentation.',\n agentSkills: [],\n ponytail: 'Not used.',\n knowledgeUpdate: 'Rarely.',\n },\n TESTING: {\n type: 'TESTING',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Check git status.', 'Find existing test conventions.', 'Add tests; confirm they fail for the right reason where applicable.', 'Run the affected suite plus typecheck and lint.'],\n verification: 'Affected tests, typecheck, lint.',\n agentSkills: ['/test'],\n ponytail: 'Optional.',\n knowledgeUpdate: 'If the testing strategy or commands changed.',\n },\n PERFORMANCE: {\n type: 'PERFORMANCE',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Measure first; record the baseline.', 'Change one thing at a time.', 'Re-measure and run the regression suite and build.', 'Review.'],\n verification: 'Before/after measurement, regression suite, build.',\n agentSkills: ['/webperf', '/review'],\n ponytail: 'Review for added complexity.',\n knowledgeUpdate: 'If a persistent constraint or decision emerged.',\n },\n SECURITY: {\n type: 'SECURITY',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Check git status.', 'Understand the threat and the affected paths.', 'Test that demonstrates the issue, then fix.', 'Regression suite, typecheck, lint, build.', 'Security-focused review. Never print secret values.'],\n verification: 'Regression and exploit test, typecheck, lint, build, review.',\n agentSkills: ['/test', '/review'],\n ponytail: 'Use for bug and security review of the diff.',\n knowledgeUpdate: 'Yes for new security conventions or decisions.',\n },\n ARCHITECTURE: {\n type: 'ARCHITECTURE',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Read facts, decisions and architecture notes; map structure with Graphify.', 'Present options and record the chosen one with \"devworkspace decision add\".', 'Plan and implement in verified steps.', 'Full verification and review.'],\n verification: 'Baseline vs after, typecheck, lint, build, review.',\n agentSkills: ['/spec', '/plan', '/build', '/review'],\n ponytail: 'Review for unnecessary abstraction.',\n knowledgeUpdate: 'Always: architecture notes and the decision record.',\n },\n RELEASE: {\n type: 'RELEASE',\n contextDepth: 6,\n readOnly: false,\n trackTask: true,\n steps: ['Check git status and branch.', 'Run the full testing contract including integration/e2e where available.', 'Update changelog and version per project convention.', 'Do not publish or push without explicit user authorisation.'],\n verification: 'Everything in the testing contract.',\n agentSkills: ['/ship'],\n ponytail: 'Optional final review.',\n knowledgeUpdate: 'If release process facts changed.',\n },\n MAINTENANCE: {\n type: 'MAINTENANCE',\n contextDepth: 4,\n readOnly: false,\n trackTask: true,\n steps: ['Check git status.', 'Make the change.', 'Run lint and build; run tests when behaviour could change.'],\n verification: 'Lint, build, tests if behaviour could change.',\n agentSkills: [],\n ponytail: 'Optional.',\n knowledgeUpdate: 'Only for changed commands or tooling.',\n },\n};\n\nconst OVERRIDE_PATTERNS: [Constraint, RegExp][] = [\n ['no-modify', /\\b(?:only|just)\\s+(?:explain|describe|investigate|look|read|review)\\b|\\b(?:do\\s*n[o']t|don'?t|never|without)\\s+(?:modify|modifying|change|changing|edit|editing|touch|touching)\\b|\\bread[- ]only\\b|\\bno\\s+changes\\b/i],\n ['plan-only', /\\b(?:only|just)\\s+(?:make\\s+|write\\s+|give\\s+me\\s+)?a\\s+plan\\b|\\bplan\\s+only\\b|\\bwithout\\s+implementing(?:\\s+it)?\\b/i],\n ['no-commit', /\\b(?:do\\s*n[o']t|don'?t|never)\\s+commit\\b|\\bno\\s+commits?\\b/i],\n ['no-e2e', /\\b(?:do\\s*n[o']t|don'?t|skip|no)\\s+(?:run\\s+)?(?:the\\s+)?(?:e2e|end[- ]to[- ]end)\\b/i],\n ['no-tests', /\\b(?:do\\s*n[o']t|don'?t|skip)\\s+(?:run\\s+)?(?:any\\s+|the\\s+)?tests\\b(?!\\s+but)/i],\n ['no-fix', /\\b(?:do\\s*n[o']t|don'?t|never)\\s+fix\\b|\\bwithout\\s+fixing\\b|\\bno[- ]fix\\b/i],\n];\n\nexport function detectConstraints(text: string): Constraint[] {\n const str = typeof text === 'string' ? text : '';\n return OVERRIDE_PATTERNS.filter(([, re]) => re.test(str)).map(([c]) => c);\n}\n\nexport interface Classification {\n type: TaskType;\n confidence: 'high' | 'low';\n constraints: Constraint[];\n /** True when the request must not change files (question type, or an explicit user override). */\n readOnly: boolean;\n}\n\nconst QUESTION_START = /^\\s*(?:where|what|which|who|when|how\\s+(?:does|do|is|are|can|should)|why|explain|describe|show\\s+me|walk\\s+me|is\\s+there|are\\s+there|can\\s+you\\s+(?:explain|tell|show)|tell\\s+me|list|find|trace|follow|inspect)\\b/i;\nconst EXPLORATION_START = /^\\s*(?:investigate|examine|explore|audit)\\b/i;\nconst IMPERATIVE_START =\n /^\\s*(?:fix|add|implement|create|build|refactor|remove|delete|update|change|rename|write|make|migrate|upgrade|optimi[sz]e|release|publish|validate|ensure|prevent|enforce|guard|reject|restrict|handle|resolve|patch|repair|address|correct|replace|move|extract|rewrite|convert|improve|enable|disable|support|introduce|apply|configure|install|harden|secure|scope|isolate|architect|design)\\b/i;\n/** A direct yes/no or open question: it ends in a question mark and does not start like an instruction. */\nconst DIRECT_QUESTION = /\\?\\s*$/;\n/** Action-oriented release phrases where releasing is the primary engineering intent. */\nconst ACTIVE_RELEASE = /\\b(?:prepare\\s+release|cut\\s+release|ready\\s+release)\\b|\\b(?:release|publish|deploy|ship)\\s+(?:the\\s+)?(?:package|project|build|app|version|v\\d+)\\b|^\\s*(?:release|publish|deploy|ship)\\b|\\brelease\\s+(?:version\\s+)?v?\\d+/i;\n\n/** Heuristic classifier used to propose a task type. The agent may override it; ambiguous input defaults to the safest (read-only) type. */\nexport function classifyRequest(text: string): Classification {\n const str = typeof text === 'string' ? text : '';\n const constraints = detectConstraints(str);\n // Negated phrases (\"don't fix anything\") describe limits, not the task itself.\n const t = OVERRIDE_PATTERNS.reduce((acc, [, re]) => acc.replace(new RegExp(re.source, re.flags + 'g'), ' '), str).trim();\n const make = (type: TaskType, confidence: 'high' | 'low'): Classification => ({\n type,\n confidence,\n constraints,\n readOnly: WORKFLOWS[type].readOnly || constraints.includes('no-modify') || constraints.includes('plan-only') || constraints.includes('no-fix'),\n });\n if ((QUESTION_START.test(t) || DIRECT_QUESTION.test(t)) && !IMPERATIVE_START.test(t)) return make('QUESTION', 'high');\n if (/\\b(?:add|write|improve|increase)\\s+(?:\\w+\\s+)?(?:unit\\s+|e2e\\s+|integration\\s+|regression\\s+|smoke\\s+)?tests?\\b|\\btest coverage\\b|^\\s*run\\s+(?:the\\s+|all\\s+)?(?:\\w+\\s+)?tests?\\b|\\b(?:mock|stub|fixture|fake|harness)\\w*(?:\\s+\\w+)?\\s+for\\s+(?:\\w+\\s+)*tests?\\b/i.test(t)) return make('TESTING', 'high');\n if (/\\b(?:upgrade|bump|update\\s+(?:\\w+\\s+)?dependenc\\w*)\\b/i.test(t)) return make('MAINTENANCE', 'high');\n if (/\\b(?:vulnerab\\w*|csrf|xss|sql injection|cve-\\d+|cross-?tenant|tenant isolation|privilege escalation|idor)\\b/i.test(t)) return make('SECURITY', 'high');\n if (/\\b(?:fix|bug|broken|crash(?:es|ing)?|regression|not working|fails?|failing|exception|error|memory\\s+leak|resource\\s+leak|leak(?:s|ing)?|deadlock|infinite\\s+loop)\\b/i.test(t)) return make('BUG', 'high');\n if (/\\b(?:refactor|restructure|reorgani[sz]e|clean\\s?up|simplify|de-?duplicate)\\b/i.test(t)) return make('REFACTOR', 'high');\n if (/\\b(?:vulnerab\\w*|security|csrf|xss|sql injection|sanitiz\\w*|harden\\w*|cve-\\d+|cross-?tenant|tenant isolation|ownership|authori[sz]ation|privilege escalation|idor)\\b/i.test(t)) return make('SECURITY', 'high');\n if (/\\b(?:performance|slow|latency|speed up|optimi[sz]e|throughput)\\b/i.test(t)) return make('PERFORMANCE', 'high');\n if (ACTIVE_RELEASE.test(t)) return make('RELEASE', 'high');\n if (/\\b(?:document\\w*|readme|docs?|changelog|jsdoc|docstring|guide)\\b/i.test(t)) return make('DOCUMENTATION', 'high');\n if (/\\b(?:release|publish|deploy|ship|version bump)\\b/i.test(t)) return make('RELEASE', 'high');\n if (/\\b(?:upgrade|bump|update\\s+dependenc\\w*|chore|lint(?:ing)?|format(?:ting)?)\\b/i.test(t)) return make('MAINTENANCE', 'high');\n if (/\\b(?:redesign|(?:re-?)?architect\\w*|migrate\\s+to|architecture)\\b/i.test(t)) return make('ARCHITECTURE', 'high');\n if (/\\b(?:add|implement|create|build|support|introduce|enable|new)\\b/i.test(t)) return make('FEATURE', 'high');\n if (EXPLORATION_START.test(t)) return make('QUESTION', 'high');\n // An instruction we cannot place is still a request to change something. Never default it to a read-only question.\n if (IMPERATIVE_START.test(t)) return make('FEATURE', 'low');\n return make('QUESTION', 'low');\n}\n\nexport function renderRoutingTable(): string {\n const rows = (Object.values(WORKFLOWS) as WorkflowSpec[]).map((w) => {\n const flags = [w.readOnly ? 'read-only' : 'modifies code', w.trackTask ? 'tracked task' : 'no task file'].join(', ');\n return `| ${w.type} | ${flags} | L${w.contextDepth} | ${w.verification} |`;\n });\n return ['| Type | Nature | Max context | Verification |', '| --- | --- | --- | --- |', ...rows].join('\\n');\n}\n"]}
|
package/dist/utils/fs.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare function ensureDir(p: string): Promise<void>;
|
|
|
4
4
|
/** Write to a temp file in the same directory, flush it, then atomically rename into place. */
|
|
5
5
|
export declare function atomicWriteFile(file: string, data: string | Uint8Array, validate?: (data: string) => void): Promise<void>;
|
|
6
6
|
export declare function atomicWriteJson(file: string, value: unknown): Promise<void>;
|
|
7
|
-
export declare function readJsonFile(file: string, maxBytes?: number): Promise<
|
|
7
|
+
export declare function readJsonFile<T = unknown>(file: string, maxBytes?: number): Promise<T>;
|
|
8
8
|
export declare function sha256File(file: string): Promise<string>;
|
|
9
9
|
export declare function sha256Text(text: string): string;
|
|
10
10
|
export declare function looksBinary(buf: Uint8Array): boolean;
|
package/dist/utils/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,CAAS;IACxC,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,CAAS;IACvC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE,EAAU;IACrD,IAAI,OAAgB,CAAC;IACrB,gHAAgH;IAChH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,IAAI,CAAC;Y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AAI,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { promises as fs, createReadStream } from 'node:fs';\nimport { createHash, randomBytes } from 'node:crypto';\nimport path from 'node:path';\nimport { DevWorkspaceError } from '../errors/index.js';\n\nexport const MAX_JSON_BYTES = 5 * 1024 * 1024;\n\nexport async function pathExists(p: string): Promise<boolean> {\n try {\n await fs.access(p);\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function ensureDir(p: string): Promise<void> {\n await fs.mkdir(p, { recursive: true });\n}\n\nasync function renameWithRetry(from: string, to: string): Promise<void> {\n let lastErr: unknown;\n // Windows briefly denies renames while another process (reader, indexer, editor file watcher) holds the target.\n for (let i = 0; i < 20; i++) {\n try {\n await fs.rename(from, to);\n return;\n } catch (e) {\n lastErr = e;\n const code = (e as NodeJS.ErrnoException).code;\n if (code !== 'EPERM' && code !== 'EBUSY' && code !== 'EACCES') break;\n await new Promise((r) => setTimeout(r, Math.min(25 * (i + 1), 150)));\n }\n }\n throw lastErr;\n}\n\n/** Write to a temp file in the same directory, flush it, then atomically rename into place. */\nexport async function atomicWriteFile(file: string, data: string | Uint8Array, validate?: (data: string) => void): Promise<void> {\n await ensureDir(path.dirname(file));\n if (validate && typeof data === 'string') validate(data);\n const tmp = `${file}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;\n let fh;\n try {\n fh = await fs.open(tmp, 'wx');\n await fh.writeFile(data);\n await fh.sync();\n await fh.close();\n fh = undefined;\n await renameWithRetry(tmp, file);\n } catch (e) {\n if (fh) await fh.close().catch(() => undefined);\n await fs.rm(tmp, { force: true }).catch(() => undefined);\n throw new DevWorkspaceError('IO', `Could not write ${path.basename(file)}.`, {\n cause: e,\n hint: 'Check file permissions and free disk space.',\n });\n }\n}\n\nexport async function atomicWriteJson(file: string, value: unknown): Promise<void> {\n const text = JSON.stringify(value, null, 2) + '\\n';\n await atomicWriteFile(file, text, (t) => {\n JSON.parse(t);\n });\n}\n\nexport async function readJsonFile(file: string, maxBytes = MAX_JSON_BYTES): Promise<unknown> {\n let stat;\n try {\n stat = await fs.stat(file);\n } catch (e) {\n throw new DevWorkspaceError('NOT_FOUND', `File not found: ${path.basename(file)}`, { cause: e });\n }\n if (stat.size > maxBytes) {\n throw new DevWorkspaceError('SCHEMA', `${path.basename(file)} is unreasonably large (${stat.size} bytes).`, {\n hint: 'Restore it from version control or a backup in .devworkspace/local/backups.',\n });\n }\n const text = await fs.readFile(file, 'utf8');\n try {\n return JSON.parse(text.replace(/^\\uFEFF/, ''));\n } catch (e) {\n throw new DevWorkspaceError('SCHEMA', `${path.basename(file)} contains malformed JSON.`, {\n cause: e,\n hint: 'Restore the file from version control (git checkout -- <file>) or from .devworkspace/local/backups.',\n });\n }\n}\n\nexport async function sha256File(file: string): Promise<string> {\n const hash = createHash('sha256');\n await new Promise<void>((resolve, reject) => {\n const s = createReadStream(file);\n s.on('data', (c) => hash.update(c));\n s.on('error', reject);\n s.on('end', () => resolve());\n });\n return hash.digest('hex');\n}\n\nexport function sha256Text(text: string): string {\n return createHash('sha256').update(text).digest('hex');\n}\n\nexport function looksBinary(buf: Uint8Array): boolean {\n const n = Math.min(buf.length, 8000);\n for (let i = 0; i < n; i++) if (buf[i] === 0) return true;\n return false;\n}\n\n/** Reads a text file; returns null if binary or larger than maxBytes. */\nexport async function readTextBounded(file: string, maxBytes = 512 * 1024): Promise<string | null> {\n const stat = await fs.stat(file);\n if (stat.size > maxBytes) return null;\n const buf = await fs.readFile(file);\n if (looksBinary(buf)) return null;\n return buf.toString('utf8').replace(/^\\uFEFF/, '');\n}\n\nexport function randomId(bytes = 2): string {\n return randomBytes(bytes).toString('hex');\n}\n\nexport async function listFilesRecursive(dir: string, maxFiles = 5000): Promise<string[]> {\n const out: string[] = [];\n async function walk(d: string): Promise<void> {\n let entries;\n try {\n entries = await fs.readdir(d, { withFileTypes: true });\n } catch {\n return;\n }\n for (const e of entries) {\n if (out.length >= maxFiles) return;\n const full = path.join(d, e.name);\n if (e.isDirectory()) await walk(full);\n else if (e.isFile()) out.push(full);\n }\n }\n await walk(dir);\n return out;\n}\n\n/** Atomically write text only when it differs from what is on disk. Returns true if a write happened. */\nexport async function writeTextIfChanged(file: string, text: string): Promise<boolean> {\n try {\n if ((await fs.readFile(file, 'utf8')) === text) return false;\n } catch {\n /* missing: write below */\n }\n await atomicWriteFile(file, text);\n return true;\n}\n\nexport async function writeJsonIfChanged(file: string, value: unknown): Promise<boolean> {\n const text = JSON.stringify(value, null, 2) + '\\n';\n JSON.parse(text);\n return writeTextIfChanged(file, text);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,CAAS;IACxC,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,CAAS;IACvC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE,EAAU;IACrD,IAAI,OAAgB,CAAC;IACrB,gHAAgH;IAChH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EA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K,CAAC,IAAI,CAAC,CAAC;IACjB,OAAO,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { promises as fs, createReadStream } from 'node:fs';\nimport { createHash, randomBytes } from 'node:crypto';\nimport path from 'node:path';\nimport { DevWorkspaceError } from '../errors/index.js';\n\nexport const MAX_JSON_BYTES = 5 * 1024 * 1024;\n\nexport async function pathExists(p: string): Promise<boolean> {\n try {\n await fs.access(p);\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function ensureDir(p: string): Promise<void> {\n await fs.mkdir(p, { recursive: true });\n}\n\nasync function renameWithRetry(from: string, to: string): Promise<void> {\n let lastErr: unknown;\n // Windows briefly denies renames while another process (reader, indexer, editor file watcher) holds the target.\n for (let i = 0; i < 20; i++) {\n try {\n await fs.rename(from, to);\n return;\n } catch (e) {\n lastErr = e;\n const code = (e as NodeJS.ErrnoException).code;\n if (code !== 'EPERM' && code !== 'EBUSY' && code !== 'EACCES') break;\n await new Promise((r) => setTimeout(r, Math.min(25 * (i + 1), 150)));\n }\n }\n throw lastErr;\n}\n\n/** Write to a temp file in the same directory, flush it, then atomically rename into place. */\nexport async function atomicWriteFile(file: string, data: string | Uint8Array, validate?: (data: string) => void): Promise<void> {\n await ensureDir(path.dirname(file));\n if (validate && typeof data === 'string') validate(data);\n const tmp = `${file}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;\n let fh;\n try {\n fh = await fs.open(tmp, 'wx');\n await fh.writeFile(data);\n await fh.sync();\n await fh.close();\n fh = undefined;\n await renameWithRetry(tmp, file);\n } catch (e) {\n if (fh) await fh.close().catch(() => undefined);\n await fs.rm(tmp, { force: true }).catch(() => undefined);\n throw new DevWorkspaceError('IO', `Could not write ${path.basename(file)}.`, {\n cause: e,\n hint: 'Check file permissions and free disk space.',\n });\n }\n}\n\nexport async function atomicWriteJson(file: string, value: unknown): Promise<void> {\n const text = JSON.stringify(value, null, 2) + '\\n';\n await atomicWriteFile(file, text, (t) => {\n JSON.parse(t);\n });\n}\n\nexport async function readJsonFile<T = unknown>(file: string, maxBytes = MAX_JSON_BYTES): Promise<T> {\n let stat;\n try {\n stat = await fs.stat(file);\n } catch (e) {\n throw new DevWorkspaceError('NOT_FOUND', `File not found: ${path.basename(file)}`, { cause: e });\n }\n if (stat.size > maxBytes) {\n throw new DevWorkspaceError('SCHEMA', `${path.basename(file)} is unreasonably large (${stat.size} bytes).`, {\n hint: 'Restore it from version control or a backup in .devworkspace/local/backups.',\n });\n }\n const text = await fs.readFile(file, 'utf8');\n try {\n return JSON.parse(text.replace(/^\\uFEFF/, '')) as T;\n } catch (e) {\n throw new DevWorkspaceError('SCHEMA', `${path.basename(file)} contains malformed JSON.`, {\n cause: e,\n hint: 'Restore the file from version control (git checkout -- <file>) or from .devworkspace/local/backups.',\n });\n }\n}\n\nexport async function sha256File(file: string): Promise<string> {\n const hash = createHash('sha256');\n await new Promise<void>((resolve, reject) => {\n const s = createReadStream(file);\n s.on('data', (c) => hash.update(c));\n s.on('error', reject);\n s.on('end', () => resolve());\n });\n return hash.digest('hex');\n}\n\nexport function sha256Text(text: string): string {\n return createHash('sha256').update(text).digest('hex');\n}\n\nexport function looksBinary(buf: Uint8Array): boolean {\n const n = Math.min(buf.length, 8000);\n for (let i = 0; i < n; i++) if (buf[i] === 0) return true;\n return false;\n}\n\n/** Reads a text file; returns null if binary or larger than maxBytes. */\nexport async function readTextBounded(file: string, maxBytes = 512 * 1024): Promise<string | null> {\n const stat = await fs.stat(file);\n if (stat.size > maxBytes) return null;\n const buf = await fs.readFile(file);\n if (looksBinary(buf)) return null;\n return buf.toString('utf8').replace(/^\\uFEFF/, '');\n}\n\nexport function randomId(bytes = 2): string {\n return randomBytes(bytes).toString('hex');\n}\n\nexport async function listFilesRecursive(dir: string, maxFiles = 5000): Promise<string[]> {\n const out: string[] = [];\n async function walk(d: string): Promise<void> {\n let entries;\n try {\n entries = await fs.readdir(d, { withFileTypes: true });\n } catch {\n return;\n }\n for (const e of entries) {\n if (out.length >= maxFiles) return;\n const full = path.join(d, e.name);\n if (e.isDirectory()) await walk(full);\n else if (e.isFile()) out.push(full);\n }\n }\n await walk(dir);\n return out;\n}\n\n/** Atomically write text only when it differs from what is on disk. Returns true if a write happened. */\nexport async function writeTextIfChanged(file: string, text: string): Promise<boolean> {\n try {\n if ((await fs.readFile(file, 'utf8')) === text) return false;\n } catch {\n /* missing: write below */\n }\n await atomicWriteFile(file, text);\n return true;\n}\n\nexport async function writeJsonIfChanged(file: string, value: unknown): Promise<boolean> {\n const text = JSON.stringify(value, null, 2) + '\\n';\n JSON.parse(text);\n return writeTextIfChanged(file, text);\n}\n"]}
|
package/dist/utils/lock.js
CHANGED
|
@@ -14,12 +14,13 @@ function pidAlive(pid) {
|
|
|
14
14
|
}
|
|
15
15
|
/** Exclusive advisory lock stored under .devworkspace/local/. Stale locks (dead pid or too old) are broken. */
|
|
16
16
|
export async function withLock(workspaceDir, fn, opts = {}) {
|
|
17
|
-
const timeoutMs = opts.timeoutMs ??
|
|
17
|
+
const timeoutMs = opts.timeoutMs ?? 10_000;
|
|
18
18
|
const staleMs = opts.staleMs ?? 60_000;
|
|
19
19
|
const dir = path.join(workspaceDir, 'local');
|
|
20
20
|
const lockPath = path.join(dir, opts.name ?? 'workspace.lock');
|
|
21
21
|
await ensureDir(dir);
|
|
22
22
|
const started = Date.now();
|
|
23
|
+
let winPermRetries = 0;
|
|
23
24
|
for (;;) {
|
|
24
25
|
try {
|
|
25
26
|
const fh = await fs.open(lockPath, 'wx');
|
|
@@ -28,7 +29,14 @@ export async function withLock(workspaceDir, fn, opts = {}) {
|
|
|
28
29
|
break;
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
31
|
-
|
|
32
|
+
const code = e.code;
|
|
33
|
+
// On Windows, opening a recently unlinked lock file while its handle is closing can briefly raise EPERM/EACCES.
|
|
34
|
+
if (process.platform === 'win32' && (code === 'EPERM' || code === 'EACCES') && winPermRetries < 25 && Date.now() - started <= timeoutMs) {
|
|
35
|
+
winPermRetries++;
|
|
36
|
+
await new Promise((r) => setTimeout(r, 15 + Math.floor(Math.random() * 25)));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (code !== 'EEXIST') {
|
|
32
40
|
throw new DevWorkspaceError('IO', 'Could not acquire the workspace lock.', { cause: e });
|
|
33
41
|
}
|
|
34
42
|
let stale;
|
|
@@ -55,7 +63,7 @@ export async function withLock(workspaceDir, fn, opts = {}) {
|
|
|
55
63
|
hint: `Wait for it to finish, or delete ${path.join('.devworkspace', 'local', opts.name ?? 'workspace.lock')} if no process is running.`,
|
|
56
64
|
});
|
|
57
65
|
}
|
|
58
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
66
|
+
await new Promise((r) => setTimeout(r, 25 + Math.floor(Math.random() * 50)));
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
69
|
const dispose = onCleanup(() => {
|