@haaaiawd/loom 2.0.1 → 2.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.
@@ -12,6 +12,21 @@ answers, update the emerging whole and ask again only where important uncertaint
12
12
  human delegates a reversible decision, make and record a project-specific judgment. When they insist
13
13
  on skipping clarification, state the concrete risk once, record the assumption, and continue.`;
14
14
 
15
+ export function environmentProtocol({ humanChannel = 'available' } = {}) {
16
+ if (!['available', 'unavailable'].includes(humanChannel)) throw new Error('humanChannel must be available or unavailable');
17
+ if (humanChannel === 'available') return `## Environment availability
18
+
19
+ A human response channel is available. First inspect facts discoverable from the workspace, tests, tools, and
20
+ permitted sources. Ask the human only for consequential intent, authority, preference, or information they uniquely hold.`;
21
+ return `## Environment availability
22
+
23
+ Human response channel: unavailable. Do not fabricate a user interaction. First inspect facts discoverable from
24
+ the workspace, tests, and available tools. Research only objective external facts when the task and host permit it;
25
+ never use web research as a substitute for user intent, preference, or authority. When a consequential answer remains
26
+ unavailable, record a bounded assumption and choose a safe reversible action, or block when the action is irreversible,
27
+ high-risk, or materially costly.`;
28
+ }
29
+
15
30
  export const RUNTIME_PROTOCOL = `# LOOM runtime protocol
16
31
 
17
32
  LOOM is invisible continuity infrastructure for the Agent. The human talks naturally to you; use the
@@ -19,7 +34,7 @@ CLI silently and never make the human maintain LOOM files or state.
19
34
 
20
35
  ## Shape the whole before material execution
21
36
 
22
- Maintain four distinct layers:
37
+ Maintain five distinct layers:
23
38
 
