claude-comms 1.0.44 → 1.0.46

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 (49) hide show
  1. package/.agents/tools/agent-job/__pycache__/agent_monitor.cpython-312.pyc +0 -0
  2. package/.agents/tools/agent-job/agent_job.py +71 -1
  3. package/.agents/tools/workflow/CONSUMER_SETUP.md +114 -0
  4. package/.agents/tools/workflow/ONBOARD.md +167 -0
  5. package/.agents/tools/workflow/README.md +169 -0
  6. package/.agents/tools/workflow/cli.ts +726 -0
  7. package/.agents/tools/workflow/config.example.json +16 -0
  8. package/.agents/tools/workflow/init.ts +76 -0
  9. package/.agents/tools/workflow/lib/file-tracker.test.ts +81 -0
  10. package/.agents/tools/workflow/lib/file-tracker.ts +387 -0
  11. package/.agents/tools/workflow/lib/harness-executor.ts +649 -0
  12. package/.agents/tools/workflow/lib/prompts.scenario.test.ts +262 -0
  13. package/.agents/tools/workflow/lib/prompts.ts +548 -0
  14. package/.agents/tools/workflow/lib/streams.test.ts +140 -0
  15. package/.agents/tools/workflow/lib/streams.ts +254 -0
  16. package/.agents/tools/workflow/runner.ts +994 -0
  17. package/.agents/tools/workflow/templates/document.md +42 -0
  18. package/.agents/tools/workflow/templates/implement.md +117 -0
  19. package/.agents/tools/workflow/templates/plan.md +54 -0
  20. package/.agents/tools/workflow/templates/pm.md +84 -0
  21. package/.agents/tools/workflow/templates/product-owner.md +211 -0
  22. package/.agents/tools/workflow/templates/review.md +56 -0
  23. package/.agents/tools/workflow/templates/uat.md +71 -0
  24. package/.claude/agents/core/engineer.md +2 -13
  25. package/.claude/commands/action-feedback-item.md +14 -9
  26. package/.claude/hooks/comms/__pycache__/register_subagent.cpython-312.pyc +0 -0
  27. package/.claude/hooks/comms/__pycache__/update_subagent_completion.cpython-312.pyc +0 -0
  28. package/.claude/hooks/utils/__pycache__/server_config.cpython-312.pyc +0 -0
  29. package/.claude/settings.local.json +46 -0
  30. package/CLAUDE.md +1 -1
  31. package/bin/claude-setup.js +3 -4
  32. package/package.json +1 -1
  33. package/src/orchestrator/installer.js +5 -63
  34. package/.claude/agents/core/architect.md +0 -316
  35. package/.claude/agents/core/consultants/codex.md +0 -39
  36. package/.claude/agents/core/consultants/gemini.md +0 -39
  37. package/.claude/agents/core/designer.md +0 -181
  38. package/.claude/agents/core/planner.md +0 -251
  39. package/.claude/agents/core/uat.md +0 -147
  40. package/.claude/agents/util/feedback-executor.md +0 -29
  41. package/.claude/agents/util/meta-agent-builder.md +0 -309
  42. package/.claude/agents/util/session-review.md +0 -228
  43. package/.claude/commands/analyse-document.md +0 -10
  44. package/.claude/commands/await-feedback-orchestrator.md +0 -12
  45. package/.claude/commands/await-feedback.md +0 -21
  46. package/.claude/commands/cook.md +0 -119
  47. package/.claude/commands/feedback.md +0 -140
  48. package/.claude/commands/hello-world.md +0 -1
  49. package/.claude/commands/uat-refine.md +0 -121
@@ -299,6 +299,65 @@ class GeminiEventHandler:
299
299
  return event.get("type") == "result" and event.get("status") == "success"
300
300
 
301
301
 
