@runcofactor/cli 0.10.0 → 0.15.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.
Files changed (166) hide show
  1. package/dist/account-22LMP5PX.js +255 -0
  2. package/dist/account-22LMP5PX.js.map +1 -0
  3. package/dist/{api-catalog-GFGCLVS4.js → api-catalog-WTFQNLK6.js} +5 -4
  4. package/dist/{api-catalog-GFGCLVS4.js.map → api-catalog-WTFQNLK6.js.map} +1 -1
  5. package/dist/{attachment-SJC7D7FY.js → attachment-U3NKVPEY.js} +5 -4
  6. package/dist/{attachment-SJC7D7FY.js.map → attachment-U3NKVPEY.js.map} +1 -1
  7. package/dist/augmentor-5GMNAX4M.js +198 -0
  8. package/dist/augmentor-5GMNAX4M.js.map +1 -0
  9. package/dist/{auth-EN6NQCJY.js → auth-VQG2CDUD.js} +3 -2
  10. package/dist/{chunk-A4OFTUVV.js → chunk-3X3NW7QA.js} +7 -4
  11. package/dist/chunk-3X3NW7QA.js.map +1 -0
  12. package/dist/{chunk-N7HFALX3.js → chunk-46IUJXSD.js} +2 -2
  13. package/dist/{chunk-IMPZAX6L.js → chunk-5GD47G2D.js} +37 -1
  14. package/dist/{chunk-IMPZAX6L.js.map → chunk-5GD47G2D.js.map} +1 -1
  15. package/dist/{chunk-B2VISN2V.js → chunk-7VMO2WOZ.js} +238 -68
  16. package/dist/chunk-7VMO2WOZ.js.map +1 -0
  17. package/dist/{chunk-QFDOWABX.js → chunk-CMGI7UZD.js} +6 -3
  18. package/dist/chunk-CMGI7UZD.js.map +1 -0
  19. package/dist/{chunk-XQXVG7RA.js → chunk-FNPMWDUQ.js} +3 -3
  20. package/dist/chunk-G4UYGRZR.js +2 -0
  21. package/dist/{chunk-I4QLI3JO.js → chunk-HDFYUFBI.js} +2 -2
  22. package/dist/chunk-JMJVGMXI.js +92 -0
  23. package/dist/chunk-JMJVGMXI.js.map +1 -0
  24. package/dist/{chunk-SJJW77WN.js → chunk-JYGNMKZ5.js} +129 -38
  25. package/dist/chunk-JYGNMKZ5.js.map +1 -0
  26. package/dist/{chunk-52IO7ACJ.js → chunk-KCHKFYVX.js} +68 -10
  27. package/dist/{chunk-52IO7ACJ.js.map → chunk-KCHKFYVX.js.map} +1 -1
  28. package/dist/{chunk-ZD3KHESI.js → chunk-KRWRUU6R.js} +27 -7
  29. package/dist/chunk-KRWRUU6R.js.map +1 -0
  30. package/dist/{chunk-CLAWT7BJ.js → chunk-NHTEKEYE.js} +3 -3
  31. package/dist/{chunk-WOHL4FTB.js → chunk-PRBRSIZP.js} +16 -10
  32. package/dist/chunk-PRBRSIZP.js.map +1 -0
  33. package/dist/{chunk-GKY2KXO5.js → chunk-UETBLPKM.js} +154 -37
  34. package/dist/chunk-UETBLPKM.js.map +1 -0
  35. package/dist/{chunk-4PNOV7OV.js → chunk-VGYN2KU2.js} +9284 -1421
  36. package/dist/chunk-VGYN2KU2.js.map +1 -0
  37. package/dist/{chunk-Q4BO4Z5V.js → chunk-XJ5YYYGC.js} +4 -4
  38. package/dist/{credential-COLTBV6D.js → credential-E6KUHRGU.js} +24 -20
  39. package/dist/credential-E6KUHRGU.js.map +1 -0
  40. package/dist/{credential-template-EEPYFG7R.js → credential-template-4GPOPBGD.js} +30 -28
  41. package/dist/credential-template-4GPOPBGD.js.map +1 -0
  42. package/dist/{debug-workflow-KOVH5GOP.js → debug-workflow-XCLCY6S7.js} +5 -4
  43. package/dist/{debug-workflow-KOVH5GOP.js.map → debug-workflow-XCLCY6S7.js.map} +1 -1
  44. package/dist/{docs-3SSORHB5.js → docs-COCZYMW6.js} +95 -10
  45. package/dist/docs-COCZYMW6.js.map +1 -0
  46. package/dist/{doctor-OTSIWV6G.js → doctor-ERIVTCQS.js} +9 -5
  47. package/dist/doctor-ERIVTCQS.js.map +1 -0
  48. package/dist/environment-7Y4BV6XY.js +221 -0
  49. package/dist/environment-7Y4BV6XY.js.map +1 -0
  50. package/dist/{feature-flag-T2LRZME3.js → feature-flag-MHONEX6T.js} +164 -16
  51. package/dist/feature-flag-MHONEX6T.js.map +1 -0
  52. package/dist/index.js +123 -58
  53. package/dist/index.js.map +1 -1
  54. package/dist/{init-TGWRECT2.js → init-OROOM4HF.js} +5 -4
  55. package/dist/{init-TGWRECT2.js.map → init-OROOM4HF.js.map} +1 -1
  56. package/dist/{install-DXSNWZKO.js → install-OJFXHY6U.js} +7 -7
  57. package/dist/{issues-XIZOPX6T.js → issues-32GONR6C.js} +5 -4
  58. package/dist/{issues-XIZOPX6T.js.map → issues-32GONR6C.js.map} +1 -1
  59. package/dist/{knobs-NBINZIUB.js → knobs-UQGGY3CP.js} +7 -5
  60. package/dist/knobs-UQGGY3CP.js.map +1 -0
  61. package/dist/{list-3TDHK637.js → list-ZMIKEC5P.js} +5 -4
  62. package/dist/{list-3TDHK637.js.map → list-ZMIKEC5P.js.map} +1 -1
  63. package/dist/{local-HICVD6PU.js → local-PUD24GGQ.js} +7 -6
  64. package/dist/{local-HICVD6PU.js.map → local-PUD24GGQ.js.map} +1 -1
  65. package/dist/{login-UOIUXVUK.js → login-BSO7YX2D.js} +5 -4
  66. package/dist/{login-UOIUXVUK.js.map → login-BSO7YX2D.js.map} +1 -1
  67. package/dist/{mcp-54IJEOUA.js → mcp-4LS7OJUT.js} +24 -25
  68. package/dist/mcp-4LS7OJUT.js.map +1 -0
  69. package/dist/{pdf-extract-ABWV3L5X.js → pdf-extract-YHE54XU4.js} +2 -2
  70. package/dist/product-3JKSJCBC.js +346 -0
  71. package/dist/product-3JKSJCBC.js.map +1 -0
  72. package/dist/{property-UXLOLPTD.js → property-K5DBL4UE.js} +76 -4
  73. package/dist/property-K5DBL4UE.js.map +1 -0
  74. package/dist/{psql-BYUUNLGG.js → psql-PQFUFTSE.js} +3 -2
  75. package/dist/{psql-BYUUNLGG.js.map → psql-PQFUFTSE.js.map} +1 -1
  76. package/dist/{record-4TR2UIIS.js → record-EIIYLFJ4.js} +16 -17
  77. package/dist/record-EIIYLFJ4.js.map +1 -0
  78. package/dist/{redis-35VBUYW7.js → redis-BU36EZZI.js} +3 -2
  79. package/dist/redis-BU36EZZI.js.map +1 -0
  80. package/dist/{release-OOLTUBUT.js → release-LYC2P7DZ.js} +5 -4
  81. package/dist/{release-OOLTUBUT.js.map → release-LYC2P7DZ.js.map} +1 -1
  82. package/dist/{sandbox-XGSUU6G7.js → sandbox-CKHXXZHU.js} +55 -10
  83. package/dist/sandbox-CKHXXZHU.js.map +1 -0
  84. package/dist/{scenarios-GWLJEGHA.js → scenarios-2XJ2G3KR.js} +5 -4
  85. package/dist/{scenarios-GWLJEGHA.js.map → scenarios-2XJ2G3KR.js.map} +1 -1
  86. package/dist/{session-MYFNZPRP.js → session-UTOD5ZYH.js} +77 -10
  87. package/dist/session-UTOD5ZYH.js.map +1 -0
  88. package/dist/{skill-KM34LDMO.js → skill-GMAERMQL.js} +220 -70
  89. package/dist/skill-GMAERMQL.js.map +1 -0
  90. package/dist/skills/debug-run/SKILL.md +40 -23
  91. package/dist/skills/debug-run/history/1.2.0.md +262 -0
  92. package/dist/skills/debug-run/history/1.3.0.md +273 -0
  93. package/dist/skills/debug-run/history/1.3.1.md +279 -0
  94. package/dist/skills/debug-run/version.json +1 -1
  95. package/dist/skills/optimize-cache/SKILL.md +233 -0
  96. package/dist/{spec-RA3CFEKG.js → spec-2NP36U3Y.js} +54 -25
  97. package/dist/spec-2NP36U3Y.js.map +1 -0
  98. package/dist/{src-LB4HBTJQ.js → src-4T6GHXVO.js} +19 -11
  99. package/dist/src-4T6GHXVO.js.map +1 -0
  100. package/dist/{src-N3TPKGTY.js → src-CG52HEE7.js} +10 -7
  101. package/dist/{src-UVDX5UP6.js → src-PK5OZXCM.js} +4 -2
  102. package/dist/src-UEOOC425.js +5941 -0
  103. package/dist/src-UEOOC425.js.map +1 -0
  104. package/dist/{start-PSEQSQA3.js → start-3C7EEFW2.js} +5 -4
  105. package/dist/{start-PSEQSQA3.js.map → start-3C7EEFW2.js.map} +1 -1
  106. package/dist/{tag-YY6YAABQ.js → tag-JSHOMLBR.js} +6 -5
  107. package/dist/{task-IQC3YR5K.js → task-YGWVYTBJ.js} +5 -4
  108. package/dist/{task-IQC3YR5K.js.map → task-YGWVYTBJ.js.map} +1 -1
  109. package/dist/{test-suite-DZNJFXDW.js → test-suite-LI7ZH367.js} +12 -7
  110. package/dist/{test-suite-DZNJFXDW.js.map → test-suite-LI7ZH367.js.map} +1 -1
  111. package/dist/trace-UMLOSIIR.js +16 -0
  112. package/dist/{triage-ORG45R5W.js → triage-ZWJG4NBJ.js} +6 -5
  113. package/dist/triage-ZWJG4NBJ.js.map +1 -0
  114. package/dist/{upgrade-L2VYMP2V.js → upgrade-S7CGEK6H.js} +3 -3
  115. package/dist/{workflow-XYFH5LTP.js → workflow-T4HSAOGW.js} +316 -241
  116. package/dist/workflow-T4HSAOGW.js.map +1 -0
  117. package/dist/{workflow-cache-NQJQFWMV.js → workflow-cache-XVEZ36KF.js} +140 -7
  118. package/dist/workflow-cache-XVEZ36KF.js.map +1 -0
  119. package/dist/{workflow-debug-BGD4UIXU.js → workflow-debug-T2BULXZ7.js} +9 -8
  120. package/dist/{workflow-debug-BGD4UIXU.js.map → workflow-debug-T2BULXZ7.js.map} +1 -1
  121. package/dist/{workflow-proposals-MTUDX46O.js → workflow-proposals-XXEZICN2.js} +5 -6
  122. package/dist/workflow-proposals-XXEZICN2.js.map +1 -0
  123. package/package.json +2 -1
  124. package/dist/chunk-4PNOV7OV.js.map +0 -1
  125. package/dist/chunk-A4OFTUVV.js.map +0 -1
  126. package/dist/chunk-B2VISN2V.js.map +0 -1
  127. package/dist/chunk-GKY2KXO5.js.map +0 -1
  128. package/dist/chunk-JICSYFRJ.js +0 -46
  129. package/dist/chunk-JICSYFRJ.js.map +0 -1
  130. package/dist/chunk-QFDOWABX.js.map +0 -1
  131. package/dist/chunk-SJJW77WN.js.map +0 -1
  132. package/dist/chunk-WOHL4FTB.js.map +0 -1
  133. package/dist/chunk-ZD3KHESI.js.map +0 -1
  134. package/dist/credential-COLTBV6D.js.map +0 -1
  135. package/dist/credential-template-EEPYFG7R.js.map +0 -1
  136. package/dist/docs-3SSORHB5.js.map +0 -1
  137. package/dist/doctor-OTSIWV6G.js.map +0 -1
  138. package/dist/feature-flag-T2LRZME3.js.map +0 -1
  139. package/dist/knobs-NBINZIUB.js.map +0 -1
  140. package/dist/mcp-54IJEOUA.js.map +0 -1
  141. package/dist/property-UXLOLPTD.js.map +0 -1
  142. package/dist/record-4TR2UIIS.js.map +0 -1
  143. package/dist/redis-35VBUYW7.js.map +0 -1
  144. package/dist/sandbox-XGSUU6G7.js.map +0 -1
  145. package/dist/session-MYFNZPRP.js.map +0 -1
  146. package/dist/skill-KM34LDMO.js.map +0 -1
  147. package/dist/spec-RA3CFEKG.js.map +0 -1
  148. package/dist/src-LB4HBTJQ.js.map +0 -1
  149. package/dist/trace-HXIW7U2D.js +0 -14
  150. package/dist/workflow-XYFH5LTP.js.map +0 -1
  151. package/dist/workflow-cache-NQJQFWMV.js.map +0 -1
  152. package/dist/workflow-proposals-MTUDX46O.js.map +0 -1
  153. /package/dist/{auth-EN6NQCJY.js.map → auth-VQG2CDUD.js.map} +0 -0
  154. /package/dist/{chunk-N7HFALX3.js.map → chunk-46IUJXSD.js.map} +0 -0
  155. /package/dist/{chunk-XQXVG7RA.js.map → chunk-FNPMWDUQ.js.map} +0 -0
  156. /package/dist/{pdf-extract-ABWV3L5X.js.map → chunk-G4UYGRZR.js.map} +0 -0
  157. /package/dist/{chunk-I4QLI3JO.js.map → chunk-HDFYUFBI.js.map} +0 -0
  158. /package/dist/{chunk-CLAWT7BJ.js.map → chunk-NHTEKEYE.js.map} +0 -0
  159. /package/dist/{chunk-Q4BO4Z5V.js.map → chunk-XJ5YYYGC.js.map} +0 -0
  160. /package/dist/{install-DXSNWZKO.js.map → install-OJFXHY6U.js.map} +0 -0
  161. /package/dist/{src-N3TPKGTY.js.map → pdf-extract-YHE54XU4.js.map} +0 -0
  162. /package/dist/{src-UVDX5UP6.js.map → src-CG52HEE7.js.map} +0 -0
  163. /package/dist/{tag-YY6YAABQ.js.map → src-PK5OZXCM.js.map} +0 -0
  164. /package/dist/{trace-HXIW7U2D.js.map → tag-JSHOMLBR.js.map} +0 -0
  165. /package/dist/{triage-ORG45R5W.js.map → trace-UMLOSIIR.js.map} +0 -0
  166. /package/dist/{upgrade-L2VYMP2V.js.map → upgrade-S7CGEK6H.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/property.ts","../src/property-skill.ts"],"sourcesContent":["/**\n * CLI Property Management\n *\n * List properties and their linked GitHub repos.\n */\n\nimport process from 'node:process';\nimport { resolveConfig, hasFlag, getArgValue } from './auth.js';\nimport { fetchProperties, apiRequest, getApplicationArg } from './cli-helpers.js';\nimport { runPropertySkill } from './property-skill.js';\n\nfunction pad(s: string, n: number): string {\n return s.padEnd(n);\n}\n\nfunction printHelp(): void {\n console.log(\n [\n 'canary application: Manage applications (alias: canary property)',\n '',\n 'Sub-commands:',\n ' list List all applications',\n ' create [options] Create a new application',\n ' repo link [options] Link a GitHub repo to an application',\n ' repo update [options] Update an existing repo link',\n ' repo unlink [options] Unlink a GitHub repo from an application',\n ' skill <action> [options] Manage the application\\'s app skill (run `canary application skill help` for details)',\n '',\n 'Create options:',\n ' --name <name> Application name (required)',\n ' --base-url <url> Application base URL (required)',\n ' --description <text> Optional description',\n ' --agent-context <text> Optional agent context (max 8000 chars)',\n ' --env-var <NAME[:sensitive]> Declare a per-environment variable (repeatable); values set per-environment, injected as $var.ENV.<NAME>',\n '',\n 'Repo link/update/unlink options:',\n ' --application <app_xxx|uuid> Application ID (required; alias: --property)',\n ' --repo <owner/name> Repo full name (required for link/unlink)',\n ' --repo-id <uuid> Repo link UUID (required for update)',\n ' --role <frontend|backend|...> Conventional role (free-form)',\n ' --root-dir <path> Monorepo subdirectory hint',\n ' --agent-hint <text> Free-form hint for the planner agent',\n '',\n 'Common options:',\n ' --json Output as JSON',\n ].join('\\n')\n );\n}\n\ntype GitHubRepo = {\n id: string;\n repoFullName: string;\n repoName: string;\n defaultBranch: string;\n rootDir: string | null;\n role: string | null;\n};\n\nasync function handleList(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const properties = await fetchProperties(apiUrl, token);\n\n if (json) {\n console.log(JSON.stringify(properties, null, 2));\n return;\n }\n\n if (properties.length === 0) {\n console.log('No applications found.');\n return;\n }\n\n console.log(`${pad('Name', 30)} ${pad('Base URL', 40)} ID`);\n for (const p of properties) {\n console.log(`${pad(p.name, 30)} ${pad(p.baseUrl, 40)} ${p.id}`);\n }\n\n // Show linked repos for each property\n console.log('');\n for (const p of properties) {\n const reposRes = await apiRequest<{ ok: boolean; items: GitHubRepo[] }>(\n apiUrl, token, 'GET', `/org/properties/${p.id}/github-repos`\n );\n const repos = reposRes.ok ? (reposRes.items ?? []) : [];\n if (repos.length > 0) {\n console.log(`${p.name} repos:`);\n for (const r of repos) {\n const dir = r.rootDir && r.rootDir !== '/' ? ` (${r.rootDir})` : '';\n const role = r.role ? ` [${r.role}]` : '';\n console.log(` ${r.repoFullName}:${r.defaultBranch}${role}${dir}`);\n }\n }\n }\n}\n\n/**\n * Parse repeatable `--env-var NAME[:sensitive]` flags into env-var definitions.\n * Examples: `--env-var API_URL`, `--env-var API_TOKEN:sensitive`.\n */\nfunction parseEnvVarDefinitions(\n argv: string[]\n): Array<{ name: string; sensitive?: boolean }> {\n const defs: Array<{ name: string; sensitive?: boolean }> = [];\n for (let i = 0; i < argv.length; i++) {\n if (argv[i] !== '--env-var') continue;\n const raw = argv[i + 1];\n if (!raw || raw.startsWith('-')) continue;\n const [name, modifier] = raw.split(':');\n if (!name) continue;\n // Accept `NAME` or `NAME:sensitive`; ignore-with-no-effect any other suffix.\n defs.push({ name, ...(modifier === 'sensitive' ? { sensitive: true } : {}) });\n }\n return defs;\n}\n\nasync function handleCreate(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const name = getArgValue(argv, '--name');\n const baseUrl = getArgValue(argv, '--base-url');\n const description = getArgValue(argv, '--description');\n const agentContext = getArgValue(argv, '--agent-context');\n const envVarDefinitions = parseEnvVarDefinitions(argv);\n\n if (!name || !baseUrl) {\n console.error('Error: --name and --base-url are required.');\n console.error('Usage: canary application create --name <name> --base-url <url>');\n process.exit(1);\n }\n\n const body: Record<string, unknown> = { name, baseUrl };\n if (description !== undefined) body.description = description;\n if (agentContext !== undefined) body.agentContext = agentContext;\n if (envVarDefinitions.length > 0) body.envVarDefinitions = envVarDefinitions;\n\n const result = await apiRequest<{ ok: boolean; id?: string; error?: string }>(\n apiUrl,\n token,\n 'POST',\n '/org/properties',\n body\n );\n\n if (!result.ok) {\n if (json) {\n console.log(JSON.stringify(result, null, 2));\n } else {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n }\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(result, null, 2));\n return;\n }\n\n console.log(`Created application \"${name}\" (${result.id})`);\n}\n\nasync function handleRepoLink(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const propertyId = getApplicationArg(argv);\n const repo = getArgValue(argv, '--repo');\n const role = getArgValue(argv, '--role');\n const rootDir = getArgValue(argv, '--root-dir');\n const agentHint = getArgValue(argv, '--agent-hint');\n\n if (!propertyId || !repo) {\n console.error('Error: --application and --repo are required.');\n process.exit(1);\n }\n\n const body: Record<string, unknown> = { repoFullName: repo };\n if (role !== undefined) body.role = role;\n if (rootDir !== undefined) body.rootDir = rootDir;\n if (agentHint !== undefined) body.agentHint = agentHint;\n\n const result = await apiRequest<{ ok: boolean; id?: string; error?: string }>(\n apiUrl,\n token,\n 'POST',\n `/org/properties/${propertyId}/github-repos`,\n body\n );\n\n if (!result.ok) {\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.log(`Linked ${repo} to application ${propertyId} (${result.id})`);\n}\n\nasync function handleRepoUpdate(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const propertyId = getApplicationArg(argv);\n const repoId = getArgValue(argv, '--repo-id');\n const role = getArgValue(argv, '--role');\n const rootDir = getArgValue(argv, '--root-dir');\n const agentHint = getArgValue(argv, '--agent-hint');\n\n if (!propertyId || !repoId) {\n console.error('Error: --application and --repo-id are required.');\n process.exit(1);\n }\n\n const body: Record<string, unknown> = {};\n if (role !== undefined) body.role = role;\n if (rootDir !== undefined) body.rootDir = rootDir;\n if (agentHint !== undefined) body.agentHint = agentHint;\n\n const result = await apiRequest<{ ok: boolean; id?: string; error?: string }>(\n apiUrl,\n token,\n 'PATCH',\n `/org/properties/${propertyId}/github-repos/${repoId}`,\n body\n );\n\n if (!result.ok) {\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.log(`Updated repo link ${repoId}`);\n}\n\nasync function handleRepoUnlink(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const propertyId = getApplicationArg(argv);\n const repo = getArgValue(argv, '--repo');\n\n if (!propertyId || !repo) {\n console.error('Error: --application and --repo are required.');\n process.exit(1);\n }\n\n const result = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl,\n token,\n 'DELETE',\n `/org/properties/${propertyId}/github-repos/${encodeURIComponent(repo)}`\n );\n\n if (!result.ok) {\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.log(`Unlinked ${repo} from application ${propertyId}`);\n}\n\nasync function handleRepo(argv: string[], apiUrl: string, token: string): Promise<void> {\n const [action, ...rest] = argv;\n switch (action) {\n case 'link':\n await handleRepoLink(rest, apiUrl, token);\n break;\n case 'update':\n await handleRepoUpdate(rest, apiUrl, token);\n break;\n case 'unlink':\n await handleRepoUnlink(rest, apiUrl, token);\n break;\n default:\n console.error(`Unknown repo action: ${action ?? '(none)'}`);\n printHelp();\n process.exit(1);\n }\n}\n\nexport async function runProperty(argv: string[]): Promise<void> {\n const [subCommand, ...rest] = argv;\n\n if (!subCommand || subCommand === 'help' || hasFlag(argv, '--help', '-h')) {\n printHelp();\n return;\n }\n\n // `skill guide` and `skill help` are doc-only; skip auth resolution so\n // unauthenticated agents can discover the methodology before logging in.\n if (subCommand === 'skill') {\n const skillAction = rest[0];\n if (!skillAction || skillAction === 'help' || skillAction === 'guide') {\n await runPropertySkill(rest, '', '');\n return;\n }\n }\n\n const { apiUrl, token } = await resolveConfig(argv);\n\n const globalFlags = new Set(['--env', '--api-url', '--token']);\n const args = rest.filter((arg, i) => {\n if (globalFlags.has(arg)) return false;\n if (i > 0 && globalFlags.has(rest[i - 1])) return false;\n return true;\n });\n\n switch (subCommand) {\n case 'list':\n await handleList(args, apiUrl, token);\n break;\n case 'create':\n await handleCreate(args, apiUrl, token);\n break;\n case 'repo':\n await handleRepo(args, apiUrl, token);\n break;\n case 'skill':\n await runPropertySkill(args, apiUrl, token);\n break;\n default:\n console.error(`Unknown sub-command: ${subCommand}`);\n printHelp();\n process.exit(1);\n }\n}\n","/**\n * CLI: `canary property skill` — manage a property's app skill\n *\n * App skill = the per-property knowledge base injected into the cloud workflow\n * browser agent's system prompt. CLI is a thin client over the existing\n * /org/properties/:id/context endpoints. Source defaults to 'cli' so authored\n * items are distinguishable from browser-bootstrap or human-manual edits.\n */\n\nimport { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport process from 'node:process';\nimport { getArgValue, hasFlag } from './auth.js';\nimport { apiRequest, getApplicationArg } from './cli-helpers.js';\n\nconst HERE = dirname(fileURLToPath(import.meta.url));\nconst GUIDE_PATH = join(HERE, 'property-skill-guide.md');\n\nconst SECTIONS = [\n 'general',\n 'technology',\n 'product',\n 'ui',\n 'tenancy',\n 'auth',\n 'roles_permissions',\n 'navigation',\n 'feature_gating',\n 'environments',\n 'data_lifecycle',\n 'async_realtime',\n 'localization',\n 'feedback_errors',\n 'idiosyncrasies',\n] as const;\ntype Section = (typeof SECTIONS)[number];\n\ntype ContextItem = {\n id: string;\n propertyId: string;\n section: Section;\n itemKey: string;\n itemLabel: string;\n content: string;\n version: number;\n source: 'bootstrap' | 'workflow' | 'manual' | 'cli';\n sourceId: string | null;\n createdBy: string | null;\n createdAt: string;\n};\n\ntype ListResponse = {\n ok: boolean;\n error?: string;\n data?: { items: ContextItem[]; grouped: Record<string, ContextItem[]> };\n};\n\nfunction printSkillHelp(): void {\n console.log(\n [\n 'canary application skill: Manage an application\\'s app skill (per-application knowledge for QA browser agents). Alias: canary property skill. (--property accepted as an alias for --application.)',\n '',\n 'Sub-commands:',\n ' guide Print the full authoring methodology (start here)',\n ' list [--application <id>] [--section S] [--format json|table]',\n ' get --application <id> --section S --key K [--version N] [--format json|md]',\n ' set --application <id> --section S --key K --label L --content @file|\"text\" [--source-id <repo@sha>]',\n ' delete --application <id> --section S --key K',\n ' history --application <id> --section S --key K [--format json|table]',\n ' export --application <id> [--format md|json]',\n ' import --application <id> --file <bundle.json> [--source-id <repo@sha>]',\n '',\n 'New to app skills? Run `canary application skill guide` for the authoring methodology.',\n '',\n 'Sections:',\n ' ' + SECTIONS.join(', '),\n '',\n 'Notes:',\n ' --content @path reads content from a file (preferred for multi-line markdown)',\n ' --content \"text\" literal content string',\n ' Source defaults to \"cli\". Provide --source-id <repo@sha> for provenance.',\n '',\n 'Bundle.json shape for import:',\n ' { \"items\": [ { \"section\": S, \"itemKey\": K, \"itemLabel\": L, \"content\": \"...\" }, ... ] }',\n ].join('\\n')\n );\n}\n\nfunction readContent(value: string): string {\n if (value.startsWith('@')) {\n const path = value.slice(1);\n return readFileSync(path, 'utf8');\n }\n return value;\n}\n\nfunction isSection(s: string | undefined): s is Section {\n return !!s && (SECTIONS as readonly string[]).includes(s);\n}\n\nasync function handleList(argv: string[], apiUrl: string, token: string): Promise<void> {\n const propertyId = getApplicationArg(argv);\n const section = getArgValue(argv, '--section');\n const format = getArgValue(argv, '--format') ?? (hasFlag(argv, '--json') ? 'json' : 'table');\n\n if (!propertyId) {\n console.error('Error: --application is required (alias: --property).');\n process.exit(1);\n }\n\n const result = await apiRequest<ListResponse>(\n apiUrl,\n token,\n 'GET',\n `/org/properties/${propertyId}/context`\n );\n\n if (!result.ok) {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n let items = result.data?.items ?? [];\n if (section) items = items.filter((i) => i.section === section);\n\n if (format === 'json') {\n console.log(JSON.stringify(items, null, 2));\n return;\n }\n\n if (items.length === 0) {\n console.log('(no items)');\n return;\n }\n\n const grouped = new Map<string, ContextItem[]>();\n for (const item of items) {\n const arr = grouped.get(item.section) ?? [];\n arr.push(item);\n grouped.set(item.section, arr);\n }\n\n for (const sec of SECTIONS) {\n const arr = grouped.get(sec);\n if (!arr || arr.length === 0) continue;\n console.log(`\\n[${sec}]`);\n for (const item of arr) {\n const provenance = item.source === 'cli' && item.sourceId ? ` (${item.sourceId})` : item.source !== 'cli' ? ` (${item.source})` : '';\n console.log(` ${item.itemKey} — ${item.itemLabel}${provenance}`);\n }\n }\n}\n\nasync function handleGet(argv: string[], apiUrl: string, token: string): Promise<void> {\n const propertyId = getApplicationArg(argv);\n const section = getArgValue(argv, '--section');\n const itemKey = getArgValue(argv, '--key');\n const versionArg = getArgValue(argv, '--version');\n const format = getArgValue(argv, '--format') ?? 'md';\n\n if (!propertyId || !section || !itemKey) {\n console.error('Error: --application, --section, --key are required.');\n process.exit(1);\n }\n if (!isSection(section)) {\n console.error(`Error: invalid section \"${section}\". One of: ${SECTIONS.join(', ')}`);\n process.exit(1);\n }\n\n // Current value comes from list; specific version from history.\n if (versionArg) {\n const v = Number(versionArg);\n const result = await apiRequest<{ ok: boolean; error?: string; data?: ContextItem[] }>(\n apiUrl,\n token,\n 'GET',\n `/org/properties/${propertyId}/context/history?section=${section}&itemKey=${encodeURIComponent(itemKey)}`\n );\n if (!result.ok) {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n const item = (result.data ?? []).find((i) => i.version === v);\n if (!item) {\n console.error(`Error: no version ${v} for ${section}/${itemKey}`);\n process.exit(1);\n }\n printItem(item, format);\n return;\n }\n\n const result = await apiRequest<ListResponse>(\n apiUrl,\n token,\n 'GET',\n `/org/properties/${propertyId}/context`\n );\n if (!result.ok) {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n const item = (result.data?.items ?? []).find(\n (i) => i.section === section && i.itemKey === itemKey\n );\n if (!item) {\n console.error(`Error: no item ${section}/${itemKey}`);\n process.exit(1);\n }\n printItem(item, format);\n}\n\nfunction printItem(item: ContextItem, format: string): void {\n if (format === 'json') {\n console.log(JSON.stringify(item, null, 2));\n return;\n }\n console.log(`# ${item.itemLabel}`);\n console.log(`section: ${item.section}`);\n console.log(`key: ${item.itemKey}`);\n console.log(`version: ${item.version}`);\n console.log(`source: ${item.source}${item.sourceId ? ` (${item.sourceId})` : ''}`);\n console.log('');\n console.log(item.content);\n}\n\nasync function handleSet(argv: string[], apiUrl: string, token: string): Promise<void> {\n const propertyId = getApplicationArg(argv);\n const section = getArgValue(argv, '--section');\n const itemKey = getArgValue(argv, '--key');\n const itemLabel = getArgValue(argv, '--label');\n const contentArg = getArgValue(argv, '--content');\n const sourceId = getArgValue(argv, '--source-id');\n\n if (!propertyId || !section || !itemKey || !itemLabel || contentArg === undefined) {\n console.error('Error: --application, --section, --key, --label, --content are required.');\n process.exit(1);\n }\n if (!isSection(section)) {\n console.error(`Error: invalid section \"${section}\". One of: ${SECTIONS.join(', ')}`);\n process.exit(1);\n }\n\n const content = readContent(contentArg);\n\n const body: Record<string, unknown> = {\n section,\n itemKey,\n itemLabel,\n content,\n source: 'cli',\n };\n if (sourceId !== undefined) body.sourceId = sourceId;\n\n const result = await apiRequest<{ ok: boolean; error?: string; data?: ContextItem }>(\n apiUrl,\n token,\n 'PUT',\n `/org/properties/${propertyId}/context/items`,\n body\n );\n\n if (!result.ok) {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n console.log(`Set [${section}] ${itemKey} (v${result.data?.version ?? '?'})`);\n}\n\nasync function handleDelete(argv: string[], apiUrl: string, token: string): Promise<void> {\n const propertyId = getApplicationArg(argv);\n const section = getArgValue(argv, '--section');\n const itemKey = getArgValue(argv, '--key');\n\n if (!propertyId || !section || !itemKey) {\n console.error('Error: --application, --section, --key are required.');\n process.exit(1);\n }\n if (!isSection(section)) {\n console.error(`Error: invalid section \"${section}\". One of: ${SECTIONS.join(', ')}`);\n process.exit(1);\n }\n\n const result = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl,\n token,\n 'DELETE',\n `/org/properties/${propertyId}/context/items`,\n { section, itemKey }\n );\n\n if (!result.ok) {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n console.log(`Deleted [${section}] ${itemKey}`);\n}\n\nasync function handleHistory(argv: string[], apiUrl: string, token: string): Promise<void> {\n const propertyId = getApplicationArg(argv);\n const section = getArgValue(argv, '--section');\n const itemKey = getArgValue(argv, '--key');\n const format = getArgValue(argv, '--format') ?? 'table';\n\n if (!propertyId || !section || !itemKey) {\n console.error('Error: --application, --section, --key are required.');\n process.exit(1);\n }\n if (!isSection(section)) {\n console.error(`Error: invalid section \"${section}\". One of: ${SECTIONS.join(', ')}`);\n process.exit(1);\n }\n\n const result = await apiRequest<{ ok: boolean; error?: string; data?: ContextItem[] }>(\n apiUrl,\n token,\n 'GET',\n `/org/properties/${propertyId}/context/history?section=${section}&itemKey=${encodeURIComponent(itemKey)}`\n );\n\n if (!result.ok) {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n const versions = result.data ?? [];\n if (format === 'json') {\n console.log(JSON.stringify(versions, null, 2));\n return;\n }\n if (versions.length === 0) {\n console.log('(no history)');\n return;\n }\n for (const v of versions) {\n const provenance = v.sourceId ? ` (${v.sourceId})` : '';\n console.log(`v${v.version} ${v.source}${provenance} ${v.createdAt}`);\n }\n}\n\nasync function handleExport(argv: string[], apiUrl: string, token: string): Promise<void> {\n const propertyId = getApplicationArg(argv);\n const format = getArgValue(argv, '--format') ?? 'md';\n\n if (!propertyId) {\n console.error('Error: --application is required (alias: --property).');\n process.exit(1);\n }\n\n const result = await apiRequest<ListResponse>(\n apiUrl,\n token,\n 'GET',\n `/org/properties/${propertyId}/context`\n );\n\n if (!result.ok) {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n const items = result.data?.items ?? [];\n if (format === 'json') {\n console.log(JSON.stringify({ items }, null, 2));\n return;\n }\n\n const grouped = new Map<string, ContextItem[]>();\n for (const item of items) {\n const arr = grouped.get(item.section) ?? [];\n arr.push(item);\n grouped.set(item.section, arr);\n }\n for (const sec of SECTIONS) {\n const arr = grouped.get(sec);\n if (!arr || arr.length === 0) continue;\n console.log(`## ${sec}`);\n console.log('');\n for (const item of arr) {\n console.log(`### ${item.itemLabel} (\\`${item.itemKey}\\`)`);\n console.log('');\n console.log(item.content);\n console.log('');\n }\n }\n}\n\ntype BundleItem = { section: string; itemKey: string; itemLabel: string; content: string };\ntype Bundle = { items: BundleItem[] };\n\nasync function handleImport(argv: string[], apiUrl: string, token: string): Promise<void> {\n const propertyId = getApplicationArg(argv);\n const file = getArgValue(argv, '--file');\n const sourceId = getArgValue(argv, '--source-id');\n\n if (!propertyId || !file) {\n console.error('Error: --application and --file are required.');\n process.exit(1);\n }\n\n let bundle: Bundle;\n try {\n bundle = JSON.parse(readFileSync(file, 'utf8')) as Bundle;\n } catch (err) {\n console.error(`Error parsing ${file}: ${(err as Error).message}`);\n process.exit(1);\n return;\n }\n\n if (!bundle.items || !Array.isArray(bundle.items)) {\n console.error('Error: bundle.json must have an \"items\" array.');\n process.exit(1);\n }\n\n let ok = 0;\n let fail = 0;\n for (const item of bundle.items) {\n if (!isSection(item.section)) {\n console.error(` ✗ [${item.section}] ${item.itemKey}: invalid section`);\n fail++;\n continue;\n }\n const body: Record<string, unknown> = {\n section: item.section,\n itemKey: item.itemKey,\n itemLabel: item.itemLabel,\n content: item.content,\n source: 'cli',\n };\n if (sourceId) body.sourceId = sourceId;\n\n const result = await apiRequest<{ ok: boolean; error?: string; data?: ContextItem }>(\n apiUrl,\n token,\n 'PUT',\n `/org/properties/${propertyId}/context/items`,\n body\n );\n\n if (result.ok) {\n console.log(` ✓ [${item.section}] ${item.itemKey} (v${result.data?.version ?? '?'})`);\n ok++;\n } else {\n console.error(` ✗ [${item.section}] ${item.itemKey}: ${result.error ?? 'Unknown error'}`);\n fail++;\n }\n }\n\n console.log(`\\nImported ${ok}/${ok + fail} items${fail ? ` (${fail} failed)` : ''}.`);\n if (fail > 0) process.exit(1);\n}\n\nfunction handleGuide(): void {\n try {\n const guide = readFileSync(GUIDE_PATH, 'utf8');\n process.stdout.write(guide);\n if (!guide.endsWith('\\n')) process.stdout.write('\\n');\n } catch (err) {\n console.error(`Error: could not read authoring guide at ${GUIDE_PATH}`);\n console.error((err as Error).message);\n process.exit(1);\n }\n}\n\nexport async function runPropertySkill(argv: string[], apiUrl: string, token: string): Promise<void> {\n const [action, ...rest] = argv;\n\n if (!action || action === 'help' || hasFlag(argv, '--help', '-h')) {\n printSkillHelp();\n return;\n }\n\n switch (action) {\n case 'guide':\n handleGuide();\n return;\n case 'list':\n await handleList(rest, apiUrl, token);\n break;\n case 'get':\n await handleGet(rest, apiUrl, token);\n break;\n case 'set':\n await handleSet(rest, apiUrl, token);\n break;\n case 'delete':\n await handleDelete(rest, apiUrl, token);\n break;\n case 'history':\n await handleHistory(rest, apiUrl, token);\n break;\n case 'export':\n await handleExport(rest, apiUrl, token);\n break;\n case 'import':\n await handleImport(rest, apiUrl, token);\n break;\n default:\n console.error(`Unknown sk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AAM,cAAc,IAAI;AAElD,QAAM,cAAc,oBAAI,IAAI,CAAC,SAAS,aAAa,SAAS,CAAC;AAC7D,QAAM,OAAO,KAAK,OAAO,CAAC,KAAK,MAAM;AACnC,QAAI,YAAY,IAAI,GAAG,EAAG,QAAO;AACjC,QAAI,IAAI,KAAK,YAAY,IAAI,KAAK,IAAI,CAAC,CAAC,EAAG,QAAO;AAClD,WAAO;AAAA,EACT,CAAC;AAED,UAAQ,YAAY;AAAA,IAClB,KAAK;AACH,YAAMD,YAAW,MAAM,QAAQ,KAAK;AACpC;AAAA,IACF,KAAK;AACH,YAAM,aAAa,MAAM,QAAQ,KAAK;AACtC;AAAA,IACF,KAAK;AACH,YAAM,WAAW,MAAM,QAAQ,KAAK;AACpC;AAAA,IACF,KAAK;AACH,YAAM,iBAAiB,MAAM,QAAQ,KAAK;AAC1C;AAAA,IACF;AACE,cAAQ,MAAM,wBAAwB,UAAU,EAAE;AAClD,gBAAU;AACV,MAAAC,SAAQ,KAAK,CAAC;AAAA,EAClB;AACF;","names":["process","result","item","handleList","process"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/record.ts"],"sourcesContent":["/**\n * `canary record` — Record browser interactions for flow creation.\n *\n * Launches a headed browser, injects an in-page capture script,\n * and records user interactions (clicks, inputs, navigation) enriched\n * with accessibility snapshots and element info. On stop, bundles\n * everything as JSONL + video and uploads to the API.\n *\n * @module record\n */\n\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { getCanaryTmpDir } from '@chatsdet/tmp';\nimport process from 'node:process';\nimport { resolveConfig, getArgValue, hasFlag } from './auth.js';\nimport { apiRequest, selectCredential, downloadStorageState } from './cli-helpers.js';\n\nimport { INTERACTION_CAPTURE_SCRIPT } from './record-interaction-script.js';\nimport type { CapturedInteractionEvent } from './session/types.js';\n\n/** Recording event — uses the shared CapturedInteractionEvent type. */\ntype RecordingEvent = CapturedInteractionEvent;\n\n/** Click event narrowing helper for enrichment. */\ntype RecordingClickEvent = Extract<CapturedInteractionEvent, { type: 'click' }>;\n\ninterface CredentialDetail {\n id: string;\n name: string;\n loginUrl?: string;\n storageStateS3Key?: string | null;\n}\n\nexport async function runRecord(argv: string[]): Promise<void> {\n if (hasFlag(argv, '--help', '-h')) {\n console.log(\n [\n 'Usage: canary record [options]',\n '',\n 'Record browser interactions for flow creation.',\n '',\n 'Options:',\n ' --credential <id> Credential ID (skip interactive selection)',\n ' --url <startUrl> URL to navigate to after launch',\n ' --output <dir> Local output directory (default: temp dir)',\n ' --env <env> Environment (local, dev, prod)',\n ' --no-upload Save locally only, skip API upload',\n '',\n 'Press Ctrl+C to stop recording.',\n ].join('\\n')\n );\n return;\n }\n\n const config = await resolveConfig(argv);\n const credentialArg = getArgValue(argv, '--credential');\n const startUrl = getArgValue(argv, '--url');\n const outputDir = getArgValue(argv, '--output');\n const skipUpload = hasFlag(argv, '--no-upload');\n\n // 1. Fetch and select credential\n console.log('Fetching credentials...');\n const credential = await selectCredential(config.apiUrl, config.token, credentialArg);\n if (!credential) {\n process.exit(1);\n }\n\n console.log(`Using credential: ${credential.name}`);\n\n const propertyId = credential.propertyId;\n\n // 3. Download storage state if available\n let storageStatePath: string | undefined;\n if (credential.storageStateS3Key) {\n console.log('Downloading storage state...');\n storageStatePath = await downloadStorageState({\n apiUrl: config.apiUrl,\n token: config.token,\n propertyId: credential.propertyId,\n credentialId: credential.id,\n });\n if (storageStatePath) {\n console.log('Storage state loaded.');\n } else {\n console.warn('Could not download storage state, continuing without it.');\n }\n }\n\n // 4. Get credential detail for loginUrl\n let loginUrl = credential.loginUrl;\n if (!loginUrl) {\n const detail = await apiRequest<{ ok: boolean; credential?: CredentialDetail }>(\n config.apiUrl,\n config.token,\n 'GET',\n `/org/properties/${propertyId}/credentials/${credential.id}`\n );\n loginUrl = detail.credential?.loginUrl ?? undefined;\n }\n\n // 5. Determine start URL\n const navigateUrl = startUrl ?? loginUrl;\n if (!navigateUrl) {\n console.warn(\n 'No start URL provided and no login URL on credential. Browser will open to about:blank.'\n );\n }\n\n // 6. Launch browser\n console.log('Launching browser...');\n\n // Lazy-load playwright-dependent modules\n const { PlaywrightClient, consoleLogger, captureElementAtPoint } =\n await import('@chatsdet/browser-core');\n\n const client = new PlaywrightClient({ logger: consoleLogger });\n await client.connect({\n browserMode: 'headed',\n storageStatePath,\n recordVideo: true,\n });\n\n const page = await client.getPageForReplay();\n if (!page) {\n console.error('Failed to get browser page.');\n await client.disconnect();\n process.exit(1);\n }\n\n // 7. Inject interaction capture script\n await page.addInitScript(INTERACTION_CAPTURE_SCRIPT);\n await page.evaluate(INTERACTION_CAPTURE_SCRIPT);\n\n // 8. Navigate\n if (navigateUrl) {\n console.log(`Navigating to ${navigateUrl}`);\n await page.goto(navigateUrl, { waitUntil: 'domcontentloaded', timeout: 30_000 }).catch(() => {\n console.warn('Navigation timed out or failed, continuing anyway.');\n });\n }\n\n const events: RecordingEvent[] = [];\n let running = true;\n\n // Emit initial-url event so we know the starting page\n const currentUrl = page.url();\n const initialUrlEvent: RecordingEvent = {\n type: 'initial-url',\n ts: Date.now(),\n url: currentUrl,\n };\n try {\n const snapshot = await page.ariaSnapshot({ mode: 'ai' });\n (initialUrlEvent as { snapshot?: string }).snapshot = snapshot;\n } catch {\n // Snapshot may fail\n }\n events.push(initialUrlEvent);\n process.stdout.write(` [${events.length}] initial-url → ${currentUrl}\\n`);\n\n console.log('\\nRecording started. Interact with the browser.');\n console.log('Press Ctrl+C to stop recording.\\n');\n\n // 9. Poll loop — collect events from the page\n const pollInterval = setInterval(async () => {\n if (!running) return;\n try {\n const raw = await page.evaluate(() => {\n const evts =\n (window as unknown as { __canaryRecordedEvents?: unknown[] }).__canaryRecordedEvents ??\n [];\n (window as unknown as { __canaryRecordedEvents: unknown[] }).__canaryRecordedEvents = [];\n return evts;\n });\n\n if (!Array.isArray(raw) || raw.length === 0) return;\n\n for (const evt of raw as RecordingEvent[]) {\n // Enrich click events with element info and periodic snapshots\n if (evt.type === 'click') {\n const clickEvt = evt as RecordingClickEvent;\n try {\n const info = await captureElementAtPoint(page, clickEvt.x, clickEvt.y);\n if (info) {\n clickEvt.elementInfo = info as unknown as Record<string, unknown>;\n }\n } catch {\n // Element may have disappeared\n }\n\n // Snapshot every click for full page context\n try {\n const snapshot = await page.ariaSnapshot({ mode: 'ai' });\n clickEvt.snapshot = snapshot;\n } catch {\n // Snapshot may fail during navigation\n }\n }\n\n // Enrich navigation events with snapshot\n if (evt.type === 'navigation') {\n try {\n const snapshot = await page.ariaSnapshot({ mode: 'ai' });\n (evt as { snapshot?: string }).snapshot = snapshot;\n } catch {\n // Snapshot may fail during navigation\n }\n }\n\n events.push(evt);\n const label =\n evt.type === 'click'\n ? `click (${(evt as RecordingClickEvent).tagName})`\n : evt.type === 'input'\n ? `input`\n : evt.type === 'change'\n ? `change (${(evt as { tagName: string }).tagName})`\n : evt.type === 'navigation'\n ? `navigation → ${(evt as { url: string }).url}`\n : evt.type === 'initial-url'\n ? `initial-url → ${(evt as { url: string }).url}`\n : `keydown: ${(evt as { key: string }).key}`;\n process.stdout.write(` [${events.length}] ${label}\\n`);\n }\n } catch {\n // Page may have been closed\n }\n }, 500);\n\n // 10. Handle Ctrl+C\n const cleanup = async () => {\n if (!running) return;\n running = false;\n clearInterval(pollInterval);\n\n console.log(`\\nRecording stopped. ${events.length} events captured.`);\n\n // Save video\n console.log('Saving video...');\n const videoResult = await client.saveVideo();\n await client.disconnect();\n\n // Clean up temp storage state\n if (storageStatePath) {\n await fs.unlink(storageStatePath).catch(() => {});\n }\n\n // Prepare output directory\n const outDir = outputDir ?? path.join(getCanaryTmpDir(), `canary-recording-${Date.now()}`);\n await fs.mkdir(outDir, { recursive: true });\n\n // Write events JSONL\n const eventsPath = path.join(outDir, 'events.jsonl');\n const lines = events.map((e) => JSON.stringify(e)).join('\\n');\n await fs.writeFile(eventsPath, lines, 'utf-8');\n console.log(`Events saved: ${eventsPath}`);\n\n // Copy video if available\n let videoPath: string | undefined;\n if (videoResult?.videoPath) {\n videoPath = path.join(outDir, 'video.webm');\n await fs.copyFile(videoResult.videoPath, videoPath);\n console.log(`Video saved: ${videoPath}`);\n }\n\n // Upload to API\n if (!skipUpload && events.length > 0) {\n console.log('Uploading recording...');\n try {\n const formData = new FormData();\n formData.append('propertyId', propertyId);\n formData.append('credentialId', credential.id);\n\n const eventsBlob = new Blob([lines], { type: 'application/x-ndjson' });\n formData.append('events', eventsBlob, 'events.jsonl');\n\n if (videoPath) {\n const videoBuffer = await fs.readFile(videoPath);\n const videoBlob = new Blob([videoBuffer], { type: 'video/webm' });\n formData.append('video', videoBlob, 'video.webm');\n }\n\n const res = await fetch(`${config.apiUrl}/org/recordings/upload`, {\n method: 'POST',\n headers: { Authorization: `Bearer ${config.token}` },\n body: formData,\n });\n\n const json = (await res.json()) as {\n ok: boolean;\n recordingId?: string;\n error?: string;\n };\n\n if (json.ok) {\n console.log(`Recording uploaded. ID: ${json.recordingId}`);\n } else {\n console.error(`Upload failed: ${json.error ?? 'Unknown error'}`);\n }\n } catch (err) {\n console.error('Upload failed:', err instanceof Error ? err.message : err);\n }\n }\n\n console.log(`\\nOutput directory: ${outDir}`);\n process.exit(0);\n };\n\n process.on('SIGINT', () => void cleanup());\n process.on('SIGTERM', () => void cleanup());\n\n // Also stop if the page is closed\n page.on('close', () => void cleanup());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAWA,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,OAAO,aAAa;AAoBpB,eAAsB,UAAU,MAA+B;AAC7D,MAAI,QAAQ,MAAM,UAAU,IAAI,GAAG;AACjC,YAAQ;AAAA,MACN;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,EAAE,KAAK,IAAI;AAAA,IACb;AACA;AAAA,EACF;AAEA,QAAM,SAAS,MAAM,cAAc,IAAI;AACvC,QAAM,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AAO;AACL,kBAAQ,MAAM,kBAAkB,KAAK,SAAS,eAAe,EAAE;AAAA,QACjE;AAAA,MACF,SAAS,KAAK;AACZ,gBAAQ,MAAM,kBAAkB,eAAe,QAAQ,IAAI,UAAU,GAAG;AAAA,MAC1E;AAAA,IACF;AAEA,YAAQ,IAAI;AAAA,oBAAuB,MAAM,EAAE;AAC3C,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,UAAQ,GAAG,UAAU,MAAM,KAAK,QAAQ,CAAC;AACzC,UAAQ,GAAG,WAAW,MAAM,KAAK,QAAQ,CAAC;AAG1C,OAAK,GAAG,SAAS,MAAM,KAAK,QAAQ,CAAC;AACvC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/redis.ts"],"sourcesContent":["/**\n * CLI Redis Passthrough\n *\n * Allows superadmins to execute read-only Redis commands against the production cache.\n */\n\nimport process from \"node:process\";\nimport { resolveConfig } from \"./auth.js\";\nimport { fetchOrExit } from \"./api-fetch.js\";\n\nconst MAX_COMMAND_SIZE = 10_000; // 10KB - reasonable for interactive use\n\ntype RedisResponse = {\n ok: boolean;\n data?: unknown;\n durationMs?: number;\n error?: string;\n code?: \"DISABLED\" | \"BLOCKED\";\n};\n\nfunction getArgValue(argv: string[], key: string): string | undefined {\n const index = argv.indexOf(key);\n if (index === -1 || index >= argv.length - 1) return undefined;\n return argv[index + 1];\n}\n\nfunction hasFlag(argv: string[], ...flags: string[]): boolean {\n return flags.some((flag) => argv.includes(flag));\n}\n\n/**\n * Formats Redis response for display.\n */\nfunction formatOutput(data: unknown): string {\n if (data === null) {\n return \"(nil)\";\n }\n\n if (typeof data === \"string\") {\n return data;\n }\n\n if (typeof data === \"number\") {\n return `(integer) ${data}`;\n }\n\n if (Array.isArray(data)) {\n if (data.length === 0) {\n return \"(empty array)\";\n }\n return data\n .map((item, index) => `${index + 1}) ${formatOutput(item)}`)\n .join(\"\\n\");\n }\n\n if (typeof data === \"object\") {\n return JSON.stringify(data, null, 2);\n }\n\n return String(data);\n}\n\nexport async function runRedis(argv: string[]): Promise<void> {\n const { apiUrl, token } = await resolveConfig(argv);\n\n const jsonOutput = hasFlag(argv, \"--json\");\n\n // Get command: remaining args after filtering flags\n const flagsWithValues = [\"--api-url\", \"--token\", \"--env\"];\n const commandParts: string[] = [];\n for (let i = 0; i < argv.length; i++) {\n if (flagsWithValues.includes(argv[i])) {\n i++; // Skip flag value\n continue;\n }\n if (argv[i].startsWith(\"--\")) continue;\n commandParts.push(argv[i]);\n }\n const command = commandParts.join(\" \");\n\n if (!command) {\n console.error(\"Error: No command provided.\");\n console.error(\"\");\n console.error(\"Usage: canary redis <command> [--json]\");\n console.error(' canary redis KEYS \"job:*\"');\n console.error(\"\");\n console.error(\"Examples:\");\n console.error(\" canary redis PING\");\n console.error(\" canary redis INFO\");\n console.error(' canary redis KEYS \"job:*\"');\n console.error(' canary redis HGETALL \"job:123:status\"');\n console.error(' canary redis GET \"some:key\" --json');\n process.exit(1);\n }\n\n if (command.length > MAX_COMMAND_SIZE) {\n console.error(`Error: Command too large (${command.length} chars, max ${MAX_COMMAND_SIZE})`);\n process.exit(1);\n }\n\n try {\n const res = await fetchOrExit(`${apiUrl}/superadmin/redis`, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${token}`,\n \"Content-Type\": \"application/json\",\n },\n token,\n body: JSON.stringify({ command }),\n });\n\n // Handle HTTP errors before parsing JSON\n if (!res.ok) {\n const text = await res.text();\n\n if (res.status === 404) {\n console.error(\"Error: Endpoint not found. The redis feature may not be deployed to this environment.\");\n process.exit(1);\n }\n\n // Try to parse error as JSON, fallback to raw text\n try {\n const errorJson = JSON.parse(text) as { error?: string };\n console.error(`Error: ${errorJson.error ?? text}`);\n } catch {\n console.error(`Error (${res.status}): ${text || res.statusText}`);\n }\n process.exit(1);\n }\n\n const json_response = (await res.json()) as RedisResponse;\n\n if (!json_response.ok) {\n console.error(`Error: ${json_response.error}`);\n if (json_response.code === \"BLOCKED\") {\n console.error(\"The Redis debugging feature has been disabled due to this blocked command.\");\n }\n process.exit(1);\n }\n\n if (jsonOutput) {\n console.log(JSON.stringify(json_response.data, null, 2));\n } else {\n console.log(formatOutput(json_response.data));\n console.log(`\\nTime: ${json_response.durationMs}ms`);\n }\n } catch (err) {\n console.error(`Failed to execute command: ${err}`);\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;AAMA,OAAO,aAAa;AAIpB,IAAM,mBAAmB;AAgBzB,SAAS,QAAQ,SAAmB,OAA0B;AAC5D,SAAO,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC;AACjD;AAKA,SAAS,aAAa,MAAuB;AAC3C,MAAI,SAAS,MAAM;AACjB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO,aAAa,IAAI;AAAA,EAC1B;AAEA,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO;AAAA,IACT;AACA,WAAO,KACJ,IAAI,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,aAAa,IAAI,CAAC,EAAE,EAC1D,KAAK,IAAI;AAAA,EACd;AAEA,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO,KAAK,UAAU,MAAM,MAAM,CAAC;AAAA,EACrC;AAEA,SAAO,OAAO,IAAI;AACpB;AAEA,eAAsB,SAAS,MAA+B;AAC5D,QAAM,EAAE,QAAQ,MAAM,IAAI,MAAM,cAAc,IAAI;AAElD,QAAM,aAAa,QAAQ,MAAM,QAAQ;AAGzC,QAAM,kBAAkB,CAAC,aAAa,WAAW,OAAO;AACxD,QAAM,eAAyB,CAAC;AAChC,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAI,gBAAgB,SAAS,KAAK,CAAC,CAAC,GAAG;AACrC;AACA;AAAA,IACF;AACA,QAAI,KAAK,CAA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AAA,IAChB;AAEA,UAAM,gBAAiB,MAAM,IAAI,KAAK;AAEtC,QAAI,CAAC,cAAc,IAAI;AACrB,cAAQ,MAAM,UAAU,cAAc,KAAK,EAAE;AAC7C,UAAI,cAAc,SAAS,WAAW;AACpC,gBAAQ,MAAM,4EAA4E;AAAA,MAC5F;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,QAAI,YAAY;AACd,cAAQ,IAAI,KAAK,UAAU,cAAc,MAAM,MAAM,CAAC,CAAC;AAAA,IACzD,OAAO;AACL,cAAQ,IAAI,aAAa,cAAc,IAAI,CAAC;AAC5C,cAAQ,IAAI;AAAA,QAAW,cAAc,UAAU,IAAI;AAAA,IACrD;AAAA,EACF,SAAS,KAAK;AACZ,YAAQ,MAAM,8BAA8B,GAAG,EAAE;AACjD,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/sandbox.ts"],"sourcesContent":["/**\n * CLI Sandbox Management\n *\n * Create, provision, and manage sandbox templates and instances.\n * Drive template authoring through artifact uploads, command execution,\n * and diagnostics — designed for Claude Code to iterate on sandbox setup.\n */\n\nimport process from 'node:process';\nimport { readFileSync } from 'node:fs';\nimport { resolveConfig, getArgValue, hasFlag } from './auth.js';\nimport { apiRequest, selectProperty } from './cli-helpers.js';\nimport { apiFetch, isTerminalFailure, exitOnFailure } from './api-fetch.js';\nimport { SANDBOX_GUIDE_SECTIONS, printGuide } from '@chatsdet/content';\nimport { INSTANCE_SIZES, INSTANCE_SIZE_SPEC, parseInstanceSize, type InstanceSize } from '@chatsdet/types';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ntype Template = {\n id: string;\n name: string;\n propertyId: string | null;\n repositoryFullName: string;\n branch: string;\n subdirectory: string | null;\n status: string;\n checklistProfile: string | null;\n configSchema: Array<{ key: string; description?: string; required: boolean; sensitive: boolean }> | null;\n configDefaults: Record<string, string> | null;\n createdAt: string;\n updatedAt: string;\n};\n\ntype GitHubRepo = {\n id: string;\n repoFullName: string;\n repoName: string;\n defaultBranch: string;\n rootDir: string | null;\n agentHint: string | null;\n};\n\ntype Instance = {\n id: string;\n templateId: string;\n name: string;\n status: string;\n hostUrl: string | null;\n isPrivate: boolean;\n expiresAt: string | null;\n createdAt: string;\n};\n\ntype Artifact = {\n id: string;\n taskId: string;\n artifactType: string;\n filename: string;\n content?: string;\n createdAt: string;\n updatedAt: string;\n};\n\ntype ChecklistItem = {\n id: string;\n label: string;\n description: string;\n dependsOn: string[];\n producesArtifacts: string[];\n agentAutomatable: boolean;\n itemStatus: { status: string; startedAt?: string; completedAt?: string; summary?: string; error?: string };\n actionable: boolean;\n artifacts: Array<{ artifactType: string; filename: string }>;\n};\n\ntype CommandOrError = { stdout: string; stderr: string; exitCode: number } | { error: string };\n\ntype DiagnosticsResult = {\n instance: Record<string, unknown>;\n docker: CommandOrError;\n git: CommandOrError;\n disk: CommandOrError;\n agentHealth: CommandOrError;\n appHealth: CommandOrError;\n provision?: {\n phase: string;\n jobStatus: string;\n startedAt?: string;\n elapsedSeconds: number | null;\n lastError?: string;\n };\n};\n\ntype ServiceRoute = { service: string; route: string; port: string };\n\nasync function fetchInstanceRoutes(apiUrl: string, token: string, instanceId: string): Promise<ServiceRoute[]> {\n const res = await apiRequest<{ ok: boolean; error?: string; data: { routes: ServiceRoute[] } }>(\n apiUrl, token, 'GET', `/org/environments/instances/${instanceId}/routes`,\n undefined,\n { timeoutMs: 30_000 }\n );\n return res.ok ? res.data.routes : [];\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nconst STATUS_ICONS: Record<string, string> = {\n completed: '[done]',\n running: '[....]',\n pending: '[ ]',\n failed: '[FAIL]',\n skipped: '[skip]',\n};\n\nfunction formatDate(iso: string): string {\n return new Date(iso).toLocaleString();\n}\n\nfunction pad(s: string, n: number): string {\n return s.padEnd(n);\n}\n\nconst INSTANCE_SIZE_HELP_LINES = INSTANCE_SIZES.map((size) => {\n const spec = INSTANCE_SIZE_SPEC[size];\n return ` ${pad(size, 8)} ${spec.ec2InstanceType} · ${spec.vcpu} vCPU · ${spec.memoryMiB / 1024} GiB`;\n});\n\n// ---------------------------------------------------------------------------\n// Help\n// ---------------------------------------------------------------------------\n\nfunction printHelp(): void {\n console.log(\n [\n 'canary sandbox: Manage sandbox templates and instances',\n '',\n 'Sub-commands:',\n ' guide [section] Show sandbox authoring guide',\n ' list List templates and instances',\n ' template [id] Show template details',\n ' repo list --template <id> List repos linked to a template',\n ' repo add --template <id> --property-github-repo-id <uuid> [--role <r>] [--spec <r=owner/name@branch:subdir>]',\n ' repo update --template <id> --link-id <uuid> [--role <r>] [--branch <b>] [--subdirectory <s>] [--service-name <n>]',\n ' repo remove --template <id> --link-id <uuid>',\n ' checklist <template-id> Show checklist state',\n ' checklist skip <template-id> <item-id> Skip a checklist item',\n ' checklist complete <template-id> <item-id> [options] Mark item complete from CLI',\n ' artifacts <template-id> List artifacts',\n ' artifact get <template-id> <type> Get artifact content',\n ' artifact create <template-id> <type> <file> Upload artifact (use --path for file type)',\n ' create [property] [options] Create template from property (triggers provisioning)',\n ' provision <template-id> [options] Create instance from verified template',\n ' verify <template-id> Verify an authoring template (provision + probe + flip to verified)',\n ' set-size <template-id> <size> Set EC2 size for next provision (see \"Instance sizes\" below)',\n ' ami list <template-id> List per-template AMI history',\n ' ami rebake <template-id> [opts] Trigger a fresh AMI bake (--force, --wait)',\n ' ami use <template-id> <ami-row-id> Switch the template to a specific AMI (rollback)',\n ' build <instance-id> Build and start app services on sandbox',\n ' run-command <instance-id> <command...> Execute shell command on sandbox',\n ' --service <name> Run inside a Docker container instead of on the host VM',\n ' diagnostics <instance-id> Show sandbox diagnostics',\n ' logs <instance-id> [options] Show container logs',\n ' terminate <instance-id> Terminate an instance',\n ' config list <template-id> Show config schema and defaults',\n ' config set <template-id> <key> <value> Set a config default value',\n ' delete <template-id> Delete template and all instances',\n '',\n 'Create options:',\n ' --property <name|id> Property (prompted if omitted, auto-selected if only one)',\n ' --branch <branch> Branch (default: from linked repo)',\n ' --name <name> Template name (default: repo name)',\n ' --subdirectory <path> Subdirectory (default: from linked repo rootDir)',\n ' --size <size> EC2 size for first authoring sandbox (default: medium; see \"Instance sizes\" below)',\n '',\n 'Provision options:',\n ' --name <name> Instance name',\n ' --ttl <hours> Time to live in hours (default: 8)',\n ' --with-agent Start with sandbox agent',\n '',\n 'Artifact get options:',\n ' --output <file> Write to file instead of stdout',\n '',\n 'Logs options:',\n ' --service <name> Service name (default: all services)',\n ' --tail <n> Number of lines (default: 200)',\n '',\n 'Guide sections:',\n ' goal, research, artifacts, actions, verify, checklist',\n '',\n 'Instance sizes:',\n ...INSTANCE_SIZE_HELP_LINES,\n '',\n 'Action sub-commands:',\n ' action list <template-id> List actions for a template',\n ' action get <template-id> <slug> Show action definition + script',\n ' action create <template-id> <slug> [opts] Create or update an action',\n ' action delete <template-id> <slug> Delete an action',\n ' action execute <instance-id> <slug> [opts] Execute action on a running instance',\n ' action executions <instance-id> [opts] List execution history',\n '',\n 'Action create options:',\n ' --label <label> Display name (default: slug → Title Case)',\n ' --description <text> Description',\n ' --icon <icon> Phosphor icon name',\n ' --script <file> Path to script file (bash)',\n ' --input-schema <file> Path to JSON Schema file for input params',\n ' --output-schema <file> Path to JSON Schema file for output',\n ' --credential-output-config <file> JSON file with ActionCredentialOutputConfig (auto-creates a Canary credential from the action result)',\n ' --credential-template <id> Credential template this action provisions; login nodes using it auto-provision',\n ' --provisioning-mode <shared|unique> shared = provision once / reused (default); unique = one credential per run (script must accept a runId input param)',\n ' --timeout <ms> Timeout in ms (default: 55000)',\n ' --encrypt-script Encrypt script content at rest',\n '',\n 'Action execute options:',\n ' --param <key>=<value> Set parameter (repeatable)',\n ' --params-file <file> JSON file with all params',\n '',\n 'Global options:',\n ' --json Output raw JSON',\n ' --env <env> Environment (prod, dev, local)',\n ' -h, --help Show help',\n ].join('\\n')\n );\n}\n\n// ---------------------------------------------------------------------------\n// Sub-command handlers\n// ---------------------------------------------------------------------------\n\nasync function handleList(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n\n const [templatesRes, instancesRes] = await Promise.all([\n apiRequest<{ ok: boolean; error?: string; data: Template[] }>(\n apiUrl, token, 'GET', '/org/environments/templates'\n ),\n apiRequest<{ ok: boolean; error?: string; data: Instance[] }>(\n apiUrl, token, 'GET', '/org/environments/instances'\n ),\n ]);\n\n if (!templatesRes.ok) {\n console.error(`Error: ${templatesRes.error}`);\n process.exit(1);\n }\n if (!instancesRes.ok) {\n console.error(`Error loading instances: ${instancesRes.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify({ templates: templatesRes.data, instances: instancesRes.data }, null, 2));\n return;\n }\n\n const templates = templatesRes.data ?? [];\n const instances = instancesRes.data ?? [];\n\n console.log('Templates:');\n if (templates.length === 0) {\n console.log(' (none)');\n } else {\n console.log(` ${pad('ID', 38)} ${pad('Name', 24)} ${pad('Status', 14)} ${pad('Profile', 12)} Repository`);\n for (const t of templates) {\n console.log(` ${pad(t.id, 38)} ${pad(t.name, 24)} ${pad(t.status, 14)} ${pad(t.checklistProfile ?? '-', 12)} ${t.repositoryFullName}:${t.branch}`);\n }\n }\n\n console.log('');\n console.log('Instances:');\n if (instances.length === 0) {\n console.log(' (none)');\n } else {\n console.log(` ${pad('ID', 38)} ${pad('Status', 14)} ${pad('Access', 10)} ${pad('Template', 38)} Expires`);\n for (const i of instances) {\n const access = i.isPrivate ? 'private' : 'public';\n console.log(` ${pad(i.id, 38)} ${pad(i.status, 14)} ${pad(access, 10)} ${pad(i.templateId, 38)} ${i.expiresAt ? formatDate(i.expiresAt) : '-'}`);\n }\n }\n}\n\nasync function handleTemplate(argv: string[], apiUrl: string, token: string): Promise<void> {\n const [id] = argv.filter((a) => !a.startsWith('-'));\n const json = hasFlag(argv, '--json');\n\n if (!id) {\n await handleList(argv, apiUrl, token);\n return;\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: Template }>(\n apiUrl, token, 'GET', `/org/environments/templates/${id}`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n const t = res.data;\n console.log(`Template: ${t.name}`);\n console.log(` ID: ${t.id}`);\n console.log(` Repository: ${t.repositoryFullName}:${t.branch}`);\n if (t.subdirectory) console.log(` Subdir: ${t.subdirectory}`);\n console.log(` Status: ${t.status}`);\n console.log(` Profile: ${t.checklistProfile ?? 'full-stack (default)'}`);\n console.log(` Created: ${formatDate(t.createdAt)}`);\n console.log(` Updated: ${formatDate(t.updatedAt)}`);\n\n if (t.configSchema && t.configSchema.length > 0) {\n console.log('');\n console.log(' Config Schema:');\n for (const c of t.configSchema) {\n const flags = [c.required ? 'required' : 'optional', c.sensitive ? 'sensitive' : ''].filter(Boolean).join(', ');\n console.log(` ${c.key} (${flags})${c.description ? ` — ${c.description}` : ''}`);\n }\n }\n}\n\nasync function handleArtifacts(argv: string[], apiUrl: string, token: string): Promise<void> {\n const [templateId] = argv.filter((a) => !a.startsWith('-'));\n const json = hasFlag(argv, '--json');\n\n if (!templateId) {\n console.error('Error: template ID required. Usage: canary sandbox artifacts <template-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: Artifact[] }>(\n apiUrl, token, 'GET', `/org/environments/templates/${templateId}/artifacts`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n const artifacts = res.data ?? [];\n if (artifacts.length === 0) {\n console.log('No artifacts found.');\n return;\n }\n\n console.log(`${pad('Type', 22)} ${pad('Filename', 30)} ${pad('Task', 24)} Created`);\n for (const a of artifacts) {\n console.log(`${pad(a.artifactType, 22)} ${pad(a.filename, 30)} ${pad(a.taskId, 24)} ${formatDate(a.createdAt)}`);\n }\n}\n\nasync function handleChecklist(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const json = hasFlag(argv, '--json');\n\n // Handle checklist sub-commands: skip, complete\n if (positional[0] === 'skip') {\n await handleChecklistSkip(argv.slice(1), apiUrl, token);\n return;\n }\n if (positional[0] === 'complete') {\n await handleChecklistComplete(argv.slice(1), apiUrl, token);\n return;\n }\n\n const templateId = positional[0];\n if (!templateId) {\n console.error('Error: template ID required. Usage: canary sandbox checklist <template-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: ChecklistItem[] }>(\n apiUrl, token, 'GET', `/org/environments/templates/${templateId}/checklist`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n const items = res.data ?? [];\n if (items.length === 0) {\n console.log('No checklist items.');\n return;\n }\n\n console.log('Checklist:');\n for (const item of items) {\n const icon = STATUS_ICONS[item.itemStatus.status] ?? '[????]';\n const actionable = item.actionable ? ' *' : '';\n console.log(` ${icon} ${item.label}${actionable}`);\n if (item.itemStatus.summary) {\n console.log(` ${item.itemStatus.summary}`);\n }\n if (item.itemStatus.error) {\n console.log(` ERROR: ${item.itemStatus.error}`);\n }\n if (item.artifacts.length > 0) {\n console.log(` Artifacts: ${item.artifacts.map((a) => a.artifactType).join(', ')}`);\n }\n }\n console.log('');\n console.log(' * = actionable (deps met, ready to run)');\n}\n\nasync function handleChecklistSkip(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const itemId = positional[1];\n\n if (!templateId || !itemId) {\n console.error('Error: both template ID and item ID required. Usage: canary sandbox checklist skip <template-id> <item-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl, token, 'POST', `/org/environments/templates/${templateId}/checklist/${itemId}/skip`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n console.log(`Skipped checklist item: ${itemId}`);\n}\n\nasync function handleChecklistComplete(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const itemId = positional[1];\n\n const json = hasFlag(argv, '--json');\n\n if (!templateId || !itemId) {\n console.error('Error: both template ID and item ID required.');\n console.error('Usage: canary sandbox checklist complete <template-id> <item-id> [--status success|failed] [--summary \"...\"]');\n process.exit(1);\n }\n\n const status = getArgValue(argv, '--status') ?? 'success';\n const summary = getArgValue(argv, '--summary');\n const configSchemaArg = getArgValue(argv, '--config-schema');\n const healthCheckPath = getArgValue(argv, '--health-check-path');\n\n let configSchema: unknown;\n if (configSchemaArg) {\n // Accept inline JSON or a file path\n try {\n configSchema = JSON.parse(configSchemaArg);\n } catch {\n try {\n configSchema = JSON.parse(readFileSync(configSchemaArg, 'utf-8'));\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n console.error(`Error reading config schema from \"${configSchemaArg}\": ${msg}`);\n process.exit(1);\n }\n }\n }\n\n const body: Record<string, unknown> = {\n status: status === 'failed' ? 'failed' : 'completed',\n ...(summary ? { summary } : {}),\n ...(configSchema ? { configSchema } : {}),\n ...(healthCheckPath ? { healthCheckPath } : {}),\n };\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: { itemId: string; status: string } }>(\n apiUrl, token, 'POST', `/org/environments/templates/${templateId}/checklist/${itemId}/complete`, body\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n console.log(`Completed checklist item: ${itemId} (${res.data?.status})`);\n}\n\nasync function handleConfigList(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const json = hasFlag(argv, '--json');\n\n if (!templateId) {\n console.error('Error: template ID required. Usage: canary sandbox config list <template-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: Template }>(\n apiUrl, token, 'GET', `/org/environments/templates/${templateId}`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n const t = res.data;\n const schema = t.configSchema ?? [];\n const defaults = t.configDefaults ?? {};\n\n if (json) {\n console.log(JSON.stringify({ configSchema: schema, configDefaults: defaults }, null, 2));\n return;\n }\n\n if (schema.length === 0) {\n console.log('No config schema defined for this template.');\n return;\n }\n\n console.log('Config Schema:');\n for (const item of schema) {\n const value = defaults[item.key];\n const display = item.sensitive && value ? '••••••••' : (value ?? '(not set)');\n const required = item.required ? ' (required)' : '';\n const sensitive = item.sensitive ? ' [sensitive]' : '';\n console.log(` ${item.key}${required}${sensitive}`);\n if (item.description) console.log(` ${item.description}`);\n console.log(` Value: ${display}`);\n }\n}\n\nasync function handleConfigSet(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const fromStdin = hasFlag(argv, '--value-stdin');\n const templateId = positional[0];\n const key = positional[1];\n let value = positional[2];\n\n if (!templateId || !key) {\n console.error('Error: template ID and key required.');\n console.error('Usage: canary sandbox config set <template-id> <key> <value>');\n console.error(' For sensitive values: echo \"sk-ant-...\" | canary sandbox config set <template-id> <key> --value-stdin');\n process.exit(1);\n }\n\n if (fromStdin) {\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) chunks.push(chunk as Buffer);\n value = Buffer.concat(chunks).toString('utf-8').trim();\n }\n\n if (value === undefined) {\n console.error('Error: value required. Pass as argument or use --value-stdin');\n process.exit(1);\n }\n\n // First get current defaults to merge\n const getRes = await apiRequest<{ ok: boolean; error?: string; data: Template }>(\n apiUrl, token, 'GET', `/org/environments/templates/${templateId}`\n );\n if (!getRes.ok) {\n console.error(`Error: ${getRes.error}`);\n process.exit(1);\n }\n\n const currentDefaults = getRes.data?.configDefaults ?? {};\n const updatedDefaults = { ...currentDefaults, [key]: value };\n\n // The server may take longer than 30s to acknowledge config writes\n // (encrypted columns, audit log). Even when it does the write succeeds —\n // bump the CLI ceiling so the user sees the success rather than a\n // misleading timeout.\n const res = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl, token, 'PATCH', `/org/environments/templates/${templateId}/config`, {\n configDefaults: updatedDefaults,\n },\n { timeoutMs: 90_000 }\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n console.log(`Config set: ${key}`);\n}\n\nasync function handleSetSize(argv: string[], apiUrl: string, token: string): Promise<void> {\n const [templateId, sizeArg] = argv.filter((a) => !a.startsWith('-'));\n\n if (!templateId || !sizeArg) {\n console.error('Error: template ID and size required.');\n console.error(`Usage: canary sandbox set-size <template-id> <${INSTANCE_SIZES.join('|')}>`);\n process.exit(1);\n }\n\n const size = parseInstanceSize(sizeArg);\n if (!size) {\n console.error(`Error: invalid size '${sizeArg}'. Must be one of: ${INSTANCE_SIZES.join(', ')}`);\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; instanceSize?: InstanceSize }>(\n apiUrl,\n token,\n 'PATCH',\n `/org/environments/templates/${templateId}/instance-size`,\n { instanceSize: size }\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n console.log(`Instance size set to ${size}`);\n}\n\nasync function handleCreate(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const json = hasFlag(argv, '--json');\n\n // Resolve property — positional arg or --property flag, prompted if omitted\n const propertyHint = positional[0] ?? getArgValue(argv, '--property');\n const property = await selectProperty(apiUrl, token, propertyHint ?? undefined);\n if (!property) process.exit(1);\n\n // Fetch linked repos for the property\n const reposRes = await apiRequest<{ ok: boolean; error?: string; items: GitHubRepo[] }>(\n apiUrl, token, 'GET', `/org/properties/${property.id}/github-repos`\n );\n if (!reposRes.ok || !reposRes.items?.length) {\n console.error(`No GitHub repos linked to property \"${property.name}\". Link one first in the web app.`);\n process.exit(1);\n }\n\n const linkedRepo = reposRes.items[0];\n const branch = getArgValue(argv, '--branch') ?? linkedRepo.defaultBranch ?? 'main';\n const name = getArgValue(argv, '--name') ?? linkedRepo.repoName ?? linkedRepo.repoFullName.split('/').pop() ?? property.name;\n const subdirectory = getArgValue(argv, '--subdirectory') ?? linkedRepo.rootDir ?? undefined;\n\n const sizeArg = getArgValue(argv, '--size');\n const instanceSize = sizeArg ? parseInstanceSize(sizeArg) : undefined;\n if (sizeArg && !instanceSize) {\n console.error(`Error: invalid --size '${sizeArg}'. Must be one of: ${INSTANCE_SIZES.join(', ')}`);\n process.exit(1);\n }\n\n const body: Record<string, unknown> = {\n name,\n propertyId: property.id,\n repositoryFullName: linkedRepo.repoFullName,\n branch,\n };\n if (subdirectory) body.subdirectory = subdirectory;\n if (linkedRepo.agentHint) body.hints = linkedRepo.agentHint;\n if (instanceSize) body.instanceSize = instanceSize;\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: Template }>(\n apiUrl, token, 'POST', '/org/environments/templates', body\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n console.log(`Template created: ${res.data.id}`);\n console.log(` Property: ${property.name}`);\n console.log(` Repository: ${res.data.repositoryFullName}:${res.data.branch}`);\n console.log(` Status: ${res.data.status}`);\n console.log('');\n console.log('Authoring job enqueued. Poll status with:');\n console.log(` canary sandbox template ${res.data.id}`);\n}\n\nasync function handleProvision(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const json = hasFlag(argv, '--json');\n\n if (!templateId) {\n console.error('Error: template ID required. Usage: canary sandbox provision <template-id> [--ttl 8]');\n process.exit(1);\n }\n\n const name = getArgValue(argv, '--name') ?? `instance-${Date.now()}`;\n const ttl = parseInt(getArgValue(argv, '--ttl') ?? '8', 10);\n const withAgent = hasFlag(argv, '--with-agent');\n const isPrivate = hasFlag(argv, '--private');\n\n const body: Record<string, unknown> = {\n templateId,\n name,\n expiresInHours: ttl,\n userConfig: {},\n withAgent,\n isPrivate,\n };\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: Instance }>(\n apiUrl, token, 'POST', '/org/environments/instances', body\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n console.log(`Instance created: ${res.data.id}`);\n console.log(` Status: ${res.data.status}`);\n if (isPrivate) console.log(` Access: private (no public URL)`);\n console.log(` Expires: ${res.data.expiresAt ? formatDate(res.data.expiresAt) : '-'}`);\n}\n\nexport interface ContainerLine {\n name: string;\n status: string;\n state: 'up-healthy' | 'up' | 'up-unhealthy' | 'restarting' | 'exited' | 'other';\n}\n\n/**\n * Parse `docker ps --format '{{.Names}}\\t{{.Status}}\\t{{.Ports}}'` output\n * into a structured list. State classification is coarse — the verify loop\n * only needs to know \"is this container healthy / exited / restart-looping\".\n */\nexport function parseDockerPs(stdout: string): ContainerLine[] {\n const lines = stdout.split('\\n').map((l) => l.trim()).filter(Boolean);\n return lines.map((line) => {\n const [name = '', status = ''] = line.split('\\t');\n const lower = status.toLowerCase();\n let state: ContainerLine['state'] = 'other';\n if (lower.startsWith('restarting')) state = 'restarting';\n else if (lower.startsWith('exited')) state = 'exited';\n else if (lower.startsWith('up') && lower.includes('unhealthy')) state = 'up-unhealthy';\n else if (lower.startsWith('up') && lower.includes('healthy')) state = 'up-healthy';\n else if (lower.startsWith('up')) state = 'up';\n return { name, status, state };\n });\n}\n\n/** Containers that aren't cleanly up. Used to decide what to dump logs for. */\nexport function isBrokenContainer(c: ContainerLine): boolean {\n return c.state === 'restarting' || c.state === 'exited' || c.state === 'up-unhealthy';\n}\n\n/**\n * Map a container name back to its compose service.\n *\n * docker-compose names containers `<project>-<service>-<replica>`. The\n * sandbox platform sets the project to `workspace` via\n * `--project-directory /workspace` (see `SANDBOX_COMPOSE_BASE` in\n * apps/api/.../sandbox-cli/service.ts), so the common case is\n * `workspace-<svc>-<n>`. Fall back to stripping the trailing replica\n * index only, so attribution still works if the project name ever\n * changes or someone uses an explicit `container_name:` override.\n */\nexport function containerNameToService(containerName: string): string {\n const withProject = containerName.match(/^workspace-(.+)-\\d+$/);\n if (withProject) return withProject[1]!;\n const withoutProject = containerName.match(/^(.+)-\\d+$/);\n if (withoutProject) return withoutProject[1]!;\n return containerName;\n}\n\nasync function fetchServiceLogs(\n apiUrl: string,\n token: string,\n instanceId: string,\n service: string,\n tail: number\n): Promise<string> {\n const res = await apiRequest<{ ok: boolean; error?: string; data: { logs: string } }>(\n apiUrl,\n token,\n 'POST',\n `/org/environments/instances/${instanceId}/docker/logs`,\n { service, tail }\n );\n if (!res.ok) return `(log fetch failed: ${res.error ?? 'unknown'})`;\n return res.data?.logs ?? '';\n}\n\nasync function handleVerify(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const json = hasFlag(argv, '--json');\n // --keep-instance is kept as a success-path alias (existing behavior).\n // On failure the probe is now preserved by default so the user can debug;\n // pass --auto-terminate-on-failure for CI where you want cleanup anyway.\n const keepInstance = hasFlag(argv, '--keep-instance');\n const autoTerminateOnFailure = hasFlag(argv, '--auto-terminate-on-failure');\n\n if (!templateId) {\n console.error('Error: template ID required. Usage: canary sandbox verify <template-id>');\n process.exit(1);\n }\n\n console.log(`Verifying template ${templateId}...`);\n\n // Kick off a verification instance — server bypasses the \"verified\" gate\n // via verificationMode but otherwise runs the full provisioning flow.\n const verifyRes = await apiRequest<{ ok: boolean; error?: string; data: { instanceId: string; expiresAt: string } }>(\n apiUrl, token, 'POST', `/org/environments/templates/${templateId}/verify`, {}\n );\n if (!verifyRes.ok) {\n console.error(`Error: ${verifyRes.error}`);\n process.exit(1);\n }\n const instanceId = verifyRes.data.instanceId;\n console.log(` Verification instance: ${instanceId}`);\n\n // Poll diagnostics until instance reaches 'running' or a terminal state.\n const POLL_INTERVAL_MS = 10_000;\n const TIMEOUT_MS = 600_000; // 10 minutes\n const DETAIL_DUMP_INTERVAL_MS = 30_000; // rate-limit noisy dumps\n const LOG_TAIL_LINES = 40;\n const startTime = Date.now();\n let finalStatus = '';\n let publicUrl: string | undefined;\n let lastDetailDumpAt = 0;\n let routes: ServiceRoute[] = [];\n let routesFetched = false;\n\n while (Date.now() - startTime < TIMEOUT_MS) {\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));\n\n const diag = await apiRequest<{ ok: boolean; error?: string; data: DiagnosticsResult }>(\n apiUrl, token, 'GET', `/org/environments/instances/${instanceId}/diagnostics`,\n undefined,\n { timeoutMs: 60_000 }\n );\n if (!diag.ok) continue;\n\n const now = Date.now();\n const elapsed = Math.round((now - startTime) / 1000);\n const remaining = Math.max(0, Math.round((TIMEOUT_MS - (now - startTime)) / 1000));\n const status = String((diag.data.instance as { status?: string; publicUrl?: string }).status ?? '');\n publicUrl = (diag.data.instance as { publicUrl?: string }).publicUrl;\n const appOutput = 'stdout' in diag.data.appHealth ? diag.data.appHealth.stdout : '';\n const appUp = appOutput.length > 0 && !appOutput.includes('UNREACHABLE');\n const dockerOutput = 'stdout' in diag.data.docker ? diag.data.docker.stdout : '';\n const containers = parseDockerPs(dockerOutput);\n const broken = containers.filter(isBrokenContainer);\n\n // Compact progress line (overwriting, like before) — adds remaining time.\n const ttl = remaining > 60 ? `${elapsed}s elapsed` : `${remaining}s remaining`;\n process.stdout.write(\n `\\r [${ttl}] status: ${status}, app: ${appUp ? 'up' : 'waiting'}, containers: ${containers.length}, unhealthy: ${broken.length} `\n );\n\n if (status === 'running' && appUp) {\n process.stdout.write('\\n');\n finalStatus = 'running';\n break;\n }\n if (status === 'failed' || status === 'terminated') {\n process.stdout.write('\\n');\n finalStatus = status;\n break;\n }\n\n // When the app is still down and at least one container is broken,\n // dump details + log tails once every DETAIL_DUMP_INTERVAL_MS so the\n // user actually sees what's failing instead of staring at a spinner.\n const shouldDump =\n !appUp &&\n broken.length > 0 &&\n now - lastDetailDumpAt >= DETAIL_DUMP_INTERVAL_MS;\n if (shouldDump) {\n lastDetailDumpAt = now;\n process.stdout.write('\\n');\n console.log('');\n console.log(` App unreachable after ${elapsed}s. Container state:`);\n for (const c of containers) {\n console.log(` ${c.name.padEnd(40)} ${c.status}`);\n }\n console.log('');\n // Per-broken-container log tails. Cap to MAX_LOG_CONTAINERS to avoid\n // SSM call amplification on pathological cases (a template with 6\n // restart-looping services would otherwise issue 6 sequential SSM\n // calls every 30s). Fetch in parallel — these are independent.\n const MAX_LOG_CONTAINERS = 3;\n const toFetch = broken.slice(0, MAX_LOG_CONTAINERS);\n const overflow = broken.length - toFetch.length;\n const fetched = await Promise.all(\n toFetch.map((c) =>\n fetchServiceLogs(apiUrl, token, instanceId, containerNameToService(c.name), LOG_TAIL_LINES)\n .then((logs) => ({ c, logs }))\n )\n );\n for (const { c, logs } of fetched) {\n const tail = logs.trim().split('\\n').slice(-LOG_TAIL_LINES).join('\\n ');\n console.log(` --- ${c.name} (${c.state}) ---`);\n console.log(` ${tail || '(no logs)'}`);\n console.log('');\n }\n if (overflow > 0) {\n console.log(\n ` (+${overflow} more broken container${overflow === 1 ? '' : 's'} — re-run with: canary sandbox logs ${instanceId} --service <name>)`\n );\n console.log('');\n }\n // Attribution: if nginx-proxy is looping because of a labeled upstream\n // that's exited, call that out so the user doesn't chase nginx's\n // \"host not found in upstream\" as the root cause.\n if (!routesFetched) {\n routes = await fetchInstanceRoutes(apiUrl, token, instanceId);\n routesFetched = true;\n }\n const nginxProxy = containers.find((c) => containerNameToService(c.name) === 'nginx-proxy');\n if (nginxProxy?.state === 'restarting' && routes.length > 0) {\n const failedUpstreams = routes\n .map((r) => ({\n route: r.route,\n service: r.service,\n container: broken.find((c) => containerNameToService(c.name) === r.service),\n }))\n .filter((x) => x.container);\n if (failedUpstreams.length > 0) {\n for (const fu of failedUpstreams) {\n console.log(\n ` >> nginx-proxy is restart-looping because upstream '${fu.service}' (route '${fu.route}') is ${fu.container!.state}. Read that service's logs above, not nginx's.`\n );\n }\n console.log('');\n }\n }\n }\n }\n\n if (finalStatus !== 'running') {\n console.error('');\n console.error(`Verification failed — instance ended in status '${finalStatus || 'timeout'}'.`);\n if (publicUrl) console.error(` Instance URL: ${publicUrl}`);\n console.error(` Instance ID: ${instanceId}`);\n console.error(` Debug with: canary sandbox diagnostics ${instanceId}`);\n console.error(` canary sandbox logs ${instanceId} --service <name>`);\n console.error(` canary sandbox run-command ${instanceId} 'docker ps -a'`);\n if (autoTerminateOnFailure) {\n await apiRequest(apiUrl, token, 'POST', `/org/environments/instances/${instanceId}/terminate`);\n console.error(` Terminated (--auto-terminate-on-failure).`);\n } else {\n // Default flip (was: auto-terminate). Call it out so CI users don't\n // silently accumulate orphan instances.\n console.error(` Instance preserved by default for debugging. Pass --auto-terminate-on-failure in CI.`);\n console.error(` Terminate manually with:`);\n console.error(` canary sandbox terminate ${instanceId}`);\n }\n process.exit(1);\n }\n\n // We just observed the instance reach status === 'running' && appUp.\n // That's the same observation that backs the server-running and\n // server-accessible checklist items, so flip them too — best-effort\n // (templates without those items in their checklist 404 silently).\n const evidenceSummary = `Verified via canary sandbox verify — fresh instance ${instanceId} came up healthy.`;\n for (const itemId of ['server-running', 'server-accessible']) {\n await apiRequest(\n apiUrl,\n token,\n 'POST',\n `/org/environments/templates/${templateId}/checklist/${itemId}/complete`,\n { status: 'completed', summary: evidenceSummary }\n ).catch(() => {\n // Item not present on this checklist profile — fine.\n });\n }\n\n // Mark the template-verified checklist item complete — this is what flips\n // template.status to 'verified' (via ChecklistService.completeChecklistItem).\n const completeRes = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl,\n token,\n 'POST',\n `/org/environments/templates/${templateId}/checklist/template-verified/complete`,\n {\n status: 'completed',\n summary: evidenceSummary,\n }\n );\n if (!completeRes.ok) {\n console.error(`Failed to record verification: ${completeRes.error}`);\n console.error(`Instance ${instanceId} left running for inspection.`);\n process.exit(1);\n }\n\n if (!keepInstance) {\n await apiRequest(apiUrl, token, 'POST', `/org/environments/instances/${instanceId}/terminate`);\n console.log(` Terminated verification instance.`);\n } else {\n console.log(` --keep-instance: instance ${instanceId} left running${publicUrl ? ` at ${publicUrl}` : ''}.`);\n }\n\n // Confirm the template actually flipped to verified. The status flip only\n // happens when every item in the checklist profile is terminal\n // (completed or skipped); if other items are still pending, the probe\n // succeeded but the template stays in its prior status.\n const templateAfter = await apiRequest<{ ok: boolean; data?: { status?: string } }>(\n apiUrl,\n token,\n 'GET',\n `/org/environments/templates/${templateId}`\n ).catch(() => ({ ok: false }) as { ok: boolean; data?: { status?: string } });\n const templateStatus = templateAfter.data?.status;\n const verified = templateStatus === 'verified';\n\n if (json) {\n console.log(JSON.stringify({ templateId, verified, status: templateStatus, instanceId, publicUrl }, null, 2));\n return;\n }\n\n if (verified) {\n console.log('Template verified.');\n return;\n }\n\n // Probe passed but status didn't flip — surface the pending items so the\n // user knows what to complete/skip before re-running verify.\n console.log(`Verification probe passed (instance ${instanceId} came up healthy),`);\n console.log(`but template status is still '${templateStatus ?? 'unknown'}'.`);\n type ChecklistItemSummary = { id: string; label: string; itemStatus?: { status?: string } };\n const checklistRes = await apiRequest<{ ok: boolean; data?: ChecklistItemSummary[] }>(\n apiUrl,\n token,\n 'GET',\n `/org/environments/templates/${templateId}/checklist`\n ).catch(() => ({ ok: false }) as { ok: boolean; data?: ChecklistItemSummary[] });\n const pending = (checklistRes.data ?? []).filter((it) => {\n const s = it.itemStatus?.status ?? 'pending';\n return s !== 'completed' && s !== 'skipped';\n });\n if (pending.length > 0) {\n console.log('Pending checklist items must be completed or skipped:');\n for (const item of pending) {\n console.log(` - ${item.label} (${item.id})`);\n }\n console.log('');\n console.log('Complete: canary sandbox checklist complete <template-id> <item-id> --status success --summary \"...\"');\n console.log('Skip: canary sandbox checklist skip <template-id> <item-id>');\n }\n process.exit(1);\n}\n\nasync function handleArtifactGet(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const type = positional[1];\n const outputFile = getArgValue(argv, '--output');\n\n if (!templateId || !type) {\n console.error('Error: template ID and artifact type required. Usage: canary sandbox artifact get <template-id> <type>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: Artifact }>(\n apiUrl, token, 'GET', `/org/environments/templates/${templateId}/artifacts/${type}`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (outputFile) {\n const { writeFileSync } = await import('node:fs');\n writeFileSync(outputFile, res.data.content ?? '', 'utf-8');\n console.log(`Written to ${outputFile}`);\n } else {\n process.stdout.write(res.data.content ?? '');\n }\n}\n\nasync function handleArtifactCreate(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const type = positional[1];\n const filePath = positional[2];\n const json = hasFlag(argv, '--json');\n\n if (!templateId || !type || !filePath) {\n console.error('Error: all args required. Usage: canary sandbox artifact create <template-id> <type> <file>');\n process.exit(1);\n }\n\n // Keep in sync with WellKnownArtifactType in packages/types/src/sandbox-tasks.ts + 'file' (custom with --path)\n const WELL_KNOWN_TYPES = ['docker-compose', 'dockerfile', 'startup-script', 'setup-script', 'seed-script', 'environment-config', 'file'];\n if (!WELL_KNOWN_TYPES.includes(type)) {\n console.error(`Error: invalid artifact type \"${type}\". Valid types: ${WELL_KNOWN_TYPES.join(', ')}`);\n process.exit(1);\n }\n\n // File artifacts require --path <destination>\n const destinationPath = getArgValue(argv, '--path');\n if (type === 'file' && !destinationPath) {\n console.error('Error: file artifacts require --path <destination>. Example: --path /workspace/.canary/vite.sandbox.config.ts');\n process.exit(1);\n }\n if (destinationPath && !destinationPath.startsWith('/workspace/.canary/')) {\n const suggestedName = destinationPath.split('/').filter(Boolean).pop() ?? 'yourfile';\n console.error(\n 'Error: --path must be under /workspace/.canary/ (the repo tree is user-owned — sandbox files live in .canary/).\\n' +\n ` try: --path /workspace/.canary/${suggestedName}`\n );\n process.exit(1);\n }\n\n let content: string;\n try {\n content = readFileSync(filePath, 'utf-8');\n } catch (err) {\n console.error(`Error reading file: ${err}`);\n process.exit(1);\n }\n\n // Derive filename from path\n const filename = filePath.split('/').pop() ?? filePath;\n\n // Artifact upload writes through to the live authoring instance, which on\n // first push (or a large file) can outlast 30s easily. 90s lines up with\n // the slowest legitimate upload we've observed.\n const res = await apiRequest<{\n ok: boolean;\n error?: string;\n data?: { kind: 'created' | 'replaced'; previousPath?: string };\n }>(\n apiUrl, token, 'PUT', `/org/environments/templates/${templateId}/artifacts`, {\n artifactType: type,\n filename,\n content,\n ...(destinationPath ? { destinationPath } : {}),\n },\n { timeoutMs: 90_000 }\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n const kind = res.data?.kind;\n const marker = kind === 'replaced' ? ' (replaced)' : kind === 'created' ? ' (created)' : '';\n console.log(`Artifact uploaded: ${type} (${filename}, ${content.length} bytes)${marker}`);\n if (kind === 'replaced' && res.data?.previousPath) {\n console.log(` previous destination removed: ${res.data.previousPath}`);\n }\n}\n\nasync function handleBuild(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const json = hasFlag(argv, '--json');\n const noWait = hasFlag(argv, '--no-wait');\n const instanceId = positional[0];\n\n if (!instanceId) {\n console.error('Error: instance ID required. Usage: canary sandbox build <instance-id>');\n process.exit(1);\n }\n\n console.log('Building sandbox (this takes a few minutes)...');\n\n // The build is async by design: a single HTTP connection cannot reliably\n // span a multi-minute build (ALB caps, our own client timeouts, flaky\n // networks). Kick the build off with a short timeout — the server has\n // already started the work by the time it would otherwise reply — then\n // move to polling diagnostics for the truth.\n const KICKOFF_TIMEOUT_MS = 8_000;\n\n let buildCompleted = false;\n let buildResult: { stdout: string; stderr: string; exitCode: number } | null = null;\n\n const result = await apiFetch(`${apiUrl}/org/environments/instances/${instanceId}/build`, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n token,\n timeoutMs: KICKOFF_TIMEOUT_MS,\n });\n\n if (result.ok) {\n // Fast path: server responded within the kickoff window (cached/no-op build).\n const data = (await result.response.json().catch(() => null)) as\n | { ok: boolean; error?: string; data?: { stdout: string; stderr: string; exitCode: number } }\n | null;\n if (data?.ok && data.data) {\n buildCompleted = true;\n buildResult = data.data;\n } else if (data && !data.ok) {\n console.error(`Error: ${data.error ?? 'build failed'}`);\n process.exit(1);\n }\n } else {\n const { failure } = result;\n // network = our kickoff timeout firing; 502/504 = gateway giving up while\n // the build runs on. Both mean \"watch via polling, not an error\".\n const isExpectedAsync =\n failure.kind === 'network' ||\n (failure.kind === 'http-error' && (failure.status === 502 || failure.status === 504));\n if (!isExpectedAsync) {\n if (isTerminalFailure(failure)) exitOnFailure(failure);\n console.error(`Error: ${failure.message}`);\n process.exit(1);\n }\n }\n\n // If build completed synchronously, print results and exit\n if (buildCompleted && buildResult) {\n if (json) {\n console.log(JSON.stringify(buildResult, null, 2));\n return;\n }\n\n if (buildResult.stdout) {\n process.stdout.write(buildResult.stdout);\n if (!buildResult.stdout.endsWith('\\n')) process.stdout.write('\\n');\n }\n if (buildResult.stderr) {\n process.stderr.write(`STDERR: ${buildResult.stderr}`);\n if (!buildResult.stderr.endsWith('\\n')) process.stderr.write('\\n');\n }\n\n if (buildResult.exitCode === 0) {\n console.log('Build complete.');\n } else {\n console.error(`Build failed with exit code ${buildResult.exitCode}`);\n process.exit(1);\n }\n return;\n }\n\n // Build is async — poll diagnostics until the app is reachable or timeout\n if (noWait) {\n console.log('Build started. Use diagnostics to monitor progress:');\n console.log(` canary sandbox diagnostics ${instanceId}`);\n return;\n }\n\n console.log('Build started, watching for services...');\n\n const BUILD_POLL_TIMEOUT_MS = 300_000; // 5 minutes\n const POLL_INTERVAL_MS = 10_000;\n const startTime = Date.now();\n\n while (Date.now() - startTime < BUILD_POLL_TIMEOUT_MS) {\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));\n\n const diag = await apiRequest<{ ok: boolean; error?: string; data: DiagnosticsResult }>(\n apiUrl, token, 'GET', `/org/environments/instances/${instanceId}/diagnostics`,\n undefined,\n { timeoutMs: 60_000 }\n );\n\n if (!diag.ok) continue;\n\n const elapsed = Math.round((Date.now() - startTime) / 1000);\n const dockerOutput = 'stdout' in diag.data.docker ? diag.data.docker.stdout : '';\n const appOutput = 'stdout' in diag.data.appHealth ? diag.data.appHealth.stdout : '';\n const appUp = appOutput.length > 0 && !appOutput.includes('UNREACHABLE');\n\n // Show a compact progress line\n const containerCount = (dockerOutput.match(/\\n/g) || []).length + (dockerOutput ? 1 : 0);\n const healthyCount = (dockerOutput.match(/\\(healthy\\)/g) || []).length;\n process.stdout.write(`\\r [${elapsed}s] containers: ${containerCount}, healthy: ${healthyCount}, app: ${appUp ? 'up' : 'waiting'} `);\n\n // Trust the HTTP probe: if nginx is serving the app on :3000 or :8000, we're done.\n // Compose healthchecks are optional and most user services don't declare them.\n if (appUp) {\n process.stdout.write('\\n');\n console.log('Build complete.');\n return;\n }\n }\n\n process.stdout.write('\\n');\n console.error('Build timed out waiting for the app to respond. Check diagnostics and logs:');\n console.error(` canary sandbox diagnostics ${instanceId}`);\n console.error(` canary sandbox logs ${instanceId} --service <name>`);\n process.exit(1);\n}\n\nasync function handleRunCommand(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const service = getArgValue(argv, '--service');\n const timeoutFlag = getArgValue(argv, '--timeout');\n\n // Strip our flags (--json, --service <value>, --timeout <value>) so they\n // don't leak into the remote command.\n const filtered = argv.filter((a, i, arr) => {\n if (a === '--json') return false;\n if (a === '--service' || a === '--timeout') return false;\n if (i > 0 && (arr[i - 1] === '--service' || arr[i - 1] === '--timeout')) return false;\n return true;\n });\n\n // First non-flag arg is the instance ID; everything after it is the command\n // (including flags like -la that belong to the remote command, not to us)\n const firstNonFlag = filtered.findIndex((a) => !a.startsWith('-'));\n const instanceId = firstNonFlag >= 0 ? filtered[firstNonFlag] : undefined;\n const command = firstNonFlag >= 0 ? filtered.slice(firstNonFlag + 1).join(' ') : '';\n\n if (!instanceId || !command) {\n console.error('Error: instance ID and command required. Usage: canary sandbox run-command <instance-id> [--service <name>] [--timeout <ms>] <command...>');\n process.exit(1);\n }\n\n // Server-side run-command caps at 55s (SANDBOX_COMMAND_TIMEOUT). Default\n // the CLI just past that so we surface the server's typed timeout rather\n // than an opaque client-side cancel. For longer ops (test suites,\n // playwright), pass a higher value or use first-class actions.\n const timeoutMs = timeoutFlag ? Math.max(parseInt(timeoutFlag, 10), 1000) : 60_000;\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: { stdout: string; stderr: string; exitCode: number } }>(\n apiUrl, token, 'POST', `/org/environments/instances/${instanceId}/run-command`,\n { command, ...(service ? { service } : {}) },\n { timeoutMs }\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n if (res.data.stdout) {\n process.stdout.write(res.data.stdout);\n if (!res.data.stdout.endsWith('\\n')) process.stdout.write('\\n');\n }\n if (res.data.stderr) {\n process.stderr.write(`STDERR: ${res.data.stderr}`);\n if (!res.data.stderr.endsWith('\\n')) process.stderr.write('\\n');\n }\n if (res.data.exitCode !== 0) {\n console.log(`Exit code: ${res.data.exitCode}`);\n }\n}\n\nasync function handleDiagnostics(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const instanceId = positional[0];\n const json = hasFlag(argv, '--json');\n\n if (!instanceId) {\n console.error('Error: instance ID required. Usage: canary sandbox diagnostics <instance-id>');\n process.exit(1);\n }\n\n // Server-side DIAGNOSTICS_TIMEOUT_MS is 30s; the client needs a bit more\n // headroom than that or we race the server and report a misleading client\n // timeout for a server-side timeout.\n const res = await apiRequest<{ ok: boolean; error?: string; data: DiagnosticsResult }>(\n apiUrl, token, 'GET', `/org/environments/instances/${instanceId}/diagnostics`,\n undefined,\n { timeoutMs: 60_000 }\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n const routes = await fetchInstanceRoutes(apiUrl, token, instanceId);\n const data = { ...res.data, routes };\n\n if (json) {\n console.log(JSON.stringify(data, null, 2));\n return;\n }\n\n const d = data;\n\n console.log('=== Instance ===');\n for (const [key, value] of Object.entries(d.instance)) {\n console.log(` ${key}: ${value}`);\n }\n\n if (d.provision) {\n console.log('');\n console.log('=== Provisioning ===');\n console.log(` phase: ${d.provision.phase}`);\n console.log(` jobStatus: ${d.provision.jobStatus}`);\n if (d.provision.startedAt) console.log(` startedAt: ${d.provision.startedAt}`);\n if (d.provision.elapsedSeconds !== null) console.log(` elapsed: ${d.provision.elapsedSeconds}s`);\n if (d.provision.lastError) console.log(` lastError: ${d.provision.lastError}`);\n }\n\n const sections: Array<[string, CommandOrError]> = [\n ['Docker Containers', d.docker],\n ['Git Status', d.git],\n ['Disk Usage', d.disk],\n ['Agent Health', d.agentHealth],\n ['App Health', d.appHealth],\n ];\n\n for (const [title, result] of sections) {\n console.log('');\n console.log(`=== ${title} ===`);\n if ('error' in result) {\n console.log(` Error: ${result.error}`);\n } else {\n if (result.stdout) console.log(result.stdout);\n if (result.stderr) console.log(` STDERR: ${result.stderr}`);\n }\n }\n}\n\nasync function handleLogs(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const instanceId = positional[0];\n const json = hasFlag(argv, '--json');\n\n if (!instanceId) {\n console.error('Error: instance ID required. Usage: canary sandbox logs <instance-id>');\n process.exit(1);\n }\n\n const service = getArgValue(argv, '--service');\n const tail = getArgValue(argv, '--tail') ?? '200';\n\n // Don't send `service: ''` — the server's regex validator rejects empty\n // strings even though the field is optional, and the route then returns\n // 500 instead of an all-services tail. Omit the field when absent.\n const res = await apiRequest<{ ok: boolean; error?: string; data: { logs: string } }>(\n apiUrl, token, 'POST', `/org/environments/instances/${instanceId}/docker/logs`, {\n ...(service ? { service } : {}),\n tail: parseInt(tail, 10),\n }\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n process.stdout.write(res.data.logs ?? '(no logs)');\n}\n\nasync function handleTerminate(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const instanceId = positional[0];\n\n if (!instanceId) {\n console.error('Error: instance ID required. Usage: canary sandbox terminate <instance-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl, token, 'POST', `/org/environments/instances/${instanceId}/terminate`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n console.log(`Instance ${instanceId} termination initiated.`);\n}\n\nasync function handleDelete(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n\n if (!templateId) {\n console.error('Error: template ID required. Usage: canary sandbox delete <template-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl, token, 'DELETE', `/org/environments/templates/${templateId}`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n console.log(`Template ${templateId} deleted.`);\n}\n\n// ---------------------------------------------------------------------------\n// Action handlers\n// ---------------------------------------------------------------------------\n\ntype ActionDef = {\n id: string;\n slug: string;\n label: string;\n description: string | null;\n icon: string | null;\n enabled: boolean;\n inputSchema: Record<string, unknown>;\n outputSchema: Record<string, unknown> | null;\n scriptContent: string;\n timeoutMs: number;\n createdAt: string;\n updatedAt: string;\n};\n\ntype ActionExecution = {\n id: string;\n actionId: string;\n instanceId: string;\n source: string;\n status: string;\n result: Record<string, unknown> | null;\n stdout: string | null;\n stderr: string | null;\n exitCode: number | null;\n durationMs: number | null;\n error: string | null;\n createdAt: string;\n};\n\nasync function handleActionList(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const json = hasFlag(argv, '--json');\n\n if (!templateId) {\n console.error('Error: template ID required. Usage: canary sandbox action list <template-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: ActionDef[] }>(\n apiUrl, token, 'GET', `/org/environments/templates/${templateId}/actions`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n const actions = res.data ?? [];\n if (actions.length === 0) {\n console.log('No actions defined for this template.');\n return;\n }\n\n console.log(`Actions (${actions.length}):`);\n for (const a of actions) {\n const status = a.enabled ? '' : ' [disabled]';\n console.log(` ${pad(a.slug, 30)} ${pad(a.label, 25)}${status}`);\n }\n}\n\nasync function handleActionGet(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const slug = positional[1];\n const json = hasFlag(argv, '--json');\n\n if (!templateId || !slug) {\n console.error('Error: template ID and slug required. Usage: canary sandbox action get <template-id> <slug>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: ActionDef }>(\n apiUrl, token, 'GET', `/org/environments/templates/${templateId}/actions/${slug}`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n const a = res.data;\n console.log(`Action: ${a.slug}`);\n console.log(` Label: ${a.label}`);\n console.log(` Description: ${a.description ?? '(none)'}`);\n console.log(` Icon: ${a.icon ?? '(none)'}`);\n console.log(` Enabled: ${a.enabled}`);\n console.log(` Timeout: ${a.timeoutMs}ms`);\n console.log(` Input Schema:`);\n console.log(` ${JSON.stringify(a.inputSchema, null, 2).split('\\n').join('\\n ')}`);\n if (a.outputSchema) {\n console.log(` Output Schema:`);\n console.log(` ${JSON.stringify(a.outputSchema, null, 2).split('\\n').join('\\n ')}`);\n }\n console.log(` Script:`);\n console.log(` ${a.scriptContent.split('\\n').join('\\n ')}`);\n}\n\nasync function handleActionCreate(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const slug = positional[1];\n const json = hasFlag(argv, '--json');\n\n if (!templateId || !slug) {\n console.error('Error: template ID and slug required. Usage: canary sandbox action create <template-id> <slug> [options]');\n process.exit(1);\n }\n\n const scriptPath = getArgValue(argv, '--script');\n const inputSchemaPath = getArgValue(argv, '--input-schema');\n const outputSchemaPath = getArgValue(argv, '--output-schema');\n const credentialOutputConfigPath = getArgValue(argv, '--credential-output-config');\n const label = getArgValue(argv, '--label') ?? slug.replace(/-/g, ' ').replace(/\\b\\w/g, (c) => c.toUpperCase());\n const description = getArgValue(argv, '--description');\n const icon = getArgValue(argv, '--icon');\n const timeoutStr = getArgValue(argv, '--timeout');\n const encryptScript = hasFlag(argv, '--encrypt-script');\n const credentialTemplateId = getArgValue(argv, '--credential-template');\n const provisioningMode = getArgValue(argv, '--provisioning-mode');\n\n if (provisioningMode && provisioningMode !== 'shared' && provisioningMode !== 'unique') {\n console.error(\"Error: --provisioning-mode must be 'shared' or 'unique'\");\n process.exit(1);\n }\n\n if (!scriptPath) {\n console.error('Error: --script <file> is required');\n process.exit(1);\n }\n if (!inputSchemaPath) {\n console.error('Error: --input-schema <file> is required');\n process.exit(1);\n }\n\n let scriptContent: string;\n try {\n scriptContent = readFileSync(scriptPath, 'utf-8');\n } catch (err) {\n console.error(`Error reading script file: ${err}`);\n process.exit(1);\n }\n\n let inputSchema: Record<string, unknown>;\n try {\n inputSchema = JSON.parse(readFileSync(inputSchemaPath, 'utf-8'));\n } catch (err) {\n console.error(`Error reading input schema file: ${err}`);\n process.exit(1);\n }\n\n let outputSchema: Record<string, unknown> | undefined;\n if (outputSchemaPath) {\n try {\n outputSchema = JSON.parse(readFileSync(outputSchemaPath, 'utf-8'));\n } catch (err) {\n console.error(`Error reading output schema file: ${err}`);\n process.exit(1);\n }\n }\n\n let credentialOutputConfig: Record<string, unknown> | undefined;\n if (credentialOutputConfigPath) {\n try {\n credentialOutputConfig = JSON.parse(readFileSync(credentialOutputConfigPath, 'utf-8'));\n } catch (err) {\n console.error(`Error reading credential output config file: ${err}`);\n process.exit(1);\n }\n }\n\n const body: Record<string, unknown> = {\n label,\n scriptContent,\n inputSchema,\n ...(description ? { description } : {}),\n ...(icon ? { icon } : {}),\n ...(outputSchema ? { outputSchema } : {}),\n ...(credentialOutputConfig ? { credentialOutputConfig } : {}),\n ...(credentialTemplateId ? { credentialTemplateId } : {}),\n ...(provisioningMode ? { provisioningMode } : {}),\n ...(timeoutStr ? { timeoutMs: parseInt(timeoutStr, 10) } : {}),\n ...(encryptScript ? { scriptEncrypted: true } : {}),\n };\n\n const res = await apiRequest<{ ok: boolean; error?: string; data?: ActionDef }>(\n apiUrl, token, 'PUT', `/org/environments/templates/${templateId}/actions/${slug}`, body\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n console.log(`Action '${slug}' saved (${scriptContent.length} bytes script, label: \"${label}\")`);\n}\n\nasync function handleActionDelete(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const slug = positional[1];\n\n if (!templateId || !slug) {\n console.error('Error: template ID and slug required. Usage: canary sandbox action delete <template-id> <slug>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl, token, 'DELETE', `/org/environments/templates/${templateId}/actions/${slug}`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n console.log(`Action '${slug}' deleted.`);\n}\n\nasync function handleActionExecute(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const instanceId = positional[0];\n const slug = positional[1];\n const json = hasFlag(argv, '--json');\n\n if (!instanceId || !slug) {\n console.error('Error: instance ID and slug required. Usage: canary sandbox action execute <instance-id> <slug> [options]');\n process.exit(1);\n }\n\n // Collect params from --param key=value flags\n let params: Record<string, unknown> = {};\n\n const paramsFile = getArgValue(argv, '--params-file');\n if (paramsFile) {\n try {\n params = JSON.parse(readFileSync(paramsFile, 'utf-8'));\n } catch (err) {\n console.error(`Error reading params file: ${err}`);\n process.exit(1);\n }\n }\n\n // --param flags override params-file\n for (let i = 0; i < argv.length; i++) {\n if (argv[i] === '--param' && argv[i + 1]) {\n const [key, ...valueParts] = argv[i + 1]!.split('=');\n if (key && valueParts.length > 0) {\n params[key] = valueParts.join('=');\n }\n i++; // skip value\n }\n }\n\n interface ActionExecuteResponse {\n executionId: string;\n status: string;\n result: unknown;\n stdout: string | null;\n stderr: string | null;\n exitCode: number | null;\n durationMs: number | null;\n error: string | null;\n credentialId?: string | null;\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data?: ActionExecuteResponse }>(\n apiUrl, token, 'POST', `/org/environments/instances/${instanceId}/actions/${slug}/execute`, {\n params,\n source: 'cli',\n }\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n const exec = res.data!;\n const statusIcon = exec.status === 'completed' ? '[done]' : exec.status === 'failed' ? '[FAIL]' : `[${exec.status}]`;\n console.log(`${statusIcon} Action '${slug}' ${exec.status} (${exec.durationMs ?? 0}ms, exit ${exec.exitCode ?? '?'})`);\n if (exec.result) {\n console.log(`Result: ${JSON.stringify(exec.result, null, 2)}`);\n }\n if (exec.credentialId) {\n console.log(`Credential: ${exec.credentialId} (linked in property vault)`);\n }\n if (exec.status === 'failed' && exec.stderr) {\n // Cap by bytes first so a single multi-MB line doesn't blow up the terminal,\n // then by line count for readability.\n const tail = exec.stderr.slice(-10_000).trim().split('\\n').slice(-20).join('\\n');\n console.log(`Stderr (last 20 lines):\\n${tail}`);\n }\n if (exec.error) {\n console.log(`Error: ${exec.error}`);\n }\n}\n\nasync function handleActionExecutions(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const instanceId = positional[0];\n const json = hasFlag(argv, '--json');\n\n if (!instanceId) {\n console.error('Error: instance ID required. Usage: canary sandbox action executions <instance-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<{ ok: boolean; error?: string; data: ActionExecution[] }>(\n apiUrl, token, 'GET', `/org/environments/instances/${instanceId}/actions/executions`\n );\n\n if (!res.ok) {\n console.error(`Error: ${res.error}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res.data, null, 2));\n return;\n }\n\n const execs = res.data ?? [];\n if (execs.length === 0) {\n console.log('No executions yet.');\n return;\n }\n\n console.log('Executions:');\n for (const e of execs) {\n const icon = STATUS_ICONS[e.status] ?? `[${e.status}]`;\n const dur = e.durationMs !== null && e.durationMs !== undefined ? `${e.durationMs}ms` : '?ms';\n console.log(` ${icon} ${pad(e.id.slice(0, 8), 10)} ${pad(e.source, 6)} ${pad(e.status, 12)} ${pad(dur, 8)} ${formatDate(e.createdAt)}`);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Multi-repo: manage repos linked to a sandbox template\n// ---------------------------------------------------------------------------\n\ntype TemplateRepoLink = {\n id: string;\n templateId: string;\n propertyGithubRepoId: string;\n role: string | null;\n branch: string;\n subdirectory: string | null;\n serviceName: string;\n};\n\n/**\n * Parse `role=owner/name@branch:subdir` (branch and subdir optional) into the\n * pieces the API expects. Used by `canary sandbox repo add --spec ...`.\n */\nfunction parseRepoSpec(spec: string): {\n role?: string;\n repoFullName: string;\n branch?: string;\n subdirectory?: string;\n} {\n let rest = spec;\n let role: string | undefined;\n const eq = rest.indexOf('=');\n if (eq > -1 && !rest.slice(0, eq).includes('/')) {\n role = rest.slice(0, eq);\n rest = rest.slice(eq + 1);\n }\n let subdirectory: string | undefined;\n const colon = rest.indexOf(':');\n if (colon > -1) {\n subdirectory = rest.slice(colon + 1);\n rest = rest.slice(0, colon);\n }\n let branch: string | undefined;\n const at = rest.indexOf('@');\n if (at > -1) {\n branch = rest.slice(at + 1);\n rest = rest.slice(0, at);\n }\n return { role, repoFullName: rest, branch, subdirectory };\n}\n\nasync function handleRepoList(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const templateId = getArgValue(argv, '--template');\n if (!templateId) {\n console.error('Error: --template is required.');\n process.exit(1);\n }\n\n const result = await apiRequest<{ ok: boolean; items?: TemplateRepoLink[]; error?: string }>(\n apiUrl,\n token,\n 'GET',\n `/org/environments/templates/${templateId}/repos`\n );\n\n if (!result.ok) {\n console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(result.items ?? [], null, 2));\n return;\n }\n\n const items = result.items ?? [];\n if (items.length === 0) {\n console.log('No repos linked to this template.');\n return;\n }\n for (const r of items) {\n const role = r.role ? ` [${r.role}]` : '';\n const subdir = r.subdirectory ? `:${r.subdirectory}` : '';\n console.log(` ${r.serviceName} → ${r.propertyGithubRepoId}@${r.branch}${subdir}${role} (link=${r.id})`);\n }\n}\n\nasync function handleRepoAdd(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const templateId = getArgValue(argv, '--template');\n const propertyGithubRepoId = getArgValue(argv, '--property-github-repo-id');\n const spec = getArgValue(argv, '--spec');\n const role = getArgValue(argv, '--role');\n const branch = getArgValue(argv, '--branch');\n const subdirectory = getArgValue(argv, '--subdirectory');\n const serviceName = getArgValue(argv, '--service-name');\n\n if (!templateId || !propertyGithubRepoId) {\n console.error('Error: --template and --property-github-repo-id are required.');\n console.error('Tip: link the repo to the property first via `canary property repo link`, then pass its id here.');\n process.exit(1);\n }\n\n const parsed: ReturnType<typeof parseRepoSpec> | { role?: undefined; branch?: undefined; subdirectory?: undefined } = spec ? parseRepoSpec(spec) : {};\n\n const body: Record<string, unknown> = { propertyGithubRepoId };\n const finalRole = role ?? parsed.role;\n const finalBranch = branch ?? parsed.branch;\n const finalSubdir = subdirectory ?? parsed.subdirectory;\n if (finalRole !== undefined) body.role = finalRole;\n if (finalBranch !== undefined) body.branch = finalBranch;\n if (finalSubdir !== undefined) body.subdirectory = finalSubdir;\n if (serviceName !== undefined) body.serviceName = serviceName;\n\n const result = await apiRequest<{ ok: boolean; data?: TemplateRepoLink; error?: string }>(\n apiUrl,\n token,\n 'POST',\n `/org/environments/templates/${templateId}/repos`,\n body\n );\n\n if (!result.ok) {\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n if (json) console.log(JSON.stringify(result.data, null, 2));\n else console.log(`Linked repo to template ${templateId} (link=${result.data?.id})`);\n}\n\nasync function handleRepoUpdate(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const templateId = getArgValue(argv, '--template');\n const linkId = getArgValue(argv, '--link-id');\n const role = getArgValue(argv, '--role');\n const branch = getArgValue(argv, '--branch');\n const subdirectory = getArgValue(argv, '--subdirectory');\n const serviceName = getArgValue(argv, '--service-name');\n\n if (!templateId || !linkId) {\n console.error('Error: --template and --link-id are required.');\n process.exit(1);\n }\n\n const body: Record<string, unknown> = {};\n if (role !== undefined) body.role = role;\n if (branch !== undefined) body.branch = branch;\n if (subdirectory !== undefined) body.subdirectory = subdirectory;\n if (serviceName !== undefined) body.serviceName = serviceName;\n\n const result = await apiRequest<{ ok: boolean; data?: TemplateRepoLink; error?: string }>(\n apiUrl,\n token,\n 'PATCH',\n `/org/environments/templates/${templateId}/repos/${linkId}`,\n body\n );\n\n if (!result.ok) {\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n if (json) console.log(JSON.stringify(result.data, null, 2));\n else console.log(`Updated repo link ${linkId}`);\n}\n\nasync function handleRepoRemove(argv: string[], apiUrl: string, token: string): Promise<void> {\n const json = hasFlag(argv, '--json');\n const templateId = getArgValue(argv, '--template');\n const linkId = getArgValue(argv, '--link-id');\n if (!templateId || !linkId) {\n console.error('Error: --template and --link-id are required.');\n process.exit(1);\n }\n const result = await apiRequest<{ ok: boolean; error?: string }>(\n apiUrl,\n token,\n 'DELETE',\n `/org/environments/templates/${templateId}/repos/${linkId}`\n );\n if (!result.ok) {\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.error(`Error: ${result.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n if (json) console.log(JSON.stringify(result, null, 2));\n else console.log(`Removed repo link ${linkId} from template ${templateId}`);\n}\n\nasync function handleRepo(argv: string[], apiUrl: string, token: string): Promise<void> {\n const [action, ...rest] = argv;\n switch (action) {\n case 'list':\n await handleRepoList(rest, apiUrl, token);\n break;\n case 'add':\n await handleRepoAdd(rest, apiUrl, token);\n break;\n case 'update':\n await handleRepoUpdate(rest, apiUrl, token);\n break;\n case 'remove':\n case 'rm':\n await handleRepoRemove(rest, apiUrl, token);\n break;\n default:\n console.error(\n `Unknown repo action: ${action ?? '(none)'}. Use list/add/update/remove.\\n` +\n 'Examples:\\n' +\n ' canary sandbox repo list --template <template-id>\\n' +\n ' canary sandbox repo add --template <template-id> --property-github-repo-id <uuid> --role frontend\\n' +\n ' canary sandbox repo add --template <template-id> --property-github-repo-id <uuid> --spec frontend=owner/web@main:/apps/web'\n );\n process.exit(1);\n }\n}\n\n// ---------------------------------------------------------------------------\n// AMI lifecycle (per-template golden AMI). See\n// specs/sandbox-infrastructure-optimization.md §Phase 2 §Naming + rollback UX.\n// ---------------------------------------------------------------------------\n\ninterface AmiRow {\n id: string;\n amiId: string | null;\n amiName: string | null;\n status: 'building' | 'ready' | 'failed' | 'superseded' | 'deregistered';\n artifactHash: string;\n instanceSize: string;\n baseAmiId: string;\n builtAt: string | null;\n supersededAt: string | null;\n deregisteredAt: string | null;\n buildError: string | null;\n buildJobId: string | null;\n createdAt: string;\n isCurrent: boolean;\n}\n\ninterface AmiListResponse {\n ok: boolean;\n error?: string;\n templateId?: string;\n currentAmiId?: string | null;\n pendingAmiBakeHash?: string | null;\n amis?: AmiRow[];\n}\n\nconst AMI_TERMINAL_STATUSES = new Set(['ready', 'failed', 'superseded', 'deregistered']);\n\nconst formatHashShort = (hash: string): string => hash.slice(0, 8);\n\n// Single source of truth for column widths so the header and row formatters\n// can't drift apart. The marker is a 1-char prefix sitting outside the\n// padded columns, with a single space gap.\nconst AMI_COL = {\n status: 12,\n hash: 8,\n built: 20,\n size: 8,\n amiId: 22,\n} as const;\n\nfunction printAmiTable(rows: AmiRow[], currentAmiId: string | null | undefined): void {\n if (rows.length === 0) {\n console.log('No AMI history yet — trigger one with `canary sandbox ami rebake <template-id>`.');\n return;\n }\n\n const header = ` ${'STATUS'.padEnd(AMI_COL.status)} ${'HASH'.padEnd(AMI_COL.hash)} ${'BUILT'.padEnd(AMI_COL.built)} ${'SIZE'.padEnd(AMI_COL.size)} ${'AMI-ID'.padEnd(AMI_COL.amiId)} ROW-ID`;\n const lines: string[] = [header];\n const markerFor = (row: AmiRow): string => {\n if (currentAmiId && row.id === currentAmiId) return '*';\n if (row.status === 'ready' || row.status === 'superseded') return 'R';\n return ' ';\n };\n for (const row of rows) {\n const marker = markerFor(row);\n const built = row.builtAt ? new Date(row.builtAt).toISOString().slice(0, 19) + 'Z' : '—';\n lines.push(\n `${marker} ${row.status.padEnd(AMI_COL.status)} ${formatHashShort(row.artifactHash).padEnd(AMI_COL.hash)} ${built.padEnd(AMI_COL.built)} ${row.instanceSize.padEnd(AMI_COL.size)} ${(row.amiId ?? '—').padEnd(AMI_COL.amiId)} ${row.id}`\n );\n }\n console.log(lines.join('\\n'));\n console.log('');\n console.log(\" '*' = current 'R' = ready/superseded (eligible for `canary sandbox ami use`)\");\n}\n\nasync function handleAmiList(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const json = hasFlag(argv, '--json');\n\n if (!templateId) {\n console.error('Error: template ID required. Usage: canary sandbox ami list <template-id>');\n process.exit(1);\n }\n\n const res = await apiRequest<AmiListResponse>(\n apiUrl,\n token,\n 'GET',\n `/org/environments/templates/${templateId}/amis`\n );\n\n if (!res.ok) {\n if (json) console.log(JSON.stringify(res, null, 2));\n else console.error(`Error: ${res.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res, null, 2));\n return;\n }\n\n console.log(`Template: ${res.templateId}`);\n console.log(`Current AMI row: ${res.currentAmiId ?? '— (using base AMI)'}`);\n if (res.pendingAmiBakeHash) {\n console.log(`Pending bake hash: ${formatHashShort(res.pendingAmiBakeHash)}`);\n }\n console.log('');\n printAmiTable(res.amis ?? [], res.currentAmiId);\n}\n\ninterface AmiRebakeResponse {\n ok: boolean;\n error?: string;\n reason?: 'enqueued' | 'already-baked' | 'coalesced';\n jobId?: string;\n amiRowId?: string;\n status?: AmiRow['status'];\n artifactHash?: string;\n}\n\n// Tolerate transient API errors during a long bake — a 502/504/ECONNRESET\n// shouldn't abort a 45-minute wait. Three consecutive failures still bails;\n// a single blip is logged and the next poll retries.\nconst POLL_TRANSIENT_FAILURE_LIMIT = 3;\n\nasync function pollAmiBuild(\n apiUrl: string,\n token: string,\n templateId: string,\n jobId: string,\n pollIntervalMs = 5000,\n timeoutMs = 45 * 60 * 1000\n): Promise<AmiRow | null> {\n const startedAt = Date.now();\n let lastSeenStatus: string | null = null;\n let consecutiveFailures = 0;\n while (Date.now() - startedAt < timeoutMs) {\n const res = await apiRequest<AmiListResponse>(\n apiUrl,\n token,\n 'GET',\n `/org/environments/templates/${templateId}/amis`\n );\n if (!res.ok) {\n consecutiveFailures += 1;\n if (consecutiveFailures >= POLL_TRANSIENT_FAILURE_LIMIT) {\n console.error(\n `Aborting wait after ${consecutiveFailures} consecutive poll failures: ${res.error ?? 'Unknown'}`\n );\n return null;\n }\n console.error(\n ` ↳ poll failure ${consecutiveFailures}/${POLL_TRANSIENT_FAILURE_LIMIT} — ${res.error ?? 'Unknown'}; retrying`\n );\n await new Promise((r) => setTimeout(r, pollIntervalMs));\n continue;\n }\n consecutiveFailures = 0;\n // Match on build_job_id, not artifactHash — multiple historical rows can\n // share the same hash (prior failed bakes), so a hash-only match races\n // against the worker's `building` row insert and can latch onto a stale\n // terminal row before the new row appears.\n const matching = (res.amis ?? []).find((r) => r.buildJobId === jobId);\n if (matching && AMI_TERMINAL_STATUSES.has(matching.status)) {\n return matching;\n }\n if (matching && matching.status !== lastSeenStatus) {\n lastSeenStatus = matching.status;\n console.log(` ↳ ${new Date().toISOString()} — status: ${matching.status}`);\n }\n await new Promise((r) => setTimeout(r, pollIntervalMs));\n }\n console.error(`Timed out after ${Math.round(timeoutMs / 1000)}s waiting for bake to finish.`);\n return null;\n}\n\nasync function handleAmiRebake(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const json = hasFlag(argv, '--json');\n const force = hasFlag(argv, '--force');\n const wait = hasFlag(argv, '--wait');\n\n if (!templateId) {\n console.error('Error: template ID required.');\n console.error('Usage: canary sandbox ami rebake <template-id> [--force] [--wait]');\n process.exit(1);\n }\n\n const res = await apiRequest<AmiRebakeResponse>(\n apiUrl,\n token,\n 'POST',\n `/org/environments/templates/${templateId}/amis/rebake`,\n { force }\n );\n\n if (!res.ok) {\n if (json) console.log(JSON.stringify(res, null, 2));\n else console.error(`Error: ${res.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res, null, 2));\n return;\n }\n\n if (res.reason === 'already-baked') {\n console.log(`AMI for hash ${formatHashShort(res.artifactHash ?? '')} already exists (${res.status}).`);\n console.log(` Row id: ${res.amiRowId}`);\n console.log(` Use \\`canary sandbox ami use ${templateId} ${res.amiRowId}\\` to switch to it,`);\n console.log(' or pass --force to bake a fresh copy anyway.');\n return;\n }\n\n if (res.reason === 'coalesced') {\n console.log('Another rebake was already queued for this template; nothing to do.');\n if (wait) {\n console.log(\n ' (--wait skipped: coalesced response has no job handle to follow. ' +\n 'Watch via `canary task list --status in_progress` or re-run rebake when the in-flight one finishes.)'\n );\n }\n return;\n }\n\n // res.reason === 'enqueued'\n console.log(`Bake job enqueued.`);\n console.log(` Job id: ${res.jobId}`);\n console.log(` Hash: ${formatHashShort(res.artifactHash ?? '')}`);\n\n if (wait) {\n if (!res.jobId) {\n console.error('Cannot --wait: API did not return a jobId for the enqueued bake.');\n process.exit(1);\n }\n console.log('');\n console.log('Polling for completion (Ctrl+C to detach; bake continues server-side)…');\n const final = await pollAmiBuild(apiUrl, token, templateId, res.jobId);\n if (final) {\n console.log('');\n if (final.status === 'ready') {\n console.log(`Bake complete: AMI ${final.amiId} (row ${final.id})`);\n } else {\n console.error(`Bake ended in status: ${final.status}`);\n if (final.buildError) console.error(` ${final.buildError}`);\n process.exit(1);\n }\n }\n }\n}\n\ninterface AmiUseResponse {\n ok: boolean;\n error?: string;\n templateId?: string;\n /** Row UUID (`environment_template_amis.id`) — what the request set as current. */\n currentAmiRowId?: string;\n /** AWS AMI handle (`ami-XXXXX`) of the row, when known. */\n currentAmiId?: string | null;\n alreadyCurrent?: boolean;\n promotedFromSuperseded?: boolean;\n demotedPriorAmiRowId?: string | null;\n priorDemoteSkipped?: boolean;\n}\n\nasync function handleAmiUse(argv: string[], apiUrl: string, token: string): Promise<void> {\n const positional = argv.filter((a) => !a.startsWith('-'));\n const templateId = positional[0];\n const amiRowId = positional[1];\n const json = hasFlag(argv, '--json');\n\n if (!templateId || !amiRowId) {\n console.error('Error: template ID and AMI row id required.');\n console.error('Usage: canary sandbox ami use <template-id> <ami-row-id>');\n console.error('Find row ids with `canary sandbox ami list <template-id>`.');\n process.exit(1);\n }\n\n const res = await apiRequest<AmiUseResponse>(\n apiUrl,\n token,\n 'PATCH',\n `/org/environments/templates/${templateId}/current-ami`,\n { amiRowId }\n );\n\n if (!res.ok) {\n if (json) console.log(JSON.stringify(res, null, 2));\n else console.error(`Error: ${res.error ?? 'Unknown error'}`);\n process.exit(1);\n }\n\n if (json) {\n console.log(JSON.stringify(res, null, 2));\n return;\n }\n\n if (res.alreadyCurrent) {\n console.log(`Row ${amiRowId} is already the current AMI for template ${templateId}.`);\n return;\n }\n\n console.log(`Current AMI updated.`);\n console.log(` Template: ${res.templateId}`);\n console.log(` Row: ${res.currentAmiRowId}`);\n if (res.currentAmiId) {\n console.log(` AMI: ${res.currentAmiId}`);\n }\n if (res.promotedFromSuperseded) {\n console.log(' Note: chosen row was superseded; promoted back to ready.');\n }\n if (res.demotedPriorAmiRowId) {\n console.log(` Demoted: ${res.demotedPriorAmiRowId} (prior current → superseded)`);\n }\n if (res.priorDemoteSkipped) {\n console.log(\n ' Warning: prior current row was not in `ready` status — demote skipped (see server logs).'\n );\n }\n}\n\nasync function handleAmi(argv: string[], apiUrl: string, token: string): Promise<void> {\n const [action, ...rest] = argv;\n switch (action) {\n case 'list':\n await handleAmiList(rest, apiUrl, token);\n break;\n case 'rebake':\n await handleAmiRebake(rest, apiUrl, token);\n break;\n case 'use':\n await handleAmiUse(rest, apiUrl, token);\n break;\n default:\n console.error(\n `Unknown ami action: ${action ?? '(none)'}. Use list/rebake/use.\\n` +\n 'Examples:\\n' +\n ' canary sandbox ami list <template-id>\\n' +\n ' canary sandbox ami rebake <template-id> [--force] [--wait]\\n' +\n ' canary sandbox ami use <template-id> <ami-row-id>'\n );\n process.exit(1);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Main dispatcher\n// ---------------------------------------------------------------------------\n\nexport async function runSandbox(argv: string[]): Promise<void> {\n const [subCommand, ...rest] = argv;\n\n if (!subCommand || subCommand === 'help' || hasFlag(argv, '--help', '-h')) {\n printHelp();\n return;\n }\n\n // Guide is purely local — no auth needed\n if (subCommand === 'guide') {\n const section = rest.find((a) => !a.startsWith('-'));\n const json = hasFlag(rest, '--json');\n printGuide(SANDBOX_GUIDE_SECTIONS, section, json);\n return;\n }\n\n const { apiUrl, token } = await resolveConfig(argv);\n\n // Strip global flags consumed by resolveConfig so handlers don't see them as positional args\n const globalFlags = new Set(['--env', '--api-url', '--token']);\n const args = rest.filter((arg, i) => {\n if (globalFlags.has(arg)) return false;\n if (i > 0 && globalFlags.has(rest[i - 1])) return false;\n return true;\n });\n\n switch (subCommand) {\n case 'list':\n await handleList(args, apiUrl, token);\n break;\n case 'template':\n await handleTemplate(args, apiUrl, token);\n break;\n case 'repo':\n await handleRepo(args, apiUrl, token);\n break;\n case 'artifacts':\n await handleArtifacts(args, apiUrl, token);\n break;\n case 'checklist':\n await handleChecklist(args, apiUrl, token);\n break;\n case 'create':\n await handleCreate(args, apiUrl, token);\n break;\n case 'provision':\n await handleProvision(args, apiUrl, token);\n break;\n case 'verify':\n await handleVerify(args, apiUrl, token);\n break;\n case 'set-size':\n await handleSetSize(args, apiUrl, token);\n break;\n case 'ami':\n await handleAmi(args, apiUrl, token);\n break;\n case 'artifact': {\n const [action, ...actionRest] = args;\n if (action === 'get') {\n await handleArtifactGet(actionRest, apiUrl, token);\n } else if (action === 'create') {\n await handleArtifactCreate(actionRest, apiUrl, token);\n } else {\n console.error(`Unknown artifact action: ${action}. Use \"get\" or \"create\".`);\n process.exit(1);\n }\n break;\n }\n case 'config': {\n const [configAction, ...configRest] = args;\n if (configAction === 'list') {\n await handleConfigList(configRest, apiUrl, token);\n } else if (configAction === 'set') {\n await handleConfigSet(configRest, apiUrl, token);\n } else {\n console.error(`Unknown config action: ${configAction}. Use \"list\" or \"set\".`);\n process.exit(1);\n }\n break;\n }\n case 'action': {\n const [actionSub, ...actionRest] = args;\n switch (actionSub) {\n case 'list':\n await handleActionList(actionRest, apiUrl, token);\n break;\n case 'get':\n await handleActionGet(actionRest, apiUrl, token);\n break;\n case 'create':\n await handleActionCreate(actionRest, apiUrl, token);\n break;\n case 'delete':\n await handleActionDelete(actionRest, apiUrl, token);\n break;\n case 'execute':\n await handleActionExecute(actionRest, apiUrl, token);\n break;\n case 'executions':\n await handleActionExecutions(actionRest, apiUrl, token);\n break;\n default:\n console.error(`Unknown action sub-command: ${actionSub}. Use \"list\", \"get\", \"create\", \"delete\", \"execute\", or \"executions\".`);\n process.exit(1);\n }\n break;\n }\n case 'build':\n await handleBuild(args, apiUrl, token);\n break;\n case 'run-command':\n await handleRunCommand(args, apiUrl, token);\n break;\n case 'diagnostics':\n await handleDiagnostics(args, apiUrl, token);\n break;\n case 'logs':\n await handleLogs(args, apiUrl, token);\n break;\n case 'terminate':\n await handleTerminate(args, apiUrl, token);\n break;\n case 'delete':\n await handleDelete(args, apiUrl, token);\n break;\n default:\n console.error(`Unknown sub-command: ${subCommand}`);\n printHelp();\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,OAAO,aAAa;AACpB,SAAS,oBAAoB;AAwF7B,eAAe,oBAAoB,QAAgB,OAAe,YAA6C;AAC7G,QAAM,MAAM,MAAM;AAAA,IAChB;AAAA,IAAQ;AAAA,IAAO;AAAA,IAAO,+BAA+B,UAAU;AAAA,IAC/D;AAAA,IACA,EAAE,WAAW,IAAO;AAAA,EACtB;AACA,SAAO,IAAI,KAAK,IAAI,KAAK,SAAS,CAAC;AACrC;AAMA,IAAM,eAAuC;AAAA,EAC3C,WAAW;AAAA,EACX,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AACX;AAEA,SAAS,WAAW,KAAqB;AACvC,SAAO,IAAI,KAAK,GAAG,EAAE,eAAe;AACtC;AAEA,SAAS,IAAI,GAAW,GAAmB;AACzC,SAAO,EAAE,OAAO,CAAC;AACnB;AAEA,IAA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