24
39
  1. \`.loom/PROJECT.md\` is the concise entry point and map of the current whole.
25
40
  2. \`.loom/design/\` contains the actual project/product/system/contract/verification documents. Split
@@ -31,8 +46,18 @@ Maintain four distinct layers:
31
46
  pharmacology, security, or distributed systems. Do not merge fields into a clever hybrid title and
32
47
  do not mistake a task technique such as ranking, triage, parsing, or caching for the project's entire
33
48
  capability surface. Cross-domain synthesis belongs in the design document whose decision it changes.
49
+ Each dossier is a research directory containing a decision-tree capability file, a research folder of
50
+ expert narratives and sources, and a status file tracking the shaping lifecycle. The kernel of a
51
+ dossier is a conditional-branch decision tree — how an expert in this field thinks through this
52
+ project's problems — not a fixed step list or a declarative stance. Every decision node carries a
53
+ source citation and a counterexample. The tree is a resource for the Agent, not a script; when
54
+ evidence points outside it, the Agent updates the tree rather than ignoring the evidence.
34
55
  4. \`.loom/tasks.json\` is a restartable Work Map. Every Task names the exact design documents,
35
56
  capability dossiers, source files, fixtures, and contracts it must read.
57
+ 5. \`.loom/STRUCTURE.md\` declares where project files live — source code, tests, docs, configs,
58
+ assets. The Agent reads this before creating or moving files so the project stays organized
59
+ without the human having to redirect every placement. Customize it for each project; LOOM does
60
+ not prescribe a fixed directory layout.
36
61
 
37
62
  Start from the desired result, inspect the workspace when relevant, describe the emerging whole
38
63
  naturally, and identify the current uncertainty frontier. After every answer round, update project
@@ -44,9 +69,21 @@ be observed.
44
69
 
45
70
  Identify capabilities at the level of established professional fields. Create separate dossiers when
46
71
  different fields use different evidence, make different judgments, or could disagree. A dossier is not
47
- a textbook summary or a costume labelled "expert". It must show a distinctive project-specific stance,
48
- opened sources when research was used, rejected generic defaults, concrete consequences for design and
49
- implementation, characteristic failure modes, and observable verification signals.
72
+ a textbook summary or a costume labelled "expert". Its kernel is a conditional-branch decision tree
73
+ that captures how an expert in this field thinks through this project's problems — not a fixed step
74
+ list. Each decision node carries an entry condition, options, judgment criteria, a source citation,
75
+ a counterexample, and an output. Nodes without sources are not accepted; branches without
76
+ counterexamples are fixed steps in disguise.
77
+
78
+ Build dossiers in four steps: research (collect expert narratives, case studies, and methodology
79
+ sources), synthesize (construct the project-specific decision tree from research), confirm (the user
80
+ confirms which expert scenario this project most resembles — the Agent must not decide this alone),
81
+ and confirmed. \`loom capability research\` creates a \`_guide.md\` in the research directory explaining
82
+ what to write — create one .md file per source, citing where the knowledge came from. \`loom capability
83
+ synthesize\` reads those files and validates that every decision tree node has a source citation and a
84
+ counterexample. A dossier that has not been confirmed should not be referenced by Tasks, but the
85
+ Agent may proceed provisionally when the user is unavailable and record the assumption. Confirmed
86
+ dossiers can be reopened when new evidence changes the professional reasoning.
50
87
 
51
88
  Do not force every conceivable field into the project. Include a field only when its knowledge changes
52
89
  questions, a design decision, implementation, risk handling, or verification. If the work needs several
@@ -54,10 +91,36 @@ fields, preserve each field's identity and synthesize them explicitly in the aff
54
91
 
55
92
  ## Build a restartable Work Map
56
93
 
57
- Plan the whole delivery at milestone resolution, then keep the active horizon detailed. A Task records
58
- an outcome, observable done conditions, boundaries, dependencies, exact reads, expected touches,
59
- progress, next action, and evidence. A long project may have many Tasks, but do not pre-write thousands
60
- of speculative micro-steps. Split and revise the map as reality becomes clearer.
94
+ Plan the whole delivery surface first, then decompose into Tasks at a granularity where each Task
95
+ produces one verifiable unit of real work. A Task that says "implement the feature" is too large; a
96
+ Task that says "add one field to one struct" is too small. The right granularity is: one Task produces
97
+ one piece of evidence you can point to and say "this is done and here is how I know."
98
+
99
+ Each Task records:
100
+ - **outcome**: what changes in the world when this Task is done — not a summary of activity, but the
101
+ observable difference. At least one sentence with a concrete noun.
102
+ - **acceptance**: an array of conditions, each pairing three things —
103
+ - \`criterion\`: what must be true for this condition to pass (observable, not aspirational)
104
+ - \`verify_by\`: how to check — run a test, walk through a flow, review against a design, inspect a
105
+ dashboard, ask an editor. LOOM does not prescribe the method; the field does.
106
+ - \`evidence\`: what the proof looks like when done — a test log, a screenshot, a review record, a
107
+ monitoring snapshot. Plan it before starting; fill in the actual result when completing.
108
+ - **boundaries**: what this Task does NOT do. At least one. Without boundaries a Task grows until it
109
+ becomes the whole project.
110
+ - **reads**: every file, document, or artifact the Agent must consume to do this Task. Must be specific
111
+ paths, not categories. If the Agent needs it, list it; if it is not listed, the Agent should not
112
+ depend on it.
113
+ - **touches**: every file, document, or artifact the Task is expected to produce or modify. Must be
114
+ specific paths. A Task that touches nothing is not a Task.
115
+ - **depends_on**: other Tasks that must be done first. Empty is valid only when this Task has no
116
+ prerequisites.
117
+ - **covers**: which delivery units this Task advances. Use this to check that the delivery surface is
118
+ fully covered.
119
+
120
+ A long project may have many Tasks. Do not pre-write thousands of speculative micro-steps — split and
121
+ revise the map as reality becomes clearer. But do not leave the map at five vague placeholders either.
122
+ Each Task should be small enough that its acceptance conditions are concrete, and large enough that
123
+ completing it means something real shipped.
61
124
 
62
125
  Before engineering or another material operation begins, tell the human what is about to happen and
63
126
  which consequential assumptions remain. Ordinary reversible work needs no extra ceremony; irreversible,
@@ -70,66 +133,100 @@ answers and decisions -> update design and capability maps -> repeat while mater
70
133
 
71
134
  Keeper loop: prepare a frozen digest -> fresh Keeper attempts to start from disk -> on
72
135
  \`needs_revision\` or \`blocked\`, absorb every concrete gap into project truth, design docs, capability
73
- dossiers, or Tasks -> prepare a changed digest -> use another fresh Keeper. Keeper passes only once the
74
- handoff is genuinely buildable; it does not reappear for every Task.
136
+ dossiers, or Tasks -> prepare a changed digest. When all gaps are minor and 3 or fewer, fixing them
137
+ and running \`loom project ready\` auto-passes without a new Keeper round; otherwise another fresh
138
+ Keeper is required. Keeper does not reappear for every Task.
75
139
 
76
140
  Delivery loop: select an executable Task -> load exactly referenced context -> implement and verify ->
77
- map every done condition to concrete evidence -> complete, block with recovery conditions, or reopen a
78
- blocked or disproven completion after upstream correction ->
79
- continue. When the human changes a consequential prior answer, preserve the superseding decision and
80
- repair affected documents and Tasks before continuing.`;
81
-
82
- export const AGENT_PROTOCOL = `${AGENT_CORE}\n\n${RUNTIME_PROTOCOL}`;
83
-
84
- export const EXECUTION_PROTOCOL = `# LOOM active Task execution protocol
85
-
86
- This block applies only when a Task is active or explicitly loaded. Treat the disk state below as the
87
- recovery source; conversation memory may be incomplete.
88
-
89
- ## Recover before changing anything
90
-
91
- 1. Re-read the Task outcome, exact done_when criteria, boundaries, dependencies, reads, expected
92
- touches, progress, next action, and existing evidence. Read every injected Task context file.
93
- 2. Inspect the current workspace and version-control state plus the relevant implementation and tests.
94
- Preserve user changes. If the Task conflicts with discoverable reality, update or block the Task instead
95
- of silently following stale context or inventing missing facts.
96
- 3. Resume from progress.next when it remains valid. Otherwise choose the smallest complete next action
97
- that advances the outcome and can be checked against a done condition.
98
-
99
- ## Build and prove the smallest complete change
100
-
101
- - Stay inside the outcome and boundaries. If implementation requires a wider system, authority, risk, or
102
- file surface than the Task describes, repair the Task or upstream design first.
103
- - Inspect the relevant existing tests before editing. When observable behavior changes and a stable test
104
- seam exists, add or update the smallest test that can fail for the missing behavior, then implement and
105
- run it. Documentation, research, configuration, and operational Tasks use the verification appropriate
106
- to their claim; do not manufacture a ceremonial unit test.
107
- - Iterate on local failures while the Task remains active. If the failure exposes an upstream design gap,
108
- unavailable authority, or external dependency, block with concrete recovery conditions rather than
109
- broadening scope invisibly.
110
-
111
- ## Leave a restartable handoff
112
-
113
- - After a material checkpoint, before an expected context reset, or when handing work to another Agent,
114
- persist concise completed, current, and executable next progress with loom task update.
115
- Record evidence only after the referenced command, artifact, or observation actually exists.
116
- - Complete through loom task done only after every exact done_when criterion has reproducible
117
- evidence. Report known blind spots and unverified boundaries honestly.
118
- - A branch, commit, or pull request is a delivery mechanism, not a universal Task requirement. Create one
119
- when the human or repository workflow asks for it, map it to the Task outcome, and include the verification
120
- evidence; do not use a PR to disguise an incomplete Task.
121
-
122
- Do not narrate this protocol to the human unless it helps them understand a decision, risk, or handoff.`;
141
+ fill in each acceptance condition's evidence with the actual result -> complete, block with recovery
142
+ conditions, or reopen a blocked or disproven completion after upstream correction ->
143
+ continue.
144
+
145
+ Evolution loop: when a new idea changes an existing decision, record what changed and why with
146
+ \`loom decision --json-file\` (listing affected files and tasks), then update the design document
147
+ directly — the current truth always lives in \`.loom/\`, not in versioned snapshots. If the change
148
+ affects completed Tasks, \`loom check\` warns which done Tasks were marked affected; reopen them when
149
+ the change invalidates prior work. Git history preserves old versions; LOOM does not duplicate version
150
+ numbers. The project has one current truth at a time.`;
151
+
152
+ export function agentProtocol(options = {}) {
153
+ return `${AGENT_CORE}\n\n${environmentProtocol(options)}\n\n${RUNTIME_PROTOCOL}`;
154
+ }
155
+
156
+ export const AGENT_PROTOCOL = agentProtocol();
157
+
158
+ export const EXECUTION_PROTOCOL = `# LOOM active Task execution protocol
159
+
160
+ This block applies only when a Task is active or explicitly loaded. Treat the disk state below as the
161
+ recovery source; conversation memory may be incomplete.
162
+
163
+ ## Recover before changing anything
164
+
165
+ 1. Re-read the Task outcome, acceptance conditions (criterion, verify_by, evidence), boundaries,
166
+ dependencies, reads, expected touches, progress, next action, and existing evidence. Read every
167
+ injected Task context file.
168
+ 2. If the Task carries capability_hooks, treat them as professional reasoning you can use not a script
169
+ you must follow. Each hook points to a specific node (e.g. \`ui-ux-design#C2\`) with entry conditions,
170
+ options, judgment criteria, a source citation, and a counterexample. Use them to inform your judgment.
171
+ If the node's entry condition is not met, skip it. If the evidence points somewhere the tree does not
172
+ cover, trust the evidence and update the capability. If a hook's must_produce field names an artifact,
173
+ produce it before completing the Task.
174
+ 3. Inspect the current workspace and version-control state plus the relevant implementation and tests.
175
+ Preserve user changes. If the Task conflicts with discoverable reality, update or block the Task instead
176
+ of silently following stale context or inventing missing facts.
177
+ 4. Resume from progress.next when it remains valid. Otherwise choose the smallest complete next action
178
+ that advances the outcome and can be checked against a done condition.
179
+
180
+ ## Build and prove the smallest complete change
181
+
182
+ - Stay inside the outcome and boundaries. If implementation requires a wider system, authority, risk, or
183
+ file surface than the Task describes, repair the Task or upstream design first.
184
+ - Inspect the relevant existing tests before editing. When observable behavior changes and a stable test
185
+ seam exists, add or update the smallest test that can fail for the missing behavior, then implement and
186
+ run it. Documentation, research, configuration, and operational Tasks use the verification appropriate
187
+ to their claim; do not manufacture a ceremonial unit test.
188
+ - Iterate on local failures while the Task remains active. If the failure exposes an upstream design gap,
189
+ unavailable authority, or external dependency, block with concrete recovery conditions rather than
190
+ broadening scope invisibly.
191
+
192
+ ## Leave a restartable handoff
193
+
194
+ - After a material checkpoint, before an expected context reset, or when handing work to another Agent,
195
+ persist concise completed, current, and executable next progress with loom task update.
196
+ Record evidence only after the referenced command, artifact, or observation actually exists.
197
+ - Complete through loom task done only after every acceptance condition has its evidence filled
198
+ with a reproducible result. Report known blind spots and unverified boundaries honestly.
199
+ - A branch, commit, or pull request is a delivery mechanism, not a universal Task requirement. Create one
200
+ when the human or repository workflow asks for it, map it to the Task outcome, and include the verification
201
+ evidence; do not use a PR to disguise an incomplete Task.
202
+
203
+ ## Show progress and review at checkpoints
204
+
205
+ The human's patience is the project's fuel. Do not let several Tasks pass in silence.
206
+
207
+ - **After each Task**: if the Task produced something the human can see or run, show it — run the command,
208
+ open the page, display the output. One real working thing is worth more than a status line.
209
+ - **Every few Tasks or at a natural milestone**: do a staged review. Run the project's own tests, inspect
210
+ code quality against the design intent, and tell the human what passed and what surprised you. Catch
211
+ drift while it is cheap to fix.
212
+ - **Before declaring a batch done**: run \`loom check\` and the project's own tests together. Both must
213
+ pass. If tests fail or coverage drops, fix before moving on — do not let partial work accumulate behind
214
+ a green-looking summary.
215
+ - **Prioritize the exciting surface**: if the project has a surface the human will enjoy — a UI, clean CLI
216
+ output, a visualization, a working demo — reach an early slice of it sooner rather than saving it for
217
+ last. The human's "I want to see more" feeling is real project fuel.
218
+
219
+ Do not narrate this protocol to the human unless it helps them understand a decision, risk, or handoff.`;
123
220
 
