agentplane 0.3.1 → 0.3.3

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 (201) hide show
  1. package/assets/AGENTS.md +5 -4
  2. package/assets/agents/CODER.json +4 -3
  3. package/assets/agents/DOCS.json +1 -1
  4. package/assets/agents/INTEGRATOR.json +1 -1
  5. package/assets/agents/ORCHESTRATOR.json +1 -0
  6. package/assets/agents/PLANNER.json +1 -0
  7. package/assets/agents/TESTER.json +3 -1
  8. package/assets/policy/dod.code.md +2 -2
  9. package/assets/policy/dod.core.md +16 -2
  10. package/assets/policy/dod.docs.md +2 -2
  11. package/assets/policy/incidents.md +44 -1
  12. package/assets/policy/workflow.direct.md +10 -5
  13. package/bin/agentplane.js +116 -18
  14. package/bin/dist-guard.js +78 -10
  15. package/bin/runtime-context.d.ts +23 -0
  16. package/bin/runtime-context.js +94 -0
  17. package/bin/runtime-watch.d.ts +26 -0
  18. package/bin/runtime-watch.js +116 -0
  19. package/bin/stale-dist-policy.d.ts +6 -0
  20. package/bin/stale-dist-policy.js +44 -0
  21. package/dist/.build-manifest.json +2480 -5
  22. package/dist/backends/task-backend/local-backend.d.ts.map +1 -1
  23. package/dist/backends/task-backend/local-backend.js +9 -12
  24. package/dist/backends/task-backend/redmine-backend.d.ts.map +1 -1
  25. package/dist/backends/task-backend/redmine-backend.js +23 -18
  26. package/dist/backends/task-backend/shared/constants.d.ts +1 -0
  27. package/dist/backends/task-backend/shared/constants.d.ts.map +1 -1
  28. package/dist/backends/task-backend/shared/constants.js +1 -0
  29. package/dist/backends/task-backend/shared/doc.d.ts +1 -0
  30. package/dist/backends/task-backend/shared/doc.d.ts.map +1 -1
  31. package/dist/backends/task-backend/shared/doc.js +4 -1
  32. package/dist/backends/task-backend/shared/export.js +3 -3
  33. package/dist/cli/bootstrap-guide.d.ts +16 -0
  34. package/dist/cli/bootstrap-guide.d.ts.map +1 -0
  35. package/dist/cli/bootstrap-guide.js +112 -0
  36. package/dist/cli/command-guide.d.ts.map +1 -1
  37. package/dist/cli/command-guide.js +62 -203
  38. package/dist/cli/command-snippets.d.ts +2 -2
  39. package/dist/cli/command-snippets.js +2 -2
  40. package/dist/cli/run-cli/catalog.d.ts +7 -0
  41. package/dist/cli/run-cli/catalog.d.ts.map +1 -0
  42. package/dist/cli/run-cli/catalog.js +22 -0
  43. package/dist/cli/run-cli/command-catalog.d.ts +1 -1
  44. package/dist/cli/run-cli/command-catalog.d.ts.map +1 -1
  45. package/dist/cli/run-cli/command-catalog.js +11 -0
  46. package/dist/cli/run-cli/commands/core.js +1 -1
  47. package/dist/cli/run-cli/commands/init/write-config.d.ts.map +1 -1
  48. package/dist/cli/run-cli/commands/init/write-config.js +2 -0
  49. package/dist/cli/run-cli/commands/init.js +5 -14
  50. package/dist/cli/run-cli/error-guidance.d.ts +9 -0
  51. package/dist/cli/run-cli/error-guidance.d.ts.map +1 -0
  52. package/dist/cli/run-cli/error-guidance.js +180 -0
  53. package/dist/cli/run-cli/globals.d.ts +22 -0
  54. package/dist/cli/run-cli/globals.d.ts.map +1 -0
  55. package/dist/cli/run-cli/globals.js +197 -0
  56. package/dist/cli/run-cli/update-warning.d.ts +6 -0
  57. package/dist/cli/run-cli/update-warning.d.ts.map +1 -0
  58. package/dist/cli/run-cli/update-warning.js +64 -0
  59. package/dist/cli/run-cli.d.ts.map +1 -1
  60. package/dist/cli/run-cli.js +5 -476
  61. package/dist/cli/spec/docs-render.d.ts.map +1 -1
  62. package/dist/cli/spec/docs-render.js +14 -1
  63. package/dist/commands/doctor/archive.d.ts +4 -0
  64. package/dist/commands/doctor/archive.d.ts.map +1 -0
  65. package/dist/commands/doctor/archive.js +211 -0
  66. package/dist/commands/doctor/fixes.d.ts +9 -0
  67. package/dist/commands/doctor/fixes.d.ts.map +1 -0
  68. package/dist/commands/doctor/fixes.js +40 -0
  69. package/dist/commands/doctor/layering.d.ts +2 -0
  70. package/dist/commands/doctor/layering.d.ts.map +1 -0
  71. package/dist/commands/doctor/layering.js +87 -0
  72. package/dist/commands/doctor/runtime.d.ts +4 -0
  73. package/dist/commands/doctor/runtime.d.ts.map +1 -0
  74. package/dist/commands/doctor/runtime.js +56 -0
  75. package/dist/commands/doctor/workflow.d.ts +6 -0
  76. package/dist/commands/doctor/workflow.d.ts.map +1 -0
  77. package/dist/commands/doctor/workflow.js +62 -0
  78. package/dist/commands/doctor/workspace.d.ts +2 -0
  79. package/dist/commands/doctor/workspace.d.ts.map +1 -0
  80. package/dist/commands/doctor/workspace.js +165 -0
  81. package/dist/commands/doctor.run.d.ts.map +1 -1
  82. package/dist/commands/doctor.run.js +16 -305
  83. package/dist/commands/doctor.spec.d.ts +1 -0
  84. package/dist/commands/doctor.spec.d.ts.map +1 -1
  85. package/dist/commands/doctor.spec.js +15 -1
  86. package/dist/commands/finish.run.d.ts.map +1 -1
  87. package/dist/commands/finish.run.js +1 -0
  88. package/dist/commands/finish.spec.d.ts +1 -0
  89. package/dist/commands/finish.spec.d.ts.map +1 -1
  90. package/dist/commands/finish.spec.js +23 -2
  91. package/dist/commands/guard/impl/commands.d.ts.map +1 -1
  92. package/dist/commands/guard/impl/commands.js +19 -0
  93. package/dist/commands/release/apply.command.d.ts +2 -7
  94. package/dist/commands/release/apply.command.d.ts.map +1 -1
  95. package/dist/commands/release/apply.command.js +159 -382
  96. package/dist/commands/release/apply.mutation.d.ts +7 -0
  97. package/dist/commands/release/apply.mutation.d.ts.map +1 -0
  98. package/dist/commands/release/apply.mutation.js +107 -0
  99. package/dist/commands/release/apply.preflight.d.ts +25 -0
  100. package/dist/commands/release/apply.preflight.d.ts.map +1 -0
  101. package/dist/commands/release/apply.preflight.js +338 -0
  102. package/dist/commands/release/apply.reporting.d.ts +4 -0
  103. package/dist/commands/release/apply.reporting.d.ts.map +1 -0
  104. package/dist/commands/release/apply.reporting.js +24 -0
  105. package/dist/commands/release/apply.types.d.ts +46 -0
  106. package/dist/commands/release/apply.types.d.ts.map +1 -0
  107. package/dist/commands/release/apply.types.js +1 -0
  108. package/dist/commands/runtime.command.d.ts +28 -0
  109. package/dist/commands/runtime.command.d.ts.map +1 -0
  110. package/dist/commands/runtime.command.js +169 -0
  111. package/dist/commands/shared/task-store.d.ts.map +1 -1
  112. package/dist/commands/shared/task-store.js +7 -3
  113. package/dist/commands/task/add.d.ts.map +1 -1
  114. package/dist/commands/task/add.js +3 -33
  115. package/dist/commands/task/block.d.ts.map +1 -1
  116. package/dist/commands/task/block.js +2 -2
  117. package/dist/commands/task/close-duplicate.d.ts.map +1 -1
  118. package/dist/commands/task/close-duplicate.js +2 -2
  119. package/dist/commands/task/close-noop.d.ts.map +1 -1
  120. package/dist/commands/task/close-noop.js +2 -2
  121. package/dist/commands/task/comment.js +2 -2
  122. package/dist/commands/task/derive.d.ts.map +1 -1
  123. package/dist/commands/task/derive.js +3 -3
  124. package/dist/commands/task/doc-template.d.ts +10 -0
  125. package/dist/commands/task/doc-template.d.ts.map +1 -0
  126. package/dist/commands/task/doc-template.js +104 -0
  127. package/dist/commands/task/doc.d.ts.map +1 -1
  128. package/dist/commands/task/doc.js +36 -1
  129. package/dist/commands/task/finish.d.ts +1 -0
  130. package/dist/commands/task/finish.d.ts.map +1 -1
  131. package/dist/commands/task/finish.js +26 -10
  132. package/dist/commands/task/migrate-doc.command.d.ts.map +1 -1
  133. package/dist/commands/task/migrate-doc.command.js +5 -1
  134. package/dist/commands/task/migrate-doc.d.ts.map +1 -1
  135. package/dist/commands/task/migrate-doc.js +136 -2
  136. package/dist/commands/task/new.d.ts.map +1 -1
  137. package/dist/commands/task/new.js +4 -110
  138. package/dist/commands/task/new.spec.js +3 -3
  139. package/dist/commands/task/plan.d.ts.map +1 -1
  140. package/dist/commands/task/plan.js +5 -4
  141. package/dist/commands/task/scaffold.d.ts.map +1 -1
  142. package/dist/commands/task/scaffold.js +7 -52
  143. package/dist/commands/task/set-status.d.ts.map +1 -1
  144. package/dist/commands/task/set-status.js +2 -2
  145. package/dist/commands/task/shared/dependencies.d.ts +15 -0
  146. package/dist/commands/task/shared/dependencies.d.ts.map +1 -0
  147. package/dist/commands/task/shared/dependencies.js +143 -0
  148. package/dist/commands/task/shared/docs.d.ts +21 -0
  149. package/dist/commands/task/shared/docs.d.ts.map +1 -0
  150. package/dist/commands/task/shared/docs.js +121 -0
  151. package/dist/commands/task/shared/listing.d.ts +20 -0
  152. package/dist/commands/task/shared/listing.d.ts.map +1 -0
  153. package/dist/commands/task/shared/listing.js +127 -0
  154. package/dist/commands/task/shared/tags.d.ts +24 -0
  155. package/dist/commands/task/shared/tags.d.ts.map +1 -0
  156. package/dist/commands/task/shared/tags.js +177 -0
  157. package/dist/commands/task/shared/transitions.d.ts +42 -0
  158. package/dist/commands/task/shared/transitions.d.ts.map +1 -0
  159. package/dist/commands/task/shared/transitions.js +175 -0
  160. package/dist/commands/task/shared.d.ts +5 -106
  161. package/dist/commands/task/shared.d.ts.map +1 -1
  162. package/dist/commands/task/shared.js +5 -681
  163. package/dist/commands/task/start.d.ts.map +1 -1
  164. package/dist/commands/task/start.js +7 -5
  165. package/dist/commands/task/verify-record.d.ts.map +1 -1
  166. package/dist/commands/task/verify-record.js +9 -25
  167. package/dist/commands/task/verify-show.command.d.ts.map +1 -1
  168. package/dist/commands/task/verify-show.command.js +5 -1
  169. package/dist/commands/upgrade/apply.d.ts +44 -0
  170. package/dist/commands/upgrade/apply.d.ts.map +1 -0
  171. package/dist/commands/upgrade/apply.js +180 -0
  172. package/dist/commands/upgrade/report.d.ts +21 -0
  173. package/dist/commands/upgrade/report.d.ts.map +1 -0
  174. package/dist/commands/upgrade/report.js +81 -0
  175. package/dist/commands/upgrade/source.d.ts +35 -0
  176. package/dist/commands/upgrade/source.d.ts.map +1 -0
  177. package/dist/commands/upgrade/source.js +109 -0
  178. package/dist/commands/upgrade/types.d.ts +31 -0
  179. package/dist/commands/upgrade/types.d.ts.map +1 -0
  180. package/dist/commands/upgrade/types.js +1 -0
  181. package/dist/commands/upgrade.command.d.ts.map +1 -1
  182. package/dist/commands/upgrade.command.js +11 -7
  183. package/dist/commands/upgrade.d.ts +1 -35
  184. package/dist/commands/upgrade.d.ts.map +1 -1
  185. package/dist/commands/upgrade.js +54 -320
  186. package/dist/shared/diagnostics.d.ts +23 -0
  187. package/dist/shared/diagnostics.d.ts.map +1 -0
  188. package/dist/shared/diagnostics.js +57 -0
  189. package/dist/shared/errors.d.ts +2 -0
  190. package/dist/shared/errors.d.ts.map +1 -1
  191. package/dist/shared/errors.js +2 -0
  192. package/dist/shared/repo-cli-version.d.ts +13 -0
  193. package/dist/shared/repo-cli-version.d.ts.map +1 -0
  194. package/dist/shared/repo-cli-version.js +63 -0
  195. package/dist/shared/runtime-source.d.ts +33 -0
  196. package/dist/shared/runtime-source.d.ts.map +1 -0
  197. package/dist/shared/runtime-source.js +156 -0
  198. package/dist/shared/version-compare.d.ts +7 -0
  199. package/dist/shared/version-compare.d.ts.map +1 -0
  200. package/dist/shared/version-compare.js +30 -0
  201. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/commands/upgrade/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,CAAC,CAAC;IAClB,KAAK,EAAE,sBAAsB,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;IACnC,cAAc,EAAE,wBAAwB,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;IAClF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;IACxD,WAAW,EAAE,OAAO,CAAC;IACrB,wBAAwB,EAAE,OAAO,GAAG,IAAI,CAAC;IACzC,yBAAyB,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1C,0BAA0B,EAAE,OAAO,CAAC;IACpC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EACL,MAAM,GACN,mBAAmB,GACnB,MAAM,GACN,cAAc,GACd,sBAAsB,GACtB,aAAa,GACb,iBAAiB,CAAC;CACvB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade.command.d.ts","sourceRoot":"","sources":["../../src/commands/upgrade.command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC;AAEzC,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,aAAa,CA2JlD,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,cAAc,CAAC,aAAa,CACsB,CAAC"}
