azclaude-copilot 0.7.0 → 0.7.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.
@@ -9,7 +9,7 @@
9
9
  {
10
10
  "name": "azclaude",
11
11
  "description": "AZCLAUDE is a complete AI coding environment for Claude Code. It installs 40 commands, 10 auto-invoked skills, 15 specialized agents, 5 hooks, a real-time pipeline visualizer, and a persistent memory system — in one command.\n\nKey features:\n• Memory across sessions — goals.md + checkpoints injected automatically before every session\n• Self-improving loop — /reflect fixes stale CLAUDE.md rules, /reflexes learns from tool-use patterns, /evolve creates agents from git evidence\n• Autonomous copilot mode — /copilot runs a three-tier team (orchestrator → problem-architect → milestone-builder) across sessions until the product ships\n• Spec-driven workflow — /constitute writes project rules, /spec writes structured ACs, /analyze detects plan drift and ghost milestones, /blueprint traces every milestone to a spec\n• Security layer — 111-rule environment scan (/sentinel), pre-write secret blocking, pre-ship credential audit\n• Progressive levels 0–10 — start with CLAUDE.md, grow into multi-agent pipelines and self-evolving environments\n• Zero dependencies — no npm packages, no external APIs, no vector databases. Plain markdown files and Claude Code's native architecture.\n• Smart install — npx azclaude-copilot@latest auto-detects first install vs upgrade vs verify. Context-aware onboarding shows the right next command for your project state.\n\nExample use cases:\n• /setup — scan an existing project, detect stack + domain + scale, fill CLAUDE.md, generate project-specific skills and agents automatically\n• /copilot \"Build a compliance SaaS with trilingual support\" — walk away, come back to working code across multiple sessions\n• /sentinel — run a scored security audit (0–100, grade A–F) across hooks, permissions, MCP servers, agent configs, and secrets\n• /evolve — detect gaps in the environment, generate new skills and agents from git co-change evidence, report score delta (e.g. 42/100 → 68/100)\n• /constitute — write your project's constitution (non-negotiables, architectural commitments, definition of done) — gates all future AI actions\n• /analyze — cross-artifact consistency check: ghost milestones, spec vs. code drift, unplanned commits\n• /reflect — find stale, missing, or contradicting rules in CLAUDE.md and propose exact fixes\n• /debate \"REST vs GraphQL for this project\" — adversarial evidence-based decision with order-independent scoring, logged to decisions.md",
12
- "version": "0.7.0",
12
+ "version": "0.7.2",
13
13
  "source": {
14
14
  "source": "github",
15
15
  "repo": "haytamAroui/AZ-CLAUDE-COPILOT",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azclaude",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "AZCLAUDE is a complete AI coding environment for Claude Code. It installs 40 commands, 10 auto-invoked skills, 15 specialized agents, 5 hooks, a real-time pipeline visualizer, and a persistent memory system — in one command.\n\nKey features:\n• Memory across sessions — goals.md + checkpoints injected automatically before every session\n• Self-improving loop — /reflect fixes stale CLAUDE.md rules, /reflexes learns from tool-use patterns, /evolve creates agents from git evidence\n• Autonomous copilot mode — /copilot runs a three-tier team (orchestrator → problem-architect → milestone-builder) across sessions until the product ships\n• Spec-driven workflow — /constitute writes project rules, /spec writes structured ACs, /analyze detects plan drift and ghost milestones, /blueprint traces every milestone to a spec\n• Security layer — 111-rule environment scan (/sentinel), pre-write secret blocking, pre-ship credential audit\n• Progressive levels 0–10 — start with CLAUDE.md, grow into multi-agent pipelines and self-evolving environments\n• Zero dependencies — no npm packages, no external APIs, no vector databases. Plain markdown files and Claude Code's native architecture.\n• Smart install — npx azclaude-copilot@latest auto-detects first install vs upgrade vs verify. Context-aware onboarding shows the right next command for your project state.\n\nExample use cases:\n• /setup — scan an existing project, detect stack + domain + scale, fill CLAUDE.md, generate project-specific skills and agents automatically\n• /copilot \"Build a compliance SaaS with trilingual support\" — walk away, come back to working code across multiple sessions\n• /sentinel — run a scored security audit (0–100, grade A–F) across hooks, permissions, MCP servers, agent configs, and secrets\n• /evolve — detect gaps in the environment, generate new skills and agents from git co-change evidence, report score delta (e.g. 42/100 → 68/100)\n• /constitute — write your project's constitution (non-negotiables, architectural commitments, definition of done) — gates all future AI actions\n• /analyze — cross-artifact consistency check: ghost milestones, spec vs. code drift, unplanned commits\n• /reflect — find stale, missing, or contradicting rules in CLAUDE.md and propose exact fixes\n• /debate \"REST vs GraphQL for this project\" — adversarial evidence-based decision with order-independent scoring, logged to decisions.md",
5
5
  "author": {
6
6
  "name": "haytamAroui",
package/README.md CHANGED
@@ -637,11 +637,11 @@ AZCLAUDE is a lazy-loaded environment of 48 capability modules. It only loads wh
637
637
 
638
638
  ## Verified
639
639
 
640
- 1868 tests. Every template, command, capability, agent, hook, and CLI feature verified.
640
+ 1881 tests. Every template, command, capability, agent, hook, and CLI feature verified.
641
641
 
642
642
  ```bash
643
643
  bash tests/test-features.sh
644
- # Results: 1868 passed, 0 failed, 1868 total
644
+ # Results: 1881 passed, 0 failed, 1881 total
645
645
  ```
646
646
 
647
647
  ---
package/bin/cli.js CHANGED
@@ -144,8 +144,8 @@ function buildHookEntries(scriptsDir) {
144
144
  return {
145
145
  UserPromptSubmit: [{ matcher: '', hooks: [{ type: 'command', command: `"${nodeExe}" "${userPromptScript}"` }] }],
146
146
  Stop: [{ matcher: '', hooks: [{ type: 'command', command: `"${nodeExe}" "${stopScript}"` }] }],
147
- PreToolUse: [{ matcher: 'Write|Edit|MultiEdit', hooks: [{ type: 'command', command: `"${nodeExe}" "${preToolUseScript}"` }] }],
148
- PostToolUse: [{ matcher: 'Write|Edit|Read|Bash|Grep', hooks: [{ type: 'command', command: `"${nodeExe}" "${postToolUseScript}"` }] }],
147
+ PreToolUse: [{ matcher: '', hooks: [{ type: 'command', command: `"${nodeExe}" "${preToolUseScript}"` }] }],
148
+ PostToolUse: [{ matcher: '', hooks: [{ type: 'command', command: `"${nodeExe}" "${postToolUseScript}"` }] }],
149
149
  Notification: [{ matcher: '', hooks: [{ type: 'command', command: `"${nodeExe}" "${vizScript}"` }] }],
150
150
  SubagentStart: [{ matcher: '', hooks: [{ type: 'command', command: `"${nodeExe}" "${vizScript}"` }] }],
151
151
  SubagentStop: [{ matcher: '', hooks: [{ type: 'command', command: `"${nodeExe}" "${vizScript}"` }] }],
@@ -1146,7 +1146,10 @@ if (process.argv[2] === 'visualize') {
1146
1146
  console.error('Visualizer not installed. Run: npx azclaude-copilot');
1147
1147
  process.exit(1);
1148
1148
  }
1149
+ const settingsPath = path.join(process.cwd(), vizCfg, 'settings.local.json');
1150
+
1149
1151
  if (action === 'stop') {
1152
+ // 1. Kill server
1150
1153
  const pidFile = path.join(os.tmpdir(), '.azclaude-visualizer.pid');
1151
1154
  if (fs.existsSync(pidFile)) {
1152
1155
  const pid = parseInt(fs.readFileSync(pidFile, 'utf8'), 10);
@@ -1156,8 +1159,22 @@ if (process.argv[2] === 'visualize') {
1156
1159
  } else {
1157
1160
  info('No running visualizer found');
1158
1161
  }
1162
+ // 2. Remove env var from settings.local.json
1163
+ if (fs.existsSync(settingsPath)) {
1164
+ try {
1165
+ const s = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
1166
+ if (s.env && s.env.AZCLAUDE_VISUALIZER) {
1167
+ delete s.env.AZCLAUDE_VISUALIZER;
1168
+ if (Object.keys(s.env).length === 0) delete s.env;
1169
+ atomicWriteFileSync(settingsPath, JSON.stringify(s, null, 2));
1170
+ ok('Removed AZCLAUDE_VISUALIZER from settings');
1171
+ }
1172
+ } catch (_) {}
1173
+ }
1159
1174
  } else {
1160
1175
  const port = process.argv[4] || '8765';
1176
+
1177
+ // 1. Start server
1161
1178
  const { spawn } = require('child_process');
1162
1179
  const child = spawn(process.execPath, [serverPath], {
1163
1180
  detached: true, stdio: 'ignore',
@@ -1167,8 +1184,28 @@ if (process.argv[2] === 'visualize') {
1167
1184
  const pidFile = path.join(os.tmpdir(), '.azclaude-visualizer.pid');
1168
1185
  fs.writeFileSync(pidFile, String(child.pid));
1169
1186
  ok(`Visualizer started on port ${port} (PID: ${child.pid})`);
1170
- info(`Open: http://localhost:${port}`);
1171
- info(`Set env: AZCLAUDE_VISUALIZER=${port}`);
1187
+
1188
+ // 2. Write AZCLAUDE_VISUALIZER env var into settings.local.json
1189
+ // Claude Code reads env from here — hooks pick it up automatically
1190
+ let settings = {};
1191
+ if (fs.existsSync(settingsPath)) {
1192
+ try { settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch (_) {}
1193
+ }
1194
+ if (!settings.env) settings.env = {};
1195
+ settings.env.AZCLAUDE_VISUALIZER = port;
1196
+ atomicWriteFileSync(settingsPath, JSON.stringify(settings, null, 2));
1197
+ ok(`AZCLAUDE_VISUALIZER=${port} written to settings.local.json`);
1198
+
1199
+ // 3. Open browser (cross-platform)
1200
+ const url = `http://localhost:${port}`;
1201
+ try {
1202
+ const openCmd = process.platform === 'win32' ? `start "" "${url}"`
1203
+ : process.platform === 'darwin' ? `open "${url}"`
1204
+ : `xdg-open "${url}" 2>/dev/null || true`;
1205
+ require('child_process').exec(openCmd);
1206
+ } catch (_) {}
1207
+ ok(`Dashboard: ${url}`);
1208
+ info('Hooks will send events automatically — just open Claude Code and work');
1172
1209
  }
1173
1210
  process.exit(0);
1174
1211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azclaude-copilot",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "AI coding environment — 40 commands, 10 skills, 15 agents, real-time visualizer, memory, reflexes, evolution. Install: npx azclaude-copilot@latest, then open Claude Code.",
5
5
  "bin": {
6
6
  "azclaude": "bin/cli.js",
@@ -77,11 +77,12 @@ Agents live in `.claude/agents/`. Spawn them via the Agent tool with the matchin
77
77
 
78
78
  **Mandatory pipeline for ALL code tasks (enforced by hook on every message):**
79
79
  1. **ALWAYS** spawn `problem-architect` FIRST → get Team Spec (agents, skills, files, risks)
80
- 2. Follow Team Spec exactly: load listed skills, pre-read listed files, in order
81
- 3. If structural decision flagged spawn `architecture-advisor` skill or run /debate
82
- 4. Implement following Team Spec patterns
83
- 5. **ALWAYS** spawn `code-reviewer` after implementation
84
- 6. **ALWAYS** spawn `test-writer` if tests are needed
80
+ 2. **RELAY**: Pass Team Spec + pre-read file contents to the next agent via `## Pre-loaded Context` block. The receiving agent MUST NOT re-read files listed in that block. See `capabilities/shared/context-relay.md` for role-based filters and size limits.
81
+ 3. Follow Team Spec exactly: load listed skills, pre-read listed files, in order
82
+ 4. If structural decision flagged → spawn `architecture-advisor` skill or run /debate
83
+ 5. Implement following Team Spec patterns
84
+ 6. **ALWAYS** spawn `code-reviewer` after implementation
85
+ 7. **ALWAYS** spawn `test-writer` if tests are needed
85
86
 
86
87
  **Skip pipeline only if:** message is a pure question with no action verb (e.g., "what does this function do?").
87
88
  **Never skip for:** any code change, no matter how small. The pipeline catches bugs in 1-line changes too.
@@ -155,11 +155,13 @@ If verdict is `APPROVED` or `APPROVED (no constitution found)`: proceed to Step
155
155
 
156
156
  Load `capabilities/shared/parallel-coordination.md` first.
157
157
  Load `capabilities/shared/context-inoculation.md` and prepend its Required Preamble to every agent prompt below.
158
+ Load `capabilities/shared/context-relay.md` for relay protocol and role-based filters.
158
159
 
159
160
  1. Write `.claude/ownership.md` table (branch, directories, status) for every agent in this batch
160
161
  2. Write `.claude/parallel-wave-state.md` with `dispatch_mode: dag` (see parallel-coordination.md)
161
- 3. **Pre-read shared files** (models, schemas, configs referenced by 2+ agents) and inject their content inline into each agent's prompt — eliminates redundant file reads across agents
162
- 4. Spawn each builder via Task with `isolation: "worktree"` in the same message (true parallel)
162
+ 3. **Pre-read shared files** (models, schemas, configs referenced by 2+ agents) and relay their content via a `## Pre-loaded Context` block in each agent's prompt — builders MUST NOT re-read relayed files
163
+ 4. If problem-architect returned a `## Relay` section, include it in the builder prompt as-is
164
+ 5. Spawn each builder via Task with `isolation: "worktree"` in the same message (true parallel)
163
165
  5. Include worktree rules + **test scope** (`Test scope: {test-dir}`) in every parallel prompt
164
166
  6. **Merge-on-complete**: as each agent reports done, merge its branch immediately (don't wait for all)
165
167
  7. After each merge: check if newly-unblocked milestones exist → dispatch them immediately
@@ -168,6 +170,7 @@ Load `capabilities/shared/context-inoculation.md` and prepend its Required Pream
168
170
  **Sequential dispatch (single milestone OR overlapping files):**
169
171
 
170
172
  Load `capabilities/shared/context-inoculation.md` and prepend its Required Preamble to the agent prompt below.
173
+ Load `capabilities/shared/context-relay.md` for relay protocol and size limits.
171
174
 
172
175
  Spawn milestone-builder via Task with fully packaged context:
173
176
 
@@ -177,25 +180,33 @@ Task: Implement Milestone {N} — {title}
177
180
  Agent role: {agent-name from spec} (owns {directories})
178
181
  Skills to activate: {skill list from spec}
179
182
 
180
- Pre-read BEFORE writing anything:
181
- - {file}: {reason}
182
- - {file}: {reason}
183
+ ## Pre-loaded Context (do NOT re-read these files)
183
184
 
184
- Pre-conditions verified:
185
- - {checklist from spec}
185
+ ### Team Spec
186
+ {paste problem-architect's full Team Spec}
187
+
188
+ ### Relay (from problem-architect)
189
+ {paste problem-architect's ## Relay section if present — condensed file contents it already read}
190
+
191
+ ### File contents (pre-read by orchestrator)
192
+ {paste contents of files listed in Team Spec's "Pre-Read Files" that you already have in context}
186
193
 
187
- Conventions (from patterns.md):
188
- - {relevant entries}
194
+ ### Conventions (from patterns.md)
195
+ {relevant entries}
189
196
 
190
- Anti-patterns (from antipatterns.md):
191
- - {relevant entries}
197
+ ### Anti-patterns (from antipatterns.md)
198
+ {relevant entries}
192
199
 
193
- Architecture decisions (from decisions.md):
194
- - {relevant entries}
200
+ ### Architecture decisions (from decisions.md)
201
+ {relevant entries}
202
+
203
+ Pre-conditions verified:
204
+ - {checklist from spec}
195
205
 
196
206
  Complexity: {SIMPLE|MEDIUM|COMPLEX}
197
207
  Fix attempts: {2 for SIMPLE/MEDIUM, 3 for COMPLEX}
198
208
 
209
+ Only read files NOT listed in Pre-loaded Context.
199
210
  When done, report: files changed + test status + new patterns/anti-patterns.
200
211
  ```
201
212
 
@@ -161,6 +161,15 @@ YES | NO
161
161
  If NO: reason = {specific conflict — shared file, schema dependency, runtime ordering}
162
162
  The orchestrator uses this to decide whether to use worktree isolation or sequential dispatch.
163
163
  Parallel Safe = YES requires: isolated directories, no shared config/schema, no runtime dependency on a sibling milestone.
164
+
165
+ ### Relay (for milestone-builder — do not re-read)
166
+ {Include condensed contents of key files you read during analysis.
167
+ Only include files the builder will need. Filter by relevance.
168
+ For files >200 lines, include only the relevant section with line ranges.
169
+ Maximum ~4000 tokens for this section.}
170
+
171
+ ### {file-path} (lines N-M)
172
+ {content}
164
173
  ```
165
174
  </output_format>
166
175
 
@@ -29,6 +29,7 @@ Load only the files that match the current task. Never load the full list.
29
29
  | shared/context-inoculation.md | /copilot dispatch, milestone-builder spawn, autonomous agent context — inject anti-reward-hack boundaries (75-90% reduction) | ~120 |
30
30
  | shared/reward-hack-detection.md | /audit, /ship, post-milestone review — detect reward hacking patterns in test modifications | ~150 |
31
31
  | shared/ultrathink.md | $ARGUMENTS contains --deep, or command needs extended thinking for complex analysis | ~80 |
32
+ | shared/context-relay.md | About to spawn a subagent — pass pre-read files to eliminate redundant reads across agent boundaries | ~300 |
32
33
 
33
34
  ## Level Builders — load ONE at a time
34
35
  | File | When to load | Tokens |
@@ -0,0 +1,125 @@
1
+ # Context Relay — Eliminate Redundant Reads Across Agent Boundaries
2
+
3
+ Every agent spawn is a context boundary. Without relay, each agent re-reads the same files
4
+ its parent already has in context. This wastes 5-15 tool calls per spawn and 20-50k tokens
5
+ per pipeline run.
6
+
7
+ ## The Rule
8
+
9
+ **When spawning a subagent via Agent() or Task(), include a `## Pre-loaded Context` block
10
+ in the prompt with the relevant files you already read. The subagent MUST NOT re-read
11
+ files listed in this block.**
12
+
13
+ ## What to Relay
14
+
15
+ Pass context **filtered by the subagent's role**. Not everything — just what this agent needs.
16
+
17
+ ### Role-based relay filters
18
+
19
+ | Subagent | Relay these | Skip these |
20
+ |----------|------------|------------|
21
+ | problem-architect | CLAUDE.md identity + rules, goals.md current threads, file list from recent reads | Full checkpoint, session history |
22
+ | milestone-builder | Team Spec (from problem-architect), file contents listed in `Files:`, patterns relevant to this milestone | Other milestones' files, decisions.md |
23
+ | code-reviewer | The diff (what changed), relevant test patterns, CLAUDE.md rules section | Goals, checkpoints, deployment config |
24
+ | test-writer | Source file under test, existing test file patterns (first 20 lines), test framework config | Goals, security rules, deployment |
25
+ | security-auditor | Files being reviewed, security patterns from CLAUDE.md | Test patterns, frontend config |
26
+ | orchestrator | plan.md, goals.md, constitution.md non-negotiables | Individual file contents (too large) |
27
+
28
+ ### Size limits
29
+
30
+ - Maximum relay block: **4000 tokens** (~3000 words)
31
+ - If the content exceeds this, summarize: include file paths + key findings, not raw content
32
+ - File contents: include only the **relevant section**, not the full file
33
+ - For large files (>200 lines): include line range references (`file.ts:45-120`) instead of content
34
+
35
+ ## Protocol
36
+
37
+ ### For commands (/add, /fix, /refactor)
38
+
39
+ When the command reads files to understand context, and then spawns a subagent:
40
+
41
+ ```
42
+ Spawn Agent(subagent_type="problem-architect") with this prompt:
43
+ "Task: {description}
44
+
45
+ ## Pre-loaded Context
46
+ The following files were already read. Do NOT re-read them.
47
+
48
+ ### CLAUDE.md (rules section)
49
+ {paste rules section only — not the full file}
50
+
51
+ ### Current goals
52
+ {paste goals.md current threads — not done history}
53
+
54
+ ### Relevant source files
55
+ {paste key file sections already in your context}
56
+ "
57
+ ```
58
+
59
+ ### For orchestrator → milestone-builder
60
+
61
+ The orchestrator already reads plan.md and gets Team Specs from problem-architect.
62
+ When dispatching a milestone-builder:
63
+
64
+ ```
65
+ Task: Implement milestone M3 — {title}
66
+
67
+ ## Pre-loaded Context (do NOT re-read these)
68
+
69
+ ### Team Spec (from problem-architect)
70
+ {paste the full Team Spec for this milestone}
71
+
72
+ ### File contents (pre-read by orchestrator)
73
+ {paste contents of files listed in Team Spec's "Files to pre-read"}
74
+
75
+ ### Project patterns
76
+ {paste relevant patterns from CLAUDE.md or patterns.md}
77
+
78
+ ## Instructions
79
+ Implement the milestone. You have all the context you need above.
80
+ Only read files NOT listed in Pre-loaded Context.
81
+ ```
82
+
83
+ ### For problem-architect → return relay data
84
+
85
+ When problem-architect returns a Team Spec, it SHOULD include a `## Relay` section
86
+ with condensed file contents it read during analysis:
87
+
88
+ ```
89
+ ## Relay (for milestone-builder — do not re-read)
90
+ ### src/auth/jwt.ts (lines 1-45)
91
+ {content}
92
+ ### src/types/user.ts (full file, 30 lines)
93
+ {content}
94
+ ```
95
+
96
+ The orchestrator passes this relay block directly into the milestone-builder's prompt.
97
+
98
+ ## What NOT to relay
99
+
100
+ - **Mutable state** — goals.md "In progress" section changes between agent spawns
101
+ - **Large binary/config files** — package-lock.json, node_modules paths
102
+ - **Full git history** — pass only the relevant commit message or diff
103
+ - **Other agents' results** — unless explicitly needed (e.g., code-reviewer's findings for a fix)
104
+
105
+ ## Anti-patterns
106
+
107
+ 1. **Relay everything** — bloats the subagent prompt, wastes tokens on irrelevant context
108
+ 2. **Relay nothing** — status quo, each agent re-reads 5-15 files
109
+ 3. **Relay stale data** — if a file was modified between parent read and agent spawn, the relay is wrong. Only relay files that won't change during this pipeline run.
110
+ 4. **Skip the filter** — sending a code-reviewer the full decisions.md when it only needs the diff
111
+
112
+ ## Measuring impact
113
+
114
+ Before context-relay:
115
+ - problem-architect: ~8 Read calls to understand the project
116
+ - milestone-builder: ~6 Read calls to re-read what problem-architect already read
117
+ - code-reviewer: ~4 Read calls for CLAUDE.md + patterns + the files under review
118
+ - Total per /add pipeline: ~18 Read calls, ~40k tokens on re-reads
119
+
120
+ After context-relay:
121
+ - problem-architect: ~8 Read calls (unchanged — it's the first reader)
122
+ - milestone-builder: ~1-2 Read calls (only files not in relay)
123
+ - code-reviewer: ~1 Read call (only the diff, everything else relayed)
124
+ - Total per /add pipeline: ~11 Read calls, ~15k tokens on re-reads
125
+ - **Savings: ~40% fewer reads, ~60% fewer re-read tokens**
@@ -42,11 +42,20 @@ Available skills: {output of: ls .claude/skills/ 2>/dev/null}
42
42
  |-------|--------|
43
43
  | Skills to Load | Load each skill before implementing |
44
44
  | Pre-Read Files | Read every file listed, in order: schema → source → tests → patterns → antipatterns |
45
+ | Relay | Pass directly to builder prompt (see below) |
45
46
  | Pre-Conditions | Verify each; STOP if any unmet |
46
47
  | Files Written | Note for parallel safety — no concurrent work on same files |
47
48
  | Structural Decision: YES | Run /debate before proceeding; log result to `.claude/memory/decisions.md` |
48
49
  | Risks | Read mitigation; apply to implementation approach |
49
50
 
51
+ ### Context Relay — Eliminate Redundant Reads
52
+
53
+ After reading pre-read files, if spawning a builder agent:
54
+ 1. Include a `## Pre-loaded Context` block in the builder's prompt with file contents you already read
55
+ 2. Filter by the builder's role — see `capabilities/shared/context-relay.md` for role-based filters and size limits
56
+ 3. The spawned agent **MUST NOT** re-read files listed in the Pre-loaded Context block
57
+ 4. If problem-architect returned a `## Relay` section, pass it directly into the builder prompt
58
+
50
59
  ---
51
60
 
52
61
  ## Implementation Protocol (milestone-builder)
@@ -83,7 +83,7 @@ Do NOT push to origin. Commit locally only.
83
83
  Report branch name in completion message.
84
84
 
85
85
  ## Pre-loaded Context (do NOT re-read these files)
86
- {orchestrator pre-reads shared files and injects content here}
86
+ {orchestrator pre-reads shared files and relays content here — see context-relay.md for role-based filters and size limits}
87
87
 
88
88
  {standard milestone context from orchestrator Step 4}
89
89
  ```
@@ -24,11 +24,19 @@ let filePath = '';
24
24
  let changeSummary = '';
25
25
  let toolName = '';
26
26
  let toolOutput = '';
27
+ let _rawInput = null;
28
+ let _agentId = null;
29
+ let _agentType = null;
30
+ let _toolUseId = null;
27
31
  try {
28
32
  const raw = fs.readFileSync(0, 'utf8'); // fd 0 = stdin, cross-platform
29
33
  const data = JSON.parse(raw);
30
34
  toolName = data.tool_name || '';
31
35
  filePath = data.tool_input?.file_path || data.tool_input?.path || data.tool_input?.command || '';
36
+ _rawInput = data.tool_input || null;
37
+ _agentId = data.agent_id || null;
38
+ _agentType = data.agent_type || null;
39
+ _toolUseId = data.tool_use_id || null;
32
40
  // Extract change summary from old_string/new_string diff hint (Edit tool)
33
41
  // MultiEdit: edits[] array — use first edit's new_string
34
42
  const oldStr = data.tool_input?.old_string || data.tool_input?.edits?.[0]?.old_string || '';
@@ -47,6 +55,36 @@ try {
47
55
  // Also accept env var fallback (older Claude Code versions)
48
56
  if (!filePath) filePath = process.env.CLAUDE_FILE_PATH || '';
49
57
 
58
+ // ── Forward full hook event to visualizer (so dashboard shows tool results) ──
59
+ if (process.env.AZCLAUDE_VISUALIZER && toolName) {
60
+ try {
61
+ const vPort = parseInt(process.env.AZCLAUDE_VISUALIZER, 10) || 8765;
62
+ let vizId = _toolUseId || null;
63
+ if (!vizId) {
64
+ const vizIdPath = path.join(os.tmpdir(), `.azclaude-vizid-${process.ppid || process.pid}`);
65
+ try { vizId = fs.readFileSync(vizIdPath, 'utf8').trim(); } catch (_) {}
66
+ }
67
+ const fwd = JSON.stringify({
68
+ hook_event_name: 'PostToolUse',
69
+ tool_name: toolName,
70
+ tool_input: _rawInput,
71
+ tool_response: toolOutput ? toolOutput.slice(0, 2000) : null,
72
+ tool_use_id: vizId,
73
+ session_id: String(process.ppid || process.pid),
74
+ agent_id: _agentId,
75
+ agent_type: _agentType,
76
+ });
77
+ const vReq = require('http').request(
78
+ { hostname: '127.0.0.1', port: vPort, path: '/event', method: 'POST',
79
+ headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(fwd) } },
80
+ () => {}
81
+ );
82
+ vReq.setTimeout(1500, () => vReq.destroy());
83
+ vReq.on('error', () => {});
84
+ vReq.end(fwd);
85
+ } catch (_) {}
86
+ }
87
+
50
88
  const cfg = process.env.AZCLAUDE_CFG || '.claude';
51
89
  // Guard: cfg must resolve inside the project root
52
90
  if (path.resolve(cfg).indexOf(process.cwd()) !== 0) process.exit(0);
@@ -14,16 +14,24 @@ const path = require('path');
14
14
  const os = require('os');
15
15
 
16
16
  // ── Parse stdin ──────────────────────────────────────────────────────────────
17
- let toolName = '';
18
- let filePath = '';
19
- let content = '';
20
- let command = '';
17
+ let toolName = '';
18
+ let filePath = '';
19
+ let content = '';
20
+ let command = '';
21
+ let _rawInput = null; // full tool_input for visualizer
22
+ let _agentId = null;
23
+ let _agentType = null;
24
+ let _toolUseId = null;
21
25
  try {
22
26
  const raw = fs.readFileSync(0, 'utf8'); // fd 0 = stdin
23
27
  const data = JSON.parse(raw);
24
28
  toolName = data.tool_name || '';
25
29
  filePath = data.tool_input?.file_path || data.tool_input?.path || '';
26
30
  command = data.tool_input?.command || '';
31
+ _rawInput = data.tool_input || null;
32
+ _agentId = data.agent_id || null;
33
+ _agentType = data.agent_type || null;
34
+ _toolUseId = data.tool_use_id || null;
27
35
  // Edit uses new_string; Write/MultiEdit use content
28
36
  content = data.tool_input?.new_string || data.tool_input?.content || '';
29
37
  // MultiEdit: scan all edits
@@ -34,6 +42,32 @@ try {
34
42
  process.exit(0); // malformed JSON — stay out of the way
35
43
  }
36
44
 
45
+ // ── Forward full hook event to visualizer (so dashboard shows tool cards) ────
46
+ if (process.env.AZCLAUDE_VISUALIZER && toolName) {
47
+ try {
48
+ const vPort = parseInt(process.env.AZCLAUDE_VISUALIZER, 10) || 8765;
49
+ const vizId = _toolUseId || `pre-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
50
+ const fwd = JSON.stringify({
51
+ hook_event_name: 'PreToolUse',
52
+ tool_name: toolName,
53
+ tool_input: _rawInput,
54
+ tool_use_id: vizId,
55
+ session_id: String(process.ppid || process.pid),
56
+ agent_id: _agentId,
57
+ agent_type: _agentType,
58
+ });
59
+ try { fs.writeFileSync(path.join(os.tmpdir(), `.azclaude-vizid-${process.ppid || process.pid}`), vizId); } catch (_) {}
60
+ const vReq = require('http').request(
61
+ { hostname: '127.0.0.1', port: vPort, path: '/event', method: 'POST',
62
+ headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(fwd) } },
63
+ () => {}
64
+ );
65
+ vReq.setTimeout(1500, () => vReq.destroy());
66
+ vReq.on('error', () => {});
67
+ vReq.end(fwd);
68
+ } catch (_) {}
69
+ }
70
+
37
71
  // ── Session security event log (shared with post-tool-use, stop) ─────────────
38
72
  const _secSid = process.ppid || process.pid;
39
73
  const _seclogPath = path.join(os.tmpdir(), `.azclaude-seclog-${_secSid}`);