124
221
  export const AGENT_ANCHOR = `<!-- loom:v2 -->
125
222
  ## LOOM
126
223
 
127
- This project uses LOOM as Agent-only continuity infrastructure. Run \`loom context\` when entering the
128
- project, after a context reset, and before substantial work. When a Task is active, the command restores
129
- its execution protocol, exact state, and declared context; rerun it before editing after any interruption.
130
- Keep project truth, design documents, professional capability dossiers, and Tasks current through the CLI,
131
- and never ask the human to operate LOOM. Do not rerun LOOM before every tool call: persist and restore at
132
- meaningful work boundaries.`;
224
+ This project uses LOOM as Agent-only continuity infrastructure. Run \`loom context\` when entering the
225
+ project, after a context reset, and before substantial work. When a Task is active, the command restores
226
+ its execution protocol, exact state, and declared context; rerun it before editing after any interruption.
227
+ Keep project truth, design documents, professional capability dossiers, and Tasks current through the CLI,
228
+ and never ask the human to operate LOOM. Do not rerun LOOM before every tool call: persist and restore at
229
+ meaningful work boundaries.`;
133
230
 
134
231
  function renderKeeperGap(item) {
135
232
  if (typeof item === 'string') return ` - ${item}`;
@@ -184,7 +281,41 @@ You are a fresh Agent with no access to the shaping conversation. Do not repair
184
281
  edit implementation. Use only this workspace and the LOOM CLI. Run \`loom context --keeper\`, inspect
185
282
  the referenced files, and attempt a real handoff from disk.
186
283
 
187
- Judge buildability, not document polish or document count. Demonstrate whether you can:
284
+ Your job is a Crux review: check that the chain from responsible intent to verifiable behavior is intact.
285
+ Do not judge document polish or count. Judge whether a fresh Agent could start from disk and still
286
+ produce what the human actually wants.
287
+
288
+ ## Integrity chain check
289
+
290
+ Walk this chain and look for the six distortions:
291
+
292
+ 1. **Responsible intent** — What should exist or become possible? Who or what experiences it? What are
293
+ the non-negotiable boundaries and accepted tradeoffs?
294
+ 2. **Project promises** — Does PROJECT.md still express that intent, or has it drifted into document
295
+ self-reference? Are the design documents and capability maps tied to the same goal?
296
+ 3. **Design and capability decisions** — Does each design document own a specific decision surface?
297
+ Does each capability dossier represent a recognizable field with source-cited, counterexample-backed
298
+ decision nodes? Are capability and design synthesis in the right place?
299
+ 4. **Work Map** — Are Tasks at evidence granularity? Do they read the right documents, touch the right
300
+ files, and state clear boundaries and acceptance conditions? Is the first executable Task responsible?
301
+ 5. **Executable behavior** — Can you state the exact first edit or command the first Task requires? Can
302
+ you find or infer the tests, commands, or observations that would prove completion?
303
+ 6. **Human feedback loop** — Is there a clear, observable completion signal? Could the human recognize
304
+ whether the result matched their intent without being a LOOM operator?
305
+
306
+ Look for these specific distortions:
307
+
308
+ - **Omission**: intent, boundary, or decision that exists in conversation but not in the documents.
309
+ - **Substitution**: a document, metric, or local optimization presented as the real result.
310
+ - **Drift**: a later design or Task that silently changed the intent, boundary, or accepted tradeoff.
311
+ - **Leap**: a claim that jumps from design to implementation without a verifiable bridge.
312
+ - **Blindness**: a key state the project cannot observe, such as whether a fresh Agent can start, whether
313
+ a done Task has real evidence, or whether a design document is stale.
314
+ - **Ownerless**: an exception, contradiction, or long-term maintenance item with no responsible party.
315
+
316
+ ## Buildability check
317
+
318
+ After the integrity chain, also demonstrate whether you can:
188
319
 
189
320
  1. Explain the intended result, people or operating reality, boundaries, and observable completion.
190
321
  2. Navigate PROJECT.md into the necessary product, experience, system, contract, operations, and
@@ -202,7 +333,10 @@ This is Keeper attempt ${attemptNumber || '<unknown>'}. The frozen prepared dige
202
333
  include both run_id and prepared_digest in the result.
203
334
 
204
335
  Use this result shape. Keep \`gaps\` empty on pass; otherwise prefer structured gaps so the next Agent
205
- receives the reason and closure evidence without interpretation loss:
336
+ receives the reason and closure evidence without interpretation loss. Mark each gap with severity
337
+ \`blocking\` (a fresh Agent cannot start without this being fixed) or \`minor\` (an improvement that
338
+ does not block the first Task). When all gaps are minor and there are 3 or fewer, LOOM will auto-pass
339
+ after the gaps are fixed without requiring another Keeper round:
206
340
 
207
341
  \`\`\`json
208
342
  {
@@ -213,6 +347,7 @@ receives the reason and closure evidence without interpretation loss:
213
347
  "gaps": [
214
348
  {
215
349
  "gap": "<missing or contradictory truth>",
350
+ "severity": "blocking | minor",
216
351
  "why_it_blocks_start": "<concrete consequence for a fresh Agent>",
217
352
  "evidence_to_close": "<observable condition that would close it>"
218
353
  }
@@ -225,13 +360,15 @@ Record the result with \`loom keeper record --json-file <result.json>\`. Use \`p
225
360
  could responsibly begin the first Task. Otherwise use \`needs_revision\` with concrete gaps and the
226
361
  observable evidence that would close each one, or \`blocked\` when progress requires unavailable
227
362
  authority or external state. A failed attempt returns the project to shaping; revision requires a
228
- changed digest and another fresh Keeper.`;
363
+ changed digest. When all gaps are minor and 3 or fewer, fixing them and running \`loom project ready\`
364
+ will auto-pass without a new Keeper round; otherwise another fresh Keeper is required.`;
229
365
  }