1
+ {"version":3,"file":"upgrade.command.d.ts","sourceRoot":"","sources":["../../src/commands/upgrade.command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC;AAEzC,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,aAAa,CA8JlD,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,cAAc,CAAC,aAAa,CACsB,CAAC"}
@@ -4,19 +4,19 @@ export const upgradeSpec = {
4
4
  id: ["upgrade"],
5
5
  group: "Setup",
6
6
  summary: "Upgrade the local agentplane framework bundle in the repo.",
7
- description: "Upgrades the local agentplane framework bundle in the repo using a strict manifest of managed files. By default, upgrade generates an agent-assisted plan from the locally installed agentplane package assets (no network) and does not modify files. Use --auto to apply changes and create a dedicated upgrade commit. Use --remote to fetch a GitHub release bundle; network access is gated by config approvals.",
7
+ description: "Upgrades the local agentplane framework bundle in the repo using a strict manifest of managed files. By default, upgrade applies the bundled managed files from the locally installed agentplane package assets (no network) and creates a dedicated upgrade commit. Use --dry-run to preview changes without writing files, or --agent to generate a review plan instead of applying. Use --remote to fetch a GitHub release bundle; network access is gated by config approvals.",
8
8
  options: [
9
9
  {
10
10
  kind: "boolean",
11
11
  name: "agent",
12
12
  default: false,
13
- description: "Generate an agent-assisted upgrade plan (no files are modified). This is the default mode.",
13
+ description: "Generate an agent-assisted upgrade plan instead of applying managed files.",
14
14
  },
15
15
  {
16
16
  kind: "boolean",
17
17
  name: "auto",
18
18
  default: false,
19
- description: "Apply the upgrade automatically (writes managed files) and create a dedicated upgrade commit.",
19
+ description: "Apply the upgrade automatically (same behavior as the default mode; useful for explicit scripts).",
20
20
  },
21
21
  {
22
22
  kind: "boolean",
@@ -97,11 +97,15 @@ export const upgradeSpec = {
97
97
  examples: [
98
98
  {
99
99
  cmd: "agentplane upgrade",
100
- why: "Generate an agent-assisted plan using locally installed assets (no network).",
100
+ why: "Apply managed files from the installed CLI assets and create an upgrade commit.",
101
101
  },
102
102
  {
103
- cmd: "agentplane upgrade --auto",
104
- why: "Apply the upgrade automatically (writes managed files).",
103
+ cmd: "agentplane upgrade --dry-run",
104
+ why: "Preview managed-file changes without modifying the repo.",
105
+ },
106
+ {
107
+ cmd: "agentplane upgrade --agent",
108
+ why: "Generate an agent-assisted upgrade plan instead of applying files.",
105
109
  },
106
110
  {
107
111
  cmd: "agentplane upgrade --remote --tag v0.1.9 --dry-run",
@@ -115,7 +119,7 @@ export const upgradeSpec = {
115
119
  parse: (raw) => {
116
120
  const noBackup = raw.opts["no-backup"] === true;
117
121
  return {
118
- mode: raw.opts.auto === true ? "auto" : "agent",
122
+ mode: raw.opts.agent === true ? "agent" : "auto",
119
123
  remote: raw.opts.remote === true,
120
124
  allowTarball: raw.opts["allow-tarball"] === true,
121
125
  source: raw.opts.source,
@@ -12,44 +12,10 @@ export type UpgradeFlags = {
12
12
  backup: boolean;
13
13
  yes: boolean;
14
14
  };
15
- type GitHubRelease = {
16
- tag_name?: string;
17
- assets?: {
18
- name?: string;
19
- browser_download_url?: string;
20
- }[];
21
- tarball_url?: string;
22
- };
23
- export declare function normalizeFrameworkSourceForUpgrade(source: string): {
24
- source: string;
25
- owner: string;
26
- repo: string;
27
- migrated: boolean;
28
- };
29
- export declare function resolveUpgradeDownloadFromRelease(opts: {
30
- release: GitHubRelease;
31
- owner: string;
32
- repo: string;
33
- assetName: string;
34
- checksumName: string;
35
- }): {
36
- kind: "assets";
37
- bundleUrl: string;
38
- checksumUrl: string;
39
- } | {
40
- kind: "tarball";
41
- tarballUrl: string;
42
- };
43
- export declare function resolveRepoTarballUrl(opts: {
44
- release: GitHubRelease;
45
- owner: string;
46
- repo: string;
47
- explicitTag?: string;
48
- }): string;
49
15
  export declare function cmdUpgradeParsed(opts: {
50
16
  cwd: string;
51
17
  rootOverride?: string;
52
18
  flags: UpgradeFlags;
53
19
  }): Promise<number>;
54
- export {};
20
+ export { normalizeFrameworkSourceForUpgrade, resolveRepoTarballUrl, resolveUpgradeDownloadFromRelease, } from "./upgrade/source.js";
55
21
  //# sourceMappingURL=upgrade.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../src/commands/upgrade.ts"],"names":[],"mappings":"AAqCA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAiGF,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,MAAM,GAAG;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB,CAWA;AAED,wBAAgB,iCAAiC,CAAC,IAAI,EAAE;IACtD,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB,GACG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAqB1C;AAUD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,MAAM,CAgBT;AAmRD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,YAAY,CAAC;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CA6oBlB"}
1
+ {"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../src/commands/upgrade.ts"],"names":[],"mappings":"AA2CA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAuMF,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,YAAY,CAAC;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4gBlB;AAED,OAAO,EACL,kCAAkC,EAClC,qBAAqB,EACrB,iCAAiC,GAClC,MAAM,qBAAqB,CAAC"}
@@ -1,50 +1,25 @@
1
- import { lstat, mkdir, mkdtemp, readdir, readFile, readlink, rm, writeFile, } from "node:fs/promises";
1
+ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
- import { loadConfig, resolveProject, saveConfig, setByDottedKey } from "@agentplaneorg/core";
6
- import { backupPath, fileExists, getPathKind } from "../cli/fs-utils.js";
5
+ import { loadConfig, resolveProject } from "@agentplaneorg/core";
6
+ import { fileExists, getPathKind } from "../cli/fs-utils.js";
7
7
  import { downloadToFile, fetchJson } from "../cli/http.js";
8
8
  import { parseSha256Text, sha256File } from "../cli/checksum.js";
9
9
  import { extractArchive } from "../cli/archive.js";
10
- import { invalidFieldMessage, invalidValueMessage, requiredFieldMessage, warnMessage, } from "../cli/output.js";
11
10
  import { exitCodeForError } from "../cli/exit-codes.js";
11
+ import { warnMessage } from "../cli/output.js";
12
12
  import { CliError } from "../shared/errors.js";
13
13
  import { ensureNetworkApproved } from "./shared/network-approval.js";
14
- import { execFileAsync, gitEnv } from "./shared/git.js";
15
14
  import { getVersion } from "../meta/version.js";
15
+ import { applyManagedFiles, cleanupAutoUpgradeArtifacts, createUpgradeCommit, ensureCleanTrackedTreeForUpgrade, persistUpgradeState, } from "./upgrade/apply.js";
16
+ import { printUpgradeDryRun, writeUpgradeAgentReview } from "./upgrade/report.js";
17
+ import { describeUpgradeSource, loadFrameworkManifestFromPath, normalizeFrameworkSourceForUpgrade, resolveRepoTarballUrl, resolveUpgradeDownloadFromRelease, resolveUpgradeRoot, } from "./upgrade/source.js";
16
18
  const DEFAULT_UPGRADE_ASSET = "agentplane-upgrade.tar.gz";
17
19
  const DEFAULT_UPGRADE_CHECKSUM_ASSET = "agentplane-upgrade.tar.gz.sha256";
18
20
  const UPGRADE_DOWNLOAD_TIMEOUT_MS = 60_000;
19
21
  const UPGRADE_RELEASE_METADATA_TIMEOUT_MS = 15_000;
20
- async function safeRemovePath(targetPath) {
21
- try {
22
- await rm(targetPath, { recursive: true, force: true });
23
- }
24
- catch {
25
- // best-effort cleanup
26
- }
27
- }
28
- async function cleanupAutoUpgradeArtifacts(opts) {
29
- for (const backupPath of opts.createdBackups) {
30
- await safeRemovePath(backupPath);
31
- }
32
- // Keep durable state files at .upgrade root; remove transient per-run agent artifacts.
33
- await safeRemovePath(path.join(opts.upgradeStateDir, "agent"));
34
- }
35
22
  const ASSETS_DIR_URL = new URL("../../assets/", import.meta.url);
36
- async function loadFrameworkManifestFromPath(manifestPath) {
37
- const text = await readFile(manifestPath, "utf8");
38
- const parsed = JSON.parse(text);
39
- if (parsed?.schema_version !== 1 || !Array.isArray(parsed?.files)) {
40
- throw new CliError({
41
- exitCode: 3,
42
- code: "E_VALIDATION",
43
- message: "Invalid framework.manifest.json (expected schema_version=1 and files array).",
44
- });
45
- }
46
- return parsed;
47
- }
48
23
  function isDeniedUpgradePath(relPath) {
49
24
  if (relPath === ".agentplane/config.json")
50
25
  return true;
@@ -64,89 +39,6 @@ function isDeniedUpgradePath(relPath) {
64
39
  return true;
65
40
  return false;
66
41
  }
67
- function parseGitHubRepo(source) {
68
- const trimmed = source.trim();
69
- if (!trimmed)
70
- throw new Error(requiredFieldMessage("config.framework.source"));
71
- if (!trimmed.includes("github.com")) {
72
- throw new Error(invalidFieldMessage("config.framework.source", "GitHub URL"));
73
- }
74
- try {
75
- const url = new URL(trimmed);
76
- const parts = url.pathname.replaceAll(".git", "").split("/").filter(Boolean);
77
- if (parts.length < 2)
78
- throw new Error(invalidValueMessage("GitHub repo URL", trimmed, "owner/repo"));
79
- return { owner: parts[0], repo: parts[1] };
80
- }
81
- catch {
82
- throw new Error(invalidValueMessage("GitHub repo URL", trimmed, "owner/repo"));
83
- }
84
- }
85
- export function normalizeFrameworkSourceForUpgrade(source) {
86
- const { owner, repo } = parseGitHubRepo(source);
87
- if (owner === "basilisk-labs" && repo === "agent-plane") {
88
- return {
89
- source: `https://github.com/${owner}/agentplane`,
90
- owner,
91
- repo: "agentplane",
92
- migrated: true,
93
- };
94
- }
95
- return { source: `https://github.com/${owner}/${repo}`, owner, repo, migrated: false };
96
- }
97
- export function resolveUpgradeDownloadFromRelease(opts) {
98
- const assets = Array.isArray(opts.release.assets) ? opts.release.assets : [];
99
- const asset = assets.find((a) => a?.name === opts.assetName);
100
- const checksumAsset = assets.find((a) => a?.name === opts.checksumName);
101
- if (asset?.browser_download_url && checksumAsset?.browser_download_url) {
102
- return {
103
- kind: "assets",
104
- bundleUrl: asset.browser_download_url,
105
- checksumUrl: checksumAsset.browser_download_url,
106
- };
107
- }
108
- const tarballUrl = typeof opts.release.tarball_url === "string" ? opts.release.tarball_url : "";
109
- if (!tarballUrl) {
110
- throw new CliError({
111
- exitCode: exitCodeForError("E_NETWORK"),
112
- code: "E_NETWORK",
113
- message: `Upgrade assets not found in ${opts.owner}/${opts.repo} release`,
114
- });
115
- }
116
- return { kind: "tarball", tarballUrl };
117
- }
118
- function buildCodeloadTarGzUrl(opts) {
119
- // Prefer codeload over api.github.com tarball_url. It is less brittle and does not require
120
- // GitHub API-specific behavior/rate limits.
121
- const tag = opts.tag.trim();
122
- if (!tag)
123
- throw new Error("tag is required");
124
- return `https://codeload.github.com/${opts.owner}/${opts.repo}/tar.gz/${encodeURIComponent(tag)}`;
125
- }
126
- export function resolveRepoTarballUrl(opts) {
127
- const tag = (typeof opts.explicitTag === "string" && opts.explicitTag.trim()) ||
128
- (typeof opts.release.tag_name === "string" && opts.release.tag_name.trim()) ||
129
- "";
130
- if (tag)
131
- return buildCodeloadTarGzUrl({ owner: opts.owner, repo: opts.repo, tag });
132
- const tarballUrl = typeof opts.release.tarball_url === "string" ? opts.release.tarball_url : "";
133
- if (tarballUrl)
134
- return tarballUrl;
135
- throw new CliError({
136
- exitCode: exitCodeForError("E_NETWORK"),
137
- code: "E_NETWORK",
138
- message: "GitHub release did not provide tag_name or tarball_url; cannot fall back to repo tarball.",
139
- });
140
- }
141
- async function resolveUpgradeRoot(extractedDir) {
142
- const entries = await readdir(extractedDir, { withFileTypes: true });
143
- const dirs = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
144
- const files = entries.filter((entry) => entry.isFile()).map((entry) => entry.name);
145
- if (files.length === 0 && dirs.length === 1) {
146
- return path.join(extractedDir, dirs[0]);
147
- }
148
- return extractedDir;
149
- }
150
42
  function isAllowedUpgradePath(relPath) {
151
43
  if (relPath === "AGENTS.md")
152
44
  return true;
@@ -297,73 +189,9 @@ function normalizeUpgradeVersionLabel(input) {
297
189
  return trimmed;
298
190
  return `v${trimmed}`;
299
191
  }
300
- async function ensureCleanTrackedTreeForUpgrade(gitRoot) {
301
- const { stdout } = await execFileAsync("git", ["status", "--short", "--untracked-files=no"], {
302
- cwd: gitRoot,
303
- env: gitEnv(),
304
- maxBuffer: 10 * 1024 * 1024,
305
- });
306
- const dirty = String(stdout ?? "")
307
- .split(/\r?\n/u)
308
- .map((line) => line.trimEnd())
309
- .filter((line) => line.length > 0);
310
- if (dirty.length === 0)
311
- return;
312
- throw new CliError({
313
- exitCode: exitCodeForError("E_GIT"),
314
- code: "E_GIT",
315
- message: "Upgrade --auto requires a clean tracked working tree.\n" +
316
- `Found tracked changes:\n${dirty.map((line) => ` ${line}`).join("\n")}`,
317
- });
318
- }
319
- async function createUpgradeCommit(opts) {
320
- const uniquePaths = [...new Set(opts.paths.filter(Boolean))];
321
- if (uniquePaths.length === 0)
322
- return null;
323
- await execFileAsync("git", ["add", "--", ...uniquePaths], {
324
- cwd: opts.gitRoot,
325
- env: gitEnv(),
326
- maxBuffer: 10 * 1024 * 1024,
327
- });
328
- const { stdout: stagedOut } = await execFileAsync("git", ["diff", "--cached", "--name-only", "-z"], {
329
- cwd: opts.gitRoot,
330
- env: gitEnv(),
331
- encoding: "buffer",
332
- maxBuffer: 10 * 1024 * 1024,
333
- });
334
- const staged = (Buffer.isBuffer(stagedOut) ? stagedOut.toString("utf8") : String(stagedOut ?? ""))
335
- .split("\0")
336
- .map((entry) => entry.trim())
337
- .some(Boolean);
338
- if (!staged)
339
- return null;
340
- const subject = `⬆️ upgrade: apply framework ${opts.versionLabel}`;
341
- const body = `Upgrade-Version: ${opts.versionLabel}\n` +
342
- `Source: ${opts.source}\n` +
343
- `Managed-Changes: add=${opts.additions}, update=${opts.updates}, unchanged=${opts.unchanged}\n` +
344
- `Incidents-Appended: ${opts.incidentsAppendedCount}\n`;
345
- try {
346
- await execFileAsync("git", ["commit", "-m", subject, "-m", body], {
347
- cwd: opts.gitRoot,
348
- env: gitEnv(),
349
- maxBuffer: 10 * 1024 * 1024,
350
- });
351
- }
352
- catch (err) {
353
- const details = err?.stderr ?? "";
354
- throw new CliError({
355
- exitCode: exitCodeForError("E_GIT"),
356
- code: "E_GIT",
357
- message: "Upgrade applied but failed to create the upgrade commit.\n" +
358
- "Fix commit policy/hook issues and commit the staged upgrade files as a dedicated upgrade commit.\n" +
359
- (String(details).trim() ? `Details:\n${String(details).trim()}` : ""),
360
- });
361
- }
362
- const { stdout: hashOut } = await execFileAsync("git", ["rev-parse", "HEAD"], {
363
- cwd: opts.gitRoot,
364
- env: gitEnv(),
365
- });
366
- return { hash: String(hashOut ?? "").trim(), subject };
192
+ function normalizeVersionForConfig(input) {
193
+ const trimmed = input.trim().replace(/^v/i, "");
194
+ return trimmed.length > 0 ? trimmed : null;
367
195
  }
368
196
  export async function cmdUpgradeParsed(opts) {
369
197
  const flags = opts.flags;
@@ -537,6 +365,14 @@ export async function cmdUpgradeParsed(opts) {
537
365
  ? fileURLToPath(new URL("../../assets/framework.manifest.json", import.meta.url))
538
366
  : path.join(bundleRoot, "framework.manifest.json");
539
367
  const manifest = await loadFrameworkManifestFromPath(manifestPath);
368
+ const modeLabel = flags.dryRun ? "dry-run" : flags.mode === "agent" ? "review" : "apply";
369
+ process.stdout.write(`Upgrade source: ${describeUpgradeSource({
370
+ bundleLayout,
371
+ hasExplicitBundle: hasBundle,
372
+ useRemote,
373
+ })}\n` +
374
+ `Upgrade version: ${upgradeVersionLabel}\n` +
375
+ `Upgrade mode: ${modeLabel}\n`);
540
376
  const additions = [];
541
377
  const updates = [];
542
378
  const skipped = [];
@@ -752,15 +588,7 @@ export async function cmdUpgradeParsed(opts) {
752
588
  });
753
589
  }
754
590
  if (flags.dryRun) {
755
- process.stdout.write(`Upgrade dry-run: ${additions.length} add, ${updates.length} update, ${skipped.length} unchanged\n`);
756
- for (const rel of additions)
757
- process.stdout.write(`ADD ${rel}\n`);
758
- for (const rel of updates)
759
- process.stdout.write(`UPDATE ${rel}\n`);
760
- for (const rel of skipped)
761
- process.stdout.write(`SKIP ${rel}\n`);
762
- for (const rel of merged)
763
- process.stdout.write(`MERGE ${rel}\n`);
591
+ printUpgradeDryRun({ additions, updates, skipped, merged });
764
592
  return 0;
765
593
  }
766
594
  const needsReview = reviewRecords.filter((r) => r.needsSemanticReview);
@@ -771,140 +599,45 @@ export async function cmdUpgradeParsed(opts) {
771
599
  process.stdout.write("Upgrade plan: no managed changes detected\n");
772
600
  return 0;
773
601
  }
774
- const agentDir = path.join(upgradeStateDir, "agent");
775
- const runId = new Date().toISOString().replaceAll(":", "-").replaceAll(".", "-");
776
- const runDir = path.join(agentDir, runId);
777
- await mkdir(runDir, { recursive: true });
778
- const managedFiles = manifest.files.map((f) => f.path.replaceAll("\\", "/").trim());
779
- const planMd = `# agentplane upgrade plan (${runId})\n\n` +
780
- `Mode: agent-assisted (no files modified)\n\n` +
781
- `## Summary\n\n` +
782
- `- additions: ${additions.length}\n` +
783
- `- updates: ${updates.length}\n` +
784
- `- unchanged: ${skipped.length}\n` +
785
- `- merged (auto-safe transforms already applied to incoming): ${merged.length}\n\n` +
786
- `## Managed files (manifest)\n\n` +
787
- managedFiles.map((p) => `- ${p}`).join("\n") +
788
- `\n\n` +
789
- `## Proposed changes\n\n` +
790
- additions.map((p) => `- ADD ${p}`).join("\n") +
791
- (additions.length > 0 ? "\n" : "") +
792
- updates.map((p) => `- UPDATE ${p}`).join("\n") +
793
- (updates.length > 0 ? "\n" : "") +
794
- merged.map((p) => `- MERGE ${p}`).join("\n") +
795
- (merged.length > 0 ? "\n" : "") +
796
- skipped.map((p) => `- SKIP ${p}`).join("\n") +
797
- (skipped.length > 0 ? "\n" : "") +
798
- `\n` +
799
- `## Next steps\n\n` +
800
- `1. Review the proposed changes list.\n` +
801
- `2. Apply changes manually or re-run with \`agentplane upgrade --auto\` to apply managed files.\n` +
802
- `3. Run \`agentplane doctor\` (or \`agentplane doctor --fix\`) and ensure checks pass.\n`;
803
- const constraintsMd = `# Upgrade constraints\n\n` +
804
- `This upgrade is restricted to framework-managed files only.\n\n` +
805
- `## Must not touch\n\n` +
806
- `- .agentplane/tasks/** (task data)\n` +
807
- `- .agentplane/tasks.json (export snapshot)\n` +
808
- `- .agentplane/backends/** (backend configuration)\n` +
809
- `- .agentplane/config.json (project config)\n` +
810
- `- .git/**\n\n` +
811
- `## Notes\n\n` +
812
- `- The upgrade bundle is validated against framework.manifest.json.\n` +
813
- `- The policy gateway file at workspace root is AGENTS.md or CLAUDE.md.\n`;
814
- const reportMd = `# Upgrade report (${runId})\n\n` +
815
- `## Actions taken\n\n` +
816
- `- [ ] Reviewed plan.md\n` +
817
- `- [ ] Applied changes (manual or --auto)\n` +
818
- `- [ ] Ran doctor\n` +
819
- `- [ ] Ran tests / lint\n\n` +
820
- `## Notes\n\n` +
821
- `- \n`;
822
- await writeFile(path.join(runDir, "plan.md"), planMd, "utf8");
823
- await writeFile(path.join(runDir, "constraints.md"), constraintsMd, "utf8");
824
- await writeFile(path.join(runDir, "report.md"), reportMd, "utf8");
825
- await writeFile(path.join(runDir, "files.json"), JSON.stringify({ additions, updates, skipped, merged }, null, 2) + "\n", "utf8");
826
- await writeFile(path.join(runDir, "review.json"), JSON.stringify({
827
- generated_at: new Date().toISOString(),
828
- counts: {
829
- total: reviewRecords.length,
830
- needsSemanticReview: needsReview.length,
831
- },
832
- files: reviewRecords,
833
- }, null, 2) + "\n", "utf8");
834
- const relRunDir = path.relative(resolved.gitRoot, runDir);
602
+ const { relRunDir, needsReviewCount } = await writeUpgradeAgentReview({
603
+ gitRoot: resolved.gitRoot,
604
+ runRoot: path.join(upgradeStateDir, "agent"),
605
+ manifest,
606
+ additions,
607
+ updates,
608
+ skipped,
609
+ merged,
610
+ reviewRecords,
611
+ });
835
612
  process.stdout.write(`Upgrade plan written: ${relRunDir}\n`);
836
- process.stdout.write(`Review-required files: ${needsReview.length}\n`);
613
+ process.stdout.write(`Review-required files: ${needsReviewCount}\n`);
837
614
  return 0;
838
615
  }
839
- for (const rel of [...additions, ...updates]) {
840
- const destPath = path.join(resolved.gitRoot, rel);
841
- if (flags.backup && (await fileExists(destPath))) {
842
- const backup = await backupPath(destPath);
843
- createdBackups.push(backup);
844
- }
845
- await mkdir(path.dirname(destPath), { recursive: true });
846
- const data = fileContents.get(rel);
847
- if (data) {
848
- if (rel === "AGENTS.md" || rel === "CLAUDE.md") {
849
- // If policy gateway file is a symlink, avoid overwriting an arbitrary external target.
850
- // This permits repo-internal symlinks (e.g. the agentplane repo itself) while
851
- // keeping user workspaces safe.
852
- try {
853
- const st = await lstat(destPath);
854
- if (st.isSymbolicLink()) {
855
- const linkTarget = await readlink(destPath);
856
- const targetAbs = path.resolve(path.dirname(destPath), linkTarget);
857
- const relFromRoot = path.relative(resolved.gitRoot, targetAbs);
858
- if (relFromRoot.startsWith("..") || path.isAbsolute(relFromRoot)) {
859
- throw new CliError({
860
- exitCode: exitCodeForError("E_VALIDATION"),
861
- code: "E_VALIDATION",
862
- message: `Refusing to overwrite symlinked ${rel} target outside repo: ${linkTarget}. ` +
863
- "Replace the symlink with a regular file and retry.",
864
- });
865
- }
866
- }
867
- }
868
- catch (err) {
869
- const code = err?.code;
870
- if (code !== "ENOENT")
871
- throw err;
872
- }
873
- }
874
- await writeFile(destPath, data);
875
- }
876
- // Record a baseline copy for future three-way merges.
877
- const baselineKey = toBaselineKey(rel);
878
- if (baselineKey && data) {
879
- const baselinePath = path.join(baselineDirNew, baselineKey);
880
- await mkdir(path.dirname(baselinePath), { recursive: true });
881
- await writeFile(baselinePath, data);
882
- }
883
- }
616
+ await applyManagedFiles({
617
+ gitRoot: resolved.gitRoot,
618
+ additions,
619
+ updates,
620
+ backup: flags.backup,
621
+ fileContents,
622
+ baselineDir: baselineDirNew,
623
+ createdBackups,
624
+ toBaselineKey,
625
+ });
884
626
  const hasManagedMutations = additions.length > 0 || updates.length > 0;
885
- const hasSourceMigration = normalizedSourceToPersist !== null;
886
- const shouldMutateConfig = hasManagedMutations || hasSourceMigration;
887
- if (shouldMutateConfig) {
888
- const raw = { ...loaded.raw };
889
- if (normalizedSourceToPersist) {
890
- setByDottedKey(raw, "framework.source", normalizedSourceToPersist);
891
- }
892
- setByDottedKey(raw, "framework.last_update", new Date().toISOString());
893
- await saveConfig(resolved.agentplaneDir, raw);
894
- }
895
- await writeFile(statePath, JSON.stringify({
896
- applied_at: new Date().toISOString(),
627
+ const shouldMutateConfig = await persistUpgradeState({
628
+ agentplaneDir: resolved.agentplaneDir,
629
+ rawConfig: loaded.raw,
630
+ normalizedSourceToPersist,
631
+ expectedCliVersionToPersist: normalizeVersionForConfig(upgradeVersionLabel),
632
+ hasManagedMutations,
633
+ statePath,
634
+ upgradeStateDir,
897
635
  source: bundleLayout,
898
- updated: { add: additions.length, update: updates.length, unchanged: skipped.length },
899
- }, null, 2) + "\n", "utf8");
900
- await writeFile(path.join(upgradeStateDir, "last-review.json"), JSON.stringify({
901
- generated_at: new Date().toISOString(),
902
- counts: {
903
- total: reviewRecords.length,
904
- needsSemanticReview: reviewRecords.filter((r) => r.needsSemanticReview).length,
905
- },
906
- files: reviewRecords,
907
- }, null, 2) + "\n", "utf8");
636
+ reviewRecords,
637
+ additions: additions.length,
638
+ updates: updates.length,
639
+ skipped: skipped.length,
640
+ });
908
641
  const commitPaths = [
909
642
  ...new Set([...additions, ...updates, ...(shouldMutateConfig ? [CONFIG_REL_PATH] : [])]),
910
643
  ];
@@ -940,3 +673,4 @@ export async function cmdUpgradeParsed(opts) {
940
673
  }
941
674
  }
942
675
  }
676
+ export { normalizeFrameworkSourceForUpgrade, resolveRepoTarballUrl, resolveUpgradeDownloadFromRelease, } from "./upgrade/source.js";
@@ -0,0 +1,23 @@
1
+ export type DiagnosticNextAction = {
2
+ command: string;
3
+ reason: string;
4
+ reasonCode?: string;
5
+ };
6
+ export type DiagnosticInfo = {
7
+ state: string;
8
+ likelyCause: string;
9
+ nextAction?: DiagnosticNextAction;
10
+ hint?: string;
11
+ };
12
+ type DiagnosticContextRecord = Record<string, unknown>;
13
+ export declare function withDiagnosticContext(context: DiagnosticContextRecord | undefined, diagnostic: DiagnosticInfo): DiagnosticContextRecord;
14
+ export declare function readDiagnosticContext(context: DiagnosticContextRecord | undefined): Partial<DiagnosticInfo>;
15
+ export declare function renderDiagnosticFinding(opts: {
16
+ severity: "ERROR" | "WARN" | "INFO";
17
+ state: string;
18
+ likelyCause: string;
19
+ nextAction?: DiagnosticNextAction;
20
+ details?: string[];
21
+ }): string;
22
+ export {};
23
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/shared/diagnostics.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAMvD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,uBAAuB,GAAG,SAAS,EAC5C,UAAU,EAAE,cAAc,GACzB,uBAAuB,CAiBzB;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,uBAAuB,GAAG,SAAS,GAC3C,OAAO,CAAC,cAAc,CAAC,CAqBzB;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,GAAG,MAAM,CAaT"}
@@ -0,0 +1,57 @@
1
+ function readString(value) {
2
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
3
+ }
4
+ export function withDiagnosticContext(context, diagnostic) {
5
+ const base = context ? { ...context } : {};
6
+ return {
7
+ ...base,
8
+ diagnostic_state: diagnostic.state,
9
+ diagnostic_likely_cause: diagnostic.likelyCause,
10
+ ...(diagnostic.hint ? { diagnostic_hint: diagnostic.hint } : {}),
11
+ ...(diagnostic.nextAction
12
+ ? {
13
+ diagnostic_next_action_command: diagnostic.nextAction.command,
14
+ diagnostic_next_action_reason: diagnostic.nextAction.reason,
15
+ ...(diagnostic.nextAction.reasonCode
16
+ ? { diagnostic_next_action_reason_code: diagnostic.nextAction.reasonCode }
17
+ : {}),
18
+ }
19
+ : {}),
20
+ };
21
+ }
22
+ export function readDiagnosticContext(context) {
23
+ const state = readString(context?.diagnostic_state);
24
+ const likelyCause = readString(context?.diagnostic_likely_cause);
25
+ const hint = readString(context?.diagnostic_hint);
26
+ const nextActionCommand = readString(context?.diagnostic_next_action_command);
27
+ const nextActionReason = readString(context?.diagnostic_next_action_reason);
28
+ const nextActionReasonCode = readString(context?.diagnostic_next_action_reason_code);
29
+ return {
30
+ state,
31
+ likelyCause,
32
+ hint,
33
+ nextAction: nextActionCommand && nextActionReason
34
+ ? {
35
+ command: nextActionCommand,
36
+ reason: nextActionReason,
37
+ ...(nextActionReasonCode ? { reasonCode: nextActionReasonCode } : {}),
38
+ }
39
+ : undefined,
40
+ };
41
+ }
42
+ export function renderDiagnosticFinding(opts) {
43
+ const lines = [`[${opts.severity}] State: ${opts.state}`, `Likely cause: ${opts.likelyCause}`];
44
+ if (opts.nextAction) {
45
+ lines.push(`Next action: ${opts.nextAction.command} (${opts.nextAction.reason})`);
46
+ }
47
+ if (Array.isArray(opts.details) && opts.details.length > 0) {
48
+ const [first, ...rest] = opts.details;
49
+ if (first)
50
+ lines.push(`Details: ${first}`);
51
+ for (const detail of rest) {
52
+ if (detail.trim())
53
+ lines.push(` - ${detail}`);
54
+ }
55
+ }
56
+ return lines.join("\n");
57
+ }
@@ -11,6 +11,8 @@ export declare class CliError extends Error {
11
11
  });
12
12
  }
13
13
  export type JsonErrorGuidance = {
14
+ state?: string;
15
+ likelyCause?: string;
14
16
  hint?: string;
15
17
  nextAction?: {
16
18
  command: string;