devworkspace 0.3.1 → 0.3.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/README.md +3 -1
  3. package/dist/cli/args.d.ts +42 -0
  4. package/dist/cli/args.js +12 -0
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli/help.js +52 -5
  7. package/dist/cli/help.js.map +1 -1
  8. package/dist/cli/render.d.ts +10 -0
  9. package/dist/cli/render.js +167 -0
  10. package/dist/cli/render.js.map +1 -1
  11. package/dist/cli/run.js +84 -4
  12. package/dist/cli/run.js.map +1 -1
  13. package/dist/config/schemas.d.ts +6 -0
  14. package/dist/config/schemas.js +6 -0
  15. package/dist/config/schemas.js.map +1 -1
  16. package/dist/core/version.d.ts +7 -0
  17. package/dist/core/version.js +13 -0
  18. package/dist/core/version.js.map +1 -1
  19. package/dist/core/workspace.d.ts +1 -0
  20. package/dist/core/workspace.js +1 -0
  21. package/dist/core/workspace.js.map +1 -1
  22. package/dist/discovery/commands.d.ts +1 -0
  23. package/dist/discovery/commands.js +3 -1
  24. package/dist/discovery/commands.js.map +1 -1
  25. package/dist/features/schema.d.ts +3 -0
  26. package/dist/features/schema.js +79 -0
  27. package/dist/features/schema.js.map +1 -0
  28. package/dist/features/types.d.ts +77 -0
  29. package/dist/features/types.js +2 -0
  30. package/dist/features/types.js.map +1 -0
  31. package/dist/features/validate.d.ts +14 -0
  32. package/dist/features/validate.js +124 -0
  33. package/dist/features/validate.js.map +1 -0
  34. package/dist/index.d.ts +5 -0
  35. package/dist/index.js +3 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/services/doctor.js +34 -0
  38. package/dist/services/doctor.js.map +1 -1
  39. package/dist/services/drift.d.ts +21 -0
  40. package/dist/services/drift.js +89 -0
  41. package/dist/services/drift.js.map +1 -0
  42. package/dist/services/features.d.ts +22 -0
  43. package/dist/services/features.js +105 -0
  44. package/dist/services/features.js.map +1 -0
  45. package/dist/services/graph.d.ts +97 -0
  46. package/dist/services/graph.js +342 -0
  47. package/dist/services/graph.js.map +1 -0
  48. package/dist/services/refresh.js +15 -0
  49. package/dist/services/refresh.js.map +1 -1
  50. package/dist/services/setup.d.ts +56 -0
  51. package/dist/services/setup.js +116 -0
  52. package/dist/services/setup.js.map +1 -0
  53. package/dist/services/status.d.ts +6 -0
  54. package/dist/services/status.js +16 -0
  55. package/dist/services/status.js.map +1 -1
  56. package/dist/services/verify.d.ts +11 -0
  57. package/dist/services/verify.js +64 -2
  58. package/dist/services/verify.js.map +1 -1
  59. package/docs/architecture-report/01-executive-summary.md +168 -0
  60. package/docs/architecture-report/02-system-architecture.md +356 -0
  61. package/docs/architecture-report/03-tools-and-technologies.md +112 -0
  62. package/docs/architecture-report/04-execution-flows.md +257 -0
  63. package/docs/architecture-report/05-codebase-map.md +150 -0
  64. package/docs/architecture-report/06-command-reference.md +446 -0
  65. package/docs/architecture-report/07-data-flow-and-integrations.md +268 -0
  66. package/docs/architecture-report/08-build-test-deployment.md +185 -0
  67. package/docs/architecture-report/09-security-and-reliability.md +165 -0
  68. package/docs/architecture-report/10-feature-status.md +110 -0
  69. package/docs/architecture-report/11-glossary.md +97 -0
  70. package/docs/architecture-report/README.md +103 -0
  71. package/docs/architecture-report/diagrams.md +446 -0
  72. package/docs/getting-started.md +38 -1
  73. package/package.json +1 -1
