@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.
- package/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +17 -0
- package/corpus/core/docs/content/faq.mdx +17 -0
- package/corpus/core/docs/content/notifications.mdx +12 -6
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/production-agent.ts +140 -46
- package/corpus/core/src/agent/tool-search.ts +71 -4
- package/corpus/core/src/cli/index.ts +20 -0
- package/corpus/core/src/cli/upgrade.ts +798 -0
- package/corpus/core/src/client/AssistantChat.tsx +1 -1
- package/corpus/core/src/client/HighlightedCodeBlock.tsx +20 -3
- package/corpus/core/src/client/agent-chat-adapter.ts +31 -6
- package/corpus/core/src/client/chat/message-components.tsx +85 -8
- package/corpus/core/src/client/chat/tool-call-display.tsx +355 -144
- package/corpus/core/src/client/code-agent-chat-adapter.ts +2 -9
- package/corpus/core/src/client/session-replay.ts +3 -97
- package/corpus/core/src/client/settings/SettingsPanel.tsx +533 -389
- package/corpus/core/src/client/settings/SettingsSection.tsx +154 -17
- package/corpus/core/src/client/sse-event-processor.ts +29 -2
- package/corpus/core/src/extensions/actions.ts +113 -5
- package/corpus/core/src/notifications/channels.ts +88 -25
- package/corpus/core/src/notifications/registry.ts +17 -3
- package/corpus/core/src/notifications/types.ts +4 -1
- package/corpus/core/src/server/agent-chat-plugin.ts +7 -3
- package/corpus/core/src/server/request-context.ts +7 -0
- package/corpus/core/src/styles/agent-conversation.css +1 -1
- package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/core/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/core/src/templates/default/AGENTS.md +10 -3
- package/corpus/core/src/templates/default/package.json +2 -1
- package/corpus/core/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/core/src/templates/headless/AGENTS.md +9 -3
- package/corpus/core/src/templates/headless/package.json +1 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/core/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/core/src/templates/workspace-root/AGENTS.md +10 -4
- package/corpus/core/src/templates/workspace-root/package.json +1 -0
- package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/analytics/.agents/skills/session-replay/SKILL.md +5 -6
- package/corpus/templates/analytics/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/analytics/AGENTS.md +7 -5
- package/corpus/templates/analytics/actions/save-monitor.ts +14 -0
- package/corpus/templates/analytics/app/components/dashboard/DataTable.tsx +41 -6
- package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +122 -11
- package/corpus/templates/analytics/app/pages/monitoring/MonitoringPage.tsx +8 -2
- package/corpus/templates/analytics/app/pages/monitoring/uptime/MonitorFormPage.tsx +151 -32
- package/corpus/templates/analytics/app/pages/monitoring/uptime/i18n.ts +17 -2
- package/corpus/templates/analytics/app/pages/monitoring/uptime/types.ts +4 -0
- package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +54 -190
- package/corpus/templates/analytics/changelog/2026-07-08-dashboard-tables-keep-their-size-while-loading.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-08-monitoring-uptime-and-errors-tabs-now-clearly-show-which-view-is-active.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-08-session-replay-uses-stock-rrweb-sizing-again-so-recorded.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-08-sidebar-dashboard-menus-now-open-above-the-dashboard-canvas.md +6 -0
- 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
- package/corpus/templates/analytics/docs/uptime-monitoring.md +13 -11
- package/corpus/templates/analytics/server/db/schema-monitoring.ts +4 -0
- package/corpus/templates/analytics/server/lib/uptime-monitors.ts +60 -12
- package/corpus/templates/analytics/server/plugins/db.ts +10 -0
- package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/assets/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/brain/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/calendar/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/clips/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/clips/changelog/2026-07-08-desktop-meeting-notes-stay-active-from-tray-and-shortcut-controls.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-08-desktop-meeting-popovers-can-start-notes-and-join-the-meetin.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-08-meeting-notes-keep-their-recording-state-when-the-desktop.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-08-meeting-reminder-dropdowns-now-expand-fully-instead-of-being.md +6 -0
- package/corpus/templates/clips/desktop/src/app.tsx +123 -3
- package/corpus/templates/clips/desktop/src/hooks/useMeetingTranscription.ts +15 -1
- package/corpus/templates/clips/desktop/src/overlays/meeting-notification.tsx +23 -0
- package/corpus/templates/clips/desktop/src/styles.css +23 -1
- package/corpus/templates/clips/desktop/src-tauri/src/adhoc_meetings_watcher.rs +1 -3
- package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +40 -6
- package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +4 -2
- package/corpus/templates/clips/desktop/src-tauri/src/meetings_watcher.rs +3 -5
- package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +23 -19
- package/corpus/templates/clips/desktop/src-tauri/src/shortcuts.rs +3 -3
- package/corpus/templates/clips/desktop/src-tauri/src/silence_detector.rs +0 -1
- package/corpus/templates/clips/desktop/src-tauri/src/state.rs +5 -0
- package/corpus/templates/clips/desktop/src-tauri/src/tray.rs +18 -6
- package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/content/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/content/actions/_batch-utils.ts +8 -0
- package/corpus/templates/content/actions/_builder-cms-read-client.ts +7 -5
- package/corpus/templates/content/actions/_database-source-utils.ts +776 -319
- package/corpus/templates/content/actions/_database-utils.ts +6 -1
- package/corpus/templates/content/actions/_property-utils.ts +168 -0
- package/corpus/templates/content/actions/add-content-database-source-field-property.ts +19 -12
- package/corpus/templates/content/actions/bind-content-database-source-field.ts +19 -12
- package/corpus/templates/content/actions/delete-document.ts +9 -13
- package/corpus/templates/content/actions/refresh-content-database-source.ts +5 -5
- package/corpus/templates/content/app/components/editor/body-hydration.ts +35 -11
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +47 -5
- package/corpus/templates/content/app/hooks/use-documents.ts +8 -2
- package/corpus/templates/content/changelog/2026-07-08-builder-source-sync-now-completes-reliably-on-hosted-databases.md +6 -0
- package/corpus/templates/content/changelog/2026-07-08-fixed-builder-database-sync-so-large-sources-continue-past-t.md +6 -0
- package/corpus/templates/content/server/plugins/db.ts +19 -0
- package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/design/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/dispatch/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/forms/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/macros/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/mail/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/plan/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/corpus/templates/slides/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/videos/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/voice/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/dist/agent/production-agent.d.ts +5 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +112 -42
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/tool-search.d.ts +2 -0
- package/dist/agent/tool-search.d.ts.map +1 -1
- package/dist/agent/tool-search.js +60 -4
- package/dist/agent/tool-search.js.map +1 -1
- package/dist/cli/index.js +19 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/upgrade.d.ts +100 -0
- package/dist/cli/upgrade.d.ts.map +1 -0
- package/dist/cli/upgrade.js +678 -0
- package/dist/cli/upgrade.js.map +1 -0
- package/dist/client/AssistantChat.js +1 -1
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/HighlightedCodeBlock.d.ts +2 -0
- package/dist/client/HighlightedCodeBlock.d.ts.map +1 -1
- package/dist/client/HighlightedCodeBlock.js +10 -1
- package/dist/client/HighlightedCodeBlock.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +32 -4
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/chat/message-components.d.ts.map +1 -1
- package/dist/client/chat/message-components.js +61 -8
- package/dist/client/chat/message-components.js.map +1 -1
- package/dist/client/chat/tool-call-display.d.ts +12 -0
- package/dist/client/chat/tool-call-display.d.ts.map +1 -1
- package/dist/client/chat/tool-call-display.js +136 -42
- package/dist/client/chat/tool-call-display.js.map +1 -1
- package/dist/client/code-agent-chat-adapter.js +2 -9
- package/dist/client/code-agent-chat-adapter.js.map +1 -1
- package/dist/client/session-replay.d.ts +0 -8
- package/dist/client/session-replay.d.ts.map +1 -1
- package/dist/client/session-replay.js +3 -80
- package/dist/client/session-replay.js.map +1 -1
- package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
- package/dist/client/settings/SettingsPanel.js +52 -19
- package/dist/client/settings/SettingsPanel.js.map +1 -1
- package/dist/client/settings/SettingsSection.d.ts +19 -4
- package/dist/client/settings/SettingsSection.d.ts.map +1 -1
- package/dist/client/settings/SettingsSection.js +33 -4
- package/dist/client/settings/SettingsSection.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts +9 -0
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +20 -2
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/extensions/actions.d.ts.map +1 -1
- package/dist/extensions/actions.js +85 -5
- package/dist/extensions/actions.js.map +1 -1
- package/dist/notifications/channels.d.ts +8 -3
- package/dist/notifications/channels.d.ts.map +1 -1
- package/dist/notifications/channels.js +61 -22
- package/dist/notifications/channels.js.map +1 -1
- package/dist/notifications/registry.d.ts.map +1 -1
- package/dist/notifications/registry.js +14 -3
- package/dist/notifications/registry.js.map +1 -1
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/notifications/types.d.ts +4 -1
- package/dist/notifications/types.d.ts.map +1 -1
- package/dist/notifications/types.js.map +1 -1
- package/dist/observability/routes.d.ts +1 -1
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/server/agent-chat-plugin.d.ts +5 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +2 -2
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/request-context.d.ts +7 -0
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/request-context.js.map +1 -1
- package/dist/styles/agent-conversation.css +1 -1
- package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/dist/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/dist/templates/default/AGENTS.md +10 -3
- package/dist/templates/default/package.json +2 -1
- package/dist/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/dist/templates/headless/AGENTS.md +9 -3
- package/dist/templates/headless/package.json +1 -0
- package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/dist/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/dist/templates/workspace-root/AGENTS.md +10 -4
- package/dist/templates/workspace-root/package.json +1 -0
- package/docs/content/faq.mdx +17 -0
- package/docs/content/notifications.mdx +12 -6
- package/package.json +2 -2
- package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/src/templates/default/AGENTS.md +10 -3
- package/src/templates/default/package.json +2 -1
- package/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/src/templates/headless/AGENTS.md +9 -3
- package/src/templates/headless/package.json +1 -0
- package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +20 -2
- package/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/src/templates/workspace-root/AGENTS.md +10 -4
- package/src/templates/workspace-root/package.json +1 -0
- package/corpus/templates/analytics/changelog/2026-07-08-session-replay-clamps-ultra-wide-viewports-while-keeping-the.md +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-search.d.ts","sourceRoot":"","sources":["../../src/agent/tool-search.ts"],"names":[],"mappings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AAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACrC,IAAI,GAAE,cAAmB,EACzB,OAAO,GAAE,iBAAsB,GAC9B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC7B,CA0HA"}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { parseMcpToolName } from "../mcp-client/manager.js";
|
|
2
2
|
import { isMcpToolAllowedForRequest } from "../mcp-client/visibility.js";
|
|
3
|
+
import { getRequestRunContext } from "../server/request-context.js";
|
|
3
4
|
export const TOOL_SEARCH_ACTION_NAME = "tool-search";
|
|
4
5
|
const DEFAULT_LIMIT = 8;
|
|
5
6
|
const MAX_LIMIT = 25;
|
|
6
7
|
export function createToolSearchEntry(getRegistry, options = {}) {
|
|
7
8
|
return {
|
|
8
9
|
tool: {
|
|
9
|
-
description: "Discover callable tools/actions, including connected MCP server tools named `mcp__<server>__<tool>`. Call it with NO query to list every available tool by name with a one-line description (cheap — no input schemas)
|
|
10
|
+
description: "Discover callable tools/actions, including connected MCP server tools named `mcp__<server>__<tool>`. Call it with NO query to list every available tool by name with a one-line description (cheap — no input schemas); names from that menu are not loaded for calling yet, so call tool-search again with a specific query for the tool/capability before invoking it. Use this whenever you need a capability but aren't sure which tool to call — most tools are not loaded into context up front, so this is how you find and then call them.",
|
|
10
11
|
parameters: {
|
|
11
12
|
type: "object",
|
|
12
13
|
properties: {
|
|
13
14
|
query: {
|
|
14
15
|
type: "string",
|
|
15
|
-
description: "What capability to find, e.g. `send slack message`, `create calendar event`, `zapier gmail`, or `browser screenshot`. Omit to list every available tool name (the full menu) with one-line descriptions.",
|
|
16
|
+
description: "What capability to find, e.g. `send slack message`, `create calendar event`, `zapier gmail`, or `browser screenshot`. Omit to list every available tool name (the full menu) with one-line descriptions; then call tool-search again with a specific query before calling a tool from that menu.",
|
|
16
17
|
},
|
|
17
18
|
limit: {
|
|
18
19
|
type: "number",
|
|
@@ -44,12 +45,39 @@ export function searchToolRegistry(registry, args = {}, options = {}) {
|
|
|
44
45
|
const listAll = query.length === 0;
|
|
45
46
|
const includeSchemas = !listAll && parseBoolean(args.includeSchemas);
|
|
46
47
|
const limit = parseLimit(args.limit, options.defaultLimit ?? DEFAULT_LIMIT, options.maxLimit ?? MAX_LIMIT);
|
|
48
|
+
const cacheKey = normalizeToolSearchCacheKey({
|
|
49
|
+
query,
|
|
50
|
+
limit,
|
|
51
|
+
includeSchemas,
|
|
52
|
+
});
|
|
53
|
+
const runCtx = getRequestRunContext();
|
|
54
|
+
const priorSearch = includeSchemas
|
|
55
|
+
? undefined
|
|
56
|
+
: runCtx?.toolSearchReads?.[cacheKey];
|
|
57
|
+
if (priorSearch) {
|
|
58
|
+
return {
|
|
59
|
+
query,
|
|
60
|
+
totalTools: priorSearch.totalTools,
|
|
61
|
+
count: priorSearch.resultNames.length,
|
|
62
|
+
repeated: true,
|
|
63
|
+
message: "This exact tool-search query already ran in this agent run. Use the previously returned schemas/details instead of searching again.",
|
|
64
|
+
results: priorSearch.resultNames.map((name) => ({
|
|
65
|
+
name,
|
|
66
|
+
kind: parseMcpToolName(name) ? "mcp" : "action",
|
|
67
|
+
score: 0,
|
|
68
|
+
description: "Already returned by an earlier identical tool-search call.",
|
|
69
|
+
parameters: [],
|
|
70
|
+
})),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
47
73
|
const queryTokens = tokenize(query);
|
|
48
74
|
const candidates = [];
|
|
49
75
|
let totalTools = 0;
|
|
50
76
|
for (const [name, entry] of Object.entries(registry)) {
|
|
51
77
|
if (!entry?.tool || name === TOOL_SEARCH_ACTION_NAME)
|
|
52
78
|
continue;
|
|
79
|
+
if (entry.agentTool === false)
|
|
80
|
+
continue;
|
|
53
81
|
if (name.startsWith("mcp__") && !isMcpToolAllowedForRequest(name)) {
|
|
54
82
|
continue;
|
|
55
83
|
}
|
|
@@ -93,19 +121,47 @@ export function searchToolRegistry(registry, args = {}, options = {}) {
|
|
|
93
121
|
}
|
|
94
122
|
if (listAll) {
|
|
95
123
|
candidates.sort((a, b) => a.name.localeCompare(b.name));
|
|
96
|
-
|
|
124
|
+
const result = {
|
|
125
|
+
query,
|
|
126
|
+
totalTools,
|
|
127
|
+
count: candidates.length,
|
|
128
|
+
message: 'Menu mode lists tool names only; it does not load schemas for calling. Before invoking a tool found here, call tool-search again with a specific query such as the tool name or capability (for example, { "query": "hubspot-deals" }).',
|
|
129
|
+
results: candidates,
|
|
130
|
+
};
|
|
131
|
+
rememberToolSearchResult(cacheKey, result);
|
|
132
|
+
return result;
|
|
97
133
|
}
|
|
98
134
|
candidates.sort((a, b) => {
|
|
99
135
|
if (b.score !== a.score)
|
|
100
136
|
return b.score - a.score;
|
|
101
137
|
return a.name.localeCompare(b.name);
|
|
102
138
|
});
|
|
103
|
-
|
|
139
|
+
const result = {
|
|
104
140
|
query,
|
|
105
141
|
totalTools,
|
|
106
142
|
count: Math.min(candidates.length, limit),
|
|
107
143
|
results: candidates.slice(0, limit),
|
|
108
144
|
};
|
|
145
|
+
if (!includeSchemas)
|
|
146
|
+
rememberToolSearchResult(cacheKey, result);
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
function normalizeToolSearchCacheKey(options) {
|
|
150
|
+
return JSON.stringify({
|
|
151
|
+
query: options.query.trim().toLowerCase(),
|
|
152
|
+
limit: options.limit,
|
|
153
|
+
includeSchemas: options.includeSchemas,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function rememberToolSearchResult(cacheKey, result) {
|
|
157
|
+
const runCtx = getRequestRunContext();
|
|
158
|
+
if (!runCtx)
|
|
159
|
+
return;
|
|
160
|
+
const reads = (runCtx.toolSearchReads ??= {});
|
|
161
|
+
reads[cacheKey] = {
|
|
162
|
+
totalTools: result.totalTools,
|
|
163
|
+
resultNames: result.results.map((item) => item.name),
|
|
164
|
+
};
|
|
109
165
|
}
|
|
110
166
|
function truncate(value, max) {
|
|
111
167
|
if (value.length <= max)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-search.js","sourceRoot":"","sources":["../../src/agent/tool-search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAGzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AA+BrD,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,MAAM,UAAU,qBAAqB,CACnC,WAA8C,EAC9C,OAAO,GAAsB,EAAE;IAE/B,OAAO;QACL,IAAI,EAAE;YACJ,WAAW,EACT,wfAAwf;YAC1f,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,WAAW,EACT,0MAA0M;qBAC7M;oBACD,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,sDAAsD,OAAO,CAAC,YAAY,IAAI,aAAa,kDAAkD;qBAC3J;oBACD,cAAc,EAAE;wBACd,IAAI,EAAE,SAAS;wBACf,WAAW,EACT,2EAA2E;qBAC9E;iBACF;aACF;SACF;QACD,IAAI,EAAE,KAAK;QACX,QAAQ,EAAE,IAAI;QACd,GAAG,EAAE,KAAK,EAAE,IAA4B,EAAE,EAAE,CAC1C,kBAAkB,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,QAAqC,EACrC,OAAO,GAAsB,EAAE;IAE/B,QAAQ,CAAC,uBAAuB,CAAC,GA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":["import { parseMcpToolName } from \"../mcp-client/manager.js\";\nimport { isMcpToolAllowedForRequest } from \"../mcp-client/visibility.js\";\nimport type { ActionEntry } from \"./production-agent.js\";\n\nexport const TOOL_SEARCH_ACTION_NAME = \"tool-search\";\n\ntype ToolSearchArgs = {\n query?: unknown;\n limit?: unknown;\n includeSchemas?: unknown;\n};\n\ntype ToolParameterSummary = {\n name: string;\n type?: string;\n required: boolean;\n description?: string;\n enum?: string[];\n};\n\ntype ToolSearchResult = {\n name: string;\n kind: \"action\" | \"mcp\";\n source?: string;\n description: string;\n score: number;\n parameters: ToolParameterSummary[];\n inputSchema?: unknown;\n};\n\ntype ToolSearchOptions = {\n defaultLimit?: number;\n maxLimit?: number;\n};\n\nconst DEFAULT_LIMIT = 8;\nconst MAX_LIMIT = 25;\n\nexport function createToolSearchEntry(\n getRegistry: () => Record<string, ActionEntry>,\n options: ToolSearchOptions = {},\n): ActionEntry {\n return {\n tool: {\n description:\n \"Discover callable tools/actions, including connected MCP server tools named `mcp__<server>__<tool>`. Call it with NO query to list every available tool by name with a one-line description (cheap — no input schemas) so you can see the full menu of what exists; pass a `query` to find specific tools and get their parameter summaries. Use this whenever you need a capability but aren't sure which tool to call — most tools are not loaded into context up front, so this is how you find and then call them.\",\n parameters: {\n type: \"object\",\n properties: {\n query: {\n type: \"string\",\n description:\n \"What capability to find, e.g. `send slack message`, `create calendar event`, `zapier gmail`, or `browser screenshot`. Omit to list every available tool name (the full menu) with one-line descriptions.\",\n },\n limit: {\n type: \"number\",\n description: `Maximum results to return for a query. Defaults to ${options.defaultLimit ?? DEFAULT_LIMIT}. Ignored when listing the full menu (no query).`,\n },\n includeSchemas: {\n type: \"boolean\",\n description:\n \"When true, include each matching tool's full input schema. Default false.\",\n },\n },\n },\n },\n http: false,\n readOnly: true,\n run: async (args: Record<string, string>) =>\n searchToolRegistry(getRegistry(), args, options),\n };\n}\n\nexport function attachToolSearch(\n registry: Record<string, ActionEntry>,\n options: ToolSearchOptions = {},\n): Record<string, ActionEntry> {\n registry[TOOL_SEARCH_ACTION_NAME] = createToolSearchEntry(\n () => registry,\n options,\n );\n return registry;\n}\n\nexport function searchToolRegistry(\n registry: Record<string, ActionEntry>,\n args: ToolSearchArgs = {},\n options: ToolSearchOptions = {},\n): {\n query: string;\n totalTools: number;\n count: number;\n results: ToolSearchResult[];\n} {\n const query = String(args.query ?? \"\").trim();\n // No query → \"menu\" mode: list every available tool by name + a terse\n // description, with no parameter summaries or input schemas. This is the\n // cheap, non-opaque counterpart to the compact catalog: the agent can see\n // the full set of tools for a small token cost, then search/load the few it\n // actually needs. A query switches to ranked search with parameter details.\n const listAll = query.length === 0;\n const includeSchemas = !listAll && parseBoolean(args.includeSchemas);\n const limit = parseLimit(\n args.limit,\n options.defaultLimit ?? DEFAULT_LIMIT,\n options.maxLimit ?? MAX_LIMIT,\n );\n const queryTokens = tokenize(query);\n\n const candidates: ToolSearchResult[] = [];\n let totalTools = 0;\n\n for (const [name, entry] of Object.entries(registry)) {\n if (!entry?.tool || name === TOOL_SEARCH_ACTION_NAME) continue;\n if (name.startsWith(\"mcp__\") && !isMcpToolAllowedForRequest(name)) {\n continue;\n }\n\n totalTools++;\n const description = normalizeWhitespace(entry.tool.description ?? \"\");\n const parsedMcp = parseMcpToolName(name);\n const kind = parsedMcp ? \"mcp\" : \"action\";\n const source = parsedMcp?.serverId;\n\n if (listAll) {\n candidates.push({\n name,\n kind,\n ...(source ? { source } : {}),\n description: truncate(description, 140),\n score: 0,\n parameters: [],\n });\n continue;\n }\n\n const parameters = summarizeParameters(entry.tool.parameters);\n const score = scoreTool({\n query,\n queryTokens,\n name,\n source,\n description,\n parameters,\n kind,\n });\n\n if (score <= 0) continue;\n\n candidates.push({\n name,\n kind,\n ...(source ? { source } : {}),\n description,\n score,\n parameters,\n ...(includeSchemas ? { inputSchema: entry.tool.parameters ?? {} } : {}),\n });\n }\n\n if (listAll) {\n candidates.sort((a, b) => a.name.localeCompare(b.name));\n return { query, totalTools, count: candidates.length, results: candidates };\n }\n\n candidates.sort((a, b) => {\n if (b.score !== a.score) return b.score - a.score;\n return a.name.localeCompare(b.name);\n });\n\n return {\n query,\n totalTools,\n count: Math.min(candidates.length, limit),\n results: candidates.slice(0, limit),\n };\n}\n\nfunction truncate(value: string, max: number): string {\n if (value.length <= max) return value;\n return `${value.slice(0, max - 1).trimEnd()}…`;\n}\n\nfunction parseLimit(value: unknown, fallback: number, max: number): number {\n const n =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\" && value.trim()\n ? Number(value)\n : fallback;\n if (!Number.isFinite(n) || n <= 0) return fallback;\n return Math.max(1, Math.min(max, Math.floor(n)));\n}\n\nfunction parseBoolean(value: unknown): boolean {\n if (typeof value === \"boolean\") return value;\n if (typeof value !== \"string\") return false;\n const normalized = value.trim().toLowerCase();\n return normalized === \"true\" || normalized === \"1\" || normalized === \"yes\";\n}\n\nfunction summarizeParameters(schema: unknown): ToolParameterSummary[] {\n if (!schema || typeof schema !== \"object\") return [];\n const obj = schema as {\n properties?: Record<string, unknown>;\n required?: unknown;\n };\n const properties = obj.properties;\n if (!properties || typeof properties !== \"object\") return [];\n const required = new Set(\n Array.isArray(obj.required)\n ? obj.required.filter(\n (value): value is string => typeof value === \"string\",\n )\n : [],\n );\n\n return Object.entries(properties).map(([name, raw]) => {\n const prop =\n raw && typeof raw === \"object\" ? (raw as Record<string, unknown>) : {};\n const enumValues = Array.isArray(prop.enum)\n ? prop.enum.map((value) => String(value)).slice(0, 20)\n : undefined;\n return {\n name,\n type: summarizeType(prop.type),\n required: required.has(name),\n description:\n typeof prop.description === \"string\"\n ? normalizeWhitespace(prop.description)\n : undefined,\n ...(enumValues && enumValues.length > 0 ? { enum: enumValues } : {}),\n };\n });\n}\n\nfunction summarizeType(value: unknown): string | undefined {\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) {\n const parts = value.filter((v): v is string => typeof v === \"string\");\n return parts.length > 0 ? parts.join(\" | \") : undefined;\n }\n return undefined;\n}\n\nfunction scoreTool(input: {\n query: string;\n queryTokens: string[];\n name: string;\n source?: string;\n description: string;\n parameters: ToolParameterSummary[];\n kind: \"action\" | \"mcp\";\n}): number {\n if (input.queryTokens.length === 0) return 1;\n\n const name = searchableText(input.name);\n const source = searchableText(input.source ?? \"\");\n const description = searchableText(input.description);\n const params = searchableText(\n input.parameters\n .map((p) => `${p.name} ${p.type ?? \"\"} ${p.description ?? \"\"}`)\n .join(\" \"),\n );\n const all = `${name} ${source} ${description} ${params} ${input.kind}`;\n const phrase = searchableText(input.query);\n\n let score = 0;\n if (name.includes(phrase)) score += 14;\n if (source && source.includes(phrase)) score += 10;\n if (description.includes(phrase)) score += 8;\n if (params.includes(phrase)) score += 5;\n\n for (const token of input.queryTokens) {\n if (name.split(\" \").includes(token)) score += 9;\n else if (name.includes(token)) score += 6;\n\n if (source) {\n if (source.split(\" \").includes(token)) score += 6;\n else if (source.includes(token)) score += 3;\n }\n\n if (description.includes(token)) score += 3;\n if (params.includes(token)) score += 2;\n if (all.includes(token)) score += 1;\n }\n\n return score;\n}\n\nfunction tokenize(value: string): string[] {\n const seen = new Set<string>();\n for (const token of searchableText(value).split(\" \")) {\n if (token.length > 0) seen.add(token);\n }\n return Array.from(seen);\n}\n\nfunction searchableText(value: string): string {\n return value\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \" \")\n .trim();\n}\n\nfunction normalizeWhitespace(value: string): string {\n return value.replace(/\\s+/g, \" \").trim();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-search.js","sourceRoot":"","sources":["../../src/agent/tool-search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;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CAAC,IAAI,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import { parseMcpToolName } from \"../mcp-client/manager.js\";\nimport { isMcpToolAllowedForRequest } from \"../mcp-client/visibility.js\";\nimport { getRequestRunContext } from \"../server/request-context.js\";\nimport type { ActionEntry } from \"./production-agent.js\";\n\nexport const TOOL_SEARCH_ACTION_NAME = \"tool-search\";\n\ntype ToolSearchArgs = {\n query?: unknown;\n limit?: unknown;\n includeSchemas?: unknown;\n};\n\ntype ToolParameterSummary = {\n name: string;\n type?: string;\n required: boolean;\n description?: string;\n enum?: string[];\n};\n\ntype ToolSearchResult = {\n name: string;\n kind: \"action\" | \"mcp\";\n source?: string;\n description: string;\n score: number;\n parameters: ToolParameterSummary[];\n inputSchema?: unknown;\n};\n\ntype ToolSearchOptions = {\n defaultLimit?: number;\n maxLimit?: number;\n};\n\nconst DEFAULT_LIMIT = 8;\nconst MAX_LIMIT = 25;\n\nexport function createToolSearchEntry(\n getRegistry: () => Record<string, ActionEntry>,\n options: ToolSearchOptions = {},\n): ActionEntry {\n return {\n tool: {\n description:\n \"Discover callable tools/actions, including connected MCP server tools named `mcp__<server>__<tool>`. Call it with NO query to list every available tool by name with a one-line description (cheap — no input schemas); names from that menu are not loaded for calling yet, so call tool-search again with a specific query for the tool/capability before invoking it. Use this whenever you need a capability but aren't sure which tool to call — most tools are not loaded into context up front, so this is how you find and then call them.\",\n parameters: {\n type: \"object\",\n properties: {\n query: {\n type: \"string\",\n description:\n \"What capability to find, e.g. `send slack message`, `create calendar event`, `zapier gmail`, or `browser screenshot`. Omit to list every available tool name (the full menu) with one-line descriptions; then call tool-search again with a specific query before calling a tool from that menu.\",\n },\n limit: {\n type: \"number\",\n description: `Maximum results to return for a query. Defaults to ${options.defaultLimit ?? DEFAULT_LIMIT}. Ignored when listing the full menu (no query).`,\n },\n includeSchemas: {\n type: \"boolean\",\n description:\n \"When true, include each matching tool's full input schema. Default false.\",\n },\n },\n },\n },\n http: false,\n readOnly: true,\n run: async (args: Record<string, string>) =>\n searchToolRegistry(getRegistry(), args, options),\n };\n}\n\nexport function attachToolSearch(\n registry: Record<string, ActionEntry>,\n options: ToolSearchOptions = {},\n): Record<string, ActionEntry> {\n registry[TOOL_SEARCH_ACTION_NAME] = createToolSearchEntry(\n () => registry,\n options,\n );\n return registry;\n}\n\nexport function searchToolRegistry(\n registry: Record<string, ActionEntry>,\n args: ToolSearchArgs = {},\n options: ToolSearchOptions = {},\n): {\n query: string;\n totalTools: number;\n count: number;\n repeated?: boolean;\n message?: string;\n results: ToolSearchResult[];\n} {\n const query = String(args.query ?? \"\").trim();\n // No query → \"menu\" mode: list every available tool by name + a terse\n // description, with no parameter summaries or input schemas. This is the\n // cheap, non-opaque counterpart to the compact catalog: the agent can see\n // the full set of tools for a small token cost, then search/load the few it\n // actually needs. A query switches to ranked search with parameter details.\n const listAll = query.length === 0;\n const includeSchemas = !listAll && parseBoolean(args.includeSchemas);\n const limit = parseLimit(\n args.limit,\n options.defaultLimit ?? DEFAULT_LIMIT,\n options.maxLimit ?? MAX_LIMIT,\n );\n const cacheKey = normalizeToolSearchCacheKey({\n query,\n limit,\n includeSchemas,\n });\n const runCtx = getRequestRunContext();\n const priorSearch = includeSchemas\n ? undefined\n : runCtx?.toolSearchReads?.[cacheKey];\n if (priorSearch) {\n return {\n query,\n totalTools: priorSearch.totalTools,\n count: priorSearch.resultNames.length,\n repeated: true,\n message:\n \"This exact tool-search query already ran in this agent run. Use the previously returned schemas/details instead of searching again.\",\n results: priorSearch.resultNames.map((name) => ({\n name,\n kind: parseMcpToolName(name) ? (\"mcp\" as const) : (\"action\" as const),\n score: 0,\n description:\n \"Already returned by an earlier identical tool-search call.\",\n parameters: [],\n })),\n };\n }\n const queryTokens = tokenize(query);\n\n const candidates: ToolSearchResult[] = [];\n let totalTools = 0;\n\n for (const [name, entry] of Object.entries(registry)) {\n if (!entry?.tool || name === TOOL_SEARCH_ACTION_NAME) continue;\n if (entry.agentTool === false) continue;\n if (name.startsWith(\"mcp__\") && !isMcpToolAllowedForRequest(name)) {\n continue;\n }\n\n totalTools++;\n const description = normalizeWhitespace(entry.tool.description ?? \"\");\n const parsedMcp = parseMcpToolName(name);\n const kind = parsedMcp ? \"mcp\" : \"action\";\n const source = parsedMcp?.serverId;\n\n if (listAll) {\n candidates.push({\n name,\n kind,\n ...(source ? { source } : {}),\n description: truncate(description, 140),\n score: 0,\n parameters: [],\n });\n continue;\n }\n\n const parameters = summarizeParameters(entry.tool.parameters);\n const score = scoreTool({\n query,\n queryTokens,\n name,\n source,\n description,\n parameters,\n kind,\n });\n\n if (score <= 0) continue;\n\n candidates.push({\n name,\n kind,\n ...(source ? { source } : {}),\n description,\n score,\n parameters,\n ...(includeSchemas ? { inputSchema: entry.tool.parameters ?? {} } : {}),\n });\n }\n\n if (listAll) {\n candidates.sort((a, b) => a.name.localeCompare(b.name));\n const result = {\n query,\n totalTools,\n count: candidates.length,\n message:\n 'Menu mode lists tool names only; it does not load schemas for calling. Before invoking a tool found here, call tool-search again with a specific query such as the tool name or capability (for example, { \"query\": \"hubspot-deals\" }).',\n results: candidates,\n };\n rememberToolSearchResult(cacheKey, result);\n return result;\n }\n\n candidates.sort((a, b) => {\n if (b.score !== a.score) return b.score - a.score;\n return a.name.localeCompare(b.name);\n });\n\n const result = {\n query,\n totalTools,\n count: Math.min(candidates.length, limit),\n results: candidates.slice(0, limit),\n };\n if (!includeSchemas) rememberToolSearchResult(cacheKey, result);\n return result;\n}\n\nfunction normalizeToolSearchCacheKey(options: {\n query: string;\n limit: number;\n includeSchemas: boolean;\n}): string {\n return JSON.stringify({\n query: options.query.trim().toLowerCase(),\n limit: options.limit,\n includeSchemas: options.includeSchemas,\n });\n}\n\nfunction rememberToolSearchResult(\n cacheKey: string,\n result: { totalTools: number; results: Array<{ name: string }> },\n) {\n const runCtx = getRequestRunContext();\n if (!runCtx) return;\n const reads = (runCtx.toolSearchReads ??= {});\n reads[cacheKey] = {\n totalTools: result.totalTools,\n resultNames: result.results.map((item) => item.name),\n };\n}\n\nfunction truncate(value: string, max: number): string {\n if (value.length <= max) return value;\n return `${value.slice(0, max - 1).trimEnd()}…`;\n}\n\nfunction parseLimit(value: unknown, fallback: number, max: number): number {\n const n =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\" && value.trim()\n ? Number(value)\n : fallback;\n if (!Number.isFinite(n) || n <= 0) return fallback;\n return Math.max(1, Math.min(max, Math.floor(n)));\n}\n\nfunction parseBoolean(value: unknown): boolean {\n if (typeof value === \"boolean\") return value;\n if (typeof value !== \"string\") return false;\n const normalized = value.trim().toLowerCase();\n return normalized === \"true\" || normalized === \"1\" || normalized === \"yes\";\n}\n\nfunction summarizeParameters(schema: unknown): ToolParameterSummary[] {\n if (!schema || typeof schema !== \"object\") return [];\n const obj = schema as {\n properties?: Record<string, unknown>;\n required?: unknown;\n };\n const properties = obj.properties;\n if (!properties || typeof properties !== \"object\") return [];\n const required = new Set(\n Array.isArray(obj.required)\n ? obj.required.filter(\n (value): value is string => typeof value === \"string\",\n )\n : [],\n );\n\n return Object.entries(properties).map(([name, raw]) => {\n const prop =\n raw && typeof raw === \"object\" ? (raw as Record<string, unknown>) : {};\n const enumValues = Array.isArray(prop.enum)\n ? prop.enum.map((value) => String(value)).slice(0, 20)\n : undefined;\n return {\n name,\n type: summarizeType(prop.type),\n required: required.has(name),\n description:\n typeof prop.description === \"string\"\n ? normalizeWhitespace(prop.description)\n : undefined,\n ...(enumValues && enumValues.length > 0 ? { enum: enumValues } : {}),\n };\n });\n}\n\nfunction summarizeType(value: unknown): string | undefined {\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) {\n const parts = value.filter((v): v is string => typeof v === \"string\");\n return parts.length > 0 ? parts.join(\" | \") : undefined;\n }\n return undefined;\n}\n\nfunction scoreTool(input: {\n query: string;\n queryTokens: string[];\n name: string;\n source?: string;\n description: string;\n parameters: ToolParameterSummary[];\n kind: \"action\" | \"mcp\";\n}): number {\n if (input.queryTokens.length === 0) return 1;\n\n const name = searchableText(input.name);\n const source = searchableText(input.source ?? \"\");\n const description = searchableText(input.description);\n const params = searchableText(\n input.parameters\n .map((p) => `${p.name} ${p.type ?? \"\"} ${p.description ?? \"\"}`)\n .join(\" \"),\n );\n const all = `${name} ${source} ${description} ${params} ${input.kind}`;\n const phrase = searchableText(input.query);\n\n let score = 0;\n if (name.includes(phrase)) score += 14;\n if (source && source.includes(phrase)) score += 10;\n if (description.includes(phrase)) score += 8;\n if (params.includes(phrase)) score += 5;\n\n for (const token of input.queryTokens) {\n if (name.split(\" \").includes(token)) score += 9;\n else if (name.includes(token)) score += 6;\n\n if (source) {\n if (source.split(\" \").includes(token)) score += 6;\n else if (source.includes(token)) score += 3;\n }\n\n if (description.includes(token)) score += 3;\n if (params.includes(token)) score += 2;\n if (all.includes(token)) score += 1;\n }\n\n return score;\n}\n\nfunction tokenize(value: string): string[] {\n const seen = new Set<string>();\n for (const token of searchableText(value).split(\" \")) {\n if (token.length > 0) seen.add(token);\n }\n return Array.from(seen);\n}\n\nfunction searchableText(value: string): string {\n return value\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \" \")\n .trim();\n}\n\nfunction normalizeWhitespace(value: string): string {\n return value.replace(/\\s+/g, \" \").trim();\n}\n"]}
|
package/dist/cli/index.js
CHANGED
|
@@ -646,6 +646,20 @@ switch (command) {
|
|
|
646
646
|
.catch(handleScaffoldImportError);
|
|
647
647
|
break;
|
|
648
648
|
}
|
|
649
|
+
case "upgrade": {
|
|
650
|
+
// Bring an existing app/workspace to current @agent-native/* packages,
|
|
651
|
+
// refresh scaffold skills, and verify — without framework patches.
|
|
652
|
+
import("./upgrade.js")
|
|
653
|
+
.then(async (m) => {
|
|
654
|
+
const code = await m.runUpgrade(args);
|
|
655
|
+
process.exit(code);
|
|
656
|
+
})
|
|
657
|
+
.catch((err) => {
|
|
658
|
+
console.error(err?.message ?? err);
|
|
659
|
+
process.exit(1);
|
|
660
|
+
});
|
|
661
|
+
break;
|
|
662
|
+
}
|
|
649
663
|
case "code": {
|
|
650
664
|
import("./code.js")
|
|
651
665
|
.then((m) => m.runCode(args))
|
|
@@ -928,6 +942,11 @@ Usage:
|
|
|
928
942
|
local serve | local verify | local preview
|
|
929
943
|
agent-native migrate <source> Create an Agent-Native Code /migrate session, or use
|
|
930
944
|
--emit for a portable own-agent dossier.
|
|
945
|
+
agent-native upgrade Bring an existing app/workspace to current
|
|
946
|
+
@agent-native/* packages, refresh scaffold
|
|
947
|
+
skills, and typecheck. Prefer this over
|
|
948
|
+
patching core/dispatch. 'upgrade check' is
|
|
949
|
+
doctor-only.
|
|
931
950
|
agent-native add-app [name] Add one or more apps to the current workspace
|
|
932
951
|
agent-native workspace-dev Start the multi-app workspace gateway
|
|
933
952
|
agent-native deploy Build & deploy every app in the workspace to
|