302
+ class ClaudeEventHandler:
303
+ """Handle Claude CLI JSON stream events."""
304
+
305
+ def __init__(self):
306
+ self._text_chunks: list[str] = []
307
+ self._final_result: Optional[str] = None
308
+ self._complete = False
309
+ self._success = False
310
+
311
+ def extract_job_id(self, event: dict) -> Optional[str]:
312
+ """Extract job ID from initial event."""
313
+ if event.get("type") == "system" and event.get("subtype") == "init":
314
+ return event.get("session_id")
315
+ return None
316
+
317
+ def process_event(self, event: dict, status: JobStatus) -> None:
318
+ """Process a Claude event and update status."""
319
+ event_type = event.get("type", "")
320
+
321
+ # Capture assistant text messages
322
+ if event_type == "assistant":
323
+ status.status_reason = "responding"
324
+ msg = event.get("message", {})
325
+ content = msg.get("content", [])
326
+ if isinstance(content, list):
327
+ for block in content:
328
+ if isinstance(block, dict):
329
+ if block.get("type") == "text" and block.get("text"):
330
+ self._text_chunks.append(block["text"])
331
+ elif block.get("type") == "tool_use":
332
+ tool_name = block.get("name", "tool")
333
+ status.status_reason = tool_name
334
+
335
+ # Handle tool results
336
+ elif event_type == "user":
337
+ status.status_reason = "tool_result"
338
+
339
+ # Capture final result
340
+ elif event_type == "result":
341
+ self._complete = True
342
+ self._success = event.get("subtype") == "success"
343
+ status.status_reason = "completed" if self._success else "failed"
344
+
345
+ if event.get("result"):
346
+ self._final_result = str(event["result"])
347
+
348
+ # Extract duration if available
349
+ if event.get("duration_ms"):
350
+ status.completion.duration_ms = event["duration_ms"]
351
+
352
+ def is_completion_event(self, event: dict) -> bool:
353
+ """Check if this event indicates completion."""
354
+ return event.get("type") == "result" and event.get("subtype") == "success"
355
+
356
+ def get_result(self) -> str:
357
+ """Get the accumulated result."""
358
+ return self._final_result or "\n\n".join(self._text_chunks)
359
+
360
+
302
361
  # =============================================================================
303
362
  # Job Manager
304
363
  # =============================================================================
@@ -423,6 +482,15 @@ def build_harness_command(harness: str, assignment: str) -> list[str]:
423
482
  assignment,
424
483
  "--json",
425
484
  ]
485
+ elif harness == "claude":
486
+ return [
487
+ "claude",
488
+ "--dangerously-skip-permissions",
489
+ "--verbose",
490
+ "--output-format", "stream-json",
491
+ "-p",
492
+ assignment,
493
+ ]
426
494
  else:
427
495
  raise ValueError(f"Unknown harness: {harness}")
428
496
 
@@ -562,6 +630,8 @@ def spawn_job(harness: str, assignment: str) -> dict:
562
630
  # Create appropriate event handler
563
631
  if harness == "gemini":
564
632
  handler = GeminiEventHandler()
633
+ elif harness == "claude":
634
+ handler = ClaudeEventHandler()
565
635
  else:
566
636
  handler = CodexEventHandler()
567
637
 
@@ -779,7 +849,7 @@ def main():
779
849
  spawn_parser.add_argument(
780
850
  "--harness",
781
851
  required=True,
782
- choices=["gemini", "codex"],
852
+ choices=["gemini", "codex", "claude"],
783
853
  help="Agent harness to use"
784
854
  )
