@agent-native/core 0.91.2 → 0.92.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 (216) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +17 -0
  3. package/corpus/core/docs/content/faq.mdx +17 -0
  4. package/corpus/core/docs/content/notifications.mdx +12 -6
  5. package/corpus/core/package.json +1 -1
  6. package/corpus/core/src/agent/production-agent.ts +140 -46
  7. package/corpus/core/src/agent/tool-search.ts +71 -4
  8. package/corpus/core/src/cli/index.ts +20 -0
  9. package/corpus/core/src/cli/upgrade.ts +798 -0
  10. package/corpus/core/src/client/AssistantChat.tsx +1 -1
  11. package/corpus/core/src/client/HighlightedCodeBlock.tsx +20 -3
  12. package/corpus/core/src/client/agent-chat-adapter.ts +31 -6
  13. package/corpus/core/src/client/chat/message-components.tsx +85 -8
  14. package/corpus/core/src/client/chat/tool-call-display.tsx +355 -144
  15. package/corpus/core/src/client/code-agent-chat-adapter.ts +2 -9
  16. package/corpus/core/src/client/session-replay.ts +3 -97
  17. package/corpus/core/src/client/settings/SettingsPanel.tsx +533 -389
  18. package/corpus/core/src/client/settings/SettingsSection.tsx +154 -17
  19. package/corpus/core/src/client/sse-event-processor.ts +29 -2
  20. package/corpus/core/src/extensions/actions.ts +113 -5
  21. package/corpus/core/src/notifications/channels.ts +88 -25
  22. package/corpus/core/src/notifications/registry.ts +17 -3
  23. package/corpus/core/src/notifications/types.ts +4 -1
  24. package/corpus/core/src/server/agent-chat-plugin.ts +7 -3
  25. package/corpus/core/src/server/request-context.ts +7 -0
  26. package/corpus/core/src/styles/agent-conversation.css +1 -1
  27. package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +20 -2
  28. package/corpus/core/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  29. package/corpus/core/src/templates/default/AGENTS.md +10 -3
  30. package/corpus/core/src/templates/default/package.json +2 -1
  31. package/corpus/core/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  32. package/corpus/core/src/templates/headless/AGENTS.md +9 -3
  33. package/corpus/core/src/templates/headless/package.json +1 -0
  34. package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +20 -2
  35. package/corpus/core/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  36. package/corpus/core/src/templates/workspace-root/AGENTS.md +10 -4
  37. package/corpus/core/src/templates/workspace-root/package.json +1 -0
  38. package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +20 -2
  39. package/corpus/templates/analytics/.agents/skills/session-replay/SKILL.md +5 -6
  40. package/corpus/templates/analytics/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  41. package/corpus/templates/analytics/AGENTS.md +7 -5
  42. package/corpus/templates/analytics/actions/save-monitor.ts +14 -0
  43. package/corpus/templates/analytics/app/components/dashboard/DataTable.tsx +41 -6
  44. package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +122 -11
  45. package/corpus/templates/analytics/app/pages/monitoring/MonitoringPage.tsx +8 -2
  46. package/corpus/templates/analytics/app/pages/monitoring/uptime/MonitorFormPage.tsx +151 -32
  47. package/corpus/templates/analytics/app/pages/monitoring/uptime/i18n.ts +17 -2
  48. package/corpus/templates/analytics/app/pages/monitoring/uptime/types.ts +4 -0
  49. package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +54 -190
  50. package/corpus/templates/analytics/changelog/2026-07-08-dashboard-tables-keep-their-size-while-loading.md +6 -0
  51. package/corpus/templates/analytics/changelog/2026-07-08-monitoring-uptime-and-errors-tabs-now-clearly-show-which-view-is-active.md +6 -0
  52. package/corpus/templates/analytics/changelog/2026-07-08-session-replay-uses-stock-rrweb-sizing-again-so-recorded.md +6 -0
  53. package/corpus/templates/analytics/changelog/2026-07-08-sidebar-dashboard-menus-now-open-above-the-dashboard-canvas.md +6 -0
  54. package/corpus/templates/analytics/changelog/2026-07-08-uptime-alerting-clarifies-in-app-inbox-vs-email-and-lets-you-paste-slack-or-webhook-urls-per-monitor.md +6 -0
  55. package/corpus/templates/analytics/docs/uptime-monitoring.md +13 -11
  56. package/corpus/templates/analytics/server/db/schema-monitoring.ts +4 -0
  57. package/corpus/templates/analytics/server/lib/uptime-monitors.ts +60 -12
  58. package/corpus/templates/analytics/server/plugins/db.ts +10 -0
  59. package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +20 -2
  60. package/corpus/templates/assets/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  61. package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +20 -2
  62. package/corpus/templates/brain/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  63. package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +20 -2
  64. package/corpus/templates/calendar/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  65. package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +20 -2
  66. package/corpus/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  67. package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +20 -2
  68. package/corpus/templates/clips/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  69. package/corpus/templates/clips/changelog/2026-07-08-desktop-meeting-notes-stay-active-from-tray-and-shortcut-controls.md +6 -0
  70. package/corpus/templates/clips/changelog/2026-07-08-desktop-meeting-popovers-can-start-notes-and-join-the-meetin.md +6 -0
  71. package/corpus/templates/clips/changelog/2026-07-08-meeting-notes-keep-their-recording-state-when-the-desktop.md +6 -0
  72. package/corpus/templates/clips/changelog/2026-07-08-meeting-reminder-dropdowns-now-expand-fully-instead-of-being.md +6 -0
  73. package/corpus/templates/clips/desktop/src/app.tsx +123 -3
  74. package/corpus/templates/clips/desktop/src/hooks/useMeetingTranscription.ts +15 -1
  75. package/corpus/templates/clips/desktop/src/overlays/meeting-notification.tsx +23 -0
  76. package/corpus/templates/clips/desktop/src/styles.css +23 -1
  77. package/corpus/templates/clips/desktop/src-tauri/src/adhoc_meetings_watcher.rs +1 -3
  78. package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +40 -6
  79. package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +4 -2
  80. package/corpus/templates/clips/desktop/src-tauri/src/meetings_watcher.rs +3 -5
  81. package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +23 -19
  82. package/corpus/templates/clips/desktop/src-tauri/src/shortcuts.rs +3 -3
  83. package/corpus/templates/clips/desktop/src-tauri/src/silence_detector.rs +0 -1
  84. package/corpus/templates/clips/desktop/src-tauri/src/state.rs +5 -0
  85. package/corpus/templates/clips/desktop/src-tauri/src/tray.rs +18 -6
  86. package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +20 -2
  87. package/corpus/templates/content/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  88. package/corpus/templates/content/actions/_batch-utils.ts +8 -0
  89. package/corpus/templates/content/actions/_builder-cms-read-client.ts +7 -5
  90. package/corpus/templates/content/actions/_database-source-utils.ts +776 -319
  91. package/corpus/templates/content/actions/_database-utils.ts +6 -1
  92. package/corpus/templates/content/actions/_property-utils.ts +168 -0
  93. package/corpus/templates/content/actions/add-content-database-source-field-property.ts +19 -12
  94. package/corpus/templates/content/actions/bind-content-database-source-field.ts +19 -12
  95. package/corpus/templates/content/actions/delete-document.ts +9 -13
  96. package/corpus/templates/content/actions/refresh-content-database-source.ts +5 -5
  97. package/corpus/templates/content/app/components/editor/body-hydration.ts +35 -11
  98. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +47 -5
  99. package/corpus/templates/content/app/hooks/use-documents.ts +8 -2
  100. package/corpus/templates/content/changelog/2026-07-08-builder-source-sync-now-completes-reliably-on-hosted-databases.md +6 -0
  101. package/corpus/templates/content/changelog/2026-07-08-fixed-builder-database-sync-so-large-sources-continue-past-t.md +6 -0
  102. package/corpus/templates/content/server/plugins/db.ts +19 -0
  103. package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +20 -2
  104. package/corpus/templates/design/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  105. package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +20 -2
  106. package/corpus/templates/dispatch/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  107. package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +20 -2
  108. package/corpus/templates/forms/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  109. package/corpus/templates/macros/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  110. package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +20 -2
  111. package/corpus/templates/mail/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  112. package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +20 -2
  113. package/corpus/templates/plan/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  114. package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +20 -2
  115. package/corpus/templates/slides/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  116. package/corpus/templates/videos/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  117. package/corpus/templates/voice/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  118. package/dist/agent/production-agent.d.ts +5 -1
  119. package/dist/agent/production-agent.d.ts.map +1 -1
  120. package/dist/agent/production-agent.js +112 -42
  121. package/dist/agent/production-agent.js.map +1 -1
  122. package/dist/agent/tool-search.d.ts +2 -0
  123. package/dist/agent/tool-search.d.ts.map +1 -1
  124. package/dist/agent/tool-search.js +60 -4
  125. package/dist/agent/tool-search.js.map +1 -1
  126. package/dist/cli/index.js +19 -0
  127. package/dist/cli/index.js.map +1 -1
  128. package/dist/cli/upgrade.d.ts +100 -0
  129. package/dist/cli/upgrade.d.ts.map +1 -0
  130. package/dist/cli/upgrade.js +678 -0
  131. package/dist/cli/upgrade.js.map +1 -0
  132. package/dist/client/AssistantChat.js +1 -1
  133. package/dist/client/AssistantChat.js.map +1 -1
  134. package/dist/client/HighlightedCodeBlock.d.ts +2 -0
  135. package/dist/client/HighlightedCodeBlock.d.ts.map +1 -1
  136. package/dist/client/HighlightedCodeBlock.js +10 -1
  137. package/dist/client/HighlightedCodeBlock.js.map +1 -1
  138. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  139. package/dist/client/agent-chat-adapter.js +32 -4
  140. package/dist/client/agent-chat-adapter.js.map +1 -1
  141. package/dist/client/chat/message-components.d.ts.map +1 -1
  142. package/dist/client/chat/message-components.js +61 -8
  143. package/dist/client/chat/message-components.js.map +1 -1
  144. package/dist/client/chat/tool-call-display.d.ts +12 -0
  145. package/dist/client/chat/tool-call-display.d.ts.map +1 -1
  146. package/dist/client/chat/tool-call-display.js +136 -42
  147. package/dist/client/chat/tool-call-display.js.map +1 -1
  148. package/dist/client/code-agent-chat-adapter.js +2 -9
  149. package/dist/client/code-agent-chat-adapter.js.map +1 -1
  150. package/dist/client/session-replay.d.ts +0 -8
  151. package/dist/client/session-replay.d.ts.map +1 -1
  152. package/dist/client/session-replay.js +3 -80
  153. package/dist/client/session-replay.js.map +1 -1
  154. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  155. package/dist/client/settings/SettingsPanel.js +52 -19
  156. package/dist/client/settings/SettingsPanel.js.map +1 -1
  157. package/dist/client/settings/SettingsSection.d.ts +19 -4
  158. package/dist/client/settings/SettingsSection.d.ts.map +1 -1
  159. package/dist/client/settings/SettingsSection.js +33 -4
  160. package/dist/client/settings/SettingsSection.js.map +1 -1
  161. package/dist/client/sse-event-processor.d.ts +9 -0
  162. package/dist/client/sse-event-processor.d.ts.map +1 -1
  163. package/dist/client/sse-event-processor.js +20 -2
  164. package/dist/client/sse-event-processor.js.map +1 -1
  165. package/dist/collab/routes.d.ts +1 -1
  166. package/dist/extensions/actions.d.ts.map +1 -1
  167. package/dist/extensions/actions.js +85 -5
  168. package/dist/extensions/actions.js.map +1 -1
  169. package/dist/notifications/channels.d.ts +8 -3
  170. package/dist/notifications/channels.d.ts.map +1 -1
  171. package/dist/notifications/channels.js +61 -22
  172. package/dist/notifications/channels.js.map +1 -1
  173. package/dist/notifications/registry.d.ts.map +1 -1
  174. package/dist/notifications/registry.js +14 -3
  175. package/dist/notifications/registry.js.map +1 -1
  176. package/dist/notifications/routes.d.ts +1 -1
  177. package/dist/notifications/types.d.ts +4 -1
  178. package/dist/notifications/types.d.ts.map +1 -1
  179. package/dist/notifications/types.js.map +1 -1
  180. package/dist/observability/routes.d.ts +1 -1
  181. package/dist/resources/handlers.d.ts +1 -1
  182. package/dist/server/agent-chat-plugin.d.ts +5 -1
  183. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  184. package/dist/server/agent-chat-plugin.js +2 -2
  185. package/dist/server/agent-chat-plugin.js.map +1 -1
  186. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  187. package/dist/server/request-context.d.ts +7 -0
  188. package/dist/server/request-context.d.ts.map +1 -1
  189. package/dist/server/request-context.js.map +1 -1
  190. package/dist/styles/agent-conversation.css +1 -1
  191. package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +20 -2
  192. package/dist/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  193. package/dist/templates/default/AGENTS.md +10 -3
  194. package/dist/templates/default/package.json +2 -1
  195. package/dist/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  196. package/dist/templates/headless/AGENTS.md +9 -3
  197. package/dist/templates/headless/package.json +1 -0
  198. package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +20 -2
  199. package/dist/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  200. package/dist/templates/workspace-root/AGENTS.md +10 -4
  201. package/dist/templates/workspace-root/package.json +1 -0
  202. package/docs/content/faq.mdx +17 -0
  203. package/docs/content/notifications.mdx +12 -6
  204. package/package.json +2 -2
  205. package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +20 -2
  206. package/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  207. package/src/templates/default/AGENTS.md +10 -3
  208. package/src/templates/default/package.json +2 -1
  209. package/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  210. package/src/templates/headless/AGENTS.md +9 -3
  211. package/src/templates/headless/package.json +1 -0
  212. package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +20 -2
  213. package/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
  214. package/src/templates/workspace-root/AGENTS.md +10 -4
  215. package/src/templates/workspace-root/package.json +1 -0
  216. package/corpus/templates/analytics/changelog/2026-07-08-session-replay-clamps-ultra-wide-viewports-while-keeping-the.md +0 -6