@@ -0,0 +1,356 @@
1
+ # Chapter 2: System Architecture
2
+
3
+ > **A deep dive into the layered architecture of DevWorkspace, component relationships, and boundary interfaces.**
4
+
5
+ ---
6
+
7
+ ## 1. Architectural Overview & Design Philosophy
8
+
9
+ DevWorkspace is organized as a clean, unidirectional layered architecture. Data and control flow strictly downward from the presentation interface to the filesystem and external processes:
10
+
11
+ ```
12
+ +-----------------------------------------------------------------------------------+
13
+ | 1. CLI & PRESENTATION LAYER |
14
+ | (src/cli/main.ts, args.ts, run.ts, render.ts, help.ts) |
15
+ +-----------------------------------------------------------------------------------+
16
+ |
17
+ v
18
+ +-----------------------------------------------------------------------------------+
19
+ | 2. SERVICE ORCHESTRATION LAYER |
20
+ | (src/services/: init, analysis, status, doctor, agent, ...) |
21
+ +-----------------------------------------------------------------------------------+
22
+ |
23
+ v
24
+ +-----------------------------------------------------------------------------------+
25
+ | 3. DOMAIN ENGINES |
26
+ | Discovery Agents Integrations Tasks & Gates Knowledge |
27
+ | (src/discovery/) (src/agents/) (src/integrations/) (src/tasks/) (src/knowl.) |
28
+ +-----------------------------------------------------------------------------------+
29
+ |
30
+ v
31
+ +-----------------------------------------------------------------------------------+
32
+ | 4. CORE FOUNDATION & SECURITY INVARIANTS |
33
+ | Security Invariants Atomic Filesystem & Locks Schemas & Validation |
34
+ | (src/security/) (src/utils/, src/core/) (src/config/) |
35
+ +-----------------------------------------------------------------------------------+
36
+ ```
37
+
38
+ ### Key Architectural Invariants
39
+ 1. **Zero Runtime Dependencies**: The core codebase relies solely on Node.js built-in APIs (`node:fs`, `node:path`, `node:crypto`, `node:child_process`, `node:util`).
40
+ 2. **Pure Service Layer**: Service functions return plain JavaScript objects representing facts and outcomes; they never call `process.exit()` or print directly to `stdout`/`stderr`. This makes the entire service layer directly callable from a programmatic API (`src/index.ts`) for future IDE plugins or dashboards.
41
+ 3. **Immutable State & Atomic Writes**: Files are written using `atomicWriteJson` (writing to a temporary file, flushing to disk, and renaming atomically). Partial file writes never occur even during unexpected crashes or power interruptions.
42
+ 4. **Untrusted Repository Content**: Source code, test scripts, comments, documentation, and manifests are treated as untrusted data. They can be analyzed, but they can never override system safety rules or execute arbitrarily.
43
+
44
+ ---
45
+
46
+ ## 2. Diagram 1: High-Level System Architecture
47
+
48
+ ```mermaid
49
+ flowchart TD
50
+ subgraph UI_Layer["1. Presentation Layer"]
51
+ CLI_Entry["CLI Entrypoint\n(src/cli/main.ts)"]
52
+ ArgParser["Arg Parser\n(src/cli/args.ts)"]
53
+ CommandRouter["Command Dispatcher\n(src/cli/run.ts)"]
54
+ TerminalRenderer["Terminal / JSON Renderer\n(src/cli/render.ts)"]
55
+ end
56
+
57
+ subgraph Service_Layer["2. Service Orchestration Layer"]
58
+ SvcInit["initWorkspace()"]
59
+ SvcAnalyze["analyzeWorkspace()"]
60
+ SvcStatus["getStatus()"]
61
+ SvcDoctor["runDoctor()"]
62
+ SvcAgent["installAgent()"]
63
+ SvcTask["createTask() / runTaskCheck()"]
64
+ SvcKnowledge["addFact() / getContext()"]
65
+ SvcIntegrations["setupIntegrations()"]
66
+ end
67
+
68
+ subgraph Engine_Layer["3. Domain Engine Subsystems"]
69
+ subgraph DiscoverySub["Discovery Engine"]
70
+ Scanner["Filesystem Scanner\n(src/discovery/scan.ts)"]
71
+ Detector["Stack & Framework Detector\n(src/discovery/detect.ts)"]
72
+ CommandBuilder["Testing Contract Builder\n(src/discovery/commands.ts)"]
73
+ DocScanner["Documentation Detector\n(src/discovery/docs.ts)"]
74
+ EntryScanner["Entry Points Detector\n(src/discovery/entrypoints.ts)"]
75
+ end
76
+
77
+ subgraph AgentsSub["Multi-Agent Compatibility Engine"]
78
+ AgentRegistry["Agent Registry\n(src/agents/index.ts)"]
79
+ ClaudeAdapter["Claude Code Adapter\n(CLAUDE.md & SKILL.md)"]
80
+ CodexAdapter["OpenAI Codex Adapter\n(AGENTS.md)"]
81
+ CursorAdapter["Cursor Adapter\n(.cursor/rules/)"]
82
+ CopilotAdapter["Copilot Adapter\n(.github/copilot-instructions.md)"]
83
+ SectionMerger["Non-Destructive Section Merger\n(src/agents/shared.ts)"]
84
+ end
85
+
86
+ subgraph TasksSub["Task & Verification Engine"]
87
+ TaskRouter["Request Classifier\n(src/tasks/routing.ts)"]
88
+ TaskLifecycle["Task State Machine\n(src/tasks/task.ts)"]
89
+ GateEvaluator["evaluateGate()\n(src/tasks/task.ts)"]
90
+ SafetyClassifier["classifyCommand()\n(src/verification/safety.ts)"]
91
+ ScopeTracker["Scope & Baseline Tracker\n(src/verification/scope.ts)"]
92
+ end
93
+
94
+ subgraph IntegrationsSub["External Integration Manager"]
95
+ IntManager["Integration Manager\n(src/integrations/manager.ts)"]
96
+ GraphifyAdapter["Graphify Adapter\n(graphifyy PyPI)"]
97
+ AgentSkillsAdapter["Agent Skills Adapter\n(addyosmani/agent-skills)"]
98
+ PonytailAdapter["Ponytail Adapter\n(DietrichGebert/ponytail)"]
99
+ OmniRouteAdapter["OmniRoute Adapter\n(Observed optional)"]
100
+ end
101
+ end
102
+
103
+ subgraph Foundation_Layer["4. Core Foundation & Security"]
104
+ WorkspaceCore["Workspace Root & Paths\n(src/core/workspace.ts)"]
105
+ SecurityFiles["safeReadText() & Path Guard\n(src/security/files.ts)"]
106
+ SecretRedact["findSecrets() & redact()\n(src/security/redact.ts)"]
107
+ AtomicFs["atomicWriteJson() & Lockfile\n(src/utils/fs.ts, lock.ts)"]
108
+ Schemas["Data Contracts & Validation\n(src/config/schemas.ts)"]
109
+ end
110
+
111
+ CLI_Entry --> ArgParser
112
+ ArgParser --> CommandRouter
113
+ CommandRouter --> Service_Layer
114
+ CommandRouter --> TerminalRenderer
115
+
116
+ SvcInit --> WorkspaceCore
117
+ SvcAnalyze --> DiscoverySub
118
+ SvcAgent --> AgentsSub
119
+ SvcTask --> TasksSub
120
+ SvcIntegrations --> IntegrationsSub
121
+
122
+ DiscoverySub --> SecurityFiles
123
+ TasksSub --> SafetyClassifier
124
+ TasksSub --> ScopeTracker
125
+ AgentsSub --> SectionMerger
126
+ IntegrationsSub --> AtomicFs
127
+
128
+ SecurityFiles --> WorkspaceCore
129
+ AtomicFs --> Schemas
130
+ SecretRedact --> AtomicFs
131
+ ```
132
+
133
+ ---
134
+
135
+ ## 3. Subsystem Breakdown and Responsibilities
136
+
137
+ ### Subsystem 1: CLI and Presentation Layer (`src/cli/`)
138
+ - **`main.ts`**: The Node.js binary shebang (`#!/usr/bin/env node`). It hooks process signals (`SIGINT`, `SIGTERM`) to trigger cleanup handlers (`src/utils/cleanup.ts`), ensuring lockfiles are deleted and incomplete operations do not leave stale state. It translates asynchronous results into integer exit codes:
139
+ - `0`: Success (OK)
140
+ - `1`: Failure / error
141
+ - `2`: Usage error or manual approval needed
142
+ - `3`: Warnings encountered (under `--strict` mode)
143
+ - `130`: Terminated by signal (SIGINT/SIGTERM)
144
+ - **`args.ts`**: Strict argument parser using `node:util/parseArgs`. It declares the exact supported flags (`--json`, `--cwd`, `--dry-run`, `--strict`, `--yes`, `--agent`, etc.). Unrecognized flags trigger a `DevWorkspaceError('USAGE')` so typos never fail silently.
145
+ - **`run.ts`**: The main dispatcher. It builds the execution context (`Ctx`), maps aliases (e.g., `tasks` -> `task list`), routes commands to their respective async handler functions, and handles JSON vs human-readable output formatting.
146
+ - **`render.ts`**: Pure visual presentation engine. Formats tables, checkmarks (`✓`, `✗`, `⚠`), badges, and hierarchical task summaries with optional ANSI colors. When `--ascii` or `NO_COLOR` is detected, it renders plain ASCII fallbacks.
147
+ - **`help.ts`**: Contains command documentation, parameter guides, and examples printed during `devworkspace --help` and `devworkspace <command> --help`.
148
+
149
+ ---
150
+
151
+ ### Subsystem 2: Service Orchestration Layer (`src/services/`)
152
+ The service layer implements the business logic of each CLI command. Every service function accepts a standard `ServiceOptions` object containing `{ cwd, dryRun, env, runner, homeDir }` and returns structured result data.
153
+
154
+ | Service Module | Function | Responsibility |
155
+ |---|---|---|
156
+ | `init.ts` | `initWorkspace()` | Idempotently creates `.devworkspace/` directories, `project.json`, and `.gitignore`. |
157
+ | `analysis.ts` | `analyzeWorkspace()` | Coordinates filesystem scanning, framework detection, testing contract construction, and onboarding prompt generation. |
158
+ | `status.ts` | `getStatus()` | Aggregates high-level project health, uncommitted Git changes, knowledge facts count, active tasks, and integration summaries. |
159
+ | `doctor.ts` | `runDoctor()` | Runs 20+ diagnostic checks inspecting Node version, Git status, workspace integrity, secret exposure, and integration readiness. |
160
+ | `agent.ts` | `installAgent()`, `listAgents()` | Coordinates the multi-agent adapters to plan, create, or update agent instruction files (`AGENTS.md`, `CLAUDE.md`, etc.). |
161
+ | `tasks.ts` | `createTask()`, `setTaskStatus()` | Manages task records in `.devworkspace/tasks/`, validates status transitions, and enforces the completion gate. |
162
+ | `taskContext.ts` | `getTaskContext()` | Formats a compact, task-specific prompt containing only the facts, rules, and commands needed for a specific request. |
163
+ | `verify.ts` | `runTaskCheck()`, `declareTestEnv()` | Executes testing contract commands safely, checking destructive keywords and test environment requirements. |
164
+ | `knowledge.ts` | `addFact()`, `getContext()` | Stores, updates, and queries durable facts with authority ranking and source tracking. |
165
+ | `refresh.ts` | `refreshWorkspace()` | Re-runs deterministic discovery and marks facts as `STALE` if their source files have changed. |
166
+ | `records.ts` | `recordDecision()`, `recordSession()` | Appends Architecture Decision Records (ADRs) to `.devworkspace/decisions/` and session logs to `.devworkspace/sessions/`. |
167
+ | `portability.ts` | `exportWorkspace()`, `importWorkspace()` | Bundles portable project knowledge into a single JSON file and validates imports against schema limits. |
168
+ | `reset.ts` | `resetWorkspace()` | Safely resets `.devworkspace/` after generating an explicit deletion plan and requiring `--yes`. |
169
+ | `migrate.ts` | `migrateWorkspace()` | Upgrades workspace data structures across schema versions, saving automatic backups in `.devworkspace/local/backups/`. |
170
+
171
+ ---
172
+
173
+ ### Subsystem 3: Discovery Engine (`src/discovery/`)
174
+ The discovery engine analyzes a project repository without executing user code and without calling an AI model.
175
+
176
+ ```mermaid
177
+ flowchart LR
178
+ Scan["scan.ts\n(Tree walk with ignore rules)"]
179
+ Detect["detect.ts\n(Framework & ecosystem detection)"]
180
+ Commands["commands.ts\n(Testing contract derivation)"]
181
+ Docs["docs.ts\n(Architecture & ADR discovery)"]
182
+ Entry["entrypoints.ts\n(Server & worker entrypoints)"]
183
+
184
+ Scan --> Detect
185
+ Detect --> Commands
186
+ Detect --> Docs
187
+ Detect --> Entry
188
+ Commands --> Output["discovery.json\ncommands.json\nonboarding-prompt.md"]
189
+ Docs --> Output
190
+ Entry --> Output
191
+ ```
192
+
193
+ - **`scan.ts`**: Walks the directory tree up to a bounded maximum (10,000 files). Automatically skips `node_modules/`, `.git/`, `dist/`, `build/`, `vendor/`, and paths specified in `.gitignore`. Detects symlinks and skips them to avoid circular traversal loops.
194
+ - **`detect.ts`**: Inspects package manifests (`package.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`) and file extensions to detect:
195
+ - Ecosystems (Node.js, Python, Go, Rust, Java, C#, PHP, Ruby)
196
+ - Frameworks (React, Fastify, Express, Next.js, NestJS, Vite, Django, FastAPI)
197
+ - Databases and ORMs (Drizzle, Prisma, TypeORM, Mongoose, PostgreSQL, Redis)
198
+ - Monorepo tools (npm/pnpm/yarn workspaces, Lerna, Turbo, Nx, Cargo/Go workspaces, or multi-package repos without a root manifest)
199
+ - **`commands.ts`**: Inspects `scripts` in all package manifests across the repository. Maps them into standard contract checks: `typecheck`, `unit`, `integration`, `e2e`, `lint`, `format`, `build`, `migrations`, `security`. Tracks the exact `cwd` (working directory) for each script.
200
+ - **`entrypoints.ts`**: Discovers application launch files by inspecting `main`, `bin`, and script definitions like `start`, `dev`, `server`, and `worker:*`.
201
+ - **`docs.ts`**: Finds architecture docs, READMEs, and ADRs (Architecture Decision Records) up to a bounded limit of 25 files, ignoring changelogs and licenses.
202
+
203
+ ---
204
+
205
+ ### Subsystem 4: Multi-Agent Compatibility Engine (`src/agents/`)
206
+ The multi-agent engine adapts DevWorkspace's instructions to the exact file formats expected by different coding agents:
207
+
208
+ ```mermaid
209
+ flowchart TD
210
+ AdapterInterface["AgentAdapter Interface\n(src/agents/types.ts)"]
211
+
212
+ AdapterInterface --> Claude["Claude Code Adapter\n(CLAUDE.md + .claude/skills/)"]
213
+ AdapterInterface --> Codex["OpenAI Codex Adapter\n(AGENTS.md)"]
214
+ AdapterInterface --> Cursor["Cursor Adapter\n(.cursor/rules/devworkspace.mdc)"]
215
+ AdapterInterface --> Copilot["Copilot Adapter\n(.github/copilot-instructions.md)"]
216
+
217
+ Claude --> SectionMerge["mergeSection()\n(Non-destructive managed block injection)"]
218
+ Codex --> SectionMerge
219
+ Cursor --> SectionMerge
220
+ Copilot --> SectionMerge
221
+
222
+ SectionMerge --> TargetFiles["User Repository Instruction Files"]
223
+ ```
224
+
225
+ - **`types.ts`**: Defines the `AgentAdapter` interface. Every adapter implements `id`, `displayName`, `capabilities`, `detectExisting()`, `detectAvailable()`, `plan()`, and `unplan()`.
226
+ - **`shared.ts`**: Provides `mergeSection()`, `removeManagedSection()`, and EOL detection (`\r\n` vs `\n`). When writing instructions, DevWorkspace encloses its content in:
227
+ ```markdown
228
+ <!-- devworkspace:start (managed by DevWorkspace - edit outside this block; run "devworkspace agent install" to refresh) -->
229
+ ## DevWorkspace
230
+ ...
231
+ <!-- devworkspace:end -->
232
+ ```
233
+ If a user has already written instructions above or below this block, **their custom instructions are 100% preserved**.
234
+ - **`claude/adapter.ts`**: Writes `CLAUDE.md` and generates a dedicated skill at `.claude/skills/devworkspace/SKILL.md` containing task routing rules.
235
+ - **`codex/adapter.ts`**: Writes standard `AGENTS.md` (which is also read by OpenAI Codex, Google Antigravity, and other open-spec agents).
236
+ - **`cursor/adapter.ts`**: Writes `.cursor/rules/devworkspace.mdc` with YAML frontmatter `alwaysApply: true`, and falls back to legacy `.cursorrules` if present.
237
+ - **`copilot/adapter.ts`**: Writes `.github/copilot-instructions.md` for GitHub Copilot in VS Code.
238
+
239
+ ---
240
+
241
+ ### Subsystem 5: Task and Verification Gate Engine (`src/tasks/` & `src/verification/`)
242
+ Manages task lifecycles and enforces that work is verified before being declared complete.
243
+
244
+ - **`routing.ts`**: Classifies incoming user prompts into 10 task types (`QUESTION`, `BUG`, `FEATURE`, `REFACTOR`, `DOCUMENTATION`, `TESTING`, `PERFORMANCE`, `SECURITY`, `ARCHITECTURE`, `RELEASE`) and detects explicit user constraints (e.g. `no-modify`, `no-commit`, `no-e2e`, `plan-only`).
245
+ - **`task.ts`**: Represents tasks as JSON documents stored in `.devworkspace/tasks/active/` and moved to `.devworkspace/tasks/completed/` when finished. Holds verification checklists, test baselines, and attestations.
246
+ - **`task.ts (evaluateGate)`**: Pure logic function that evaluates whether a task satisfies completion requirements:
247
+ - All required verification checks must be `PASS` or `SKIPPED` (with explicit user override).
248
+ - Test counts must not regress (`after.failed <= baseline.failed` and `after.passed >= baseline.passed`).
249
+ - Read-only tasks must not have modified any files.
250
+ - Three attestations must be checked: `userWorkIntact`, `knowledgeReviewed`, `finalStateInspected`.
251
+ - A completion summary must be provided.
252
+ - **`safety.ts`**: Evaluates whether DevWorkspace may execute a command automatically. Classifies commands as:
253
+ - `safe`: `typecheck`, `lint`, `build`, and unit tests without external dependencies.
254
+ - `needs-test-environment`: Integration, security, or catch-all tests that require databases or queues (PostgreSQL, Redis, MongoDB). Blocked unless declared via `devworkspace testenv declare`.
255
+ - `blocked`: Commands that mutate files (`format`, `lint --fix`), run migrations (`db:migrate`), or contain destructive keywords (`drop`, `truncate`, `flushall`, `rm -rf`). DevWorkspace will never execute these commands automatically.
256
+ - **`scope.ts`**: Captures a baseline fingerprint of uncommitted files at task creation. When verification runs later, DevWorkspace only requires checks for packages that were modified *by the current task*.
257
+
258
+ ---
259
+
260
+ ### Subsystem 6: External Integration Manager (`src/integrations/`)
261
+ DevWorkspace does not invent its own AI models or code-graph parsers. Instead, it inspects and coordinates external tools installed on the developer's machine:
262
+
263
+ ```mermaid
264
+ flowchart TD
265
+ Mgr["Integration Manager (src/integrations/manager.ts)"]
266
+
267
+ subgraph ExternalTools["Observed / Coordinated Tools"]
268
+ Graphify["Graphify (PyPI: graphifyy)\nKnowledge graph of code structure\n(CLI + .claude/skills/graphify)"]
269
+ AgentSkills["Agent Skills (addyosmani/agent-skills)\nEngineering methodology slash commands\n(/spec /plan /build /test /review /ship)"]
270
+ Ponytail["Ponytail (DietrichGebert/ponytail)\nCode complexity & diff review\n(/ponytail-review, /ponytail-audit)"]
271
+ OmniRoute["OmniRoute (diegosouzapw/OmniRoute)\nModel routing proxy\n(Observed only; never required or executed)"]
272
+ end
273
+
274
+ Mgr -->|"inspect(deep) & plan()"| Graphify
275
+ Mgr -->|"inspect(deep) & plan()"| AgentSkills
276
+ Mgr -->|"inspect(deep) & plan()"| Ponytail
277
+ Mgr -->|"inspect(deep)"| OmniRoute
278
+ ```
279
+
280
+ - **`manager.ts`**: Runs inspection, plans installation steps, checks prerequisites, and executes installations with user consent.
281
+ - **`exec.ts`**: Safe process runner that checks PATH, executes `which`/`where`, parses semantic versions, and enforces timeouts so processes never hang indefinitely.
282
+ - **`protect.ts`**: Takes pre-execution snapshots of files that third-party tools might mutate (such as `CLAUDE.md` or `.claude/settings.json`) and verifies that uncommitted user changes were not overwritten.
283
+
284
+ ---
285
+
286
+ ### Subsystem 7: Core Security and Foundation (`src/security/`, `src/utils/`, `src/core/`)
287
+ Underpins the entire application with safety invariants:
288
+ - **`files.ts` (`safeReadText`)**: Canonicalizes paths and strictly verifies that files reside inside the repository root. Rejects any file whose name matches sensitive patterns (`.env`, `.pem`, `.key`, `id_rsa`, `credentials`). Verifies that no intermediate symlink escapes outside the repository.
289
+ - **`redact.ts`**: Scans text using regex patterns for API keys (AWS, GitHub, Slack, Google, npm, OpenAI, JWTs, private keys) and replaces them with `[REDACTED:<type>]`.
290
+ - **`lock.ts`**: Implements file-based mutual exclusion (`.devworkspace/local/devworkspace.lock`). Prevents concurrent CLI invocations from corrupting workspace files.
291
+ - **`fs.ts`**: Provides `atomicWriteJson` and `atomicWriteFile`. Writes to temporary files and executes atomic renames.
292
+ - **`schemas.ts`**: Type-safe schema validation for all persisted JSON files (`project.json`, `facts.json`, `commands.json`, `discovery.json`, tasks, and sessions).
293
+
294
+ ---
295
+
296
+ ## 4. Diagram 4: Tool and Integration Map
297
+
298
+ The following diagram maps which internal DevWorkspace modules interact with external tools and dependencies:
299
+
300
+ ```mermaid
301
+ flowchart LR
302
+ subgraph InternalModules["Internal DevWorkspace Modules"]
303
+ CLI["src/cli/"]
304
+ SvcAnal["src/services/analysis.ts"]
305
+ SvcAgent["src/services/agent.ts"]
306
+ SvcInt["src/services/integrations.ts"]
307
+ SvcVer["src/services/verify.ts"]
308
+ Sec["src/security/"]
309
+ end
310
+
311
+ subgraph NodeBuiltins["Node.js 20+ Built-in APIs"]
312
+ FS["node:fs / node:fs/promises"]
313
+ Path["node:path"]
314
+ Proc["node:child_process (spawnSync)"]
315
+ Crypto["node:crypto (createHash, randomUUID)"]
316
+ Util["node:util (parseArgs)"]
317
+ OS["node:os (tmpdir, platform)"]
318
+ end
319
+
320
+ subgraph ExternalAgents["Coding Agent Instruction Targets"]
321
+ ClaudeCode["Claude Code (CLAUDE.md)"]
322
+ Codex["OpenAI Codex / Antigravity (AGENTS.md)"]
323
+ Cursor["Cursor IDE (.cursor/rules/)"]
324
+ Copilot["GitHub Copilot (.github/copilot-instructions.md)"]
325
+ end
326
+
327
+ subgraph ExternalToolchains["External Subprocesses (Observed / Coordinated)"]
328
+ Git["git (git status, rev-parse, diff)"]
329
+ GraphifyCli["graphify (Python / pipx / uv)"]
330
+ ClaudeCli["claude (plugin list, plugin install)"]
331
+ SkillsCli["skills (npx skills add)"]
332
+ NodeExe["node (for Ponytail lifecycle hooks)"]
333
+ ProjectNPM["npm / pnpm / yarn (running contract tests)"]
334
+ end
335
+
336
+ CLI --> Util
337
+ CLI --> FS
338
+ SvcAnal --> FS
339
+ SvcAnal --> Path
340
+ SvcAgent --> ExternalAgents
341
+ SvcInt --> Proc
342
+ SvcInt --> GraphifyCli
343
+ SvcInt --> ClaudeCli
344
+ SvcInt --> SkillsCli
345
+ SvcInt --> NodeExe
346
+ SvcVer --> Git
347
+ SvcVer --> ProjectNPM
348
+ Sec --> Crypto
349
+ Sec --> Path
350
+ Sec --> FS
351
+ ```
352
+
353
+ ---
354
+
355
+ *Continue to [Chapter 3: Tools and Technologies](./03-tools-and-technologies.md) for the complete inventory of all libraries, tools, and integrations.*
356
+
@@ -0,0 +1,112 @@
1
+ # Chapter 3: Tools & Technologies
2
+
3
+ > **An exhaustive, evidence-backed inventory of every technology, library, framework, tool, and integration used by DevWorkspace.**
4
+
5
+ ---
6
+
7
+ ## 1. Runtime Technology Stack
8
+
9
+ DevWorkspace is intentionally engineered with **zero external production runtime dependencies**:
10
+
11
+ ```json
12
+ // package.json
13
+ "dependencies": {}
14
+ ```
15
+
16
+ Every runtime capability—from CLI parsing to atomic filesystem writing, child process execution, and cryptographic hashing—is implemented using the **Node.js 20+ standard library**.
17
+
18
+ ### Complete Runtime Inventory Table
19
+
20
+ | Name | Category | Purpose in DevWorkspace | Responsibility | Input | Output | Integration / Callers | Execution | Status | Evidence |
21
+ |---|---|---|---|---|---|---|---|---|---|
22
+ | **Node.js (v20+)** | Runtime Platform | Execution environment | Executes JavaScript modules and provides system APIs | TS compiled JS files | Process execution | Entire application | Host machine OS | Verified | `package.json` (`engines.node: ">=20.11"`) |
23
+ | **`node:util` (`parseArgs`)** | Standard Library | CLI Argument Parsing | Parses flags (`--json`, `--cwd`, `--agent`) and positional arguments | `process.argv` string array | Typed `values` and `positionals` | `src/cli/args.ts` | On CLI startup | Verified | `src/cli/args.ts#L1` |
24
+ | **`node:fs/promises`** | Standard Library | Filesystem Operations | Async reads, directory creation, file stat, and unlinking | File paths, buffers | Text, metadata, void | `src/utils/fs.ts`, `src/core/workspace.ts` | Throughout all commands | Verified | `src/utils/fs.ts#L1` |
25
+ | **`node:path`** | Standard Library | Path Manipulation | Resolves, normalizes, and compares filesystem paths | Path segments | Canonical path strings | `src/utils/paths.ts`, `src/security/files.ts` | Continuous | Verified | `src/utils/paths.ts#L1` |
26
+ | **`node:child_process` (`spawnSync`)** | Standard Library | Subprocess Execution | Executes external tools (`git`, `npm`, `graphify`, `claude`) | Command string, args array, environment | Exit code, stdout, stderr | `src/utils/proc.ts`, `src/integrations/exec.ts` | During diagnostics, testing, setup | Verified | `src/utils/proc.ts#L1` |
27
+ | **`node:crypto`** | Standard Library | Cryptographic Hashing | Generates SHA-256 file fingerprints and unique task IDs | File buffers, strings | Hex digests, UUIDs | `src/utils/fs.ts`, `src/tasks/task.ts` | During facts loading, task creation | Verified | `src/utils/fs.ts#L2` |
28
+ | **`node:os`** | Standard Library | OS Abstraction | Resolves home directory, temp directories, and platform | System info | Paths (`tmpdir()`, `homedir()`) | `src/utils/paths.ts`, `src/integrations/manager.ts` | During path resolution | Verified | `src/integrations/manager.ts#L3` |
29
+ | **`node:process`** | Standard Library | Process Lifecycle | Handles signals (`SIGINT`, `SIGTERM`), exit codes, and environment | OS signals, env vars | Exit code, cleanup execution | `src/cli/main.ts`, `src/cli/run.ts` | On startup and exit | Verified | `src/cli/main.ts#L7` |
30
+
31
+ ---
32
+
33
+ ## 2. Build & Development Tools
34
+
35
+ The development and validation toolchain enforces strict code quality, type safety, and 90%+ test coverage.
36
+
37
+ | Name | Category | Purpose in Project | Responsibility | Configuration Source | Status | Evidence |
38
+ |---|---|---|---|---|---|---|
39
+ | **TypeScript (v6.0)** | Compiler / Type Checker | Type safety & compilation | Compiles TypeScript in `src/` to ES modules in `dist/` | `tsconfig.json`, `tsconfig.build.json` | Verified | `package.json#L66`, `scripts/clean.mjs` |
40
+ | **ESLint (v10.12)** | Static Analysis / Linter | Code quality enforcement | Detects syntax issues, unused variables, and style violations | `eslint.config.js` | Verified | `package.json#L65`, `npm run lint` |
41
+ | **Vitest (v5.0)** | Test Runner | Unit, Integration, & E2E Testing | Runs 778 tests across 31 test suites with mock runners | `vitest.config.ts` | Verified | `package.json#L68`, `npm test` |
42
+ | **`@vitest/coverage-v8`** | Code Coverage | Coverage threshold gate | Measures statement, branch, function, and line coverage | `vitest.config.ts` (`coverage` thresholds: 90%) | Verified | `package.json#L64`, `npm run coverage` |
43
+ | **Release Check Script** | Internal Tool | Pre-release gate | Enforces clean Git tree, SemVer tag, changelog, and zero TODO/FIXME markers | `scripts/release-check.mjs` | Verified | `scripts/release-check.mjs` |
44
+ | **Smoke Test Script** | Internal Tool | End-to-end packaging test | Packs npm tarball, installs in clean temp dirs, runs real CLI commands | `scripts/smoke.mjs` | Verified | `scripts/smoke.mjs` |
45
+
46
+ ---
47
+
48
+ ## 3. Coordinated External Tools & Coding Agents
49
+
50
+ DevWorkspace coordinates external tools and coding agents through clean, documented boundaries:
51
+
52
+ ### A. Coding Agent Instruction Targets
53
+
54
+ | Tool Name | Type | How DevWorkspace Integrates With It | Managed Files | Verified Working | Evidence |
55
+ |---|---|---|---|---|---|
56
+ | **Claude Code** | AI Coding Agent (CLI/Desktop) | Injects managed section into project instructions and generates custom task routing skill | `CLAUDE.md`, `.claude/skills/devworkspace/SKILL.md` | Yes | `src/agents/claude/adapter.ts` |
57
+ | **OpenAI Codex** | AI Coding Agent | Generates repository instructions adhering to open agent standards | `AGENTS.md` | Yes | `src/agents/codex/adapter.ts` |
58
+ | **Google Antigravity** | AI Coding Agent / IDE | Reads standard repository agent instructions | `AGENTS.md` | Yes | `src/agents/codex/adapter.ts` |
59
+ | **Cursor** | AI Coding IDE | Writes project rules with YAML frontmatter `alwaysApply: true` | `.cursor/rules/devworkspace.mdc` (fallback: `.cursorrules`) | Yes | `src/agents/cursor/adapter.ts` |
60
+ | **GitHub Copilot** | AI Coding Agent | Writes repository instruction file for Copilot in VS Code / GitHub | `.github/copilot-instructions.md` | Yes | `src/agents/copilot/adapter.ts` |
61
+
62
+ ### B. External Engineering Tools (Observed / Managed)
63
+
64
+ | Tool Name | Package Source | Purpose in Ecosystem | DevWorkspace Integration Level | Status | Evidence |
65
+ |---|---|---|---|---|---|
66
+ | **Git** | CLI (`git`) | Version control & status tracking | Reads branch, HEAD commit, uncommitted diffs, and tracked files. Never runs destructive commands (`reset --hard`, `clean -fd`). | Core requirement for safety gates | `src/git/git.ts` |
67
+ | **Graphify** | PyPI (`graphifyy`), binary `graphify` | Structural knowledge graph of code | DevWorkspace inspects executable on PATH, checks version, and coordinates project skill installation (`graphify install --project`). DevWorkspace **does not build the graph itself** (graph building uses an LLM). | Optional / Recommended | `src/integrations/adapters/graphify.ts` |
68
+ | **Agent Skills** | GitHub: `addyosmani/agent-skills` | Engineering methodology slash commands (`/spec`, `/plan`, `/test`, `/review`, `/ship`) | Inspects native plugin in Claude Code (`claude plugin list`) or portable skills installed via `npx skills add`. | Optional / Recommended | `src/integrations/adapters/agent-skills.ts` |
69
+ | **Ponytail** | GitHub: `DietrichGebert/ponytail` | Code complexity and diff review (`/ponytail-review`, `/ponytail-audit`) | Inspects native plugin or portable skills. Verifies that `node` is on PATH because Ponytail lifecycle hooks require Node.js. | Optional / Recommended | `src/integrations/adapters/ponytail.ts` |
70
+ | **OmniRoute** | GitHub: `diegosouzapw/OmniRoute` | LLM model routing proxy | **Observed only**. DevWorkspace detects if `omniroute` is on PATH, but never installs it, never calls it, and never requires API keys. | Observed (Unused) | `src/integrations/adapters/omniroute.ts` |
71
+
72
+ ---
73
+
74
+ ## 4. Deep Component Analysis: Why Each Tool Exists & Impact If Removed
75
+
76
+ ### 1. `node:util (parseArgs)`
77
+ - **Why it exists**: Provides strict, type-safe command-line argument parsing without needing heavy third-party libraries like `yargs`, `commander`, or `meow`.
78
+ - **What happens if removed**: Argument parsing would break, or DevWorkspace would need to pull in an external dependency with hundreds of transitive dependencies, violating its zero-dependency invariant.
79
+
80
+ ### 2. `node:crypto (createHash)`
81
+ - **Why it exists**: Computes SHA-256 hashes of repository source files and package manifests to detect when cached facts become `STALE`. Also generates deterministic task IDs (`T-YYYYMMDD-xxxx`).
82
+ - **What happens if removed**: Staleness detection would have to rely on filesystem timestamps (`mtime`), which are notoriously unreliable across Git checkouts and CI environments.
83
+
84
+ ### 3. Git Integration (`src/git/git.ts`)
85
+ - **Why it exists**: Detects uncommitted user work, captures baseline fingerprints at task start, and verifies whether credential files are accidentally tracked by Git.
86
+ - **What happens if removed**: DevWorkspace still functions in non-Git folders, but cannot warn developers before running actions, cannot enforce baseline test comparison, and cannot attest that user work was untouched.
87
+
88
+ ### 4. Graphify Adapter (`src/integrations/adapters/graphify.ts`)
89
+ - **Why it exists**: Knowledge graphs represent high-level architectural relationships between files, classes, and dependencies better than raw file dumps. DevWorkspace verifies that Graphify's skill is properly wired into the agent's environment.
90
+ - **What happens if removed**: Coding agents would lack code-graph structural navigation and would rely entirely on text search (grep/glob). DevWorkspace core functionality would remain intact.
91
+
92
+ ### 5. Multi-Agent Adapters (`src/agents/`)
93
+ - **Why it exists**: Prevents vendor lock-in to Claude Code. Allows teams using Cursor, Copilot, Codex, and Antigravity to share the exact same project facts, testing contracts, and verification rules.
94
+ - **What happens if removed**: DevWorkspace would only work with Claude Code, severely limiting adoption in multi-agent engineering workflows.
95
+
96
+ ---
97
+
98
+ ## 5. Discrepancy & Gap Analysis
99
+
100
+ Based on an exhaustive scan of the codebase vs documentation:
101
+
102
+ | Documented Feature / Claim | Actual Implementation Status in Code | Notes & Evidence |
103
+ |---|---|---|
104
+ | **OmniRoute integration** | **Observed only (not executed)** | `src/integrations/adapters/omniroute.ts#L12` explicitly notes: `"Not used by DevWorkspace."` It inspects whether `omniroute` is on PATH for reporting, but never configures or invokes it. |
105
+ | **Automatic Graph Construction** | **Delegated to agent / user** | DevWorkspace does not build the code graph itself because graph construction requires an LLM. It verifies that the `graphify` CLI exists and reminds the user to run `/graphify .` inside Claude Code. |
106
+ | **Database Migrations Execution** | **Intentionally Blocked** | `src/verification/safety.ts#L84` explicitly blocks automatic execution of `migrations` or `db:migrate` scripts to protect live databases from unauthorized schema modifications. |
107
+ | **Production Dependencies** | **Strictly Zero** | No external runtime dependencies exist in `package.json`. |
108
+
109
+ ---
110
+
111
+ *Continue to [Chapter 4: Execution Flows](./04-execution-flows.md) for step-by-step traces of the CLI, analysis, skills, and task lifecycles.*
112
+