785
855
  spawn_parser.add_argument(
@@ -0,0 +1,114 @@
1
+ # Consumer Repo Setup
2
+
3
+ This document describes how to set up the workflow engine in repos that consume the `.agents/` directory.
4
+
5
+ ## Current Architecture
6
+
7
+ ```
8
+ .agents/tools/workflow/
9
+ ├── workflow-engine -> ../../../workflow-engine (symlink)
10
+ ├── cli.ts
11
+ ├── runner.ts
12
+ ├── config.json
13
+ └── templates/
14
+ ```
15
+
16
+ The CLI and runner import from `./workflow-engine/convex/_generated/api.js`, which resolves through the symlink to the actual `workflow-engine/` directory containing the Convex schema and generated types.
17
+
18
+ ## Problem
19
+
20
+ When copying `.agents/` to a consumer repo, the symlink points to `../../../workflow-engine` which won't exist in the consumer repo's directory structure.
21
+
22
+ ## Options
23
+
24
+ ### Option 1: Copy workflow-engine alongside .agents
25
+
26
+ ```bash
27
+ # In consumer repo
28
+ cp -r /path/to/workflow-engine ./workflow-engine
29
+ # Symlink already points to ../../../workflow-engine, adjust if needed
30
+ ```
31
+
32
+ Pros: Simple, self-contained
33
+ Cons: Duplicated code, manual updates
34
+
35
+ ### Option 2: Publish workflow-engine to npm
36
+
37
+ ```bash
38
+ # Publish
39
+ cd workflow-engine && npm publish
40
+
41
+ # In consumer repo
42
+ npm install @yourorg/workflow-engine
43
+
44
+ # Update symlink
45
+ cd .agents/tools/workflow
46
+ rm workflow-engine
47
+ ln -s ../../../node_modules/@yourorg/workflow-engine workflow-engine
48
+ ```
49
+
50
+ Pros: Clean dependency management, versioned
51
+ Cons: Requires npm publishing workflow
52
+
53
+ ### Option 3: Git submodule
54
+
55
+ ```bash
56
+ # In consumer repo
57
+ git submodule add <workflow-engine-repo-url> workflow-engine
58
+
59
+ # Symlink points to it
60
+ cd .agents/tools/workflow
61
+ ln -s ../../../workflow-engine workflow-engine
62
+ ```
63
+
64
+ Pros: Always up to date with upstream
65
+ Cons: Submodule complexity
66
+
67
+ ### Option 4: Monorepo with shared packages
68
+
69
+ If using a monorepo (turborepo, nx, etc.), workflow-engine can be a workspace package that .agents/tools/workflow depends on.
70
+
71
+ ## Config Per Repo
72
+
73
+ Each consumer repo needs its own `config.json`:
74
+
75
+ ```json
76
+ {
77
+ "convexUrl": "https://your-project-123.convex.cloud",
78
+ "namespace": "consumer-repo-name",
79
+ "timeoutMs": 600000,
80
+ "harnessDefaults": {
81
+ "default": "claude",
82
+ "plan": "claude",
83
+ "implement": "claude",
84
+ "review": "claude",
85
+ "uat": "claude",
86
+ "document": "claude",
87
+ "pm": "claude",
88
+ "chat": "claude"
89
+ }
90
+ }
91
+ ```
92
+
93
+ The `namespace` field isolates assignments/jobs per repo in the shared Convex backend.
94
+
95
+ ## Initialization
96
+
97
+ After setting up `config.json`, run the init script to register your namespace in the database:
98
+
99
+ ```bash
100
+ cd .agents/tools/workflow
101
+ npx tsx init.ts
102
+ ```
103
+
104
+ This script is **idempotent** - running it multiple times is safe and won't create duplicate namespaces. It will either:
105
+ - Create the namespace if it doesn't exist
106
+ - Report that the namespace already exists
107
+
108
+ You must run this before the runner or CLI will work, as all assignments and chat threads require a valid namespace ID.
109
+
110
+ ## TODO
111
+
112
+ - [ ] Decide on distribution strategy (npm publish vs git submodule vs copy)
113
+ - [ ] Automate consumer repo setup script
114
+ - [ ] Consider generating standalone client without symlink dependency
@@ -0,0 +1,167 @@
1
+ # Workflow Engine Onboarding
2
+
3
+ ## What We Built
4
+
5
+ A job queue system for orchestrating sequential Claude/Codex/Gemini headless runs. Solves the "checkbox brain" problem where Claude rushes through todos without quality gates.
6
+
7
+ ### Architecture
8
+
9
+ ```
10
+ Convex Backend (workflow-engine/) ← Schema, queries, mutations
11
+ ↑
12
+ │ WebSocket subscription
13
+ │
14
+ Runner Daemon (.agents/tools/workflow/runner.ts) ← Executes jobs
15
+ │
16
+ │ spawns
17
+ ↓
18
+ Claude/Codex/Gemini headless ← Actual work
19
+ │
20
+ │ on complete
21
+ ↓
22
+ PM Shadow Job ← Reviews, decides next step
23
+ ```
24
+
25
+ ### Key Concepts
26
+
27
+ - **Assignment**: User intent (north star). Has linked list of jobs.
28
+ - **Job**: Single Claude/Codex/Gemini run. Types: plan, implement, review, uat, document, pm.
29
+ - **PM Agent**: Runs after each job. Reviews result, inserts next job or completes/blocks assignment.
30
+ - **Namespace**: Isolates assignments per repo in shared Convex backend.
31
+
32
+ ## Files Created
33
+
34
+ ### Backend (`workflow-engine/`)
35
+ ```
36
+ convex/
37
+ ├── schema.ts # assignments + jobs tables
38
+ ├── assignments.ts # CRUD
39
+ ├── jobs.ts # CRUD
40
+ └── scheduler.ts # getReadyJobs, watchQueue
41
+ ```
42
+
43
+ **Deployed to**: `https://utmost-vulture-618.convex.cloud`
44
+
45
+ ### Consumer-facing (`.agents/tools/workflow/`)
46
+ ```
47
+ ├── workflow-engine/ # symlink → ../../../workflow-engine
48
+ ├── cli.ts # PM-ergonomic CLI
49
+ ├── runner.ts # WebSocket daemon
50
+ ├── config.json # namespace, convex URL
51
+ ├── templates/ # Prompt templates (plan.md, implement.md, etc.)
52
+ ├── README.md
53
+ ├── CONSUMER_SETUP.md # Distribution notes for other repos
54
+ └── SPEC.md # (in workflow-engine/)
55
+ ```
56
+
57
+ ## Current State
58
+
59
+ - ✅ Convex schema deployed
60
+ - ✅ CLI working (`npx tsx .agents/tools/workflow/cli.ts queue`)
61
+ - ✅ Templates created
62
+ - ✅ Runner daemon written
63
+ - ⏳ Runner not yet tested end-to-end
64
+ - ⏳ PM shadow job flow not tested
65
+
66
+ ## What Needs Testing
67
+
68
+ ### 1. Start the runner
69
+ ```bash
70
+ npx tsx .agents/tools/workflow/runner.ts
71
+ ```
72
+
73
+ ### 2. Create a test assignment
74
+ ```bash
75
+ npx tsx .agents/tools/workflow/cli.ts create "Create a hello world function in test-hello.ts"
76
+ ```
77
+
78
+ ### 3. Add initial job
79
+ ```bash
80
+ npx tsx .agents/tools/workflow/cli.ts insert-job <assignment_id> \
81
+ --type implement \
82
+ --harness claude \
83
+ --context "Create a simple hello world function that returns 'Hello, World!'"
84
+ ```
85
+
86
+ ### 4. Watch the runner
87
+ - Should pick up the job
88
+ - Execute Claude headless
89
+ - On completion, trigger PM job
90
+ - PM should review and decide next steps
91
+
92
+ ### 5. Verify end state
93
+ ```bash
94
+ npx tsx .agents/tools/workflow/cli.ts assignment <assignment_id>
95
+ ```
96
+
97
+ ## CLI Quick Reference
98
+
99
+ ```bash
100
+ # Queries
101
+ cli.ts queue # Queue status
102
+ cli.ts assignments # List all
103
+ cli.ts assignment <id> # Details with jobs
104
+ cli.ts jobs # List jobs
105
+ cli.ts job <id> # Job details
106
+
107
+ # Mutations
108
+ cli.ts create "<north_star>" # New assignment
109
+ cli.ts insert-job <aid> --type X --harness Y --context "Z"
110
+ cli.ts complete <aid> # Mark done
111
+ cli.ts block <aid> --reason "..." # Escalate to human
112
+ cli.ts unblock <aid> # Resume
113
+ ```
114
+
115
+ ## Config
116
+
117
+ Copy `config.example.json` to `config.json` and edit:
118
+
119
+ ```json
120
+ {
121
+ "convexUrl": "https://your-project.convex.cloud",
122
+ "namespace": "your-repo-name",
123
+ "timeoutMs": 600000,
124
+ "harnessDefaults": {
125
+ "default": "claude",
126
+ "plan": "claude",
127
+ "implement": "claude",
128
+ "review": "claude",
129
+ "uat": "claude",
130
+ "document": "claude",
131
+ "pm": "claude",
132
+ "chat": "claude"
133
+ }
134
+ }
135
+ ```
136
+
137
+ ## Claude JSON Stream Format
138
+
139
+ ```
140
+ {"type":"system","subtype":"init","session_id":"...","tools":[...],...}
141
+ {"type":"assistant","message":{"content":[{"type":"text","text":"..."}],...}}
142
+ {"type":"assistant","message":{"content":[{"type":"tool_use","name":"...","input":{...}}],...}}
143
+ {"type":"user","message":{"content":[{"type":"tool_result","content":"..."}]}}
144
+ {"type":"result","subtype":"success","result":"final output text","duration_ms":...}
145
+ ```
146
+
147
+ **Key extraction:**
148
+ - Assistant text: `event.message.content[].text` where `type === "text"`
149
+ - Final result: `event.result` when `event.type === "result"`
150
+ - Success: `event.subtype === "success"`
151
+
152
+ ## Known Issues / TODO
153
+
154
+ 1. Consumer repo distribution strategy not finalized (see CONSUMER_SETUP.md)
155
+ 2. Parallel job execution logic could be tightened
156
+ 3. No retry logic for transient failures yet
157
+
158
+ ## Session Context
159
+
160
+ We spec'd this collaboratively, iterating on:
161
+ - Entity model (Assignment → Jobs linked list)
162
+ - Parallelism (assignment-level, not job-level)
163
+ - PM as shadow job pattern
164
+ - Convex-first for real-time reactivity
165
+ - CLI ergonomics for PM agent consumption
166
+
167
+ The eng-cog metacognitive framework from `docs/options/eng-prompt.md` was used for initial framing but dropped during rapid iteration.
@@ -0,0 +1,169 @@
1
+ # Workflow Engine
2
+
3
+ Job queue system for orchestrating sequential Claude/Codex/Gemini headless runs.
4
+
5
+ ## Architecture
6
+
7
+ ```
8
+ Convex Backend (workflow-engine/)
9
+ ↑
10
+ │ WebSocket subscription
11
+ │
12
+ Runner Daemon (runner.ts)
13
+ │
14
+ │ spawns
15
+ ↓
16
+ Claude/Codex/Gemini headless processes
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ### 1. Configure
22
+
23
+ Copy the example config and edit:
24
+
25
+ ```bash
26
+ cp config.example.json config.json
27
+ ```
28
+
29
+ Edit `config.json`:
30
+
31
+ ```json
32
+ {
33
+ "convexUrl": "https://utmost-vulture-618.convex.cloud",
34
+ "namespace": "your-repo-name",
35
+ "timeoutMs": 600000,
36
+ "harnessDefaults": {
37
+ "default": "claude",
38
+ "plan": "claude",
39
+ "implement": "claude",
40
+ "review": "claude",
41
+ "uat": "claude",
42
+ "document": "claude",
43
+ "pm": "claude",
44
+ "chat": "claude"
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### 2. Start the Runner
50
+
51
+ ```bash
52
+ npx tsx .agents/tools/workflow/runner.ts
53
+ ```
54
+
55
+ The runner subscribes to Convex and executes jobs as they become ready.
56
+
57
+ ### 3. Create an Assignment
58
+
59
+ ```bash
60
+ npx tsx .agents/tools/workflow/cli.ts create "Build user authentication feature"
61
+ ```
62
+
63
+ ### 4. Add Jobs
64
+
65
+ ```bash
66
+ npx tsx .agents/tools/workflow/cli.ts insert-job <assignment_id> \
67
+ --type plan \
68
+ --harness claude \
69
+ --context "Create implementation plan"
70
+ ```
71
+
72
+ ## CLI Reference
73
+
74
+ ### Queries
75
+
76
+ ```bash
77
+ # List assignments
78
+ cli.ts assignments [--status pending|active|blocked|complete]
79
+
80
+ # Get assignment with jobs
81
+ cli.ts assignment <id>
82
+
83
+ # List jobs
84
+ cli.ts jobs [--status pending|running|complete|failed]
85
+
86
+ # Get job details
87
+ cli.ts job <id>
88
+
89
+ # Queue status
90
+ cli.ts queue
91
+ ```
92
+
93
+ ### Mutations
94
+
95
+ ```bash
96
+ # Create assignment
97
+ cli.ts create "<north_star>" [--priority N] [--independent]
98
+
99
+ # Insert job
100
+ cli.ts insert-job <assignment_id> \
101
+ --type <plan|implement|review|uat|document> \
102
+ --harness <claude|codex|gemini> \
103
+ [--context "instructions"] \
104
+ [--after <job_id>]
105
+
106
+ # Update assignment metadata
107
+ cli.ts update-assignment <id> \
108
+ [--artifacts "filepath:description"] \
109
+ [--decisions "decision text"]
110
+
111
+ # Complete assignment
112
+ cli.ts complete <assignment_id>
113
+
114
+ # Block assignment
115
+ cli.ts block <assignment_id> --reason "why"
116
+
117
+ # Unblock assignment
118
+ cli.ts unblock <assignment_id>
119
+
120
+ # Job status updates (typically used by runner)
121
+ cli.ts start-job <job_id>
122
+ cli.ts complete-job <job_id> --result "output"
123
+ cli.ts fail-job <job_id> [--result "error"]
124
+ ```
125
+
126
+ ## Job Types
127
+
128
+ | Type | Purpose |
129
+ |------|---------|
130
+ | `plan` | Create spec doc + work packages |
131
+ | `implement` | Build implementation via engineer batches |
132
+ | `review` | Read-only engineering quality review |
133
+ | `uat` | User acceptance testing |
134
+ | `document` | Update docs and finalize assignment |
135
+ | `pm` | (Shadow job) Review result, decide next |
136
+
137
+ ## How It Works
138
+
139
+ 1. **Assignment created** with north star (human intent)
140
+ 2. **Jobs added** to assignment's linked list
141
+ 3. **Runner picks up** ready jobs (pending + predecessor complete)
142
+ 4. **Job executes** via Claude/Codex/Gemini headless
143
+ 5. **PM job triggers** automatically after each completion
144
+ 6. **PM decides**: insert more jobs, complete, or block
145
+ 7. **Loop** until assignment complete or blocked
146
+
147
+ ## Parallelism Rules
148
+
149
+ - Jobs within an assignment run **sequentially** (linked list)
150
+ - Independent assignments can run **in parallel**
151
+ - Non-independent assignments run **one at a time**
152
+ - Priority: oldest first, then lowest priority number
153
+
154
+ ## Templates
155
+
156
+ Prompt templates live in `templates/`:
157
+ - `plan.md`
158
+ - `implement.md`
159
+ - `review.md`
160
+ - `uat.md`
161
+ - `document.md`
162
+ - `pm.md`
163
+
164
+ Templates use placeholders:
165
+ - `{{NORTH_STAR}}` - Assignment goal
166
+ - `{{ARTIFACTS}}` - Files produced
167
+ - `{{DECISIONS}}` - Decision record
168
+ - `{{CONTEXT}}` - Job-specific instructions
169
+ - `{{PREVIOUS_RESULT}}` - Prior job output