@microvac/adapter-codex-local 0.0.0-stage → 0.1.0-rc.15

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 (300) 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 +218 -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 +104 -0
  12. package/dist/cli/quota-probe.js.map +1 -0
  13. package/dist/index.d.ts +41 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +268 -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 +125 -0
  20. package/dist/index.test.js.map +1 -0
  21. package/dist/server/acp.cli-version.test.d.ts +2 -0
  22. package/dist/server/acp.cli-version.test.d.ts.map +1 -0
  23. package/dist/server/acp.cli-version.test.js +151 -0
  24. package/dist/server/acp.cli-version.test.js.map +1 -0
  25. package/dist/server/acp.d.ts +31 -0
  26. package/dist/server/acp.d.ts.map +1 -0
  27. package/dist/server/acp.js +608 -0
  28. package/dist/server/acp.js.map +1 -0
  29. package/dist/server/acp.quota.test.d.ts +2 -0
  30. package/dist/server/acp.quota.test.d.ts.map +1 -0
  31. package/dist/server/acp.quota.test.js +176 -0
  32. package/dist/server/acp.quota.test.js.map +1 -0
  33. package/dist/server/acp.test.d.ts +2 -0
  34. package/dist/server/acp.test.d.ts.map +1 -0
  35. package/dist/server/acp.test.js +1263 -0
  36. package/dist/server/acp.test.js.map +1 -0
  37. package/dist/server/adapter-auth-promotion.d.ts +102 -0
  38. package/dist/server/adapter-auth-promotion.d.ts.map +1 -0
  39. package/dist/server/adapter-auth-promotion.js +210 -0
  40. package/dist/server/adapter-auth-promotion.js.map +1 -0
  41. package/dist/server/adapter-auth-promotion.test.d.ts +2 -0
  42. package/dist/server/adapter-auth-promotion.test.d.ts.map +1 -0
  43. package/dist/server/adapter-auth-promotion.test.js +615 -0
  44. package/dist/server/adapter-auth-promotion.test.js.map +1 -0
  45. package/dist/server/auth-check.d.ts +8 -0
  46. package/dist/server/auth-check.d.ts.map +1 -0
  47. package/dist/server/auth-check.js +8 -0
  48. package/dist/server/auth-check.js.map +1 -0
  49. package/dist/server/auth-precedence.d.ts +16 -0
  50. package/dist/server/auth-precedence.d.ts.map +1 -0
  51. package/dist/server/auth-precedence.js +20 -0
  52. package/dist/server/auth-precedence.js.map +1 -0
  53. package/dist/server/auth-precedence.test.d.ts +2 -0
  54. package/dist/server/auth-precedence.test.d.ts.map +1 -0
  55. package/dist/server/auth-precedence.test.js +100 -0
  56. package/dist/server/auth-precedence.test.js.map +1 -0
  57. package/dist/server/cli-version.d.ts +45 -0
  58. package/dist/server/cli-version.d.ts.map +1 -0
  59. package/dist/server/cli-version.js +95 -0
  60. package/dist/server/cli-version.js.map +1 -0
  61. package/dist/server/codex-args.d.ts +13 -0
  62. package/dist/server/codex-args.d.ts.map +1 -0
  63. package/dist/server/codex-args.js +64 -0
  64. package/dist/server/codex-args.js.map +1 -0
  65. package/dist/server/codex-args.test.d.ts +2 -0
  66. package/dist/server/codex-args.test.d.ts.map +1 -0
  67. package/dist/server/codex-args.test.js +257 -0
  68. package/dist/server/codex-args.test.js.map +1 -0
  69. package/dist/server/codex-auth-cache.d.ts +179 -0
  70. package/dist/server/codex-auth-cache.d.ts.map +1 -0
  71. package/dist/server/codex-auth-cache.js +520 -0
  72. package/dist/server/codex-auth-cache.js.map +1 -0
  73. package/dist/server/codex-auth-cache.test.d.ts +2 -0
  74. package/dist/server/codex-auth-cache.test.d.ts.map +1 -0
  75. package/dist/server/codex-auth-cache.test.js +530 -0
  76. package/dist/server/codex-auth-cache.test.js.map +1 -0
  77. package/dist/server/codex-auth-copyback.d.ts +53 -0
  78. package/dist/server/codex-auth-copyback.d.ts.map +1 -0
  79. package/dist/server/codex-auth-copyback.js +123 -0
  80. package/dist/server/codex-auth-copyback.js.map +1 -0
  81. package/dist/server/codex-auth-copyback.test.d.ts +2 -0
  82. package/dist/server/codex-auth-copyback.test.d.ts.map +1 -0
  83. package/dist/server/codex-auth-copyback.test.js +507 -0
  84. package/dist/server/codex-auth-copyback.test.js.map +1 -0
  85. package/dist/server/codex-auth-merge-decision.cjs +170 -0
  86. package/dist/server/codex-auth-merge-decision.d.ts +22 -0
  87. package/dist/server/codex-auth-merge-decision.d.ts.map +1 -0
  88. package/dist/server/codex-auth-merge-decision.js +58 -0
  89. package/dist/server/codex-auth-merge-decision.js.map +1 -0
  90. package/dist/server/codex-auth-merge-decision.test.d.ts +2 -0
  91. package/dist/server/codex-auth-merge-decision.test.d.ts.map +1 -0
  92. package/dist/server/codex-auth-merge-decision.test.js +215 -0
  93. package/dist/server/codex-auth-merge-decision.test.js.map +1 -0
  94. package/dist/server/codex-auth-merge-extract.sh +73 -0
  95. package/dist/server/codex-auth-merge-scripts.d.ts +21 -0
  96. package/dist/server/codex-auth-merge-scripts.d.ts.map +1 -0
  97. package/dist/server/codex-auth-merge-scripts.js +40 -0
  98. package/dist/server/codex-auth-merge-scripts.js.map +1 -0
  99. package/dist/server/codex-auth-merge.test.d.ts +2 -0
  100. package/dist/server/codex-auth-merge.test.d.ts.map +1 -0
  101. package/dist/server/codex-auth-merge.test.js +714 -0
  102. package/dist/server/codex-auth-merge.test.js.map +1 -0
  103. package/dist/server/codex-auth-seed-write.d.ts +30 -0
  104. package/dist/server/codex-auth-seed-write.d.ts.map +1 -0
  105. package/dist/server/codex-auth-seed-write.js +41 -0
  106. package/dist/server/codex-auth-seed-write.js.map +1 -0
  107. package/dist/server/codex-home.d.ts +169 -0
  108. package/dist/server/codex-home.d.ts.map +1 -0
  109. package/dist/server/codex-home.js +822 -0
  110. package/dist/server/codex-home.js.map +1 -0
  111. package/dist/server/codex-home.test.d.ts +2 -0
  112. package/dist/server/codex-home.test.d.ts.map +1 -0
  113. package/dist/server/codex-home.test.js +1287 -0
  114. package/dist/server/codex-home.test.js.map +1 -0
  115. package/dist/server/config-schema.d.ts +3 -0
  116. package/dist/server/config-schema.d.ts.map +1 -0
  117. package/dist/server/config-schema.js +67 -0
  118. package/dist/server/config-schema.js.map +1 -0
  119. package/dist/server/device-login-export.d.ts +56 -0
  120. package/dist/server/device-login-export.d.ts.map +1 -0
  121. package/dist/server/device-login-export.js +230 -0
  122. package/dist/server/device-login-export.js.map +1 -0
  123. package/dist/server/device-login-export.test.d.ts +2 -0
  124. package/dist/server/device-login-export.test.d.ts.map +1 -0
  125. package/dist/server/device-login-export.test.js +245 -0
  126. package/dist/server/device-login-export.test.js.map +1 -0
  127. package/dist/server/device-login-parse.d.ts +20 -0
  128. package/dist/server/device-login-parse.d.ts.map +1 -0
  129. package/dist/server/device-login-parse.js +155 -0
  130. package/dist/server/device-login-parse.js.map +1 -0
  131. package/dist/server/device-login-parse.test.d.ts +2 -0
  132. package/dist/server/device-login-parse.test.d.ts.map +1 -0
  133. package/dist/server/device-login-parse.test.js +269 -0
  134. package/dist/server/device-login-parse.test.js.map +1 -0
  135. package/dist/server/device-login-runner.d.ts +69 -0
  136. package/dist/server/device-login-runner.d.ts.map +1 -0
  137. package/dist/server/device-login-runner.js +110 -0
  138. package/dist/server/device-login-runner.js.map +1 -0
  139. package/dist/server/device-login-runner.test.d.ts +2 -0
  140. package/dist/server/device-login-runner.test.d.ts.map +1 -0
  141. package/dist/server/device-login-runner.test.js +201 -0
  142. package/dist/server/device-login-runner.test.js.map +1 -0
  143. package/dist/server/engine-availability.test.d.ts +2 -0
  144. package/dist/server/engine-availability.test.d.ts.map +1 -0
  145. package/dist/server/engine-availability.test.js +41 -0
  146. package/dist/server/engine-availability.test.js.map +1 -0
  147. package/dist/server/execute.acp-fallback.test.d.ts +2 -0
  148. package/dist/server/execute.acp-fallback.test.d.ts.map +1 -0
  149. package/dist/server/execute.acp-fallback.test.js +123 -0
  150. package/dist/server/execute.acp-fallback.test.js.map +1 -0
  151. package/dist/server/execute.auth-precedence.test.d.ts +2 -0
  152. package/dist/server/execute.auth-precedence.test.d.ts.map +1 -0
  153. package/dist/server/execute.auth-precedence.test.js +137 -0
  154. package/dist/server/execute.auth-precedence.test.js.map +1 -0
  155. package/dist/server/execute.auth.test.d.ts +2 -0
  156. package/dist/server/execute.auth.test.d.ts.map +1 -0
  157. package/dist/server/execute.auth.test.js +197 -0
  158. package/dist/server/execute.auth.test.js.map +1 -0
  159. package/dist/server/execute.d.ts +40 -0
  160. package/dist/server/execute.d.ts.map +1 -0
  161. package/dist/server/execute.js +1485 -0
  162. package/dist/server/execute.js.map +1 -0
  163. package/dist/server/execute.remote.test.d.ts +2 -0
  164. package/dist/server/execute.remote.test.d.ts.map +1 -0
  165. package/dist/server/execute.remote.test.js +851 -0
  166. package/dist/server/execute.remote.test.js.map +1 -0
  167. package/dist/server/execute.ssh-host-auth.test.d.ts +2 -0
  168. package/dist/server/execute.ssh-host-auth.test.d.ts.map +1 -0
  169. package/dist/server/execute.ssh-host-auth.test.js +214 -0
  170. package/dist/server/execute.ssh-host-auth.test.js.map +1 -0
  171. package/dist/server/execute.stderr-error.test.d.ts +2 -0
  172. package/dist/server/execute.stderr-error.test.d.ts.map +1 -0
  173. package/dist/server/execute.stderr-error.test.js +142 -0
  174. package/dist/server/execute.stderr-error.test.js.map +1 -0
  175. package/dist/server/execute.test.d.ts +2 -0
  176. package/dist/server/execute.test.d.ts.map +1 -0
  177. package/dist/server/execute.test.js +300 -0
  178. package/dist/server/execute.test.js.map +1 -0
  179. package/dist/server/index.d.ts +18 -0
  180. package/dist/server/index.d.ts.map +1 -0
  181. package/dist/server/index.js +84 -0
  182. package/dist/server/index.js.map +1 -0
  183. package/dist/server/output-inactivity-monitor.d.ts +62 -0
  184. package/dist/server/output-inactivity-monitor.d.ts.map +1 -0
  185. package/dist/server/output-inactivity-monitor.integration.test.d.ts +2 -0
  186. package/dist/server/output-inactivity-monitor.integration.test.d.ts.map +1 -0
  187. package/dist/server/output-inactivity-monitor.integration.test.js +136 -0
  188. package/dist/server/output-inactivity-monitor.integration.test.js.map +1 -0
  189. package/dist/server/output-inactivity-monitor.js +112 -0
  190. package/dist/server/output-inactivity-monitor.js.map +1 -0
  191. package/dist/server/output-inactivity-monitor.test.d.ts +2 -0
  192. package/dist/server/output-inactivity-monitor.test.d.ts.map +1 -0
  193. package/dist/server/output-inactivity-monitor.test.js +284 -0
  194. package/dist/server/output-inactivity-monitor.test.js.map +1 -0
  195. package/dist/server/parse.d.ts +69 -0
  196. package/dist/server/parse.d.ts.map +1 -0
  197. package/dist/server/parse.js +278 -0
  198. package/dist/server/parse.js.map +1 -0
  199. package/dist/server/parse.test.d.ts +2 -0
  200. package/dist/server/parse.test.d.ts.map +1 -0
  201. package/dist/server/parse.test.js +203 -0
  202. package/dist/server/parse.test.js.map +1 -0
  203. package/dist/server/process-activity-monitor.d.ts +21 -0
  204. package/dist/server/process-activity-monitor.d.ts.map +1 -0
  205. package/dist/server/process-activity-monitor.js +103 -0
  206. package/dist/server/process-activity-monitor.js.map +1 -0
  207. package/dist/server/process-activity-monitor.test.d.ts +2 -0
  208. package/dist/server/process-activity-monitor.test.d.ts.map +1 -0
  209. package/dist/server/process-activity-monitor.test.js +82 -0
  210. package/dist/server/process-activity-monitor.test.js.map +1 -0
  211. package/dist/server/quota-spawn-error.test.d.ts +2 -0
  212. package/dist/server/quota-spawn-error.test.d.ts.map +1 -0
  213. package/dist/server/quota-spawn-error.test.js +343 -0
  214. package/dist/server/quota-spawn-error.test.js.map +1 -0
  215. package/dist/server/quota.d.ts +66 -0
  216. package/dist/server/quota.d.ts.map +1 -0
  217. package/dist/server/quota.js +577 -0
  218. package/dist/server/quota.js.map +1 -0
  219. package/dist/server/runtime-config.d.ts +11 -0
  220. package/dist/server/runtime-config.d.ts.map +1 -0
  221. package/dist/server/runtime-config.js +389 -0
  222. package/dist/server/runtime-config.js.map +1 -0
  223. package/dist/server/runtime-config.test.d.ts +2 -0
  224. package/dist/server/runtime-config.test.d.ts.map +1 -0
  225. package/dist/server/runtime-config.test.js +389 -0
  226. package/dist/server/runtime-config.test.js.map +1 -0
  227. package/dist/server/skills.d.ts +8 -0
  228. package/dist/server/skills.d.ts.map +1 -0
  229. package/dist/server/skills.js +26 -0
  230. package/dist/server/skills.js.map +1 -0
  231. package/dist/server/ssh-host-runtime.d.ts +24 -0
  232. package/dist/server/ssh-host-runtime.d.ts.map +1 -0
  233. package/dist/server/ssh-host-runtime.js +84 -0
  234. package/dist/server/ssh-host-runtime.js.map +1 -0
  235. package/dist/server/ssh-session-state.d.ts +18 -0
  236. package/dist/server/ssh-session-state.d.ts.map +1 -0
  237. package/dist/server/ssh-session-state.js +11 -0
  238. package/dist/server/ssh-session-state.js.map +1 -0
  239. package/dist/server/test.d.ts +3 -0
  240. package/dist/server/test.d.ts.map +1 -0
  241. package/dist/server/test.js +531 -0
  242. package/dist/server/test.js.map +1 -0
  243. package/dist/server/test.remote.test.d.ts +2 -0
  244. package/dist/server/test.remote.test.d.ts.map +1 -0
  245. package/dist/server/test.remote.test.js +596 -0
  246. package/dist/server/test.remote.test.js.map +1 -0
  247. package/dist/ui/build-config.d.ts +10 -0
  248. package/dist/ui/build-config.d.ts.map +1 -0
  249. package/dist/ui/build-config.js +284 -0
  250. package/dist/ui/build-config.js.map +1 -0
  251. package/dist/ui/build-config.test.d.ts +2 -0
  252. package/dist/ui/build-config.test.d.ts.map +1 -0
  253. package/dist/ui/build-config.test.js +367 -0
  254. package/dist/ui/build-config.test.js.map +1 -0
  255. package/dist/ui/index.d.ts +4 -0
  256. package/dist/ui/index.d.ts.map +1 -0
  257. package/dist/ui/index.js +8 -0
  258. package/dist/ui/index.js.map +1 -0
  259. package/dist/ui/parse-stdout.d.ts +3 -0
  260. package/dist/ui/parse-stdout.d.ts.map +1 -0
  261. package/dist/ui/parse-stdout.js +265 -0
  262. package/dist/ui/parse-stdout.js.map +1 -0
  263. package/dist/ui/parse-stdout.test.d.ts +2 -0
  264. package/dist/ui/parse-stdout.test.d.ts.map +1 -0
  265. package/dist/ui/parse-stdout.test.js +77 -0
  266. package/dist/ui/parse-stdout.test.js.map +1 -0
  267. package/package.json +55 -4
  268. package/skills/agentmail/SKILL.md +70 -0
  269. package/skills/complain/LICENSE +27 -0
  270. package/skills/complain/SKILL.md +68 -0
  271. package/skills/paperclip/SKILL.md +864 -0
  272. package/skills/paperclip/references/api-reference.md +1814 -0
  273. package/skills/paperclip/references/artifacts.md +163 -0
  274. package/skills/paperclip/references/cases.md +570 -0
  275. package/skills/paperclip/references/company-skills.md +266 -0
  276. package/skills/paperclip/references/issue-documents.md +58 -0
  277. package/skills/paperclip/references/issue-workspaces.md +94 -0
  278. package/skills/paperclip/references/routines.md +249 -0
  279. package/skills/paperclip/references/run-diagnostics.md +28 -0
  280. package/skills/paperclip/references/workflows.md +141 -0
  281. package/skills/paperclip/scripts/paperclip-issue-update.sh +166 -0
  282. package/skills/paperclip/scripts/paperclip-upload-artifact.sh +603 -0
  283. package/skills/paperclip/scripts/submit-agent-commentary.mjs +52 -0
  284. package/skills/paperclip-board/SKILL.md +633 -0
  285. package/skills/paperclip-converting-plans-to-tasks/SKILL.md +28 -0
  286. package/skills/paperclip-create-agent/SKILL.md +213 -0
  287. package/skills/paperclip-create-agent/references/agent-instruction-templates.md +24 -0
  288. package/skills/paperclip-create-agent/references/agents/coder.md +18 -0
  289. package/skills/paperclip-create-agent/references/agents/qa.md +18 -0
  290. package/skills/paperclip-create-agent/references/agents/securityengineer.md +26 -0
  291. package/skills/paperclip-create-agent/references/agents/uxdesigner.md +18 -0
  292. package/skills/paperclip-create-agent/references/api-reference.md +110 -0
  293. package/skills/paperclip-create-agent/references/baseline-role-guide.md +22 -0
  294. package/skills/paperclip-create-agent/references/draft-review-checklist.md +29 -0
  295. package/skills/para-memory-files/SKILL.md +100 -0
  296. package/skills/para-memory-files/references/schemas.md +35 -0
  297. package/skills/slack/SKILL.md +92 -0
  298. package/skills/suggestion-box/LICENSE +27 -0
  299. package/skills/suggestion-box/SKILL.md +77 -0
  300. package/README.md +0 -3
