devworkspace 0.2.2 → 0.3.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 +11 -0
- package/dist/agents/claude/content.js +1 -1
- package/dist/agents/claude/content.js.map +1 -1
- package/dist/cli/args.d.ts +3 -0
- package/dist/cli/args.js +1 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.js +3 -3
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/render.d.ts +2 -0
- package/dist/cli/render.js +25 -0
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/run.js +8 -1
- package/dist/cli/run.js.map +1 -1
- package/dist/discovery/cache.d.ts +19 -0
- package/dist/discovery/cache.js +50 -0
- package/dist/discovery/cache.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/adapters/claudePlugin.js +12 -3
- package/dist/integrations/adapters/claudePlugin.js.map +1 -1
- package/dist/services/analysis.d.ts +7 -1
- package/dist/services/analysis.js +11 -4
- package/dist/services/analysis.js.map +1 -1
- package/dist/services/refresh.js +1 -1
- package/dist/services/refresh.js.map +1 -1
- package/dist/services/taskContext.d.ts +59 -0
- package/dist/services/taskContext.js +164 -0
- package/dist/services/taskContext.js.map +1 -0
- package/dist/tasks/routing.js +2 -0
- package/dist/tasks/routing.js.map +1 -1
- package/docs/benchmarking.md +19 -0
- package/docs/knowledge.md +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { SCHEMA_VERSION, validateCommands } from '../config/schemas.js';
|
|
4
|
+
import { loadProject, requireWorkspace } from '../core/workspace.js';
|
|
5
|
+
import { readVersioned } from '../core/versioned.js';
|
|
6
|
+
import { listDecisions } from '../decisions/decision.js';
|
|
7
|
+
import { loadFacts } from '../knowledge/facts.js';
|
|
8
|
+
import { classifyRequest } from '../tasks/routing.js';
|
|
9
|
+
import { pathExists } from '../utils/fs.js';
|
|
10
|
+
import { classifyCommand, readManifestEvidence } from '../verification/safety.js';
|
|
11
|
+
import { dirtyFiles, packageDirs } from '../verification/scope.js';
|
|
12
|
+
import { SAFETY_RULES } from './knowledge.js';
|
|
13
|
+
const STOP = new Set(['the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'does', 'how', 'what', 'where', 'why', 'when', 'which', 'fix', 'add', 'bug', 'make', 'new', 'can', 'are', 'not', 'our', 'all', 'use', 'get', 'set']);
|
|
14
|
+
const CLIP = 400;
|
|
15
|
+
const SECURITY_WORDS = /auth|tenant|permission|rbac|security|isolation|role|session|ownership/i;
|
|
16
|
+
const ISSUE_KEY = /^(?:issue|limit|known|bug|risk)/i;
|
|
17
|
+
/** Facts that describe the stack and layout; implementation-style tasks need them, a lookup question does not. */
|
|
18
|
+
const STACK_KEY = /^(?:stack\.|repo\.packages|repo\.monorepo|repo\.entry-points|convention|style|arch|pattern|testing)/i;
|
|
19
|
+
const BROAD_TYPES = ['FEATURE', 'REFACTOR', 'ARCHITECTURE', 'TESTING', 'PERFORMANCE', 'MAINTENANCE', 'RELEASE'];
|
|
20
|
+
const words = (text) => [...new Set((text.toLowerCase().match(/[a-z0-9_][a-z0-9_.-]{2,}/g) ?? []).filter((w) => !STOP.has(w)))].sort();
|
|
21
|
+
const norm = (s) => s.toLowerCase().replace(/\s+/g, ' ').trim();
|
|
22
|
+
/** Which context documents are worth pointing at for a task type. */
|
|
23
|
+
const DOCS_BY_TYPE = {
|
|
24
|
+
ARCHITECTURE: ['architecture.md', 'integrations.md'],
|
|
25
|
+
REFACTOR: ['architecture.md', 'conventions.md'],
|
|
26
|
+
FEATURE: ['architecture.md', 'conventions.md'],
|
|
27
|
+
BUG: ['testing.md'],
|
|
28
|
+
TESTING: ['testing.md'],
|
|
29
|
+
SECURITY: ['testing.md', 'architecture.md'],
|
|
30
|
+
PERFORMANCE: ['architecture.md'],
|
|
31
|
+
RELEASE: ['testing.md'],
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Task-aware context. Selection is deterministic (sorted inputs, no clocks, no randomness) and rule-based: the request is
|
|
35
|
+
* classified, its keywords select facts/decisions/packages, and the type decides which broader groups come along.
|
|
36
|
+
* Safety rules are included for every type; the per-package "not run automatically" list whenever checks are included.
|
|
37
|
+
*/
|
|
38
|
+
export async function getTaskContext(o, opts) {
|
|
39
|
+
const ws = await requireWorkspace(o.cwd);
|
|
40
|
+
const project = await loadProject(ws);
|
|
41
|
+
const cls = classifyRequest(opts.request);
|
|
42
|
+
const type = cls.type;
|
|
43
|
+
const kw = words(opts.request);
|
|
44
|
+
const included = [];
|
|
45
|
+
const hit = (text) => kw.filter((w) => text.includes(w));
|
|
46
|
+
// Facts
|
|
47
|
+
const all = (await loadFacts(ws)).facts;
|
|
48
|
+
const picked = new Map();
|
|
49
|
+
for (const f of all) {
|
|
50
|
+
const m = hit(`${f.key} ${f.value} ${f.source}`.toLowerCase());
|
|
51
|
+
if (m.length > 0)
|
|
52
|
+
picked.set(f.key, `matches "${m.slice(0, 3).join('", "')}"`);
|
|
53
|
+
}
|
|
54
|
+
const group = (re, why, also) => {
|
|
55
|
+
for (const f of all)
|
|
56
|
+
if (!picked.has(f.key) && (re.test(f.key) || also?.(f)))
|
|
57
|
+
picked.set(f.key, why);
|
|
58
|
+
};
|
|
59
|
+
if (type !== 'QUESTION' && type !== 'DOCUMENTATION')
|
|
60
|
+
group(/^repo\.(?:packages|entry-points)$/, `package layout (${type})`);
|
|
61
|
+
if (type === 'BUG' || type === 'SECURITY')
|
|
62
|
+
group(ISSUE_KEY, 'known issue / limitation', (f) => f.status === 'STALE' && f.sourceType !== 'detector');
|
|
63
|
+
if (BROAD_TYPES.includes(type))
|
|
64
|
+
group(STACK_KEY, `stack and conventions (${type})`);
|
|
65
|
+
if (type === 'SECURITY')
|
|
66
|
+
group(/^$/, 'security / authorization rule', (f) => SECURITY_WORDS.test(`${f.key} ${f.value}`));
|
|
67
|
+
if (type === 'DOCUMENTATION')
|
|
68
|
+
group(/^repo\.docs$/, 'documentation index');
|
|
69
|
+
const selected = all.filter((f) => picked.has(f.key));
|
|
70
|
+
// Compaction: a detector fact whose value equals another selected fact's is folded into it. Human-authored facts are never folded or clipped.
|
|
71
|
+
const aliases = [];
|
|
72
|
+
const owners = new Map();
|
|
73
|
+
for (const f of [...selected].sort((a, b) => Number(a.sourceType === 'detector') - Number(b.sourceType === 'detector') || a.key.localeCompare(b.key))) {
|
|
74
|
+
if (!owners.has(norm(f.value)))
|
|
75
|
+
owners.set(norm(f.value), f.key);
|
|
76
|
+
}
|
|
77
|
+
const facts = [];
|
|
78
|
+
for (const f of [...selected].sort((a, b) => a.key.localeCompare(b.key))) {
|
|
79
|
+
const owner = owners.get(norm(f.value));
|
|
80
|
+
if (owner !== f.key && f.sourceType === 'detector') {
|
|
81
|
+
aliases.push({ key: f.key, sameAs: owner });
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const clip = f.sourceType === 'detector' && f.value.length > CLIP;
|
|
85
|
+
facts.push(clip ? { ...f, value: f.value.slice(0, CLIP), clipped: f.value.length - CLIP } : f);
|
|
86
|
+
included.push({ kind: 'fact', id: f.key, reason: picked.get(f.key) });
|
|
87
|
+
}
|
|
88
|
+
// Packages and the testing contract
|
|
89
|
+
let allChecks = [];
|
|
90
|
+
if (await pathExists(ws.commands))
|
|
91
|
+
allChecks = (await readVersioned(ws.commands, 'commands', SCHEMA_VERSION, validateCommands)).data.checks;
|
|
92
|
+
const pkgReason = new Map();
|
|
93
|
+
for (const d of packageDirs(allChecks)) {
|
|
94
|
+
const m = hit(d.toLowerCase());
|
|
95
|
+
if (m.length > 0)
|
|
96
|
+
pkgReason.set(d, `request names "${m[0]}"`);
|
|
97
|
+
}
|
|
98
|
+
// dirtyFiles already leaves out documentation and tool-managed files, so a docs-only change selects no package.
|
|
99
|
+
// Only worth the Git calls when the request did not already pick a package and there is more than one to choose from.
|
|
100
|
+
const dirty = type !== 'QUESTION' && type !== 'DOCUMENTATION' && pkgReason.size === 0 && packageDirs(allChecks).length > 1 ? await dirtyFiles(ws.root) : null;
|
|
101
|
+
for (const f of Object.keys(dirty?.files ?? {})) {
|
|
102
|
+
const d = packageDirs(allChecks).find((x) => f === x || f.startsWith(`${x}/`));
|
|
103
|
+
if (d && !pkgReason.has(d))
|
|
104
|
+
pkgReason.set(d, 'has uncommitted code changes');
|
|
105
|
+
}
|
|
106
|
+
const usable = allChecks.filter((c) => c.available);
|
|
107
|
+
const scoped = pkgReason.size > 0 ? usable.filter((c) => !c.cwd || c.cwd === '.' || pkgReason.has(c.cwd)) : usable;
|
|
108
|
+
const checks = type === 'QUESTION' || type === 'DOCUMENTATION' ? [] : scoped;
|
|
109
|
+
for (const c of checks)
|
|
110
|
+
included.push({ kind: 'check', id: `${c.cwd ?? '.'}:${c.id}`, reason: c.cwd && pkgReason.has(c.cwd) ? `package: ${pkgReason.get(c.cwd)}` : `testing contract (${type})` });
|
|
111
|
+
// Commands that must not run unguarded stay visible whenever their package's checks are in play.
|
|
112
|
+
const safety = [];
|
|
113
|
+
for (const c of checks) {
|
|
114
|
+
const s = classifyCommand(c, await readManifestEvidence(ws.root, c));
|
|
115
|
+
if (s.safety !== 'safe')
|
|
116
|
+
safety.push({ package: c.cwd ?? '.', check: c.id, command: c.command, safety: s.safety, reasons: s.reasons });
|
|
117
|
+
}
|
|
118
|
+
SAFETY_RULES.forEach((_, i) => included.push({ kind: 'rule', id: `safety-${i + 1}`, reason: 'safety rule, included in every context' }));
|
|
119
|
+
// Decisions: titles and file references only
|
|
120
|
+
const decs = (await listDecisions(ws)).decisions;
|
|
121
|
+
const wantAll = type === 'ARCHITECTURE' || type === 'SECURITY';
|
|
122
|
+
const decisions = [];
|
|
123
|
+
for (const d of decs) {
|
|
124
|
+
const m = hit(`${d.title} ${d.decision} ${d.context}`.toLowerCase());
|
|
125
|
+
if (d.status === 'superseded' && m.length === 0)
|
|
126
|
+
continue;
|
|
127
|
+
if (m.length > 0 || wantAll) {
|
|
128
|
+
decisions.push({ number: d.number, title: d.title, status: d.status, file: d.file });
|
|
129
|
+
included.push({ kind: 'decision', id: String(d.number).padStart(4, '0'), reason: m.length > 0 ? `matches "${m[0]}"` : `${type} tasks review all decisions` });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Documents: referenced, never embedded
|
|
133
|
+
const documents = [];
|
|
134
|
+
let docCount = 0;
|
|
135
|
+
if (await pathExists(ws.contextDir)) {
|
|
136
|
+
for (const name of (await fs.readdir(ws.contextDir)).filter((n) => n.endsWith('.md')).sort()) {
|
|
137
|
+
docCount++;
|
|
138
|
+
const byType = (DOCS_BY_TYPE[type] ?? []).includes(name);
|
|
139
|
+
const m = hit(name.toLowerCase());
|
|
140
|
+
if (byType || m.length > 0) {
|
|
141
|
+
documents.push({ name, bytes: (await fs.stat(path.join(ws.contextDir, name))).size });
|
|
142
|
+
included.push({ kind: 'document', id: name, reason: byType ? `reference for ${type}` : `request names "${m[0]}"` });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
project: { name: project.name, id: project.projectId },
|
|
148
|
+
request: opts.request,
|
|
149
|
+
type,
|
|
150
|
+
confidence: cls.confidence,
|
|
151
|
+
readOnly: cls.readOnly,
|
|
152
|
+
facts,
|
|
153
|
+
aliases,
|
|
154
|
+
checks,
|
|
155
|
+
safety,
|
|
156
|
+
rules: SAFETY_RULES,
|
|
157
|
+
decisions,
|
|
158
|
+
documents,
|
|
159
|
+
packages: [...pkgReason.keys()].sort(),
|
|
160
|
+
included,
|
|
161
|
+
counts: { facts: [facts.length, all.length], checks: [checks.length, usable.length], decisions: [decisions.length, decs.length], documents: [documents.length, docCount] },
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=taskContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task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,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBACtF,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;YACtH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,SAAS,EAAE;QACtD,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI;QACJ,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,KAAK;QACL,OAAO;QACP,MAAM;QACN,MAAM;QACN,KAAK,EAAE,YAAY;QACnB,SAAS;QACT,SAAS;QACT,QAAQ,EAAE,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QACtC,QAAQ;QACR,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE;KAC3K,CAAC;AACJ,CAAC","sourcesContent":["import { promises as fs } from 'node:fs';\nimport path from 'node:path';\nimport { SCHEMA_VERSION, validateCommands, type CommandEntry, type Fact } from '../config/schemas.js';\nimport { loadProject, requireWorkspace } from '../core/workspace.js';\nimport { readVersioned } from '../core/versioned.js';\nimport { listDecisions } from '../decisions/decision.js';\nimport { loadFacts } from '../knowledge/facts.js';\nimport { classifyRequest } from '../tasks/routing.js';\nimport type { TaskType } from '../tasks/task.js';\nimport { pathExists } from '../utils/fs.js';\nimport { classifyCommand, readManifestEvidence } from '../verification/safety.js';\nimport { dirtyFiles, packageDirs } from '../verification/scope.js';\nimport { SAFETY_RULES, type ContextResult } from './knowledge.js';\nimport type { ServiceOptions } from './common.js';\n\nexport interface ContextItem {\n kind: 'fact' | 'check' | 'decision' | 'document' | 'rule';\n id: string;\n /** Why this item is in the context; every item carries one. */\n reason: string;\n}\n\nexport interface TaskContextResult {\n project: { name: string; id: string };\n request: string;\n type: TaskType;\n confidence: 'high' | 'low';\n readOnly: boolean;\n /** `clipped` = characters left out of a long detector-derived value; the full value is in facts.json. */\n facts: (Fact & { clipped?: number })[];\n /** Detector facts folded into another fact with the identical value; nothing is deleted from facts.json. */\n aliases: { key: string; sameAs: string }[];\n checks: CommandEntry[];\n safety: ContextResult['safety'];\n rules: string[];\n decisions: { number: number; title: string; status: string; file: string }[];\n /** Detailed documents are referenced by name, never embedded. */\n documents: { name: string; bytes: number }[];\n packages: string[];\n included: ContextItem[];\n counts: { facts: [number, number]; checks: [number, number]; decisions: [number, number]; documents: [number, number] };\n}\n\nconst STOP = new Set(['the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'does', 'how', 'what', 'where', 'why', 'when', 'which', 'fix', 'add', 'bug', 'make', 'new', 'can', 'are', 'not', 'our', 'all', 'use', 'get', 'set']);\nconst CLIP = 400;\nconst SECURITY_WORDS = /auth|tenant|permission|rbac|security|isolation|role|session|ownership/i;\nconst ISSUE_KEY = /^(?:issue|limit|known|bug|risk)/i;\n/** Facts that describe the stack and layout; implementation-style tasks need them, a lookup question does not. */\nconst STACK_KEY = /^(?:stack\\.|repo\\.packages|repo\\.monorepo|repo\\.entry-points|convention|style|arch|pattern|testing)/i;\nconst BROAD_TYPES: TaskType[] = ['FEATURE', 'REFACTOR', 'ARCHITECTURE', 'TESTING', 'PERFORMANCE', 'MAINTENANCE', 'RELEASE'];\n\nconst words = (text: string): string[] => [...new Set((text.toLowerCase().match(/[a-z0-9_][a-z0-9_.-]{2,}/g) ?? []).filter((w) => !STOP.has(w)))].sort();\nconst norm = (s: string): string => s.toLowerCase().replace(/\\s+/g, ' ').trim();\n\n/** Which context documents are worth pointing at for a task type. */\nconst DOCS_BY_TYPE: Partial<Record<TaskType, string[]>> = {\n ARCHITECTURE: ['architecture.md', 'integrations.md'],\n REFACTOR: ['architecture.md', 'conventions.md'],\n FEATURE: ['architecture.md', 'conventions.md'],\n BUG: ['testing.md'],\n TESTING: ['testing.md'],\n SECURITY: ['testing.md', 'architecture.md'],\n PERFORMANCE: ['architecture.md'],\n RELEASE: ['testing.md'],\n};\n\n/**\n * Task-aware context. Selection is deterministic (sorted inputs, no clocks, no randomness) and rule-based: the request is\n * classified, its keywords select facts/decisions/packages, and the type decides which broader groups come along.\n * Safety rules are included for every type; the per-package \"not run automatically\" list whenever checks are included.\n */\nexport async function getTaskContext(o: ServiceOptions, opts: { request: string }): Promise<TaskContextResult> {\n const ws = await requireWorkspace(o.cwd);\n const project = await loadProject(ws);\n const cls = classifyRequest(opts.request);\n const type = cls.type;\n const kw = words(opts.request);\n const included: ContextItem[] = [];\n const hit = (text: string): string[] => kw.filter((w) => text.includes(w));\n\n // Facts\n const all = (await loadFacts(ws)).facts;\n const picked = new Map<string, string>();\n for (const f of all) {\n const m = hit(`${f.key} ${f.value} ${f.source}`.toLowerCase());\n if (m.length > 0) picked.set(f.key, `matches \"${m.slice(0, 3).join('\", \"')}\"`);\n }\n const group = (re: RegExp, why: string, also?: (f: Fact) => boolean): void => {\n for (const f of all) if (!picked.has(f.key) && (re.test(f.key) || also?.(f))) picked.set(f.key, why);\n };\n if (type !== 'QUESTION' && type !== 'DOCUMENTATION') group(/^repo\\.(?:packages|entry-points)$/, `package layout (${type})`);\n if (type === 'BUG' || type === 'SECURITY') group(ISSUE_KEY, 'known issue / limitation', (f) => f.status === 'STALE' && f.sourceType !== 'detector');\n if (BROAD_TYPES.includes(type)) group(STACK_KEY, `stack and conventions (${type})`);\n if (type === 'SECURITY') group(/^$/, 'security / authorization rule', (f) => SECURITY_WORDS.test(`${f.key} ${f.value}`));\n if (type === 'DOCUMENTATION') group(/^repo\\.docs$/, 'documentation index');\n const selected = all.filter((f) => picked.has(f.key));\n\n // Compaction: a detector fact whose value equals another selected fact's is folded into it. Human-authored facts are never folded or clipped.\n const aliases: TaskContextResult['aliases'] = [];\n const owners = new Map<string, string>();\n for (const f of [...selected].sort((a, b) => Number(a.sourceType === 'detector') - Number(b.sourceType === 'detector') || a.key.localeCompare(b.key))) {\n if (!owners.has(norm(f.value))) owners.set(norm(f.value), f.key);\n }\n const facts: TaskContextResult['facts'] = [];\n for (const f of [...selected].sort((a, b) => a.key.localeCompare(b.key))) {\n const owner = owners.get(norm(f.value))!;\n if (owner !== f.key && f.sourceType === 'detector') {\n aliases.push({ key: f.key, sameAs: owner });\n continue;\n }\n const clip = f.sourceType === 'detector' && f.value.length > CLIP;\n facts.push(clip ? { ...f, value: f.value.slice(0, CLIP), clipped: f.value.length - CLIP } : f);\n included.push({ kind: 'fact', id: f.key, reason: picked.get(f.key)! });\n }\n\n // Packages and the testing contract\n let allChecks: CommandEntry[] = [];\n if (await pathExists(ws.commands)) allChecks = (await readVersioned(ws.commands, 'commands', SCHEMA_VERSION, validateCommands)).data.checks;\n const pkgReason = new Map<string, string>();\n for (const d of packageDirs(allChecks)) {\n const m = hit(d.toLowerCase());\n if (m.length > 0) pkgReason.set(d, `request names \"${m[0]}\"`);\n }\n // dirtyFiles already leaves out documentation and tool-managed files, so a docs-only change selects no package.\n // Only worth the Git calls when the request did not already pick a package and there is more than one to choose from.\n const dirty = type !== 'QUESTION' && type !== 'DOCUMENTATION' && pkgReason.size === 0 && packageDirs(allChecks).length > 1 ? await dirtyFiles(ws.root) : null;\n for (const f of Object.keys(dirty?.files ?? {})) {\n const d = packageDirs(allChecks).find((x) => f === x || f.startsWith(`${x}/`));\n if (d && !pkgReason.has(d)) pkgReason.set(d, 'has uncommitted code changes');\n }\n const usable = allChecks.filter((c) => c.available);\n const scoped = pkgReason.size > 0 ? usable.filter((c) => !c.cwd || c.cwd === '.' || pkgReason.has(c.cwd)) : usable;\n const checks = type === 'QUESTION' || type === 'DOCUMENTATION' ? [] : scoped;\n for (const c of checks) included.push({ kind: 'check', id: `${c.cwd ?? '.'}:${c.id}`, reason: c.cwd && pkgReason.has(c.cwd) ? `package: ${pkgReason.get(c.cwd)}` : `testing contract (${type})` });\n\n // Commands that must not run unguarded stay visible whenever their package's checks are in play.\n const safety: ContextResult['safety'] = [];\n for (const c of checks) {\n const s = classifyCommand(c, await readManifestEvidence(ws.root, c));\n if (s.safety !== 'safe') safety.push({ package: c.cwd ?? '.', check: c.id, command: c.command, safety: s.safety, reasons: s.reasons });\n }\n SAFETY_RULES.forEach((_, i) => included.push({ kind: 'rule', id: `safety-${i + 1}`, reason: 'safety rule, included in every context' }));\n\n // Decisions: titles and file references only\n const decs = (await listDecisions(ws)).decisions;\n const wantAll = type === 'ARCHITECTURE' || type === 'SECURITY';\n const decisions: TaskContextResult['decisions'] = [];\n for (const d of decs) {\n const m = hit(`${d.title} ${d.decision} ${d.context}`.toLowerCase());\n if (d.status === 'superseded' && m.length === 0) continue;\n if (m.length > 0 || wantAll) {\n decisions.push({ number: d.number, title: d.title, status: d.status, file: d.file });\n included.push({ kind: 'decision', id: String(d.number).padStart(4, '0'), reason: m.length > 0 ? `matches \"${m[0]}\"` : `${type} tasks review all decisions` });\n }\n }\n\n // Documents: referenced, never embedded\n const documents: TaskContextResult['documents'] = [];\n let docCount = 0;\n if (await pathExists(ws.contextDir)) {\n for (const name of (await fs.readdir(ws.contextDir)).filter((n) => n.endsWith('.md')).sort()) {\n docCount++;\n const byType = (DOCS_BY_TYPE[type] ?? []).includes(name);\n const m = hit(name.toLowerCase());\n if (byType || m.length > 0) {\n documents.push({ name, bytes: (await fs.stat(path.join(ws.contextDir, name))).size });\n included.push({ kind: 'document', id: name, reason: byType ? `reference for ${type}` : `request names \"${m[0]}\"` });\n }\n }\n }\n\n return {\n project: { name: project.name, id: project.projectId },\n request: opts.request,\n type,\n confidence: cls.confidence,\n readOnly: cls.readOnly,\n facts,\n aliases,\n checks,\n safety,\n rules: SAFETY_RULES,\n decisions,\n documents,\n packages: [...pkgReason.keys()].sort(),\n included,\n counts: { facts: [facts.length, all.length], checks: [checks.length, usable.length], decisions: [decisions.length, decs.length], documents: [documents.length, docCount] },\n };\n}\n"]}
|
package/dist/tasks/routing.js
CHANGED
|
@@ -178,6 +178,8 @@ export function classifyRequest(text) {
|
|
|
178
178
|
return make('TESTING', 'high');
|
|
179
179
|
if (/\b(?:upgrade|bump|update\s+dependenc\w*)\b/i.test(t))
|
|
180
180
|
return make('MAINTENANCE', 'high');
|
|
181
|
+
if (/\b(?:vulnerab\w*|csrf|xss|sql injection|cve-\d+|cross-?tenant|tenant isolation|privilege escalation|idor)\b/i.test(t))
|
|
182
|
+
return make('SECURITY', 'high');
|
|
181
183
|
if (/\b(?:fix|bug|broken|crash(?:es|ing)?|regression|not working|fails?|failing|exception|error)\b/i.test(t))
|
|
182
184
|
return make('BUG', 'high');
|
|
183
185
|
if (/\b(?:refactor|restructure|reorgani[sz]e|clean\s?up|simplify|de-?duplicate)\b/i.test(t))
|
|
@@ -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,Y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H,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)\\s+(?:modify|change|edit|touch)\\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/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)\\s+fix\\b|\\bwithout\\s+fixing\\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)\\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)\\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\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'),\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+)?tests?\\b|\\btest coverage\\b|^\\s*run\\s+(?:the\\s+|all\\s+)?(?:\\w+\\s+)?tests?\\b/i.test(t)) return make('TESTING', 'high');\n if (/\\b(?:upgrade|bump|update\\s+dependenc\\w*)\\b/i.test(t)) return make('MAINTENANCE', 'high');\n if (/\\b(?:fix|bug|broken|crash(?:es|ing)?|regression|not working|fails?|failing|exception|error)\\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 (/\\b(?:document|readme|docs|changelog|jsdoc|docstring)\\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 // 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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' | '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)\\s+(?:modify|change|edit|touch)\\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/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)\\s+fix\\b|\\bwithout\\s+fixing\\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)\\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)\\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\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'),\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+)?tests?\\b|\\btest coverage\\b|^\\s*run\\s+(?:the\\s+|all\\s+)?(?:\\w+\\s+)?tests?\\b/i.test(t)) return make('TESTING', 'high');\n if (/\\b(?:upgrade|bump|update\\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)\\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 (/\\b(?:document|readme|docs|changelog|jsdoc|docstring)\\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 // 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/docs/benchmarking.md
CHANGED
|
@@ -31,3 +31,22 @@ Report medians and ranges, not single runs. Include the onboarding cost in arm B
|
|
|
31
31
|
- Provider token counts are often unavailable inside IDE integrations; use tool-call counts as a proxy and say so.
|
|
32
32
|
- Savings depend heavily on repository size, task type and knowledge quality. A one-file repo will show none.
|
|
33
33
|
- Do not extrapolate to percentages without data from your own runs.
|
|
34
|
+
|
|
35
|
+
## Measuring DevWorkspace itself (speed and context size)
|
|
36
|
+
|
|
37
|
+
The section above is about agent behaviour. This one measures the tool, deterministically and offline.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
npm run build
|
|
41
|
+
node scripts/bench.mjs --files 3000 --runs 9 --json result.json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`scripts/bench.mjs` generates an ERP-shaped monorepo (NestJS-style `backend/` with DB-dependent scripts, React `frontend/`, docs, a `.env` that is never read) in a temp directory, commits it, and times the `dist/` build in-process: first and repeated `analyze`, dry-run `analyze`/`refresh`, `refresh`, and context generation (legacy, `--topic`, and `--for` for five request types). It prints medians, min/max and every sample.
|
|
45
|
+
|
|
46
|
+
To compare against a baseline, build the baseline commit in a separate `git worktree`, copy `scripts/bench.mjs` into it, and run the script in both. Alternate the runs (A, B, A, B) to cancel machine drift.
|
|
47
|
+
|
|
48
|
+
**Token counts are estimates**: rendered CLI output bytes / 4. No tokenizer or model is called. Use them to compare two outputs of the same tool, not as billing numbers. The generated fixture's facts are synthetic; real repositories have more and longer facts, so absolute sizes will differ.
|
|
49
|
+
|
|
50
|
+
Reported per context: bytes, estimated tokens, facts included/available, checks included/available, decisions and documents included/available, and how many safety rules and unsafe-command warnings were kept. Cache behaviour (`hit` / `miss` / `invalidated`) is asserted in `tests/integration/progressive-context.test.ts`; correctness of discovery is covered by the existing discovery suites.
|
|
51
|
+
|
|
52
|
+
What the numbers do not show: the scan (`readdir` of every directory) and the Git query still run on every analyze, because the cache may not decide that nothing changed. Both are the remaining bottlenecks.
|
package/docs/knowledge.md
CHANGED
|
@@ -66,3 +66,20 @@ Never store: source files, `node_modules`/generated output, chat transcripts, te
|
|
|
66
66
|
## Progressive loading
|
|
67
67
|
|
|
68
68
|
The generated instructions tell the agent to load context in levels and stop at the shallowest one that answers the request: (1) instructions → (2) `devworkspace context --topic …` → (3) relevant decisions → (4) Graphify → (5) specific source files → (6) tests/implementation. "Where is customer uniqueness checked?" stops at level 4–5; "Refactor the customer validation architecture" goes to level 6.
|
|
69
|
+
|
|
70
|
+
### Task-aware context (`context --for`)
|
|
71
|
+
|
|
72
|
+
`devworkspace context --for "<request>"` classifies the request (same classifier as `task new`) and prints only what it needs, each item with the reason it is included:
|
|
73
|
+
|
|
74
|
+
- facts whose key, value or source match the request's keywords, plus type groups (stack and conventions for implementation tasks; known issues for bugs; authorization and tenant rules for security);
|
|
75
|
+
- checks of the package the request names, or of the packages with uncommitted code changes, otherwise all checks; none for questions and documentation;
|
|
76
|
+
- decisions by title and file (never their text) and context documents by name (never embedded);
|
|
77
|
+
- the safety rules, always, and the list of commands DevWorkspace will not run by itself whenever their checks are included.
|
|
78
|
+
|
|
79
|
+
Detector-derived facts whose value equals another selected fact's are folded into it in the output, and very long detector values are clipped with a pointer to `context --topic <key>`. Human- and AI-authored facts are never folded or clipped, and nothing is removed from `facts.json`. Output is deterministic. Plain `context` is unchanged.
|
|
80
|
+
|
|
81
|
+
Routing note (0.3.0): requests naming cross-tenant access, tenant isolation, CSRF/XSS, SQL injection, IDOR, CVEs or privilege escalation are classified SECURITY even when they begin with "fix" (they were BUG), so the exploit-test and review gates apply.
|
|
82
|
+
|
|
83
|
+
### Discovery cache
|
|
84
|
+
|
|
85
|
+
`analyze` and `refresh` reuse the previous detection result from `.devworkspace/local/cache/discovery.json` (git-ignored, never exported) only when the scan result, the content of every manifest detection reads, the project name, the scan limit and the DevWorkspace version are identical. The directory scan and the Git query always run; the cache is a shortcut for recomputation, never evidence. `--dry-run`, `status`, `doctor` and `context` never write it. Delete the `local/cache` folder at any time.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devworkspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Project-local AI engineering workspace: deterministic repository discovery, portable project knowledge, tasks, decisions and verification gates for AI coding agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|