@@ -0,0 +1,678 @@
1
+ /**
2
+ * `agent-native upgrade` — bring an existing Agent Native app/workspace current.
3
+ *
4
+ * Older branches often break after a core bump. Agents then invent
5
+ * `pnpm.overrides` / patches against `@agent-native/*` (especially dispatch),
6
+ * which makes things worse. This command is the supported path:
7
+ *
8
+ * 1. Doctor: refuse or warn on framework overrides/patches
9
+ * 2. Bump `@agent-native/*` deps to `latest` (unless file:/link:/workspace:)
10
+ * 3. Install
11
+ * 4. Refresh scaffold skills (`skills update scaffold --project`)
12
+ * 5. Verify with typecheck when available
13
+ *
14
+ * On failure: print the error and stop. Do not patch framework packages.
15
+ */
16
+ import { spawnSync } from "node:child_process";
17
+ import fs from "node:fs";
18
+ import path from "node:path";
19
+ import { fileURLToPath } from "node:url";
20
+ const AGENT_NATIVE_SCOPE = "@agent-native/";
21
+ const PINNABLE_VERSION = "latest";
22
+ const defaultIo = {
23
+ log: (message) => console.log(message),
24
+ err: (message) => console.error(message),
25
+ spawn: (command, args, options) => spawnSync(command, args, {
26
+ cwd: options.cwd,
27
+ stdio: options.stdio ?? "inherit",
28
+ encoding: "utf-8",
29
+ shell: process.platform === "win32",
30
+ }),
31
+ runSkillsUpdate: async (cwd) => {
32
+ const { runSkills } = await import("./skills.js");
33
+ const previous = process.cwd();
34
+ process.chdir(cwd);
35
+ try {
36
+ await runSkills(["update", "scaffold", "--project"]);
37
+ }
38
+ finally {
39
+ process.chdir(previous);
40
+ }
41
+ },
42
+ };
43
+ export function parseUpgradeArgs(argv) {
44
+ const opts = { command: "run" };
45
+ for (let i = 0; i < argv.length; i++) {
46
+ const arg = argv[i];
47
+ if (arg === "check" || arg === "doctor") {
48
+ opts.command = "check";
49
+ }
50
+ else if (arg === "help" || arg === "--help" || arg === "-h") {
51
+ opts.command = "help";
52
+ opts.help = true;
53
+ }
54
+ else if (arg === "--dry-run") {
55
+ opts.dryRun = true;
56
+ }
57
+ else if (arg === "--skip-install") {
58
+ opts.skipInstall = true;
59
+ }
60
+ else if (arg === "--skip-verify") {
61
+ opts.skipVerify = true;
62
+ }
63
+ else if (arg === "--skip-skills") {
64
+ opts.skipSkills = true;
65
+ }
66
+ else if (arg === "--json") {
67
+ opts.json = true;
68
+ }
69
+ else if (arg === "--force") {
70
+ opts.force = true;
71
+ }
72
+ else if (arg === "--cwd" && argv[i + 1]) {
73
+ opts.cwd = argv[++i];
74
+ }
75
+ else if (arg.startsWith("--cwd=")) {
76
+ opts.cwd = arg.slice("--cwd=".length);
77
+ }
78
+ else if (!arg.startsWith("-")) {
79
+ // Ignore unknown positional for forward-compat; help covers usage.
80
+ }
81
+ }
82
+ return opts;
83
+ }
84
+ export function printUpgradeHelp(io = defaultIo) {
85
+ io.log([
86
+ "Usage:",
87
+ " agent-native upgrade Bring this app/workspace to current @agent-native/*",
88
+ " agent-native upgrade check Doctor only: overrides, patches, pending bumps",
89
+ " agent-native upgrade --dry-run Show the plan without writing or installing",
90
+ "",
91
+ "Options:",
92
+ " --skip-install Bump package.json only; do not run the package manager",
93
+ " --skip-skills Skip `skills update scaffold --project`",
94
+ " --skip-verify Skip typecheck after upgrade",
95
+ " --force Continue even when framework overrides/patches are present",
96
+ " --json Machine-readable report",
97
+ " --cwd <dir> Run against a project root other than the current directory",
98
+ "",
99
+ "On failure: report the error and stop. Do NOT add pnpm.overrides,",
100
+ "patchedDependencies, or local patches against @agent-native/* packages.",
101
+ "Do NOT edit node_modules/@agent-native/* or invent dispatch/core behavior",
102
+ "overrides. Revert those changes and re-run `agent-native upgrade`.",
103
+ ].join("\n"));
104
+ }
105
+ function readJsonFile(filePath) {
106
+ try {
107
+ return JSON.parse(fs.readFileSync(filePath, "utf-8"));
108
+ }
109
+ catch {
110
+ return null;
111
+ }
112
+ }
113
+ function writeJsonFile(filePath, value) {
114
+ fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
115
+ }
116
+ export function isAgentNativePackageName(name) {
117
+ return name === "@agent-native" || name.startsWith(AGENT_NATIVE_SCOPE);
118
+ }
119
+ export function isPinnedOrLocalVersion(version) {
120
+ const v = version.trim();
121
+ return (v.startsWith("file:") ||
122
+ v.startsWith("link:") ||
123
+ v.startsWith("workspace:") ||
124
+ v.startsWith("portal:") ||
125
+ v.startsWith("git+") ||
126
+ v.startsWith("github:") ||
127
+ v.startsWith("http:") ||
128
+ v.startsWith("https:"));
129
+ }
130
+ export function shouldBumpAgentNativeVersion(version) {
131
+ if (isPinnedOrLocalVersion(version))
132
+ return false;
133
+ return version.trim() !== PINNABLE_VERSION;
134
+ }
135
+ function collectOverrideFindings(file, pkg) {
136
+ const findings = [];
137
+ const tables = [
138
+ { field: "pnpm.overrides", map: pkg.pnpm?.overrides },
139
+ { field: "pnpm.patchedDependencies", map: pkg.pnpm?.patchedDependencies },
140
+ { field: "overrides", map: pkg.overrides },
141
+ { field: "resolutions", map: pkg.resolutions },
142
+ ];
143
+ for (const table of tables) {
144
+ if (!table.map)
145
+ continue;
146
+ for (const [key, value] of Object.entries(table.map)) {
147
+ // Keys may be bare (`@agent-native/core`) or versioned
148
+ // (`@agent-native/core@1.2.3` for patchedDependencies).
149
+ if (key.includes(AGENT_NATIVE_SCOPE) || isAgentNativePackageName(key)) {
150
+ findings.push({ file, field: table.field, key, value: String(value) });
151
+ }
152
+ }
153
+ }
154
+ return findings;
155
+ }
156
+ function collectBumps(file, pkg) {
157
+ const bumps = [];
158
+ const sections = [
159
+ "dependencies",
160
+ "devDependencies",
161
+ "optionalDependencies",
162
+ ];
163
+ for (const section of sections) {
164
+ const deps = pkg[section];
165
+ if (!deps)
166
+ continue;
167
+ for (const [name, version] of Object.entries(deps)) {
168
+ if (!isAgentNativePackageName(name))
169
+ continue;
170
+ if (!shouldBumpAgentNativeVersion(version))
171
+ continue;
172
+ bumps.push({
173
+ file,
174
+ section,
175
+ name,
176
+ from: version,
177
+ to: PINNABLE_VERSION,
178
+ });
179
+ }
180
+ }
181
+ return bumps;
182
+ }
183
+ function applyBumps(pkg, bumps) {
184
+ for (const bump of bumps) {
185
+ const section = pkg[bump.section];
186
+ if (!section)
187
+ continue;
188
+ if (section[bump.name] === bump.from) {
189
+ section[bump.name] = bump.to;
190
+ }
191
+ }
192
+ }
193
+ export function detectUpgradeProject(cwd) {
194
+ const start = path.resolve(cwd);
195
+ let dir = start;
196
+ while (true) {
197
+ const pkgPath = path.join(dir, "package.json");
198
+ if (fs.existsSync(pkgPath)) {
199
+ const pkg = readJsonFile(pkgPath);
200
+ const hasCore = Boolean(pkg?.dependencies?.["@agent-native/core"]) ||
201
+ Boolean(pkg?.devDependencies?.["@agent-native/core"]);
202
+ const workspaceYaml = path.join(dir, "pnpm-workspace.yaml");
203
+ const isWorkspace = fs.existsSync(workspaceYaml);
204
+ if (hasCore || isWorkspace) {
205
+ const packageFiles = [pkgPath];
206
+ if (isWorkspace) {
207
+ packageFiles.push(...workspacePackageFiles(dir, workspaceYaml));
208
+ }
209
+ return {
210
+ root: dir,
211
+ kind: isWorkspace ? "workspace" : "standalone",
212
+ packageFiles: Array.from(new Set(packageFiles)),
213
+ };
214
+ }
215
+ }
216
+ const parent = path.dirname(dir);
217
+ if (parent === dir)
218
+ break;
219
+ dir = parent;
220
+ }
221
+ return null;
222
+ }
223
+ function workspacePackageFiles(root, workspaceYaml) {
224
+ const patterns = parseWorkspacePackagePatterns(workspaceYaml);
225
+ const included = new Set();
226
+ const excluded = new Set();
227
+ for (const rawPattern of patterns) {
228
+ const exclude = rawPattern.startsWith("!");
229
+ const pattern = exclude ? rawPattern.slice(1) : rawPattern;
230
+ const files = packageFilesForWorkspacePattern(root, pattern);
231
+ for (const file of files) {
232
+ if (exclude)
233
+ excluded.add(file);
234
+ else
235
+ included.add(file);
236
+ }
237
+ }
238
+ return Array.from(included)
239
+ .filter((file) => !excluded.has(file))
240
+ .sort();
241
+ }
242
+ function parseWorkspacePackagePatterns(workspaceYaml) {
243
+ let text = "";
244
+ try {
245
+ text = fs.readFileSync(workspaceYaml, "utf-8");
246
+ }
247
+ catch {
248
+ return ["apps/*", "packages/*"];
249
+ }
250
+ const patterns = [];
251
+ let inPackages = false;
252
+ for (const line of text.split(/\r?\n/)) {
253
+ const trimmed = line.trim();
254
+ if (!trimmed || trimmed.startsWith("#"))
255
+ continue;
256
+ if (/^[A-Za-z0-9_-]+:/.test(trimmed)) {
257
+ inPackages = trimmed === "packages:";
258
+ continue;
259
+ }
260
+ if (!inPackages || !trimmed.startsWith("-"))
261
+ continue;
262
+ const pattern = trimmed
263
+ .slice(1)
264
+ .trim()
265
+ .replace(/^['"]|['"]$/g, "");
266
+ if (pattern)
267
+ patterns.push(pattern);
268
+ }
269
+ return patterns.length ? patterns : ["apps/*", "packages/*"];
270
+ }
271
+ function packageFilesForWorkspacePattern(root, pattern) {
272
+ const normalized = pattern.replace(/\\/g, "/").replace(/\/+$/g, "");
273
+ if (!normalized || normalized.includes("node_modules"))
274
+ return [];
275
+ if (normalized.endsWith("/**")) {
276
+ return collectPackageFilesRecursive(path.join(root, normalized.slice(0, -3)));
277
+ }
278
+ if (normalized.endsWith("/*")) {
279
+ const base = path.join(root, normalized.slice(0, -2));
280
+ if (!fs.existsSync(base))
281
+ return [];
282
+ return fs
283
+ .readdirSync(base, { withFileTypes: true })
284
+ .filter((entry) => entry.isDirectory())
285
+ .map((entry) => path.join(base, entry.name, "package.json"))
286
+ .filter((file) => fs.existsSync(file));
287
+ }
288
+ if (normalized.includes("*")) {
289
+ return collectPackageFilesRecursive(path.join(root, normalized.split("*")[0]));
290
+ }
291
+ const file = path.join(root, normalized, "package.json");
292
+ return fs.existsSync(file) ? [file] : [];
293
+ }
294
+ function collectPackageFilesRecursive(dir) {
295
+ if (!fs.existsSync(dir))
296
+ return [];
297
+ const files = [];
298
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
299
+ if (!entry.isDirectory())
300
+ continue;
301
+ if (entry.name === "node_modules" || entry.name === ".git")
302
+ continue;
303
+ const child = path.join(dir, entry.name);
304
+ const pkg = path.join(child, "package.json");
305
+ if (fs.existsSync(pkg))
306
+ files.push(pkg);
307
+ files.push(...collectPackageFilesRecursive(child));
308
+ }
309
+ return files;
310
+ }
311
+ function resolveInstalledPackageVersion(projectRoot, packageName) {
312
+ let dir = projectRoot;
313
+ while (true) {
314
+ const candidate = path.join(dir, "node_modules", ...packageName.split("/"), "package.json");
315
+ if (fs.existsSync(candidate)) {
316
+ const pkg = readJsonFile(candidate);
317
+ return typeof pkg?.version === "string" ? pkg.version : null;
318
+ }
319
+ const parent = path.dirname(dir);
320
+ if (parent === dir)
321
+ break;
322
+ dir = parent;
323
+ }
324
+ return null;
325
+ }
326
+ function readCliCoreVersion() {
327
+ try {
328
+ const here = path.dirname(fileURLToPath(import.meta.url));
329
+ const pkgPath = path.resolve(here, "../../package.json");
330
+ const pkg = readJsonFile(pkgPath);
331
+ return typeof pkg?.version === "string" ? pkg.version : null;
332
+ }
333
+ catch {
334
+ return null;
335
+ }
336
+ }
337
+ function detectPackageManager(projectRoot) {
338
+ if (fs.existsSync(path.join(projectRoot, "pnpm-lock.yaml")))
339
+ return "pnpm";
340
+ if (fs.existsSync(path.join(projectRoot, "yarn.lock")))
341
+ return "yarn";
342
+ if (fs.existsSync(path.join(projectRoot, "package-lock.json")))
343
+ return "npm";
344
+ // Prefer pnpm for Agent Native scaffolds.
345
+ return "pnpm";
346
+ }
347
+ function installArgs(pm) {
348
+ if (pm === "npm")
349
+ return ["install"];
350
+ if (pm === "yarn")
351
+ return ["install"];
352
+ return ["install"];
353
+ }
354
+ export function buildUpgradeDoctorReport(project) {
355
+ const findings = [];
356
+ const bumps = [];
357
+ for (const file of project.packageFiles) {
358
+ const pkg = readJsonFile(file);
359
+ if (!pkg)
360
+ continue;
361
+ findings.push(...collectOverrideFindings(file, pkg));
362
+ bumps.push(...collectBumps(file, pkg));
363
+ }
364
+ const installedCoreVersion = resolveInstalledPackageVersion(project.root, "@agent-native/core");
365
+ const cliCoreVersion = readCliCoreVersion();
366
+ const skillsUpdateScript = project.packageFiles.some((file) => {
367
+ const pkg = readJsonFile(file);
368
+ return Boolean(pkg?.scripts?.["skills:update"]);
369
+ });
370
+ return {
371
+ project,
372
+ findings,
373
+ bumps,
374
+ installedCoreVersion,
375
+ cliCoreVersion,
376
+ scaffoldStaleHint: skillsUpdateScript || bumps.length > 0,
377
+ };
378
+ }
379
+ function relativeTo(root, file) {
380
+ const rel = path.relative(root, file);
381
+ return rel || ".";
382
+ }
383
+ function formatDoctorHuman(report) {
384
+ const lines = [];
385
+ lines.push(`Project: ${report.project.root} (${report.project.kind})`);
386
+ if (report.installedCoreVersion) {
387
+ lines.push(`Installed @agent-native/core: ${report.installedCoreVersion}`);
388
+ }
389
+ else {
390
+ lines.push("Installed @agent-native/core: (not found in node_modules)");
391
+ }
392
+ if (report.cliCoreVersion) {
393
+ lines.push(`CLI package version: ${report.cliCoreVersion}`);
394
+ }
395
+ if (report.findings.length === 0) {
396
+ lines.push("Framework overrides/patches: none");
397
+ }
398
+ else {
399
+ lines.push("Framework overrides/patches:");
400
+ for (const finding of report.findings) {
401
+ lines.push(` - ${relativeTo(report.project.root, finding.file)} ${finding.field}["${finding.key}"] = ${finding.value}`);
402
+ }
403
+ }
404
+ if (report.bumps.length === 0) {
405
+ lines.push("Pending @agent-native/* bumps: none");
406
+ }
407
+ else {
408
+ lines.push("Pending @agent-native/* bumps:");
409
+ for (const bump of report.bumps) {
410
+ lines.push(` - ${relativeTo(report.project.root, bump.file)} ${bump.name}: ${bump.from} → ${bump.to}`);
411
+ }
412
+ }
413
+ return lines.join("\n");
414
+ }
415
+ const FAILURE_GUIDANCE = [
416
+ "Upgrade failed. Do not paper over this with framework patches.",
417
+ "Never add pnpm.overrides / patchedDependencies / resolutions for @agent-native/*.",
418
+ "Never edit node_modules/@agent-native/* or invent local dispatch/core behavior overrides.",
419
+ "Revert those changes if present, fix the app-level compile/runtime error, then re-run:",
420
+ " npx @agent-native/core@latest upgrade",
421
+ ].join("\n");
422
+ export async function runUpgrade(argv, io = defaultIo) {
423
+ const opts = parseUpgradeArgs(argv);
424
+ if (opts.help || opts.command === "help") {
425
+ printUpgradeHelp(io);
426
+ return 0;
427
+ }
428
+ const cwd = path.resolve(opts.cwd ?? process.cwd());
429
+ const project = detectUpgradeProject(cwd);
430
+ if (!project) {
431
+ const message = "No Agent Native app/workspace found. Run from an app or workspace root that depends on @agent-native/core.";
432
+ if (opts.json) {
433
+ io.err(JSON.stringify({ ok: false, message }, null, 2));
434
+ }
435
+ else {
436
+ io.err(message);
437
+ }
438
+ return 1;
439
+ }
440
+ const doctor = buildUpgradeDoctorReport(project);
441
+ if (opts.command === "check") {
442
+ if (opts.json) {
443
+ io.log(JSON.stringify({ ok: doctor.findings.length === 0, doctor }, null, 2));
444
+ }
445
+ else {
446
+ io.log(formatDoctorHuman(doctor));
447
+ if (doctor.findings.length > 0) {
448
+ io.err("");
449
+ io.err(FAILURE_GUIDANCE);
450
+ }
451
+ }
452
+ return doctor.findings.length > 0 ? 1 : 0;
453
+ }
454
+ const result = {
455
+ ok: true,
456
+ dryRun: Boolean(opts.dryRun),
457
+ doctor,
458
+ steps: [],
459
+ message: "",
460
+ exitCode: 0,
461
+ };
462
+ if (doctor.findings.length > 0 && !opts.force) {
463
+ result.ok = false;
464
+ result.exitCode = 1;
465
+ result.message =
466
+ "Blocked: framework overrides/patches for @agent-native/* are present. Remove them, then re-run upgrade (or pass --force to continue unsafely).";
467
+ result.steps.push({
468
+ id: "doctor",
469
+ status: "failed",
470
+ detail: result.message,
471
+ });
472
+ if (opts.json) {
473
+ io.err(JSON.stringify(result, null, 2));
474
+ }
475
+ else {
476
+ io.log(formatDoctorHuman(doctor));
477
+ io.err("");
478
+ io.err(result.message);
479
+ io.err("");
480
+ io.err(FAILURE_GUIDANCE);
481
+ }
482
+ return 1;
483
+ }
484
+ result.steps.push({
485
+ id: "doctor",
486
+ status: doctor.findings.length > 0 ? "ok" : "ok",
487
+ detail: doctor.findings.length > 0
488
+ ? "Continuing with --force despite framework overrides/patches"
489
+ : "No framework overrides/patches",
490
+ });
491
+ // Apply package.json bumps.
492
+ if (doctor.bumps.length === 0) {
493
+ result.steps.push({
494
+ id: "bump",
495
+ status: "skipped",
496
+ detail: "All @agent-native/* deps already use latest or local pins",
497
+ });
498
+ }
499
+ else if (opts.dryRun) {
500
+ result.steps.push({
501
+ id: "bump",
502
+ status: "planned",
503
+ detail: doctor.bumps
504
+ .map((b) => `${relativeTo(project.root, b.file)} ${b.name}: ${b.from} → ${b.to}`)
505
+ .join("; "),
506
+ });
507
+ }
508
+ else {
509
+ const byFile = new Map();
510
+ for (const bump of doctor.bumps) {
511
+ const list = byFile.get(bump.file) ?? [];
512
+ list.push(bump);
513
+ byFile.set(bump.file, list);
514
+ }
515
+ for (const [file, bumps] of byFile) {
516
+ const pkg = readJsonFile(file);
517
+ if (!pkg)
518
+ continue;
519
+ applyBumps(pkg, bumps);
520
+ writeJsonFile(file, pkg);
521
+ }
522
+ result.steps.push({
523
+ id: "bump",
524
+ status: "ok",
525
+ detail: `Updated ${doctor.bumps.length} @agent-native/* dependency pin(s)`,
526
+ });
527
+ }
528
+ // Install.
529
+ if (opts.skipInstall) {
530
+ result.steps.push({
531
+ id: "install",
532
+ status: "skipped",
533
+ detail: "--skip-install",
534
+ });
535
+ }
536
+ else if (opts.dryRun) {
537
+ result.steps.push({
538
+ id: "install",
539
+ status: "planned",
540
+ detail: `${detectPackageManager(project.root)} install`,
541
+ });
542
+ }
543
+ else {
544
+ const pm = detectPackageManager(project.root);
545
+ const spawned = io.spawn(pm, installArgs(pm), {
546
+ cwd: project.root,
547
+ stdio: opts.json ? "pipe" : "inherit",
548
+ });
549
+ if (spawned.status !== 0) {
550
+ result.ok = false;
551
+ result.exitCode = spawned.status ?? 1;
552
+ result.message = `${pm} install failed`;
553
+ result.steps.push({
554
+ id: "install",
555
+ status: "failed",
556
+ detail: result.message,
557
+ });
558
+ emitResult(io, opts, result);
559
+ return result.exitCode;
560
+ }
561
+ result.steps.push({ id: "install", status: "ok", detail: `${pm} install` });
562
+ }
563
+ // Skills refresh.
564
+ if (opts.skipSkills) {
565
+ result.steps.push({
566
+ id: "skills",
567
+ status: "skipped",
568
+ detail: "--skip-skills",
569
+ });
570
+ }
571
+ else if (opts.dryRun) {
572
+ result.steps.push({
573
+ id: "skills",
574
+ status: "planned",
575
+ detail: "skills update scaffold --project",
576
+ });
577
+ }
578
+ else {
579
+ try {
580
+ await io.runSkillsUpdate(project.root);
581
+ result.steps.push({
582
+ id: "skills",
583
+ status: "ok",
584
+ detail: "skills update scaffold --project",
585
+ });
586
+ }
587
+ catch (err) {
588
+ result.ok = false;
589
+ result.exitCode = 1;
590
+ result.message = `skills update failed: ${err instanceof Error ? err.message : String(err)}`;
591
+ result.steps.push({
592
+ id: "skills",
593
+ status: "failed",
594
+ detail: result.message,
595
+ });
596
+ emitResult(io, opts, result);
597
+ return result.exitCode;
598
+ }
599
+ }
600
+ // Verify.
601
+ if (opts.skipVerify) {
602
+ result.steps.push({
603
+ id: "verify",
604
+ status: "skipped",
605
+ detail: "--skip-verify",
606
+ });
607
+ }
608
+ else if (opts.dryRun) {
609
+ result.steps.push({
610
+ id: "verify",
611
+ status: "planned",
612
+ detail: "typecheck (when available)",
613
+ });
614
+ }
615
+ else {
616
+ const rootPkg = readJsonFile(path.join(project.root, "package.json"));
617
+ const hasTypecheck = Boolean(rootPkg?.scripts?.typecheck);
618
+ if (!hasTypecheck) {
619
+ result.steps.push({
620
+ id: "verify",
621
+ status: "skipped",
622
+ detail: "no typecheck script",
623
+ });
624
+ }
625
+ else {
626
+ const pm = detectPackageManager(project.root);
627
+ const args = pm === "npm"
628
+ ? ["run", "typecheck"]
629
+ : pm === "yarn"
630
+ ? ["typecheck"]
631
+ : ["typecheck"];
632
+ const spawned = io.spawn(pm, args, {
633
+ cwd: project.root,
634
+ stdio: opts.json ? "pipe" : "inherit",
635
+ });
636
+ if (spawned.status !== 0) {
637
+ result.ok = false;
638
+ result.exitCode = spawned.status ?? 1;
639
+ result.message = "typecheck failed";
640
+ result.steps.push({
641
+ id: "verify",
642
+ status: "failed",
643
+ detail: result.message,
644
+ });
645
+ emitResult(io, opts, result);
646
+ return result.exitCode;
647
+ }
648
+ result.steps.push({ id: "verify", status: "ok", detail: "typecheck" });
649
+ }
650
+ }
651
+ result.message = opts.dryRun
652
+ ? "Dry run complete. Re-run without --dry-run to apply."
653
+ : "Upgrade complete. If the app still fails to run, fix app-level code — do not patch @agent-native/*.";
654
+ emitResult(io, opts, result);
655
+ return 0;
656
+ }
657
+ function emitResult(io, opts, result) {
658
+ if (opts.json) {
659
+ const sink = result.ok ? io.log : io.err;
660
+ sink(JSON.stringify(result, null, 2));
661
+ return;
662
+ }
663
+ io.log(formatDoctorHuman(result.doctor));
664
+ io.log("");
665
+ for (const step of result.steps) {
666
+ io.log(`[${step.status}] ${step.id}${step.detail ? ` — ${step.detail}` : ""}`);
667
+ }
668
+ io.log("");
669
+ if (result.ok) {
670
+ io.log(result.message);
671
+ }
672
+ else {
673
+ io.err(result.message);
674
+ io.err("");
675
+ io.err(FAILURE_GUIDANCE);
676
+ }
677
+ }
678
+ //# sourceMappingURL=upgrade.js.map