@microvac/adapter-claude-local 0.0.0-stage → 0.1.0-rc.14

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 (242) hide show
  1. package/dist/cli/format-event.d.ts +2 -0
  2. package/dist/cli/format-event.d.ts.map +1 -0
  3. package/dist/cli/format-event.js +141 -0
  4. package/dist/cli/format-event.js.map +1 -0
  5. package/dist/cli/index.d.ts +2 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +2 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/cli/quota-probe.d.ts +3 -0
  10. package/dist/cli/quota-probe.d.ts.map +1 -0
  11. package/dist/cli/quota-probe.js +106 -0
  12. package/dist/cli/quota-probe.js.map +1 -0
  13. package/dist/index.d.ts +13 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +99 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/index.test.d.ts +2 -0
  18. package/dist/index.test.d.ts.map +1 -0
  19. package/dist/index.test.js +72 -0
  20. package/dist/index.test.js.map +1 -0
  21. package/dist/server/acp-billing.d.ts +13 -0
  22. package/dist/server/acp-billing.d.ts.map +1 -0
  23. package/dist/server/acp-billing.js +28 -0
  24. package/dist/server/acp-billing.js.map +1 -0
  25. package/dist/server/acp.auth.test.d.ts +2 -0
  26. package/dist/server/acp.auth.test.d.ts.map +1 -0
  27. package/dist/server/acp.auth.test.js +588 -0
  28. package/dist/server/acp.auth.test.js.map +1 -0
  29. package/dist/server/acp.d.ts +69 -0
  30. package/dist/server/acp.d.ts.map +1 -0
  31. package/dist/server/acp.js +882 -0
  32. package/dist/server/acp.js.map +1 -0
  33. package/dist/server/acp.quota.test.d.ts +2 -0
  34. package/dist/server/acp.quota.test.d.ts.map +1 -0
  35. package/dist/server/acp.quota.test.js +168 -0
  36. package/dist/server/acp.quota.test.js.map +1 -0
  37. package/dist/server/acp.test.d.ts +2 -0
  38. package/dist/server/acp.test.d.ts.map +1 -0
  39. package/dist/server/acp.test.js +1645 -0
  40. package/dist/server/acp.test.js.map +1 -0
  41. package/dist/server/auth-check.d.ts +8 -0
  42. package/dist/server/auth-check.d.ts.map +1 -0
  43. package/dist/server/auth-check.js +8 -0
  44. package/dist/server/auth-check.js.map +1 -0
  45. package/dist/server/claude-config.d.ts +73 -0
  46. package/dist/server/claude-config.d.ts.map +1 -0
  47. package/dist/server/claude-config.js +408 -0
  48. package/dist/server/claude-config.js.map +1 -0
  49. package/dist/server/claude-config.test.d.ts +2 -0
  50. package/dist/server/claude-config.test.d.ts.map +1 -0
  51. package/dist/server/claude-config.test.js +376 -0
  52. package/dist/server/claude-config.test.js.map +1 -0
  53. package/dist/server/cli-capabilities.d.ts +39 -0
  54. package/dist/server/cli-capabilities.d.ts.map +1 -0
  55. package/dist/server/cli-capabilities.js +149 -0
  56. package/dist/server/cli-capabilities.js.map +1 -0
  57. package/dist/server/cli-capabilities.test.d.ts +2 -0
  58. package/dist/server/cli-capabilities.test.d.ts.map +1 -0
  59. package/dist/server/cli-capabilities.test.js +35 -0
  60. package/dist/server/cli-capabilities.test.js.map +1 -0
  61. package/dist/server/config-schema.d.ts +3 -0
  62. package/dist/server/config-schema.d.ts.map +1 -0
  63. package/dist/server/config-schema.js +67 -0
  64. package/dist/server/config-schema.js.map +1 -0
  65. package/dist/server/engine-availability.test.d.ts +2 -0
  66. package/dist/server/engine-availability.test.d.ts.map +1 -0
  67. package/dist/server/engine-availability.test.js +70 -0
  68. package/dist/server/engine-availability.test.js.map +1 -0
  69. package/dist/server/execute.acp-fallback.test.d.ts +2 -0
  70. package/dist/server/execute.acp-fallback.test.d.ts.map +1 -0
  71. package/dist/server/execute.acp-fallback.test.js +104 -0
  72. package/dist/server/execute.acp-fallback.test.js.map +1 -0
  73. package/dist/server/execute.d.ts +23 -0
  74. package/dist/server/execute.d.ts.map +1 -0
  75. package/dist/server/execute.js +1212 -0
  76. package/dist/server/execute.js.map +1 -0
  77. package/dist/server/execute.max-turns-classification.test.d.ts +2 -0
  78. package/dist/server/execute.max-turns-classification.test.d.ts.map +1 -0
  79. package/dist/server/execute.max-turns-classification.test.js +82 -0
  80. package/dist/server/execute.max-turns-classification.test.js.map +1 -0
  81. package/dist/server/execute.remote.test.d.ts +2 -0
  82. package/dist/server/execute.remote.test.d.ts.map +1 -0
  83. package/dist/server/execute.remote.test.js +830 -0
  84. package/dist/server/execute.remote.test.js.map +1 -0
  85. package/dist/server/index.d.ts +16 -0
  86. package/dist/server/index.d.ts.map +1 -0
  87. package/dist/server/index.js +97 -0
  88. package/dist/server/index.js.map +1 -0
  89. package/dist/server/model-order.d.ts +14 -0
  90. package/dist/server/model-order.d.ts.map +1 -0
  91. package/dist/server/model-order.js +87 -0
  92. package/dist/server/model-order.js.map +1 -0
  93. package/dist/server/model-order.test.d.ts +2 -0
  94. package/dist/server/model-order.test.d.ts.map +1 -0
  95. package/dist/server/model-order.test.js +82 -0
  96. package/dist/server/model-order.test.js.map +1 -0
  97. package/dist/server/models.d.ts +13 -0
  98. package/dist/server/models.d.ts.map +1 -0
  99. package/dist/server/models.js +163 -0
  100. package/dist/server/models.js.map +1 -0
  101. package/dist/server/parse.d.ts +101 -0
  102. package/dist/server/parse.d.ts.map +1 -0
  103. package/dist/server/parse.js +504 -0
  104. package/dist/server/parse.js.map +1 -0
  105. package/dist/server/parse.test.d.ts +2 -0
  106. package/dist/server/parse.test.d.ts.map +1 -0
  107. package/dist/server/parse.test.js +432 -0
  108. package/dist/server/parse.test.js.map +1 -0
  109. package/dist/server/permissions.d.ts +14 -0
  110. package/dist/server/permissions.d.ts.map +1 -0
  111. package/dist/server/permissions.js +13 -0
  112. package/dist/server/permissions.js.map +1 -0
  113. package/dist/server/permissions.test.d.ts +2 -0
  114. package/dist/server/permissions.test.d.ts.map +1 -0
  115. package/dist/server/permissions.test.js +22 -0
  116. package/dist/server/permissions.test.js.map +1 -0
  117. package/dist/server/probe-diagnostics.d.ts +102 -0
  118. package/dist/server/probe-diagnostics.d.ts.map +1 -0
  119. package/dist/server/probe-diagnostics.js +140 -0
  120. package/dist/server/probe-diagnostics.js.map +1 -0
  121. package/dist/server/probe-diagnostics.test.d.ts +2 -0
  122. package/dist/server/probe-diagnostics.test.d.ts.map +1 -0
  123. package/dist/server/probe-diagnostics.test.js +114 -0
  124. package/dist/server/probe-diagnostics.test.js.map +1 -0
  125. package/dist/server/probe-env.d.ts +42 -0
  126. package/dist/server/probe-env.d.ts.map +1 -0
  127. package/dist/server/probe-env.js +149 -0
  128. package/dist/server/probe-env.js.map +1 -0
  129. package/dist/server/probe-env.test.d.ts +2 -0
  130. package/dist/server/probe-env.test.d.ts.map +1 -0
  131. package/dist/server/probe-env.test.js +135 -0
  132. package/dist/server/probe-env.test.js.map +1 -0
  133. package/dist/server/probe-redaction.test.d.ts +2 -0
  134. package/dist/server/probe-redaction.test.d.ts.map +1 -0
  135. package/dist/server/probe-redaction.test.js +86 -0
  136. package/dist/server/probe-redaction.test.js.map +1 -0
  137. package/dist/server/prompt-cache.d.ts +17 -0
  138. package/dist/server/prompt-cache.d.ts.map +1 -0
  139. package/dist/server/prompt-cache.js +126 -0
  140. package/dist/server/prompt-cache.js.map +1 -0
  141. package/dist/server/quota-keychain.test.d.ts +2 -0
  142. package/dist/server/quota-keychain.test.d.ts.map +1 -0
  143. package/dist/server/quota-keychain.test.js +83 -0
  144. package/dist/server/quota-keychain.test.js.map +1 -0
  145. package/dist/server/quota.d.ts +30 -0
  146. package/dist/server/quota.d.ts.map +1 -0
  147. package/dist/server/quota.js +544 -0
  148. package/dist/server/quota.js.map +1 -0
  149. package/dist/server/sandbox-cli-version.d.ts +10 -0
  150. package/dist/server/sandbox-cli-version.d.ts.map +1 -0
  151. package/dist/server/sandbox-cli-version.js +62 -0
  152. package/dist/server/sandbox-cli-version.js.map +1 -0
  153. package/dist/server/sandbox-cli-version.test.d.ts +2 -0
  154. package/dist/server/sandbox-cli-version.test.d.ts.map +1 -0
  155. package/dist/server/sandbox-cli-version.test.js +107 -0
  156. package/dist/server/sandbox-cli-version.test.js.map +1 -0
  157. package/dist/server/setup-token-characterization.test.d.ts +2 -0
  158. package/dist/server/setup-token-characterization.test.d.ts.map +1 -0
  159. package/dist/server/setup-token-characterization.test.js +123 -0
  160. package/dist/server/setup-token-characterization.test.js.map +1 -0
  161. package/dist/server/setup-token-parse.d.ts +50 -0
  162. package/dist/server/setup-token-parse.d.ts.map +1 -0
  163. package/dist/server/setup-token-parse.js +553 -0
  164. package/dist/server/setup-token-parse.js.map +1 -0
  165. package/dist/server/setup-token-parse.test.d.ts +2 -0
  166. package/dist/server/setup-token-parse.test.d.ts.map +1 -0
  167. package/dist/server/setup-token-parse.test.js +684 -0
  168. package/dist/server/setup-token-parse.test.js.map +1 -0
  169. package/dist/server/setup-token-runner.d.ts +117 -0
  170. package/dist/server/setup-token-runner.d.ts.map +1 -0
  171. package/dist/server/setup-token-runner.js +346 -0
  172. package/dist/server/setup-token-runner.js.map +1 -0
  173. package/dist/server/setup-token-runner.test.d.ts +2 -0
  174. package/dist/server/setup-token-runner.test.d.ts.map +1 -0
  175. package/dist/server/setup-token-runner.test.js +424 -0
  176. package/dist/server/setup-token-runner.test.js.map +1 -0
  177. package/dist/server/skills.d.ts +8 -0
  178. package/dist/server/skills.d.ts.map +1 -0
  179. package/dist/server/skills.js +42 -0
  180. package/dist/server/skills.js.map +1 -0
  181. package/dist/server/test.d.ts +3 -0
  182. package/dist/server/test.d.ts.map +1 -0
  183. package/dist/server/test.js +454 -0
  184. package/dist/server/test.js.map +1 -0
  185. package/dist/server/test.probe.test.d.ts +2 -0
  186. package/dist/server/test.probe.test.d.ts.map +1 -0
  187. package/dist/server/test.probe.test.js +609 -0
  188. package/dist/server/test.probe.test.js.map +1 -0
  189. package/dist/server/test.remote.test.d.ts +2 -0
  190. package/dist/server/test.remote.test.d.ts.map +1 -0
  191. package/dist/server/test.remote.test.js +189 -0
  192. package/dist/server/test.remote.test.js.map +1 -0
  193. package/dist/ui/build-config.d.ts +3 -0
  194. package/dist/ui/build-config.d.ts.map +1 -0
  195. package/dist/ui/build-config.js +82 -0
  196. package/dist/ui/build-config.js.map +1 -0
  197. package/dist/ui/build-config.test.d.ts +2 -0
  198. package/dist/ui/build-config.test.d.ts.map +1 -0
  199. package/dist/ui/build-config.test.js +82 -0
  200. package/dist/ui/build-config.test.js.map +1 -0
  201. package/dist/ui/index.d.ts +3 -0
  202. package/dist/ui/index.d.ts.map +1 -0
  203. package/dist/ui/index.js +3 -0
  204. package/dist/ui/index.js.map +1 -0
  205. package/dist/ui/parse-stdout.d.ts +3 -0
  206. package/dist/ui/parse-stdout.d.ts.map +1 -0
  207. package/dist/ui/parse-stdout.js +153 -0
  208. package/dist/ui/parse-stdout.js.map +1 -0
  209. package/package.json +57 -4
  210. package/skills/agentmail/SKILL.md +70 -0
  211. package/skills/complain/LICENSE +27 -0
  212. package/skills/complain/SKILL.md +68 -0
  213. package/skills/paperclip/SKILL.md +864 -0
  214. package/skills/paperclip/references/api-reference.md +1814 -0
  215. package/skills/paperclip/references/artifacts.md +163 -0
  216. package/skills/paperclip/references/cases.md +570 -0
  217. package/skills/paperclip/references/company-skills.md +266 -0
  218. package/skills/paperclip/references/issue-documents.md +58 -0
  219. package/skills/paperclip/references/issue-workspaces.md +94 -0
  220. package/skills/paperclip/references/routines.md +249 -0
  221. package/skills/paperclip/references/run-diagnostics.md +28 -0
  222. package/skills/paperclip/references/workflows.md +141 -0
  223. package/skills/paperclip/scripts/paperclip-issue-update.sh +166 -0
  224. package/skills/paperclip/scripts/paperclip-upload-artifact.sh +603 -0
  225. package/skills/paperclip/scripts/submit-agent-commentary.mjs +52 -0
  226. package/skills/paperclip-board/SKILL.md +633 -0
  227. package/skills/paperclip-converting-plans-to-tasks/SKILL.md +28 -0
  228. package/skills/paperclip-create-agent/SKILL.md +213 -0
  229. package/skills/paperclip-create-agent/references/agent-instruction-templates.md +24 -0
  230. package/skills/paperclip-create-agent/references/agents/coder.md +18 -0
  231. package/skills/paperclip-create-agent/references/agents/qa.md +18 -0
  232. package/skills/paperclip-create-agent/references/agents/securityengineer.md +26 -0
  233. package/skills/paperclip-create-agent/references/agents/uxdesigner.md +18 -0
  234. package/skills/paperclip-create-agent/references/api-reference.md +110 -0
  235. package/skills/paperclip-create-agent/references/baseline-role-guide.md +22 -0
  236. package/skills/paperclip-create-agent/references/draft-review-checklist.md +29 -0
  237. package/skills/para-memory-files/SKILL.md +100 -0
  238. package/skills/para-memory-files/references/schemas.md +35 -0
  239. package/skills/slack/SKILL.md +92 -0
  240. package/skills/suggestion-box/LICENSE +27 -0
  241. package/skills/suggestion-box/SKILL.md +77 -0
  242. package/README.md +0 -3
