vibe-coding-master 0.6.21 → 0.6.23

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 (30) hide show
  1. package/README.md +37 -3
  2. package/dist/backend/adapters/filesystem.js +8 -0
  3. package/dist/backend/api/harness-routes.js +54 -0
  4. package/dist/backend/api/runtime-state-routes.js +6 -2
  5. package/dist/backend/cli/install-vcm-harness.js +1 -1
  6. package/dist/backend/server.js +16 -0
  7. package/dist/backend/services/app-settings-service.js +1 -0
  8. package/dist/backend/services/auto-memory-service.js +760 -0
  9. package/dist/backend/services/claude-hook-service.js +66 -0
  10. package/dist/backend/services/gate-review-service.js +4 -1
  11. package/dist/backend/services/harness-service.js +1 -1
  12. package/dist/backend/services/runtime-coordinator-service.js +34 -1
  13. package/dist/backend/services/session-service.js +3 -0
  14. package/dist/backend/templates/harness/architect-agent.js +68 -28
  15. package/dist/backend/templates/harness/claude-root.js +11 -7
  16. package/dist/backend/templates/harness/coder-agent.js +3 -0
  17. package/dist/backend/templates/harness/gate-review.js +20 -9
  18. package/dist/backend/templates/harness/harness-engineer-agent.js +32 -8
  19. package/dist/backend/templates/harness/project-coding-standards.js +5 -5
  20. package/dist/backend/templates/harness/project-manager-agent.js +33 -24
  21. package/dist/backend/templates/harness/role-memory.js +9 -0
  22. package/dist/backend/templates/harness/tester-agent.js +3 -0
  23. package/dist/backend/templates/harness/vcm-final-acceptance-skill.js +6 -5
  24. package/dist/shared/types/gate-review.js +2 -1
  25. package/dist/shared/types/memory.js +8 -0
  26. package/dist-frontend/assets/index-9V9COJZy.js +96 -0
  27. package/dist-frontend/assets/{index-DmSHDyiQ.css → index-C2QzumXk.css} +1 -1
  28. package/dist-frontend/index.html +2 -2
  29. package/package.json +1 -1
  30. package/dist-frontend/assets/index-DYBg_qYS.js +0 -96
@@ -97,6 +97,28 @@ export function createClaudeHookService(deps) {
97
97
  transcriptPath: stringOrUndefined(input.event.transcript_path),
98
98
  cwd: stringOrUndefined(input.event.cwd) ?? stringOrUndefined(input.event.new_cwd)
99
99
  });
