@versatly/workgraph 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # @clawvault/workgraph
2
+
3
+ Agent-first workgraph workspace for multi-agent collaboration.
4
+
5
+ `@clawvault/workgraph` is the coordination core extracted from ClawVault. It focuses only on:
6
+
7
+ - Dynamic primitive registry (`thread`, `space`, `decision`, `lesson`, `fact`, `agent`, plus custom types)
8
+ - Append-only event ledger (`.clawvault/ledger.jsonl`)
9
+ - Ledger claim index (`.clawvault/ledger-index.json`) for fast ownership queries
10
+ - Tamper-evident ledger hash-chain (`.clawvault/ledger-chain.json`)
11
+ - Markdown-native primitive store
12
+ - Thread lifecycle coordination (claim/release/block/unblock/done/decompose)
13
+ - Space-scoped thread scheduling (`--space`)
14
+ - Generated markdown command center (`workgraph command-center`)
15
+ - Native skill primitive lifecycle (`workgraph skill write/load/propose/promote`)
16
+ - Primitive-registry manifest + auto-generated `.base` files
17
+ - JSON-friendly CLI for agent orchestration
18
+
19
+ No memory-category scaffolding, no qmd dependency, no observational-memory pipeline.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install @clawvault/workgraph
25
+ ```
26
+
27
+ Or global CLI:
28
+
29
+ ```bash
30
+ npm install -g @clawvault/workgraph
31
+ ```
32
+
33
+ ## Agent-first CLI
34
+
35
+ ```bash
36
+ # Initialize pure workgraph workspace
37
+ workgraph init ./wg-space --json
38
+
39
+ # Define custom primitive
40
+ workgraph primitive define command-center \
41
+ --description "Agent ops cockpit" \
42
+ --fields owner:string \
43
+ --fields panel_refs:list \
44
+ --json
45
+
46
+ # Create and route thread work
47
+ workgraph thread create "Ship command center" \
48
+ --goal "Production-ready multi-agent command center" \
49
+ --priority high \
50
+ --actor agent-lead \
51
+ --json
52
+
53
+ workgraph thread next --claim --actor agent-worker --json
54
+ workgraph ledger show --count 20 --json
55
+ workgraph command-center --output "ops/Command Center.md" --json
56
+ workgraph bases generate --refresh-registry --json
57
+ ```
58
+
59
+ ### JSON contract
60
+
61
+ All commands support `--json` and emit:
62
+
63
+ - Success: `{ "ok": true, "data": ... }`
64
+ - Failure: `{ "ok": false, "error": "..." }` (non-zero exit)
65
+
66
+ This is intended for robust parsing by autonomous agents.
67
+
68
+ ### Space-scoped scheduling
69
+
70
+ ```bash
71
+ workgraph thread create "Implement auth middleware" \
72
+ --goal "Protect private routes" \
73
+ --space spaces/backend.md \
74
+ --actor agent-api \
75
+ --json
76
+
77
+ workgraph thread list --space spaces/backend --ready --json
78
+ workgraph thread next --space spaces/backend --claim --actor agent-api --json
79
+ ```
80
+
81
+ ### Auto-generate `.base` files from primitive registry
82
+
83
+ ```bash
84
+ # Sync .clawvault/primitive-registry.yaml
85
+ workgraph bases sync-registry --json
86
+
87
+ # Generate canonical primitive .base files
88
+ workgraph bases generate --json
89
+
90
+ # Include non-canonical (agent-defined) primitives
91
+ workgraph bases generate --all --refresh-registry --json
92
+ ```
93
+
94
+ ### Ledger query, blame, and tamper detection
95
+
96
+ ```bash
97
+ workgraph ledger query --actor agent-worker --op claim --json
98
+ workgraph ledger blame threads/auth.md --json
99
+ workgraph ledger verify --strict --json
100
+ ```
101
+
102
+ ### Native skill lifecycle (shared vault / Tailscale)
103
+
104
+ ```bash
105
+ # with shared vault env (e.g. tailscale-mounted path)
106
+ export WORKGRAPH_SHARED_VAULT=/mnt/tailscale/company-workgraph
107
+
108
+ workgraph skill write "workgraph-manual" \
109
+ --body-file ./skills/workgraph-manual.md \
110
+ --owner agent-architect \
111
+ --actor agent-architect \
112
+ --json
113
+
114
+ workgraph skill propose workgraph-manual --actor agent-reviewer --space spaces/platform --json
115
+ workgraph skill promote workgraph-manual --actor agent-lead --json
116
+ workgraph skill load workgraph-manual --json
117
+ ```
118
+
119
+ ## ClawVault memory vs Workgraph primitives (split clarification)
120
+
121
+ `@clawvault/workgraph` is **execution coordination only**.
122
+
123
+ - Use it for: ownership, decomposition, dependency management, typed coordination primitives.
124
+ - Do not use it for: long-term memory categories (`decisions/`, `people/`, `projects/` memory workflows), qmd semantic retrieval pipelines, observer/reflector memory compression.
125
+
126
+ This split keeps the workgraph package focused, portable, and shell-agent-native.
127
+
128
+ ## Migrating from mixed memory/workgraph vaults
129
+
130
+ 1. Initialize a clean workgraph workspace:
131
+ ```bash
132
+ workgraph init ./coordination-space --json
133
+ ```
134
+ 2. Recreate only coordination entities as workgraph primitives (`thread`, `space`, custom types).
135
+ 3. Move or archive memory-specific folders outside the coordination workspace.
136
+ 4. Generate a control plane note for humans/agents:
137
+ ```bash
138
+ workgraph command-center --output "ops/Command Center.md" --json
139
+ ```
140
+
141
+ ## Programmatic API
142
+
143
+ ```ts
144
+ import { registry, thread, store, ledger, workspace } from '@clawvault/workgraph';
145
+
146
+ workspace.initWorkspace('/tmp/wg');
147
+
148
+ registry.defineType('/tmp/wg', 'milestone', 'Release checkpoint', {
149
+ thread_refs: { type: 'list', default: [] },
150
+ target_date: { type: 'date' },
151
+ }, 'agent-architect');
152
+
153
+ const t = thread.createThread('/tmp/wg', 'Build Auth', 'JWT and refresh flow', 'agent-lead');
154
+ thread.claim('/tmp/wg', t.path, 'agent-worker');
155
+ thread.done('/tmp/wg', t.path, 'agent-worker', 'Shipped');
156
+ ```
157
+
158
+ ## Publish (package-only)
159
+
160
+ From this directory:
161
+
162
+ ```bash
163
+ npm run ci
164
+ npm publish --access public
165
+ ```
166
+
167
+ ## Skill guide
168
+
169
+ See `SKILL.md` for the full operational playbook optimized for autonomous agents (including pi-mono compatibility guidance).
package/SKILL.md ADDED
@@ -0,0 +1,304 @@
1
+ ---
2
+ name: workgraph
3
+ version: "0.1.0"
4
+ description: Agent-first multi-agent coordination skill for markdown-native workgraph workspaces. Use when coordinating threads, ownership, dependencies, and custom primitive schemas across multiple agents. Do not use for general long-term memory capture; this package intentionally excludes ClawVault memory scaffolding.
5
+ author: Versatly
6
+ source: https://github.com/Versatly/clawvault/tree/main/packages/workgraph
7
+ user-invocable: true
8
+ ---
9
+
10
+ # Workgraph Skill — Multi-Agent Coordination
11
+
12
+ This skill defines how autonomous agents should operate a shared workgraph workspace safely and predictably.
13
+
14
+ ## Purpose
15
+
16
+ Use workgraph to coordinate execution, not to hoard generic memory.
17
+
18
+ - **Good fit:** ownership, decomposition, dependency scheduling, execution audit trail.
19
+ - **Not a fit:** journaling, free-form personal memory, semantic search infrastructure.
20
+
21
+ ## Workspace Model
22
+
23
+ A workgraph workspace contains:
24
+
25
+ - `.workgraph.json` — workspace identity and mode.
26
+ - `.clawvault/registry.json` — primitive type definitions.
27
+ - `.clawvault/ledger.jsonl` — append-only event stream.
28
+ - `.clawvault/ledger-index.json` — derived claim snapshot for fast ownership checks.
29
+ - `.clawvault/ledger-chain.json` — tamper-evident hash-chain state.
30
+ - `.clawvault/primitive-registry.yaml` — canonical primitive registry manifest.
31
+ - `.clawvault/bases/*.base` — generated Obsidian Bases files.
32
+ - Primitive directories (e.g. `threads/`, `spaces/`, `agents/`, custom directories).
33
+
34
+ Initialize once:
35
+
36
+ ```bash
37
+ workgraph init /path/to/workspace --json
38
+ ```
39
+
40
+ ## Core Operational Contract
41
+
42
+ ### 1) Every mutating action must be attributable
43
+
44
+ Always pass `--actor <agent-name>` on thread/primitive mutation commands.
45
+
46
+ ### 2) Always parse machine output
47
+
48
+ Use `--json` for all automation.
49
+
50
+ Success payload:
51
+
52
+ ```json
53
+ { "ok": true, "data": { ... } }
54
+ ```
55
+
56
+ Failure payload (non-zero exit):
57
+
58
+ ```json
59
+ { "ok": false, "error": "..." }
60
+ ```
61
+
62
+ ### 3) Never assume a thread is claimable
63
+
64
+ Call `thread next --json` or `thread list --ready --json`, then claim.
65
+
66
+ ### 4) Never mutate without ledger awareness
67
+
68
+ Before major orchestration steps, inspect:
69
+
70
+ ```bash
71
+ workgraph ledger claims --json
72
+ workgraph ledger show --count 30 --json
73
+ workgraph ledger verify --json
74
+ ```
75
+
76
+ ## Standard Agent Loop
77
+
78
+ This loop is the canonical multi-agent behavior:
79
+
80
+ 1. **Sense**
81
+ - `workgraph thread next --json`
82
+ - `workgraph ledger claims --json`
83
+ 2. **Claim**
84
+ - `workgraph thread claim <path> --actor <agent> --json`
85
+ 3. **Execute**
86
+ - Perform implementation work in repo.
87
+ 4. **Publish state**
88
+ - `workgraph thread done <path> --actor <agent> --output "<result>" --json`
89
+ - OR `workgraph thread block <path> --blocked-by <dep> --reason "<why>" --actor <agent> --json`
90
+ 5. **Continue**
91
+ - Return to step 1.
92
+
93
+ ## Dependency and Readiness Semantics
94
+
95
+ `thread next` and `thread list --ready` treat a thread as ready only when:
96
+
97
+ - status is `open`
98
+ - all dependency refs point to threads whose status is `done`
99
+ - external dependencies (prefix `external/`) are considered not ready
100
+
101
+ This allows deterministic autonomous scheduling without hidden state.
102
+
103
+ ## Primitive Design Rules
104
+
105
+ When creating custom types:
106
+
107
+ 1. Add only fields needed by a specific recurring coordination pattern.
108
+ 2. Use `ref` or `list` fields for links to other primitives.
109
+ 3. Keep state-machine-like fields explicit (`status`, `phase`, `go_no_go`, etc).
110
+ 4. Define type once; instantiate many times.
111
+
112
+ Example:
113
+
114
+ ```bash
115
+ workgraph primitive define command-center \
116
+ --description "Operational cockpit for active agents" \
117
+ --fields owner:string \
118
+ --fields panel_refs:list \
119
+ --fields active_agents:list \
120
+ --dir command-centers \
121
+ --actor agent-architect \
122
+ --json
123
+ ```
124
+
125
+ ## Advanced Patterns
126
+
127
+ ### Pattern: Decompose before contention
128
+
129
+ If several agents are idle and one large thread exists:
130
+
131
+ ```bash
132
+ workgraph thread decompose threads/large-initiative.md \
133
+ --sub "Schema|Model storage and indexes" \
134
+ --sub "Execution|Implement worker pipeline" \
135
+ --sub "Validation|Run multi-agent E2E checks" \
136
+ --actor agent-lead \
137
+ --json
138
+ ```
139
+
140
+ ### Pattern: Pull-based agent scheduling
141
+
142
+ Each worker repeatedly executes:
143
+
144
+ ```bash
145
+ workgraph thread next --claim --actor agent-worker-X --json
146
+ ```
147
+
148
+ No centralized scheduler is required.
149
+
150
+ ### Pattern: Space-scoped queues
151
+
152
+ Teams can isolate execution lanes with `space`:
153
+
154
+ ```bash
155
+ workgraph thread list --space spaces/backend --ready --json
156
+ workgraph thread next --space spaces/backend --claim --actor agent-backend-1 --json
157
+ ```
158
+
159
+ ### Pattern: Audit-first incident review
160
+
161
+ For postmortems:
162
+
163
+ ```bash
164
+ workgraph ledger history threads/critical-thread.md --json
165
+ workgraph ledger show --count 200 --json
166
+ workgraph ledger blame threads/critical-thread.md --json
167
+ ```
168
+
169
+ ## pi-mono Compatibility Profile
170
+
171
+ This package is designed for shell-driven agents like `pi-mono`.
172
+
173
+ ### Why it works
174
+
175
+ - CLI has deterministic JSON envelopes.
176
+ - Errors are machine-readable.
177
+ - No GUI dependency.
178
+ - No qmd dependency.
179
+
180
+ ### Recommended command wrapper
181
+
182
+ For pi-mono or similar agents, always run:
183
+
184
+ ```bash
185
+ workgraph <command...> --json
186
+ ```
187
+
188
+ Then parse:
189
+
190
+ - `ok === true` -> continue
191
+ - `ok === false` -> route to retry/escalation path
192
+
193
+ ### Suggested pi-mono orchestration sequence
194
+
195
+ 1. `workgraph thread next --claim --actor pi-mono-worker --json`
196
+ 2. if no thread: sleep/backoff
197
+ 3. implement task
198
+ 4. `workgraph thread done <path> --actor pi-mono-worker --output "<summary>" --json`
199
+ 5. repeat
200
+
201
+ ### pi-mono skill distribution flow
202
+
203
+ ```bash
204
+ workgraph skill write "workgraph-manual" --body-file ./skills/workgraph-manual.md --actor pi-mono-curator --json
205
+ workgraph skill propose workgraph-manual --actor pi-mono-reviewer --space spaces/platform --json
206
+ workgraph skill promote workgraph-manual --actor pi-mono-lead --json
207
+ ```
208
+
209
+ ### Backoff recommendations
210
+
211
+ - Empty queue: exponential backoff (`2s`, `4s`, `8s`, `16s`, cap `60s`)
212
+ - Claim conflict: immediate refresh via `thread next --json`
213
+
214
+ ## Safety and Concurrency Guardrails
215
+
216
+ 1. Never force-claim an active thread.
217
+ 2. Only owner can release/done owner-bound threads.
218
+ 3. Use `block` when waiting on external or unresolved dependencies.
219
+ 4. Keep `output` concise but sufficient for downstream agents.
220
+ 5. Keep parent/child decomposition coherent; workers should usually claim leaf threads first.
221
+
222
+ ## Exit Criteria for Agent Tasks
223
+
224
+ A task is complete only when:
225
+
226
+ - Thread transitioned to `done`
227
+ - Output summary recorded
228
+ - Any new primitives created are linked/referenced by path
229
+ - Ledger confirms expected final operations
230
+
231
+ ## Recommended Team Conventions
232
+
233
+ - Agent names: `role-instance` (`agent-worker-1`, `agent-reviewer-a`)
234
+ - Thread titles: imperative and specific (`Implement token refresh API`)
235
+ - Dependency refs: workspace-relative paths (`threads/schema.md`)
236
+ - Use `external/<system>` for dependencies outside workgraph
237
+
238
+ ## Quick Command Reference
239
+
240
+ ```bash
241
+ # init
242
+ workgraph init /path/to/ws --json
243
+
244
+ # threads
245
+ workgraph thread create "Title" --goal "Outcome" --actor me --json
246
+ workgraph thread list --json
247
+ workgraph thread list --ready --json
248
+ workgraph thread next --claim --actor me --json
249
+ workgraph thread claim threads/x.md --actor me --json
250
+ workgraph thread block threads/x.md --blocked-by external/api --reason "Waiting token" --actor me --json
251
+ workgraph thread unblock threads/x.md --actor lead --json
252
+ workgraph thread done threads/x.md --actor me --output "Shipped" --json
253
+
254
+ # primitives
255
+ workgraph primitive define type-name --description "..." --fields key:string --actor me --json
256
+ workgraph primitive create type-name "Instance Title" --set key=value --actor me --json
257
+ workgraph primitive list --json
258
+
259
+ # bases
260
+ workgraph bases sync-registry --json
261
+ workgraph bases generate --json
262
+ workgraph bases generate --all --refresh-registry --json
263
+
264
+ # ledger
265
+ workgraph ledger show --count 30 --json
266
+ workgraph ledger claims --json
267
+ workgraph ledger history threads/x.md --json
268
+ workgraph ledger query --actor me --op claim --json
269
+ workgraph ledger blame threads/x.md --json
270
+ workgraph ledger verify --strict --json
271
+ workgraph ledger seal --json
272
+
273
+ # command center
274
+ workgraph command-center --output "ops/Command Center.md" --json
275
+
276
+ # skills
277
+ workgraph skill write "name" --body-file ./skills/name.md --actor me --json
278
+ workgraph skill load name --json
279
+ workgraph skill propose name --actor me --json
280
+ workgraph skill promote name --actor me --json
281
+ ```
282
+
283
+ ## Anti-Patterns
284
+
285
+ - Using workgraph as a dumping ground for unstructured notes.
286
+ - Skipping `--actor` on mutating operations.
287
+ - Parsing text output in automation instead of `--json`.
288
+ - Treating `open` as implicitly claimable without readiness checks.
289
+
290
+ ## Migration Guidance (from memory-heavy flows)
291
+
292
+ If your agents currently use broad memory categories for execution coordination:
293
+
294
+ 1. Move active execution tasks into `thread` primitives.
295
+ 2. Store governance facts as `decision`/`fact` primitives if needed.
296
+ 3. Keep long-term memory in a separate system/package.
297
+ 4. Use workgraph only for active multi-agent execution topology.
298
+
299
+ ## Split Clarification
300
+
301
+ - `clawvault` package: memory + retrieval + broader vault lifecycle.
302
+ - `@clawvault/workgraph` package: coordination substrate only.
303
+
304
+ Treat this package as the authoritative runtime for multi-agent primitives and claims, not as a memory taxonomy tool.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import('../dist/cli.js');