230
366
 
231
367
  export const PROJECT_TEMPLATE = `# Project Whole and Document Map
232
368
 
233
369
  > This is the concise entry point, not the container for every design decision. Describe the whole and
234
370
  > link the documents that make it buildable. Add or remove documents according to project complexity.
371
+ > The Agent uses \`loom context\` to compile this with the active Task and referenced files.
235
372
 
236
373
  ## Intended result
237
374
 
@@ -256,16 +393,98 @@ decision surface it owns. Complex subsystems should have their own files under \
256
393
 
257
394
  ## Professional capability map
258
395
 
259
- Link each separate field dossier under \`.loom/capabilities/\` and state which design decisions it
260
- changes. Do not merge distinct fields into one dossier.
396
+ Link each separate field dossier under \`.loom/capabilities/<field>/capability.md\` and state which
397
+ design decisions it changes. Do not merge distinct fields into one dossier. Capabilities are shaped in
398
+ four steps: \`loom capability research\` → \`synthesize\` → \`confirm\` (user confirms the scenario).
399
+
400
+ ## Project structure
401
+
402
+ Point to \`.loom/STRUCTURE.md\` — where source code, tests, docs, assets, and configuration files live.
403
+ The Agent reads this before creating or moving files.
404
+
405
+ ## Work map
406
+
407
+ Point to \`.loom/tasks.json\`; do not duplicate volatile Task state here. Each Task uses
408
+ \`acceptance[]\` with \`criterion\`, \`verify_by\`, and \`evidence\` fields. Completion requires one
409
+ \`acceptance_results\` entry per criterion with concrete evidence. Use \`done_when[]\` only for legacy
410
+ Tasks.
411
+
412
+ ## Decision history
413
+
414
+ Consequential changes to existing decisions go in \`.loom/DECISIONS.md\`. Use \`loom decision --json-file\`
415
+ to record what changed, why, and which tasks were affected. \`loom check\` warns when a done Task is
416
+ marked affected by a later decision.
261
417
 
262
418
  ## Completion and failure
263
419
 
264
420
  What observable evidence means the project worked? What could look complete while actually failing?
265
421
 
266
- ## Work map
422
+ ## Staged visibility and review
423
+
424
+ The human funds this project with attention and patience. Long stretches without visible progress
425
+ erode that patience, even when the work is sound. Design the Work Map so the human sees the project
426
+ growing, not just LOOM state changing.
427
+
428
+ - **Human-visible acceptance**: when designing Tasks, prefer acceptance criteria whose evidence is
429
+ something the human can see or feel — a command running, a page rendering, a file with real content,
430
+ a test passing in front of them. Machine-only verification is valid but should not be the only thing
431
+ the human sees for long stretches.
432
+ - **Staged showcase**: every few Tasks, or at each natural project milestone, show the human something
433
+ real that now works. Run the CLI, open the page, display the data, walk through the flow. A working
434
+ thing creates momentum; a status update does not.
435
+ - **Staged review**: at material checkpoints, review what was built — run tests, inspect code quality,
436
+ check against design intent. Catch drift early while it is cheap to fix. Tell the human what passed
437
+ and what surprised you.
438
+ - **Verification gate**: after a batch of Tasks, run \`loom check\` and the project's own tests together.
439
+ Both should pass before telling the human the batch is done. If tests fail or coverage drops, fix
440
+ before moving on — do not let partial work accumulate behind a green-looking summary.
441
+ - **Excitement is a feature**: if the project has a surface the human will enjoy seeing — a UI, a CLI
442
+ with clean output, a visualization, a working demo — prioritize reaching that surface early. The
443
+ human's "I want to see more of this" feeling is real project fuel. Do not save the satisfying part
444
+ for last if an early slice can deliver it.
445
+
446
+ ## Keeper handoff
447
+
448
+ Before material execution, run \`loom project ready\` to freeze a digest, then ask a fresh Agent to
449
+ run \`loom keeper prompt\` and \`loom keeper record\`. If the Keeper returns only minor gaps (3 or fewer),
450
+ fixing them and running \`loom project ready\` again auto-passes without another Keeper round.
451
+ `;
452
+
453
+ export const STRUCTURE_TEMPLATE = `# Project structure
454
+
455
+ > Where things live in this project. The Agent reads this before creating or moving files.
456
+ > Update this when the structure changes. Delete sections that do not apply. Add sections
457
+ > that do. This is a map, not a prescription — each project declares its own conventions.
458
+
459
+ ## Source code
460
+
461
+ Where implementation files go. Example: \`src/\` for application logic, \`src/core/\` for
462
+ domain logic, \`src/cli/\` for command-line interface.
463
+
464
+ ## Tests
465
+
466
+ Where test files go and how they mirror source structure. Example: \`tests/\` mirroring
467
+ \`src/\` layout, or \`__tests__/\` co-located with source.
468
+
469
+ ## Documents
267
470
 
268
- Explain the delivery shape and point to \`.loom/tasks.json\`; do not duplicate volatile Task state here.
471
+ Where project documentation goes (excluding \`.loom/\` which is LOOM state). Example:
472
+ \`docs/\` for user-facing docs, \`README.md\` at root for entry.
473
+
474
+ ## Configuration and build
475
+
476
+ Where build configs, CI definitions, and dependency manifests go. Example:
477
+ \`package.json\`, \`.github/workflows/\`, \`tsconfig.json\`.
478
+
479
+ ## Assets and fixtures
480
+
481
+ Where static assets, test fixtures, and data files go. Example: \`assets/\`, \`fixtures/\`,
482
+ \`data/\`.
483
+
484
+ ## Conventions
485
+
486
+ Any naming or placement conventions the Agent should follow. Example: "one module per
487
+ file", "test files end with \`.test.\`", "config files are JSON not YAML".
269
488
  `;