@@ -0,0 +1,603 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+
5
+ usage() {
6
+ cat <<'EOF'
7
+ Usage:
8
+ paperclip-upload-artifact.sh FILE [options]
9
+
10
+ Uploads a generated file from the current workspace to the current Paperclip
11
+ issue, then creates an attachment-backed artifact work product by default.
12
+
13
+ Required environment for live uploads:
14
+ PAPERCLIP_API_URL, PAPERCLIP_API_KEY, PAPERCLIP_COMPANY_ID, PAPERCLIP_TASK_ID, PAPERCLIP_RUN_ID
15
+
16
+ Options:
17
+ --issue-id ID Issue id to attach to (default: PAPERCLIP_TASK_ID)
18
+ --company-id ID Company id (default: PAPERCLIP_COMPANY_ID)
19
+ --title TEXT Work product title (default: file basename)
20
+ --summary TEXT Work product summary
21
+ --content-type TYPE Override detected upload content type
22
+ --status STATUS Work product status (default: ready_for_review)
23
+ --chat-comment TEXT Bind this file to an explicit external-chat response
24
+ --retry-unknown-upload Retry after an unresolved transport failure (duplicate risk)
25
+ --no-work-product Only upload the issue attachment
26
+ --no-primary Do not mark the artifact work product primary for its type
27
+ --output FORMAT markdown or json (default: markdown)
28
+ --dry-run Print resolved upload settings without calling the API
29
+ --help, -h Show this help
30
+
31
+ Examples:
32
+ bash scripts/paperclip-upload-artifact.sh dist/demo.mp4 \
33
+ --title "Demo video render" \
34
+ --summary "MP4 render for board review"
35
+
36
+ bash scripts/paperclip-upload-artifact.sh out/walkthrough.webm \
37
+ --title "Walkthrough video" \
38
+ --content-type video/webm
39
+
40
+ bash scripts/paperclip-upload-artifact.sh out/result.png \
41
+ --title "Generated image" \
42
+ --chat-comment "Here is the requested image."
43
+ EOF
44
+ }
45
+
46
+ require_command() {
47
+ if ! command -v "$1" >/dev/null 2>&1; then
48
+ printf 'Missing required command: %s\n' "$1" >&2
49
+ exit 1
50
+ fi
51
+ }
52
+
53
+ json_bool() {
54
+ if [[ "${1:-0}" == "1" ]]; then
55
+ printf 'true'
56
+ else
57
+ printf 'false'
58
+ fi
59
+ }
60
+
61
+ detect_content_type() {
62
+ local path="$1"
63
+ local lower
64
+ lower="$(printf '%s' "$path" | tr '[:upper:]' '[:lower:]')"
65
+
66
+ case "$lower" in
67
+ *.mp4|*.m4v) printf 'video/mp4' ;;
68
+ *.webm) printf 'video/webm' ;;
69
+ *.mov|*.qt) printf 'video/quicktime' ;;
70
+ *.png) printf 'image/png' ;;
71
+ *.jpg|*.jpeg) printf 'image/jpeg' ;;
72
+ *.gif) printf 'image/gif' ;;
73
+ *.webp) printf 'image/webp' ;;
74
+ *.svg) printf 'image/svg+xml' ;;
75
+ *.pdf) printf 'application/pdf' ;;
76
+ *.txt|*.log) printf 'text/plain' ;;
77
+ *.md|*.markdown) printf 'text/markdown' ;;
78
+ *.json) printf 'application/json' ;;
79
+ *.csv) printf 'text/csv' ;;
80
+ *.html|*.htm) printf 'text/html' ;;
81
+ *.zip) printf 'application/zip' ;;
82
+ *)
83
+ if command -v file >/dev/null 2>&1; then
84
+ file --brief --mime-type "$path"
85
+ else
86
+ printf 'application/octet-stream'
87
+ fi
88
+ ;;
89
+ esac
90
+ }
91
+
92
+ sha256_file() {
93
+ local path="$1"
94
+ if command -v sha256sum >/dev/null 2>&1; then
95
+ sha256sum -- "$path" | awk '{print tolower($1)}'
96
+ elif command -v shasum >/dev/null 2>&1; then
97
+ shasum -a 256 -- "$path" | awk '{print tolower($1)}'
98
+ else
99
+ printf 'Missing required command: sha256sum or shasum\n' >&2
100
+ exit 1
101
+ fi
102
+ }
103
+
104
+ sha256_text() {
105
+ local value="$1"
106
+ if command -v sha256sum >/dev/null 2>&1; then
107
+ printf '%s' "$value" | sha256sum | awk '{print tolower($1)}'
108
+ elif command -v shasum >/dev/null 2>&1; then
109
+ printf '%s' "$value" | shasum -a 256 | awk '{print tolower($1)}'
110
+ else
111
+ printf 'Missing required command: sha256sum or shasum\n' >&2
112
+ exit 1
113
+ fi
114
+ }
115
+
116
+ helper_state_directory() {
117
+ printf '%s' "${PAPERCLIP_HELPER_STATE_DIR:-${PAPERCLIP_WORKSPACE_CWD:-$PWD}/.paperclip/artifact-helper}"
118
+ }
119
+
120
+ helper_response_file() {
121
+ local directory
122
+ directory="$(helper_state_directory)"
123
+ # TMPDIR can name a controller-owned directory outside a CLI sandbox.
124
+ (umask 077; mkdir -p "$directory" && mktemp "$directory/response.XXXXXX")
125
+ }
126
+
127
+ request_json() {
128
+ local method="$1"
129
+ local url="$2"
130
+ local body="${3:-}"
131
+ local response_file
132
+ local status_code
133
+
134
+ response_file="$(helper_response_file)"
135
+ if [[ -n "$body" ]]; then
136
+ status_code="$(
137
+ curl -sS -X "$method" -w '%{http_code}' -o "$response_file" \
138
+ "$url" \
139
+ -H "Authorization: Bearer $PAPERCLIP_API_KEY" \
140
+ -H "X-Paperclip-Run-Id: $PAPERCLIP_RUN_ID" \
141
+ -H 'Content-Type: application/json' \
142
+ --data-binary "$body"
143
+ )"
144
+ else
145
+ status_code="$(
146
+ curl -sS -X "$method" -w '%{http_code}' -o "$response_file" \
147
+ "$url" \
148
+ -H "Authorization: Bearer $PAPERCLIP_API_KEY" \
149
+ -H "X-Paperclip-Run-Id: $PAPERCLIP_RUN_ID"
150
+ )"
151
+ fi
152
+
153
+ if [[ "$status_code" -lt 200 || "$status_code" -ge 300 ]]; then
154
+ printf 'Request failed (%s): %s\n' "$status_code" "$url" >&2
155
+ cat "$response_file" >&2
156
+ printf '\n' >&2
157
+ rm -f "$response_file"
158
+ exit 1
159
+ fi
160
+
161
+ cat "$response_file"
162
+ rm -f "$response_file"
163
+ }
164
+
165
+ upload_file() {
166
+ local url="$1"
167
+ local path="$2"
168
+ local content_type="$3"
169
+ local escaped_path
170
+ local response_file
171
+ local status_code
172
+ local curl_status=0
173
+ local indeterminate=0
174
+
175
+ escaped_path="${path//\\/\\\\}"
176
+ escaped_path="${escaped_path//\"/\\\"}"
177
+ response_file="$(helper_response_file)"
178
+ status_code="$(
179
+ curl -sS -X POST -w '%{http_code}' -o "$response_file" \
180
+ "$url" \
181
+ -H "Authorization: Bearer $PAPERCLIP_API_KEY" \
182
+ -H "X-Paperclip-Run-Id: $PAPERCLIP_RUN_ID" \
183
+ -F "file=@\"${escaped_path}\";type=${content_type}"
184
+ )" || curl_status=$?
185
+
186
+ if [[ "$curl_status" -ne 0 ]]; then
187
+ rm -f "$response_file"
188
+ return 75
189
+ fi
190
+
191
+ if [[ "$status_code" -lt 200 || "$status_code" -ge 300 ]]; then
192
+ printf 'Upload failed (%s): %s\n' "$status_code" "$url" >&2
193
+ cat "$response_file" >&2
194
+ printf '\n' >&2
195
+ # The bridge uses a structured 409 outcome after a possibly committed
196
+ # mutation. Keep the marker so the next invocation reconciles by listing.
197
+ if [[ "$status_code" == "409" ]] && jq -e '.outcome == "indeterminate"' "$response_file" >/dev/null 2>&1; then
198
+ indeterminate=1
199
+ fi
200
+ rm -f "$response_file"
201
+ if [[ "$status_code" == "408" || "$status_code" -ge 500 || "$indeterminate" == "1" ]]; then
202
+ return 75
203
+ fi
204
+ return 1
205
+ fi
206
+
207
+ cat "$response_file"
208
+ rm -f "$response_file"
209
+ }
210
+
211
+ operation_lock_path=""
212
+ operation_lock_owner=""
213
+ operation_lock_held=0
214
+ operation_state_root=""
215
+
216
+ process_start_identity() {
217
+ local pid="$1"
218
+ ps -p "$pid" -o lstart= 2>/dev/null | tr -s '[:space:]' ' ' | sed 's/^ //;s/ $//'
219
+ }
220
+
221
+ release_operation_lock() {
222
+ if [[ "$operation_lock_held" == "1" && -n "$operation_lock_path" ]]; then
223
+ local current_owner=""
224
+ current_owner="$(readlink "$operation_lock_path" 2>/dev/null || true)"
225
+ if [[ "$current_owner" == "$operation_lock_owner" ]]; then
226
+ rm -f "$operation_lock_path"
227
+ fi
228
+ operation_lock_held=0
229
+ fi
230
+ }
231
+
232
+ acquire_operation_lock() {
233
+ local operation_key="$1"
234
+ local attempts=0
235
+
236
+ umask 077
237
+ operation_state_root="$(helper_state_directory)"
238
+ mkdir -p "$operation_state_root"
239
+ operation_lock_path="$operation_state_root/$operation_key.lock"
240
+ operation_lock_owner="$$|$(process_start_identity "$$" || true)"
241
+ while ! ln -s "$operation_lock_owner" "$operation_lock_path" 2>/dev/null; do
242
+ local owner_pid=""
243
+ local owner_start=""
244
+ local current_lock_owner=""
245
+ current_lock_owner="$(readlink "$operation_lock_path" 2>/dev/null || true)"
246
+ IFS='|' read -r owner_pid owner_start <<<"$current_lock_owner"
247
+ if [[ "$owner_pid" =~ ^[0-9]+$ ]]; then
248
+ local current_owner_start=""
249
+ current_owner_start="$(process_start_identity "$owner_pid" || true)"
250
+ if ! kill -0 "$owner_pid" 2>/dev/null ||
251
+ [[ -n "$owner_start" && -n "$current_owner_start" && "$owner_start" != "$current_owner_start" ]]; then
252
+ # Serialize stale-lock reclamation separately. Without this guard, two
253
+ # contenders can both observe the old owner and the slower one can
254
+ # delete the faster contender's newly acquired live lock.
255
+ local reclaim_lock_path="$operation_lock_path.reclaim"
256
+ if mkdir "$reclaim_lock_path" 2>/dev/null; then
257
+ local guarded_owner=""
258
+ guarded_owner="$(readlink "$operation_lock_path" 2>/dev/null || true)"
259
+ if [[ "$guarded_owner" == "$current_lock_owner" ]]; then
260
+ rm -f "$operation_lock_path"
261
+ fi
262
+ rmdir "$reclaim_lock_path" 2>/dev/null || true
263
+ continue
264
+ fi
265
+ fi
266
+ fi
267
+ attempts=$((attempts + 1))
268
+ if [[ "$attempts" -ge 400 ]]; then
269
+ printf 'Another matching artifact upload is still in progress; retry after it finishes.\n' >&2
270
+ exit 1
271
+ fi
272
+ sleep 0.05
273
+ done
274
+ operation_lock_held=1
275
+ }
276
+
277
+ file_path=""
278
+ issue_id="${PAPERCLIP_TASK_ID:-}"
279
+ company_id="${PAPERCLIP_COMPANY_ID:-}"
280
+ title=""
281
+ summary=""
282
+ content_type=""
283
+ status="ready_for_review"
284
+ chat_comment=""
285
+ create_work_product=1
286
+ is_primary=1
287
+ output_format="markdown"
288
+ dry_run=0
289
+ retry_unknown_upload=0
290
+
291
+ while [[ $# -gt 0 ]]; do
292
+ case "$1" in
293
+ --issue-id)
294
+ issue_id="${2:-}"
295
+ shift 2
296
+ ;;
297
+ --company-id)
298
+ company_id="${2:-}"
299
+ shift 2
300
+ ;;
301
+ --title)
302
+ title="${2:-}"
303
+ shift 2
304
+ ;;
305
+ --summary)
306
+ summary="${2:-}"
307
+ shift 2
308
+ ;;
309
+ --content-type)
310
+ content_type="${2:-}"
311
+ shift 2
312
+ ;;
313
+ --status)
314
+ status="${2:-}"
315
+ shift 2
316
+ ;;
317
+ --chat-comment)
318
+ chat_comment="${2:-}"
319
+ shift 2
320
+ ;;
321
+ --no-work-product)
322
+ create_work_product=0
323
+ shift
324
+ ;;
325
+ --retry-unknown-upload)
326
+ retry_unknown_upload=1
327
+ shift
328
+ ;;
329
+ --no-primary)
330
+ is_primary=0
331
+ shift
332
+ ;;
333
+ --output)
334
+ output_format="${2:-}"
335
+ shift 2
336
+ ;;
337
+ --dry-run)
338
+ dry_run=1
339
+ shift
340
+ ;;
341
+ --help|-h)
342
+ usage
343
+ exit 0
344
+ ;;
345
+ --*)
346
+ printf 'Unknown argument: %s\n' "$1" >&2
347
+ usage >&2
348
+ exit 1
349
+ ;;
350
+ *)
351
+ if [[ -n "$file_path" ]]; then
352
+ printf 'Unexpected positional argument: %s\n' "$1" >&2
353
+ usage >&2
354
+ exit 1
355
+ fi
356
+ file_path="$1"
357
+ shift
358
+ ;;
359
+ esac
360
+ done
361
+
362
+ if [[ -z "$file_path" ]]; then
363
+ printf 'Missing file path.\n' >&2
364
+ usage >&2
365
+ exit 1
366
+ fi
367
+
368
+ if [[ ! -f "$file_path" ]]; then
369
+ printf 'Artifact file does not exist: %s\n' "$file_path" >&2
370
+ exit 1
371
+ fi
372
+
373
+ if [[ "$output_format" != "markdown" && "$output_format" != "json" ]]; then
374
+ printf 'Unsupported output format: %s\n' "$output_format" >&2
375
+ exit 1
376
+ fi
377
+
378
+ if [[ -n "$chat_comment" && "$create_work_product" != "1" ]]; then
379
+ printf '%s\n' '--chat-comment requires the attachment-backed work product created by this helper.' >&2
380
+ exit 1
381
+ fi
382
+
383
+ require_command curl
384
+ require_command jq
385
+
386
+ if [[ -z "$title" ]]; then
387
+ title="$(basename "$file_path")"
388
+ fi
389
+
390
+ if [[ -z "$content_type" ]]; then
391
+ content_type="$(detect_content_type "$file_path")"
392
+ fi
393
+
394
+ if [[ "$dry_run" == "1" ]]; then
395
+ create_work_product_json="$(json_bool "$create_work_product")"
396
+ is_primary_json="$(json_bool "$is_primary")"
397
+ jq -n \
398
+ --arg file "$file_path" \
399
+ --arg issueId "$issue_id" \
400
+ --arg companyId "$company_id" \
401
+ --arg title "$title" \
402
+ --arg summary "$summary" \
403
+ --arg contentType "$content_type" \
404
+ --arg status "$status" \
405
+ --arg chatComment "$chat_comment" \
406
+ --argjson createWorkProduct "$create_work_product_json" \
407
+ --argjson isPrimary "$is_primary_json" \
408
+ '{file: $file, issueId: $issueId, companyId: $companyId, title: $title, summary: $summary, contentType: $contentType, status: $status, chatComment: (if $chatComment == "" then null else $chatComment end), createWorkProduct: $createWorkProduct, isPrimary: $isPrimary}'
409
+ exit 0
410
+ fi
411
+
412
+ if [[ -z "${PAPERCLIP_API_URL:-}" || -z "${PAPERCLIP_API_KEY:-}" || -z "${PAPERCLIP_RUN_ID:-}" ]]; then
413
+ printf 'Missing PAPERCLIP_API_URL, PAPERCLIP_API_KEY, or PAPERCLIP_RUN_ID.\n' >&2
414
+ exit 1
415
+ fi
416
+
417
+ if [[ -z "$issue_id" || -z "$company_id" ]]; then
418
+ printf 'Missing issue or company id. Pass --issue-id/--company-id or set PAPERCLIP_TASK_ID/PAPERCLIP_COMPANY_ID.\n' >&2
419
+ exit 1
420
+ fi
421
+
422
+ api_root="${PAPERCLIP_API_URL%/}"
423
+ case "$api_root" in
424
+ */api) api_base="$api_root" ;;
425
+ *) api_base="$api_root/api" ;;
426
+ esac
427
+ file_sha256="$(sha256_file "$file_path")"
428
+ original_filename="$(basename "$file_path")"
429
+ operation_key="$(
430
+ sha256_text "$api_base|$company_id|$issue_id|$PAPERCLIP_RUN_ID|$original_filename|$file_sha256|$content_type"
431
+ )"
432
+ acquire_operation_lock "$operation_key"
433
+ trap release_operation_lock EXIT
434
+
435
+ attachment=""
436
+ reused_attachment=0
437
+ unknown_upload_marker="$operation_state_root/$operation_key.uncertain"
438
+ lookup_attempts=1
439
+ if [[ -f "$unknown_upload_marker" && "$retry_unknown_upload" != "1" ]]; then
440
+ lookup_attempts=20
441
+ fi
442
+ for ((lookup_attempt = 1; lookup_attempt <= lookup_attempts; lookup_attempt++)); do
443
+ existing_attachments="$(request_json GET "$api_base/issues/$issue_id/attachments")"
444
+ attachment="$(
445
+ jq -nc \
446
+ --argjson attachments "$existing_attachments" \
447
+ --arg runId "$PAPERCLIP_RUN_ID" \
448
+ --arg sha256 "$file_sha256" \
449
+ --arg originalFilename "$original_filename" \
450
+ --arg contentType "$content_type" \
451
+ 'first(
452
+ $attachments[]
453
+ | select(
454
+ .originatingRunId == $runId
455
+ and ((.sha256 // "") | ascii_downcase) == ($sha256 | ascii_downcase)
456
+ and (.originalFilename // "") == $originalFilename
457
+ and ((.contentType // "") | ascii_downcase) == ($contentType | ascii_downcase)
458
+ )
459
+ ) // empty'
460
+ )"
461
+ if [[ -n "$attachment" ]]; then
462
+ reused_attachment=1
463
+ rm -f "$unknown_upload_marker"
464
+ break
465
+ fi
466
+ if [[ "$lookup_attempt" -lt "$lookup_attempts" ]]; then
467
+ sleep 0.25
468
+ fi
469
+ done
470
+
471
+ if [[ -z "$attachment" && -f "$unknown_upload_marker" && "$retry_unknown_upload" != "1" ]]; then
472
+ printf '%s\n' 'A previous matching upload ended without a definitive response, and Paperclip has not exposed its durable attachment yet.' >&2
473
+ printf '%s\n' 'Retry this command later. If the upload definitely did not commit, pass --retry-unknown-upload to accept the duplicate-file risk.' >&2
474
+ exit 1
475
+ fi
476
+
477
+ if [[ -z "$attachment" ]]; then
478
+ rm -f "$unknown_upload_marker"
479
+ : >"$unknown_upload_marker"
480
+ upload_status=0
481
+ attachment="$(
482
+ upload_file \
483
+ "$api_base/companies/$company_id/issues/$issue_id/attachments" \
484
+ "$file_path" \
485
+ "$content_type"
486
+ )" || upload_status=$?
487
+ if [[ "$upload_status" -ne 0 ]]; then
488
+ if [[ "$upload_status" -ne 75 ]]; then
489
+ rm -f "$unknown_upload_marker"
490
+ fi
491
+ exit 1
492
+ fi
493
+ fi
494
+
495
+ attachment_id="$(jq -r '.id // empty' <<<"$attachment")"
496
+ content_path="$(jq -r '.contentPath // empty' <<<"$attachment")"
497
+ download_path="$(jq -r '.downloadPath // (if .contentPath then (.contentPath + "?download=1") else "" end)' <<<"$attachment")"
498
+ if [[ -z "$attachment_id" || -z "$content_path" || -z "$download_path" ]]; then
499
+ printf 'Upload response did not include attachment path metadata.\n' >&2
500
+ printf '%s\n' "$attachment" >&2
501
+ exit 1
502
+ fi
503
+ rm -f "$unknown_upload_marker"
504
+
505
+ work_product="null"
506
+ if [[ "$create_work_product" == "1" ]]; then
507
+ is_primary_json="$(json_bool "$is_primary")"
508
+ byte_size="$(jq -r '.byteSize // 0' <<<"$attachment")"
509
+ open_path="$(jq -r '.openPath // .contentPath // empty' <<<"$attachment")"
510
+ original_filename="$(jq -r '.originalFilename // empty' <<<"$attachment")"
511
+
512
+ work_product_payload="$(
513
+ jq -nc \
514
+ --arg title "$title" \
515
+ --arg summary "$summary" \
516
+ --arg status "$status" \
517
+ --arg runId "$PAPERCLIP_RUN_ID" \
518
+ --arg attachmentId "$attachment_id" \
519
+ --arg contentType "$content_type" \
520
+ --argjson byteSize "$byte_size" \
521
+ --arg contentPath "$content_path" \
522
+ --arg openPath "$open_path" \
523
+ --arg downloadPath "$download_path" \
524
+ --arg originalFilename "$original_filename" \
525
+ --argjson isPrimary "$is_primary_json" \
526
+ '{
527
+ type: "artifact",
528
+ provider: "paperclip",
529
+ title: $title,
530
+ status: $status,
531
+ reviewState: "none",
532
+ isPrimary: $isPrimary,
533
+ healthStatus: "unknown",
534
+ summary: (if $summary == "" then null else $summary end),
535
+ createdByRunId: $runId,
536
+ metadata: {
537
+ attachmentId: $attachmentId,
538
+ contentType: $contentType,
539
+ byteSize: $byteSize,
540
+ contentPath: $contentPath,
541
+ openPath: $openPath,
542
+ downloadPath: $downloadPath,
543
+ originalFilename: (if $originalFilename == "" then null else $originalFilename end)
544
+ }
545
+ }'
546
+ )"
547
+
548
+ work_product="$(
549
+ request_json \
550
+ POST \
551
+ "$api_base/issues/$issue_id/work-products" \
552
+ "$work_product_payload"
553
+ )"
554
+ fi
555
+
556
+ chat_response="null"
557
+ if [[ -n "$chat_comment" ]]; then
558
+ chat_comment_payload="$(
559
+ jq -nc \
560
+ --arg body "$chat_comment" \
561
+ --arg attachmentId "$attachment_id" \
562
+ '{body: $body, attachmentIds: [$attachmentId]}'
563
+ )"
564
+ chat_response="$(
565
+ request_json \
566
+ POST \
567
+ "$api_base/issues/$issue_id/comments" \
568
+ "$chat_comment_payload"
569
+ )"
570
+ chat_comment_id="$(jq -r '.id // empty' <<<"$chat_response")"
571
+ if [[ -z "$chat_comment_id" ]]; then
572
+ printf 'Chat attachment response did not include a comment id.\n' >&2
573
+ exit 1
574
+ fi
575
+ fi
576
+
577
+ if [[ "$output_format" == "json" ]]; then
578
+ jq -n \
579
+ --argjson attachment "$attachment" \
580
+ --argjson workProduct "$work_product" \
581
+ --argjson chatComment "$chat_response" \
582
+ '{attachment: $attachment, workProduct: $workProduct, chatComment: $chatComment}'
583
+ exit 0
584
+ fi
585
+
586
+ work_product_id="$(jq -r '.id // empty' <<<"$work_product")"
587
+
588
+ if [[ "$reused_attachment" == "1" ]]; then
589
+ printf 'Reused matching artifact from this run\n\n'
590
+ else
591
+ printf 'Uploaded artifact\n\n'
592
+ fi
593
+ printf -- '- Attachment: [%s](%s)\n' "$title" "$content_path"
594
+ printf -- '- Download: [%s](%s)\n' "$title" "$download_path"
595
+ printf -- '- Attachment ID: `%s`\n' "$attachment_id"
596
+ if [[ -n "$work_product_id" ]]; then
597
+ printf -- '- Work product ID: `%s`\n' "$work_product_id"
598
+ fi
599
+ if [[ -n "$chat_comment" ]]; then
600
+ printf -- '- Paperclip comment binding: saved. External publication requires an authorized active chat origin; this helper does not confirm provider delivery.\n'
601
+ fi
602
+ printf '\nFinal comment snippet:\n\n'
603
+ printf -- '- Artifact: [%s](%s)\n' "$title" "$content_path"
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ // One bounded, nonfatal submission. Feedback comes from stdin, never shell arguments.
3
+ import { randomUUID } from "node:crypto";
4
+
5
+ const MAX_BODY_LENGTH = 524288;
6
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
7
+
8
+ async function readBounded(stream, maxBytes) {
9
+ const chunks = [];
10
+ let bytes = 0;
11
+ for await (const chunk of stream) {
12
+ bytes += chunk.length;
13
+ if (bytes > maxBytes) throw new Error("Input too large");
14
+ chunks.push(chunk);
15
+ }
16
+ return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Buffer.concat(chunks));
17
+ }
18
+
19
+ try {
20
+ const [kind, idempotencyKey = randomUUID()] = process.argv.slice(2);
21
+ if (kind !== "complaint" && kind !== "suggestion") throw new Error("Invalid kind");
22
+ // Bound bytes before decoding; JavaScript string length matches the server's ceiling.
23
+ const body = await readBounded(process.stdin, 4 * MAX_BODY_LENGTH);
24
+ if (!body.trim() || body.length > MAX_BODY_LENGTH) throw new Error("Invalid body");
25
+ const { PAPERCLIP_API_URL, PAPERCLIP_API_KEY, PAPERCLIP_COMPANY_ID, PAPERCLIP_RUN_ID } = process.env;
26
+ if (!PAPERCLIP_API_URL || !PAPERCLIP_API_KEY || !UUID.test(PAPERCLIP_COMPANY_ID ?? "") || !UUID.test(PAPERCLIP_RUN_ID ?? "")) {
27
+ throw new Error("Missing run context");
28
+ }
29
+ const apiUrl = PAPERCLIP_API_URL.replace(/\/+$/, "").replace(/\/api$/, "");
30
+ const response = await fetch(`${apiUrl}/api/companies/${PAPERCLIP_COMPANY_ID}/agent-commentary`, {
31
+ method: "POST",
32
+ headers: {
33
+ "Content-Type": "application/json",
34
+ Authorization: `Bearer ${PAPERCLIP_API_KEY}`,
35
+ "X-Paperclip-Run-Id": PAPERCLIP_RUN_ID,
36
+ },
37
+ body: JSON.stringify({ kind, body, idempotencyKey }),
38
+ // Never forward run credentials through redirects. Bound the entire HTTP attempt.
39
+ redirect: "error",
40
+ signal: AbortSignal.timeout(10_000),
41
+ });
42
+ if (response.status !== 200 && response.status !== 201) {
43
+ await response.body?.cancel();
44
+ throw new Error("Submission failed");
45
+ }
46
+ const acknowledgement = JSON.parse(await readBounded(response.body, 4096));
47
+ if (typeof acknowledgement.id !== "string" || !acknowledgement.id) throw new Error("Invalid acknowledgement");
48
+ console.log("Feedback stored.");
49
+ } catch {
50
+ // No exception text: transport errors may contain credentials or submitted text.
51
+ console.error("Feedback could not be confirmed. Ignore this failure, do not retry, and continue the primary task.");
52
+ }