@@ -0,0 +1,570 @@
1
+ # Cases
2
+
3
+ Cases are agent-owned work records for durable outputs such as blog posts,
4
+ research packets, release notes, incidents, QA runs, or generated asset sets.
5
+ They are company-scoped and live beside issues: issues coordinate work, while
6
+ cases preserve the structured object an agent is producing.
7
+
8
+ Cases are experimental and must be enabled with `experimental.enableCases`.
9
+ If a route returns `403 Cases are disabled`, stop and report that the operator
10
+ must enable cases before the skill can use this surface.
11
+
12
+ **Reusable workflows.**
13
+
14
+ Under the same Cases flag, use `list_workflows` to discover company-shared
15
+ name-and-prompt definitions, `read_workflow` to read one, and `create_workflow`
16
+ or `update_workflow` to author explicit reusable instructions. Creation needs
17
+ `name`, `prompt`, and `idempotencyKey`; update needs `workflowId`, a retry key,
18
+ and a name or prompt. These definitions are shared across the company. Case
19
+ documents are never automatically published into them.
20
+
21
+ Native `create_case` and REST kickoff accept **either** `workflowId` or the
22
+ inline `workflow_document_text` described below; kickoff is still required.
23
+ Adoption copies the prompt into the primary task's ordinary `workflow` document.
24
+ Read that task document for current instructions, which may contain case-specific
25
+ edits. Editing the shared definition leaves existing copies unchanged.
26
+
27
+ On an agent `handoff_case`, omit `workflowId` to preserve the current definition
28
+ and document. Supply an ID to adopt its current prompt, including the current ID
29
+ to refresh explicitly. Supply null to leave the workflow while retaining task
30
+ instructions. Free-text phases and case types are independent of definitions.
31
+ The handoff captures the selected prompt when accepted and applies it only on
32
+ transfer. If someone edits the task document in between, the handoff is held;
33
+ read current state, cancel the unapplied handoff, then submit new intent. Do not
34
+ overwrite intervening edits. The same case/task and document history survive
35
+ A → B → A. Generic case updates cannot change workflow routing.
36
+
37
+ `read_workflow` returns bounded JSON text in `data`. Continue with the same
38
+ workflow ID, returned `snapshot`, and `responseText: {offsetBytes: <nextOffsetBytes>}`
39
+ until `responseText.nextOffsetBytes` is null, then parse the concatenated JSON.
40
+ An intervening edit returns 409; restart at offset zero without `snapshot`.
41
+ Mutation responses contain metadata.
42
+
43
+ ## Core Model
44
+
45
+ A case has:
46
+
47
+ - `identifier`: server-assigned display id such as `PAP-C42`
48
+ - `caseType`: skill-owned type such as `blog_post`, `image_assets`, or `incident`
49
+ - `key`: optional deterministic upsert key inside `(companyId, caseType)`
50
+ - `title` and optional `summary`
51
+ - `status`: `draft`, `in_progress`, `in_review`, `approved`, `done`, or `cancelled`
52
+ - `fields`: JSON object owned by the skill using the case
53
+ - `parentCaseId`: optional parent case for child work
54
+ - `workIssueId`: optional primary workflow task; later handoffs reuse it
55
+ - `phase` and `handoffVersion`: current applied phase and observed routing revision
56
+ - documents, attachments, issue links, labels, and events
57
+
58
+ Use deterministic `caseType` + `key` when a skill may be retried. Repeating
59
+ `POST /api/companies/:companyId/cases` with the same `caseType` and `key`
60
+ upserts the same case instead of creating a duplicate.
61
+
62
+ ## Upsert Semantics
63
+
64
+ `POST /api/companies/:companyId/cases` creates or upserts a case.
65
+
66
+ Request:
67
+
68
+ ```json
69
+ {
70
+ "caseType": "blog_post",
71
+ "key": "launch-announcement",
72
+ "title": "Launch announcement",
73
+ "summary": "Draft launch post for operators.",
74
+ "status": "draft",
75
+ "fields": {
76
+ "slug": "launch-announcement",
77
+ "target_audience": "operators"
78
+ }
79
+ }
80
+ ```
81
+
82
+ Response:
83
+
84
+ - `201` when a new case was created
85
+ - `200` when an existing `(caseType, key)` case was updated
86
+
87
+ Field behavior on upsert:
88
+
89
+ - `title` is required and replaces the previous title.
90
+ - `projectId`, `summary`, `status`, `fields`, and `parentCaseId` replace the
91
+ previous value when present.
92
+ - Omitted optional values preserve the previous value during upsert.
93
+ - `fields` is replaced as a whole object when provided. It is not deep-merged.
94
+ Send the complete desired JSON object each time.
95
+ - Concurrent retries with the same `(caseType, key)` converge to one case.
96
+
97
+ Do not use a random `key` for retryable skills. Use a stable content slug,
98
+ external id, source URL hash, or parent-derived request key.
99
+
100
+ ## Start And Hand Off Work
101
+
102
+ Native `create_case` always creates a case and starts its first ordinary task.
103
+ `kickoff` and either `workflowId` or `workflow_document_text` are required; missing kickoff or both instruction sources is rejected
104
+ before any records are created. Provide the first agent, phase, instructions,
105
+ the full workflow description, and optional initial task documents:
106
+
107
+ ```json
108
+ {
109
+ "idempotencyKey":"csv-export-kickoff-1",
110
+ "caseType":"software_change",
111
+ "title":"Add a CSV export",
112
+ "workflow_document_text":"Agent ownership: triage=<triage-agent-uuid>, implementation=<implementation-agent-uuid>, verification=<verification-agent-uuid>. Transition ready: triage saves clear scope and research, then hands the same task to implementation; ask material questions and wait for answers first. Transition candidate_ready: implementation saves changes and check results, then hands off to verification. Transition changes_requested: verification saves concrete defects and returns to implementation; after two failed correction rounds ask for human direction. Transition verified_and_approved: checks and required human approvals are accepted; request handoff to done and complete the same task normally.\n\n```mermaid\nstateDiagram-v2\n [*] --> triage\n triage --> implementation : ready\n implementation --> verification : candidate_ready\n verification --> implementation : changes_requested\n verification --> done : verified_and_approved\n done --> [*]\n```",
113
+ "kickoff":{"toAgentId":"<triage-agent-uuid>","phase":"triage","instructions":"Research the request, then hand this same task to implementation."},
114
+ "initialDocuments":[{"key":"brief","title":"Export brief","body":"Export the filtered rows as CSV. Preserve the current column order."}]
115
+ }
116
+ ```
117
+
118
+ The harness saves `workflow_document_text` verbatim as the ordinary task document
119
+ `workflow`, titled **Workflow**, in Markdown format. It creates the primary task
120
+ and all seeded documents in the same transaction before delivery. Documents do not belong to
121
+ the case. Keys follow ordinary task document rules (trimmed/lowercased,
122
+ 1–64 characters); duplicate keys and the reserved `workflow` key are rejected in
123
+ `initialDocuments`. A kickoff accepts up to 20 additional documents, with at most
124
+ 200,000 body characters including the workflow text. There is no pending document
125
+ seed storage on the case. Read `read_document({"key":"workflow"})` before deciding
126
+ what to do or where to hand off. The harness supplies its reference; it does not
127
+ repeat the entire body in every prompt. Update the workflow through ordinary task
128
+ document revision tools when authorized; do not resend it on later handoffs.
129
+
130
+ Recommend both a fenced Mermaid `stateDiagram-v2` map and prose explaining
131
+ every transition. Include the objective, phase owners (actual agent IDs), expected
132
+ outputs, transition conditions, human waits, correction limits, and completion
133
+ criteria. For example:
134
+
135
+ ```mermaid
136
+ stateDiagram-v2
137
+ [*] --> triage
138
+ triage --> specification : needs_spec
139
+ triage --> implementation : ready
140
+ specification --> implementation : spec_approved
141
+ implementation --> verification : candidate_ready
142
+ verification --> implementation : changes_requested
143
+ verification --> done : verified_and_approved
144
+ done --> [*]
145
+ ```
146
+
147
+ Follow the map with prose that defines its named outcomes:
148
+
149
+ | Transition | Prose definition |
150
+ | --- | --- |
151
+ | `triage → specification` (`needs_spec`) | Scope or acceptance criteria need a specification. Save findings and unresolved questions, then assign the named specification agent. |
152
+ | `triage → implementation` (`ready`) | Scope, inputs and acceptance criteria are clear. Save the research and give the named implementation agent its evidence and constraints. |
153
+ | `specification → implementation` (`spec_approved`) | The required approval for the saved spec revision is accepted. While pending, use the normal review wait; resume only after approval. |
154
+ | `implementation → verification` (`candidate_ready`) | Save the candidate, artifacts and actual check results. Give the named verification agent the read paths and acceptance criteria. |
155
+ | `verification → implementation` (`changes_requested`) | Persist concrete defects and failing evidence before returning to the implementation agent. Allow at most two correction rounds, then ask for human direction. |
156
+ | `verification → done` (`verified_and_approved`) | Evidence satisfies acceptance criteria and required reviews/approvals are accepted. Request `to: "done"` and complete the same task through its normal gates. |
157
+
158
+ Use stable state IDs matching agent phase names and map every active phase to its
159
+ actual agent ID. Define each transition's trigger, evidence, destination and any
160
+ wait/resume, correction or escalation rules; a diagram alone is insufficient.
161
+ Arrow labels are not executable guards. Paperclip stores this document as
162
+ task data and does not parse or enforce its graph. Human waits use existing
163
+ question/review/approval mechanisms, and `done` still requires accepted normal
164
+ task completion. See [Mermaid state diagrams](https://mermaid.js.org/syntax/stateDiagram.html).
165
+
166
+ Alternatively use native `handoff_case` or
167
+ `POST /api/companies/:companyId/case-handoffs`:
168
+
169
+ ```json
170
+ {
171
+ "idempotencyKey": "launch-triage-1",
172
+ "case": {
173
+ "create": {
174
+ "caseType": "software_change",
175
+ "title": "Add a CSV export",
176
+ "summary": "Deliver the requested export with verification and review."
177
+ }
178
+ },
179
+ "toAgentId": "<triage-agent-uuid>",
180
+ "phase": "triage",
181
+ "workflow_document_text": "Agent ownership: triage=<triage-agent-uuid>, implementation=<implementation-agent-uuid>, verification=<verification-agent-uuid>. Transition ready: triage saves clear scope and evidence, then sends the same task to implementation; wait for answers to material questions first. Transition candidate_ready: implementation saves changes and actual check results, then sends the task to verification. Transition changes_requested: verification saves concrete defects before returning to implementation; after two failed correction rounds request human direction. Transition verified_and_approved: checks and required approvals are accepted; hand off to done and complete normally.\n\n```mermaid\nstateDiagram-v2\n [*] --> triage\n triage --> implementation : ready\n implementation --> verification : candidate_ready\n verification --> implementation : changes_requested\n verification --> done : verified_and_approved\n done --> [*]\n```",
182
+ "instructions": "Research the request. Ask material questions or hand this same task to the implementation agent."
183
+ }
184
+ ```
185
+
186
+ The harness creates the initial ordinary task and assigns it. For an existing
187
+ case, send `case: {"id": "<case-uuid>"}`, `expectedHandoffVersion`, and
188
+ `expectedIssueStatusVersion` from fresh authorized context. The existing primary
189
+ task is reused automatically. A passive case may explicitly bind an existing
190
+ ordinary task with `bindIssueId` and its observed status version.
191
+ New-case API creation also requires top-level `workflowId` or `workflow_document_text`. Starting
192
+ the first new task of an older passive case requires it too. New-case binding
193
+ creates the bound task's `workflow` document only if that key is absent; an
194
+ existing workflow key conflicts for inline text. An explicit workflowId adopts the selected prompt as a new revision instead. Later primary-task
195
+ handoffs omit workflow text. The agent-handoff input accepts `initialDocuments` only when
196
+ it creates the first primary task, including for an existing passive case.
197
+ Existing-task handoffs, task binding and `to: "done"` reject initial documents;
198
+ use ordinary task document tools to revise existing work.
199
+
200
+ Save findings, documents, and artifacts before handing off. Include the next
201
+ phase's objective, relevant evidence, remaining work, and any constraints in
202
+ `instructions`. Reuse a stable idempotency key when retrying the same operation;
203
+ different content under that key is a conflict. Reload on a version conflict.
204
+ The source run is provenance; a later run can recover the same principal's receipt.
205
+
206
+ After an accepted self-handoff, end the turn without marking the task done. The
207
+ harness keeps the recipient waiting until your execution and workspace settle.
208
+ `202` means intent accepted; `delivered` means the ordinary wake queue accepted
209
+ it. Neither is proof the recipient ran. Handoff to the same agent is also a new
210
+ phase/turn. Each returning agent may resume its own task session.
211
+
212
+ Separate work uses ordinary task creation plus a case link. It does not replace
213
+ the primary task. Human clarification, specification approval, code review, and
214
+ final approval use existing interactions. A phase called `review` is not a verdict.
215
+ Ordinary task completion leaves case status unchanged. To finish the case as
216
+ part of completing its primary task, hand off to the terminal destination:
217
+
218
+ ```json
219
+ {
220
+ "idempotencyKey": "launch-finished-1",
221
+ "case": { "id": "<case-uuid>" },
222
+ "to": "done",
223
+ "instructions": "Implementation and verification are complete; saved evidence is in the case documents.",
224
+ "expectedHandoffVersion": 4,
225
+ "expectedIssueStatusVersion": 7
226
+ }
227
+ ```
228
+
229
+ This records an intent to close an existing case with a primary task; it does
230
+ not create work, transfer assignment, or satisfy completion criteria. The
231
+ receipt has `callerMustYield: false` and `state: awaiting_completion`. Finish
232
+ the same task normally, including any required review, human answer or approval.
233
+ Once task completion is accepted, its transaction closes the case, sets phase
234
+ `done`, and settles the terminal handoff as `completed`. If the task was already
235
+ done, closing is immediate. Pending review or user input keeps the case open.
236
+ Do not change case status separately. An accepted terminal request survives
237
+ restart; Stop, task cancellation or reassignment cancels it. Cancelling the
238
+ request leaves the task untouched. A replay returns the original receipt.
239
+
240
+ History is at `GET /api/cases/:id/handoffs?limit=20&cursor=...`. Authorized task
241
+ controllers can POST to `/api/cases/:id/handoffs/:handoffId/retry` or `/cancel`.
242
+ Retry delivers the same intent; cancellation never reverses an applied assignment.
243
+
244
+ Cases retain task/project permission boundaries, including copied run output.
245
+ An inaccessible or deleted source cannot be bypassed by unlinking it. For an
246
+ existing private passive case, select an agent who already qualifies for those
247
+ source permissions. Handoff does not grant unrelated task/project access.
248
+
249
+ ### Example factory instructions
250
+
251
+ Use the supplied company agent IDs for triage, specification, implementation,
252
+ and verification. Operate on the case's primary task throughout:
253
+
254
+ 1. Triage researches the request and saves findings on the case. Clarify material
255
+ ambiguity through the normal question interaction. Park work that should not
256
+ proceed; otherwise hand off to specification or implementation.
257
+ 2. Specification saves a revisioned `spec` document and requests normal human
258
+ confirmation. After acceptance, hand the task to implementation.
259
+ 3. Implementation builds the approved work, registers artifacts/PR references,
260
+ records checks, and hands the task to verification.
261
+ 4. Verification checks the actual result and saves its report. Return concrete
262
+ defects to implementation on the same task. After two unsuccessful correction
263
+ rounds, request human direction rather than starting an unbounded loop.
264
+ 5. Follow existing code-review and human-approval requirements before completion
265
+ or shipping. The final agent calls `handoff_case` with `to: "done"`, the
266
+ existing case and current versions, then completes the same task normally.
267
+ Monitoring may create a new case for a new incident.
268
+
269
+ Routing belongs in these instructions. Paperclip does not require a pipeline or
270
+ preconfigured phase graph to execute them.
271
+
272
+ ## Read And Search
273
+
274
+ Native runner agents have production case tools in standard work mode
275
+ when cases are enabled:
276
+
277
+ | Tool | Use |
278
+ | --- | --- |
279
+ | `create_case` | Create a case and start its first task with required `kickoff` and either `workflowId` or `workflow_document_text`, plus optional `initialDocuments`. |
280
+ | `read_case` | Read current case facts, fields, versions, document references, or a selected document body. |
281
+ | `update_case` | Change title, summary or fields; fields replaces the entire object. |
282
+
283
+ Omit `caseId` to use the current task's primary workflow case, or pass an
284
+ authorized standalone case UUID. These tools do not operate on pipeline cases.
285
+ `update_case` cannot change status, phase, assignment or access. Use
286
+ `handoff_case` for routing and completion. New documents belong to tasks. Use
287
+ `read_document({key})` and `write_document` for the active task, with its current
288
+ `baseRevisionId` when revising. Case detail includes `taskDocuments` references
289
+ with their owning task and authenticated read path. For a linked task document,
290
+ use `read_case` with `section: "document"`, its `documentKey` and owning
291
+ `documentIssueId`. Omit `documentIssueId` for a historical case-owned document.
292
+ This works when generic API tools are disabled. The selected task must still be
293
+ the primary task or linked to the case, and its current permissions must allow
294
+ the read. The ordinary task document tools operate on the active task;
295
+ `read_case_document` and `write_case_document` are not live tools.
296
+
297
+ For example, read a linked task's research document:
298
+
299
+ ```json
300
+ {
301
+ "section": "document",
302
+ "documentKey": "research",
303
+ "documentIssueId": "<task-uuid-from-taskDocuments>"
304
+ }
305
+ ```
306
+
307
+ The result uses bounded `readPage.text` JSON pages. Keep the document selector
308
+ and returned `snapshot` on every continuation. Pass
309
+ `offsetBytes: readPage.nextOffsetBytes` until it is null, then concatenate the
310
+ text and parse the selected document JSON. Every page checks current case and
311
+ source-task access. A changed document revision or routing snapshot returns 409;
312
+ restart from offset zero without the old snapshot. Unlinking a source task or
313
+ losing access prevents further reads. System and quarantined documents remain
314
+ unavailable through this path. This operation reads saved data; it does not grant
315
+ new document editing authority or turn document content into system instructions.
316
+
317
+ Writes require `idempotencyKey`. Reuse the key with identical input after a lost
318
+ response in the same admitted run, even if the provider uses a new tool-call ID.
319
+ `update_case` receipts are run-scoped; after a restart into a different run, read
320
+ current state and document revisions before deciding whether another write is
321
+ needed. An uncertain outcome requires inspection rather than blind replay.
322
+ `create_case` and `handoff_case` share the principal-scoped
323
+ handoff replay contract. Kickoff retries do not duplicate tasks or initial
324
+ document revisions. Reuse the original key and exact input to recover the
325
+ accepted kickoff receipt after response loss, including from a later run.
326
+
327
+ The task prompt identifies its primary case, current phase, incoming handoff
328
+ and authenticated read path. Native resumed turns use verified session context
329
+ to send changed case facts and new handoff instructions without repeating
330
+ unchanged facts. Fresh or incompatible sessions receive the full bounded
331
+ snapshot. Persisted session history can still contain earlier snapshots;
332
+ `read_case` and ordinary task document reads provide current authoritative data.
333
+
334
+ Get a case by UUID or identifier:
335
+
336
+ ```http
337
+ GET /api/cases/PAP-C42
338
+ ```
339
+
340
+ List cases for a company:
341
+
342
+ ```http
343
+ GET /api/companies/:companyId/cases?type=blog_post&status=active&q=launch
344
+ ```
345
+
346
+ Useful filters:
347
+
348
+ - `type`: exact `caseType`
349
+ - `status`: exact lifecycle status, or `active` for non-terminal cases
350
+ - `projectId` / `project`: project UUID
351
+ - `labelId` / `label`: label UUID
352
+ - `q`: identifier, title, summary, or key search
353
+ - `limit`: 1-200, default 100
354
+
355
+ ## Task Documents And Legacy Case Documents
356
+
357
+ Use ordinary task documents for new drafts, briefs, reports and plans. Seed them
358
+ through first-task `initialDocuments`, then use native `read_document` and
359
+ `write_document` on the active task. Case detail surfaces their owner and revision
360
+ references; it does not copy their bodies or create a second revision history.
361
+
362
+ The following REST endpoints remain compatible for historical case-owned
363
+ documents. They are not the new-work document workflow:
364
+
365
+ ```http
366
+ PUT /api/cases/:caseIdOrIdentifier/documents/body
367
+ Content-Type: application/json
368
+
369
+ {
370
+ "title": "Launch announcement body",
371
+ "format": "markdown",
372
+ "body": "# Launch announcement\n\nDraft copy...",
373
+ "changeSummary": "Initial draft"
374
+ }
375
+ ```
376
+
377
+ Updating an existing case document requires `baseRevisionId`:
378
+
379
+ ```json
380
+ {
381
+ "baseRevisionId": "latest-revision-uuid",
382
+ "body": "Updated body"
383
+ }
384
+ ```
385
+
386
+ If you get `409 stale_base_revision`, refetch the case detail, read the latest
387
+ document revision id, merge intentionally, and retry with that `baseRevisionId`.
388
+
389
+ ## Fields
390
+
391
+ Each skill owns the schema of `fields` for the `caseType` it creates. Keep fields
392
+ small, typed, and stable enough for other agents to inspect.
393
+
394
+ Examples:
395
+
396
+ ```json
397
+ {
398
+ "slug": "launch-announcement",
399
+ "target_audience": "operators",
400
+ "publish_url": "https://example.com/blog/launch-announcement"
401
+ }
402
+ ```
403
+
404
+ Patch fields or status with:
405
+
406
+ ```http
407
+ PATCH /api/cases/:caseIdOrIdentifier
408
+ Content-Type: application/json
409
+
410
+ {
411
+ "status": "in_review",
412
+ "fields": {
413
+ "slug": "launch-announcement",
414
+ "target_audience": "operators",
415
+ "publish_url": "https://example.com/blog/launch-announcement"
416
+ }
417
+ }
418
+ ```
419
+
420
+ Remember: `fields` replaces the whole object when present.
421
+
422
+ ## Issue Links
423
+
424
+ Link cases to issues explicitly when needed:
425
+
426
+ ```http
427
+ POST /api/cases/:caseIdOrIdentifier/links
428
+ Content-Type: application/json
429
+
430
+ {
431
+ "issueId": "issue-uuid",
432
+ "role": "reference"
433
+ }
434
+ ```
435
+
436
+ Roles:
437
+
438
+ - `origin`: the issue/run that created the case
439
+ - `work`: an issue/run that changed the case
440
+ - `reference`: related issue context
441
+
442
+ Agent run writes auto-link the run's issue when Paperclip can resolve it from
443
+ the run JWT or `X-Paperclip-Run-Id`. Creation/upsert writes use `origin`; later
444
+ document, patch, and attachment writes use `work` when no link already exists.
445
+ You do not need to manually link the current issue before writing the case.
446
+
447
+ ## Child Cases
448
+
449
+ Create child cases by setting `parentCaseId` to the parent case UUID.
450
+
451
+ ```json
452
+ {
453
+ "caseType": "image_assets",
454
+ "key": "launch-announcement:hero-images",
455
+ "title": "Hero images for launch announcement",
456
+ "parentCaseId": "parent-case-uuid",
457
+ "fields": {
458
+ "required_assets": ["hero", "social-card"]
459
+ }
460
+ }
461
+ ```
462
+
463
+ Use child cases when the output has independently inspectable pieces or when
464
+ another agent can work on a bounded part without editing the parent case body.
465
+
466
+ ## Attachments
467
+
468
+ Attach generated files with multipart form data:
469
+
470
+ ```http
471
+ POST /api/cases/:caseIdOrIdentifier/attachments
472
+ Content-Type: multipart/form-data
473
+
474
+ file=@hero.png
475
+ ```
476
+
477
+ The server records an asset and adds an `attachment_added` case event.
478
+
479
+ ## Lifecycle
480
+
481
+ Use the lifecycle consistently:
482
+
483
+ - `draft`: case exists but useful work has not started
484
+ - `in_progress`: an agent is actively producing or revising it
485
+ - `in_review`: ready for reviewer, board, or downstream approval
486
+ - `approved`: accepted but not finally shipped or archived
487
+ - `done`: complete and no further action remains
488
+ - `cancelled`: intentionally abandoned
489
+
490
+ Terminal statuses are `done` and `cancelled`; setting either records
491
+ `completedAt`. Moving back to a non-terminal status clears `completedAt`.
492
+
493
+ ## Worked Blog Post Example
494
+
495
+ Create or upsert the parent blog post:
496
+
497
+ ```http
498
+ POST /api/companies/:companyId/cases
499
+ Content-Type: application/json
500
+
501
+ {
502
+ "caseType": "blog_post",
503
+ "key": "paperclip-cases-launch",
504
+ "title": "Introducing Paperclip Cases",
505
+ "summary": "Blog post explaining the cases surface for agent outputs.",
506
+ "status": "in_progress",
507
+ "fields": {
508
+ "slug": "paperclip-cases-launch",
509
+ "target_audience": "AI company operators",
510
+ "publish_url": null
511
+ }
512
+ }
513
+ ```
514
+
515
+ Start drafting on the case's first task and seed its body document:
516
+
517
+ ```json
518
+ {
519
+ "idempotencyKey": "paperclip-cases-launch-draft",
520
+ "case": {"id": "<blog-case-uuid>"},
521
+ "expectedHandoffVersion": 0,
522
+ "toAgentId": "<writer-agent-uuid>",
523
+ "phase": "draft",
524
+ "instructions": "Finish the draft on this same task, then hand it to editorial review.",
525
+ "initialDocuments": [{"key":"body","title":"Introducing Paperclip Cases","body":"# Introducing Paperclip Cases\n\n..."}]
526
+ }
527
+ ```
528
+
529
+ Send this input to `handoff_case`. The writer uses ordinary task document tools
530
+ for subsequent revisions; the case page rolls up that same document.
531
+
532
+ Create the child image-assets case:
533
+
534
+ ```http
535
+ POST /api/companies/:companyId/cases
536
+ Content-Type: application/json
537
+
538
+ {
539
+ "caseType": "image_assets",
540
+ "key": "paperclip-cases-launch:image-assets",
541
+ "title": "Image assets for Introducing Paperclip Cases",
542
+ "parentCaseId": "parent-case-uuid",
543
+ "status": "in_progress",
544
+ "fields": {
545
+ "slug": "paperclip-cases-launch",
546
+ "required_assets": ["hero", "social-card"],
547
+ "publish_url": null
548
+ }
549
+ }
550
+ ```
551
+
552
+ Attach generated assets to the child, then patch both cases as they move through
553
+ review:
554
+
555
+ ```http
556
+ PATCH /api/cases/PAP-C42
557
+ Content-Type: application/json
558
+
559
+ {
560
+ "status": "in_review",
561
+ "fields": {
562
+ "slug": "paperclip-cases-launch",
563
+ "target_audience": "AI company operators",
564
+ "publish_url": "https://example.com/blog/paperclip-cases-launch"
565
+ }
566
+ }
567
+ ```
568
+
569
+ If the same skill retries the example with the same keys, it updates the parent
570
+ and child cases rather than creating duplicates.