devworkspace 0.2.0 → 0.2.2
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 +39 -0
- package/README.md +4 -3
- package/dist/agents/claude/content.js +3 -2
- package/dist/agents/claude/content.js.map +1 -1
- package/dist/cli/args.d.ts +16 -0
- package/dist/cli/args.js +5 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.js +30 -7
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/render.d.ts +7 -1
- package/dist/cli/render.js +70 -13
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/run.js +47 -8
- package/dist/cli/run.js.map +1 -1
- package/dist/config/schemas.d.ts +12 -1
- package/dist/config/schemas.js +12 -0
- package/dist/config/schemas.js.map +1 -1
- package/dist/discovery/commands.d.ts +34 -3
- package/dist/discovery/commands.js +109 -33
- package/dist/discovery/commands.js.map +1 -1
- package/dist/discovery/detect.d.ts +23 -0
- package/dist/discovery/detect.js +113 -48
- package/dist/discovery/detect.js.map +1 -1
- package/dist/discovery/docs.d.ts +10 -0
- package/dist/discovery/docs.js +52 -0
- package/dist/discovery/docs.js.map +1 -0
- package/dist/discovery/entrypoints.d.ts +20 -0
- package/dist/discovery/entrypoints.js +67 -0
- package/dist/discovery/entrypoints.js.map +1 -0
- package/dist/integrations/adapters/graphify.js +46 -8
- package/dist/integrations/adapters/graphify.js.map +1 -1
- package/dist/integrations/manager.js +14 -1
- package/dist/integrations/manager.js.map +1 -1
- package/dist/integrations/persistentPath.d.ts +20 -0
- package/dist/integrations/persistentPath.js +47 -0
- package/dist/integrations/persistentPath.js.map +1 -0
- package/dist/integrations/types.d.ts +6 -0
- package/dist/integrations/types.js.map +1 -1
- package/dist/knowledge/facts.d.ts +59 -2
- package/dist/knowledge/facts.js +115 -17
- package/dist/knowledge/facts.js.map +1 -1
- package/dist/prompts/onboarding.js +9 -6
- package/dist/prompts/onboarding.js.map +1 -1
- package/dist/services/analysis.d.ts +13 -1
- package/dist/services/analysis.js +23 -18
- package/dist/services/analysis.js.map +1 -1
- package/dist/services/doctor.js +92 -7
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/knowledge.d.ts +17 -0
- package/dist/services/knowledge.js +28 -2
- package/dist/services/knowledge.js.map +1 -1
- package/dist/services/refresh.js +6 -6
- package/dist/services/refresh.js.map +1 -1
- package/dist/services/status.d.ts +12 -2
- package/dist/services/status.js +11 -9
- package/dist/services/status.js.map +1 -1
- package/dist/services/tasks.d.ts +2 -0
- package/dist/services/tasks.js +20 -12
- package/dist/services/tasks.js.map +1 -1
- package/dist/services/verify.d.ts +47 -0
- package/dist/services/verify.js +172 -0
- package/dist/services/verify.js.map +1 -0
- package/dist/tasks/routing.js +8 -3
- package/dist/tasks/routing.js.map +1 -1
- package/dist/tasks/task.d.ts +49 -5
- package/dist/tasks/task.js +68 -11
- package/dist/tasks/task.js.map +1 -1
- package/dist/verification/safety.d.ts +38 -0
- package/dist/verification/safety.js +120 -0
- package/dist/verification/safety.js.map +1 -0
- package/dist/verification/scope.d.ts +19 -0
- package/dist/verification/scope.js +119 -0
- package/dist/verification/scope.js.map +1 -0
- package/docs/integrations.md +1 -1
- package/docs/knowledge.md +2 -0
- package/docs/testing.md +29 -2
- package/docs/troubleshooting.md +4 -1
- package/package.json +1 -1
package/dist/config/schemas.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export interface ProjectConfig {
|
|
|
21
21
|
devworkspaceVersion: string;
|
|
22
22
|
settings: {
|
|
23
23
|
review: ReviewLevel;
|
|
24
|
-
maxFiles: number;
|
|
24
|
+
maxFiles: number; /** The project intentionally has no tests/lint/build; doctor stops warning about it. */
|
|
25
|
+
acknowledgeNoVerification?: boolean;
|
|
25
26
|
};
|
|
26
27
|
managedFiles: ManagedFile[];
|
|
27
28
|
}
|
|
@@ -57,6 +58,16 @@ export interface CommandEntry {
|
|
|
57
58
|
source: string | null;
|
|
58
59
|
/** 'repository-script' = defined by repo config (untrusted input); 'inferred' = guessed from tooling; 'user' = set by a human. */
|
|
59
60
|
origin: 'repository-script' | 'inferred' | 'user';
|
|
61
|
+
/**
|
|
62
|
+
* Working directory, relative to the project root (POSIX separators). Absent means the project root.
|
|
63
|
+
* Package-specific commands (backend vs frontend) must carry it so they are never run in the wrong place.
|
|
64
|
+
*/
|
|
65
|
+
cwd?: string;
|
|
66
|
+
/**
|
|
67
|
+
* True when running the command rewrites project files (a formatter, a fixer). Absent means read-only or unknown.
|
|
68
|
+
* DevWorkspace never runs a mutating command on its own.
|
|
69
|
+
*/
|
|
70
|
+
mutates?: boolean;
|
|
60
71
|
}
|
|
61
72
|
export interface CommandsFile {
|
|
62
73
|
schemaVersion: number;
|
package/dist/config/schemas.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DevWorkspaceError } from '../errors/index.js';
|
|
2
|
+
import { validateRelativePath } from '../utils/paths.js';
|
|
1
3
|
import { Check } from './validate.js';
|
|
2
4
|
export const SCHEMA_VERSION = 1;
|
|
3
5
|
export const CONFIDENCE = ['HIGH', 'MEDIUM', 'LOW'];
|
|
@@ -16,6 +18,8 @@ export function validateProject(v, file = 'project.json') {
|
|
|
16
18
|
const s = c.at_('settings').obj(o.settings);
|
|
17
19
|
c.at_('settings.review').oneOf(s.review, REVIEW_LEVELS);
|
|
18
20
|
c.at_('settings.maxFiles').int(s.maxFiles, 100);
|
|
21
|
+
if (s.acknowledgeNoVerification !== undefined)
|
|
22
|
+
c.at_('settings.acknowledgeNoVerification').bool(s.acknowledgeNoVerification);
|
|
19
23
|
const mf = c.at_('managedFiles').arr(o.managedFiles, 200);
|
|
20
24
|
mf.forEach((m, i) => {
|
|
21
25
|
const mc = c.at_(`managedFiles.${i}`);
|
|
@@ -67,6 +71,14 @@ export function validateCommands(v, file = 'commands.json') {
|
|
|
67
71
|
ec.at_('command').str(eo.command, { max: 500 });
|
|
68
72
|
ec.at_('required').oneOf(eo.required, REQUIRED_LEVELS);
|
|
69
73
|
ec.at_('origin').oneOf(eo.origin, ['repository-script', 'inferred', 'user']);
|
|
74
|
+
if (eo.mutates !== undefined)
|
|
75
|
+
ec.at_('mutates').bool(eo.mutates);
|
|
76
|
+
if (eo.cwd !== undefined) {
|
|
77
|
+
const cwd = ec.at_('cwd').str(eo.cwd, { max: 240 });
|
|
78
|
+
const err = validateRelativePath(cwd);
|
|
79
|
+
if (err)
|
|
80
|
+
throw new DevWorkspaceError('SCHEMA', `Invalid ${file}: checks.${i}.cwd ${err}.`);
|
|
81
|
+
}
|
|
70
82
|
});
|
|
71
83
|
return o;
|
|
72
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/config/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,CAAU,CAAC;AAC9G,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAU,CAAC;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAwBjE,MAAM,UAAU,eAAe,CAAC,CAAU,EAAE,IAAI,GAAG,cAAc;IAC/D,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAA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CAAC,CAAC;QACzE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QACvD,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,mBAAmB,EAAE,UAAU,EAAE,MAAM,CAAU,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;IACL,OAAO,CAA4B,CAAC;AACtC,CAAC;AAYD,MAAM,UAAU,qBAAqB,CAAC,CAAU,EAAE,IAAI,GAAG,eAAe;IACtE,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,OAAO,CAA6B,CAAC;AACvC,CAAC","sourcesContent":["import { Check } from './validate.js';\n\nexport const SCHEMA_VERSION = 1;\n\nexport const CONFIDENCE = ['HIGH', 'MEDIUM', 'LOW'] as const;\nexport const FACT_STATUS = ['VERIFIED', 'DETECTED', 'INFERRED', 'USER_DECISION', 'UNKNOWN', 'STALE'] as const;\nexport const SOURCE_TYPES = ['detector', 'file', 'git', 'user', 'ai'] as const;\nexport const REVIEW_LEVELS = ['off', 'light', 'strict'] as const;\n\nexport type Confidence = (typeof CONFIDENCE)[number];\nexport type FactStatus = (typeof FACT_STATUS)[number];\nexport type SourceType = (typeof SOURCE_TYPES)[number];\nexport type ReviewLevel = (typeof REVIEW_LEVELS)[number];\n\nexport interface ManagedFile {\n path: string;\n mode: 'owned' | 'section';\n agent?: string;\n}\n\nexport interface ProjectConfig {\n schemaVersion: number;\n projectId: string;\n name: string;\n createdAt: string;\n updatedAt: string;\n devworkspaceVersion: string;\n settings: { review: ReviewLevel; maxFiles: number };\n managedFiles: ManagedFile[];\n}\n\nexport function validateProject(v: unknown, file = 'project.json'): ProjectConfig {\n const c = new Check(file);\n const o = c.obj(v);\n c.at_('schemaVersion').int(o.schemaVersion, 1);\n c.at_('projectId').str(o.projectId, { min: 8, max: 64 });\n c.at_('name').str(o.name, { min: 1, max: 200 });\n c.at_('createdAt').iso(o.createdAt);\n c.at_('updatedAt').iso(o.updatedAt);\n c.at_('devworkspaceVersion').str(o.devworkspaceVersion, { max: 40 });\n const s = c.at_('settings').obj(o.settings);\n c.at_('settings.review').oneOf(s.review, REVIEW_LEVELS);\n c.at_('settings.maxFiles').int(s.maxFiles, 100);\n const mf = c.at_('managedFiles').arr(o.managedFiles, 200);\n mf.forEach((m, i) => {\n const mc = c.at_(`managedFiles.${i}`);\n const mo = mc.obj(m);\n mc.at_('path').str(mo.path, { max: 240 });\n mc.at_('mode').oneOf(mo.mode, ['owned', 'section'] as const);\n });\n return o as unknown as ProjectConfig;\n}\n\nexport interface Fact {\n id: string;\n key: string;\n value: string;\n source: string;\n sourceType: SourceType;\n sources: string[];\n sourceHashes: Record<string, string>;\n confidence: Confidence;\n status: FactStatus;\n createdAt: string;\n updatedAt: string;\n lastVerifiedAt: string | null;\n staleReason?: string;\n}\n\nexport interface FactsFile {\n schemaVersion: number;\n facts: Fact[];\n}\n\nexport function validateFacts(v: unknown, file = 'facts.json'): FactsFile {\n const c = new Check(file);\n const o = c.obj(v);\n c.at_('schemaVersion').int(o.schemaVersion, 1);\n const facts = c.at_('facts').arr(o.facts, 5000);\n facts.forEach((f, i) => {\n const fc = c.at_(`facts.${i}`);\n const fo = fc.obj(f);\n fc.at_('id').str(fo.id, { max: 64 });\n fc.at_('key').str(fo.key, { min: 1, max: 100 });\n fc.at_('value').str(fo.value, { max: 4000 });\n fc.at_('source').str(fo.source, { max: 500 });\n fc.at_('sourceType').oneOf(fo.sourceType, SOURCE_TYPES);\n fc.at_('sources').strArr(fo.sources, 100);\n fc.at_('sourceHashes').obj(fo.sourceHashes);\n fc.at_('confidence').oneOf(fo.confidence, CONFIDENCE);\n fc.at_('status').oneOf(fo.status, FACT_STATUS);\n fc.at_('createdAt').iso(fo.createdAt);\n fc.at_('updatedAt').iso(fo.updatedAt);\n if (fo.lastVerifiedAt !== null) fc.at_('lastVerifiedAt').iso(fo.lastVerifiedAt);\n });\n return o as unknown as FactsFile;\n}\n\nexport const CHECK_IDS = ['typecheck', 'unit', 'integration', 'e2e', 'lint', 'format', 'build', 'migrations', 'security'] as const;\nexport type CheckId = (typeof CHECK_IDS)[number];\nexport const REQUIRED_LEVELS = ['yes', 'context', 'no'] as const;\n\nexport interface CommandEntry {\n id: CheckId;\n available: boolean;\n command: string | null;\n required: (typeof REQUIRED_LEVELS)[number];\n source: string | null;\n /** 'repository-script' = defined by repo config (untrusted input); 'inferred' = guessed from tooling; 'user' = set by a human. */\n origin: 'repository-script' | 'inferred' | 'user';\n}\n\nexport interface CommandsFile {\n schemaVersion: number;\n checks: CommandEntry[];\n trustNote: string;\n}\n\nexport function validateCommands(v: unknown, file = 'commands.json'): CommandsFile {\n const c = new Check(file);\n const o = c.obj(v);\n c.at_('schemaVersion').int(o.schemaVersion, 1);\n c.at_('trustNote').str(o.trustNote);\n c.at_('checks')\n .arr(o.checks, 100)\n .forEach((e, i) => {\n const ec = c.at_(`checks.${i}`);\n const eo = ec.obj(e);\n ec.at_('id').oneOf(eo.id, CHECK_IDS);\n ec.at_('available').bool(eo.available);\n if (eo.command !== null) ec.at_('command').str(eo.command, { max: 500 });\n ec.at_('required').oneOf(eo.required, REQUIRED_LEVELS);\n ec.at_('origin').oneOf(eo.origin, ['repository-script', 'inferred', 'user'] as const);\n });\n return o as unknown as CommandsFile;\n}\n\nexport interface AnalysisState {\n schemaVersion: number;\n analyzedAt: string;\n refreshedAt: string | null;\n gitHead: string | null;\n fileCount: number;\n truncated: boolean;\n discoveryHash: string;\n}\n\nexport function validateAnalysisState(v: unknown, file = 'analysis.json'): AnalysisState {\n const c = new Check(file);\n const o = c.obj(v);\n c.at_('schemaVersion').int(o.schemaVersion, 1);\n c.at_('analyzedAt').iso(o.analyzedAt);\n c.at_('fileCount').int(o.fileCount);\n c.at_('truncated').bool(o.truncated);\n c.at_('discoveryHash').str(o.discoveryHash, { max: 100 });\n return o as unknown as AnalysisState;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/config/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,CAAU,CAAC;AAC9G,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAU,CAAC;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG,CA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CAAC,CAAC,CAAC;IACL,OAAO,CAA4B,CAAC;AACtC,CAAC;AAYD,MAAM,UAAU,qBAAqB,CAAC,CAAU,EAAE,IAAI,GAAG,eAAe;IACtE,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,OAAO,CAA6B,CAAC;AACvC,CAAC","sourcesContent":["import { DevWorkspaceError } from '../errors/index.js';\nimport { validateRelativePath } from '../utils/paths.js';\nimport { Check } from './validate.js';\n\nexport const SCHEMA_VERSION = 1;\n\nexport const CONFIDENCE = ['HIGH', 'MEDIUM', 'LOW'] as const;\nexport const FACT_STATUS = ['VERIFIED', 'DETECTED', 'INFERRED', 'USER_DECISION', 'UNKNOWN', 'STALE'] as const;\nexport const SOURCE_TYPES = ['detector', 'file', 'git', 'user', 'ai'] as const;\nexport const REVIEW_LEVELS = ['off', 'light', 'strict'] as const;\n\nexport type Confidence = (typeof CONFIDENCE)[number];\nexport type FactStatus = (typeof FACT_STATUS)[number];\nexport type SourceType = (typeof SOURCE_TYPES)[number];\nexport type ReviewLevel = (typeof REVIEW_LEVELS)[number];\n\nexport interface ManagedFile {\n path: string;\n mode: 'owned' | 'section';\n agent?: string;\n}\n\nexport interface ProjectConfig {\n schemaVersion: number;\n projectId: string;\n name: string;\n createdAt: string;\n updatedAt: string;\n devworkspaceVersion: string;\n settings: { review: ReviewLevel; maxFiles: number; /** The project intentionally has no tests/lint/build; doctor stops warning about it. */ acknowledgeNoVerification?: boolean };\n managedFiles: ManagedFile[];\n}\n\nexport function validateProject(v: unknown, file = 'project.json'): ProjectConfig {\n const c = new Check(file);\n const o = c.obj(v);\n c.at_('schemaVersion').int(o.schemaVersion, 1);\n c.at_('projectId').str(o.projectId, { min: 8, max: 64 });\n c.at_('name').str(o.name, { min: 1, max: 200 });\n c.at_('createdAt').iso(o.createdAt);\n c.at_('updatedAt').iso(o.updatedAt);\n c.at_('devworkspaceVersion').str(o.devworkspaceVersion, { max: 40 });\n const s = c.at_('settings').obj(o.settings);\n c.at_('settings.review').oneOf(s.review, REVIEW_LEVELS);\n c.at_('settings.maxFiles').int(s.maxFiles, 100);\n if (s.acknowledgeNoVerification !== undefined) c.at_('settings.acknowledgeNoVerification').bool(s.acknowledgeNoVerification);\n const mf = c.at_('managedFiles').arr(o.managedFiles, 200);\n mf.forEach((m, i) => {\n const mc = c.at_(`managedFiles.${i}`);\n const mo = mc.obj(m);\n mc.at_('path').str(mo.path, { max: 240 });\n mc.at_('mode').oneOf(mo.mode, ['owned', 'section'] as const);\n });\n return o as unknown as ProjectConfig;\n}\n\nexport interface Fact {\n id: string;\n key: string;\n value: string;\n source: string;\n sourceType: SourceType;\n sources: string[];\n sourceHashes: Record<string, string>;\n confidence: Confidence;\n status: FactStatus;\n createdAt: string;\n updatedAt: string;\n lastVerifiedAt: string | null;\n staleReason?: string;\n}\n\nexport interface FactsFile {\n schemaVersion: number;\n facts: Fact[];\n}\n\nexport function validateFacts(v: unknown, file = 'facts.json'): FactsFile {\n const c = new Check(file);\n const o = c.obj(v);\n c.at_('schemaVersion').int(o.schemaVersion, 1);\n const facts = c.at_('facts').arr(o.facts, 5000);\n facts.forEach((f, i) => {\n const fc = c.at_(`facts.${i}`);\n const fo = fc.obj(f);\n fc.at_('id').str(fo.id, { max: 64 });\n fc.at_('key').str(fo.key, { min: 1, max: 100 });\n fc.at_('value').str(fo.value, { max: 4000 });\n fc.at_('source').str(fo.source, { max: 500 });\n fc.at_('sourceType').oneOf(fo.sourceType, SOURCE_TYPES);\n fc.at_('sources').strArr(fo.sources, 100);\n fc.at_('sourceHashes').obj(fo.sourceHashes);\n fc.at_('confidence').oneOf(fo.confidence, CONFIDENCE);\n fc.at_('status').oneOf(fo.status, FACT_STATUS);\n fc.at_('createdAt').iso(fo.createdAt);\n fc.at_('updatedAt').iso(fo.updatedAt);\n if (fo.lastVerifiedAt !== null) fc.at_('lastVerifiedAt').iso(fo.lastVerifiedAt);\n });\n return o as unknown as FactsFile;\n}\n\nexport const CHECK_IDS = ['typecheck', 'unit', 'integration', 'e2e', 'lint', 'format', 'build', 'migrations', 'security'] as const;\nexport type CheckId = (typeof CHECK_IDS)[number];\nexport const REQUIRED_LEVELS = ['yes', 'context', 'no'] as const;\n\nexport interface CommandEntry {\n id: CheckId;\n available: boolean;\n command: string | null;\n required: (typeof REQUIRED_LEVELS)[number];\n source: string | null;\n /** 'repository-script' = defined by repo config (untrusted input); 'inferred' = guessed from tooling; 'user' = set by a human. */\n origin: 'repository-script' | 'inferred' | 'user';\n /**\n * Working directory, relative to the project root (POSIX separators). Absent means the project root.\n * Package-specific commands (backend vs frontend) must carry it so they are never run in the wrong place.\n */\n cwd?: string;\n /**\n * True when running the command rewrites project files (a formatter, a fixer). Absent means read-only or unknown.\n * DevWorkspace never runs a mutating command on its own.\n */\n mutates?: boolean;\n}\n\nexport interface CommandsFile {\n schemaVersion: number;\n checks: CommandEntry[];\n trustNote: string;\n}\n\nexport function validateCommands(v: unknown, file = 'commands.json'): CommandsFile {\n const c = new Check(file);\n const o = c.obj(v);\n c.at_('schemaVersion').int(o.schemaVersion, 1);\n c.at_('trustNote').str(o.trustNote);\n c.at_('checks')\n .arr(o.checks, 100)\n .forEach((e, i) => {\n const ec = c.at_(`checks.${i}`);\n const eo = ec.obj(e);\n ec.at_('id').oneOf(eo.id, CHECK_IDS);\n ec.at_('available').bool(eo.available);\n if (eo.command !== null) ec.at_('command').str(eo.command, { max: 500 });\n ec.at_('required').oneOf(eo.required, REQUIRED_LEVELS);\n ec.at_('origin').oneOf(eo.origin, ['repository-script', 'inferred', 'user'] as const);\n if (eo.mutates !== undefined) ec.at_('mutates').bool(eo.mutates);\n if (eo.cwd !== undefined) {\n const cwd = ec.at_('cwd').str(eo.cwd, { max: 240 });\n const err = validateRelativePath(cwd);\n if (err) throw new DevWorkspaceError('SCHEMA', `Invalid ${file}: checks.${i}.cwd ${err}.`);\n }\n });\n return o as unknown as CommandsFile;\n}\n\nexport interface AnalysisState {\n schemaVersion: number;\n analyzedAt: string;\n refreshedAt: string | null;\n gitHead: string | null;\n fileCount: number;\n truncated: boolean;\n discoveryHash: string;\n}\n\nexport function validateAnalysisState(v: unknown, file = 'analysis.json'): AnalysisState {\n const c = new Check(file);\n const o = c.obj(v);\n c.at_('schemaVersion').int(o.schemaVersion, 1);\n c.at_('analyzedAt').iso(o.analyzedAt);\n c.at_('fileCount').int(o.fileCount);\n c.at_('truncated').bool(o.truncated);\n c.at_('discoveryHash').str(o.discoveryHash, { max: 100 });\n return o as unknown as AnalysisState;\n}\n"]}
|
|
@@ -1,12 +1,43 @@
|
|
|
1
|
-
import type { CommandEntry } from '../config/schemas.js';
|
|
1
|
+
import type { CheckId, CommandEntry } from '../config/schemas.js';
|
|
2
2
|
import type { PackageInfo } from './detect.js';
|
|
3
3
|
export declare const TRUST_NOTE: string;
|
|
4
|
+
/** One Node.js package: the manifest, where it lives, and which package manager its own lockfile says it uses. */
|
|
5
|
+
export interface NodePackageInput {
|
|
6
|
+
/** Directory relative to the project root, POSIX separators; '' for the root. */
|
|
7
|
+
dir: string;
|
|
8
|
+
pkg: PackageInfo;
|
|
9
|
+
packageManager: string;
|
|
10
|
+
hasTsconfig: boolean;
|
|
11
|
+
}
|
|
4
12
|
export interface ContractInput {
|
|
5
|
-
|
|
6
|
-
packageManager: string | null;
|
|
13
|
+
nodePackages: NodePackageInput[];
|
|
7
14
|
ecosystems: Set<string>;
|
|
8
15
|
has: (rel: string) => boolean;
|
|
9
16
|
pythonEvidence: Record<string, string>;
|
|
10
17
|
files: Set<string>;
|
|
11
18
|
}
|
|
19
|
+
export declare const CHECK_ORDER: CheckId[];
|
|
20
|
+
/**
|
|
21
|
+
* Detected verification commands. Node commands are produced per package and only for scripts that exist in that
|
|
22
|
+
* package's own manifest. Every check that no package provides gets one unavailable entry so the contract always
|
|
23
|
+
* lists all nine checks.
|
|
24
|
+
*/
|
|
12
25
|
export declare function buildContract(input: ContractInput): CommandEntry[];
|
|
26
|
+
export interface MergeResult {
|
|
27
|
+
checks: CommandEntry[];
|
|
28
|
+
/** Entries kept from the previous contract because a human confirmed them (origin "user"). */
|
|
29
|
+
preservedUser: number;
|
|
30
|
+
/** Previously detected entries kept because this analysis found nothing or was cut short. */
|
|
31
|
+
preservedStale: number;
|
|
32
|
+
/** The new detection found no verification commands at all, or the scan was truncated. */
|
|
33
|
+
incomplete: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Combine the previous contract with fresh detection.
|
|
37
|
+
* - Entries confirmed by a person (origin "user") are never dropped or overwritten. A user entry without a cwd
|
|
38
|
+
* covers its whole check; one with a cwd covers only that directory, and detection fills in the other packages.
|
|
39
|
+
* - If detection is incomplete, previously available entries survive too, with their original provenance.
|
|
40
|
+
*/
|
|
41
|
+
export declare function mergeContract(previous: CommandEntry[] | null, detected: CommandEntry[], opts?: {
|
|
42
|
+
truncated?: boolean;
|
|
43
|
+
}): MergeResult;
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
export const TRUST_NOTE = 'Commands marked "repository-script" come from files in the repository (e.g. package.json scripts) and are untrusted input. ' +
|
|
2
2
|
'Inspect what a script does before running it, especially in automation or on unfamiliar repositories.';
|
|
3
|
+
/** First match wins, so more specific scripts (test:unit) are preferred over catch-alls (test). */
|
|
3
4
|
const SCRIPT_CANDIDATES = {
|
|
4
5
|
typecheck: ['typecheck', 'type-check', 'check-types', 'tsc', 'types'],
|
|
5
|
-
unit: ['test', '
|
|
6
|
+
unit: ['test:unit', 'unit', 'test', 'test:run'],
|
|
6
7
|
integration: ['test:integration', 'test:int', 'integration'],
|
|
7
8
|
e2e: ['test:e2e', 'e2e', 'test:playwright', 'test:cypress', 'cypress:run'],
|
|
8
9
|
lint: ['lint', 'eslint', 'lint:check'],
|
|
9
10
|
format: ['format:check', 'prettier:check', 'format-check', 'check:format'],
|
|
10
11
|
build: ['build', 'compile'],
|
|
12
|
+
migrations: ['db:migrate', 'migrate'],
|
|
13
|
+
security: ['test:security', 'security:test', 'security', 'audit:security'],
|
|
11
14
|
};
|
|
15
|
+
/** Scripts that format in place. They are listed for the user but are never required and never run by DevWorkspace. */
|
|
16
|
+
const FORMATTER_SCRIPTS = ['format', 'fmt', 'format:write', 'prettier:write', 'format:fix'];
|
|
17
|
+
/** True unless the script body clearly only checks. Unknown formatter bodies are treated as modifying files. */
|
|
18
|
+
function writesFiles(body) {
|
|
19
|
+
if (/(^|\s)--(?:check|list-different)\b|(^|\s)-l(\s|$)/.test(body))
|
|
20
|
+
return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
12
23
|
const REQUIRED = {
|
|
13
24
|
typecheck: 'yes',
|
|
14
25
|
unit: 'yes',
|
|
@@ -20,73 +31,138 @@ const REQUIRED = {
|
|
|
20
31
|
migrations: 'context',
|
|
21
32
|
security: 'context',
|
|
22
33
|
};
|
|
23
|
-
const
|
|
34
|
+
export const CHECK_ORDER = ['typecheck', 'unit', 'integration', 'e2e', 'lint', 'format', 'build', 'migrations', 'security'];
|
|
24
35
|
function scriptCommand(pm, script) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (mgr === 'yarn')
|
|
36
|
+
if (script === 'test' && (pm === 'npm' || pm === 'pnpm' || pm === 'yarn' || pm === 'bun'))
|
|
37
|
+
return `${pm} test`;
|
|
38
|
+
if (pm === 'yarn')
|
|
29
39
|
return `yarn ${script}`;
|
|
30
|
-
if (
|
|
40
|
+
if (pm === 'bun')
|
|
31
41
|
return `bun run ${script}`;
|
|
32
|
-
return `${
|
|
42
|
+
return `${pm} run ${script}`;
|
|
33
43
|
}
|
|
34
44
|
/** Placeholder scripts such as npm's default "no test specified" do not count as tests. */
|
|
35
45
|
function isRealScript(body) {
|
|
36
46
|
return !/no test specified/i.test(body) && body.trim() !== '';
|
|
37
47
|
}
|
|
48
|
+
const byCwd = (a, b) => (a.cwd ?? '').localeCompare(b.cwd ?? '');
|
|
49
|
+
/**
|
|
50
|
+
* Detected verification commands. Node commands are produced per package and only for scripts that exist in that
|
|
51
|
+
* package's own manifest. Every check that no package provides gets one unavailable entry so the contract always
|
|
52
|
+
* lists all nine checks.
|
|
53
|
+
*/
|
|
38
54
|
export function buildContract(input) {
|
|
39
|
-
const found =
|
|
40
|
-
const
|
|
41
|
-
if (!found.
|
|
42
|
-
found.
|
|
55
|
+
const found = [];
|
|
56
|
+
const add = (id, command, source, origin, cwd, mutates) => {
|
|
57
|
+
if (!found.some((f) => f.id === id && (f.cwd ?? '') === (cwd ?? ''))) {
|
|
58
|
+
found.push({ id, available: true, command, required: mutates ? 'no' : REQUIRED[id], source, origin, ...(cwd ? { cwd } : {}), ...(mutates !== undefined ? { mutates } : {}) });
|
|
59
|
+
}
|
|
43
60
|
};
|
|
44
|
-
|
|
61
|
+
for (const np of input.nodePackages) {
|
|
62
|
+
const manifest = np.dir ? `${np.dir}/package.json` : 'package.json';
|
|
45
63
|
for (const [id, names] of Object.entries(SCRIPT_CANDIDATES)) {
|
|
46
64
|
for (const name of names) {
|
|
47
|
-
const body =
|
|
65
|
+
const body = np.pkg.scripts[name];
|
|
48
66
|
if (body !== undefined && isRealScript(body)) {
|
|
49
|
-
|
|
67
|
+
add(id, scriptCommand(np.packageManager, name), `${manifest}#scripts.${name}`, 'repository-script', np.dir, id === 'format' ? /(^|\s)(?:--write|--fix|-w)(\s|$)/.test(body) : undefined);
|
|
50
68
|
break;
|
|
51
69
|
}
|
|
52
70
|
}
|
|
53
71
|
}
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
// A package with only an in-place formatter (`format`) still gets a format entry, flagged as modifying files.
|
|
73
|
+
if (!found.some((f) => f.id === 'format' && (f.cwd ?? '') === np.dir)) {
|
|
74
|
+
const name = FORMATTER_SCRIPTS.find((n) => np.pkg.scripts[n] !== undefined && isRealScript(np.pkg.scripts[n]));
|
|
75
|
+
if (name)
|
|
76
|
+
add('format', scriptCommand(np.packageManager, name), `${manifest}#scripts.${name}`, 'repository-script', np.dir, writesFiles(np.pkg.scripts[name]));
|
|
77
|
+
}
|
|
78
|
+
if (np.pkg.scripts.typecheck === undefined && np.hasTsconfig && np.pkg.hasTypes && !found.some((f) => f.id === 'typecheck' && (f.cwd ?? '') === np.dir)) {
|
|
79
|
+
add('typecheck', `${np.packageManager === 'pnpm' ? 'pnpm exec' : 'npx'} tsc --noEmit`, `${np.dir ? `${np.dir}/` : ''}tsconfig.json`, 'inferred', np.dir);
|
|
56
80
|
}
|
|
57
81
|
}
|
|
58
82
|
if (input.ecosystems.has('python')) {
|
|
59
83
|
const ev = input.pythonEvidence;
|
|
60
84
|
const hasTestsDir = [...input.files].some((f) => /^tests?\//.test(f) && f.endsWith('.py'));
|
|
61
85
|
if (ev.pytest || hasTestsDir || input.has('pytest.ini'))
|
|
62
|
-
|
|
86
|
+
add('unit', 'pytest', ev.pytest ?? 'tests/', 'inferred');
|
|
63
87
|
if (ev.ruff)
|
|
64
|
-
|
|
88
|
+
add('lint', 'ruff check .', ev.ruff, 'inferred');
|
|
65
89
|
if (ev.mypy)
|
|
66
|
-
|
|
90
|
+
add('typecheck', 'mypy .', ev.mypy, 'inferred');
|
|
67
91
|
if (ev.black)
|
|
68
|
-
|
|
92
|
+
add('format', 'black --check .', ev.black, 'inferred');
|
|
69
93
|
if (ev.alembic)
|
|
70
|
-
|
|
94
|
+
add('migrations', 'alembic check', ev.alembic, 'inferred');
|
|
71
95
|
}
|
|
72
96
|
if (input.ecosystems.has('go')) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
97
|
+
add('unit', 'go test ./...', 'go.mod', 'inferred');
|
|
98
|
+
add('build', 'go build ./...', 'go.mod', 'inferred');
|
|
99
|
+
add('lint', 'go vet ./...', 'go.mod', 'inferred');
|
|
76
100
|
}
|
|
77
101
|
if (input.ecosystems.has('rust')) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
102
|
+
add('unit', 'cargo test', 'Cargo.toml', 'inferred');
|
|
103
|
+
add('build', 'cargo build', 'Cargo.toml', 'inferred');
|
|
104
|
+
add('lint', 'cargo clippy', 'Cargo.toml', 'inferred');
|
|
81
105
|
}
|
|
82
106
|
if (input.has('pom.xml')) {
|
|
83
|
-
|
|
84
|
-
|
|
107
|
+
add('unit', 'mvn test', 'pom.xml', 'inferred');
|
|
108
|
+
add('build', 'mvn package', 'pom.xml', 'inferred');
|
|
85
109
|
}
|
|
86
110
|
if (input.has('build.gradle') || input.has('build.gradle.kts')) {
|
|
87
|
-
|
|
88
|
-
|
|
111
|
+
add('unit', 'gradle test', 'build.gradle', 'inferred');
|
|
112
|
+
add('build', 'gradle build', 'build.gradle', 'inferred');
|
|
113
|
+
}
|
|
114
|
+
return withPlaceholders(found);
|
|
115
|
+
}
|
|
116
|
+
function withPlaceholders(entries) {
|
|
117
|
+
const out = [];
|
|
118
|
+
for (const id of CHECK_ORDER) {
|
|
119
|
+
const mine = entries.filter((e) => e.id === id && e.available).sort(byCwd);
|
|
120
|
+
if (mine.length > 0)
|
|
121
|
+
out.push(...mine);
|
|
122
|
+
else {
|
|
123
|
+
const unavailable = entries.find((e) => e.id === id);
|
|
124
|
+
out.push(unavailable ?? { id, available: false, command: null, required: 'no', source: null, origin: 'inferred' });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Combine the previous contract with fresh detection.
|
|
131
|
+
* - Entries confirmed by a person (origin "user") are never dropped or overwritten. A user entry without a cwd
|
|
132
|
+
* covers its whole check; one with a cwd covers only that directory, and detection fills in the other packages.
|
|
133
|
+
* - If detection is incomplete, previously available entries survive too, with their original provenance.
|
|
134
|
+
*/
|
|
135
|
+
export function mergeContract(previous, detected, opts = {}) {
|
|
136
|
+
const prev = previous ?? [];
|
|
137
|
+
const detectedAvailable = detected.filter((d) => d.available);
|
|
138
|
+
const incomplete = detectedAvailable.length === 0 || !!opts.truncated;
|
|
139
|
+
let preservedUser = 0;
|
|
140
|
+
let preservedStale = 0;
|
|
141
|
+
const out = [];
|
|
142
|
+
for (const id of CHECK_ORDER) {
|
|
143
|
+
const user = prev.filter((p) => p.id === id && p.origin === 'user' && p.available);
|
|
144
|
+
const globalUser = user.some((u) => !u.cwd);
|
|
145
|
+
const det = detectedAvailable.filter((d) => d.id === id);
|
|
146
|
+
const chosen = [...user];
|
|
147
|
+
preservedUser += user.length;
|
|
148
|
+
if (!globalUser) {
|
|
149
|
+
for (const d of det)
|
|
150
|
+
if (!user.some((u) => (u.cwd ?? '') === (d.cwd ?? '')))
|
|
151
|
+
chosen.push(d);
|
|
152
|
+
}
|
|
153
|
+
if (chosen.length === 0 && incomplete) {
|
|
154
|
+
const old = prev.filter((p) => p.id === id && p.available);
|
|
155
|
+
chosen.push(...old);
|
|
156
|
+
preservedStale += old.length;
|
|
157
|
+
}
|
|
158
|
+
if (chosen.length > 0)
|
|
159
|
+
out.push(...chosen.sort(byCwd));
|
|
160
|
+
else {
|
|
161
|
+
// nothing confirmed, nothing detected: list the check as unavailable so the contract always names all nine checks
|
|
162
|
+
const unavailable = detected.find((d) => d.id === id) ?? { id, available: false, command: null, required: 'no', source: null, origin: 'inferred' };
|
|
163
|
+
out.push(unavailable);
|
|
164
|
+
}
|
|
89
165
|
}
|
|
90
|
-
return
|
|
166
|
+
return { checks: out, preservedUser, preservedStale, incomplete };
|
|
91
167
|
}
|
|
92
168
|
//# sourceMappingURL=commands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/discovery/commands.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,UAAU,GACrB,6HAA6H;IAC7H,uGAAuG,CAAC;AAW1G,MAAM,iBAAiB,GAA6B;IAClD,SAAS,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC;IACrE,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC;IAC/C,WAAW,EAAE,CAAC,kBAAkB,EAAE,UAAU,EAAE,aAAa,CAAC;IAC5D,GAAG,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,CAAC;IAC1E,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,CAAC;IACtC,MAAM,EAAE,CAAC,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,CAAC;IAC1E,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC;CAC5B,CAAC;AAEF,MAAM,QAAQ,GAA8C;IAC1D,SAAS,EAAE,KAAK;IAChB,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,SAAS;IACtB,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,KAAK;IACZ,UAAU,EAAE,SAAS;IACrB,QAAQ,EAAE,SAAS;CACpB,CAAC;AAEF,MAAM,KAAK,GAAc,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAA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/C,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC/D,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;QACvD,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,KAAK,CAAC,GAAG,CACd,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAmB,EAAE,CACrI,CAAC;AACJ,CAAC","sourcesContent":["import type { CheckId, CommandEntry } from '../config/schemas.js';\nimport type { PackageInfo } from './detect.js';\n\nexport const TRUST_NOTE =\n 'Commands marked \"repository-script\" come from files in the repository (e.g. package.json scripts) and are untrusted input. ' +\n 'Inspect what a script does before running it, especially in automation or on unfamiliar repositories.';\n\nexport interface ContractInput {\n pkg: PackageInfo | null;\n packageManager: string | null;\n ecosystems: Set<string>;\n has: (rel: string) => boolean;\n pythonEvidence: Record<string, string>;\n files: Set<string>;\n}\n\nconst SCRIPT_CANDIDATES: Record<string, string[]> = {\n typecheck: ['typecheck', 'type-check', 'check-types', 'tsc', 'types'],\n unit: ['test', 'test:unit', 'unit', 'test:run'],\n integration: ['test:integration', 'test:int', 'integration'],\n e2e: ['test:e2e', 'e2e', 'test:playwright', 'test:cypress', 'cypress:run'],\n lint: ['lint', 'eslint', 'lint:check'],\n format: ['format:check', 'prettier:check', 'format-check', 'check:format'],\n build: ['build', 'compile'],\n};\n\nconst REQUIRED: Record<CheckId, CommandEntry['required']> = {\n typecheck: 'yes',\n unit: 'yes',\n integration: 'context',\n e2e: 'context',\n lint: 'yes',\n format: 'context',\n build: 'yes',\n migrations: 'context',\n security: 'context',\n};\n\nconst ORDER: CheckId[] = ['typecheck', 'unit', 'integration', 'e2e', 'lint', 'format', 'build', 'migrations', 'security'];\n\nfunction scriptCommand(pm: string | null, script: string): string {\n const mgr = pm ?? 'npm';\n if (script === 'test' && (mgr === 'npm' || mgr === 'pnpm' || mgr === 'yarn' || mgr === 'bun')) return `${mgr} test`;\n if (mgr === 'yarn') return `yarn ${script}`;\n if (mgr === 'bun') return `bun run ${script}`;\n return `${mgr} run ${script}`;\n}\n\n/** Placeholder scripts such as npm's default \"no test specified\" do not count as tests. */\nfunction isRealScript(body: string): boolean {\n return !/no test specified/i.test(body) && body.trim() !== '';\n}\n\nexport function buildContract(input: ContractInput): CommandEntry[] {\n const found = new Map<CheckId, CommandEntry>();\n const set = (id: CheckId, command: string, source: string, origin: CommandEntry['origin']): void => {\n if (!found.has(id)) found.set(id, { id, available: true, command, required: REQUIRED[id], source, origin });\n };\n\n if (input.pkg) {\n for (const [id, names] of Object.entries(SCRIPT_CANDIDATES)) {\n for (const name of names) {\n const body = input.pkg.scripts[name];\n if (body !== undefined && isRealScript(body)) {\n set(id as CheckId, scriptCommand(input.packageManager, name), `${input.pkg.rel}#scripts.${name}`, 'repository-script');\n break;\n }\n }\n }\n if (!found.has('typecheck') && input.has('tsconfig.json') && input.pkg.hasTypes) {\n set('typecheck', `${input.packageManager === 'pnpm' ? 'pnpm exec' : 'npx'} tsc --noEmit`, 'tsconfig.json', 'inferred');\n }\n }\n\n if (input.ecosystems.has('python')) {\n const ev = input.pythonEvidence;\n const hasTestsDir = [...input.files].some((f) => /^tests?\\//.test(f) && f.endsWith('.py'));\n if (ev.pytest || hasTestsDir || input.has('pytest.ini')) set('unit', 'pytest', ev.pytest ?? 'tests/', 'inferred');\n if (ev.ruff) set('lint', 'ruff check .', ev.ruff, 'inferred');\n if (ev.mypy) set('typecheck', 'mypy .', ev.mypy, 'inferred');\n if (ev.black) set('format', 'black --check .', ev.black, 'inferred');\n if (ev.alembic) set('migrations', 'alembic check', ev.alembic, 'inferred');\n }\n if (input.ecosystems.has('go')) {\n set('unit', 'go test ./...', 'go.mod', 'inferred');\n set('build', 'go build ./...', 'go.mod', 'inferred');\n set('lint', 'go vet ./...', 'go.mod', 'inferred');\n }\n if (input.ecosystems.has('rust')) {\n set('unit', 'cargo test', 'Cargo.toml', 'inferred');\n set('build', 'cargo build', 'Cargo.toml', 'inferred');\n set('lint', 'cargo clippy', 'Cargo.toml', 'inferred');\n }\n if (input.has('pom.xml')) {\n set('unit', 'mvn test', 'pom.xml', 'inferred');\n set('build', 'mvn package', 'pom.xml', 'inferred');\n }\n if (input.has('build.gradle') || input.has('build.gradle.kts')) {\n set('unit', 'gradle test', 'build.gradle', 'inferred');\n set('build', 'gradle build', 'build.gradle', 'inferred');\n }\n\n return ORDER.map(\n (id) => found.get(id) ?? { id, available: false, command: null, required: 'no' as const, source: null, origin: 'inferred' as const },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/discovery/commands.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,UAAU,GACrB,6HAA6H;IAC7H,uGAAuG,CAAC;AAmB1G,mGAAmG;AACnG,MAAM,iBAAiB,GAA6B;IAClD,SAAS,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC;IACrE,IAAI,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC;IAC/C,WAAW,EAAE,CAAC,kBAAkB,EAAE,UAAU,EAAE,aAAa,CAAC;IAC5D,GAAG,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,CAAC;IAC1E,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,CAA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detect.js';\n\nexport const TRUST_NOTE =\n 'Commands marked \"repository-script\" come from files in the repository (e.g. package.json scripts) and are untrusted input. ' +\n 'Inspect what a script does before running it, especially in automation or on unfamiliar repositories.';\n\n/** One Node.js package: the manifest, where it lives, and which package manager its own lockfile says it uses. */\nexport interface NodePackageInput {\n /** Directory relative to the project root, POSIX separators; '' for the root. */\n dir: string;\n pkg: PackageInfo;\n packageManager: string;\n hasTsconfig: boolean;\n}\n\nexport interface ContractInput {\n nodePackages: NodePackageInput[];\n ecosystems: Set<string>;\n has: (rel: string) => boolean;\n pythonEvidence: Record<string, string>;\n files: Set<string>;\n}\n\n/** First match wins, so more specific scripts (test:unit) are preferred over catch-alls (test). */\nconst SCRIPT_CANDIDATES: Record<string, string[]> = {\n typecheck: ['typecheck', 'type-check', 'check-types', 'tsc', 'types'],\n unit: ['test:unit', 'unit', 'test', 'test:run'],\n integration: ['test:integration', 'test:int', 'integration'],\n e2e: ['test:e2e', 'e2e', 'test:playwright', 'test:cypress', 'cypress:run'],\n lint: ['lint', 'eslint', 'lint:check'],\n format: ['format:check', 'prettier:check', 'format-check', 'check:format'],\n build: ['build', 'compile'],\n migrations: ['db:migrate', 'migrate'],\n security: ['test:security', 'security:test', 'security', 'audit:security'],\n};\n\n/** Scripts that format in place. They are listed for the user but are never required and never run by DevWorkspace. */\nconst FORMATTER_SCRIPTS = ['format', 'fmt', 'format:write', 'prettier:write', 'format:fix'];\n\n/** True unless the script body clearly only checks. Unknown formatter bodies are treated as modifying files. */\nfunction writesFiles(body: string): boolean {\n if (/(^|\\s)--(?:check|list-different)\\b|(^|\\s)-l(\\s|$)/.test(body)) return false;\n return true;\n}\n\nconst REQUIRED: Record<CheckId, CommandEntry['required']> = {\n typecheck: 'yes',\n unit: 'yes',\n integration: 'context',\n e2e: 'context',\n lint: 'yes',\n format: 'context',\n build: 'yes',\n migrations: 'context',\n security: 'context',\n};\n\nexport const CHECK_ORDER: CheckId[] = ['typecheck', 'unit', 'integration', 'e2e', 'lint', 'format', 'build', 'migrations', 'security'];\n\nfunction scriptCommand(pm: string, script: string): string {\n if (script === 'test' && (pm === 'npm' || pm === 'pnpm' || pm === 'yarn' || pm === 'bun')) return `${pm} test`;\n if (pm === 'yarn') return `yarn ${script}`;\n if (pm === 'bun') return `bun run ${script}`;\n return `${pm} run ${script}`;\n}\n\n/** Placeholder scripts such as npm's default \"no test specified\" do not count as tests. */\nfunction isRealScript(body: string): boolean {\n return !/no test specified/i.test(body) && body.trim() !== '';\n}\n\nconst byCwd = (a: CommandEntry, b: CommandEntry): number => (a.cwd ?? '').localeCompare(b.cwd ?? '');\n\n/**\n * Detected verification commands. Node commands are produced per package and only for scripts that exist in that\n * package's own manifest. Every check that no package provides gets one unavailable entry so the contract always\n * lists all nine checks.\n */\nexport function buildContract(input: ContractInput): CommandEntry[] {\n const found: CommandEntry[] = [];\n const add = (id: CheckId, command: string, source: string, origin: CommandEntry['origin'], cwd?: string, mutates?: boolean): void => {\n if (!found.some((f) => f.id === id && (f.cwd ?? '') === (cwd ?? ''))) {\n found.push({ id, available: true, command, required: mutates ? 'no' : REQUIRED[id], source, origin, ...(cwd ? { cwd } : {}), ...(mutates !== undefined ? { mutates } : {}) });\n }\n };\n\n for (const np of input.nodePackages) {\n const manifest = np.dir ? `${np.dir}/package.json` : 'package.json';\n for (const [id, names] of Object.entries(SCRIPT_CANDIDATES)) {\n for (const name of names) {\n const body = np.pkg.scripts[name];\n if (body !== undefined && isRealScript(body)) {\n add(id as CheckId, scriptCommand(np.packageManager, name), `${manifest}#scripts.${name}`, 'repository-script', np.dir, id === 'format' ? /(^|\\s)(?:--write|--fix|-w)(\\s|$)/.test(body) : undefined);\n break;\n }\n }\n }\n // A package with only an in-place formatter (`format`) still gets a format entry, flagged as modifying files.\n if (!found.some((f) => f.id === 'format' && (f.cwd ?? '') === np.dir)) {\n const name = FORMATTER_SCRIPTS.find((n) => np.pkg.scripts[n] !== undefined && isRealScript(np.pkg.scripts[n]!));\n if (name) add('format', scriptCommand(np.packageManager, name), `${manifest}#scripts.${name}`, 'repository-script', np.dir, writesFiles(np.pkg.scripts[name]!));\n }\n if (np.pkg.scripts.typecheck === undefined && np.hasTsconfig && np.pkg.hasTypes && !found.some((f) => f.id === 'typecheck' && (f.cwd ?? '') === np.dir)) {\n add('typecheck', `${np.packageManager === 'pnpm' ? 'pnpm exec' : 'npx'} tsc --noEmit`, `${np.dir ? `${np.dir}/` : ''}tsconfig.json`, 'inferred', np.dir);\n }\n }\n\n if (input.ecosystems.has('python')) {\n const ev = input.pythonEvidence;\n const hasTestsDir = [...input.files].some((f) => /^tests?\\//.test(f) && f.endsWith('.py'));\n if (ev.pytest || hasTestsDir || input.has('pytest.ini')) add('unit', 'pytest', ev.pytest ?? 'tests/', 'inferred');\n if (ev.ruff) add('lint', 'ruff check .', ev.ruff, 'inferred');\n if (ev.mypy) add('typecheck', 'mypy .', ev.mypy, 'inferred');\n if (ev.black) add('format', 'black --check .', ev.black, 'inferred');\n if (ev.alembic) add('migrations', 'alembic check', ev.alembic, 'inferred');\n }\n if (input.ecosystems.has('go')) {\n add('unit', 'go test ./...', 'go.mod', 'inferred');\n add('build', 'go build ./...', 'go.mod', 'inferred');\n add('lint', 'go vet ./...', 'go.mod', 'inferred');\n }\n if (input.ecosystems.has('rust')) {\n add('unit', 'cargo test', 'Cargo.toml', 'inferred');\n add('build', 'cargo build', 'Cargo.toml', 'inferred');\n add('lint', 'cargo clippy', 'Cargo.toml', 'inferred');\n }\n if (input.has('pom.xml')) {\n add('unit', 'mvn test', 'pom.xml', 'inferred');\n add('build', 'mvn package', 'pom.xml', 'inferred');\n }\n if (input.has('build.gradle') || input.has('build.gradle.kts')) {\n add('unit', 'gradle test', 'build.gradle', 'inferred');\n add('build', 'gradle build', 'build.gradle', 'inferred');\n }\n\n return withPlaceholders(found);\n}\n\nfunction withPlaceholders(entries: CommandEntry[]): CommandEntry[] {\n const out: CommandEntry[] = [];\n for (const id of CHECK_ORDER) {\n const mine = entries.filter((e) => e.id === id && e.available).sort(byCwd);\n if (mine.length > 0) out.push(...mine);\n else {\n const unavailable = entries.find((e) => e.id === id);\n out.push(unavailable ?? { id, available: false, command: null, required: 'no', source: null, origin: 'inferred' });\n }\n }\n return out;\n}\n\nexport interface MergeResult {\n checks: CommandEntry[];\n /** Entries kept from the previous contract because a human confirmed them (origin \"user\"). */\n preservedUser: number;\n /** Previously detected entries kept because this analysis found nothing or was cut short. */\n preservedStale: number;\n /** The new detection found no verification commands at all, or the scan was truncated. */\n incomplete: boolean;\n}\n\n/**\n * Combine the previous contract with fresh detection.\n * - Entries confirmed by a person (origin \"user\") are never dropped or overwritten. A user entry without a cwd\n * covers its whole check; one with a cwd covers only that directory, and detection fills in the other packages.\n * - If detection is incomplete, previously available entries survive too, with their original provenance.\n */\nexport function mergeContract(previous: CommandEntry[] | null, detected: CommandEntry[], opts: { truncated?: boolean } = {}): MergeResult {\n const prev = previous ?? [];\n const detectedAvailable = detected.filter((d) => d.available);\n const incomplete = detectedAvailable.length === 0 || !!opts.truncated;\n let preservedUser = 0;\n let preservedStale = 0;\n const out: CommandEntry[] = [];\n\n for (const id of CHECK_ORDER) {\n const user = prev.filter((p) => p.id === id && p.origin === 'user' && p.available);\n const globalUser = user.some((u) => !u.cwd);\n const det = detectedAvailable.filter((d) => d.id === id);\n const chosen: CommandEntry[] = [...user];\n preservedUser += user.length;\n if (!globalUser) {\n for (const d of det) if (!user.some((u) => (u.cwd ?? '') === (d.cwd ?? ''))) chosen.push(d);\n }\n if (chosen.length === 0 && incomplete) {\n const old = prev.filter((p) => p.id === id && p.available);\n chosen.push(...old);\n preservedStale += old.length;\n }\n if (chosen.length > 0) out.push(...chosen.sort(byCwd));\n else {\n // nothing confirmed, nothing detected: list the check as unavailable so the contract always names all nine checks\n const unavailable = detected.find((d) => d.id === id) ?? { id, available: false, command: null, required: 'no' as const, source: null, origin: 'inferred' as const };\n out.push(unavailable);\n }\n }\n return { checks: out, preservedUser, preservedStale, incomplete };\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ScanResult } from './scan.js';
|
|
2
|
+
import { type NodePackageInput } from './commands.js';
|
|
2
3
|
import type { CommandEntry } from '../config/schemas.js';
|
|
4
|
+
import { type EntryPoint } from './entrypoints.js';
|
|
3
5
|
export interface Detected {
|
|
4
6
|
name: string;
|
|
5
7
|
category: 'framework' | 'test' | 'tool' | 'database' | 'runtime';
|
|
@@ -10,6 +12,7 @@ export interface SubProject {
|
|
|
10
12
|
name: string;
|
|
11
13
|
ecosystem: string;
|
|
12
14
|
frameworks: string[];
|
|
15
|
+
packageManager?: string;
|
|
13
16
|
}
|
|
14
17
|
export interface PackageInfo {
|
|
15
18
|
rel: string;
|
|
@@ -20,6 +23,9 @@ export interface PackageInfo {
|
|
|
20
23
|
packageManagerField?: string;
|
|
21
24
|
hasTypes: boolean;
|
|
22
25
|
type?: string;
|
|
26
|
+
/** `main` field and `bin` targets, used as evidence for entry points. */
|
|
27
|
+
main?: string;
|
|
28
|
+
bin?: string[];
|
|
23
29
|
}
|
|
24
30
|
export interface DiscoveryReport {
|
|
25
31
|
schemaVersion: 1;
|
|
@@ -49,6 +55,8 @@ export interface DiscoveryReport {
|
|
|
49
55
|
packages: SubProject[];
|
|
50
56
|
};
|
|
51
57
|
commands: CommandEntry[];
|
|
58
|
+
/** Recognised package manifests (project-relative). Used as evidence for derived facts. */
|
|
59
|
+
manifests: string[];
|
|
52
60
|
testConfigs: string[];
|
|
53
61
|
ci: string[];
|
|
54
62
|
docker: string[];
|
|
@@ -58,6 +66,8 @@ export interface DiscoveryReport {
|
|
|
58
66
|
/** Names of credential-like files that exist. Their content is never read. */
|
|
59
67
|
sensitiveFilesPresent: string[];
|
|
60
68
|
entryHints: string[];
|
|
69
|
+
/** Entry points a package itself declares (start-like scripts, `main`, `bin`), with the evidence for each. */
|
|
70
|
+
entryPoints: EntryPoint[];
|
|
61
71
|
warnings: string[];
|
|
62
72
|
}
|
|
63
73
|
export declare function isAuxPath(rel: string): boolean;
|
|
@@ -69,4 +79,17 @@ export interface DetectInput {
|
|
|
69
79
|
projectName: string;
|
|
70
80
|
scan: ScanResult;
|
|
71
81
|
}
|
|
82
|
+
export interface FoundNodePackage extends NodePackageInput {
|
|
83
|
+
manifest: string;
|
|
84
|
+
/** Where the package manager came from, for transparency in discovery.json consumers. */
|
|
85
|
+
pmSource: 'lockfile' | 'packageManager field' | 'inherited from root' | 'default';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Find every Node.js package, not just the root one. Each package gets its own package manager from its own lockfile
|
|
89
|
+
* (falling back to the packageManager field, then the root lockfile, then npm). No script is ever executed.
|
|
90
|
+
*/
|
|
91
|
+
export declare function discoverNodePackages(root: string, files: Set<string>): Promise<{
|
|
92
|
+
packages: FoundNodePackage[];
|
|
93
|
+
unparsable: string[];
|
|
94
|
+
}>;
|
|
72
95
|
export declare function detectProject(input: DetectInput): Promise<DiscoveryReport>;
|