270
489
 
271
490
  const DESIGN_SECTIONS = {
@@ -291,53 +510,115 @@ export const CAPABILITY_TEMPLATE = ({ title }) => `# ${title}
291
510
  > One dossier covers one recognizable professional field. Keep UI/UX, visual art direction, game
292
511
  > design, psychology, biology, security, and other fields separate when their evidence and judgments
293
512
  > differ. Put cross-field synthesis in the affected design document, not in a hybrid capability title.
513
+ > The kernel of a capability is a decision tree with conditional branches that captures how an expert
514
+ > in this field thinks — not a fixed step list or a declarative stance document. It is a resource for
515
+ > the Agent to use, not a script it must follow. When evidence points outside the tree, trust the
516
+ > evidence and update the tree.
294
517
 
295
518
  ## Field identity and boundary
296
519
 
297
520
  Name the established field, what expertise it contributes, and what belongs to another dossier.
298
521
 
299
- ## Project decisions this field changes
522
+ ## Project scenario
300
523
 
301
- Identify the consequential questions, design choices, risks, or verification methods that would be
302
- weaker without this field.
524
+ > This section records the user-confirmed project scenario: which expert situation this project most
525
+ > closely resembles. The Agent must not fill this alone; it requires user confirmation via
526
+ > \`loom capability confirm <slug> --scenario <text>\`.
303
527
 
304
- ## Project-specific diagnosis
528
+ State the project scenario that determines which branches of the decision tree are active.
305
529
 
306
- Interpret this project's users, constraints, existing evidence, and tensions through this field. Show
307
- authored judgment rather than a generic overview.
530
+ ## Decision tree
308
531
 
309
- ## Principles, evidence, and sources
532
+ > Each node is a named decision point an expert reaches in this field. Nodes have entry conditions,
533
+ > conditional options, judgment criteria, source citations, counterexamples, and outputs. A node
534
+ > without a source citation is not accepted. A branch without a counterexample is a fixed step in
535
+ > disguise.
310
536
 
311
- Record specialist principles and opened sources when research is used. State what each source changed,
312
- where sources disagree, and what remains uncertain.
537
+ ### C1: <node name>
313
538
 
314
- ## Distinctive stance and rejected defaults
539
+ - entry_when: <condition under which an expert arrives at this node>
540
+ - options:
541
+ - A: <option A> → leads_to: <next node or output>
542
+ - B: <option B> → leads_to: <next node or output>
543
+ - decide_by: <evidence that determines which option to take>
544
+ - source: <which research material or expert narrative supports this node>
545
+ - counterexample: <a situation where an expert would NOT walk this path>
546
+ - output: <what this node produces — typically a design decision>
315
547
 
316
- State what this project will do, why, the important tradeoffs, and which common or generic approaches it
317
- will deliberately refuse.
548
+ ### C2: <node name>
318
549
 
319
- ## Consequences for design, implementation, and verification
550
+ <repeat the structure above for each decision node>
320
551
 
321
- Translate the field's stance into concrete requirements and link the design documents it affects.
552
+ ## Stance and rejected defaults
322
553
 
323
- ## Questions that could change the stance
554
+ > The stance is subordinate to the decision tree. It records what this project refuses and why, but
555
+ > the decision tree carries the thinking process.
324
556
 
325
- Keep only unresolved questions whose answers would materially alter this field's contribution.
557
+ State what this project will do, why, the important tradeoffs, and which common or generic approaches it
558
+ will deliberately refuse.
326
559
 
327
- ## Failure modes and proof signals
560
+ ## Failure signals
328
561
 
329
562
  Describe characteristic weak, generic, or harmful outcomes and the observable evidence that distinguishes
330
- a strong result.
563
+ a strong result. Experts know when they have gone wrong — record those signals here.
331
564
 
332
565
  ## Relationships without merger
333
566
 
334
567
  Link adjacent capability dossiers and explain the tension or handoff. Do not absorb their expertise here.
335
568
  `;
336
569
 
337
- export function evalConditionPrompt({ brief, loom }) {
570
+ export const RESEARCH_GUIDE = `# Research guide for this capability
571
+
572
+ > This file guides what to write in the research/ directory. Delete it when you have added your own
573
+ > research materials. \`loom capability synthesize\` reads all .md files in this directory (except this
574
+ > guide) and expects them to contain expert narratives, case studies, or methodology sources that
575
+ > inform the decision tree.
576
+
577
+ ## What to write
578
+
579
+ Create one .md file per research source. Each file should answer: **how does an expert in this field
580
+ think through the problems this project faces?**
581
+
582
+ Good research materials include:
583
+ - Expert narratives: how a practitioner describes their own decision process
584
+ - Case studies: real projects where this field's decisions mattered, and what happened
585
+ - Methodology sources: established frameworks, heuristics, or principles from the field
586
+ - Failure accounts: what went wrong when the field's judgment was absent or ignored
587
+
588
+ Bad research materials (will produce weak decision trees):
589
+ - Generic textbook summaries with no project-specific relevance
590
+ - Tool documentation or API references (those are not professional judgment)
591
+ - Marketing copy or opinion pieces without evidence
592
+
593
+ ## File format
594
+
595
+ Name files descriptively: \`expert-decision-process.md\`, \`case-study-X.md\`, \`failure-account-Y.md\`.
596
+ Each file should be 1-3 paragraphs of substantive content. Include the source at the top:
597
+
598
+ \`\`\`markdown
599
+ # <descriptive title>
600
+
601
+ Source: <book, article, interview, observation, or personal experience>
602
+
603
+ <content: how the expert thinks, what they decided, what evidence they used, what happened>
604
+ \`\`\`
605
+
606
+ ## How this feeds synthesize
607
+
608
+ \`loom capability synthesize\` checks that:
609
+ 1. At least one .md file exists in research/ (besides this guide)
610
+ 2. Every decision tree node (### C1, C2, ...) in capability.md has a \`source:\` field
611
+ 3. Every node has a \`counterexample:\` field
612
+
613
+ The source field in each node should reference which research file supports it. Write research that
614
+ you can cite by name when you build the decision tree.
615
+ `;
616
+
617
+ export function evalConditionPrompt({ brief, loom, humanChannel = 'available' }) {
618
+ const environment = environmentProtocol({ humanChannel }).replace('## Environment availability\n\n', '');
338
619
  return loom
339
- ? `# Evaluation condition\n\n${brief}\n\nWork with all ordinary Agent capabilities and tools. Use LOOM as invisible continuity infrastructure: run \`loom context\`, maintain its disk state, and never ask the human to operate it. This condition has no extra authority or information.`
340
- : `# Evaluation condition\n\n${brief}\n\nWork as a normal capable Agent with all ordinary capabilities and tools. LOOM and its files are unavailable in this condition. Use any normal planning or documentation you judge useful.`;
620
+ ? `# Evaluation condition\n\n${brief}\n\n${environment}\n\nWork with all ordinary Agent capabilities and tools. Use LOOM as invisible continuity infrastructure: run \`loom context --human-channel ${humanChannel}\`, maintain its disk state, and never ask the human to operate it. This condition has no extra authority or information.`
621
+ : `# Evaluation condition\n\n${brief}\n\n${environment}\n\nWork as a normal capable Agent with all ordinary capabilities and tools. LOOM and its files are unavailable in this condition. Use any normal planning or documentation you judge useful.`;
341
622
  }
342
623
 
343
624
  export function evalJudgePrompt() {
@@ -378,20 +659,23 @@ export function promptCatalog() {
378
659
  };
379
660
  return {
380
661
  purpose: 'Complete inventory of LOOM cognitive messages. Validation errors and JSON status payloads enforce state but are not Agent prompts.',
381
- layers: {
382
- stable_core: AGENT_CORE,
383
- runtime_protocol: RUNTIME_PROTOCOL,
384
- execution_protocol: EXECUTION_PROTOCOL,
662
+ layers: {
663
+ stable_core: AGENT_CORE,
664
+ environment_adaptation_available: environmentProtocol({ humanChannel: 'available' }),
665
+ environment_adaptation_unavailable: environmentProtocol({ humanChannel: 'unavailable' }),
666
+ runtime_protocol: RUNTIME_PROTOCOL,
667
+ execution_protocol: EXECUTION_PROTOCOL,
385
668
  project_state: shapingContext({ state: placeholderState, taskSummary: { total: 0, done: 0, open: 0, blocked: 0, active: null }, capabilityNames: [], designNames: [] }),
386
- project_state_after_keeper_failure: shapingContext({ state: revisionState, taskSummary: { total: 1, done: 0, open: 1, blocked: 0, active: null }, capabilityNames: ['<field>.md'], designNames: ['<system>.md'] }),
387
- keeper_review_of_prior_failure: shapingContext({ state: revisionState, taskSummary: { total: 1, done: 0, open: 1, blocked: 0, active: null }, capabilityNames: ['<field>.md'], designNames: ['<system>.md'], forKeeper: true }),
388
- current_task: '## Active Task\n\n<exact Task JSON>\n\n---\n\n## Task context: <path from Task.reads>\n\n<exact file content>\n\n(repeated for every read path)',
389
- on_demand_map: '## On-demand project context\n\n- Decision history: .loom/DECISIONS.md (read when correction or lineage matters)\n- Design: .loom/design/<document>.md\n- Professional capability: .loom/capabilities/<field>.md',
669
+ project_state_after_keeper_failure: shapingContext({ state: revisionState, taskSummary: { total: 1, done: 0, open: 1, blocked: 0, active: null }, capabilityNames: ['<field>'], designNames: ['<system>.md'] }),
670
+ keeper_review_of_prior_failure: shapingContext({ state: revisionState, taskSummary: { total: 1, done: 0, open: 1, blocked: 0, active: null }, capabilityNames: ['<field>'], designNames: ['<system>.md'], forKeeper: true }),
671
+ current_task: '## Active Task\n\n<exact Task JSON including acceptance, implements, capability_hooks, and covers if present>\n\n---\n\n## Task context: <path from Task.reads>\n\n<exact file content>\n\n(repeated for every read path)\n\n---\n\n## Capability decision points\n\n<extracted decision-tree nodes referenced by capability_hooks, with options, criteria, sources, and counterexamples>',
672
+ on_demand_map: '## On-demand project context\n\n- Decision history: .loom/DECISIONS.md (read when correction or lineage matters; records what changed and why)\n- Design: .loom/design/<document>.md\n- Professional capability: .loom/capabilities/<field>/capability.md\n- Project structure: .loom/STRUCTURE.md (read before creating or moving files)',
390
673
  keeper_context: '## Decision history (...)\n\n<exact DECISIONS.md>\n\n---\n\n## Work map summary\n\n<summary and first executable Task>\n\n---\n\n## Design document: <name>\n\n<exact content>\n\n---\n\n## Capability dossier: <name>\n\n<exact content>',
391
674
  },
392
675
  workspace_anchor: AGENT_ANCHOR,
393
676
  templates: {
394
677
  project_index: PROJECT_TEMPLATE,
678
+ project_structure: STRUCTURE_TEMPLATE,
395
679
  design_documents: Object.fromEntries(DESIGN_KINDS.map((kind) => [kind, designTemplate({ title: `<${kind}-title>`, kind })])),
396
680
  professional_capability: CAPABILITY_TEMPLATE({ title: '<recognizable-professional-field>' }),
397
681
  decision_history: '# Decision History\n\nCurrent truth belongs in PROJECT.md and linked design documents. This file preserves consequential superseding decisions.',
@@ -400,11 +684,13 @@ export function promptCatalog() {
400
684
  evaluation: {
401
685
  baseline_condition: evalConditionPrompt({ brief: '<identical-raw-brief>', loom: false }),
402
686
  loom_condition: evalConditionPrompt({ brief: '<identical-raw-brief>', loom: true }),
687
+ unattended_baseline_condition: evalConditionPrompt({ brief: '<identical-raw-brief>', loom: false, humanChannel: 'unavailable' }),
688
+ unattended_loom_condition: evalConditionPrompt({ brief: '<identical-raw-brief>', loom: true, humanChannel: 'unavailable' }),
403
689
  blind_judge: evalJudgePrompt(),
404
690
  },
405
- composition: {
406
- normal_resume: ['stable_core', 'runtime_protocol', 'project_state', 'PROJECT.md', 'on-demand document and capability map'],
407
- active_task: ['normal_resume', 'execution_protocol', 'active Task JSON', 'exact files in Task.reads'],
691
+ composition: {
692
+ normal_resume: ['stable_core', 'environment_adaptation', 'runtime_protocol', 'project_state', 'PROJECT.md', 'on-demand document and capability map'],
693
+ active_task: ['normal_resume', 'execution_protocol', 'active Task JSON', 'exact files in Task.reads'],
408
694
  keeper_handoff: ['keeper', 'normal_resume', 'DECISIONS.md', 'Work Map summary and first executable Task', 'all design documents', 'all professional capability dossiers'],
409
695
  },
410
696
  };