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,180 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ import { readDiagnosticContext } from "../../shared/diagnostics.js";
4
+ import { formatJsonError } from "../../shared/errors.js";
5
+ import { getReasonCodeMeta } from "../reason-codes.js";
6
+ export function writeError(err, jsonErrors) {
7
+ const guidance = resolveErrorGuidance(err);
8
+ const contextReasonCode = typeof err.context?.reason_code === "string" ? String(err.context.reason_code) : undefined;
9
+ const reasonCode = contextReasonCode ?? guidance.nextAction?.reasonCode;
10
+ const reasonDecode = getReasonCodeMeta(reasonCode);
11
+ if (jsonErrors) {
12
+ process.stdout.write(`${formatJsonError(err, {
13
+ state: guidance.state,
14
+ likelyCause: guidance.likelyCause,
15
+ hint: guidance.hint,
16
+ nextAction: guidance.nextAction,
17
+ reasonDecode,
18
+ })}\n`);
19
+ }
20
+ else {
21
+ const header = `error [${err.code}]`;
22
+ if (err.message.includes("\n")) {
23
+ process.stderr.write(`${header}\n${err.message}\n`);
24
+ }
25
+ else {
26
+ process.stderr.write(`${header}: ${err.message}\n`);
27
+ }
28
+ if (guidance.state) {
29
+ process.stderr.write(`state: ${guidance.state}\n`);
30
+ }
31
+ if (guidance.likelyCause) {
32
+ process.stderr.write(`likely_cause: ${guidance.likelyCause}\n`);
33
+ }
34
+ if (guidance.hint) {
35
+ process.stderr.write(`hint: ${guidance.hint}\n`);
36
+ }
37
+ if (guidance.nextAction) {
38
+ process.stderr.write(`next_action: ${guidance.nextAction.command} (${guidance.nextAction.reason})\n`);
39
+ }
40
+ if (reasonDecode) {
41
+ process.stderr.write(`reason_code: ${reasonDecode.code} [${reasonDecode.category}] ${reasonDecode.summary}\n`);
42
+ process.stderr.write(`reason_action: ${reasonDecode.action}\n`);
43
+ }
44
+ }
45
+ }
46
+ const AGENTPLANE_HOME_ENV = "AGENTPLANE_HOME";
47
+ export function resolveAgentplaneHome() {
48
+ const overridden = process.env[AGENTPLANE_HOME_ENV]?.trim();
49
+ if (overridden)
50
+ return overridden;
51
+ return path.join(os.homedir(), ".agentplane");
52
+ }
53
+ function resolveErrorGuidance(err) {
54
+ const explicit = readDiagnosticContext(err.context);
55
+ const command = typeof err.context?.command === "string" ? err.context.command : undefined;
56
+ const reasonCode = typeof err.context?.reason_code === "string" ? String(err.context.reason_code) : undefined;
57
+ const usage = command ? `agentplane help ${command} --compact` : "agentplane help";
58
+ const withExplicit = (fallback) => ({
59
+ state: explicit.state ?? fallback.state,
60
+ likelyCause: explicit.likelyCause ?? fallback.likelyCause,
61
+ hint: explicit.hint ?? fallback.hint,
62
+ nextAction: explicit.nextAction ?? fallback.nextAction,
63
+ });
64
+ switch (err.code) {
65
+ case "E_USAGE": {
66
+ if (reasonCode === "sync_backend_mismatch") {
67
+ return withExplicit({
68
+ hint: "Configured backend id mismatch. Check active backend and retry with a matching id.",
69
+ nextAction: {
70
+ command: "agentplane config show",
71
+ reason: "inspect active backend id before running sync",
72
+ reasonCode: "sync_backend_mismatch",
73
+ },
74
+ });
75
+ }
76
+ return withExplicit({
77
+ hint: `See \`${usage}\` for usage.`,
78
+ nextAction: {
79
+ command: usage,
80
+ reason: "inspect required arguments and flags",
81
+ reasonCode: "usage_help",
82
+ },
83
+ });
84
+ }
85
+ case "E_GIT": {
86
+ if (reasonCode === "reconcile_git_state_unreadable") {
87
+ return withExplicit({
88
+ hint: "Reconcile check could not read git state.",
89
+ nextAction: {
90
+ command: "git status --short --untracked-files=no",
91
+ reason: "confirm repository state is readable before mutating commands",
92
+ reasonCode: "reconcile_git_state_unreadable",
93
+ },
94
+ });
95
+ }
96
+ if (command?.startsWith("branch")) {
97
+ return withExplicit({
98
+ hint: "Check git repo/branch; run `git branch` or pass --root <path>.",
99
+ nextAction: {
100
+ command: "git branch",
101
+ reason: "inspect repository branch state",
102
+ reasonCode: "git_branch_state",
103
+ },
104
+ });
105
+ }
106
+ if (command === "guard commit" || command === "commit") {
107
+ return withExplicit({
108
+ hint: "Check git status/index; stage changes and retry.",
109
+ nextAction: {
110
+ command: "git status --short",
111
+ reason: "inspect staged/unstaged changes before commit",
112
+ reasonCode: "git_index_state",
113
+ },
114
+ });
115
+ }
116
+ return withExplicit({
117
+ hint: "Check git repo context; pass --root <path> if needed.",
118
+ nextAction: {
119
+ command: "git status --short --untracked-files=no",
120
+ reason: "confirm repository context and tracked changes",
121
+ reasonCode: "git_context",
122
+ },
123
+ });
124
+ }
125
+ case "E_NETWORK": {
126
+ return withExplicit({
127
+ hint: "Check network access and credentials.",
128
+ nextAction: {
129
+ command: "agentplane preflight --json",
130
+ reason: "recheck approvals and network requirements",
131
+ reasonCode: "network_gate",
132
+ },
133
+ });
134
+ }
135
+ case "E_BACKEND": {
136
+ if (command?.includes("sync")) {
137
+ return withExplicit({
138
+ hint: "Check backend config under .agentplane/backends and retry.",
139
+ nextAction: {
140
+ command: "agentplane config show",
141
+ reason: "verify backend config path and active settings",
142
+ reasonCode: "backend_sync_config",
143
+ },
144
+ });
145
+ }
146
+ return withExplicit({
147
+ hint: "Check backend config under .agentplane/backends.",
148
+ nextAction: {
149
+ command: "agentplane config show",
150
+ reason: "inspect backend configuration",
151
+ reasonCode: "backend_config",
152
+ },
153
+ });
154
+ }
155
+ case "E_VALIDATION": {
156
+ if (reasonCode === "reconcile_task_scan_failed" ||
157
+ reasonCode === "reconcile_task_scan_incomplete") {
158
+ return withExplicit({
159
+ hint: "Reconcile check failed due to task scan drift or parse/read errors.",
160
+ nextAction: {
161
+ command: "agentplane task list --strict-read",
162
+ reason: "surface task scan/read failures before retrying mutating commands",
163
+ reasonCode,
164
+ },
165
+ });
166
+ }
167
+ return withExplicit({
168
+ hint: "Fix invalid config/input shape and rerun.",
169
+ nextAction: {
170
+ command: "agentplane preflight --json",
171
+ reason: "pinpoint validation failure in one report",
172
+ reasonCode: "validation_preflight",
173
+ },
174
+ });
175
+ }
176
+ default: {
177
+ return withExplicit({});
178
+ }
179
+ }
180
+ }
@@ -0,0 +1,22 @@
1
+ export type ParsedArgs = {
2
+ help: boolean;
3
+ version: boolean;
4
+ noUpdateCheck: boolean;
5
+ root?: string;
6
+ jsonErrors: boolean;
7
+ allowNetwork: boolean;
8
+ outputMode?: "text" | "json";
9
+ };
10
+ export type CliOutputMode = "text" | "json";
11
+ export declare function prescanJsonErrors(argv: readonly string[]): boolean;
12
+ export declare function parseGlobalArgs(argv: string[]): {
13
+ globals: ParsedArgs;
14
+ rest: string[];
15
+ };
16
+ export declare function resolveOutputMode(modeFromFlag: "text" | "json" | undefined): CliOutputMode;
17
+ export declare function runWithOutputMode(opts: {
18
+ mode: CliOutputMode;
19
+ command: string;
20
+ run: () => Promise<number>;
21
+ }): Promise<number>;
22
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../../src/cli/run-cli/globals.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9B,CAAC;AAgCF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAG5C,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAsBlE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CA0FvF;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,aAAa,CAU1F;AAQD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5B,GAAG,OAAO,CAAC,MAAM,CAAC,CAyDlB"}
@@ -0,0 +1,197 @@
1
+ import { CliError } from "../../shared/errors.js";
2
+ const GLOBAL_FLAGS = [
3
+ { key: "help", forms: ["--help", "-h"], takesValue: false, scoped: false },
4
+ { key: "version", forms: ["--version", "-v"], takesValue: false, scoped: false },
5
+ { key: "noUpdateCheck", forms: ["--no-update-check"], takesValue: false, scoped: false },
6
+ { key: "allowNetwork", forms: ["--allow-network"], takesValue: false, scoped: true },
7
+ { key: "jsonErrors", forms: ["--json-errors"], takesValue: false, scoped: true },
8
+ { key: "outputMode", forms: ["--output"], takesValue: true, scoped: false },
9
+ { key: "root", forms: ["--root"], takesValue: true, scoped: false },
10
+ ];
11
+ const GLOBAL_FLAG_FORMS = new Map(GLOBAL_FLAGS.flatMap((def) => def.forms.map((form) => [form, def])));
12
+ const OUTPUT_MODE_ENV = "AGENTPLANE_OUTPUT";
13
+ export function prescanJsonErrors(argv) {
14
+ // If parseGlobalArgs throws (e.g. missing --root value), we still want to honor
15
+ // `--json-errors` in the "scoped global" zone (before the command id).
16
+ let hasRest = false;
17
+ for (let i = 0; i < argv.length; i++) {
18
+ const arg = argv[i];
19
+ if (!arg)
20
+ continue;
21
+ const def = GLOBAL_FLAG_FORMS.get(arg);
22
+ if (!def) {
23
+ // First non-global token is treated as the start of the command id.
24
+ hasRest = true;
25
+ break;
26
+ }
27
+ if (def.key === "jsonErrors" && !hasRest)
28
+ return true;
29
+ if (def.takesValue) {
30
+ // Skip the value if present; do not throw on missing value here.
31
+ i++;
32
+ }
33
+ }
34
+ return false;
35
+ }
36
+ export function parseGlobalArgs(argv) {
37
+ let help = false;
38
+ let version = false;
39
+ let noUpdateCheck = false;
40
+ let jsonErrors = false;
41
+ let root;
42
+ let allowNetwork = false;
43
+ let outputMode;
44
+ const rest = [];
45
+ for (let i = 0; i < argv.length; i++) {
46
+ const arg = argv[i];
47
+ if (!arg)
48
+ continue;
49
+ const def = GLOBAL_FLAG_FORMS.get(arg);
50
+ if (!def) {
51
+ rest.push(arg);
52
+ continue;
53
+ }
54
+ if (def.scoped && rest.length > 0) {
55
+ rest.push(arg);
56
+ continue;
57
+ }
58
+ switch (def.key) {
59
+ case "help": {
60
+ help = true;
61
+ break;
62
+ }
63
+ case "version": {
64
+ version = true;
65
+ break;
66
+ }
67
+ case "noUpdateCheck": {
68
+ noUpdateCheck = true;
69
+ break;
70
+ }
71
+ case "allowNetwork": {
72
+ allowNetwork = true;
73
+ break;
74
+ }
75
+ case "jsonErrors": {
76
+ jsonErrors = true;
77
+ break;
78
+ }
79
+ case "root": {
80
+ const next = argv[i + 1];
81
+ if (!next) {
82
+ throw new CliError({
83
+ exitCode: 2,
84
+ code: "E_USAGE",
85
+ message: "Missing value after --root (expected repository path)",
86
+ });
87
+ }
88
+ root = next;
89
+ i++;
90
+ break;
91
+ }
92
+ case "outputMode": {
93
+ const next = argv[i + 1];
94
+ if (!next) {
95
+ throw new CliError({
96
+ exitCode: 2,
97
+ code: "E_USAGE",
98
+ message: "Missing value after --output (expected text|json)",
99
+ });
100
+ }
101
+ const normalized = next.trim().toLowerCase();
102
+ if (normalized !== "text" && normalized !== "json") {
103
+ throw new CliError({
104
+ exitCode: 2,
105
+ code: "E_USAGE",
106
+ message: `Invalid value for --output: ${next} (expected text|json)`,
107
+ });
108
+ }
109
+ outputMode = normalized;
110
+ i++;
111
+ break;
112
+ }
113
+ default: {
114
+ rest.push(arg);
115
+ break;
116
+ }
117
+ }
118
+ }
119
+ return {
120
+ globals: { help, version, noUpdateCheck, root, jsonErrors, allowNetwork, outputMode },
121
+ rest,
122
+ };
123
+ }
124
+ export function resolveOutputMode(modeFromFlag) {
125
+ if (modeFromFlag)
126
+ return modeFromFlag;
127
+ const fromEnv = process.env[OUTPUT_MODE_ENV]?.trim().toLowerCase();
128
+ if (!fromEnv || fromEnv === "text")
129
+ return "text";
130
+ if (fromEnv === "json")
131
+ return "json";
132
+ throw new CliError({
133
+ exitCode: 2,
134
+ code: "E_USAGE",
135
+ message: `Invalid ${OUTPUT_MODE_ENV}: ${fromEnv} (expected text|json)`,
136
+ });
137
+ }
138
+ function chunkToString(chunk, encoding) {
139
+ if (typeof chunk === "string")
140
+ return chunk;
141
+ if (chunk instanceof Uint8Array)
142
+ return Buffer.from(chunk).toString(encoding);
143
+ return String(chunk);
144
+ }
145
+ export async function runWithOutputMode(opts) {
146
+ if (opts.mode === "text")
147
+ return await opts.run();
148
+ const stdoutWrite = process.stdout.write.bind(process.stdout);
149
+ const stderrWrite = process.stderr.write.bind(process.stderr);
150
+ let stdout = "";
151
+ let stderr = "";
152
+ process.stdout.write = ((chunk, ...rest) => {
153
+ const encoding = typeof rest[0] === "string" ? rest[0] : undefined;
154
+ stdout += chunkToString(chunk, encoding);
155
+ const callback = rest.find((item) => typeof item === "function");
156
+ callback?.(null);
157
+ return true;
158
+ });
159
+ process.stderr.write = ((chunk, ...rest) => {
160
+ const encoding = typeof rest[0] === "string" ? rest[0] : undefined;
161
+ stderr += chunkToString(chunk, encoding);
162
+ const callback = rest.find((item) => typeof item === "function");
163
+ callback?.(null);
164
+ return true;
165
+ });
166
+ try {
167
+ const exitCode = await opts.run();
168
+ let parsed;
169
+ const trimmedStdout = stdout.trim();
170
+ if (trimmedStdout.length > 0) {
171
+ try {
172
+ parsed = JSON.parse(trimmedStdout);
173
+ }
174
+ catch {
175
+ parsed = undefined;
176
+ }
177
+ }
178
+ const payload = {
179
+ schema_version: 1,
180
+ mode: "agent_json_v1",
181
+ command: opts.command,
182
+ ok: exitCode === 0,
183
+ exit_code: exitCode,
184
+ stdout: trimmedStdout,
185
+ stderr: stderr.trim(),
186
+ };
187
+ if (parsed !== undefined) {
188
+ payload.data = parsed;
189
+ }
190
+ stdoutWrite(`${JSON.stringify(payload, null, 2)}\n`);
191
+ return exitCode;
192
+ }
193
+ finally {
194
+ process.stdout.write = stdoutWrite;
195
+ process.stderr.write = stderrWrite;
196
+ }
197
+ }
@@ -0,0 +1,6 @@
1
+ export declare function maybeWarnOnUpdate(opts: {
2
+ currentVersion: string;
3
+ skip: boolean;
4
+ jsonErrors: boolean;
5
+ }): Promise<void>;
6
+ //# sourceMappingURL=update-warning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-warning.d.ts","sourceRoot":"","sources":["../../../src/cli/run-cli/update-warning.ts"],"names":[],"mappings":"AAwBA,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoDhB"}
@@ -0,0 +1,64 @@
1
+ import { warnMessage } from "../output.js";
2
+ import { fetchLatestNpmVersion, readUpdateCheckCache, resolveUpdateCheckCachePath, shouldCheckNow, UPDATE_CHECK_SCHEMA_VERSION, UPDATE_CHECK_TIMEOUT_MS, UPDATE_CHECK_TTL_MS, writeUpdateCheckCache, } from "../update-check.js";
3
+ import { resolveAgentplaneHome } from "./error-guidance.js";
4
+ import { compareVersions } from "../../shared/version-compare.js";
5
+ const UPDATE_CHECK_PACKAGE = "agentplane";
6
+ const UPDATE_CHECK_URL = `https://registry.npmjs.org/${UPDATE_CHECK_PACKAGE}/latest`;
7
+ function isTruthyEnv(value) {
8
+ if (!value)
9
+ return false;
10
+ const normalized = value.trim().toLowerCase();
11
+ return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
12
+ }
13
+ export async function maybeWarnOnUpdate(opts) {
14
+ if (opts.skip || opts.jsonErrors)
15
+ return;
16
+ if (isTruthyEnv(process.env.AGENTPLANE_NO_UPDATE_CHECK))
17
+ return;
18
+ const now = new Date();
19
+ const cachePath = resolveUpdateCheckCachePath(resolveAgentplaneHome());
20
+ const cache = await readUpdateCheckCache(cachePath);
21
+ if (cache && !shouldCheckNow(cache.checked_at, now, UPDATE_CHECK_TTL_MS)) {
22
+ if (cache.status === "ok" &&
23
+ cache.latest_version &&
24
+ compareVersions(cache.latest_version, opts.currentVersion) > 0) {
25
+ const message = `Update available: ${UPDATE_CHECK_PACKAGE} ${opts.currentVersion} → ${cache.latest_version}. Run: npm i -g ${UPDATE_CHECK_PACKAGE}@latest`;
26
+ process.stderr.write(`${warnMessage(message)}\n`);
27
+ }
28
+ return;
29
+ }
30
+ const result = await fetchLatestNpmVersion({
31
+ url: UPDATE_CHECK_URL,
32
+ timeoutMs: UPDATE_CHECK_TIMEOUT_MS,
33
+ etag: cache?.etag ?? null,
34
+ });
35
+ const nextCache = {
36
+ schema_version: UPDATE_CHECK_SCHEMA_VERSION,
37
+ checked_at: now.toISOString(),
38
+ latest_version: cache?.latest_version ?? null,
39
+ etag: cache?.etag ?? null,
40
+ status: "error",
41
+ };
42
+ if (result.status === "ok") {
43
+ nextCache.status = "ok";
44
+ nextCache.latest_version = result.latestVersion;
45
+ nextCache.etag = result.etag;
46
+ }
47
+ else if (result.status === "not_modified") {
48
+ nextCache.status = "not_modified";
49
+ nextCache.etag = result.etag ?? nextCache.etag;
50
+ }
51
+ try {
52
+ await writeUpdateCheckCache(cachePath, nextCache);
53
+ }
54
+ catch {
55
+ // Best-effort cache: ignore write failures.
56
+ }
57
+ const latest = result.status === "ok" ? result.latestVersion : nextCache.latest_version;
58
+ if (!latest || result.status === "error")
59
+ return;
60
+ if (compareVersions(latest, opts.currentVersion) <= 0)
61
+ return;
62
+ const message = `Update available: ${UPDATE_CHECK_PACKAGE} ${opts.currentVersion} → ${latest}. Run: npm i -g ${UPDATE_CHECK_PACKAGE}@latest`;
63
+ process.stderr.write(`${warnMessage(message)}\n`);
64
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"run-cli.d.ts","sourceRoot":"","sources":["../../src/cli/run-cli.ts"],"names":[],"mappings":"AA0lBA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA6N5D"}
1
+ {"version":3,"file":"run-cli.d.ts","sourceRoot":"","sources":["../../src/cli/run-cli.ts"],"names":[],"mappings":"AAqDA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA6N5D"}