100
+ const activeTask = deps.autoMemoryService
101
+ ? (await deps.taskService.listTasks(context.project.repoRoot))
102
+ .find((task) => task.cleanupStatus !== "cleaned")
103
+ : undefined;
104
+ const memoryHandled = activeTask
105
+ ? await deps.autoMemoryService?.handleHarnessEngineerHook({
106
+ baseRepoRoot: context.project.repoRoot,
107
+ taskRepoRoot: getTaskRuntimeRepoRoot(activeTask),
108
+ taskSlug: activeTask.taskSlug,
109
+ eventName
110
+ })
111
+ : false;
112
+ if (memoryHandled) {
113
+ return {
114
+ ok: true,
115
+ eventName,
116
+ taskSlug: activeTask?.taskSlug ?? input.taskSlug,
117
+ role: input.role,
118
+ sessionUpdated: Boolean(session),
119
+ dispatchedCount: 0
120
+ };
121
+ }
100
122
  await deps.harnessService?.recordHarnessBootstrapHook(context.project.repoRoot, {
101
123
  eventName,
102
124
  sessionId: session?.id,
@@ -131,6 +153,10 @@ export function createClaudeHookService(deps) {
131
153
  throwUnsupportedEvent(eventName);
132
154
  }
133
155
  const context = await getHookContext(input);
156
+ const memoryResult = await processAutoMemoryRoleHook(input, context, eventName);
157
+ if (memoryResult) {
158
+ return memoryResult;
159
+ }
134
160
  const boundToTask = await isHookSessionBoundToTask(context, input.role);
135
161
  if (boundToTask) {
136
162
  deps.jobGuard?.notePromptSubmitted({
@@ -194,6 +220,10 @@ export function createClaudeHookService(deps) {
194
220
  throwUnsupportedEvent(eventName);
195
221
  }
196
222
  const context = await getHookContext(input);
223
+ const memoryResult = await processAutoMemoryRoleHook(input, context, eventName);
224
+ if (memoryResult) {
225
+ return memoryResult;
226
+ }
197
227
  await clearStopFailureRecoveryState(context, input.role);
198
228
  if (options.allowBlock && deps.jobGuard) {
199
229
  const verdict = await deps.jobGuard.evaluateStop({
@@ -228,6 +258,10 @@ export function createClaudeHookService(deps) {
228
258
  throwUnsupportedEvent(eventName);
229
259
  }
230
260
  const context = await getHookContext(input);
261
+ const memoryResult = await processAutoMemoryRoleHook(input, context, eventName);
262
+ if (memoryResult) {
263
+ return memoryResult;
264
+ }
231
265
  const routeDispatchInput = createRouteDispatchInput(input, context);
232
266
  const pending = await deps.messageService.listPendingRouteFiles(routeDispatchInput);
233
267
  const hasCompletionEvidence = pending.some((routeFile) => routeFile.fromRole === input.role);
@@ -284,6 +318,10 @@ export function createClaudeHookService(deps) {
284
318
  throwUnsupportedEvent(eventName);
285
319
  }
286
320
  const context = await getHookContext(input);
321
+ const memoryResult = await processAutoMemoryRoleHook(input, context, eventName);
322
+ if (memoryResult) {
323
+ return memoryResult;
324
+ }
287
325
  const session = await deps.sessionService.recordClaudeHookEvent(context.project.repoRoot, {
288
326
  taskSlug: context.taskSlug,
289
327
  role: input.role,
@@ -380,6 +418,34 @@ export function createClaudeHookService(deps) {
380
418
  dispatchedCount: dispatched.filter((result) => result.delivered).length
381
419
  };
382
420
  }
421
+ async function processAutoMemoryRoleHook(input, context, eventName) {
422
+ if (!deps.autoMemoryService || !(await deps.autoMemoryService.isRoleMemoryTurn(context.taskRepoRoot, input.role))) {
423
+ return undefined;
424
+ }
425
+ const session = await deps.sessionService.recordClaudeHookEvent(context.project.repoRoot, {
426
+ taskSlug: context.taskSlug,
427
+ role: input.role,
428
+ eventName,
429
+ claudeSessionId: stringOrUndefined(input.event.session_id),
430
+ transcriptPath: stringOrUndefined(input.event.transcript_path),
431
+ cwd: stringOrUndefined(input.event.cwd) ?? stringOrUndefined(input.event.new_cwd)
432
+ });
433
+ await deps.autoMemoryService.handleRoleHook({
434
+ baseRepoRoot: context.project.repoRoot,
435
+ taskRepoRoot: context.taskRepoRoot,
436
+ taskSlug: context.taskSlug,
437
+ role: input.role,
438
+ eventName
439
+ });
440
+ return {
441
+ ok: true,
442
+ eventName,
443
+ taskSlug: context.taskSlug,
444
+ role: input.role,
445
+ sessionUpdated: Boolean(session),
446
+ dispatchedCount: 0
447
+ };
448
+ }
383
449
  function createRouteDispatchInput(input, context, stoppedRole) {
384
450
  return {
385
451
  repoRoot: context.project.repoRoot,
@@ -30,6 +30,9 @@ const CODE_DIFF_SOURCE_ARTIFACTS = {
30
30
  ],
31
31
  "architect-debug": [
32
32
  ".ai/vcm/handoffs/role-commands/architect.md"
33
+ ],
34
+ "architect-diagnosis": [
35
+ ".ai/vcm/handoffs/architecture-diagnosis.md"
33
36
  ]
34
37
  };
35
38
  const CORE_INPUT_ARTIFACTS = {
@@ -94,7 +97,7 @@ export function createGateReviewService(deps) {
94
97
  return { status: "running", gate, record, message: "Gate review is already running." };
95
98
  }
96
99
  if (gate === "code-diff" && !codeDiffSource) {
97
- const message = "code-diff requires --source coder or --source architect-debug.";
100
+ const message = "code-diff requires --source coder, --source architect-debug, or --source architect-diagnosis.";
98
101
  index = applyGateState(index, gate, {
99
102
  status: "failed",
100
103
  decision: undefined,
@@ -106,7 +106,7 @@ const HARNESS_FILES = [
106
106
  kind: "skill-vcm-final-acceptance",
107
107
  path: ".claude/skills/vcm-final-acceptance/SKILL.md",
108
108
  title: "VCM Final Acceptance Skill",
109
- frontmatter: renderSkillFrontmatter("vcm-final-acceptance", "Use when project-manager is ready to close a complete VCM code-change flow."),
109
+ frontmatter: renderSkillFrontmatter("vcm-final-acceptance", "Use when project-manager is ready to close a complete VCM code-delivery flow."),
110
110
  ownership: "whole-file",
111
111
  renderRules: renderVcmFinalAcceptanceSkillRules
112
112
  },
@@ -55,8 +55,12 @@ export function createRuntimeCoordinatorService(deps) {
55
55
  else {
56
56
  await deps.translationService.stopTask(taskRepoRoot, activeTask.taskSlug).catch(() => undefined);
57
57
  }
58
+ await reconcileAutoMemory(repoRoot, activeTask);
58
59
  if (preferences.autoTaskHarnessReviewEnabled) {
59
- await maybeStartTaskHarnessRetrospective(repoRoot, activeTask);
60
+ const memoryReadiness = await getTaskRetrospectiveMemoryReadiness(repoRoot, activeTask);
61
+ if (memoryReadiness.ready) {
62
+ await maybeStartTaskHarnessRetrospective(repoRoot, activeTask);
63
+ }
60
64
  }
61
65
  return { activeTask, gatewayStatus };
62
66
  });
@@ -159,4 +163,33 @@ export function createRuntimeCoordinatorService(deps) {
159
163
  throw error;
160
164
  }
161
165
  }
166
+ async function reconcileAutoMemory(repoRoot, task) {
167
+ const stateRoot = await deps.getStateRoot(repoRoot);
168
+ const taskRepoRoot = getTaskRuntimeRepoRoot(task);
169
+ const roundState = await deps.roundService.getSessionRoundState({
170
+ repoRoot,
171
+ stateRepoRoot: taskRepoRoot,
172
+ stateRoot,
173
+ taskSlug: task.taskSlug
174
+ });
175
+ return deps.autoMemoryService.reconcileTask({
176
+ baseRepoRoot: repoRoot,
177
+ taskRepoRoot,
178
+ taskSlug: task.taskSlug,
179
+ handoffDir: task.handoffDir,
180
+ roundReady: roundState.status === "stopped"
181
+ && Boolean(roundState.roundId)
182
+ && roundState.roleRecovery?.status !== "failed"
183
+ });
184
+ }
185
+ async function getTaskRetrospectiveMemoryReadiness(repoRoot, task) {
186
+ const taskRepoRoot = getTaskRuntimeRepoRoot(task);
187
+ return deps.autoMemoryService.getTaskRetrospectiveReadiness({
188
+ baseRepoRoot: repoRoot,
189
+ taskRepoRoot,
190
+ taskSlug: task.taskSlug,
191
+ handoffDir: task.handoffDir,
192
+ roundReady: true
193
+ });
194
+ }
162
195
  }
@@ -3,6 +3,7 @@ import { VCM_ROLE_NAMES, isDispatchableRole } from "../../shared/constants.js";
3
3
  import { VcmError } from "../errors.js";
4
4
  import { resolveRepoPath } from "../adapters/filesystem.js";
5
5
  import { submitTerminalInput } from "../runtime/terminal-submit.js";
6
+ import { ensureTaskMemorySnapshot } from "./auto-memory-service.js";
6
7
  import { claudeTranscriptPath } from "./claude-transcript-service.js";
7
8
  import { readHarnessRevisionState } from "./harness-revision.js";
8
9
  import { getTaskRuntimeRepoRoot } from "./task-service.js";
@@ -49,6 +50,7 @@ export function createSessionService(deps) {
49
50
  const config = await deps.projectService.loadConfig(repoRoot);
50
51
  const task = await deps.taskService.loadTask(repoRoot, taskSlug);
51
52
  const taskRepoRoot = getTaskRuntimeRepoRoot(task);
53
+ await ensureTaskMemorySnapshot(deps.fs, repoRoot, taskRepoRoot);
52
54
  const paths = deps.artifactService.getHandoffPaths(taskRepoRoot, task.handoffDir);
53
55
  const persisted = await loadPersistedRoleRecordForRole(deps.fs, repoRoot, taskRepoRoot, config.stateRoot, taskSlug, role);
54
56
  const permissionMode = normalizeClaudePermissionMode(input.permissionMode ?? persisted?.permissionMode);
@@ -235,6 +237,7 @@ export function createSessionService(deps) {
235
237
  }
236
238
  async function launchProjectHarnessEngineerSession(repoRoot, input, launchMode) {
237
239
  const taskContext = await resolveProjectToolTaskContext(repoRoot, input, "Harness Engineer");
240
+ await ensureTaskMemorySnapshot(deps.fs, repoRoot, taskContext.taskRepoRoot);
238
241
  const live = toRoleSessionRecordView(getRegisteredProjectHarnessEngineerSession(deps.registry, deps.runtime), deps.runtime);
239
242
  if (live && live.status === "running") {
240
243
  return withHarnessRevisionView(repoRoot, await migrateRunningProjectToolSessionCwd(repoRoot, live, taskContext.taskRepoRoot));
@@ -1,7 +1,10 @@
1
+ import { renderRoleMemoryRules } from "./role-memory.js";
1
2
  export function renderArchitectHarnessRules() {
2
3
  return `
3
4
  ## VCM Architect Rules
4
5
 
6
+ ${renderRoleMemoryRules("architect")}
7
+
5
8
  ### Role Scope
6
9
 
7
10
  - Own technical analysis, architecture planning, module boundaries, file-level responsibilities, cross-file callable surfaces, public contracts, verifiable behavior, implementation boundaries within the accepted scope, behavior/contract proof points, risks, and architect-owned replan decisions.
@@ -9,10 +12,10 @@ export function renderArchitectHarnessRules() {
9
12
  - Own \`.ai/vcm/handoffs/known-issues.md\` as its only writer: record unresolved findings reported by other roles there. Own \`docs/known-issues.md\` promotion and durable issue updates.
10
13
  - Own architecture docs sync across \`docs/ARCHITECTURE.md\` and affected \`<module>/ARCHITECTURE.md\` files.
11
14
  - Own post-task module architecture doc maintenance for every module touched by accepted code commits.
12
- - Outside Debug Mode, do not implement production code.
15
+ - Outside Debug Mode and Architecture Diagnosis Mode, do not implement production code.
13
16
  - Do not analyze existing test-case adequacy; tester owns independent test design, test adequacy, and validation confidence.
14
17
  - In architecture planning, do not design test cases, coverage matrices, validation levels, commands, or final validation strategy.
15
- - In Debug Mode, writing baseline unit tests for changed code and running targeted L1/L2 checks to verify the fix are part of the implementation duty; tester still owns final validation.
18
+ - In Debug Mode and Architecture Diagnosis Mode, writing baseline unit tests for changed code and running targeted L1/L2/L3 checks to verify the fix are part of the implementation duty; tester still owns final validation.
16
19
  - Do not make product priority or approval decisions; route those questions back to project-manager.
17
20
 
18
21
  ### Planning Inputs
@@ -69,13 +72,14 @@ export function renderArchitectHarnessRules() {
69
72
  ### Debug Mode
70
73
 
71
74
  - Project-manager may route bugs, failing tests, build/runtime failures, or unclear defects directly to architect Debug Mode.
72
- - Architect may read source/tests, edit code, add temporary diagnostics, write focused verification, and run tests until root cause is known.
73
- - Architect may finish the fix directly only if the fix stays within the accepted task scope, addresses the confirmed root cause, adds no new module, and adds no new public or cross-file callable surface.
75
+ - Architect may read source/tests, edit code, and run focused diagnostics until root cause is known. Temporary logs, instrumentation, assertions, or diagnostic code may be added to identify and confirm the root cause.
76
+ - Once the root cause is confirmed, architect owns the technical change boundary for the fix. Architect may modify production code and tests in any existing module, add or change cross-file callable surfaces, and update their callers, contracts, and tests. No pre-approved module or file list limits Debug Mode implementation.
74
77
  - When editing production code or tests in Debug Mode, read and follow \`docs/CODING_STANDARDS.md\`.
75
78
  - If the Debug Mode fix changes callable-unit behavior, add or update baseline tests required by \`docs/CODING_STANDARDS.md\` when the project has an available test path. If not, report the concrete blocker.
76
- - Remove temporary diagnostics before completion.
77
- - If the fix exceeds those limits, return a normal architecture plan with root cause, evidence, and affected scope.
79
+ - Remove all temporary diagnostics before completion.
80
+ - If the fix requires a new module or new external public surface, return a normal architecture plan with root cause, evidence, and affected scope.
78
81
  - Architect-run validation in Debug Mode is diagnostic evidence, not final acceptance.
82
+ - Architect may run targeted L1/L2/L3 checks for the affected behavior. Tester still owns full and final validation.
79
83
  - Before handing off an architect-completed Debug Mode fix, run the smallest relevant L0 fast checks for the touched files or changed modules: format, lint, typecheck, boundary, dependency, or project-defined equivalents. If a check cannot run, report the exact reason.
80
84
  - If the Debug Mode fix changes module structure, source/test file lists, public APIs, routes, exports, re-exports, or other externally consumed surface, run \`.ai/tools/generate-module-index\` / \`.ai/tools/generate-public-surface\` or their \`--check\` mode as applicable.
81
85
  - After an architect-completed Debug Mode fix, report to project-manager so PM can route tester for independent final validation before the Debug branch continues.
@@ -84,37 +88,73 @@ export function renderArchitectHarnessRules() {
84
88
 
85
89
  ### Architecture Diagnosis Mode
86
90
 
87
- In Architecture Diagnosis Mode, treat the current failure as a signal that the architecture may be wrong or incomplete. Do not assume the existing implementation or the current plan is correct just because it exists.
91
+ Architecture Diagnosis Mode is an upgraded Debug Mode. Architect owns architecture reconstruction, diagnosis, implementation, diagnostic validation, and commit completion.
92
+
93
+ Do not diagnose from session memory. Re-read every document and source file used as evidence from the current task worktree during this Diagnosis run.
94
+
95
+ Do not assume existing code or comments are correct. Read the implementation to determine actual behavior, verify comments against code and runtime evidence, and record contradictions instead of treating comments as authority.
96
+
97
+ Before choosing or implementing a fix:
98
+
99
+ - Define the affected feature or module and identify every observable entry point for the failing behavior.
100
+ - Read the relevant project and module architecture documents, public contracts, generated context, tests, handoff artifacts, and runtime evidence.
101
+ - Starting from each entry point, read the complete implementation of every reachable project-owned function, method, handler, callback, or command.
102
+ - Recursively follow every project-owned call until no unresolved project-owned callee remains. Read each symbol once and record recursive or cyclic calls.
103
+ - Follow indirect execution through callbacks, events, hooks, queues, routes, registries, dependency injection, dynamic dispatch, frontend/backend requests, and external-process callbacks.
104
+ - For every state, durable artifact, cache, queue item, database record, or runtime object on the behavior path, find and read all project-owned readers, writers, creators, completion handlers, failure handlers, cancellation handlers, retry handlers, and recovery handlers.
105
+ - For every cross-file or public callable surface on the behavior path, find and read its project-owned callers and consumers.
106
+ - Continue across module boundaries whenever the call path, state ownership, lifecycle, public contract, dependency, or failure/recovery path crosses them.
107
+ - Stop traversal only at standard-library, third-party, external-service, vendor, or generated-code boundaries. Record the boundary contract, inputs, outputs, errors, and side effects.
108
+
109
+ Maintain a \`Code Reading Closure\` in \`.ai/vcm/handoffs/architecture-diagnosis.md\`:
110
+
111
+ | Symbol | File | Called By | Calls | State Read/Written | Side Effects | Status |
112
+ |---|---|---|---|---|---|---|
113
+
114
+ \`Status\` must be \`read\`, \`external-boundary\`, or \`generated-boundary\`.
115
+
116
+ The code-reading phase is complete only when:
117
+
118
+ - every identified entry point has been read
119
+ - every reachable project-owned callee has been read
120
+ - every indirect callback, event, hook, queue, route, and dynamic dispatch path has been resolved
121
+ - every relevant state reader and writer has been read
122
+ - every relevant cross-file surface caller and consumer has been read
123
+ - no unresolved project-owned symbol remains
88
124
 
89
- First define the diagnosis boundary: the affected feature or module. The boundary must include the full failing behavior path, not only the file, function, or test where the failure appears. Do not expand to unrelated modules unless the data flow, lifecycle, public contract, or dependency path crosses that boundary.
125
+ Do not diagnose the root cause or choose a fix before the Code Reading Closure is complete.
90
126
 
91
- Within that boundary, read enough code, tests, durable docs, generated context, and handoff artifacts to reconstruct the current architecture. Before judging the failure, describe how the feature is supposed to work, how it actually works in code, and where the two differ.
127
+ After completing the code-reading closure, reconstruct and analyze:
92
128
 
93
- Analyze the problem from these angles:
129
+ - **Ownership:** owners of state, decisions, lifecycle transitions, side effects, and durable artifacts.
130
+ - **Data Flow:** inputs, transformations, persistence, consumers, source of truth, stale reads, duplicate derivation, and race windows.
131
+ - **Lifecycle:** start, active, completion, failure, cancellation, retry, restart, and recovery.
132
+ - **Boundaries:** module, service, frontend/backend, persistence, role, and tool contracts.
133
+ - **Invariants:** conditions that must always hold and where the current implementation violates them.
134
+ - **Failure Model:** failure, interruption, duplicate events, out-of-order events, partial output, retry, and recovery behavior.
94
135
 
95
- - **Ownership:** Identify who should own the failing state, decision, lifecycle, side effect, or durable artifact. Check whether ownership is duplicated, split across layers, inferred independently, or placed in the wrong component.
96
- - **Data Flow:** Trace where the relevant data enters the system, how it moves, where it is transformed, where it is persisted, and who consumes it. Look for hidden coupling, duplicate derivation, stale reads, race windows, and unclear source of truth.
97
- - **Lifecycle:** Identify the lifecycle being modeled, such as task, round, turn, session, queue item, hook event, job, file artifact, UI view, gateway message, or validation run. Check whether start, active, completion, failure, cancellation, retry, restart, and recovery states are explicitly owned and consistently updated.
98
- - **Boundaries:** Check whether module, service, frontend/backend, role, tool, or persistence boundaries are clean. Look for business logic in the UI, backend logic duplicated in frontend state, role workflow rules embedded in low-level services, or services reaching across boundaries without a clear contract.
99
- - **Invariants:** State the architecture invariant that should always hold, then compare the current implementation against it.
100
- - **Failure Model:** Identify how the architecture should behave when the operation fails, is interrupted, retries, resumes, restarts, receives duplicate events, receives events out of order, or observes partial output. Avoid treating timeout, fallback, polling, or special-case branches as a substitute for a clear completion/failure model.
101
- - **Evidence:** Use code, docs, handoff artifacts, tests, logs, and generated context as evidence. Existing code is evidence, not authority. If the code contradicts the intended architecture, say so directly.
136
+ The diagnosis must explain why the previous Debug fix failed, which assumption behind that fix was wrong, and why another local patch based on the same assumption would fail again.
102
137
 
103
- Treat "local implementation bug" as an exception that must be proven. If the problem is local, explain why ownership, data flow, lifecycle, boundaries, invariants, and failure model still hold.
138
+ Treat \`local implementation bug\` as an exception. It may be concluded only when the Code Reading Closure proves that ownership, source of truth, data flow, lifecycle, boundaries, invariants, and failure/recovery behavior remain coherent, and the failure is traced to implementation that violates that architecture.
104
139
 
105
- Write \`.ai/vcm/handoffs/architecture-diagnosis.md\` for every Architecture Diagnosis Mode run before reporting back to project-manager. This file is the current diagnosis, not a log; replace stale content instead of appending history.
140
+ Small diff, minimum change, localized fix, or preserving the current implementation shape are not Architecture Diagnosis decision criteria.
106
141
 
107
- The diagnosis file must identify:
142
+ \`.ai/vcm/handoffs/architecture-diagnosis.md\` must contain:
108
143
 
109
- 1. The diagnosis boundary.
110
- 2. How the feature is supposed to work.
111
- 3. How it actually works in code.
112
- 4. Where the two differ.
113
- 5. Whether this is a proven local implementation bug or an architecture/plan problem.
114
- 6. If local, why the architecture still holds.
115
- 7. If architectural, what replacement architecture direction and bounded refactor scope should follow.
144
+ 1. \`Diagnosis Boundary\`
145
+ 2. \`Documents And Runtime Evidence\`
146
+ 3. \`Code Reading Closure\`
147
+ 4. \`Current Architecture\`
148
+ 5. \`Previous Debug Failure\`
149
+ 6. \`Failure Trace\`
150
+ 7. \`Architecture Assessment\`
151
+ 8. \`Required Architecture Direction\`
152
+ 9. \`Implementation And Validation\`
116
153
 
117
- Do not propose a code-level patch until the architecture diagnosis is complete.
154
+ - If PM explicitly routes an analysis-only Diagnosis task, stop after completing the diagnosis artifact and report the result.
155
+ - Otherwise, implement the complete fix directly after recording the diagnosis and required architecture direction. Architect may modify production code and tests in any module, create files or modules, add or change cross-file or public callable surfaces, and update callers, contracts, and generated context.
156
+ - Follow \`docs/CODING_STANDARDS.md\`, add or update baseline tests, run the relevant L0/L1/L2/L3 checks, remove all temporary diagnostics, and commit all Diagnosis implementation changes before reporting.
157
+ - Final disposition must be one of: \`analysis completed\`, \`diagnosis implementation completed\`, or \`user clarification required\`.
118
158
 
119
159
  ### Replan And Drift
120
160
 
@@ -1,5 +1,7 @@
1
1
  export function renderRootClaudeHarnessRules() {
2
- return `## VCM Start Here
2
+ return `@.ai/vcm/memory/shared.md
3
+
4
+ ## VCM Start Here
3
5
 
4
6
  - Use the durable project docs below as role-relevant project truth.
5
7
  - Read module-local \`CLAUDE.md\` before editing a subdirectory if one exists.
@@ -43,13 +45,15 @@ If a reusable harness problem is suspected, it is enough to record a concise fee
43
45
 
44
46
  - All standard workflow routes among project-manager, architect, coder, and tester are PM-hub routes. Project-manager starts and advances every flow; architect, coder, and tester report blockers, failures, conflicts, incomplete work, and findings back to project-manager.
45
47
  - Code changes use: \`project-manager -> architect -> coder -> tester -> architect docs sync -> project-manager final acceptance\`.
46
- - Debug work is a branch inside the code-change flow: \`project-manager -> architect Debug Mode -> tester -> architect docs sync when needed -> project-manager final acceptance\`.
48
+ - Debug Mode and Architecture Diagnosis Mode may be either the task's primary flow or a branch inside an active main flow.
49
+ - When either mode is entered while a main flow is active, project-manager suspends that flow, records its resume point, runs the mode through code-diff Gate Review and tester validation when code changes are produced, then returns to the recorded resume point. The branch does not run final acceptance.
50
+ - When a task begins with Debug Mode or Architecture Diagnosis Mode and produces code changes, that mode is the task's primary code-delivery flow and continues through code-diff Gate Review, tester validation, architect docs sync, and project-manager final acceptance.
51
+ - A primary Architecture Diagnosis flow that produces analysis only completes from the diagnosis result without final acceptance.
47
52
  - Docs-only changes use: \`project-manager -> architect -> project-manager completion\`.
48
53
  - Test-only or validation-only work uses: \`project-manager -> tester -> project-manager completion\`.
49
- - Architecture Diagnosis is a PM-triggered branch inside code/debug work: \`project-manager -> architect Architecture Diagnosis Mode -> project-manager route decision\`.
50
54
  - Gate Review is PM-triggered at its defined trigger points; the tool decides whether review is enabled or required.
51
- - Final acceptance closes only the complete code-change flow, including a completed Debug branch.
52
- - PR preparation starts only after the active delivery flow completes; code-change flow also requires final acceptance to pass.
55
+ - Final acceptance closes only a complete code-delivery flow; it never closes a Debug or Architecture Diagnosis branch inside another flow.
56
+ - PR preparation starts only after the active delivery flow completes; every complete code-delivery flow requires final acceptance to pass.
53
57
  - If docs/test/validation-only work reveals required code, architecture, public contract, dependency, durable-doc, or test-strategy changes, project-manager routes through the full code-change flow.
54
58
  - Detailed failure handling and route decisions belong to project-manager rules.
55
59
  - Keep role outputs under \`.ai/vcm/handoffs/\`.
@@ -75,8 +79,8 @@ If a reusable harness problem is suspected, it is enough to record a concise fee
75
79
 
76
80
  - L0 fast checks (default runner: coder): format, lint, typecheck, boundary, dependency, or other cheap project checks.
77
81
  - L1 baseline implementation checks (default runner: coder): changed behavior and direct regressions through project-defined unit tests.
78
- - L2 module / integration checks: targeted diagnostic L2 may run in Coder when explicitly assigned or in Architect Debug Mode; Tester owns full and final L2 validation.
79
- - L3 smoke E2E checks (default runner: tester): core user journeys or critical browser/API flows.
82
+ - L2 module / integration checks: targeted diagnostic L2 may run in Coder when explicitly assigned, Architect Debug Mode, or Architecture Diagnosis Mode; Tester owns full and final L2 validation.
83
+ - L3 smoke E2E checks: targeted diagnostic L3 may run in Architect Debug Mode or Architecture Diagnosis Mode; Tester owns full and final L3 validation for core user journeys or critical browser/API flows.
80
84
  - L4 full regression / release checks (default runner: tester; architect-owned release flow) are release-only unless explicitly requested.
81
85
 
82
86
  ## VCM Worktree Policy
@@ -1,7 +1,10 @@
1
+ import { renderRoleMemoryRules } from "./role-memory.js";
1
2
  export function renderCoderHarnessRules() {
2
3
  return `
3
4
  ## VCM Coder Rules
4
5
 
6
+ ${renderRoleMemoryRules("coder")}
7
+
5
8
  ### Role Scope
6
9
 
7
10
  - Own function-level implementation and baseline implementation tests inside the approved task scope, role message, and architecture plan.
@@ -1,8 +1,11 @@
1
+ import { renderRoleMemoryRules } from "./role-memory.js";
1
2
  export function renderGateReviewerAgentRules() {
2
3
  return `## Role
3
4
 
4
5
  You are VCM \`gate-reviewer\`.
5
6
 
7
+ ${renderRoleMemoryRules("gate-reviewer")}
8
+
6
9
  Review only the gate in the VCM prompt. Use the task and worktree paths named there. Project memory may orient you, but only current worktree evidence can decide the gate.
7
10
 
8
11
  Use only these decisions:
@@ -46,11 +49,18 @@ commit range named in the VCM prompt.
46
49
  Use the code source named in the VCM prompt. For \`coder\`, compare the commits
47
50
  against the approved architecture plan and coder completion evidence. For
48
51
  \`architect-debug\`, compare the commits against the current Architect route
49
- command. Apply project coding standards in both cases. Do not expand review to
50
- the whole task, whole branch, or PR.
51
-
52
- Check that the commits match their source evidence, have no unapproved
53
- surface/dependency/docs changes, no \`VCM:CODE\`, no task-process comments or task
52
+ command. For \`architect-diagnosis\`, compare the commits against
53
+ \`.ai/vcm/handoffs/architecture-diagnosis.md\`. Apply project coding standards
54
+ in all cases. Do not expand review to the whole task, whole branch, or PR.
55
+
56
+ For \`architect-diagnosis\`, verify that the commits implement the diagnosed
57
+ ownership, data flow, lifecycle, boundaries, invariants, and failure model.
58
+ Request changes when the implementation leaves the diagnosed architecture
59
+ problem in place, contradicts the required architecture direction, or only
60
+ adds a local workaround for the surface failure.
61
+
62
+ Check that the commits match their source evidence, account for
63
+ surface/dependency/docs changes, have no \`VCM:CODE\`, no task-process comments or task
54
64
  labels, no weakened tests or bypassed real behavior, and no unhandled fallible
55
65
  paths.
56
66
 
@@ -160,7 +170,7 @@ Use this skill at every project-manager Gate Review trigger point and whenever V
160
170
 
161
171
  - \`architecture-plan\`: after architect writes \`.ai/vcm/handoffs/architecture-plan.md\`, before coder dispatch.
162
172
  - \`validation-adequacy\`: after tester writes \`.ai/vcm/handoffs/test-report.md\`, before docs sync, final acceptance, or validation-only completion.
163
- - \`code-diff\`: after Coder returns \`Decision: ready_for_review\`, or after Architect Debug Mode completes a code fix, before PM routes to the next role or flow gate. Identify the source with \`--source coder\` or \`--source architect-debug\`.
173
+ - \`code-diff\`: after Coder returns \`Decision: ready_for_review\`, Architect Debug Mode completes a code fix, or Architecture Diagnosis Mode completes a code fix, before PM routes to Tester. Identify the source with \`--source coder\`, \`--source architect-debug\`, or \`--source architect-diagnosis\`.
164
174
 
165
175
  ## Request
166
176
 
@@ -168,7 +178,7 @@ Run this unconditionally at each trigger point (do not first check whether Gate
168
178
 
169
179
  \`\`\`sh
170
180
  .ai/tools/request-gate-review --gate <architecture-plan|validation-adequacy>
171
- .ai/tools/request-gate-review --gate code-diff --source <coder|architect-debug>
181
+ .ai/tools/request-gate-review --gate code-diff --source <coder|architect-debug|architect-diagnosis>
172
182
  \`\`\`
173
183
 
174
184
  Interpret the first output line:
@@ -206,7 +216,7 @@ from pathlib import Path
206
216
 
207
217
 
208
218
  GATES = ("architecture-plan", "validation-adequacy", "code-diff")
209
- CODE_DIFF_SOURCES = ("coder", "architect-debug")
219
+ CODE_DIFF_SOURCES = ("coder", "architect-debug", "architect-diagnosis")
210
220
  REPORTS = {
211
221
  "architecture-plan": ".ai/vcm/gate-reviews/architecture-plan-review.md",
212
222
  "validation-adequacy": ".ai/vcm/gate-reviews/validation-adequacy-review.md",
@@ -226,6 +236,7 @@ CODE_DIFF_SOURCE_ARTIFACTS = {
226
236
  ".ai/vcm/handoffs/coder-completion.md",
227
237
  ],
228
238
  "architect-debug": [".ai/vcm/handoffs/role-commands/architect.md"],
239
+ "architect-diagnosis": [".ai/vcm/handoffs/architecture-diagnosis.md"],
229
240
  }
230
241
  CORE_INPUT_ARTIFACTS = {
231
242
  "architecture-plan": ".ai/vcm/handoffs/architecture-plan.md",
@@ -621,7 +632,7 @@ def main() -> int:
621
632
  args = parser.parse_args()
622
633
 
623
634
  if args.gate == "code-diff" and not args.source:
624
- print_result("failed_to_start", gate=args.gate, reason="code-diff requires --source coder or --source architect-debug")
635
+ print_result("failed_to_start", gate=args.gate, reason="code-diff requires --source coder, --source architect-debug, or --source architect-diagnosis")
625
636
  return 2
626
637
  if args.gate != "code-diff" and args.source:
627
638
  print_result("failed_to_start", gate=args.gate, reason="--source is valid only for code-diff")
@@ -1,3 +1,4 @@
1
+ import { renderRoleMemoryRules } from "./role-memory.js";
1
2
  export function renderHarnessEngineerHarnessRules() {
2
3
  return `## Role
3
4
 
@@ -7,6 +8,8 @@ Maintain and improve this repository's VCM harness. Understand both VCM fixed
7
8
  harness rules and project-specific harness customization before proposing any
8
9
  change.
9
10
 
11
+ ${renderRoleMemoryRules("harness-engineer")}
12
+
10
13
  ## Scope
11
14
 
12
15
  You may inspect:
@@ -22,7 +25,8 @@ You may inspect:
22
25
  \`docs/known-issues.md\`
23
26
  - task evidence such as handoffs, route messages, commits, commit diffs,
24
27
  generated context, validation reports, Gate Review reports, final acceptance
25
- artifacts, and user corrections
28
+ artifacts, memory drafts and diffs under .ai/vcm/memory-review, current memory
29
+ under .ai/vcm/memory, and user corrections
26
30
 
27
31
  You are not part of the task workflow round state.
28
32
 
@@ -33,18 +37,21 @@ You are not part of the task workflow round state.
33
37
  - Bootstrap Apply Mode: when VCM explicitly asks for bootstrap apply work, make
34
38
  permitted bootstrap edits directly in the active task worktree and commit them
35
39
  yourself.
36
- - Retrospective Mode: analyze a completed task for reusable harness problems. Do
37
- not edit files.
40
+ - Retrospective Mode: analyze a completed task for reusable harness problems.
41
+ Do not edit harness files; proven repeated findings may update VCM memory.
42
+ - Memory Review Mode: review role memory drafts or proven retrospective memory
43
+ findings and write only the memory files assigned by VCM.
38
44
  - VCM Feedback Mode: draft VCM product, installer, UI, or fixed-template issue
39
45
  feedback. Do not submit without explicit in-session user authorization.
40
46
 
41
47
  ## Change Policy
42
48
 
43
- - Apply edits only in Bootstrap Apply Mode or when VCM explicitly asks you to
44
- apply an approved harness change.
49
+ - Apply edits only in Bootstrap Apply Mode, Memory Review Mode, or when VCM
50
+ explicitly asks you to apply an approved harness change.
45
51
  - When applying edits, work only in the active task worktree named by VCM. Do not
46
52
  edit the base repository root unless VCM explicitly says so.
47
- - In Proposal Mode and Retrospective Mode, do not edit files.
53
+ - In Proposal Mode, do not edit files. In Retrospective Mode, do not edit
54
+ harness files; only the memory exception above may write files.
48
55
  - Commit every applied harness change yourself before ending your turn.
49
56
  - Do not overwrite VCM fixed managed blocks.
50
57
  - Keep project-specific customization outside VCM managed blocks.
@@ -54,6 +61,22 @@ You are not part of the task workflow round state.
54
61
  validation recommendations with every proposal.
55
62
  - Do not edit production source code as part of harness maintenance.
56
63
 
64
+ ## Memory Management
65
+
66
+ - Own VCM-managed project memory under \`.ai/vcm/memory/**\`.
67
+ - During an Auto Memory review, verify role drafts against task evidence, merge
68
+ duplicates, remove stale entries, and keep role-specific knowledge in the
69
+ matching role memory file.
70
+ - Keep task narrative, temporary state, unverified conclusions, and harness
71
+ rules out of memory.
72
+ - A repeated problem confirmed by Task Harness Retrospective may become memory
73
+ without collecting new role drafts.
74
+ - For a direct user-requested memory correction, edit the current task
75
+ worktree's assigned memory file; VCM records and applies the change when the
76
+ turn stops.
77
+ - When VCM assigns review output paths, edit only those paths. VCM applies the
78
+ reviewed memory and records the diff.
79
+
57
80
  ## Task Harness Retrospective
58
81
 
59
82
  After a complete code-change flow passes Final Acceptance, you may be asked to
@@ -67,7 +90,8 @@ complete correctly.
67
90
  Inspect the active task worktree as needed. Useful evidence may include
68
91
  handoffs, route messages, commits, commit diffs, durable docs, generated
69
92
  context, validation reports, Gate Review reports, final acceptance artifacts,
70
- and user corrections during the task.
93
+ memory drafts, applied memory diffs, current memory, and user corrections during
94
+ the task.
71
95
 
72
96
  For each finding, decide whether it is:
73
97
 
@@ -79,7 +103,7 @@ Do not create new rules from weak evidence, one-off execution mistakes, or role
79
103
  behavior that existing harness rules already cover. If no reusable harness
80
104
  problem is proven, say so clearly.
81
105
 
82
- Do not edit files during retrospective analysis. Write a concise analysis with:
106
+ Do not edit harness files during retrospective analysis. Write a concise analysis with:
83
107
 
84
108
  - finding
85
109
  - evidence
@@ -5,19 +5,19 @@ Project-specific rules may be added outside the VCM managed block when they make
5
5
  ## Applies To
6
6
 
7
7
  - Coder and Coder Worker implementation.
8
- - Architect Debug Mode when it edits production code or tests.
8
+ - Architect Debug Mode and Architecture Diagnosis Mode when they edit production code or tests.
9
9
  - Tester changes to tests, fixtures, and test-only helpers, plus test-integrity review.
10
10
 
11
11
  ## Implementation Discipline
12
12
 
13
- - Follow the accepted task scope, role message, architecture plan, and scaffold when present.
14
- - Do not change file responsibilities, callable-surface signatures, visibility, exports, contracts, or architect-defined intent unless the approved plan allows it.
13
+ - Coder and Coder Worker follow the accepted task scope, role message, architecture plan, and scaffold. Architect Debug Mode and Architecture Diagnosis Mode follow their confirmed root cause and PM-routed evidence.
14
+ - Coder and Coder Worker must not change file responsibilities, callable-surface signatures, visibility, exports, contracts, or architect-defined intent unless the approved plan allows it. In Debug Mode or Architecture Diagnosis Mode, Architect may change file responsibilities and callable surfaces after confirming the root cause, and must update affected callers, contracts, and tests.
15
15
  - Complete assigned \`VCM:CODE\` placeholders and remove them before handoff.
16
16
  - Do not fake completion: no hardcoded success, disabled logic, swallowed errors, test-only shortcuts, or silent fallback that hides failure.
17
17
  - Implement behavior from the approved architecture, existing domain model, real inputs, and project runtime flow.
18
18
  - Do not derive logic from visible test fixtures, fixed sample values, snapshot text, or special branches that only satisfy known tests.
19
- - Keep the diff inside approved scope: no unrelated rewrites, drive-by refactors, renamed symbols, moved files, or formatting churn.
20
- - Preserve existing behavior unless the approved plan explicitly changes it.
19
+ - Coder and Coder Worker keep the diff inside the approved plan. In Debug Mode or Architecture Diagnosis Mode, Architect owns the technical change boundary after confirming the root cause.
20
+ - Preserve existing behavior unless the approved plan or a confirmed Debug/Diagnosis root cause changes it.
21
21
 
22
22
  ## Comments
23
23