buckyos 0.7.170 → 0.7.175
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/cli/core/app.ts +2 -0
- package/cli/core/argv.ts +45 -239
- package/cli/core/command.ts +3 -35
- package/cli/dist/cli.mjs +2151 -673
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/agent.ts +3 -1
- package/cli/modules/app.ts +13 -2
- package/cli/modules/pikg.ts +70 -1
- package/cli/modules/runtime.ts +497 -0
- package/cli/modules/skill.ts +583 -161
- package/cli/modules/skill_lint.ts +462 -0
- package/cli/version.ts +1 -1
- package/dist/account-7a7bde6f.mjs +105 -0
- package/dist/account-7a7bde6f.mjs.map +1 -0
- package/dist/account-b12ac6b9.js +2 -0
- package/dist/account-b12ac6b9.js.map +1 -0
- package/dist/aicc-67851c41.mjs +582 -0
- package/dist/aicc-67851c41.mjs.map +1 -0
- package/dist/aicc-ccb36ef7.js +2 -0
- package/dist/aicc-ccb36ef7.js.map +1 -0
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +204 -194
- package/dist/browser.mjs.map +1 -1
- package/dist/did_object_client-6a1b108a.js +2 -0
- package/dist/did_object_client-6a1b108a.js.map +1 -0
- package/dist/did_object_client-7fa36f90.mjs +87 -0
- package/dist/did_object_client-7fa36f90.mjs.map +1 -0
- package/dist/did_object_client.d.ts +39 -0
- package/dist/did_object_client.d.ts.map +1 -0
- package/dist/{executor_client-5f4d0468.mjs → executor_client-c620d25c.mjs} +233 -748
- package/dist/executor_client-c620d25c.mjs.map +1 -0
- package/dist/executor_client-d4439d54.js +13 -0
- package/dist/executor_client-d4439d54.js.map +1 -0
- package/dist/executor_client.d.ts +129 -0
- package/dist/executor_client.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +209 -199
- package/dist/index.mjs.map +1 -1
- package/dist/internal/command_args.d.ts +67 -0
- package/dist/internal/command_args.d.ts.map +1 -0
- package/dist/krpc_client-26c2dc8b.js +2 -0
- package/dist/krpc_client-26c2dc8b.js.map +1 -0
- package/dist/krpc_client-673448e5.mjs +173 -0
- package/dist/krpc_client-673448e5.mjs.map +1 -0
- package/dist/krpc_client.d.ts +5 -1
- package/dist/krpc_client.d.ts.map +1 -1
- package/dist/{ndn_types-ab30fac0.mjs → ndn_types-0fac2499.mjs} +115 -215
- package/dist/ndn_types-0fac2499.mjs.map +1 -0
- package/dist/ndn_types-5b138882.js +2 -0
- package/dist/ndn_types-5b138882.js.map +1 -0
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.mjs +201 -194
- package/dist/node.mjs.map +1 -1
- package/dist/object_url-8fb5a7bf.js +2 -0
- package/dist/object_url-8fb5a7bf.js.map +1 -0
- package/dist/object_url-f72c1704.mjs +412 -0
- package/dist/object_url-f72c1704.mjs.map +1 -0
- package/dist/openai-ae2978de.mjs +163 -0
- package/dist/openai-ae2978de.mjs.map +1 -0
- package/dist/openai-f560d518.js +2 -0
- package/dist/openai-f560d518.js.map +1 -0
- package/dist/provision.cjs +6 -6
- package/dist/provision.cjs.map +1 -1
- package/dist/provision.mjs +4 -3
- package/dist/provision.mjs.map +1 -1
- package/dist/site_manager-11a7a468.mjs +6410 -0
- package/dist/site_manager-11a7a468.mjs.map +1 -0
- package/dist/site_manager-334b1a51.js +2 -0
- package/dist/site_manager-334b1a51.js.map +1 -0
- package/dist/{tus_client-b231b248.js → tus_client-809c90ab.js} +2 -2
- package/dist/{tus_client-b231b248.js.map → tus_client-809c90ab.js.map} +1 -1
- package/dist/{tus_client-d1ffe2d6.mjs → tus_client-893a3287.mjs} +2 -2
- package/dist/{tus_client-d1ffe2d6.mjs.map → tus_client-893a3287.mjs.map} +1 -1
- package/dist/xllm/core/action_parser.d.ts +15 -0
- package/dist/xllm/core/action_parser.d.ts.map +1 -0
- package/dist/xllm/core/behavior_loop.d.ts +20 -0
- package/dist/xllm/core/behavior_loop.d.ts.map +1 -0
- package/dist/xllm/core/behavior_result.d.ts +11 -0
- package/dist/xllm/core/behavior_result.d.ts.map +1 -0
- package/dist/xllm/core/config.d.ts +62 -0
- package/dist/xllm/core/config.d.ts.map +1 -0
- package/dist/xllm/core/context_window.d.ts +15 -0
- package/dist/xllm/core/context_window.d.ts.map +1 -0
- package/dist/xllm/core/deps.d.ts +97 -0
- package/dist/xllm/core/deps.d.ts.map +1 -0
- package/dist/xllm/core/errors.d.ts +94 -0
- package/dist/xllm/core/errors.d.ts.map +1 -0
- package/dist/xllm/core/interrupt.d.ts +31 -0
- package/dist/xllm/core/interrupt.d.ts.map +1 -0
- package/dist/xllm/core/json.d.ts +11 -0
- package/dist/xllm/core/json.d.ts.map +1 -0
- package/dist/xllm/core/json_check.d.ts +17 -0
- package/dist/xllm/core/json_check.d.ts.map +1 -0
- package/dist/xllm/core/loop.d.ts +135 -0
- package/dist/xllm/core/loop.d.ts.map +1 -0
- package/dist/xllm/core/messages.d.ts +18 -0
- package/dist/xllm/core/messages.d.ts.map +1 -0
- package/dist/xllm/core/observer.d.ts +14 -0
- package/dist/xllm/core/observer.d.ts.map +1 -0
- package/dist/xllm/core/open_runtime.d.ts +22 -0
- package/dist/xllm/core/open_runtime.d.ts.map +1 -0
- package/dist/xllm/core/prepare.d.ts +54 -0
- package/dist/xllm/core/prepare.d.ts.map +1 -0
- package/dist/xllm/core/prompt.d.ts +40 -0
- package/dist/xllm/core/prompt.d.ts.map +1 -0
- package/dist/xllm/core/protocol.d.ts +15 -0
- package/dist/xllm/core/protocol.d.ts.map +1 -0
- package/dist/xllm/core/result.d.ts +12 -0
- package/dist/xllm/core/result.d.ts.map +1 -0
- package/dist/xllm/core/run.d.ts +198 -0
- package/dist/xllm/core/run.d.ts.map +1 -0
- package/dist/xllm/core/rust_text.d.ts +20 -0
- package/dist/xllm/core/rust_text.d.ts.map +1 -0
- package/dist/xllm/core/site_policy.d.ts +5 -0
- package/dist/xllm/core/site_policy.d.ts.map +1 -0
- package/dist/xllm/core/store.d.ts +60 -0
- package/dist/xllm/core/store.d.ts.map +1 -0
- package/dist/xllm/core/suspension.d.ts +13 -0
- package/dist/xllm/core/suspension.d.ts.map +1 -0
- package/dist/xllm/core/tokenizer.d.ts +8 -0
- package/dist/xllm/core/tokenizer.d.ts.map +1 -0
- package/dist/xllm/core/types.d.ts +826 -0
- package/dist/xllm/core/types.d.ts.map +1 -0
- package/dist/xllm/core/xml.d.ts +19 -0
- package/dist/xllm/core/xml.d.ts.map +1 -0
- package/dist/xllm/dev/openai.d.ts +17 -0
- package/dist/xllm/dev/openai.d.ts.map +1 -0
- package/dist/xllm/dev/scripted.d.ts +46 -0
- package/dist/xllm/dev/scripted.d.ts.map +1 -0
- package/dist/xllm/dev.d.ts +5 -0
- package/dist/xllm/dev.d.ts.map +1 -0
- package/dist/xllm/hosts/browser/store.d.ts +41 -0
- package/dist/xllm/hosts/browser/store.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/deno_api.d.ts +103 -0
- package/dist/xllm/hosts/deno/deno_api.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/identity.d.ts +29 -0
- package/dist/xllm/hosts/deno/identity.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/index.d.ts +47 -0
- package/dist/xllm/hosts/deno/index.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/native_runtime.d.ts +93 -0
- package/dist/xllm/hosts/deno/native_runtime.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/native_tools.d.ts +105 -0
- package/dist/xllm/hosts/deno/native_tools.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/provider.d.ts +13 -0
- package/dist/xllm/hosts/deno/provider.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/store.d.ts +60 -0
- package/dist/xllm/hosts/deno/store.d.ts.map +1 -0
- package/dist/xllm/index.d.ts +48 -0
- package/dist/xllm/index.d.ts.map +1 -0
- package/dist/xllm/providers/aicc.d.ts +22 -0
- package/dist/xllm/providers/aicc.d.ts.map +1 -0
- package/dist/xllm/providers/timeout.d.ts +12 -0
- package/dist/xllm/providers/timeout.d.ts.map +1 -0
- package/dist/xllm/runtime/compress.d.ts +149 -0
- package/dist/xllm/runtime/compress.d.ts.map +1 -0
- package/dist/xllm/runtime/did_object_resources.d.ts +21 -0
- package/dist/xllm/runtime/did_object_resources.d.ts.map +1 -0
- package/dist/xllm/runtime/hints.d.ts +23 -0
- package/dist/xllm/runtime/hints.d.ts.map +1 -0
- package/dist/xllm/runtime/site.d.ts +22 -0
- package/dist/xllm/runtime/site.d.ts.map +1 -0
- package/dist/xllm/runtime/site_manager.d.ts +38 -0
- package/dist/xllm/runtime/site_manager.d.ts.map +1 -0
- package/dist/xllm/runtime/site_tools.d.ts +76 -0
- package/dist/xllm/runtime/site_tools.d.ts.map +1 -0
- package/dist/xllm/runtime/step_renderer.d.ts +54 -0
- package/dist/xllm/runtime/step_renderer.d.ts.map +1 -0
- package/dist/xllm/runtime/task_model.d.ts +64 -0
- package/dist/xllm/runtime/task_model.d.ts.map +1 -0
- package/dist/xllm/runtime/tool_result.d.ts +39 -0
- package/dist/xllm/runtime/tool_result.d.ts.map +1 -0
- package/dist/xllm/runtime/types.d.ts +99 -0
- package/dist/xllm/runtime/types.d.ts.map +1 -0
- package/dist/xllm.cjs +2 -0
- package/dist/xllm.cjs.map +1 -0
- package/dist/xllm.mjs +1167 -0
- package/dist/xllm.mjs.map +1 -0
- package/dist/xllm_deno.cjs +2 -0
- package/dist/xllm_deno.cjs.map +1 -0
- package/dist/xllm_deno.mjs +2487 -0
- package/dist/xllm_deno.mjs.map +1 -0
- package/dist/xllm_dev.cjs +2 -0
- package/dist/xllm_dev.cjs.map +1 -0
- package/dist/xllm_dev.mjs +70 -0
- package/dist/xllm_dev.mjs.map +1 -0
- package/package.json +22 -1
- package/src/internal/command_args.ts +268 -0
- package/dist/executor_client-1ee523cf.js +0 -13
- package/dist/executor_client-1ee523cf.js.map +0 -1
- package/dist/executor_client-5f4d0468.mjs.map +0 -1
- package/dist/ndn_types-8c2696d5.js +0 -2
- package/dist/ndn_types-8c2696d5.js.map +0 -1
- package/dist/ndn_types-ab30fac0.mjs.map +0 -1
package/cli/dist/cli.mjs
CHANGED
|
@@ -13,9 +13,6 @@ import { createInterface } from "node:readline/promises";
|
|
|
13
13
|
import { Readable } from "node:stream";
|
|
14
14
|
import { pipeline } from "node:stream/promises";
|
|
15
15
|
import { createGzip, constants } from "node:zlib";
|
|
16
|
-
function optionProperty(option) {
|
|
17
|
-
return option.property ?? option.name.replaceAll("-", "_");
|
|
18
|
-
}
|
|
19
16
|
const EXIT_SUCCESS = 0;
|
|
20
17
|
const EXIT_USAGE = 2;
|
|
21
18
|
const EXIT_AUTH = 3;
|
|
@@ -26,8 +23,8 @@ const EXIT_PARTIAL = 7;
|
|
|
26
23
|
const EXIT_TIMEOUT = 8;
|
|
27
24
|
const EXIT_INTERNAL = 9;
|
|
28
25
|
class ToolError extends Error {
|
|
29
|
-
constructor(code,
|
|
30
|
-
super(
|
|
26
|
+
constructor(code, message2, exitCode = EXIT_OPERATION, retryable = false, details = {}) {
|
|
27
|
+
super(message2);
|
|
31
28
|
this.name = "ToolError";
|
|
32
29
|
this.code = code;
|
|
33
30
|
this.exitCode = exitCode;
|
|
@@ -36,15 +33,15 @@ class ToolError extends Error {
|
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
class UsageError extends ToolError {
|
|
39
|
-
constructor(code,
|
|
40
|
-
super(code,
|
|
36
|
+
constructor(code, message2, details = {}) {
|
|
37
|
+
super(code, message2, EXIT_USAGE, false, details);
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
const JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
|
|
44
41
|
const URL_CREDENTIAL_PATTERN = /(\w+:\/\/)[^\s/@:]+:[^\s/@]+@/g;
|
|
45
42
|
const DATABASE_URI_PATTERN = /\b(?:postgres(?:ql)?|mysql|mariadb|mongodb(?:\+srv)?|redis|rediss|sqlite):\/\/[^\s,;]+/gi;
|
|
46
|
-
function sanitizeMessage(
|
|
47
|
-
return
|
|
43
|
+
function sanitizeMessage(message2) {
|
|
44
|
+
return message2.replaceAll(JWT_PATTERN, "[REDACTED_TOKEN]").replaceAll(URL_CREDENTIAL_PATTERN, "$1[REDACTED]@").replaceAll(DATABASE_URI_PATTERN, "[REDACTED_DATABASE_URI]").replace(
|
|
48
45
|
/(session[_-]?token|refresh[_-]?token|access[_-]?token|private[_-]?key|password|passwd|api[_-]?key|client[_-]?secret|secret)\s*[=:]\s*[^\s,;]+/gi,
|
|
49
46
|
"$1=[REDACTED]"
|
|
50
47
|
);
|
|
@@ -60,8 +57,8 @@ function normalizeError(error) {
|
|
|
60
57
|
);
|
|
61
58
|
}
|
|
62
59
|
const raw = error instanceof Error ? error.message : String(error);
|
|
63
|
-
const
|
|
64
|
-
const lower =
|
|
60
|
+
const message2 = sanitizeMessage(raw);
|
|
61
|
+
const lower = message2.toLowerCase();
|
|
65
62
|
if (lower.includes("abort") || lower.includes("cancel")) {
|
|
66
63
|
return new ToolError("CANCELED", "operation canceled", EXIT_TIMEOUT);
|
|
67
64
|
}
|
|
@@ -69,117 +66,75 @@ function normalizeError(error) {
|
|
|
69
66
|
return new ToolError("TIMEOUT", "operation timed out", EXIT_TIMEOUT, true);
|
|
70
67
|
}
|
|
71
68
|
if (lower.includes("permission denied") || lower.includes("no permission") || lower.includes("rpc call error: 403")) {
|
|
72
|
-
return new ToolError("PERMISSION_DENIED",
|
|
69
|
+
return new ToolError("PERMISSION_DENIED", message2, EXIT_PERMISSION);
|
|
73
70
|
}
|
|
74
71
|
if (lower.includes("rpc call error: 401") || lower.includes("unauthorized") || lower.includes("token expired") || lower.includes("session expired") || lower.includes("invalid token")) {
|
|
75
72
|
return new ToolError(
|
|
76
73
|
lower.includes("expired") ? "SESSION_EXPIRED" : "INVALID_SESSION",
|
|
77
|
-
lower.includes("expired") ? "the session token has expired" :
|
|
74
|
+
lower.includes("expired") ? "the session token has expired" : message2,
|
|
78
75
|
EXIT_AUTH
|
|
79
76
|
);
|
|
80
77
|
}
|
|
81
78
|
if (lower.includes("fetch failed") || lower.includes("connection refused") || lower.includes("rpc call error: 502") || lower.includes("rpc call error: 503") || lower.includes("rpc call error: 504")) {
|
|
82
|
-
return new ToolError("SERVICE_UNAVAILABLE",
|
|
79
|
+
return new ToolError("SERVICE_UNAVAILABLE", message2, EXIT_UNAVAILABLE, true);
|
|
83
80
|
}
|
|
84
81
|
if (lower.includes("not found") || lower.includes("key not exist")) {
|
|
85
|
-
return new ToolError("RESOURCE_NOT_FOUND",
|
|
82
|
+
return new ToolError("RESOURCE_NOT_FOUND", message2, EXIT_OPERATION);
|
|
86
83
|
}
|
|
87
84
|
if (lower.includes("rpc call error:")) {
|
|
88
|
-
return new ToolError("OPERATION_FAILED",
|
|
85
|
+
return new ToolError("OPERATION_FAILED", message2, EXIT_OPERATION);
|
|
89
86
|
}
|
|
90
|
-
return new ToolError("INTERNAL_ERROR",
|
|
87
|
+
return new ToolError("INTERNAL_ERROR", message2 || "internal error", EXIT_INTERNAL);
|
|
91
88
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
["endpoint", "endpoint"],
|
|
98
|
-
["identity", "identity"],
|
|
99
|
-
["session-token", "sessionToken"],
|
|
100
|
-
["session-token-file", "sessionTokenFile"],
|
|
101
|
-
["output", "output"],
|
|
102
|
-
["input", "input"],
|
|
103
|
-
["timeout", "timeout"],
|
|
104
|
-
["trace-id", "traceId"],
|
|
105
|
-
["idempotency-key", "idempotencyKey"]
|
|
106
|
-
]);
|
|
107
|
-
const REPEATABLE_STRING_GLOBALS = /* @__PURE__ */ new Map([
|
|
108
|
-
["allow-read", "allowRead"]
|
|
109
|
-
]);
|
|
110
|
-
const BOOLEAN_GLOBALS = /* @__PURE__ */ new Map([
|
|
111
|
-
["cli", "cli"],
|
|
112
|
-
["wait", "wait"],
|
|
113
|
-
["non-interactive", "nonInteractive"],
|
|
114
|
-
["yes", "yes"],
|
|
115
|
-
["no-color", "noColor"],
|
|
116
|
-
["verbose", "verbose"],
|
|
117
|
-
["help", "help"],
|
|
118
|
-
["version", "version"]
|
|
119
|
-
]);
|
|
120
|
-
const REPL_SCOPED_STRING_GLOBALS = /* @__PURE__ */ new Set([
|
|
121
|
-
"input",
|
|
122
|
-
"timeout",
|
|
123
|
-
"trace-id",
|
|
124
|
-
"idempotency-key",
|
|
125
|
-
"output"
|
|
126
|
-
]);
|
|
127
|
-
const REPL_SCOPED_BOOLEAN_GLOBALS = /* @__PURE__ */ new Set(["wait", "yes"]);
|
|
128
|
-
function parseInvocation(argv) {
|
|
129
|
-
const global = {};
|
|
130
|
-
let index = 0;
|
|
131
|
-
while (index < argv.length) {
|
|
132
|
-
const token = argv[index];
|
|
133
|
-
if (token === "-h") {
|
|
134
|
-
setGlobal(global, "help", true);
|
|
135
|
-
index += 1;
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
if (token === "--") {
|
|
139
|
-
index += 1;
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
if (!token.startsWith("--"))
|
|
143
|
-
break;
|
|
144
|
-
const parsed = splitLongOption(token);
|
|
145
|
-
const booleanProperty = BOOLEAN_GLOBALS.get(parsed.name);
|
|
146
|
-
if (booleanProperty) {
|
|
147
|
-
if (parsed.inlineValue !== void 0) {
|
|
148
|
-
throw new UsageError("INVALID_ARGUMENT", `--${parsed.name} does not accept a value`);
|
|
149
|
-
}
|
|
150
|
-
setGlobal(global, booleanProperty, true);
|
|
151
|
-
index += 1;
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
const stringProperty = STRING_GLOBALS.get(parsed.name);
|
|
155
|
-
const repeatableStringProperty = REPEATABLE_STRING_GLOBALS.get(parsed.name);
|
|
156
|
-
if (!stringProperty && !repeatableStringProperty) {
|
|
157
|
-
throw new UsageError("UNKNOWN_OPTION", `unknown global option: --${parsed.name}`);
|
|
158
|
-
}
|
|
159
|
-
const { value, consumed } = readOptionValue(argv, index, parsed);
|
|
160
|
-
if (repeatableStringProperty === "allowRead") {
|
|
161
|
-
global.allowRead = [...global.allowRead ?? [], value];
|
|
162
|
-
} else {
|
|
163
|
-
setGlobal(global, stringProperty, normalizeGlobalValue(parsed.name, value));
|
|
164
|
-
}
|
|
165
|
-
index += consumed;
|
|
89
|
+
class CommandArgsError extends Error {
|
|
90
|
+
constructor(code, message2) {
|
|
91
|
+
super(message2);
|
|
92
|
+
this.name = "CommandArgsError";
|
|
93
|
+
this.code = code;
|
|
166
94
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
95
|
+
}
|
|
96
|
+
function hasOwn(o, key) {
|
|
97
|
+
return Object.prototype.hasOwnProperty.call(o, key);
|
|
98
|
+
}
|
|
99
|
+
function optionProperty(option) {
|
|
100
|
+
return option.property ?? option.name.split("-").join("_");
|
|
101
|
+
}
|
|
102
|
+
function splitLongOption(token) {
|
|
103
|
+
const content = token.slice(2);
|
|
104
|
+
const equalIndex = content.indexOf("=");
|
|
105
|
+
return equalIndex < 0 ? { name: content } : { name: content.slice(0, equalIndex), inlineValue: content.slice(equalIndex + 1) };
|
|
106
|
+
}
|
|
107
|
+
function readOptionValue$1(argv, index, option) {
|
|
108
|
+
if (option.inlineValue !== void 0) {
|
|
109
|
+
if (!option.inlineValue)
|
|
110
|
+
throw new CommandArgsError("MISSING_ARGUMENT", `--${option.name} requires a value`);
|
|
111
|
+
return { value: option.inlineValue, consumed: 1 };
|
|
175
112
|
}
|
|
176
|
-
|
|
113
|
+
const value = argv[index + 1];
|
|
114
|
+
if (value === void 0 || value.startsWith("--"))
|
|
115
|
+
throw new CommandArgsError("MISSING_ARGUMENT", `--${option.name} requires a value`);
|
|
116
|
+
return { value, consumed: 2 };
|
|
177
117
|
}
|
|
178
|
-
function
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const
|
|
182
|
-
|
|
118
|
+
function parseOptionValue(type, value, name) {
|
|
119
|
+
if (type === "string")
|
|
120
|
+
return value;
|
|
121
|
+
const number = Number(value);
|
|
122
|
+
if (!Number.isFinite(number) || type === "integer" && !Number.isInteger(number)) {
|
|
123
|
+
throw new CommandArgsError("INVALID_ARGUMENT", `--${name} requires a ${type}`);
|
|
124
|
+
}
|
|
125
|
+
return number;
|
|
126
|
+
}
|
|
127
|
+
function assignPositional(input, positionals, index, value) {
|
|
128
|
+
const positional = positionals[index];
|
|
129
|
+
if (!positional)
|
|
130
|
+
throw new CommandArgsError("TOO_MANY_ARGUMENTS", `unexpected positional argument: ${value}`);
|
|
131
|
+
input[positional.name] = value;
|
|
132
|
+
return index + 1;
|
|
133
|
+
}
|
|
134
|
+
function parseArgv(spec, argv, beforeOption) {
|
|
135
|
+
const input = {};
|
|
136
|
+
const positionals = spec.positionals ?? [];
|
|
137
|
+
const optionByName = new Map((spec.options ?? []).map((o) => [o.name, o]));
|
|
183
138
|
let positionalIndex = 0;
|
|
184
139
|
let help = false;
|
|
185
140
|
for (let index = 0; index < argv.length; ) {
|
|
@@ -190,90 +145,57 @@ function parseCommandArgs(command, argv, inputObject, allowReplScopedGlobals = f
|
|
|
190
145
|
continue;
|
|
191
146
|
}
|
|
192
147
|
if (token === "--") {
|
|
193
|
-
for (const
|
|
194
|
-
positionalIndex = assignPositional(
|
|
195
|
-
cliInput,
|
|
196
|
-
positionals,
|
|
197
|
-
positionalIndex,
|
|
198
|
-
positionalValue
|
|
199
|
-
);
|
|
200
|
-
}
|
|
148
|
+
for (const value2 of argv.slice(index + 1))
|
|
149
|
+
positionalIndex = assignPositional(input, positionals, positionalIndex, value2);
|
|
201
150
|
break;
|
|
202
151
|
}
|
|
203
152
|
if (!token.startsWith("--")) {
|
|
204
|
-
positionalIndex = assignPositional(
|
|
153
|
+
positionalIndex = assignPositional(input, positionals, positionalIndex, token);
|
|
205
154
|
index += 1;
|
|
206
155
|
continue;
|
|
207
156
|
}
|
|
208
157
|
const parsed = splitLongOption(token);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
const property2 = BOOLEAN_GLOBALS.get(parsed.name);
|
|
214
|
-
setGlobal(scoped, property2, true);
|
|
215
|
-
index += 1;
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
if (allowReplScopedGlobals && REPL_SCOPED_STRING_GLOBALS.has(parsed.name)) {
|
|
219
|
-
const property2 = STRING_GLOBALS.get(parsed.name);
|
|
220
|
-
const { value: value2, consumed: consumed2 } = readOptionValue(argv, index, parsed);
|
|
221
|
-
setGlobal(scoped, property2, normalizeGlobalValue(parsed.name, value2));
|
|
222
|
-
index += consumed2;
|
|
158
|
+
const handled = beforeOption?.(parsed, argv, index);
|
|
159
|
+
if (handled !== void 0) {
|
|
160
|
+
index += handled;
|
|
223
161
|
continue;
|
|
224
162
|
}
|
|
225
|
-
if (allowReplScopedGlobals && (STRING_GLOBALS.has(parsed.name) || REPEATABLE_STRING_GLOBALS.has(parsed.name) || BOOLEAN_GLOBALS.has(parsed.name))) {
|
|
226
|
-
throw new UsageError(
|
|
227
|
-
"SESSION_OPTION_FROZEN",
|
|
228
|
-
`--${parsed.name} is frozen for the interactive session`
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
163
|
const option = optionByName.get(parsed.name);
|
|
232
164
|
if (!option)
|
|
233
|
-
throw new
|
|
165
|
+
throw new CommandArgsError("UNKNOWN_OPTION", `unknown option: --${parsed.name}`);
|
|
234
166
|
const property = optionProperty(option);
|
|
235
|
-
if (
|
|
236
|
-
throw new
|
|
237
|
-
}
|
|
167
|
+
if (hasOwn(input, property))
|
|
168
|
+
throw new CommandArgsError("DUPLICATE_ARGUMENT", `argument provided more than once: ${property}`);
|
|
238
169
|
if (option.type === "boolean") {
|
|
239
|
-
if (parsed.inlineValue !== void 0)
|
|
240
|
-
throw new
|
|
241
|
-
|
|
242
|
-
cliInput[property] = true;
|
|
170
|
+
if (parsed.inlineValue !== void 0)
|
|
171
|
+
throw new CommandArgsError("INVALID_ARGUMENT", `--${parsed.name} does not accept a value`);
|
|
172
|
+
input[property] = true;
|
|
243
173
|
index += 1;
|
|
244
174
|
continue;
|
|
245
175
|
}
|
|
246
|
-
const { value, consumed } = readOptionValue(argv, index, parsed);
|
|
247
|
-
|
|
176
|
+
const { value, consumed } = readOptionValue$1(argv, index, parsed);
|
|
177
|
+
input[property] = parseOptionValue(option.type, value, parsed.name);
|
|
248
178
|
index += consumed;
|
|
249
179
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
);
|
|
180
|
+
return { input, help, positionalCount: positionalIndex };
|
|
181
|
+
}
|
|
182
|
+
function checkRequiredPositionals(positionals, positionalCount, inputObject) {
|
|
183
|
+
for (let index = positionalCount; index < positionals.length; index++) {
|
|
184
|
+
if (positionals[index].required !== false && !hasOwn(inputObject ?? {}, positionals[index].name)) {
|
|
185
|
+
throw new CommandArgsError("MISSING_ARGUMENT", `missing positional argument: ${positionals[index].name}`);
|
|
256
186
|
}
|
|
257
187
|
}
|
|
258
|
-
const input = mergeCommandInput(inputObject, cliInput);
|
|
259
|
-
if (!deferValidation)
|
|
260
|
-
validateSchema(input, command.inputSchema, "input");
|
|
261
|
-
return { input, scoped, help };
|
|
262
188
|
}
|
|
263
|
-
function
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const scale = match[2] === "ms" ? 1 : match[2] === "s" ? 1e3 : match[2] === "m" ? 6e4 : 36e5;
|
|
270
|
-
const result = amount * scale;
|
|
271
|
-
if (!Number.isSafeInteger(result) || result <= 0) {
|
|
272
|
-
throw new UsageError("INVALID_DURATION", `invalid duration: ${value}`);
|
|
189
|
+
function mergeCommandInput(inputObject, cliInput) {
|
|
190
|
+
const result = { ...inputObject ?? {} };
|
|
191
|
+
for (const [key, value] of Object.entries(cliInput)) {
|
|
192
|
+
if (hasOwn(result, key))
|
|
193
|
+
throw new CommandArgsError("ARGUMENT_CONFLICT", `${key} is present in both --input and argv`);
|
|
194
|
+
result[key] = value;
|
|
273
195
|
}
|
|
274
196
|
return result;
|
|
275
197
|
}
|
|
276
|
-
function parseShellLine(line) {
|
|
198
|
+
function parseShellLine$1(line) {
|
|
277
199
|
const tokens = [];
|
|
278
200
|
let current = "";
|
|
279
201
|
let quote = null;
|
|
@@ -327,116 +249,214 @@ function parseShellLine(line) {
|
|
|
327
249
|
started = true;
|
|
328
250
|
}
|
|
329
251
|
if (escaped)
|
|
330
|
-
throw new
|
|
252
|
+
throw new CommandArgsError("INVALID_COMMAND_LINE", "unfinished escape sequence");
|
|
331
253
|
if (quote)
|
|
332
|
-
throw new
|
|
254
|
+
throw new CommandArgsError("INVALID_COMMAND_LINE", `unterminated ${quote} quote`);
|
|
333
255
|
if (started)
|
|
334
256
|
tokens.push(current);
|
|
335
257
|
return tokens;
|
|
336
258
|
}
|
|
337
|
-
function validateSchema(value, schema, path) {
|
|
259
|
+
function validateSchema$1(value, schema, path) {
|
|
338
260
|
if (schema.enum && !schema.enum.some((candidate) => Object.is(candidate, value))) {
|
|
339
|
-
throw new
|
|
340
|
-
"SCHEMA_VALIDATION_FAILED",
|
|
341
|
-
`${path} must be one of ${schema.enum.join(", ")}`
|
|
342
|
-
);
|
|
261
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path} must be one of ${schema.enum.join(", ")}`);
|
|
343
262
|
}
|
|
344
263
|
if (schema.type === "object") {
|
|
345
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
346
|
-
throw new
|
|
347
|
-
}
|
|
264
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
265
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path} must be an object`);
|
|
348
266
|
const object2 = value;
|
|
349
267
|
for (const required of schema.required ?? []) {
|
|
350
|
-
if (!
|
|
351
|
-
throw new
|
|
352
|
-
}
|
|
268
|
+
if (!hasOwn(object2, required))
|
|
269
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path}.${required} is required`);
|
|
353
270
|
}
|
|
354
271
|
if (schema.additionalProperties === false) {
|
|
355
272
|
for (const key of Object.keys(object2)) {
|
|
356
|
-
if (!
|
|
357
|
-
throw new
|
|
358
|
-
}
|
|
273
|
+
if (!hasOwn(schema.properties ?? {}, key))
|
|
274
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path}.${key} is not allowed`);
|
|
359
275
|
}
|
|
360
276
|
}
|
|
361
277
|
for (const [key, propertyValue] of Object.entries(object2)) {
|
|
362
278
|
const propertySchema = schema.properties?.[key];
|
|
363
279
|
if (propertySchema)
|
|
364
|
-
validateSchema(propertyValue, propertySchema, `${path}.${key}`);
|
|
280
|
+
validateSchema$1(propertyValue, propertySchema, `${path}.${key}`);
|
|
365
281
|
}
|
|
366
282
|
return;
|
|
367
283
|
}
|
|
368
284
|
if (schema.type === "array") {
|
|
369
|
-
if (!Array.isArray(value))
|
|
370
|
-
throw new
|
|
371
|
-
|
|
372
|
-
if (
|
|
373
|
-
value.forEach((item, index) => validateSchema(item,
|
|
374
|
-
}
|
|
285
|
+
if (!Array.isArray(value))
|
|
286
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path} must be an array`);
|
|
287
|
+
const items = schema.items;
|
|
288
|
+
if (items)
|
|
289
|
+
value.forEach((item, index) => validateSchema$1(item, items, `${path}[${index}]`));
|
|
375
290
|
return;
|
|
376
291
|
}
|
|
377
292
|
if (schema.type === "string") {
|
|
378
|
-
if (typeof value !== "string")
|
|
379
|
-
throw new
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
throw new UsageError("SCHEMA_VALIDATION_FAILED", `${path} is too short`);
|
|
383
|
-
}
|
|
293
|
+
if (typeof value !== "string")
|
|
294
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path} must be a string`);
|
|
295
|
+
if (schema.minLength !== void 0 && value.length < schema.minLength)
|
|
296
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path} is too short`);
|
|
384
297
|
return;
|
|
385
298
|
}
|
|
386
|
-
if (schema.type === "boolean" && typeof value !== "boolean")
|
|
387
|
-
throw new
|
|
388
|
-
}
|
|
299
|
+
if (schema.type === "boolean" && typeof value !== "boolean")
|
|
300
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path} must be a boolean`);
|
|
389
301
|
if (schema.type === "integer" && (!Number.isInteger(value) || typeof value !== "number")) {
|
|
390
|
-
throw new
|
|
391
|
-
}
|
|
392
|
-
if (schema.type === "number" && typeof value !== "number") {
|
|
393
|
-
throw new UsageError("SCHEMA_VALIDATION_FAILED", `${path} must be a number`);
|
|
302
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path} must be an integer`);
|
|
394
303
|
}
|
|
304
|
+
if (schema.type === "number" && typeof value !== "number")
|
|
305
|
+
throw new CommandArgsError("SCHEMA_VALIDATION_FAILED", `${path} must be a number`);
|
|
395
306
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
307
|
+
const OUTPUT_FORMATS = ["json", "jsonl", "table", "text", "raw"];
|
|
308
|
+
const STRING_GLOBALS = /* @__PURE__ */ new Map([
|
|
309
|
+
["config-dir", "configDir"],
|
|
310
|
+
["profile", "profile"],
|
|
311
|
+
["zone", "zone"],
|
|
312
|
+
["endpoint", "endpoint"],
|
|
313
|
+
["identity", "identity"],
|
|
314
|
+
["session-token", "sessionToken"],
|
|
315
|
+
["session-token-file", "sessionTokenFile"],
|
|
316
|
+
["output", "output"],
|
|
317
|
+
["input", "input"],
|
|
318
|
+
["timeout", "timeout"],
|
|
319
|
+
["trace-id", "traceId"],
|
|
320
|
+
["idempotency-key", "idempotencyKey"]
|
|
321
|
+
]);
|
|
322
|
+
const REPEATABLE_STRING_GLOBALS = /* @__PURE__ */ new Map([
|
|
323
|
+
["allow-read", "allowRead"]
|
|
324
|
+
]);
|
|
325
|
+
const BOOLEAN_GLOBALS = /* @__PURE__ */ new Map([
|
|
326
|
+
["cli", "cli"],
|
|
327
|
+
["wait", "wait"],
|
|
328
|
+
["non-interactive", "nonInteractive"],
|
|
329
|
+
["yes", "yes"],
|
|
330
|
+
["no-color", "noColor"],
|
|
331
|
+
["verbose", "verbose"],
|
|
332
|
+
["help", "help"],
|
|
333
|
+
["version", "version"]
|
|
334
|
+
]);
|
|
335
|
+
const REPL_SCOPED_STRING_GLOBALS = /* @__PURE__ */ new Set([
|
|
336
|
+
"input",
|
|
337
|
+
"timeout",
|
|
338
|
+
"trace-id",
|
|
339
|
+
"idempotency-key",
|
|
340
|
+
"output"
|
|
341
|
+
]);
|
|
342
|
+
const REPL_SCOPED_BOOLEAN_GLOBALS = /* @__PURE__ */ new Set(["wait", "yes"]);
|
|
343
|
+
function parseInvocation(argv) {
|
|
344
|
+
const global = {};
|
|
345
|
+
let index = 0;
|
|
346
|
+
while (index < argv.length) {
|
|
347
|
+
const token = argv[index];
|
|
348
|
+
if (token === "-h") {
|
|
349
|
+
setGlobal(global, "help", true);
|
|
350
|
+
index += 1;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (token === "--") {
|
|
354
|
+
index += 1;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
if (!token.startsWith("--"))
|
|
358
|
+
break;
|
|
359
|
+
const parsed = splitLongOption(token);
|
|
360
|
+
const booleanProperty = BOOLEAN_GLOBALS.get(parsed.name);
|
|
361
|
+
if (booleanProperty) {
|
|
362
|
+
if (parsed.inlineValue !== void 0) {
|
|
363
|
+
throw new UsageError("INVALID_ARGUMENT", `--${parsed.name} does not accept a value`);
|
|
364
|
+
}
|
|
365
|
+
setGlobal(global, booleanProperty, true);
|
|
366
|
+
index += 1;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
const stringProperty = STRING_GLOBALS.get(parsed.name);
|
|
370
|
+
const repeatableStringProperty = REPEATABLE_STRING_GLOBALS.get(parsed.name);
|
|
371
|
+
if (!stringProperty && !repeatableStringProperty) {
|
|
372
|
+
throw new UsageError("UNKNOWN_OPTION", `unknown global option: --${parsed.name}`);
|
|
373
|
+
}
|
|
374
|
+
const { value, consumed } = readOptionValue(argv, index, parsed);
|
|
375
|
+
if (repeatableStringProperty === "allowRead") {
|
|
376
|
+
global.allowRead = [...global.allowRead ?? [], value];
|
|
377
|
+
} else {
|
|
378
|
+
setGlobal(global, stringProperty, normalizeGlobalValue(parsed.name, value));
|
|
379
|
+
}
|
|
380
|
+
index += consumed;
|
|
400
381
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
382
|
+
const module = argv[index];
|
|
383
|
+
const verb = argv[index + 1];
|
|
384
|
+
const actionArgv = module ? argv.slice(index + (verb ? 2 : 1)) : [];
|
|
385
|
+
if (module?.startsWith("-")) {
|
|
386
|
+
throw new UsageError(
|
|
387
|
+
"INVALID_ARGUMENT",
|
|
388
|
+
`global options must appear before the module: ${module}`
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
return { global, module, verb, actionArgv };
|
|
408
392
|
}
|
|
409
|
-
function
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
393
|
+
function parseCommandArgs(command2, argv, inputObject, allowReplScopedGlobals = false, deferValidation = false) {
|
|
394
|
+
const scoped = {};
|
|
395
|
+
const replScoped = (parsed, args, index) => {
|
|
396
|
+
if (!allowReplScopedGlobals)
|
|
397
|
+
return void 0;
|
|
398
|
+
if (REPL_SCOPED_BOOLEAN_GLOBALS.has(parsed.name)) {
|
|
399
|
+
if (parsed.inlineValue !== void 0) {
|
|
400
|
+
throw new UsageError("INVALID_ARGUMENT", `--${parsed.name} does not accept a value`);
|
|
401
|
+
}
|
|
402
|
+
setGlobal(scoped, BOOLEAN_GLOBALS.get(parsed.name), true);
|
|
403
|
+
return 1;
|
|
413
404
|
}
|
|
414
|
-
|
|
405
|
+
if (REPL_SCOPED_STRING_GLOBALS.has(parsed.name)) {
|
|
406
|
+
const property = STRING_GLOBALS.get(parsed.name);
|
|
407
|
+
const { value, consumed } = readOptionValue(args, index, parsed);
|
|
408
|
+
setGlobal(scoped, property, normalizeGlobalValue(parsed.name, value));
|
|
409
|
+
return consumed;
|
|
410
|
+
}
|
|
411
|
+
if (STRING_GLOBALS.has(parsed.name) || REPEATABLE_STRING_GLOBALS.has(parsed.name) || BOOLEAN_GLOBALS.has(parsed.name)) {
|
|
412
|
+
throw new UsageError(
|
|
413
|
+
"SESSION_OPTION_FROZEN",
|
|
414
|
+
`--${parsed.name} is frozen for the interactive session`
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
return void 0;
|
|
418
|
+
};
|
|
419
|
+
return usage(() => {
|
|
420
|
+
const parsed = parseArgv(command2, argv, replScoped);
|
|
421
|
+
if (!deferValidation) {
|
|
422
|
+
checkRequiredPositionals(command2.positionals ?? [], parsed.positionalCount, inputObject);
|
|
423
|
+
}
|
|
424
|
+
const input = mergeCommandInput(inputObject, parsed.input);
|
|
425
|
+
if (!deferValidation)
|
|
426
|
+
validateSchema$1(input, command2.inputSchema, "input");
|
|
427
|
+
return { input, scoped, help: parsed.help };
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
function parseDuration(value) {
|
|
431
|
+
const match = /^(\d+)(ms|s|m|h)$/.exec(value.trim());
|
|
432
|
+
if (!match) {
|
|
433
|
+
throw new UsageError("INVALID_DURATION", `invalid duration: ${value}`);
|
|
415
434
|
}
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
435
|
+
const amount = Number(match[1]);
|
|
436
|
+
const scale = match[2] === "ms" ? 1 : match[2] === "s" ? 1e3 : match[2] === "m" ? 6e4 : 36e5;
|
|
437
|
+
const result = amount * scale;
|
|
438
|
+
if (!Number.isSafeInteger(result) || result <= 0) {
|
|
439
|
+
throw new UsageError("INVALID_DURATION", `invalid duration: ${value}`);
|
|
419
440
|
}
|
|
420
|
-
return
|
|
441
|
+
return result;
|
|
421
442
|
}
|
|
422
|
-
function
|
|
423
|
-
|
|
424
|
-
return value;
|
|
425
|
-
const number = Number(value);
|
|
426
|
-
if (!Number.isFinite(number) || type === "integer" && !Number.isInteger(number)) {
|
|
427
|
-
throw new UsageError("INVALID_ARGUMENT", `--${name} requires a ${type}`);
|
|
428
|
-
}
|
|
429
|
-
return number;
|
|
443
|
+
function parseShellLine(line) {
|
|
444
|
+
return usage(() => parseShellLine$1(line));
|
|
430
445
|
}
|
|
431
|
-
function
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
446
|
+
function validateSchema(value, schema, path) {
|
|
447
|
+
usage(() => validateSchema$1(value, schema, path));
|
|
448
|
+
}
|
|
449
|
+
function usage(f) {
|
|
450
|
+
try {
|
|
451
|
+
return f();
|
|
452
|
+
} catch (error) {
|
|
453
|
+
if (error instanceof CommandArgsError)
|
|
454
|
+
throw new UsageError(error.code, error.message);
|
|
455
|
+
throw error;
|
|
438
456
|
}
|
|
439
|
-
|
|
457
|
+
}
|
|
458
|
+
function readOptionValue(argv, index, option) {
|
|
459
|
+
return usage(() => readOptionValue$1(argv, index, option));
|
|
440
460
|
}
|
|
441
461
|
function normalizeGlobalValue(name, value) {
|
|
442
462
|
if (name === "output") {
|
|
@@ -454,8 +474,8 @@ function setGlobal(target, property, value) {
|
|
|
454
474
|
target[property] = value;
|
|
455
475
|
}
|
|
456
476
|
class HostError extends Error {
|
|
457
|
-
constructor(code,
|
|
458
|
-
super(
|
|
477
|
+
constructor(code, message2, path, cause) {
|
|
478
|
+
super(message2, { cause });
|
|
459
479
|
this.name = "HostError";
|
|
460
480
|
this.code = code;
|
|
461
481
|
this.path = path;
|
|
@@ -1076,8 +1096,8 @@ function redactUrl(value) {
|
|
|
1076
1096
|
return "[INVALID_URL]";
|
|
1077
1097
|
}
|
|
1078
1098
|
}
|
|
1079
|
-
function configValueError(
|
|
1080
|
-
return new ToolError("INVALID_CONFIG_VALUE",
|
|
1099
|
+
function configValueError(message2) {
|
|
1100
|
+
return new ToolError("INVALID_CONFIG_VALUE", message2, 2);
|
|
1081
1101
|
}
|
|
1082
1102
|
class BuckyOSRuntimeAdapter {
|
|
1083
1103
|
#sdk = new BuckyOSSDK("node");
|
|
@@ -2082,11 +2102,11 @@ function renderTable(data) {
|
|
|
2082
2102
|
function renderRows(rows) {
|
|
2083
2103
|
if (rows.length === 0)
|
|
2084
2104
|
return "(empty)";
|
|
2085
|
-
const
|
|
2105
|
+
const objects2 = rows.map(
|
|
2086
2106
|
(row) => row && typeof row === "object" && !Array.isArray(row) ? row : { value: row }
|
|
2087
2107
|
);
|
|
2088
|
-
const columns = [...new Set(
|
|
2089
|
-
const rendered =
|
|
2108
|
+
const columns = [...new Set(objects2.flatMap((row) => Object.keys(row)))];
|
|
2109
|
+
const rendered = objects2.map((row) => columns.map((column) => displayValue(row[column])));
|
|
2090
2110
|
const widths = columns.map(
|
|
2091
2111
|
(column, index) => Math.max(column.length, ...rendered.map((row) => row[index].length))
|
|
2092
2112
|
);
|
|
@@ -2197,14 +2217,14 @@ class CommandRegistry {
|
|
|
2197
2217
|
this.#modules.set(module.name, module);
|
|
2198
2218
|
}
|
|
2199
2219
|
get(module, verb) {
|
|
2200
|
-
const
|
|
2201
|
-
if (!
|
|
2220
|
+
const command2 = this.#commands.get(`${module}.${verb}`);
|
|
2221
|
+
if (!command2) {
|
|
2202
2222
|
if (!this.#modules.has(module)) {
|
|
2203
2223
|
throw new UsageError("UNKNOWN_MODULE", `unknown module: ${module}`);
|
|
2204
2224
|
}
|
|
2205
2225
|
throw new UsageError("UNKNOWN_COMMAND", `unknown command: ${module} ${verb}`);
|
|
2206
2226
|
}
|
|
2207
|
-
return
|
|
2227
|
+
return command2;
|
|
2208
2228
|
}
|
|
2209
2229
|
modules() {
|
|
2210
2230
|
return [...this.#modules.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -2215,42 +2235,42 @@ class CommandRegistry {
|
|
|
2215
2235
|
);
|
|
2216
2236
|
}
|
|
2217
2237
|
describe(module, verb) {
|
|
2218
|
-
const
|
|
2238
|
+
const command2 = this.get(module, verb);
|
|
2219
2239
|
return {
|
|
2220
2240
|
schema_version: 1,
|
|
2221
|
-
module:
|
|
2222
|
-
verb:
|
|
2223
|
-
summary:
|
|
2224
|
-
description:
|
|
2225
|
-
syntax: this.syntax(
|
|
2241
|
+
module: command2.module,
|
|
2242
|
+
verb: command2.verb,
|
|
2243
|
+
summary: command2.summary,
|
|
2244
|
+
description: command2.description ?? command2.summary,
|
|
2245
|
+
syntax: this.syntax(command2),
|
|
2226
2246
|
global_options: GLOBAL_OPTIONS,
|
|
2227
2247
|
repl_command_options: GLOBAL_OPTIONS.filter(
|
|
2228
2248
|
(option) => REPL_COMMAND_OPTION_NAMES.has(option.name)
|
|
2229
2249
|
),
|
|
2230
|
-
positionals:
|
|
2231
|
-
options: (
|
|
2250
|
+
positionals: command2.positionals ?? [],
|
|
2251
|
+
options: (command2.options ?? []).map((option) => ({
|
|
2232
2252
|
...option,
|
|
2233
2253
|
property: optionProperty(option)
|
|
2234
2254
|
})),
|
|
2235
|
-
input_schema:
|
|
2236
|
-
output_schema:
|
|
2237
|
-
result_schema_version:
|
|
2238
|
-
access:
|
|
2239
|
-
async_mode:
|
|
2240
|
-
requires_session:
|
|
2241
|
-
execution:
|
|
2242
|
-
network_access:
|
|
2243
|
-
examples:
|
|
2255
|
+
input_schema: command2.inputSchema,
|
|
2256
|
+
output_schema: command2.outputSchema,
|
|
2257
|
+
result_schema_version: command2.resultSchemaVersion,
|
|
2258
|
+
access: command2.access,
|
|
2259
|
+
async_mode: command2.asyncMode,
|
|
2260
|
+
requires_session: command2.requiresSession,
|
|
2261
|
+
execution: command2.execution ?? (command2.requiresSession ? "service" : "local"),
|
|
2262
|
+
network_access: command2.networkAccess ?? command2.requiresSession,
|
|
2263
|
+
examples: command2.examples ?? []
|
|
2244
2264
|
};
|
|
2245
2265
|
}
|
|
2246
|
-
syntax(
|
|
2247
|
-
const positionals = (
|
|
2266
|
+
syntax(command2) {
|
|
2267
|
+
const positionals = (command2.positionals ?? []).map(
|
|
2248
2268
|
(position) => position.required === false ? `[${position.name}]` : `<${position.name}>`
|
|
2249
2269
|
);
|
|
2250
|
-
const options = (
|
|
2270
|
+
const options = (command2.options ?? []).map(
|
|
2251
2271
|
(option) => option.type === "boolean" ? `[--${option.name}]` : `[--${option.name} <${option.property ?? option.name}>]`
|
|
2252
2272
|
);
|
|
2253
|
-
return ["buckyos",
|
|
2273
|
+
return ["buckyos", command2.module, command2.verb, ...positionals, ...options].join(" ");
|
|
2254
2274
|
}
|
|
2255
2275
|
completionCandidates(tokens) {
|
|
2256
2276
|
if (tokens.length <= 1)
|
|
@@ -2259,14 +2279,14 @@ class CommandRegistry {
|
|
|
2259
2279
|
if (!module)
|
|
2260
2280
|
return this.modules().map((candidate) => candidate.name);
|
|
2261
2281
|
if (tokens.length === 2 && !tokens[1].startsWith("--")) {
|
|
2262
|
-
return module.commands.map((
|
|
2282
|
+
return module.commands.map((command22) => command22.verb).sort();
|
|
2263
2283
|
}
|
|
2264
2284
|
const verb = tokens[1];
|
|
2265
|
-
const
|
|
2266
|
-
if (!
|
|
2285
|
+
const command2 = this.#commands.get(`${module.name}.${verb}`);
|
|
2286
|
+
if (!command2)
|
|
2267
2287
|
return module.commands.map((candidate) => candidate.verb).sort();
|
|
2268
2288
|
return [
|
|
2269
|
-
...(
|
|
2289
|
+
...(command2.options ?? []).map((option) => `--${option.name}`),
|
|
2270
2290
|
"--input",
|
|
2271
2291
|
"--timeout",
|
|
2272
2292
|
"--trace-id",
|
|
@@ -2306,7 +2326,7 @@ class CommandRegistry {
|
|
|
2306
2326
|
throw new Error(`${label} schema must be an object`);
|
|
2307
2327
|
}
|
|
2308
2328
|
}
|
|
2309
|
-
const SECRET_WORDS = /(?:session[-_]?token|refresh[-_]?token|password|private[-_]?key|sudo[-_]?token)/i;
|
|
2329
|
+
const SECRET_WORDS$1 = /(?:session[-_]?token|refresh[-_]?token|password|private[-_]?key|sudo[-_]?token)/i;
|
|
2310
2330
|
class ReplHistory {
|
|
2311
2331
|
constructor(path, limit = 500) {
|
|
2312
2332
|
this.#entries = [];
|
|
@@ -2327,8 +2347,8 @@ class ReplHistory {
|
|
|
2327
2347
|
entries() {
|
|
2328
2348
|
return [...this.#entries];
|
|
2329
2349
|
}
|
|
2330
|
-
async add(line,
|
|
2331
|
-
if (!shouldPersistHistory(line,
|
|
2350
|
+
async add(line, command2) {
|
|
2351
|
+
if (!shouldPersistHistory(line, command2))
|
|
2332
2352
|
return;
|
|
2333
2353
|
if (this.#entries.at(-1) !== line)
|
|
2334
2354
|
this.#entries.push(line);
|
|
@@ -2341,12 +2361,12 @@ class ReplHistory {
|
|
|
2341
2361
|
await host2.chmod(this.path, 384);
|
|
2342
2362
|
}
|
|
2343
2363
|
}
|
|
2344
|
-
function shouldPersistHistory(line,
|
|
2345
|
-
if (SECRET_WORDS.test(line))
|
|
2364
|
+
function shouldPersistHistory(line, command2) {
|
|
2365
|
+
if (SECRET_WORDS$1.test(line))
|
|
2346
2366
|
return false;
|
|
2347
|
-
if (!
|
|
2367
|
+
if (!command2)
|
|
2348
2368
|
return true;
|
|
2349
|
-
if (Object.values(
|
|
2369
|
+
if (Object.values(command2.inputSchema.properties ?? {}).some((schema) => schema.secret)) {
|
|
2350
2370
|
return false;
|
|
2351
2371
|
}
|
|
2352
2372
|
let tokens;
|
|
@@ -2356,7 +2376,7 @@ function shouldPersistHistory(line, command) {
|
|
|
2356
2376
|
return false;
|
|
2357
2377
|
}
|
|
2358
2378
|
const secretOptions = new Set(
|
|
2359
|
-
(
|
|
2379
|
+
(command2.options ?? []).filter((option) => option.secret).flatMap((option) => [
|
|
2360
2380
|
`--${option.name}`,
|
|
2361
2381
|
optionProperty(option)
|
|
2362
2382
|
])
|
|
@@ -2421,14 +2441,14 @@ async function runRepl(options) {
|
|
|
2421
2441
|
readline.prompt();
|
|
2422
2442
|
continue;
|
|
2423
2443
|
}
|
|
2424
|
-
let
|
|
2444
|
+
let command2;
|
|
2425
2445
|
try {
|
|
2426
2446
|
if (tokens.length >= 2)
|
|
2427
|
-
|
|
2447
|
+
command2 = options.registry.get(tokens[0], tokens[1]);
|
|
2428
2448
|
} catch {
|
|
2429
|
-
|
|
2449
|
+
command2 = void 0;
|
|
2430
2450
|
}
|
|
2431
|
-
await history.add(line,
|
|
2451
|
+
await history.add(line, command2);
|
|
2432
2452
|
running = new AbortController();
|
|
2433
2453
|
try {
|
|
2434
2454
|
await options.execute(tokens, running.signal);
|
|
@@ -2446,8 +2466,8 @@ async function runRepl(options) {
|
|
|
2446
2466
|
}
|
|
2447
2467
|
}
|
|
2448
2468
|
async function handleBuiltin(line, options, history) {
|
|
2449
|
-
const
|
|
2450
|
-
switch (
|
|
2469
|
+
const command2 = line.split(/\s+/, 1)[0];
|
|
2470
|
+
switch (command2) {
|
|
2451
2471
|
case ":exit":
|
|
2452
2472
|
case ":quit":
|
|
2453
2473
|
return true;
|
|
@@ -2488,7 +2508,7 @@ async function handleBuiltin(line, options, history) {
|
|
|
2488
2508
|
}
|
|
2489
2509
|
break;
|
|
2490
2510
|
default:
|
|
2491
|
-
await getHost().stderr(`unknown REPL command: ${
|
|
2511
|
+
await getHost().stderr(`unknown REPL command: ${command2}
|
|
2492
2512
|
`);
|
|
2493
2513
|
}
|
|
2494
2514
|
return false;
|
|
@@ -2500,7 +2520,7 @@ function replPrompt(config) {
|
|
|
2500
2520
|
return `buckyos[${profile}|${zone}|${identity}]> `;
|
|
2501
2521
|
}
|
|
2502
2522
|
const EMPTY_INPUT$3 = { type: "object", properties: {}, additionalProperties: false };
|
|
2503
|
-
const OBJECT_OUTPUT$
|
|
2523
|
+
const OBJECT_OUTPUT$h = { type: "object", additionalProperties: true };
|
|
2504
2524
|
function createAuthModule() {
|
|
2505
2525
|
return {
|
|
2506
2526
|
name: "auth",
|
|
@@ -2510,7 +2530,7 @@ function createAuthModule() {
|
|
|
2510
2530
|
verb: "whoami",
|
|
2511
2531
|
summary: "Show the effective principal and application identity",
|
|
2512
2532
|
inputSchema: EMPTY_INPUT$3,
|
|
2513
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2533
|
+
outputSchema: OBJECT_OUTPUT$h,
|
|
2514
2534
|
resultSchemaVersion: 1,
|
|
2515
2535
|
access: { mode: "fixed", level: "read" },
|
|
2516
2536
|
asyncMode: "sync",
|
|
@@ -2528,7 +2548,7 @@ function createAuthModule() {
|
|
|
2528
2548
|
verb: "session-status",
|
|
2529
2549
|
summary: "Show the in-memory session state without exposing credentials",
|
|
2530
2550
|
inputSchema: EMPTY_INPUT$3,
|
|
2531
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2551
|
+
outputSchema: OBJECT_OUTPUT$h,
|
|
2532
2552
|
resultSchemaVersion: 1,
|
|
2533
2553
|
access: { mode: "fixed", level: "read" },
|
|
2534
2554
|
asyncMode: "sync",
|
|
@@ -2549,7 +2569,7 @@ const EMPTY_INPUT$2 = {
|
|
|
2549
2569
|
properties: {},
|
|
2550
2570
|
additionalProperties: false
|
|
2551
2571
|
};
|
|
2552
|
-
const OBJECT_OUTPUT$
|
|
2572
|
+
const OBJECT_OUTPUT$g = { type: "object", additionalProperties: true };
|
|
2553
2573
|
function createCoreModules(registry) {
|
|
2554
2574
|
return [createCommandModule(registry), createConfigModule(), createCompletionModule(registry)];
|
|
2555
2575
|
}
|
|
@@ -2562,7 +2582,7 @@ function createCommandModule(registry) {
|
|
|
2562
2582
|
verb: "list",
|
|
2563
2583
|
summary: "List registered modules and commands",
|
|
2564
2584
|
inputSchema: EMPTY_INPUT$2,
|
|
2565
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2585
|
+
outputSchema: OBJECT_OUTPUT$g,
|
|
2566
2586
|
resultSchemaVersion: 1,
|
|
2567
2587
|
access: { mode: "fixed", level: "read" },
|
|
2568
2588
|
asyncMode: "sync",
|
|
@@ -2572,9 +2592,9 @@ function createCommandModule(registry) {
|
|
|
2572
2592
|
modules: registry.modules().map((module) => ({
|
|
2573
2593
|
name: module.name,
|
|
2574
2594
|
summary: module.summary,
|
|
2575
|
-
commands: module.commands.map((
|
|
2576
|
-
verb:
|
|
2577
|
-
summary:
|
|
2595
|
+
commands: module.commands.map((command2) => ({
|
|
2596
|
+
verb: command2.verb,
|
|
2597
|
+
summary: command2.summary
|
|
2578
2598
|
}))
|
|
2579
2599
|
}))
|
|
2580
2600
|
})
|
|
@@ -2595,7 +2615,7 @@ function createCommandModule(registry) {
|
|
|
2595
2615
|
required: ["target_module", "target_verb"],
|
|
2596
2616
|
additionalProperties: false
|
|
2597
2617
|
},
|
|
2598
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2618
|
+
outputSchema: OBJECT_OUTPUT$g,
|
|
2599
2619
|
resultSchemaVersion: 1,
|
|
2600
2620
|
access: { mode: "fixed", level: "read" },
|
|
2601
2621
|
asyncMode: "sync",
|
|
@@ -2617,7 +2637,7 @@ function createConfigModule() {
|
|
|
2617
2637
|
verb: "list",
|
|
2618
2638
|
summary: "List the global configuration and available profiles",
|
|
2619
2639
|
inputSchema: EMPTY_INPUT$2,
|
|
2620
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2640
|
+
outputSchema: OBJECT_OUTPUT$g,
|
|
2621
2641
|
resultSchemaVersion: 1,
|
|
2622
2642
|
access: { mode: "fixed", level: "read" },
|
|
2623
2643
|
asyncMode: "sync",
|
|
@@ -2648,7 +2668,7 @@ function createConfigModule() {
|
|
|
2648
2668
|
},
|
|
2649
2669
|
additionalProperties: false
|
|
2650
2670
|
},
|
|
2651
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2671
|
+
outputSchema: OBJECT_OUTPUT$g,
|
|
2652
2672
|
resultSchemaVersion: 1,
|
|
2653
2673
|
access: { mode: "fixed", level: "read" },
|
|
2654
2674
|
asyncMode: "sync",
|
|
@@ -2694,7 +2714,7 @@ function createConfigModule() {
|
|
|
2694
2714
|
required: ["key", "value"],
|
|
2695
2715
|
additionalProperties: false
|
|
2696
2716
|
},
|
|
2697
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2717
|
+
outputSchema: OBJECT_OUTPUT$g,
|
|
2698
2718
|
resultSchemaVersion: 1,
|
|
2699
2719
|
access: { mode: "fixed", level: "write" },
|
|
2700
2720
|
asyncMode: "sync",
|
|
@@ -2734,7 +2754,7 @@ function createConfigModule() {
|
|
|
2734
2754
|
required: ["profile_name"],
|
|
2735
2755
|
additionalProperties: false
|
|
2736
2756
|
},
|
|
2737
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2757
|
+
outputSchema: OBJECT_OUTPUT$g,
|
|
2738
2758
|
resultSchemaVersion: 1,
|
|
2739
2759
|
access: { mode: "fixed", level: "write" },
|
|
2740
2760
|
asyncMode: "sync",
|
|
@@ -2766,7 +2786,7 @@ function createConfigModule() {
|
|
|
2766
2786
|
properties: { effective: { type: "boolean" } },
|
|
2767
2787
|
additionalProperties: false
|
|
2768
2788
|
},
|
|
2769
|
-
outputSchema: OBJECT_OUTPUT$
|
|
2789
|
+
outputSchema: OBJECT_OUTPUT$g,
|
|
2770
2790
|
resultSchemaVersion: 1,
|
|
2771
2791
|
access: { mode: "fixed", level: "read" },
|
|
2772
2792
|
asyncMode: "sync",
|
|
@@ -2857,7 +2877,7 @@ function optionalString$4(value) {
|
|
|
2857
2877
|
}
|
|
2858
2878
|
function completionScript(registry, shell) {
|
|
2859
2879
|
const modules = registry.modules().map((module) => module.name).join(" ");
|
|
2860
|
-
const commands = registry.commands().map((
|
|
2880
|
+
const commands = registry.commands().map((command2) => `${command2.module}:${command2.verb}`).join(
|
|
2861
2881
|
" "
|
|
2862
2882
|
);
|
|
2863
2883
|
if (shell === "fish") {
|
|
@@ -2892,10 +2912,10 @@ async function callService(ctx, service, method, params) {
|
|
|
2892
2912
|
try {
|
|
2893
2913
|
return await ctx.clients.call(service, method, params, rpcOptions$2(ctx));
|
|
2894
2914
|
} catch (error) {
|
|
2895
|
-
const
|
|
2896
|
-
const stable =
|
|
2915
|
+
const message2 = error instanceof Error ? error.message : String(error);
|
|
2916
|
+
const stable = message2.match(/\b((?:TASK|AUDIT|DIAGNOSTIC|LOG)_[A-Z0-9_]+):/);
|
|
2897
2917
|
if (stable)
|
|
2898
|
-
throw new ToolError(stable[1],
|
|
2918
|
+
throw new ToolError(stable[1], message2);
|
|
2899
2919
|
throw error;
|
|
2900
2920
|
}
|
|
2901
2921
|
}
|
|
@@ -2944,7 +2964,7 @@ function splitServices(value) {
|
|
|
2944
2964
|
const items = Array.isArray(value) ? value : typeof value === "string" ? value.split(",") : [];
|
|
2945
2965
|
return [...new Set(items.map((item) => String(item).trim()).filter(Boolean))];
|
|
2946
2966
|
}
|
|
2947
|
-
const CONTROL_PANEL$
|
|
2967
|
+
const CONTROL_PANEL$5 = "control-panel";
|
|
2948
2968
|
const EMPTY_INPUT$1 = { type: "object", properties: {}, additionalProperties: false };
|
|
2949
2969
|
const BUCKYOS_INFO = {
|
|
2950
2970
|
type: "object",
|
|
@@ -2979,7 +2999,7 @@ function createSystemModule() {
|
|
|
2979
2999
|
examples: ["buckyos --profile production system status"],
|
|
2980
3000
|
handler: async (ctx) => {
|
|
2981
3001
|
const [status, buckyos2] = await Promise.all([
|
|
2982
|
-
callService(ctx, CONTROL_PANEL$
|
|
3002
|
+
callService(ctx, CONTROL_PANEL$5, "system.status", {}),
|
|
2983
3003
|
buckyosInfo(ctx)
|
|
2984
3004
|
]);
|
|
2985
3005
|
return { ...expectObject$4(status, "system.status"), buckyos: buckyos2 };
|
|
@@ -3003,12 +3023,12 @@ function createSystemModule() {
|
|
|
3003
3023
|
}
|
|
3004
3024
|
async function buckyosInfo(ctx) {
|
|
3005
3025
|
return expectObject$4(
|
|
3006
|
-
await callService(ctx, CONTROL_PANEL$
|
|
3026
|
+
await callService(ctx, CONTROL_PANEL$5, "system.buckyos_info.get", {}),
|
|
3007
3027
|
"system.buckyos_info.get"
|
|
3008
3028
|
);
|
|
3009
3029
|
}
|
|
3010
3030
|
const SERVICE_NAME = "system_config";
|
|
3011
|
-
const OBJECT_OUTPUT$
|
|
3031
|
+
const OBJECT_OUTPUT$f = { type: "object", additionalProperties: false };
|
|
3012
3032
|
const KEY_INPUT = {
|
|
3013
3033
|
type: "object",
|
|
3014
3034
|
properties: { key: { type: "string", minLength: 1 } },
|
|
@@ -3026,7 +3046,7 @@ function createSystemConfigModule() {
|
|
|
3026
3046
|
positionals: [{ name: "key", description: "System-config key" }],
|
|
3027
3047
|
inputSchema: KEY_INPUT,
|
|
3028
3048
|
outputSchema: {
|
|
3029
|
-
...OBJECT_OUTPUT$
|
|
3049
|
+
...OBJECT_OUTPUT$f,
|
|
3030
3050
|
properties: {
|
|
3031
3051
|
key: { type: "string" },
|
|
3032
3052
|
value: { type: "string" },
|
|
@@ -3069,7 +3089,7 @@ function createSystemConfigModule() {
|
|
|
3069
3089
|
additionalProperties: false
|
|
3070
3090
|
},
|
|
3071
3091
|
outputSchema: {
|
|
3072
|
-
...OBJECT_OUTPUT$
|
|
3092
|
+
...OBJECT_OUTPUT$f,
|
|
3073
3093
|
properties: {
|
|
3074
3094
|
key: { type: "string" },
|
|
3075
3095
|
items: { type: "array", items: { type: "string" } }
|
|
@@ -3123,7 +3143,7 @@ function setCommand() {
|
|
|
3123
3143
|
additionalProperties: false
|
|
3124
3144
|
},
|
|
3125
3145
|
outputSchema: {
|
|
3126
|
-
...OBJECT_OUTPUT$
|
|
3146
|
+
...OBJECT_OUTPUT$f,
|
|
3127
3147
|
properties: { key: { type: "string" }, updated: { type: "boolean" } },
|
|
3128
3148
|
required: ["key", "updated"]
|
|
3129
3149
|
},
|
|
@@ -3162,7 +3182,7 @@ function setFileCommand() {
|
|
|
3162
3182
|
additionalProperties: false
|
|
3163
3183
|
},
|
|
3164
3184
|
outputSchema: {
|
|
3165
|
-
...OBJECT_OUTPUT$
|
|
3185
|
+
...OBJECT_OUTPUT$f,
|
|
3166
3186
|
properties: { key: { type: "string" }, updated: { type: "boolean" } },
|
|
3167
3187
|
required: ["key", "updated"]
|
|
3168
3188
|
},
|
|
@@ -3199,7 +3219,7 @@ function mutationCommand(options) {
|
|
|
3199
3219
|
additionalProperties: false
|
|
3200
3220
|
},
|
|
3201
3221
|
outputSchema: {
|
|
3202
|
-
...OBJECT_OUTPUT$
|
|
3222
|
+
...OBJECT_OUTPUT$f,
|
|
3203
3223
|
properties: {
|
|
3204
3224
|
key: { type: "string" },
|
|
3205
3225
|
[options.resultProperty]: { type: "boolean" }
|
|
@@ -4084,8 +4104,8 @@ function validateZipEntryName(name) {
|
|
|
4084
4104
|
}
|
|
4085
4105
|
}
|
|
4086
4106
|
}
|
|
4087
|
-
function invalidZip(stage,
|
|
4088
|
-
return new ToolError("INVALID_PACKAGE",
|
|
4107
|
+
function invalidZip(stage, message2, entry) {
|
|
4108
|
+
return new ToolError("INVALID_PACKAGE", message2, 6, false, {
|
|
4089
4109
|
stage,
|
|
4090
4110
|
...entry ? { entry } : {}
|
|
4091
4111
|
});
|
|
@@ -4676,21 +4696,21 @@ function extToolsManifestErrors(value) {
|
|
|
4676
4696
|
const commands = /* @__PURE__ */ new Set();
|
|
4677
4697
|
for (const raw of Array.isArray(manifest.provides) ? manifest.provides : []) {
|
|
4678
4698
|
const entry = raw ?? {};
|
|
4679
|
-
const
|
|
4680
|
-
if (typeof
|
|
4681
|
-
errors.push(`provides: ${JSON.stringify(
|
|
4699
|
+
const command2 = entry.command;
|
|
4700
|
+
if (typeof command2 !== "string" || !EXT_TOOLS_COMMAND.test(command2)) {
|
|
4701
|
+
errors.push(`provides: ${JSON.stringify(command2)} is not a command name`);
|
|
4682
4702
|
continue;
|
|
4683
4703
|
}
|
|
4684
|
-
if (commands.has(
|
|
4685
|
-
errors.push(`provides: command ${
|
|
4686
|
-
if (EXT_TOOLS_RESERVED_COMMANDS.includes(
|
|
4687
|
-
errors.push(`provides: ${
|
|
4688
|
-
commands.add(
|
|
4704
|
+
if (commands.has(command2))
|
|
4705
|
+
errors.push(`provides: command ${command2} is listed twice`);
|
|
4706
|
+
if (EXT_TOOLS_RESERVED_COMMANDS.includes(command2))
|
|
4707
|
+
errors.push(`provides: ${command2} is a standard command and cannot be provided by a package`);
|
|
4708
|
+
commands.add(command2);
|
|
4689
4709
|
if (typeof entry.version_probe !== "string" || !entry.version_probe.trim())
|
|
4690
|
-
errors.push(`provides: ${
|
|
4710
|
+
errors.push(`provides: ${command2} has no version_probe`);
|
|
4691
4711
|
const smoke = entry.smoke;
|
|
4692
4712
|
if (smoke !== void 0 && (typeof smoke !== "string" || !isSafeRelativePath(smoke))) {
|
|
4693
|
-
errors.push(`provides: the smoke of ${
|
|
4713
|
+
errors.push(`provides: the smoke of ${command2} must be a relative path inside the payload`);
|
|
4694
4714
|
}
|
|
4695
4715
|
}
|
|
4696
4716
|
if (!Array.isArray(manifest.platforms) || manifest.platforms.length === 0)
|
|
@@ -4756,8 +4776,8 @@ function extToolsPayloadErrors(manifest, platform, tree, buildPaths = []) {
|
|
|
4756
4776
|
if (!path.startsWith("bin/"))
|
|
4757
4777
|
continue;
|
|
4758
4778
|
const name = path.slice("bin/".length);
|
|
4759
|
-
const
|
|
4760
|
-
if (!
|
|
4779
|
+
const command2 = suffixes.map((suffix) => suffix && name.endsWith(suffix) ? name.slice(0, -suffix.length) : name).find((candidate) => declared.has(candidate));
|
|
4780
|
+
if (!command2)
|
|
4761
4781
|
errors.push(`${path}: not in provides, so nothing knows this package provides it`);
|
|
4762
4782
|
}
|
|
4763
4783
|
const decoder = new TextDecoder();
|
|
@@ -5499,69 +5519,602 @@ function rejectUnknown(value, allowed, label) {
|
|
|
5499
5519
|
throw new UsageError("SCHEMA_VALIDATION_FAILED", `${label}.${unknown[0]} is not allowed`);
|
|
5500
5520
|
}
|
|
5501
5521
|
}
|
|
5502
|
-
function invalid(stage,
|
|
5503
|
-
return new ToolError("INVALID_PACKAGE",
|
|
5504
|
-
stage,
|
|
5505
|
-
...entry ? { entry: basename$1(entry) } : {}
|
|
5506
|
-
});
|
|
5522
|
+
function invalid(stage, message2, entry) {
|
|
5523
|
+
return new ToolError("INVALID_PACKAGE", message2, 6, false, {
|
|
5524
|
+
stage,
|
|
5525
|
+
...entry ? { entry: basename$1(entry) } : {}
|
|
5526
|
+
});
|
|
5527
|
+
}
|
|
5528
|
+
function stableJsonDigest(value) {
|
|
5529
|
+
return sha256Bytes(new TextEncoder().encode(ndn.toCanonicalJsonString(value)));
|
|
5530
|
+
}
|
|
5531
|
+
function validateContentHandlers(value, permissions) {
|
|
5532
|
+
if (!Array.isArray(value))
|
|
5533
|
+
throw invalid("appdoc", "content_handlers must be an array");
|
|
5534
|
+
const ids = /* @__PURE__ */ new Set();
|
|
5535
|
+
for (const raw of value) {
|
|
5536
|
+
const h = expectObject$3(raw, "content handler");
|
|
5537
|
+
const id = expectNonEmptyString(h.handler_id, "handler_id");
|
|
5538
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(id) || ids.has(id))
|
|
5539
|
+
throw invalid("appdoc", "invalid or duplicate handler_id");
|
|
5540
|
+
ids.add(id);
|
|
5541
|
+
if (!Number.isSafeInteger(h.version) || Number(h.version) < 1)
|
|
5542
|
+
throw invalid("appdoc", "invalid handler version");
|
|
5543
|
+
if (!Array.isArray(h.selectors) || !h.selectors.length)
|
|
5544
|
+
throw invalid("appdoc", "missing selectors");
|
|
5545
|
+
for (const rawSelector of h.selectors) {
|
|
5546
|
+
const s = expectObject$3(rawSelector, "selector");
|
|
5547
|
+
if (!["mime", "objType", "schema", "ext"].some((k) => k in s))
|
|
5548
|
+
throw invalid("appdoc", "empty selector");
|
|
5549
|
+
for (const key of ["mime", "objType", "schema"]) {
|
|
5550
|
+
const v = s[key];
|
|
5551
|
+
if (v !== void 0 && !(typeof v === "string" && v.length) && !(Array.isArray(v) && v.length && v.every((i) => typeof i === "string" && i.length)))
|
|
5552
|
+
throw invalid("appdoc", "invalid selector field");
|
|
5553
|
+
}
|
|
5554
|
+
if (s.maxSize !== void 0 && (!Number.isSafeInteger(s.maxSize) || Number(s.maxSize) < 0))
|
|
5555
|
+
throw invalid("appdoc", "invalid maxSize");
|
|
5556
|
+
}
|
|
5557
|
+
const intents = expectObject$3(h.intents, "intents");
|
|
5558
|
+
if (Object.keys(intents).length !== 1 || !intents.open)
|
|
5559
|
+
throw invalid("appdoc", "only open intent is supported");
|
|
5560
|
+
const open2 = expectObject$3(intents.open, "open");
|
|
5561
|
+
const entry = expectObject$3(open2.entry, "entry");
|
|
5562
|
+
const path = expectNonEmptyString(entry.path, "entry.path");
|
|
5563
|
+
let decoded;
|
|
5564
|
+
try {
|
|
5565
|
+
decoded = decodeURIComponent(path);
|
|
5566
|
+
} catch {
|
|
5567
|
+
throw invalid("appdoc", "invalid entry path");
|
|
5568
|
+
}
|
|
5569
|
+
if (entry.type !== "web" || !decoded.startsWith("/") || decoded.startsWith("//") || decoded.includes("..") || decoded.includes("\\") || decoded.includes("://") || decoded.includes("#") || /[\r\n]/.test(decoded))
|
|
5570
|
+
throw invalid("appdoc", "unsafe Web entry");
|
|
5571
|
+
if (open2.priority !== void 0 && (!Number.isSafeInteger(open2.priority) || Number(open2.priority) < 0 || Number(open2.priority) > 80))
|
|
5572
|
+
throw invalid("appdoc", "priority must be 0..80");
|
|
5573
|
+
if (open2.window !== void 0 && open2.window !== "new" && open2.window !== "reuse")
|
|
5574
|
+
throw invalid("appdoc", "invalid window policy");
|
|
5575
|
+
if (open2.multiSource !== void 0 && typeof open2.multiSource !== "boolean")
|
|
5576
|
+
throw invalid("appdoc", "invalid multiSource");
|
|
5577
|
+
if (open2.modes !== void 0 && (!Array.isArray(open2.modes) || !open2.modes.length || open2.modes.some((m) => m !== "view" && m !== "edit")))
|
|
5578
|
+
throw invalid("appdoc", "invalid modes");
|
|
5579
|
+
if (h.permissions !== void 0 && (!Array.isArray(h.permissions) || h.permissions.some((scope) => !permissions.some((p) => p && typeof p === "object" && p.scope_path === scope))))
|
|
5580
|
+
throw invalid("appdoc", "handler permissions exceed App permissions");
|
|
5581
|
+
}
|
|
5582
|
+
return value;
|
|
5583
|
+
}
|
|
5584
|
+
const SKILL_KINDS = ["work", "plan", "goal"];
|
|
5585
|
+
const SKILL_KIND_DIRS = {
|
|
5586
|
+
work: "cmd_skills",
|
|
5587
|
+
plan: "plan_skills",
|
|
5588
|
+
goal: "goal_skills"
|
|
5589
|
+
};
|
|
5590
|
+
const TOOLS_DIR = "tools";
|
|
5591
|
+
const SKILL_DIRS = [...SKILL_KINDS.map((kind) => SKILL_KIND_DIRS[kind]), TOOLS_DIR];
|
|
5592
|
+
const SKILL_MANUAL = "SKILL.md";
|
|
5593
|
+
const SKILL_REFERENCES = "references";
|
|
5594
|
+
const SKILL_REVISIONS = "revisions";
|
|
5595
|
+
const SKILL_PLATFORMS = ["linux", "macos", "windows"];
|
|
5596
|
+
const UI_MANUAL_WARN_BYTES = 16 * 1024;
|
|
5597
|
+
const PLAN_MANUAL_WARN_BYTES = 3 * 1024;
|
|
5598
|
+
const MAX_NAME_LEN = 200;
|
|
5599
|
+
const STANDARD_COMMANDS = EXT_TOOLS_RESERVED_COMMANDS;
|
|
5600
|
+
const SHELL_WORDS = /* @__PURE__ */ new Set([
|
|
5601
|
+
"if",
|
|
5602
|
+
"then",
|
|
5603
|
+
"else",
|
|
5604
|
+
"elif",
|
|
5605
|
+
"fi",
|
|
5606
|
+
"for",
|
|
5607
|
+
"while",
|
|
5608
|
+
"until",
|
|
5609
|
+
"do",
|
|
5610
|
+
"done",
|
|
5611
|
+
"case",
|
|
5612
|
+
"esac",
|
|
5613
|
+
"in",
|
|
5614
|
+
"function",
|
|
5615
|
+
"select",
|
|
5616
|
+
"time",
|
|
5617
|
+
"cd",
|
|
5618
|
+
"echo",
|
|
5619
|
+
"printf",
|
|
5620
|
+
"export",
|
|
5621
|
+
"set",
|
|
5622
|
+
"unset",
|
|
5623
|
+
"read",
|
|
5624
|
+
"exit",
|
|
5625
|
+
"return",
|
|
5626
|
+
"source",
|
|
5627
|
+
"eval",
|
|
5628
|
+
"exec",
|
|
5629
|
+
"test",
|
|
5630
|
+
"true",
|
|
5631
|
+
"false",
|
|
5632
|
+
"local",
|
|
5633
|
+
"declare",
|
|
5634
|
+
"trap",
|
|
5635
|
+
"wait",
|
|
5636
|
+
"shift",
|
|
5637
|
+
"alias",
|
|
5638
|
+
"type",
|
|
5639
|
+
"command",
|
|
5640
|
+
"pwd",
|
|
5641
|
+
"kill",
|
|
5642
|
+
"umask",
|
|
5643
|
+
"ulimit",
|
|
5644
|
+
"break",
|
|
5645
|
+
"continue",
|
|
5646
|
+
"let",
|
|
5647
|
+
"readonly",
|
|
5648
|
+
"ls",
|
|
5649
|
+
"cat",
|
|
5650
|
+
"cp",
|
|
5651
|
+
"mv",
|
|
5652
|
+
"rm",
|
|
5653
|
+
"mkdir",
|
|
5654
|
+
"rmdir",
|
|
5655
|
+
"touch",
|
|
5656
|
+
"ln",
|
|
5657
|
+
"chmod",
|
|
5658
|
+
"chown",
|
|
5659
|
+
"head",
|
|
5660
|
+
"tail",
|
|
5661
|
+
"grep",
|
|
5662
|
+
"sed",
|
|
5663
|
+
"awk",
|
|
5664
|
+
"sort",
|
|
5665
|
+
"uniq",
|
|
5666
|
+
"wc",
|
|
5667
|
+
"cut",
|
|
5668
|
+
"tr",
|
|
5669
|
+
"tee",
|
|
5670
|
+
"find",
|
|
5671
|
+
"xargs",
|
|
5672
|
+
"basename",
|
|
5673
|
+
"dirname",
|
|
5674
|
+
"date",
|
|
5675
|
+
"sleep",
|
|
5676
|
+
"env",
|
|
5677
|
+
"which",
|
|
5678
|
+
"diff",
|
|
5679
|
+
"du",
|
|
5680
|
+
"df",
|
|
5681
|
+
"stat",
|
|
5682
|
+
"mktemp",
|
|
5683
|
+
"sh",
|
|
5684
|
+
"bash",
|
|
5685
|
+
"id",
|
|
5686
|
+
"whoami",
|
|
5687
|
+
"uname",
|
|
5688
|
+
"realpath",
|
|
5689
|
+
"readlink",
|
|
5690
|
+
"seq",
|
|
5691
|
+
"yes",
|
|
5692
|
+
"nohup",
|
|
5693
|
+
"timeout",
|
|
5694
|
+
"tar",
|
|
5695
|
+
"gzip",
|
|
5696
|
+
"gunzip",
|
|
5697
|
+
"sha256sum",
|
|
5698
|
+
"base64",
|
|
5699
|
+
"cmp",
|
|
5700
|
+
"file",
|
|
5701
|
+
"ps",
|
|
5702
|
+
"less",
|
|
5703
|
+
"more",
|
|
5704
|
+
"printenv",
|
|
5705
|
+
"hostname",
|
|
5706
|
+
"expr",
|
|
5707
|
+
"od",
|
|
5708
|
+
"paste",
|
|
5709
|
+
"comm",
|
|
5710
|
+
"nl",
|
|
5711
|
+
"tac",
|
|
5712
|
+
"rev",
|
|
5713
|
+
"fold",
|
|
5714
|
+
"column",
|
|
5715
|
+
"read",
|
|
5716
|
+
"shell"
|
|
5717
|
+
]);
|
|
5718
|
+
const SHELL_LANGS = /* @__PURE__ */ new Set(["", "sh", "bash", "shell", "zsh", "console"]);
|
|
5719
|
+
const ASSIGNMENT_KEY = /^[A-Za-z0-9_]+$/;
|
|
5720
|
+
const PLAIN_WORD = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
|
|
5721
|
+
function asciiLower(text2) {
|
|
5722
|
+
return text2.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
5723
|
+
}
|
|
5724
|
+
function commandsInManual(text2) {
|
|
5725
|
+
const out = /* @__PURE__ */ new Set();
|
|
5726
|
+
let inBlock = false;
|
|
5727
|
+
let shell = false;
|
|
5728
|
+
let heredoc;
|
|
5729
|
+
let continued = false;
|
|
5730
|
+
for (const raw of text2.split("\n")) {
|
|
5731
|
+
let line = raw.trim();
|
|
5732
|
+
if (line.startsWith("```")) {
|
|
5733
|
+
inBlock = !inBlock;
|
|
5734
|
+
shell = inBlock && SHELL_LANGS.has(asciiLower(line.slice(3).trim()));
|
|
5735
|
+
heredoc = void 0;
|
|
5736
|
+
continued = false;
|
|
5737
|
+
continue;
|
|
5738
|
+
}
|
|
5739
|
+
if (!inBlock || !shell)
|
|
5740
|
+
continue;
|
|
5741
|
+
if (heredoc !== void 0) {
|
|
5742
|
+
if (line === heredoc)
|
|
5743
|
+
heredoc = void 0;
|
|
5744
|
+
continue;
|
|
5745
|
+
}
|
|
5746
|
+
const wasContinued = continued;
|
|
5747
|
+
continued = line.endsWith("\\");
|
|
5748
|
+
const at = line.indexOf("<<");
|
|
5749
|
+
if (at >= 0) {
|
|
5750
|
+
const tag = line.slice(at + 2).replace(/^-+/, "").trim().split(/\s/)[0].replace(/^['"]+|['"]+$/g, "");
|
|
5751
|
+
if (tag && /^[A-Za-z0-9_]+$/.test(tag))
|
|
5752
|
+
heredoc = tag;
|
|
5753
|
+
}
|
|
5754
|
+
if (wasContinued || !line || line.startsWith("#"))
|
|
5755
|
+
continue;
|
|
5756
|
+
if (line.startsWith("$ "))
|
|
5757
|
+
line = line.slice(2);
|
|
5758
|
+
let quote;
|
|
5759
|
+
const segments = [""];
|
|
5760
|
+
const chars = Array.from(line);
|
|
5761
|
+
for (let i = 0; i < chars.length; i += 1) {
|
|
5762
|
+
const c = chars[i];
|
|
5763
|
+
if (quote !== void 0) {
|
|
5764
|
+
if (c === quote)
|
|
5765
|
+
quote = void 0;
|
|
5766
|
+
} else if (c === "'" || c === '"') {
|
|
5767
|
+
quote = c;
|
|
5768
|
+
} else if (c === "#" && (i === 0 || /\s/.test(chars[i - 1]))) {
|
|
5769
|
+
break;
|
|
5770
|
+
} else if (
|
|
5771
|
+
// `a|b|c` without spaces is a list of alternatives in a usage line, not a pipe (as in skills.rs).
|
|
5772
|
+
c === "|" && (chars[i + 1] === void 0 || /\s/.test(chars[i + 1]) || chars[i + 1] === "|" || i > 0 && /\s/.test(chars[i - 1])) || c === ";" || c === "&" && chars[i + 1] === "&"
|
|
5773
|
+
) {
|
|
5774
|
+
if (chars[i + 1] === c)
|
|
5775
|
+
i += 1;
|
|
5776
|
+
segments.push("");
|
|
5777
|
+
continue;
|
|
5778
|
+
} else if (c === "$" && chars[i + 1] === "(") {
|
|
5779
|
+
segments.push("");
|
|
5780
|
+
i += 1;
|
|
5781
|
+
continue;
|
|
5782
|
+
}
|
|
5783
|
+
segments[segments.length - 1] += c;
|
|
5784
|
+
}
|
|
5785
|
+
for (const segment of segments) {
|
|
5786
|
+
const first = segment.split(/\s+/).filter(Boolean).find((w) => {
|
|
5787
|
+
const eq = w.indexOf("=");
|
|
5788
|
+
if (eq >= 0 && ASSIGNMENT_KEY.test(w.slice(0, eq)))
|
|
5789
|
+
return false;
|
|
5790
|
+
return w !== "sudo" && w !== "(" && w !== "{" && w !== "!";
|
|
5791
|
+
});
|
|
5792
|
+
if (first === void 0)
|
|
5793
|
+
continue;
|
|
5794
|
+
const word = first.replace(/^\(+/, "");
|
|
5795
|
+
if (PLAIN_WORD.test(word) && /[a-z]/.test(word) && !SHELL_WORDS.has(word))
|
|
5796
|
+
out.add(word);
|
|
5797
|
+
}
|
|
5798
|
+
}
|
|
5799
|
+
return out;
|
|
5800
|
+
}
|
|
5801
|
+
function splitFrontMatter(text2) {
|
|
5802
|
+
const trimmed = text2.replace(/^+/, "");
|
|
5803
|
+
const rest = trimmed.startsWith("---\n") ? trimmed.slice(4) : trimmed.startsWith("---\r\n") ? trimmed.slice(5) : void 0;
|
|
5804
|
+
if (rest === void 0)
|
|
5805
|
+
return { fields: /* @__PURE__ */ new Map(), body: text2.trim() };
|
|
5806
|
+
const fields = /* @__PURE__ */ new Map();
|
|
5807
|
+
let offset = 0;
|
|
5808
|
+
while (offset < rest.length) {
|
|
5809
|
+
const end = rest.indexOf("\n", offset);
|
|
5810
|
+
const next = end < 0 ? rest.length : end + 1;
|
|
5811
|
+
const line = rest.slice(offset, next).trim();
|
|
5812
|
+
offset = next;
|
|
5813
|
+
if (line === "---")
|
|
5814
|
+
return { fields, body: rest.slice(offset).trim() };
|
|
5815
|
+
const colon = line.indexOf(":");
|
|
5816
|
+
if (colon < 0)
|
|
5817
|
+
continue;
|
|
5818
|
+
let value = line.slice(colon + 1).trim();
|
|
5819
|
+
for (const q of ['"', "'"]) {
|
|
5820
|
+
if (value.length >= 2 && value.startsWith(q) && value.endsWith(q)) {
|
|
5821
|
+
value = value.slice(1, -1);
|
|
5822
|
+
break;
|
|
5823
|
+
}
|
|
5824
|
+
}
|
|
5825
|
+
fields.set(line.slice(0, colon).trim(), value);
|
|
5826
|
+
}
|
|
5827
|
+
return { fields: /* @__PURE__ */ new Map(), body: text2.trim() };
|
|
5828
|
+
}
|
|
5829
|
+
function skillRequirements(fields) {
|
|
5830
|
+
const raw = (fields.get("baseline") ?? "").trim();
|
|
5831
|
+
if (raw !== "" && raw !== "standard" && raw !== "extended") {
|
|
5832
|
+
throw new Error(`baseline \`${raw}\` is not standard | extended`);
|
|
5833
|
+
}
|
|
5834
|
+
const platforms = [];
|
|
5835
|
+
for (const part of (fields.get("platforms") ?? "").split(",")) {
|
|
5836
|
+
const p = part.trim();
|
|
5837
|
+
if (!p)
|
|
5838
|
+
continue;
|
|
5839
|
+
if (!SKILL_PLATFORMS.includes(p))
|
|
5840
|
+
throw new Error(`platform \`${p}\` is not one of ${SKILL_PLATFORMS.join(", ")}`);
|
|
5841
|
+
if (!platforms.includes(p))
|
|
5842
|
+
platforms.push(p);
|
|
5843
|
+
}
|
|
5844
|
+
return { baseline: raw === "extended" ? "extended" : "standard", platforms };
|
|
5845
|
+
}
|
|
5846
|
+
function skillScope(fields) {
|
|
5847
|
+
let ui = false;
|
|
5848
|
+
let work = false;
|
|
5849
|
+
for (const part of (fields.get("scope") ?? "").split(",")) {
|
|
5850
|
+
const word = part.trim();
|
|
5851
|
+
if (word === "ui")
|
|
5852
|
+
ui = true;
|
|
5853
|
+
else if (word === "work")
|
|
5854
|
+
work = true;
|
|
5855
|
+
else if (word)
|
|
5856
|
+
throw new Error(`scope \`${word}\` is not ui | work`);
|
|
5857
|
+
}
|
|
5858
|
+
return ui ? work ? "ui,work" : "ui" : "work";
|
|
5859
|
+
}
|
|
5860
|
+
function skillCommandsOf(fields) {
|
|
5861
|
+
const commands = (fields.get("commands") ?? "").split(",").map((c) => c.trim()).filter((c) => c && !c.startsWith(".") && /^[A-Za-z0-9._+-]+$/.test(c));
|
|
5862
|
+
return commands.filter((c, index) => index === 0 || commands[index - 1] !== c);
|
|
5863
|
+
}
|
|
5864
|
+
function textOf(bytes) {
|
|
5865
|
+
try {
|
|
5866
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
5867
|
+
} catch {
|
|
5868
|
+
return void 0;
|
|
5869
|
+
}
|
|
5870
|
+
}
|
|
5871
|
+
function byteLength(text2) {
|
|
5872
|
+
return new TextEncoder().encode(text2).length;
|
|
5873
|
+
}
|
|
5874
|
+
function place(path) {
|
|
5875
|
+
const bad = (hint = "") => {
|
|
5876
|
+
throw new Error(
|
|
5877
|
+
`\`${path}\` is not a skill file: a skill package holds <cmd_skills|plan_skills|goal_skills>/<name>/${SKILL_MANUAL} and their ${SKILL_REFERENCES}/…${hint}`
|
|
5878
|
+
);
|
|
5879
|
+
};
|
|
5880
|
+
const parts = path.split("/");
|
|
5881
|
+
if (parts.some((p) => p === "" || p === "." || p === ".."))
|
|
5882
|
+
bad();
|
|
5883
|
+
if (parts[0] === TOOLS_DIR) {
|
|
5884
|
+
throw new Error(
|
|
5885
|
+
`\`${path}\`: a skill is text only and brings no command or install script; publish the commands as an extension package and name them in the manual's \`commands\``
|
|
5886
|
+
);
|
|
5887
|
+
}
|
|
5888
|
+
const kind = SKILL_KINDS.find((k) => SKILL_KIND_DIRS[k] === parts[0]);
|
|
5889
|
+
if (!kind || parts.length < 2)
|
|
5890
|
+
return bad();
|
|
5891
|
+
if (parts.length === 2) {
|
|
5892
|
+
return bad(parts[1].endsWith(".md") ? ` (a flat ${parts[0]}/<name>.md is no skill: move it to ${parts[0]}/${parts[1].slice(0, -3)}/${SKILL_MANUAL})` : "");
|
|
5893
|
+
}
|
|
5894
|
+
const manual = parts.length === 3 && parts[2] === SKILL_MANUAL;
|
|
5895
|
+
const reference = parts.length >= 4 && parts[2] === SKILL_REFERENCES;
|
|
5896
|
+
if (!manual && !reference)
|
|
5897
|
+
bad();
|
|
5898
|
+
const name = parts[1];
|
|
5899
|
+
if (name.length > MAX_NAME_LEN || name.startsWith(".") || !/^[A-Za-z0-9_.-]+$/.test(name))
|
|
5900
|
+
bad();
|
|
5901
|
+
return { kind, name };
|
|
5902
|
+
}
|
|
5903
|
+
function packageSkills(packageName, files, findings) {
|
|
5904
|
+
const paths = [...files.keys()].sort();
|
|
5905
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
5906
|
+
for (const path of paths) {
|
|
5907
|
+
const { kind, name } = place(path);
|
|
5908
|
+
const key = `${SKILL_KINDS.indexOf(kind)}:${name}`;
|
|
5909
|
+
if (!grouped.has(key))
|
|
5910
|
+
grouped.set(key, { kind, name, paths: [] });
|
|
5911
|
+
grouped.get(key).paths.push(path);
|
|
5912
|
+
}
|
|
5913
|
+
const binary = paths.find((path) => textOf(files.get(path).bytes) === void 0);
|
|
5914
|
+
if (binary)
|
|
5915
|
+
throw new Error(`${binary} is not UTF-8 text: a skill is text only`);
|
|
5916
|
+
if (grouped.size === 0) {
|
|
5917
|
+
throw new Error(`package ${packageName} holds no skill (<cmd_skills|plan_skills|goal_skills>/<name>/${SKILL_MANUAL})`);
|
|
5918
|
+
}
|
|
5919
|
+
const out = [];
|
|
5920
|
+
const groups = [...grouped.values()].sort(
|
|
5921
|
+
(a, b) => SKILL_KINDS.indexOf(a.kind) - SKILL_KINDS.indexOf(b.kind) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)
|
|
5922
|
+
);
|
|
5923
|
+
for (const { kind, name, paths: own } of groups) {
|
|
5924
|
+
const dir = SKILL_KIND_DIRS[kind];
|
|
5925
|
+
const manual = `${dir}/${name}/${SKILL_MANUAL}`;
|
|
5926
|
+
const file = files.get(manual);
|
|
5927
|
+
if (!file)
|
|
5928
|
+
throw new Error(`${dir}/${name}/ has no ${SKILL_MANUAL}`);
|
|
5929
|
+
const text2 = textOf(file.bytes);
|
|
5930
|
+
if (text2 === void 0)
|
|
5931
|
+
throw new Error(`${manual} is not UTF-8 text`);
|
|
5932
|
+
const { fields, body } = splitFrontMatter(text2);
|
|
5933
|
+
let requirements;
|
|
5934
|
+
let scope;
|
|
5935
|
+
try {
|
|
5936
|
+
requirements = skillRequirements(fields);
|
|
5937
|
+
scope = skillScope(fields);
|
|
5938
|
+
if (kind !== "work") {
|
|
5939
|
+
for (const key of ["scope", "commands"]) {
|
|
5940
|
+
if ((fields.get(key) ?? "").trim()) {
|
|
5941
|
+
throw new Error(`a ${kind} skill declares no \`${key}\`: it names no commands and is read, not frozen`);
|
|
5942
|
+
}
|
|
5943
|
+
}
|
|
5944
|
+
}
|
|
5945
|
+
} catch (error) {
|
|
5946
|
+
throw new Error(`${manual}: ${error.message}`);
|
|
5947
|
+
}
|
|
5948
|
+
if (fields.has("name") && fields.get("name") !== name) {
|
|
5949
|
+
throw new Error(`${manual}: front matter name \`${fields.get("name")}\` differs from its directory`);
|
|
5950
|
+
}
|
|
5951
|
+
const refPrefix = `${dir}/${name}/${SKILL_REFERENCES}/`;
|
|
5952
|
+
const skill = {
|
|
5953
|
+
kind,
|
|
5954
|
+
name,
|
|
5955
|
+
scope: kind === "work" ? scope : "work",
|
|
5956
|
+
description: fields.get("description") ?? "",
|
|
5957
|
+
requires: fields.get("requires") ?? "",
|
|
5958
|
+
baseline: requirements.baseline,
|
|
5959
|
+
platforms: requirements.platforms,
|
|
5960
|
+
commands: skillCommandsOf(fields),
|
|
5961
|
+
size: byteLength(body),
|
|
5962
|
+
references: own.filter((p) => p.startsWith(refPrefix)).map((p) => p.slice(refPrefix.length))
|
|
5963
|
+
};
|
|
5964
|
+
const add = (code, level, note) => findings.push({ code, level, where: manual, note });
|
|
5965
|
+
if (!skill.description.trim())
|
|
5966
|
+
add("no_description", "medium", "no `description`: whoever chooses manuals only sees the name");
|
|
5967
|
+
const texts = [body];
|
|
5968
|
+
for (const path of own) {
|
|
5969
|
+
if (!path.includes(`/${SKILL_REFERENCES}/`) || !path.endsWith(".md"))
|
|
5970
|
+
continue;
|
|
5971
|
+
const reference = textOf(files.get(path).bytes);
|
|
5972
|
+
if (reference !== void 0)
|
|
5973
|
+
texts.push(reference);
|
|
5974
|
+
}
|
|
5975
|
+
const used = [...new Set(texts.flatMap((t) => [...commandsInManual(t)]))].sort();
|
|
5976
|
+
if (kind === "work") {
|
|
5977
|
+
if (skill.scope !== "work" && skill.size > UI_MANUAL_WARN_BYTES) {
|
|
5978
|
+
add("ui_manual_large", "low", `${skill.size} bytes: every conversation that takes it carries them (advised: at most ${UI_MANUAL_WARN_BYTES})`);
|
|
5979
|
+
}
|
|
5980
|
+
const undeclared = used.filter((c) => !skill.commands.includes(c) && !STANDARD_COMMANDS.includes(c));
|
|
5981
|
+
if (undeclared.length)
|
|
5982
|
+
add("undeclared_commands", "low", `the manual runs ${undeclared.join(", ")} without naming them in \`commands\``);
|
|
5983
|
+
const lower = texts.map((t) => t.toLowerCase());
|
|
5984
|
+
const unused = skill.commands.filter((c) => !lower.some((t) => t.includes(c.toLowerCase())));
|
|
5985
|
+
if (unused.length)
|
|
5986
|
+
add("unused_commands", "low", `\`commands\` names ${unused.join(", ")} but the manual never mentions them`);
|
|
5987
|
+
} else if (kind === "plan") {
|
|
5988
|
+
if (skill.size > PLAN_MANUAL_WARN_BYTES) {
|
|
5989
|
+
add("plan_manual_large", "low", `${skill.size} bytes (advised: at most ${PLAN_MANUAL_WARN_BYTES}): a plan reads it whole`);
|
|
5990
|
+
}
|
|
5991
|
+
const hard = texts.some(
|
|
5992
|
+
(t) => t.includes("create-worksession") || t.includes("--cmd-skill") || t.split("\n").some((l) => l.includes("--skill ") && !l.includes("--skill <"))
|
|
5993
|
+
);
|
|
5994
|
+
if (hard || used.length) {
|
|
5995
|
+
add(
|
|
5996
|
+
"plan_depends_on_commands",
|
|
5997
|
+
"medium",
|
|
5998
|
+
'a plan skill says how to split, order and check work, not which commands or manuals to use: move commands into a work skill and write "give this step a manual for X"'
|
|
5999
|
+
);
|
|
6000
|
+
}
|
|
6001
|
+
}
|
|
6002
|
+
out.push(skill);
|
|
6003
|
+
}
|
|
6004
|
+
return out;
|
|
6005
|
+
}
|
|
6006
|
+
const PACKAGE_MANAGERS = [
|
|
6007
|
+
"apt-get ",
|
|
6008
|
+
"apt install",
|
|
6009
|
+
"brew install",
|
|
6010
|
+
"npm install -g",
|
|
6011
|
+
"npm i -g",
|
|
6012
|
+
"pip install",
|
|
6013
|
+
"pip3 install",
|
|
6014
|
+
"winget install",
|
|
6015
|
+
"choco install",
|
|
6016
|
+
"dnf install",
|
|
6017
|
+
"yum install",
|
|
6018
|
+
"apk add"
|
|
6019
|
+
];
|
|
6020
|
+
const SECRET_WORDS = ["TOKEN", "SECRET", "PASSWORD", "API_KEY", "APIKEY", "PRIVATE_KEY"];
|
|
6021
|
+
function riskFindings(skills, files, findings) {
|
|
6022
|
+
const paths = [...files.keys()].sort();
|
|
6023
|
+
for (const skill of skills) {
|
|
6024
|
+
const dir = SKILL_KIND_DIRS[skill.kind];
|
|
6025
|
+
const key = `${skill.kind}:${skill.name}`;
|
|
6026
|
+
if (skill.scope !== "work") {
|
|
6027
|
+
findings.push({ code: "ui_scope", level: "medium", where: key, note: "its scope includes `ui`: once the owner adds it to the UI set it goes into the prompt of every conversation" });
|
|
6028
|
+
}
|
|
6029
|
+
for (const path of paths) {
|
|
6030
|
+
if (!path.startsWith(`${dir}/${skill.name}/`))
|
|
6031
|
+
continue;
|
|
6032
|
+
const text2 = textOf(files.get(path).bytes);
|
|
6033
|
+
if (text2 === void 0)
|
|
6034
|
+
continue;
|
|
6035
|
+
const lower = asciiLower(text2);
|
|
6036
|
+
const piped = lower.split("\n").some(
|
|
6037
|
+
(l) => (l.includes("curl ") || l.includes("wget ")) && (l.includes("| sh") || l.includes("|sh") || l.includes("| bash") || l.includes("|bash"))
|
|
6038
|
+
);
|
|
6039
|
+
if (piped) {
|
|
6040
|
+
findings.push({ code: "network_script", level: "high", where: path, note: "tells the agent to download a script and run it (`curl … | sh`)" });
|
|
6041
|
+
}
|
|
6042
|
+
const managers = PACKAGE_MANAGERS.filter((m) => lower.includes(m));
|
|
6043
|
+
if (managers.length) {
|
|
6044
|
+
findings.push({ code: "package_manager", level: "medium", where: path, note: `uses a package manager (${managers.join(", ").replaceAll(" ", " ")})` });
|
|
6045
|
+
}
|
|
6046
|
+
if (lower.split("\n").some((l) => l.split(/\s+/).includes("sudo"))) {
|
|
6047
|
+
findings.push({ code: "privilege", level: "high", where: path, note: "asks for root (`sudo`)" });
|
|
6048
|
+
}
|
|
6049
|
+
const secrets = [...new Set(
|
|
6050
|
+
text2.split(/[^A-Za-z0-9_]/).filter((w) => w.length > 5 && /^[A-Z0-9_]+$/.test(w) && SECRET_WORDS.some((s) => w.includes(s)))
|
|
6051
|
+
)].sort();
|
|
6052
|
+
if (secrets.length) {
|
|
6053
|
+
findings.push({ code: "secrets", level: "medium", where: path, note: `reads secrets from the environment (${secrets.join(", ")})` });
|
|
6054
|
+
}
|
|
6055
|
+
}
|
|
6056
|
+
}
|
|
6057
|
+
}
|
|
6058
|
+
function skillContentDigest(files) {
|
|
6059
|
+
const lines = [...files.keys()].sort().map((path) => `${path}|${sha256Bytes(files.get(path).bytes)}
|
|
6060
|
+
`);
|
|
6061
|
+
return `sha256:${sha256Bytes(new TextEncoder().encode(lines.join("")))}`;
|
|
5507
6062
|
}
|
|
5508
|
-
function
|
|
5509
|
-
|
|
6063
|
+
function lintSkillPackage(packageName, files) {
|
|
6064
|
+
const findings = [];
|
|
6065
|
+
try {
|
|
6066
|
+
const skills = packageSkills(packageName, files, findings);
|
|
6067
|
+
riskFindings(skills, files, findings);
|
|
6068
|
+
return { skills, findings };
|
|
6069
|
+
} catch (error) {
|
|
6070
|
+
findings.unshift({ code: "invalid_package", level: "error", where: packageName, note: error.message });
|
|
6071
|
+
return { skills: [], findings };
|
|
6072
|
+
}
|
|
5510
6073
|
}
|
|
5511
|
-
function
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
const
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
6074
|
+
async function readSkillDirectory(root, limit) {
|
|
6075
|
+
const host2 = getHost();
|
|
6076
|
+
const realRoot = await host2.realPath(root);
|
|
6077
|
+
const files = /* @__PURE__ */ new Map();
|
|
6078
|
+
const ignored = [];
|
|
6079
|
+
let total = 0;
|
|
6080
|
+
const walk = async (directory, prefix) => {
|
|
6081
|
+
const children = (await host2.readDir(directory)).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
6082
|
+
for (const child of children) {
|
|
6083
|
+
const rel = prefix ? `${prefix}/${child.name}` : child.name;
|
|
6084
|
+
const parts = rel.split("/");
|
|
6085
|
+
if (parts.length > 32)
|
|
6086
|
+
throw new Error(`${rel}: nested too deep`);
|
|
6087
|
+
if (!prefix && !SKILL_DIRS.includes(child.name)) {
|
|
6088
|
+
ignored.push(rel);
|
|
6089
|
+
continue;
|
|
6090
|
+
}
|
|
6091
|
+
if (parts[0] !== TOOLS_DIR && parts.length === 3 && parts[2] === SKILL_REVISIONS)
|
|
6092
|
+
continue;
|
|
6093
|
+
let path = host2.path.join(directory, child.name);
|
|
6094
|
+
if ((await host2.lstat(path)).isSymlink) {
|
|
6095
|
+
path = await host2.realPath(path);
|
|
6096
|
+
const inside = host2.path.relative(realRoot, path);
|
|
6097
|
+
if (inside === ".." || inside.startsWith(`..${host2.path.sep}`) || host2.path.isAbsolute(inside)) {
|
|
6098
|
+
throw new Error(`${rel}: a link out of the skill directory`);
|
|
6099
|
+
}
|
|
6100
|
+
}
|
|
6101
|
+
const info = await host2.stat(path);
|
|
6102
|
+
if (info.isDirectory) {
|
|
6103
|
+
await walk(path, rel);
|
|
6104
|
+
} else if (info.isFile) {
|
|
6105
|
+
total += info.size;
|
|
6106
|
+
if (total > limit)
|
|
6107
|
+
throw new Error(`the skill directory holds more than ${limit} bytes`);
|
|
6108
|
+
files.set(rel, { bytes: await host2.readFile(path) });
|
|
6109
|
+
} else {
|
|
6110
|
+
throw new Error(`${rel}: not a regular file`);
|
|
5533
6111
|
}
|
|
5534
|
-
if (s.maxSize !== void 0 && (!Number.isSafeInteger(s.maxSize) || Number(s.maxSize) < 0))
|
|
5535
|
-
throw invalid("appdoc", "invalid maxSize");
|
|
5536
|
-
}
|
|
5537
|
-
const intents = expectObject$3(h.intents, "intents");
|
|
5538
|
-
if (Object.keys(intents).length !== 1 || !intents.open)
|
|
5539
|
-
throw invalid("appdoc", "only open intent is supported");
|
|
5540
|
-
const open2 = expectObject$3(intents.open, "open");
|
|
5541
|
-
const entry = expectObject$3(open2.entry, "entry");
|
|
5542
|
-
const path = expectNonEmptyString(entry.path, "entry.path");
|
|
5543
|
-
let decoded;
|
|
5544
|
-
try {
|
|
5545
|
-
decoded = decodeURIComponent(path);
|
|
5546
|
-
} catch {
|
|
5547
|
-
throw invalid("appdoc", "invalid entry path");
|
|
5548
6112
|
}
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
throw invalid("appdoc", "priority must be 0..80");
|
|
5553
|
-
if (open2.window !== void 0 && open2.window !== "new" && open2.window !== "reuse")
|
|
5554
|
-
throw invalid("appdoc", "invalid window policy");
|
|
5555
|
-
if (open2.multiSource !== void 0 && typeof open2.multiSource !== "boolean")
|
|
5556
|
-
throw invalid("appdoc", "invalid multiSource");
|
|
5557
|
-
if (open2.modes !== void 0 && (!Array.isArray(open2.modes) || !open2.modes.length || open2.modes.some((m) => m !== "view" && m !== "edit")))
|
|
5558
|
-
throw invalid("appdoc", "invalid modes");
|
|
5559
|
-
if (h.permissions !== void 0 && (!Array.isArray(h.permissions) || h.permissions.some((scope) => !permissions.some((p) => p && typeof p === "object" && p.scope_path === scope))))
|
|
5560
|
-
throw invalid("appdoc", "handler permissions exceed App permissions");
|
|
5561
|
-
}
|
|
5562
|
-
return value;
|
|
6113
|
+
};
|
|
6114
|
+
await walk(realRoot, "");
|
|
6115
|
+
return { files, ignored };
|
|
5563
6116
|
}
|
|
5564
|
-
const PACKAGE_VERSION = "0.7.
|
|
6117
|
+
const PACKAGE_VERSION = "0.7.175";
|
|
5565
6118
|
const TOOL_VERSION = PACKAGE_VERSION;
|
|
5566
6119
|
const SDK_VERSION = PACKAGE_VERSION;
|
|
5567
6120
|
const PROTOCOL_VERSION = "1";
|
|
@@ -5578,7 +6131,7 @@ const VERSION$1 = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
|
5578
6131
|
const SHA256_ID = /^sha256:[0-9a-f]{64}$/;
|
|
5579
6132
|
const OBJECT_ID = /^(?:appdoc|pkg):[0-9a-f]{64}$/;
|
|
5580
6133
|
const SAFE_GENERATED_FILE = /^[A-Za-z0-9._-]+$/;
|
|
5581
|
-
const OBJECT_OUTPUT$
|
|
6134
|
+
const OBJECT_OUTPUT$e = { type: "object", additionalProperties: true };
|
|
5582
6135
|
const APP_KINDS = ["static-web", "script", "docker", "agent-skills", "aiws-controls", "ext-tools"];
|
|
5583
6136
|
const PATH_KINDS = {
|
|
5584
6137
|
"static-web": { key: "web", category: "web", selectorType: "static" },
|
|
@@ -5636,7 +6189,7 @@ function createPikgModule(dependencies = {}) {
|
|
|
5636
6189
|
},
|
|
5637
6190
|
additionalProperties: false
|
|
5638
6191
|
},
|
|
5639
|
-
outputSchema: OBJECT_OUTPUT$
|
|
6192
|
+
outputSchema: OBJECT_OUTPUT$e,
|
|
5640
6193
|
resultSchemaVersion: 1,
|
|
5641
6194
|
access: { mode: "fixed", level: "read" },
|
|
5642
6195
|
asyncMode: "sync",
|
|
@@ -5693,7 +6246,7 @@ function createPikgModule(dependencies = {}) {
|
|
|
5693
6246
|
},
|
|
5694
6247
|
additionalProperties: false
|
|
5695
6248
|
},
|
|
5696
|
-
outputSchema: OBJECT_OUTPUT$
|
|
6249
|
+
outputSchema: OBJECT_OUTPUT$e,
|
|
5697
6250
|
resultSchemaVersion: 1,
|
|
5698
6251
|
access: { mode: "fixed", level: "write" },
|
|
5699
6252
|
asyncMode: "sync",
|
|
@@ -5721,7 +6274,7 @@ function createPikgModule(dependencies = {}) {
|
|
|
5721
6274
|
properties: { meta_dir: { type: "string", minLength: 1 } },
|
|
5722
6275
|
additionalProperties: false
|
|
5723
6276
|
},
|
|
5724
|
-
outputSchema: OBJECT_OUTPUT$
|
|
6277
|
+
outputSchema: OBJECT_OUTPUT$e,
|
|
5725
6278
|
resultSchemaVersion: 1,
|
|
5726
6279
|
access: { mode: "fixed", level: "write" },
|
|
5727
6280
|
asyncMode: "sync",
|
|
@@ -5742,7 +6295,7 @@ function createPikgModule(dependencies = {}) {
|
|
|
5742
6295
|
properties: { dist_dir: { type: "string", minLength: 1 } },
|
|
5743
6296
|
additionalProperties: false
|
|
5744
6297
|
},
|
|
5745
|
-
outputSchema: OBJECT_OUTPUT$
|
|
6298
|
+
outputSchema: OBJECT_OUTPUT$e,
|
|
5746
6299
|
resultSchemaVersion: 1,
|
|
5747
6300
|
access: { mode: "fixed", level: "write" },
|
|
5748
6301
|
asyncMode: "sync",
|
|
@@ -5762,7 +6315,7 @@ function createPikgModule(dependencies = {}) {
|
|
|
5762
6315
|
required: ["pikg_path"],
|
|
5763
6316
|
additionalProperties: false
|
|
5764
6317
|
},
|
|
5765
|
-
outputSchema: OBJECT_OUTPUT$
|
|
6318
|
+
outputSchema: OBJECT_OUTPUT$e,
|
|
5766
6319
|
resultSchemaVersion: 1,
|
|
5767
6320
|
access: { mode: "fixed", level: "read" },
|
|
5768
6321
|
asyncMode: "sync",
|
|
@@ -5783,7 +6336,7 @@ function createPikgModule(dependencies = {}) {
|
|
|
5783
6336
|
properties: { meta_dir: { type: "string", minLength: 1 } },
|
|
5784
6337
|
additionalProperties: false
|
|
5785
6338
|
},
|
|
5786
|
-
outputSchema: OBJECT_OUTPUT$
|
|
6339
|
+
outputSchema: OBJECT_OUTPUT$e,
|
|
5787
6340
|
resultSchemaVersion: 1,
|
|
5788
6341
|
access: { mode: "fixed", level: "destructive" },
|
|
5789
6342
|
asyncMode: "sync",
|
|
@@ -5864,9 +6417,13 @@ async function doctorCommand(ctx, input) {
|
|
|
5864
6417
|
status: missingSources.length === 0 ? "ok" : "missing",
|
|
5865
6418
|
missing: missingSources
|
|
5866
6419
|
});
|
|
6420
|
+
const skills = pikg.sub_pkgs[PATH_KINDS["agent-skills"].key];
|
|
6421
|
+
if (skills?.source.type === "path" && !missingSources.includes(resolve$1(metaDir, skills.source.path))) {
|
|
6422
|
+
checks.push(await skillLintCheck(app.name, resolve$1(metaDir, skills.source.path)));
|
|
6423
|
+
}
|
|
5867
6424
|
if (app.categories[0] === PATH_KINDS["ext-tools"].category) {
|
|
5868
|
-
const
|
|
5869
|
-
checks.push(...await extToolsChecks(app, pikg, metaDir,
|
|
6425
|
+
const catalog2 = optionalInputString(input, "catalog");
|
|
6426
|
+
checks.push(...await extToolsChecks(app, pikg, metaDir, catalog2 ? resolveFromCwd$1(ctx, catalog2) : void 0));
|
|
5870
6427
|
}
|
|
5871
6428
|
} catch (error) {
|
|
5872
6429
|
checks.push({
|
|
@@ -5973,6 +6530,9 @@ async function initCommand(ctx, input, docker) {
|
|
|
5973
6530
|
if (kind === "aiws-controls") {
|
|
5974
6531
|
await writeAiwsSkeleton(absoluteSource, owner, name, input.composite === true);
|
|
5975
6532
|
sourceSummary2.skeleton = true;
|
|
6533
|
+
} else if (kind === "agent-skills") {
|
|
6534
|
+
await writeSkillsSkeleton(absoluteSource, name);
|
|
6535
|
+
sourceSummary2.skeleton = true;
|
|
5976
6536
|
} else {
|
|
5977
6537
|
await ctx.io.stderr(`warning: source does not exist yet: ${sourceSummary2.path}
|
|
5978
6538
|
`);
|
|
@@ -6036,6 +6596,64 @@ async function initCommand(ctx, input, docker) {
|
|
|
6036
6596
|
next_command: `buckyos pikg build ${metaDir}`
|
|
6037
6597
|
};
|
|
6038
6598
|
}
|
|
6599
|
+
const MAX_SKILL_SOURCE_BYTES = 64 * 1024 * 1024;
|
|
6600
|
+
async function skillLintCheck(packageName, source) {
|
|
6601
|
+
const check = { name: "skill_lint", path: source };
|
|
6602
|
+
let files;
|
|
6603
|
+
let ignored = [];
|
|
6604
|
+
try {
|
|
6605
|
+
if ((await getHost().stat(source)).isDirectory) {
|
|
6606
|
+
;
|
|
6607
|
+
({ files, ignored } = await readSkillDirectory(source, MAX_SKILL_SOURCE_BYTES));
|
|
6608
|
+
} else {
|
|
6609
|
+
files = /* @__PURE__ */ new Map();
|
|
6610
|
+
for (const entry of await readTarGz(await getHost().readFile(source), MAX_SKILL_SOURCE_BYTES)) {
|
|
6611
|
+
if (SKILL_DIRS.includes(entry.path.split("/")[0]))
|
|
6612
|
+
files.set(entry.path, { bytes: entry.bytes });
|
|
6613
|
+
else
|
|
6614
|
+
ignored.push(entry.path);
|
|
6615
|
+
}
|
|
6616
|
+
}
|
|
6617
|
+
} catch (error) {
|
|
6618
|
+
return { ...check, status: "error", detail: error instanceof Error ? error.message : String(error) };
|
|
6619
|
+
}
|
|
6620
|
+
const { skills, findings } = lintSkillPackage(packageName, files);
|
|
6621
|
+
const errors = findings.filter((finding) => finding.level === "error");
|
|
6622
|
+
return {
|
|
6623
|
+
...check,
|
|
6624
|
+
status: errors.length ? "error" : "ok",
|
|
6625
|
+
...errors.length ? { detail: errors.map((finding) => finding.note).join("; "), errors } : {},
|
|
6626
|
+
...errors.length ? {} : { digest: skillContentDigest(files) },
|
|
6627
|
+
skills: skills.map(({ kind, name, scope, size, commands }) => ({ kind, name, scope, size, commands })),
|
|
6628
|
+
warnings: findings.filter((finding) => finding.level !== "error"),
|
|
6629
|
+
...ignored.length ? { ignored_files: ignored } : {}
|
|
6630
|
+
};
|
|
6631
|
+
}
|
|
6632
|
+
async function writeSkillsSkeleton(dir, name) {
|
|
6633
|
+
const skill = name.replaceAll("-", "_");
|
|
6634
|
+
const manual = join(dir, "cmd_skills", skill);
|
|
6635
|
+
await getHost().mkdir(manual, { recursive: true });
|
|
6636
|
+
await getHost().writeTextFile(
|
|
6637
|
+
join(manual, "SKILL.md"),
|
|
6638
|
+
[
|
|
6639
|
+
"---",
|
|
6640
|
+
`name: ${skill}`,
|
|
6641
|
+
"description: One line: what this manual is for, so whoever picks manuals can choose it",
|
|
6642
|
+
"requires: What it needs beyond the commands below, in words",
|
|
6643
|
+
"scope: work",
|
|
6644
|
+
"---",
|
|
6645
|
+
`# ${skill}`,
|
|
6646
|
+
"",
|
|
6647
|
+
"What to do, step by step. Commands this manual runs that are not part of every runtime go into a front matter line",
|
|
6648
|
+
"`commands: name, name`; long material goes into `references/` next to this file and is read on demand.",
|
|
6649
|
+
"",
|
|
6650
|
+
"A package holds `cmd_skills/<name>/SKILL.md` (work and ui skills), `plan_skills/<name>/SKILL.md` and",
|
|
6651
|
+
"`goal_skills/<name>/SKILL.md`, each with an optional `references/`. A skill is text only: it brings no command and no",
|
|
6652
|
+
"install script. Commands come from the standard layer or from extension packages (`buckyos ext-tools`).",
|
|
6653
|
+
""
|
|
6654
|
+
].join("\n")
|
|
6655
|
+
);
|
|
6656
|
+
}
|
|
6039
6657
|
async function writeAiwsSkeleton(dir, ownerDid, name, composite) {
|
|
6040
6658
|
const kind = composite ? "composite" : "declarative";
|
|
6041
6659
|
const files = controlSkeleton({ authorDid: ownerDid, name, title: name, kind });
|
|
@@ -6264,7 +6882,7 @@ async function extToolsChecks(app, pikg, metaDir, catalogDir) {
|
|
|
6264
6882
|
for (const other of others.values()) {
|
|
6265
6883
|
if (manifest.conflicts.includes(other.id) || other.conflicts.includes(manifest.id))
|
|
6266
6884
|
continue;
|
|
6267
|
-
const shared = other.provides.map((provided) => provided.command).filter((
|
|
6885
|
+
const shared = other.provides.map((provided) => provided.command).filter((command2) => commands.has(command2));
|
|
6268
6886
|
if (shared.length > 0)
|
|
6269
6887
|
catalogErrors.push(`${other.id} also provides ${shared.join(", ")}: one of the two must list the other in conflicts`);
|
|
6270
6888
|
}
|
|
@@ -7060,11 +7678,11 @@ function deriveAppDid(name, owner) {
|
|
|
7060
7678
|
}
|
|
7061
7679
|
return `did:bns:${name}.${match[1]}`;
|
|
7062
7680
|
}
|
|
7063
|
-
async function requiredPrompt(ctx, canPrompt,
|
|
7681
|
+
async function requiredPrompt(ctx, canPrompt, message2, field) {
|
|
7064
7682
|
if (!canPrompt) {
|
|
7065
7683
|
throw new UsageError("MISSING_REQUIRED_INPUT", `${field} is required`);
|
|
7066
7684
|
}
|
|
7067
|
-
const answer = await ctx.io.prompt(
|
|
7685
|
+
const answer = await ctx.io.prompt(message2);
|
|
7068
7686
|
if (!answer?.trim())
|
|
7069
7687
|
throw new UsageError("MISSING_REQUIRED_INPUT", `${field} is required`);
|
|
7070
7688
|
return answer.trim();
|
|
@@ -7320,7 +7938,7 @@ const CONTROL_PANEL_SERVICE = "control-panel";
|
|
|
7320
7938
|
const PLAN_SCHEMA_VERSION = 4;
|
|
7321
7939
|
const STAGING_RELEASE_TIMEOUT_MS = 5e3;
|
|
7322
7940
|
const ZIP_LOCAL_MAGIC = [80, 75, 3, 4];
|
|
7323
|
-
const OBJECT_OUTPUT$
|
|
7941
|
+
const OBJECT_OUTPUT$d = { type: "object", additionalProperties: true };
|
|
7324
7942
|
const INSTALL_POLICIES = [
|
|
7325
7943
|
"strict-public",
|
|
7326
7944
|
"normal",
|
|
@@ -7331,9 +7949,9 @@ const INSTALL_POLICIES = [
|
|
|
7331
7949
|
function createAppModule(dependencies = {}) {
|
|
7332
7950
|
const commands = [
|
|
7333
7951
|
fetchCommand(dependencies),
|
|
7334
|
-
listCommand$
|
|
7952
|
+
listCommand$3(),
|
|
7335
7953
|
getCommand$3(),
|
|
7336
|
-
installCommand(dependencies),
|
|
7954
|
+
installCommand$1(dependencies),
|
|
7337
7955
|
upgradeCommand(dependencies),
|
|
7338
7956
|
uninstallCommand(dependencies),
|
|
7339
7957
|
cancelCommand$1(),
|
|
@@ -7346,10 +7964,10 @@ function createAppModule(dependencies = {}) {
|
|
|
7346
7964
|
return {
|
|
7347
7965
|
name: "app",
|
|
7348
7966
|
summary: "Inspect, install, upgrade, and control Apps",
|
|
7349
|
-
commands: commands.map((
|
|
7350
|
-
const handler =
|
|
7967
|
+
commands: commands.map((command2) => {
|
|
7968
|
+
const handler = command2.handler;
|
|
7351
7969
|
return {
|
|
7352
|
-
...
|
|
7970
|
+
...command2,
|
|
7353
7971
|
handler: async (ctx, input) => sanitizeAppOutput(await handler(ctx, input))
|
|
7354
7972
|
};
|
|
7355
7973
|
})
|
|
@@ -7371,7 +7989,7 @@ function cancelCommand$1() {
|
|
|
7371
7989
|
required: ["task_id"],
|
|
7372
7990
|
additionalProperties: false
|
|
7373
7991
|
},
|
|
7374
|
-
outputSchema: OBJECT_OUTPUT$
|
|
7992
|
+
outputSchema: OBJECT_OUTPUT$d,
|
|
7375
7993
|
resultSchemaVersion: 1,
|
|
7376
7994
|
access: { mode: "fixed", level: "write" },
|
|
7377
7995
|
asyncMode: "sync",
|
|
@@ -7406,7 +8024,7 @@ function fetchCommand(dependencies) {
|
|
|
7406
8024
|
target: { type: "object", additionalProperties: true },
|
|
7407
8025
|
install_params: { type: "object", additionalProperties: true }
|
|
7408
8026
|
}),
|
|
7409
|
-
outputSchema: OBJECT_OUTPUT$
|
|
8027
|
+
outputSchema: OBJECT_OUTPUT$d,
|
|
7410
8028
|
resultSchemaVersion: 1,
|
|
7411
8029
|
access: { mode: "fixed", level: "read" },
|
|
7412
8030
|
asyncMode: "sync",
|
|
@@ -7418,12 +8036,12 @@ function fetchCommand(dependencies) {
|
|
|
7418
8036
|
handler: async (ctx, input) => await fetchApp(ctx, input, dependencies)
|
|
7419
8037
|
};
|
|
7420
8038
|
}
|
|
7421
|
-
function listCommand$
|
|
8039
|
+
function listCommand$3() {
|
|
7422
8040
|
return {
|
|
7423
8041
|
verb: "list",
|
|
7424
8042
|
summary: "List visible installed Apps",
|
|
7425
8043
|
inputSchema: emptyInputSchema(),
|
|
7426
|
-
outputSchema: OBJECT_OUTPUT$
|
|
8044
|
+
outputSchema: OBJECT_OUTPUT$d,
|
|
7427
8045
|
resultSchemaVersion: 1,
|
|
7428
8046
|
access: { mode: "fixed", level: "read" },
|
|
7429
8047
|
asyncMode: "sync",
|
|
@@ -7448,7 +8066,7 @@ function getCommand$3() {
|
|
|
7448
8066
|
}
|
|
7449
8067
|
});
|
|
7450
8068
|
}
|
|
7451
|
-
function installCommand(dependencies) {
|
|
8069
|
+
function installCommand$1(dependencies) {
|
|
7452
8070
|
return {
|
|
7453
8071
|
verb: "install",
|
|
7454
8072
|
summary: "Install from a v4 plan or upgrade an existing App from a source",
|
|
@@ -7481,7 +8099,7 @@ function installCommand(dependencies) {
|
|
|
7481
8099
|
no_wait: { type: "boolean" },
|
|
7482
8100
|
policy: { type: "string", enum: [...INSTALL_POLICIES] }
|
|
7483
8101
|
}),
|
|
7484
|
-
outputSchema: OBJECT_OUTPUT$
|
|
8102
|
+
outputSchema: OBJECT_OUTPUT$d,
|
|
7485
8103
|
resultSchemaVersion: 1,
|
|
7486
8104
|
access: { mode: "fixed", level: "write" },
|
|
7487
8105
|
asyncMode: "either",
|
|
@@ -7525,7 +8143,7 @@ function upgradeCommand(dependencies) {
|
|
|
7525
8143
|
},
|
|
7526
8144
|
additionalProperties: false
|
|
7527
8145
|
},
|
|
7528
|
-
outputSchema: OBJECT_OUTPUT$
|
|
8146
|
+
outputSchema: OBJECT_OUTPUT$d,
|
|
7529
8147
|
resultSchemaVersion: 1,
|
|
7530
8148
|
access: { mode: "fixed", level: "write" },
|
|
7531
8149
|
asyncMode: "either",
|
|
@@ -7654,7 +8272,7 @@ function statusCommand$1() {
|
|
|
7654
8272
|
properties: { app_name: { type: "string", minLength: 1 } },
|
|
7655
8273
|
additionalProperties: false
|
|
7656
8274
|
},
|
|
7657
|
-
outputSchema: OBJECT_OUTPUT$
|
|
8275
|
+
outputSchema: OBJECT_OUTPUT$d,
|
|
7658
8276
|
resultSchemaVersion: 1,
|
|
7659
8277
|
access: { mode: "fixed", level: "read" },
|
|
7660
8278
|
asyncMode: "sync",
|
|
@@ -7725,7 +8343,7 @@ function publishCommand() {
|
|
|
7725
8343
|
required: ["local_dir", "app_doc"],
|
|
7726
8344
|
additionalProperties: false
|
|
7727
8345
|
},
|
|
7728
|
-
outputSchema: OBJECT_OUTPUT$
|
|
8346
|
+
outputSchema: OBJECT_OUTPUT$d,
|
|
7729
8347
|
resultSchemaVersion: 1,
|
|
7730
8348
|
access: { mode: "fixed", level: "write" },
|
|
7731
8349
|
asyncMode: "sync",
|
|
@@ -8106,6 +8724,10 @@ async function classifySource(ctx, input) {
|
|
|
8106
8724
|
throw new UsageError("INVALID_ARGUMENT", `invalid --from value: ${forced}`);
|
|
8107
8725
|
if (/^https?:\/\//i.test(raw))
|
|
8108
8726
|
return { kind: "url", url: parsePikgUrl(raw) };
|
|
8727
|
+
if (isDidSource(raw)) {
|
|
8728
|
+
const identifier2 = normalizeCatalogIdentifier(raw);
|
|
8729
|
+
return { kind: "catalog", display: identifier2, serviceSource: { kind: "identifier", identifier: identifier2 } };
|
|
8730
|
+
}
|
|
8109
8731
|
const candidatePath = resolveFromCwd(ctx, raw);
|
|
8110
8732
|
const stat2 = await tryLstat(candidatePath);
|
|
8111
8733
|
if (stat2) {
|
|
@@ -8446,24 +9068,24 @@ async function callControl(ctx, method, params) {
|
|
|
8446
9068
|
function normalizeAppServiceError(error) {
|
|
8447
9069
|
if (error instanceof ToolError)
|
|
8448
9070
|
return error;
|
|
8449
|
-
const
|
|
8450
|
-
const structured = parseEmbeddedJson(
|
|
9071
|
+
const message2 = errorMessage(error);
|
|
9072
|
+
const structured = parseEmbeddedJson(message2);
|
|
8451
9073
|
if (structured && typeof structured.code === "string") {
|
|
8452
9074
|
const rawDetails = isObject(structured.details) ? structured.details : structured;
|
|
8453
9075
|
const details = sanitizeAppOutput(rawDetails);
|
|
8454
9076
|
return new ToolError(
|
|
8455
9077
|
structured.code,
|
|
8456
|
-
typeof structured.message === "string" ? structured.message :
|
|
9078
|
+
typeof structured.message === "string" ? structured.message : message2,
|
|
8457
9079
|
structured.code === "AMBIGUOUS_APP_TARGET" ? EXIT_OPERATION : EXIT_OPERATION,
|
|
8458
9080
|
structured.retryable === true,
|
|
8459
9081
|
isObject(details) ? details : {}
|
|
8460
9082
|
);
|
|
8461
9083
|
}
|
|
8462
|
-
const lower =
|
|
9084
|
+
const lower = message2.toLowerCase();
|
|
8463
9085
|
if (lower.includes("invalid token") || lower.includes("unauthorized") || lower.includes("rpc call error: 401") || lower.includes("session expired") || lower.includes("token expired")) {
|
|
8464
9086
|
return new ToolError(
|
|
8465
9087
|
lower.includes("expired") ? "SESSION_EXPIRED" : "INVALID_SESSION",
|
|
8466
|
-
lower.includes("expired") ? "the session token has expired" :
|
|
9088
|
+
lower.includes("expired") ? "the session token has expired" : message2,
|
|
8467
9089
|
EXIT_AUTH
|
|
8468
9090
|
);
|
|
8469
9091
|
}
|
|
@@ -8474,18 +9096,18 @@ function normalizeAppServiceError(error) {
|
|
|
8474
9096
|
return new ToolError("TIMEOUT", "operation timed out", EXIT_TIMEOUT, true);
|
|
8475
9097
|
}
|
|
8476
9098
|
if (lower.includes("fetch failed") || lower.includes("connection refused") || lower.includes("rpc call error: 502") || lower.includes("rpc call error: 503") || lower.includes("rpc call error: 504")) {
|
|
8477
|
-
return new ToolError("SERVICE_UNAVAILABLE",
|
|
9099
|
+
return new ToolError("SERVICE_UNAVAILABLE", message2, EXIT_UNAVAILABLE, true);
|
|
8478
9100
|
}
|
|
8479
|
-
if (
|
|
8480
|
-
return new ToolError("RESOURCE_NOT_FOUND",
|
|
9101
|
+
if (message2.includes("APP_NOT_INSTALLED") || /not found/i.test(message2)) {
|
|
9102
|
+
return new ToolError("RESOURCE_NOT_FOUND", message2);
|
|
8481
9103
|
}
|
|
8482
|
-
if (/permission|forbidden/i.test(
|
|
8483
|
-
return new ToolError("PERMISSION_DENIED",
|
|
9104
|
+
if (/permission|forbidden/i.test(message2)) {
|
|
9105
|
+
return new ToolError("PERMISSION_DENIED", message2, EXIT_PERMISSION);
|
|
8484
9106
|
}
|
|
8485
|
-
if (/rolling restart is not supported/i.test(
|
|
8486
|
-
return new ToolError("UNSUPPORTED_STRATEGY",
|
|
9107
|
+
if (/rolling restart is not supported/i.test(message2)) {
|
|
9108
|
+
return new ToolError("UNSUPPORTED_STRATEGY", message2);
|
|
8487
9109
|
}
|
|
8488
|
-
return new ToolError("OPERATION_FAILED",
|
|
9110
|
+
return new ToolError("OPERATION_FAILED", message2, EXIT_OPERATION);
|
|
8489
9111
|
}
|
|
8490
9112
|
function sourceRpcParams(source) {
|
|
8491
9113
|
return { source: source.serviceSource };
|
|
@@ -8806,6 +9428,9 @@ function safeUrl(url) {
|
|
|
8806
9428
|
safe.hash = "";
|
|
8807
9429
|
return safe.toString();
|
|
8808
9430
|
}
|
|
9431
|
+
function isDidSource(value) {
|
|
9432
|
+
return value.trim().startsWith("did:");
|
|
9433
|
+
}
|
|
8809
9434
|
function looksLikeLocalPath(value) {
|
|
8810
9435
|
return value.includes("/") || value.includes("\\") || value.startsWith(".") || value.toLowerCase().endsWith(".pikg");
|
|
8811
9436
|
}
|
|
@@ -8821,10 +9446,10 @@ async function tryLstat(path) {
|
|
|
8821
9446
|
function resolveFromCwd(ctx, path) {
|
|
8822
9447
|
return isAbsolute(path) ? resolve(path) : resolve(ctx.cwd, path);
|
|
8823
9448
|
}
|
|
8824
|
-
function parseEmbeddedJson(
|
|
8825
|
-
for (let index =
|
|
9449
|
+
function parseEmbeddedJson(message2) {
|
|
9450
|
+
for (let index = message2.indexOf("{"); index >= 0; index = message2.indexOf("{", index + 1)) {
|
|
8826
9451
|
try {
|
|
8827
|
-
const value = JSON.parse(
|
|
9452
|
+
const value = JSON.parse(message2.slice(index));
|
|
8828
9453
|
if (isObject(value))
|
|
8829
9454
|
return value;
|
|
8830
9455
|
} catch {
|
|
@@ -8864,7 +9489,7 @@ function selectorCommand(options) {
|
|
|
8864
9489
|
required: ["app_name"],
|
|
8865
9490
|
additionalProperties: false
|
|
8866
9491
|
},
|
|
8867
|
-
outputSchema: OBJECT_OUTPUT$
|
|
9492
|
+
outputSchema: OBJECT_OUTPUT$d,
|
|
8868
9493
|
resultSchemaVersion: 1,
|
|
8869
9494
|
access: { mode: "fixed", level: options.access },
|
|
8870
9495
|
asyncMode: options.asyncMode,
|
|
@@ -9027,8 +9652,8 @@ async function defaultArtifactFetcher(url, ctx) {
|
|
|
9027
9652
|
function toHex(bytes) {
|
|
9028
9653
|
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
9029
9654
|
}
|
|
9030
|
-
const CONTROL_PANEL$
|
|
9031
|
-
const OBJECT_OUTPUT$
|
|
9655
|
+
const CONTROL_PANEL$4 = "control-panel";
|
|
9656
|
+
const OBJECT_OUTPUT$c = { type: "object", additionalProperties: true };
|
|
9032
9657
|
function createDiagnosticModule(dependencies = {}) {
|
|
9033
9658
|
return {
|
|
9034
9659
|
name: "diagnostic",
|
|
@@ -9067,7 +9692,7 @@ function collectCommand() {
|
|
|
9067
9692
|
required: ["services"],
|
|
9068
9693
|
additionalProperties: false
|
|
9069
9694
|
},
|
|
9070
|
-
outputSchema: OBJECT_OUTPUT$
|
|
9695
|
+
outputSchema: OBJECT_OUTPUT$c,
|
|
9071
9696
|
resultSchemaVersion: 1,
|
|
9072
9697
|
access: { mode: "fixed", level: "privileged" },
|
|
9073
9698
|
asyncMode: "task",
|
|
@@ -9083,7 +9708,7 @@ function collectCommand() {
|
|
|
9083
9708
|
const response = expectObject$4(
|
|
9084
9709
|
await callService(
|
|
9085
9710
|
ctx,
|
|
9086
|
-
CONTROL_PANEL$
|
|
9711
|
+
CONTROL_PANEL$4,
|
|
9087
9712
|
"diagnostic.collect",
|
|
9088
9713
|
compact$2({
|
|
9089
9714
|
services,
|
|
@@ -9121,7 +9746,7 @@ function exportCommand$2(dependencies) {
|
|
|
9121
9746
|
required: ["bundle_id", "path"],
|
|
9122
9747
|
additionalProperties: false
|
|
9123
9748
|
},
|
|
9124
|
-
outputSchema: OBJECT_OUTPUT$
|
|
9749
|
+
outputSchema: OBJECT_OUTPUT$c,
|
|
9125
9750
|
resultSchemaVersion: 1,
|
|
9126
9751
|
access: { mode: "fixed", level: "privileged" },
|
|
9127
9752
|
asyncMode: "sync",
|
|
@@ -9132,14 +9757,14 @@ function exportCommand$2(dependencies) {
|
|
|
9132
9757
|
}
|
|
9133
9758
|
async function exportDiagnostic(ctx, input, dependencies) {
|
|
9134
9759
|
const response = expectObject$4(
|
|
9135
|
-
await callService(ctx, CONTROL_PANEL$
|
|
9760
|
+
await callService(ctx, CONTROL_PANEL$4, "diagnostic.export", {
|
|
9136
9761
|
bundle_id: requiredInputString(input, "bundle_id")
|
|
9137
9762
|
}),
|
|
9138
9763
|
"Control Panel diagnostic.export response"
|
|
9139
9764
|
);
|
|
9140
9765
|
const downloaded = await downloadArtifact(
|
|
9141
9766
|
ctx,
|
|
9142
|
-
CONTROL_PANEL$
|
|
9767
|
+
CONTROL_PANEL$4,
|
|
9143
9768
|
expectString$2(response.url, "diagnostic.export.url"),
|
|
9144
9769
|
requiredInputString(input, "path"),
|
|
9145
9770
|
dependencies.download
|
|
@@ -9162,8 +9787,8 @@ async function exportDiagnostic(ctx, input, dependencies) {
|
|
|
9162
9787
|
function compact$2(value) {
|
|
9163
9788
|
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
|
|
9164
9789
|
}
|
|
9165
|
-
const CONTROL_PANEL$
|
|
9166
|
-
const OBJECT_OUTPUT$
|
|
9790
|
+
const CONTROL_PANEL$3 = "control-panel";
|
|
9791
|
+
const OBJECT_OUTPUT$b = { type: "object", additionalProperties: true };
|
|
9167
9792
|
const LOG_LEVELS = ["error", "warning", "info", "debug", "trace"];
|
|
9168
9793
|
function createLogModule(dependencies = {}) {
|
|
9169
9794
|
return {
|
|
@@ -9184,7 +9809,7 @@ function servicesCommand() {
|
|
|
9184
9809
|
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
9185
9810
|
outputSchema: {
|
|
9186
9811
|
type: "object",
|
|
9187
|
-
properties: { services: { type: "array", items: OBJECT_OUTPUT$
|
|
9812
|
+
properties: { services: { type: "array", items: OBJECT_OUTPUT$b } },
|
|
9188
9813
|
required: ["services"],
|
|
9189
9814
|
additionalProperties: false
|
|
9190
9815
|
},
|
|
@@ -9195,7 +9820,7 @@ function servicesCommand() {
|
|
|
9195
9820
|
examples: ["buckyos log services"],
|
|
9196
9821
|
handler: async (ctx) => {
|
|
9197
9822
|
const response = expectObject$4(
|
|
9198
|
-
await callService(ctx, CONTROL_PANEL$
|
|
9823
|
+
await callService(ctx, CONTROL_PANEL$3, "system.logs.list", {}),
|
|
9199
9824
|
"Control Panel log service list"
|
|
9200
9825
|
);
|
|
9201
9826
|
if (!Array.isArray(response.services))
|
|
@@ -9233,7 +9858,7 @@ function queryCommand$1() {
|
|
|
9233
9858
|
handler: async (ctx, input) => {
|
|
9234
9859
|
const params = normalizeFilter(input, true);
|
|
9235
9860
|
const response = expectObject$4(
|
|
9236
|
-
await callService(ctx, CONTROL_PANEL$
|
|
9861
|
+
await callService(ctx, CONTROL_PANEL$3, "system.logs.query", params),
|
|
9237
9862
|
"Control Panel log query response"
|
|
9238
9863
|
);
|
|
9239
9864
|
if (!Array.isArray(response.entries))
|
|
@@ -9257,7 +9882,7 @@ function tailCommand(dependencies) {
|
|
|
9257
9882
|
}
|
|
9258
9883
|
],
|
|
9259
9884
|
inputSchema: filterSchema({ from: { type: "string", enum: ["start", "end"] } }),
|
|
9260
|
-
outputSchema: OBJECT_OUTPUT$
|
|
9885
|
+
outputSchema: OBJECT_OUTPUT$b,
|
|
9261
9886
|
resultSchemaVersion: 1,
|
|
9262
9887
|
access: { mode: "fixed", level: "read" },
|
|
9263
9888
|
asyncMode: "stream",
|
|
@@ -9274,7 +9899,7 @@ function tailCommand(dependencies) {
|
|
|
9274
9899
|
if (remaining <= 0)
|
|
9275
9900
|
throw timeoutError();
|
|
9276
9901
|
const response = expectObject$4(
|
|
9277
|
-
await callService(ctx, CONTROL_PANEL$
|
|
9902
|
+
await callService(ctx, CONTROL_PANEL$3, "system.logs.tail", {
|
|
9278
9903
|
...params,
|
|
9279
9904
|
cursor,
|
|
9280
9905
|
from: inputString(input, "from") ?? "end",
|
|
@@ -9313,7 +9938,7 @@ function exportCommand$1(dependencies) {
|
|
|
9313
9938
|
...filterSchema({ path: { type: "string", minLength: 1 } }),
|
|
9314
9939
|
required: ["path"]
|
|
9315
9940
|
},
|
|
9316
|
-
outputSchema: OBJECT_OUTPUT$
|
|
9941
|
+
outputSchema: OBJECT_OUTPUT$b,
|
|
9317
9942
|
resultSchemaVersion: 1,
|
|
9318
9943
|
access: { mode: "fixed", level: "read" },
|
|
9319
9944
|
asyncMode: "sync",
|
|
@@ -9333,7 +9958,7 @@ function exportCommand$1(dependencies) {
|
|
|
9333
9958
|
);
|
|
9334
9959
|
}
|
|
9335
9960
|
const response = expectObject$4(
|
|
9336
|
-
await callService(ctx, CONTROL_PANEL$
|
|
9961
|
+
await callService(ctx, CONTROL_PANEL$3, "system.logs.download", {
|
|
9337
9962
|
...params,
|
|
9338
9963
|
mode: "filtered"
|
|
9339
9964
|
}),
|
|
@@ -9341,7 +9966,7 @@ function exportCommand$1(dependencies) {
|
|
|
9341
9966
|
);
|
|
9342
9967
|
const downloaded = await downloadArtifact(
|
|
9343
9968
|
ctx,
|
|
9344
|
-
CONTROL_PANEL$
|
|
9969
|
+
CONTROL_PANEL$3,
|
|
9345
9970
|
expectString$2(response.url, "log export url"),
|
|
9346
9971
|
requiredInputString(input, "path"),
|
|
9347
9972
|
dependencies.download
|
|
@@ -9464,16 +10089,16 @@ function abortableSleep(milliseconds, signal) {
|
|
|
9464
10089
|
});
|
|
9465
10090
|
}
|
|
9466
10091
|
const TASK_MANAGER = "task-manager";
|
|
9467
|
-
const CONTROL_PANEL$
|
|
9468
|
-
const OBJECT_OUTPUT$
|
|
10092
|
+
const CONTROL_PANEL$2 = "control-panel";
|
|
10093
|
+
const OBJECT_OUTPUT$a = { type: "object", additionalProperties: true };
|
|
9469
10094
|
function createTaskModule() {
|
|
9470
10095
|
return {
|
|
9471
10096
|
name: "task",
|
|
9472
10097
|
summary: "Inspect, wait for, cancel, and retry durable Tasks",
|
|
9473
|
-
commands: [listCommand$
|
|
10098
|
+
commands: [listCommand$2(), getCommand$2(), waitCommand(), cancelCommand(), retryCommand()]
|
|
9474
10099
|
};
|
|
9475
10100
|
}
|
|
9476
|
-
function listCommand$
|
|
10101
|
+
function listCommand$2() {
|
|
9477
10102
|
return {
|
|
9478
10103
|
verb: "list",
|
|
9479
10104
|
summary: "List visible Tasks",
|
|
@@ -9568,7 +10193,7 @@ function getCommand$2() {
|
|
|
9568
10193
|
required: ["task_id"],
|
|
9569
10194
|
additionalProperties: false
|
|
9570
10195
|
},
|
|
9571
|
-
outputSchema: OBJECT_OUTPUT$
|
|
10196
|
+
outputSchema: OBJECT_OUTPUT$a,
|
|
9572
10197
|
resultSchemaVersion: 1,
|
|
9573
10198
|
access: { mode: "fixed", level: "read" },
|
|
9574
10199
|
asyncMode: "sync",
|
|
@@ -9609,7 +10234,7 @@ function waitCommand() {
|
|
|
9609
10234
|
summary: "Stream changes until a Task becomes terminal",
|
|
9610
10235
|
positionals: [{ name: "task_id", description: "Opaque Task ID", required: true }],
|
|
9611
10236
|
inputSchema: taskIdSchema(),
|
|
9612
|
-
outputSchema: OBJECT_OUTPUT$
|
|
10237
|
+
outputSchema: OBJECT_OUTPUT$a,
|
|
9613
10238
|
resultSchemaVersion: 1,
|
|
9614
10239
|
access: { mode: "fixed", level: "read" },
|
|
9615
10240
|
asyncMode: "stream",
|
|
@@ -9660,7 +10285,7 @@ function cancelCommand() {
|
|
|
9660
10285
|
required: ["task_id"],
|
|
9661
10286
|
additionalProperties: false
|
|
9662
10287
|
},
|
|
9663
|
-
outputSchema: OBJECT_OUTPUT$
|
|
10288
|
+
outputSchema: OBJECT_OUTPUT$a,
|
|
9664
10289
|
resultSchemaVersion: 1,
|
|
9665
10290
|
access: { mode: "fixed", level: "write" },
|
|
9666
10291
|
asyncMode: "sync",
|
|
@@ -9703,7 +10328,7 @@ function retryCommand() {
|
|
|
9703
10328
|
required: ["task_id"],
|
|
9704
10329
|
additionalProperties: false
|
|
9705
10330
|
},
|
|
9706
|
-
outputSchema: OBJECT_OUTPUT$
|
|
10331
|
+
outputSchema: OBJECT_OUTPUT$a,
|
|
9707
10332
|
resultSchemaVersion: 1,
|
|
9708
10333
|
access: { mode: "fixed", level: "write" },
|
|
9709
10334
|
asyncMode: "either",
|
|
@@ -9720,7 +10345,7 @@ function retryCommand() {
|
|
|
9720
10345
|
throw new UsageError("TASK_NOT_RETRYABLE", "only a terminal failed Task can be retried");
|
|
9721
10346
|
}
|
|
9722
10347
|
const response = expectObject$4(
|
|
9723
|
-
await callService(ctx, CONTROL_PANEL$
|
|
10348
|
+
await callService(ctx, CONTROL_PANEL$2, "task.retry", {
|
|
9724
10349
|
task_id: taskId,
|
|
9725
10350
|
idempotency_key: ctx.idempotencyKey ?? `retry-${crypto.randomUUID()}`
|
|
9726
10351
|
}),
|
|
@@ -9777,7 +10402,7 @@ function invalidResponse$1(label) {
|
|
|
9777
10402
|
throw new ToolError("INVALID_SERVICE_RESPONSE", `${label} is invalid`, EXIT_INTERNAL);
|
|
9778
10403
|
}
|
|
9779
10404
|
const sdk = provisionSdk;
|
|
9780
|
-
const OBJECT_OUTPUT$
|
|
10405
|
+
const OBJECT_OUTPUT$9 = { type: "object", additionalProperties: true };
|
|
9781
10406
|
const ROOT_OPTION = {
|
|
9782
10407
|
name: "root",
|
|
9783
10408
|
description: "Installed BuckyOS root on this machine (BUCKYOS_ROOT); read by status/check, written by activate",
|
|
@@ -9861,7 +10486,7 @@ function statusCommand(deps) {
|
|
|
9861
10486
|
additionalProperties: false
|
|
9862
10487
|
},
|
|
9863
10488
|
outputSchema: {
|
|
9864
|
-
...OBJECT_OUTPUT$
|
|
10489
|
+
...OBJECT_OUTPUT$9,
|
|
9865
10490
|
properties: {
|
|
9866
10491
|
root: { type: "string" },
|
|
9867
10492
|
state: {
|
|
@@ -9899,7 +10524,7 @@ function checkCommand(deps) {
|
|
|
9899
10524
|
additionalProperties: false
|
|
9900
10525
|
},
|
|
9901
10526
|
outputSchema: {
|
|
9902
|
-
...OBJECT_OUTPUT$
|
|
10527
|
+
...OBJECT_OUTPUT$9,
|
|
9903
10528
|
properties: {
|
|
9904
10529
|
ready: { type: "boolean" },
|
|
9905
10530
|
root: { type: "string" },
|
|
@@ -9947,7 +10572,7 @@ function activateCommand(deps) {
|
|
|
9947
10572
|
additionalProperties: false
|
|
9948
10573
|
},
|
|
9949
10574
|
outputSchema: {
|
|
9950
|
-
...OBJECT_OUTPUT$
|
|
10575
|
+
...OBJECT_OUTPUT$9,
|
|
9951
10576
|
properties: {
|
|
9952
10577
|
root: { type: "string" },
|
|
9953
10578
|
state: { type: "string", enum: ["configured"] },
|
|
@@ -10229,13 +10854,15 @@ function inputFingerprint(input) {
|
|
|
10229
10854
|
hash.update(new TextEncoder().encode(JSON.stringify(material)));
|
|
10230
10855
|
return hash.digestHex();
|
|
10231
10856
|
}
|
|
10232
|
-
const OBJECT_OUTPUT$
|
|
10233
|
-
const SKILL_KINDS = ["cmd", "goal"];
|
|
10857
|
+
const OBJECT_OUTPUT$8 = { type: "object", additionalProperties: true };
|
|
10234
10858
|
const SKILLS_SUB_PKG = "agent_skills";
|
|
10235
|
-
const
|
|
10859
|
+
const SKILL_SCOPES = ["ui", "work"];
|
|
10860
|
+
const IMPORT_SCOPES = ["work", "ui", "plan"];
|
|
10861
|
+
const SOURCE_KINDS = ["pikg", "dir", "url", "did"];
|
|
10236
10862
|
const MAX_SKILL_PAYLOAD_BYTES = 64 * 1024 * 1024;
|
|
10863
|
+
const MAX_IMPORT_TEXT_BYTES = 512 * 1024;
|
|
10237
10864
|
const AGENT_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
10238
|
-
const AGENT_OPTION = {
|
|
10865
|
+
const AGENT_OPTION$1 = {
|
|
10239
10866
|
name: "agent",
|
|
10240
10867
|
property: "agent_id",
|
|
10241
10868
|
description: "Agent ID; the Agent serves kRPC at /kapi/<agent_id>",
|
|
@@ -10246,128 +10873,445 @@ const KIND_OPTION = {
|
|
|
10246
10873
|
name: "kind",
|
|
10247
10874
|
description: "Skill kind",
|
|
10248
10875
|
type: "string",
|
|
10249
|
-
enum: SKILL_KINDS
|
|
10876
|
+
enum: [...SKILL_KINDS]
|
|
10250
10877
|
};
|
|
10251
|
-
|
|
10878
|
+
const RUNTIME_OPTION = {
|
|
10879
|
+
name: "runtime",
|
|
10880
|
+
property: "runtime_id",
|
|
10881
|
+
description: "Runtime id (default: the private runtime)",
|
|
10882
|
+
type: "string"
|
|
10883
|
+
};
|
|
10884
|
+
const AGENT_PROPERTY = { type: "string", minLength: 1 };
|
|
10885
|
+
const NAME_PROPERTY = { type: "string", minLength: 1 };
|
|
10886
|
+
const KIND_PROPERTY = { type: "string", enum: [...SKILL_KINDS] };
|
|
10887
|
+
function command$1(definition) {
|
|
10888
|
+
const { level, properties, required, ...rest } = definition;
|
|
10889
|
+
return {
|
|
10890
|
+
options: [AGENT_OPTION$1],
|
|
10891
|
+
inputSchema: {
|
|
10892
|
+
type: "object",
|
|
10893
|
+
properties: { agent_id: AGENT_PROPERTY, ...properties },
|
|
10894
|
+
required: ["agent_id", ...required ?? []],
|
|
10895
|
+
additionalProperties: false
|
|
10896
|
+
},
|
|
10897
|
+
outputSchema: OBJECT_OUTPUT$8,
|
|
10898
|
+
resultSchemaVersion: 1,
|
|
10899
|
+
access: { mode: "fixed", level },
|
|
10900
|
+
asyncMode: "sync",
|
|
10901
|
+
requiresSession: true,
|
|
10902
|
+
...rest
|
|
10903
|
+
};
|
|
10904
|
+
}
|
|
10905
|
+
function createSkillModule(dependencies = {}) {
|
|
10252
10906
|
return {
|
|
10253
10907
|
name: "skill",
|
|
10254
|
-
summary: "List, install, and remove the
|
|
10908
|
+
summary: "List, install, enable, and remove the work/plan/goal skills of an Agent",
|
|
10255
10909
|
commands: [
|
|
10256
|
-
{
|
|
10910
|
+
command$1({
|
|
10257
10911
|
verb: "list",
|
|
10258
10912
|
summary: "List the skills of an Agent",
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
}
|
|
10266
|
-
|
|
10267
|
-
|
|
10913
|
+
description: "Skills that no new session takes (disabled by the owner) are left out unless --all, which also lists the drafts waiting for the owner. --scope selects work skills by scope. --stats adds how often each manual was frozen, and the count of work created without any manual.",
|
|
10914
|
+
options: [
|
|
10915
|
+
AGENT_OPTION$1,
|
|
10916
|
+
KIND_OPTION,
|
|
10917
|
+
{ name: "scope", description: "Work skills whose scope includes this", type: "string", enum: SKILL_SCOPES },
|
|
10918
|
+
{ name: "all", description: "Include skills that are not enabled, and drafts", type: "boolean" },
|
|
10919
|
+
{ name: "stats", description: "Include usage", type: "boolean" }
|
|
10920
|
+
],
|
|
10921
|
+
level: "read",
|
|
10922
|
+
properties: {
|
|
10923
|
+
kind: KIND_PROPERTY,
|
|
10924
|
+
scope: { type: "string", enum: SKILL_SCOPES },
|
|
10925
|
+
all: { type: "boolean" },
|
|
10926
|
+
stats: { type: "boolean" }
|
|
10268
10927
|
},
|
|
10269
|
-
outputSchema: OBJECT_OUTPUT$7,
|
|
10270
|
-
resultSchemaVersion: 1,
|
|
10271
|
-
access: { mode: "fixed", level: "read" },
|
|
10272
|
-
asyncMode: "sync",
|
|
10273
|
-
requiresSession: true,
|
|
10274
10928
|
examples: [
|
|
10275
10929
|
"buckyos skill list --agent jarvis.example.zone",
|
|
10276
|
-
"buckyos skill list --agent jarvis.example.zone --kind
|
|
10930
|
+
"buckyos skill list --agent jarvis.example.zone --kind work --scope ui",
|
|
10931
|
+
"buckyos skill list --agent jarvis.example.zone --all --stats"
|
|
10277
10932
|
],
|
|
10278
|
-
handler: async (ctx, input) =>
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
const skills = await listSkills(ctx, agentId, kind);
|
|
10282
|
-
return { agent_id: agentId, ...kind ? { kind } : {}, total: skills.length, skills };
|
|
10283
|
-
}
|
|
10284
|
-
},
|
|
10285
|
-
{
|
|
10933
|
+
handler: async (ctx, input) => await listCommand$1(ctx, input)
|
|
10934
|
+
}),
|
|
10935
|
+
command$1({
|
|
10286
10936
|
verb: "status",
|
|
10287
|
-
summary: "
|
|
10288
|
-
options: [
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
],
|
|
10292
|
-
inputSchema: {
|
|
10293
|
-
type: "object",
|
|
10294
|
-
properties: { agent_id: { type: "string", minLength: 1 }, runtime_id: { type: "string", minLength: 1 } },
|
|
10295
|
-
required: ["agent_id"],
|
|
10296
|
-
additionalProperties: false
|
|
10297
|
-
},
|
|
10298
|
-
outputSchema: OBJECT_OUTPUT$7,
|
|
10299
|
-
resultSchemaVersion: 1,
|
|
10300
|
-
access: { mode: "fixed", level: "read" },
|
|
10301
|
-
asyncMode: "sync",
|
|
10302
|
-
requiresSession: true,
|
|
10937
|
+
summary: "Whether each work skill works on a runtime of the Agent: baseline and platform, the commands it relies on, and the extension package that would bring what is missing",
|
|
10938
|
+
options: [AGENT_OPTION$1, RUNTIME_OPTION],
|
|
10939
|
+
level: "read",
|
|
10940
|
+
properties: { runtime_id: { type: "string", minLength: 1 } },
|
|
10303
10941
|
examples: ["buckyos skill status --agent jarvis.example.zone --runtime host"],
|
|
10304
|
-
handler: async (ctx, input) => await callService(ctx, agentIdFrom(input), "skills.status", {
|
|
10305
|
-
|
|
10306
|
-
|
|
10942
|
+
handler: async (ctx, input) => await callService(ctx, agentIdFrom(input), "skills.status", {
|
|
10943
|
+
runtime_id: input.runtime_id ?? null
|
|
10944
|
+
})
|
|
10945
|
+
}),
|
|
10946
|
+
command$1({
|
|
10307
10947
|
verb: "install",
|
|
10308
|
-
summary: "Install
|
|
10309
|
-
description: "
|
|
10310
|
-
positionals: [{ name: "
|
|
10948
|
+
summary: "Install skills into an Agent: plan, confirm, install",
|
|
10949
|
+
description: "The source is a skill PIKG (local file or HTTP(S) URL; verified offline, app_type agent_skills), a directory laid out like its agent_skills sub package (cmd_skills/, plan_skills/, goal_skills/; the package is named after the directory), or --draft <slug> for a draft in the AgentRoot. A skill is text only: a package with tools/ (commands, install scripts) or a file that is not UTF-8 text is refused; commands come from the standard layer or from extension packages (buckyos ext-tools) and a manual only names them in `commands`. The Agent plans the installation first (nothing is written): the plan and its risk findings are shown and must be confirmed; --yes accepts every risk level. Installing is checking and copying: nothing runs. Only the owner installs. Sessions created before keep their frozen manuals.",
|
|
10950
|
+
positionals: [{ name: "source", description: "Skill .pikg file, skill directory, or HTTP(S) URL", required: false }],
|
|
10311
10951
|
options: [
|
|
10312
|
-
AGENT_OPTION,
|
|
10313
|
-
{
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
}
|
|
10952
|
+
AGENT_OPTION$1,
|
|
10953
|
+
{ name: "from", description: "Force source type", type: "string", enum: SOURCE_KINDS },
|
|
10954
|
+
{ name: "draft", description: "Install this draft of the AgentRoot (skills_drafts/<slug>) instead of a source", type: "string" },
|
|
10955
|
+
{ ...RUNTIME_OPTION, description: "Runtime the commands the manuals name are checked against in the plan (default: the private runtime)" },
|
|
10956
|
+
{ name: "replace", description: "Replace skills of the same names from another package", type: "boolean" }
|
|
10318
10957
|
],
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
}
|
|
10326
|
-
required: ["pikg_path", "agent_id"],
|
|
10327
|
-
additionalProperties: false
|
|
10958
|
+
level: "write",
|
|
10959
|
+
properties: {
|
|
10960
|
+
source: { type: "string", minLength: 1 },
|
|
10961
|
+
from: { type: "string", enum: SOURCE_KINDS },
|
|
10962
|
+
draft: { type: "string", minLength: 1 },
|
|
10963
|
+
runtime_id: { type: "string", minLength: 1 },
|
|
10964
|
+
replace: { type: "boolean" }
|
|
10328
10965
|
},
|
|
10329
|
-
outputSchema: OBJECT_OUTPUT$7,
|
|
10330
|
-
resultSchemaVersion: 1,
|
|
10331
|
-
access: { mode: "fixed", level: "write" },
|
|
10332
|
-
asyncMode: "sync",
|
|
10333
|
-
requiresSession: true,
|
|
10334
10966
|
examples: [
|
|
10335
10967
|
"buckyos skill install ./dapp_dist/hello-skills-0.1.0.pikg --agent jarvis.example.zone",
|
|
10336
|
-
"buckyos skill install ./
|
|
10968
|
+
"buckyos --yes skill install ./skills --agent jarvis.example.zone --replace",
|
|
10969
|
+
"buckyos skill install https://example.com/hello-skills-0.1.0.pikg --agent jarvis.example.zone",
|
|
10970
|
+
"buckyos skill install --draft notes-to-slides --agent jarvis.example.zone"
|
|
10337
10971
|
],
|
|
10338
|
-
handler: async (ctx, input) => await
|
|
10339
|
-
},
|
|
10340
|
-
{
|
|
10972
|
+
handler: async (ctx, input) => await installCommand(ctx, input, dependencies)
|
|
10973
|
+
}),
|
|
10974
|
+
command$1({
|
|
10341
10975
|
verb: "remove",
|
|
10342
10976
|
summary: "Remove an installed skill from an Agent",
|
|
10343
|
-
description: "Only installed skills can be removed. Without --kind the kind is looked up by name.",
|
|
10977
|
+
description: "Only installed and imported skills can be removed. Without --kind the kind is looked up by name.",
|
|
10344
10978
|
positionals: [{ name: "name", description: "Skill name" }],
|
|
10345
|
-
options: [AGENT_OPTION, KIND_OPTION],
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10349
|
-
|
|
10350
|
-
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10979
|
+
options: [AGENT_OPTION$1, KIND_OPTION],
|
|
10980
|
+
level: "destructive",
|
|
10981
|
+
properties: { name: NAME_PROPERTY, kind: KIND_PROPERTY },
|
|
10982
|
+
required: ["name"],
|
|
10983
|
+
examples: ["buckyos --yes skill remove hello --agent jarvis.example.zone --kind work"],
|
|
10984
|
+
handler: async (ctx, input) => {
|
|
10985
|
+
const agentId = agentIdFrom(input);
|
|
10986
|
+
const name = requiredInputString(input, "name");
|
|
10987
|
+
const kind = await kindOf(ctx, agentId, name, input);
|
|
10988
|
+
await confirm$1(ctx, "skill remove", `Remove ${kind} skill ${name} from ${agentId}?`);
|
|
10989
|
+
const removed = await callService(ctx, agentId, "skills.remove", { kind, name });
|
|
10990
|
+
return { agent_id: agentId, removed: expectObject(removed, "skills.remove") };
|
|
10991
|
+
}
|
|
10992
|
+
}),
|
|
10993
|
+
command$1({
|
|
10994
|
+
verb: "disable",
|
|
10995
|
+
summary: "Disable a skill of an Agent: no new session takes it",
|
|
10996
|
+
description: "Any skill can be disabled, package ones included. Running sessions keep what they froze. Without --kind the kind is looked up by name.",
|
|
10997
|
+
positionals: [{ name: "name", description: "Skill name" }],
|
|
10998
|
+
options: [AGENT_OPTION$1, KIND_OPTION, { name: "reason", description: "Why, for the record", type: "string" }],
|
|
10999
|
+
level: "write",
|
|
11000
|
+
properties: { name: NAME_PROPERTY, kind: KIND_PROPERTY, reason: { type: "string" } },
|
|
11001
|
+
required: ["name"],
|
|
11002
|
+
examples: ['buckyos skill disable aigc_video --agent jarvis.example.zone --reason "no provider"'],
|
|
11003
|
+
handler: async (ctx, input) => await setEnabled(ctx, input, false)
|
|
11004
|
+
}),
|
|
11005
|
+
command$1({
|
|
11006
|
+
verb: "enable",
|
|
11007
|
+
summary: "Enable a disabled skill of an Agent",
|
|
11008
|
+
positionals: [{ name: "name", description: "Skill name" }],
|
|
11009
|
+
options: [AGENT_OPTION$1, KIND_OPTION],
|
|
11010
|
+
level: "write",
|
|
11011
|
+
properties: { name: NAME_PROPERTY, kind: KIND_PROPERTY },
|
|
11012
|
+
required: ["name"],
|
|
11013
|
+
examples: ["buckyos skill enable aigc_video --agent jarvis.example.zone"],
|
|
11014
|
+
handler: async (ctx, input) => await setEnabled(ctx, input, true)
|
|
11015
|
+
}),
|
|
11016
|
+
command$1({
|
|
11017
|
+
verb: "ui-list",
|
|
11018
|
+
summary: "The work skills every new conversation (UI session) of the Agent takes",
|
|
11019
|
+
level: "read",
|
|
11020
|
+
properties: {},
|
|
11021
|
+
examples: ["buckyos skill ui-list --agent jarvis.example.zone"],
|
|
11022
|
+
handler: async (ctx, input) => {
|
|
11023
|
+
const agentId = agentIdFrom(input);
|
|
11024
|
+
return { agent_id: agentId, ...await uiGet(ctx, agentId) };
|
|
11025
|
+
}
|
|
11026
|
+
}),
|
|
11027
|
+
command$1({
|
|
11028
|
+
verb: "ui-add",
|
|
11029
|
+
summary: "Add a skill whose scope includes ui to the conversations of the Agent",
|
|
11030
|
+
description: "Takes effect in conversations created afterwards. The result gives total_bytes: every conversation carries that much manual text.",
|
|
11031
|
+
positionals: [{ name: "name", description: "Skill name" }],
|
|
11032
|
+
level: "write",
|
|
11033
|
+
properties: { name: NAME_PROPERTY },
|
|
11034
|
+
required: ["name"],
|
|
11035
|
+
examples: ["buckyos skill ui-add share --agent jarvis.example.zone"],
|
|
11036
|
+
handler: async (ctx, input) => await uiChange(ctx, input, true)
|
|
11037
|
+
}),
|
|
11038
|
+
command$1({
|
|
11039
|
+
verb: "ui-remove",
|
|
11040
|
+
summary: "Take a skill out of the conversations of the Agent",
|
|
11041
|
+
positionals: [{ name: "name", description: "Skill name" }],
|
|
11042
|
+
level: "write",
|
|
11043
|
+
properties: { name: NAME_PROPERTY },
|
|
11044
|
+
required: ["name"],
|
|
11045
|
+
examples: ["buckyos skill ui-remove share --agent jarvis.example.zone"],
|
|
11046
|
+
handler: async (ctx, input) => await uiChange(ctx, input, false)
|
|
11047
|
+
}),
|
|
11048
|
+
command$1({
|
|
11049
|
+
verb: "import",
|
|
11050
|
+
summary: "Hand a text to the Agent to turn into a skill draft",
|
|
11051
|
+
description: "Reads the text from a file, an HTTP(S) URL, or stdin (-). The Agent starts a work session that writes a draft under skills_drafts/; nothing is installed. The owner reads the draft (skill drafts, skill draft-show) and installs it with skill install --draft <slug>.",
|
|
11052
|
+
positionals: [{ name: "source", description: "Text file, HTTP(S) URL, or - for stdin" }],
|
|
11053
|
+
options: [
|
|
11054
|
+
AGENT_OPTION$1,
|
|
11055
|
+
{ name: "name", description: "Slug of the draft", type: "string" },
|
|
11056
|
+
{ name: "scope", description: "What to make of it", type: "string", enum: IMPORT_SCOPES },
|
|
11057
|
+
{ ...RUNTIME_OPTION, description: "Runtime the commands the text names are checked on (default: the private runtime)" }
|
|
11058
|
+
],
|
|
11059
|
+
level: "write",
|
|
11060
|
+
properties: {
|
|
11061
|
+
source: { type: "string", minLength: 1 },
|
|
11062
|
+
name: { type: "string", minLength: 1 },
|
|
11063
|
+
scope: { type: "string", enum: IMPORT_SCOPES },
|
|
11064
|
+
runtime_id: { type: "string", minLength: 1 }
|
|
10355
11065
|
},
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
|
|
10359
|
-
|
|
10360
|
-
|
|
10361
|
-
|
|
10362
|
-
|
|
10363
|
-
|
|
11066
|
+
required: ["source"],
|
|
11067
|
+
examples: [
|
|
11068
|
+
"buckyos skill import ./notes/release-checklist.md --agent jarvis.example.zone --name release_checklist",
|
|
11069
|
+
"cat howto.md | buckyos skill import - --agent jarvis.example.zone --scope plan"
|
|
11070
|
+
],
|
|
11071
|
+
handler: async (ctx, input) => await importCommand$1(ctx, input, dependencies)
|
|
11072
|
+
}),
|
|
11073
|
+
command$1({
|
|
11074
|
+
verb: "drafts",
|
|
11075
|
+
summary: "List the skill drafts of an Agent that wait for the owner",
|
|
11076
|
+
level: "read",
|
|
11077
|
+
properties: {},
|
|
11078
|
+
examples: ["buckyos skill drafts --agent jarvis.example.zone"],
|
|
11079
|
+
handler: async (ctx, input) => {
|
|
11080
|
+
const agentId = agentIdFrom(input);
|
|
11081
|
+
const drafts = await listDrafts(ctx, agentId);
|
|
11082
|
+
return { agent_id: agentId, total: drafts.length, drafts };
|
|
11083
|
+
}
|
|
11084
|
+
}),
|
|
11085
|
+
command$1({
|
|
11086
|
+
verb: "draft-show",
|
|
11087
|
+
summary: "Show a skill draft, or one of its files",
|
|
11088
|
+
positionals: [{ name: "slug", description: "Draft slug" }],
|
|
11089
|
+
options: [AGENT_OPTION$1, { name: "file", description: "Draft-relative path of a file to print", type: "string" }],
|
|
11090
|
+
level: "read",
|
|
11091
|
+
properties: { slug: NAME_PROPERTY, file: { type: "string", minLength: 1 } },
|
|
11092
|
+
required: ["slug"],
|
|
11093
|
+
examples: [
|
|
11094
|
+
"buckyos skill draft-show release_checklist --agent jarvis.example.zone",
|
|
11095
|
+
"buckyos skill draft-show release_checklist --file cmd_skills/release_checklist/SKILL.md --agent jarvis.example.zone"
|
|
11096
|
+
],
|
|
11097
|
+
handler: async (ctx, input) => {
|
|
11098
|
+
const agentId = agentIdFrom(input);
|
|
11099
|
+
const slug = requiredInputString(input, "slug");
|
|
11100
|
+
const file = inputString(input, "file");
|
|
11101
|
+
if (file) {
|
|
11102
|
+
const shown = expectObject(await callService(ctx, agentId, "skills.draft_file", { slug, file }), "skills.draft_file");
|
|
11103
|
+
return { agent_id: agentId, slug, file, text: shown.text };
|
|
11104
|
+
}
|
|
11105
|
+
const draft = (await listDrafts(ctx, agentId)).find((item) => item.slug === slug);
|
|
11106
|
+
if (!draft)
|
|
11107
|
+
throw new ToolError("RESOURCE_NOT_FOUND", `Agent ${agentId} has no skill draft ${slug}`);
|
|
11108
|
+
return { agent_id: agentId, ...draft, install_command: `buckyos skill install --draft ${slug} --agent ${agentId}` };
|
|
11109
|
+
}
|
|
11110
|
+
}),
|
|
11111
|
+
command$1({
|
|
11112
|
+
verb: "draft-discard",
|
|
11113
|
+
summary: "Delete a skill draft",
|
|
11114
|
+
positionals: [{ name: "slug", description: "Draft slug" }],
|
|
11115
|
+
level: "destructive",
|
|
11116
|
+
properties: { slug: NAME_PROPERTY },
|
|
11117
|
+
required: ["slug"],
|
|
11118
|
+
examples: ["buckyos --yes skill draft-discard release_checklist --agent jarvis.example.zone"],
|
|
11119
|
+
handler: async (ctx, input) => {
|
|
11120
|
+
const agentId = agentIdFrom(input);
|
|
11121
|
+
const slug = requiredInputString(input, "slug");
|
|
11122
|
+
await confirm$1(ctx, "skill draft-discard", `Discard skill draft ${slug} of ${agentId}?`);
|
|
11123
|
+
await callService(ctx, agentId, "skills.draft_discard", { slug });
|
|
11124
|
+
return { agent_id: agentId, discarded: slug };
|
|
11125
|
+
}
|
|
11126
|
+
})
|
|
10364
11127
|
]
|
|
10365
11128
|
};
|
|
10366
11129
|
}
|
|
10367
|
-
async function
|
|
11130
|
+
async function listCommand$1(ctx, input) {
|
|
11131
|
+
const agentId = agentIdFrom(input);
|
|
11132
|
+
const scope = inputString(input, "scope");
|
|
11133
|
+
let kind = inputString(input, "kind");
|
|
11134
|
+
if (scope) {
|
|
11135
|
+
if (kind && kind !== "work")
|
|
11136
|
+
throw new UsageError("ARGUMENT_CONFLICT", `--scope selects work skills; a ${kind} skill has no scope`);
|
|
11137
|
+
kind = "work";
|
|
11138
|
+
}
|
|
11139
|
+
const listed = (await listSkills(ctx, agentId, kind)).filter((skill) => {
|
|
11140
|
+
if (!scope)
|
|
11141
|
+
return true;
|
|
11142
|
+
const own = typeof skill.scope === "string" ? skill.scope.split(",").map((word) => word.trim()) : ["work"];
|
|
11143
|
+
return own.includes(scope);
|
|
11144
|
+
});
|
|
11145
|
+
const shown = input.all === true ? listed : listed.filter((skill) => skill.enabled !== false);
|
|
11146
|
+
const stats = input.stats === true;
|
|
11147
|
+
const skills = stats ? shown : shown.map(({ usage: _usage, ...skill }) => skill);
|
|
11148
|
+
const result = {
|
|
11149
|
+
agent_id: agentId,
|
|
11150
|
+
...kind ? { kind } : {},
|
|
11151
|
+
...scope ? { scope } : {},
|
|
11152
|
+
total: skills.length,
|
|
11153
|
+
not_enabled: listed.length - listed.filter((skill) => skill.enabled !== false).length,
|
|
11154
|
+
skills
|
|
11155
|
+
};
|
|
11156
|
+
if (stats) {
|
|
11157
|
+
const state = expectObject(await callService(ctx, agentId, "skills.state", {}), "skills.state");
|
|
11158
|
+
const usage2 = state.usage && typeof state.usage === "object" ? state.usage : {};
|
|
11159
|
+
result.usage_none = usage2.none ?? { frozen: 0, last_ms: 0 };
|
|
11160
|
+
}
|
|
11161
|
+
if (input.all === true)
|
|
11162
|
+
result.drafts = await listDrafts(ctx, agentId);
|
|
11163
|
+
return result;
|
|
11164
|
+
}
|
|
11165
|
+
async function setEnabled(ctx, input, enabled) {
|
|
11166
|
+
const agentId = agentIdFrom(input);
|
|
11167
|
+
const name = requiredInputString(input, "name");
|
|
11168
|
+
const kind = await kindOf(ctx, agentId, name, input);
|
|
11169
|
+
const reason = inputString(input, "reason");
|
|
11170
|
+
const skill = await callService(ctx, agentId, "skills.set_enabled", {
|
|
11171
|
+
kind,
|
|
11172
|
+
name,
|
|
11173
|
+
enabled,
|
|
11174
|
+
...reason ? { reason } : {}
|
|
11175
|
+
});
|
|
11176
|
+
return { agent_id: agentId, skill: expectObject(skill, "skills.set_enabled") };
|
|
11177
|
+
}
|
|
11178
|
+
async function uiGet(ctx, agentId) {
|
|
11179
|
+
const ui = expectObject(await callService(ctx, agentId, "skills.ui_get", {}), "skills.ui_get");
|
|
11180
|
+
if (!Array.isArray(ui.names))
|
|
11181
|
+
invalidResponse("skills.ui_get");
|
|
11182
|
+
return { ...ui, names: ui.names.map(String) };
|
|
11183
|
+
}
|
|
11184
|
+
async function uiChange(ctx, input, add) {
|
|
10368
11185
|
const agentId = agentIdFrom(input);
|
|
10369
|
-
const
|
|
10370
|
-
const
|
|
11186
|
+
const name = requiredInputString(input, "name");
|
|
11187
|
+
const current = await uiGet(ctx, agentId);
|
|
11188
|
+
const has = current.names.includes(name);
|
|
11189
|
+
if (!add && !has) {
|
|
11190
|
+
throw new ToolError("RESOURCE_NOT_FOUND", `${name} is not among the UI skills of ${agentId} (${current.names.join(", ") || "none"})`);
|
|
11191
|
+
}
|
|
11192
|
+
if (add && has)
|
|
11193
|
+
return { agent_id: agentId, changed: false, ...current };
|
|
11194
|
+
const names = add ? [...current.names, name] : current.names.filter((item) => item !== name);
|
|
11195
|
+
const ui = expectObject(await callService(ctx, agentId, "skills.ui_set", { names }), "skills.ui_set");
|
|
11196
|
+
return { agent_id: agentId, changed: true, ...ui };
|
|
11197
|
+
}
|
|
11198
|
+
async function installCommand(ctx, input, dependencies) {
|
|
11199
|
+
const agentId = agentIdFrom(input);
|
|
11200
|
+
const source = await skillSource(ctx, input, dependencies);
|
|
11201
|
+
const runtimeId = inputString(input, "runtime_id");
|
|
11202
|
+
const runtime = runtimeId ? { runtime_id: runtimeId } : {};
|
|
11203
|
+
const plan = expectObject(
|
|
11204
|
+
await callService(ctx, agentId, "skills.install_plan", { ...source.params, ...runtime }),
|
|
11205
|
+
"skills.install_plan"
|
|
11206
|
+
);
|
|
11207
|
+
const planDigest = plan.plan_digest;
|
|
11208
|
+
if (typeof planDigest !== "string" || !planDigest)
|
|
11209
|
+
invalidResponse("skills.install_plan");
|
|
11210
|
+
if (!ctx.confirmed) {
|
|
11211
|
+
if (ctx.config.nonInteractive || !ctx.io.inputIsTerminal) {
|
|
11212
|
+
throw new ToolError(
|
|
11213
|
+
"CONFIRMATION_REQUIRED",
|
|
11214
|
+
`skill install requires --yes in non-interactive execution (risk: ${riskLevel(plan)})`,
|
|
11215
|
+
EXIT_PERMISSION,
|
|
11216
|
+
false,
|
|
11217
|
+
{ plan }
|
|
11218
|
+
);
|
|
11219
|
+
}
|
|
11220
|
+
await ctx.io.stderr(planText(plan));
|
|
11221
|
+
await confirm$1(ctx, "skill install", `Install into ${agentId} (risk: ${riskLevel(plan)})?`);
|
|
11222
|
+
}
|
|
11223
|
+
const report = expectObject(
|
|
11224
|
+
await callService(ctx, agentId, "skills.install", {
|
|
11225
|
+
...source.params,
|
|
11226
|
+
plan_digest: planDigest,
|
|
11227
|
+
replace: input.replace === true
|
|
11228
|
+
}),
|
|
11229
|
+
"skills.install"
|
|
11230
|
+
);
|
|
11231
|
+
return { agent_id: agentId, source: source.summary, ...source.extra, plan, ...report };
|
|
11232
|
+
}
|
|
11233
|
+
function riskLevel(plan) {
|
|
11234
|
+
const risk = plan.risk && typeof plan.risk === "object" ? plan.risk : {};
|
|
11235
|
+
return typeof risk.level === "string" ? risk.level : "unknown";
|
|
11236
|
+
}
|
|
11237
|
+
function planText(plan) {
|
|
11238
|
+
const lines = [`Install plan: ${plan.package}${plan.version ? ` ${plan.version}` : ""} (${plan.digest})`];
|
|
11239
|
+
for (const item of Array.isArray(plan.skills) ? plan.skills : []) {
|
|
11240
|
+
const skill = item;
|
|
11241
|
+
const scope = typeof skill.scope === "string" ? ` [${skill.scope}]` : "";
|
|
11242
|
+
const replaces = skill.replaces ? `; replaces the ${skill.replaces} skill` : "";
|
|
11243
|
+
const commands = Array.isArray(skill.commands) && skill.commands.length ? `; commands: ${skill.commands.join(", ")}` : "";
|
|
11244
|
+
lines.push(` ${skill.kind} ${skill.name}${scope}: ${skill.description ?? ""}${commands}${replaces}`);
|
|
11245
|
+
}
|
|
11246
|
+
if (plan.checked_runtime_id)
|
|
11247
|
+
lines.push(`Commands checked on runtime: ${plan.checked_runtime_id}`);
|
|
11248
|
+
for (const item of Array.isArray(plan.command_status) ? plan.command_status : []) {
|
|
11249
|
+
const entry = item;
|
|
11250
|
+
const status = entry.status && typeof entry.status === "object" ? entry.status : {};
|
|
11251
|
+
if (status.state !== "partial")
|
|
11252
|
+
continue;
|
|
11253
|
+
const states = status.commands && typeof status.commands === "object" ? status.commands : {};
|
|
11254
|
+
const missing = Object.keys(states).filter((name) => states[name]?.present === false);
|
|
11255
|
+
const packages = (Array.isArray(status.recommended_packages) ? status.recommended_packages : []).map((pkg) => String(pkg.id));
|
|
11256
|
+
const none = Array.isArray(status.no_package) ? status.no_package.map(String) : [];
|
|
11257
|
+
lines.push(
|
|
11258
|
+
` ${entry.name}: missing ${missing.join(", ")}` + (packages.length ? `; extension packages that bring them: ${packages.join(", ")} (buckyos ext-tools enable)` : "") + (none.length ? `; no package provides ${none.join(", ")}` : "")
|
|
11259
|
+
);
|
|
11260
|
+
}
|
|
11261
|
+
const risk = plan.risk && typeof plan.risk === "object" ? plan.risk : {};
|
|
11262
|
+
lines.push(`Risk: ${riskLevel(plan)}`);
|
|
11263
|
+
for (const item of Array.isArray(risk.findings) ? risk.findings : []) {
|
|
11264
|
+
const finding = item;
|
|
11265
|
+
lines.push(` [${finding.level}] ${finding.code} ${finding.where}: ${finding.note}`);
|
|
11266
|
+
}
|
|
11267
|
+
return `${lines.join("\n")}
|
|
11268
|
+
`;
|
|
11269
|
+
}
|
|
11270
|
+
async function skillSource(ctx, input, dependencies) {
|
|
11271
|
+
const host2 = getHost();
|
|
11272
|
+
const draft = inputString(input, "draft");
|
|
11273
|
+
const raw = inputString(input, "source");
|
|
11274
|
+
const forced = inputString(input, "from");
|
|
11275
|
+
if (draft) {
|
|
11276
|
+
if (raw || forced)
|
|
11277
|
+
throw new UsageError("ARGUMENT_CONFLICT", "--draft takes no <source> and no --from: the Agent reads the draft itself");
|
|
11278
|
+
return { summary: { kind: "draft", draft }, params: { draft }, extra: {} };
|
|
11279
|
+
}
|
|
11280
|
+
if (!raw)
|
|
11281
|
+
throw new UsageError("MISSING_ARGUMENT", "a <source> or --draft <slug> is required");
|
|
11282
|
+
const local = host2.path.isAbsolute(raw) ? host2.path.resolve(raw) : host2.path.resolve(ctx.cwd, raw);
|
|
11283
|
+
let directory = forced === "dir";
|
|
11284
|
+
if (!forced && !/^https?:\/\//i.test(raw) && !isDidSource(raw)) {
|
|
11285
|
+
try {
|
|
11286
|
+
directory = (await host2.stat(local)).isDirectory;
|
|
11287
|
+
} catch (error) {
|
|
11288
|
+
if (!isHostError(error, "NotFound"))
|
|
11289
|
+
throw error;
|
|
11290
|
+
}
|
|
11291
|
+
}
|
|
11292
|
+
if (directory)
|
|
11293
|
+
return await directorySource(local);
|
|
11294
|
+
const classified = await classifySource(ctx, { source: raw, ...forced ? { from: forced === "did" ? "catalog" : forced } : {} });
|
|
11295
|
+
if (classified.kind === "catalog") {
|
|
11296
|
+
throw new ToolError(
|
|
11297
|
+
"SKILL_SOURCE_UNSUPPORTED",
|
|
11298
|
+
`${classified.display} names a Catalog App, and the Catalog cannot hand a skill PIKG to this tool yet: install from the .pikg file or its URL`,
|
|
11299
|
+
EXIT_UNAVAILABLE
|
|
11300
|
+
);
|
|
11301
|
+
}
|
|
11302
|
+
if (classified.kind === "pikg")
|
|
11303
|
+
return await pikgSource(classified.path, { kind: "pikg", path: classified.path });
|
|
11304
|
+
await host2.mkdir(ctx.configStore.root, { recursive: true, mode: 448 });
|
|
11305
|
+
const temporary = await host2.makeTempDir({ dir: ctx.configStore.root, prefix: ".skill-pikg-" });
|
|
11306
|
+
try {
|
|
11307
|
+
const snapshot = await downloadPikg(classified.url, host2.path.join(temporary, "source.pikg"), dependencies.download, ctx.signal);
|
|
11308
|
+
return await pikgSource(snapshot.path, { kind: "url", url: snapshot.display });
|
|
11309
|
+
} finally {
|
|
11310
|
+
await host2.remove(temporary, { recursive: true }).catch(() => {
|
|
11311
|
+
});
|
|
11312
|
+
}
|
|
11313
|
+
}
|
|
11314
|
+
async function pikgSource(path, summary2) {
|
|
10371
11315
|
const inspection = await inspectPikg(path);
|
|
10372
11316
|
if (inspection.app.app_type !== SKILLS_SUB_PKG) {
|
|
10373
11317
|
throw new UsageError(
|
|
@@ -10377,72 +11321,152 @@ async function installSkills(ctx, input) {
|
|
|
10377
11321
|
}
|
|
10378
11322
|
const payload = inspection.subpackages.find((item) => item.key === SKILLS_SUB_PKG)?.payload;
|
|
10379
11323
|
const archive = await openZip(path);
|
|
10380
|
-
const bytes = await readZipEntry(
|
|
10381
|
-
archive,
|
|
10382
|
-
archive.byName.get(payload.path),
|
|
10383
|
-
MAX_SKILL_PAYLOAD_BYTES
|
|
10384
|
-
);
|
|
11324
|
+
const bytes = await readZipEntry(archive, archive.byName.get(payload.path), MAX_SKILL_PAYLOAD_BYTES);
|
|
10385
11325
|
if (`sha256:${sha256Bytes(bytes)}` !== payload.digest) {
|
|
10386
11326
|
throw new ToolError("INVALID_PACKAGE", "PIKG changed after it was verified");
|
|
10387
11327
|
}
|
|
10388
|
-
const files =
|
|
11328
|
+
const files = /* @__PURE__ */ new Map();
|
|
10389
11329
|
const ignored = [];
|
|
10390
11330
|
for (const entry of await readTarGz(bytes, MAX_SKILL_PAYLOAD_BYTES)) {
|
|
10391
|
-
if (
|
|
11331
|
+
if (SKILL_DIRS.includes(entry.path.split("/")[0]))
|
|
11332
|
+
files.set(entry.path, { bytes: entry.bytes });
|
|
11333
|
+
else
|
|
10392
11334
|
ignored.push(entry.path);
|
|
10393
|
-
continue;
|
|
10394
|
-
}
|
|
10395
|
-
files[entry.path] = { content: base64(entry.bytes), executable: entry.executable };
|
|
10396
11335
|
}
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
11336
|
+
return {
|
|
11337
|
+
summary: summary2,
|
|
11338
|
+
params: {
|
|
11339
|
+
package: {
|
|
11340
|
+
package: inspection.app.name,
|
|
11341
|
+
version: inspection.app.version,
|
|
11342
|
+
pikg_digest: inspection.pikg_digest,
|
|
11343
|
+
files: packageFiles(files)
|
|
11344
|
+
}
|
|
11345
|
+
},
|
|
11346
|
+
extra: { pikg_digest: inspection.pikg_digest, ...ignored.length ? { ignored_files: ignored } : {} }
|
|
10402
11347
|
};
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
|
|
10407
|
-
|
|
11348
|
+
}
|
|
11349
|
+
async function directorySource(path) {
|
|
11350
|
+
const host2 = getHost();
|
|
11351
|
+
let root;
|
|
11352
|
+
let read2;
|
|
11353
|
+
try {
|
|
11354
|
+
root = await host2.realPath(path);
|
|
11355
|
+
if (!(await host2.stat(root)).isDirectory)
|
|
11356
|
+
throw new Error("not a directory");
|
|
11357
|
+
read2 = await readSkillDirectory(root, MAX_SKILL_PAYLOAD_BYTES);
|
|
11358
|
+
} catch (error) {
|
|
11359
|
+
throw new UsageError("INVALID_SKILL_SOURCE", `${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
11360
|
+
}
|
|
11361
|
+
const name = host2.path.basename(root);
|
|
11362
|
+
const invalid2 = lintSkillPackage(name, read2.files).findings.find((finding) => finding.level === "error");
|
|
11363
|
+
if (invalid2)
|
|
11364
|
+
throw new UsageError("INVALID_SKILL_PACKAGE", invalid2.note);
|
|
10408
11365
|
return {
|
|
10409
|
-
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
...expectObject(result, "skills.install"),
|
|
10413
|
-
...ignored.length ? { ignored_files: ignored } : {},
|
|
10414
|
-
...commands ? { commands } : {}
|
|
11366
|
+
summary: { kind: "dir", path: root },
|
|
11367
|
+
params: { package: { package: name, version: "", files: packageFiles(read2.files) } },
|
|
11368
|
+
extra: read2.ignored.length ? { ignored_files: read2.ignored } : {}
|
|
10415
11369
|
};
|
|
10416
11370
|
}
|
|
10417
|
-
|
|
11371
|
+
function packageFiles(files) {
|
|
11372
|
+
const out = {};
|
|
11373
|
+
for (const path of [...files.keys()].sort())
|
|
11374
|
+
out[path] = { content: base64(files.get(path).bytes) };
|
|
11375
|
+
return out;
|
|
11376
|
+
}
|
|
11377
|
+
async function importCommand$1(ctx, input, dependencies) {
|
|
11378
|
+
const host2 = getHost();
|
|
10418
11379
|
const agentId = agentIdFrom(input);
|
|
10419
|
-
const
|
|
10420
|
-
let
|
|
10421
|
-
|
|
10422
|
-
|
|
10423
|
-
|
|
10424
|
-
|
|
11380
|
+
const raw = requiredInputString(input, "source");
|
|
11381
|
+
let text2;
|
|
11382
|
+
let source;
|
|
11383
|
+
if (raw === "-") {
|
|
11384
|
+
text2 = await (dependencies.readStdin ?? (() => host2.readStdin()))();
|
|
11385
|
+
source = "stdin";
|
|
11386
|
+
} else if (/^https?:\/\//i.test(raw)) {
|
|
11387
|
+
let url;
|
|
11388
|
+
try {
|
|
11389
|
+
url = new URL(raw);
|
|
11390
|
+
} catch {
|
|
11391
|
+
throw new UsageError("INVALID_ARGUMENT", `invalid URL: ${raw}`);
|
|
10425
11392
|
}
|
|
10426
|
-
if (
|
|
10427
|
-
throw new UsageError("
|
|
11393
|
+
if (url.username || url.password)
|
|
11394
|
+
throw new UsageError("INVALID_ARGUMENT", "the URL must not contain credentials");
|
|
11395
|
+
try {
|
|
11396
|
+
text2 = await (dependencies.fetchText ?? fetchText)(url, ctx.signal);
|
|
11397
|
+
} catch (error) {
|
|
11398
|
+
if (error instanceof ToolError)
|
|
11399
|
+
throw error;
|
|
11400
|
+
ctx.signal.throwIfAborted();
|
|
11401
|
+
throw new ToolError("SKILL_IMPORT_FETCH_FAILED", `failed to fetch ${url.origin}${url.pathname}: ${error instanceof Error ? error.message : String(error)}`, EXIT_UNAVAILABLE, true);
|
|
10428
11402
|
}
|
|
10429
|
-
|
|
11403
|
+
source = `${url.origin}${url.pathname}`;
|
|
11404
|
+
} else {
|
|
11405
|
+
const path = host2.path.isAbsolute(raw) ? host2.path.resolve(raw) : host2.path.resolve(ctx.cwd, raw);
|
|
11406
|
+
try {
|
|
11407
|
+
text2 = new TextDecoder("utf-8", { fatal: true }).decode(await host2.readFile(path));
|
|
11408
|
+
} catch (error) {
|
|
11409
|
+
throw new UsageError("FILE_ACCESS_FAILED", `failed to read ${raw} as UTF-8 text: ${error instanceof Error ? error.message : String(error)}`);
|
|
11410
|
+
}
|
|
11411
|
+
source = host2.path.basename(path);
|
|
11412
|
+
}
|
|
11413
|
+
if (!text2.trim())
|
|
11414
|
+
throw new UsageError("INVALID_ARGUMENT", "the text to import is empty");
|
|
11415
|
+
if (new TextEncoder().encode(text2).length > MAX_IMPORT_TEXT_BYTES) {
|
|
11416
|
+
throw new UsageError("INVALID_ARGUMENT", `the text to import is larger than ${MAX_IMPORT_TEXT_BYTES} bytes`);
|
|
11417
|
+
}
|
|
11418
|
+
const name = inputString(input, "name");
|
|
11419
|
+
const scope = inputString(input, "scope");
|
|
11420
|
+
const runtimeId = inputString(input, "runtime_id");
|
|
11421
|
+
const started = expectObject(
|
|
11422
|
+
await callService(ctx, agentId, "skills.import", {
|
|
11423
|
+
text: text2,
|
|
11424
|
+
...name ? { name } : {},
|
|
11425
|
+
...scope ? { scope } : {},
|
|
11426
|
+
source,
|
|
11427
|
+
...runtimeId ? { runtime_id: runtimeId } : {}
|
|
11428
|
+
}),
|
|
11429
|
+
"skills.import"
|
|
11430
|
+
);
|
|
11431
|
+
return {
|
|
11432
|
+
agent_id: agentId,
|
|
11433
|
+
source,
|
|
11434
|
+
...started,
|
|
11435
|
+
installed: false,
|
|
11436
|
+
note: "The Agent writes a draft in that work session; nothing is installed. When it reports, the draft is listed by the drafts command; read it, then install it.",
|
|
11437
|
+
drafts_command: `buckyos skill drafts --agent ${agentId}`,
|
|
11438
|
+
install_command: `buckyos skill install --draft ${name ?? "<slug>"} --agent ${agentId}`
|
|
11439
|
+
};
|
|
11440
|
+
}
|
|
11441
|
+
async function fetchText(url, signal) {
|
|
11442
|
+
const response = await fetch(url, { method: "GET", redirect: "follow", signal });
|
|
11443
|
+
if (!response.ok) {
|
|
11444
|
+
await response.body?.cancel();
|
|
11445
|
+
throw new ToolError("SKILL_IMPORT_FETCH_FAILED", `the URL returned HTTP ${response.status}`, EXIT_UNAVAILABLE, response.status >= 500);
|
|
10430
11446
|
}
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10437
|
-
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
}
|
|
11447
|
+
return await response.text();
|
|
11448
|
+
}
|
|
11449
|
+
async function confirm$1(ctx, verb, question) {
|
|
11450
|
+
if (ctx.confirmed)
|
|
11451
|
+
return;
|
|
11452
|
+
if (ctx.config.nonInteractive || !ctx.io.inputIsTerminal) {
|
|
11453
|
+
throw new ToolError("CONFIRMATION_REQUIRED", `${verb} requires --yes in non-interactive execution`, EXIT_PERMISSION);
|
|
11454
|
+
}
|
|
11455
|
+
const answer = (await ctx.io.prompt(`${question} [y/N] `))?.trim().toLowerCase();
|
|
11456
|
+
if (answer !== "y" && answer !== "yes") {
|
|
11457
|
+
throw new ToolError("CONFIRMATION_DECLINED", `${verb} was declined`, EXIT_PERMISSION);
|
|
10443
11458
|
}
|
|
10444
|
-
|
|
10445
|
-
|
|
11459
|
+
}
|
|
11460
|
+
async function kindOf(ctx, agentId, name, input) {
|
|
11461
|
+
const given = inputString(input, "kind");
|
|
11462
|
+
if (given)
|
|
11463
|
+
return given;
|
|
11464
|
+
const kinds = (await listSkills(ctx, agentId)).filter((skill) => skill.name === name).map((skill) => String(skill.kind));
|
|
11465
|
+
if (kinds.length === 0)
|
|
11466
|
+
throw new ToolError("RESOURCE_NOT_FOUND", `Agent ${agentId} has no skill named ${name}`);
|
|
11467
|
+
if (kinds.length > 1)
|
|
11468
|
+
throw new UsageError("AMBIGUOUS_SKILL", `${name} is a ${kinds.join(" and a ")} skill; use --kind`);
|
|
11469
|
+
return kinds[0];
|
|
10446
11470
|
}
|
|
10447
11471
|
async function listSkills(ctx, agentId, kind) {
|
|
10448
11472
|
const skills = await callService(ctx, agentId, "skills.list", kind ? { kind } : {});
|
|
@@ -10450,6 +11474,12 @@ async function listSkills(ctx, agentId, kind) {
|
|
|
10450
11474
|
invalidResponse("skills.list");
|
|
10451
11475
|
return skills.map((skill) => expectObject(skill, "skills.list"));
|
|
10452
11476
|
}
|
|
11477
|
+
async function listDrafts(ctx, agentId) {
|
|
11478
|
+
const drafts = await callService(ctx, agentId, "skills.drafts", {});
|
|
11479
|
+
if (!Array.isArray(drafts))
|
|
11480
|
+
invalidResponse("skills.drafts");
|
|
11481
|
+
return drafts.map((draft) => expectObject(draft, "skills.drafts"));
|
|
11482
|
+
}
|
|
10453
11483
|
function agentIdFrom(input) {
|
|
10454
11484
|
const agentId = requiredInputString(input, "agent_id");
|
|
10455
11485
|
if (!AGENT_ID.test(agentId)) {
|
|
@@ -10476,6 +11506,452 @@ function base64(bytes) {
|
|
|
10476
11506
|
}
|
|
10477
11507
|
return btoa(binary);
|
|
10478
11508
|
}
|
|
11509
|
+
const CONTROL_PANEL$1 = "control-panel";
|
|
11510
|
+
const OBJECT_OUTPUT$7 = { type: "object", additionalProperties: true };
|
|
11511
|
+
const ID$1 = { type: "string", minLength: 1 };
|
|
11512
|
+
const DEVICE_PREFIX = "exec-";
|
|
11513
|
+
const AGENT_RUNTIME_ACTIONS = ["list", "enable", "disable", "default"];
|
|
11514
|
+
const AGENT_OPTION = {
|
|
11515
|
+
name: "agent",
|
|
11516
|
+
property: "agent_id",
|
|
11517
|
+
description: "Agent ID as `agent list` prints it",
|
|
11518
|
+
type: "string",
|
|
11519
|
+
required: true
|
|
11520
|
+
};
|
|
11521
|
+
function objects(value) {
|
|
11522
|
+
return Array.isArray(value) ? value.filter((item) => item && typeof item === "object" && !Array.isArray(item)) : [];
|
|
11523
|
+
}
|
|
11524
|
+
function strings(value) {
|
|
11525
|
+
return Array.isArray(value) ? value.map(String) : [];
|
|
11526
|
+
}
|
|
11527
|
+
function time(value) {
|
|
11528
|
+
return typeof value === "number" && value > 0 ? new Date(value).toISOString() : "";
|
|
11529
|
+
}
|
|
11530
|
+
function allows(roots, mode, computer, baseline) {
|
|
11531
|
+
return [
|
|
11532
|
+
strings(roots).join(",") || "-",
|
|
11533
|
+
mode,
|
|
11534
|
+
...computer && computer !== "none" ? [`computer=${computer}`] : [],
|
|
11535
|
+
...baseline ? [`baseline=${baseline}`] : []
|
|
11536
|
+
].join(" ");
|
|
11537
|
+
}
|
|
11538
|
+
function catalogRows(runtimes) {
|
|
11539
|
+
return runtimes.map((runtime) => ({
|
|
11540
|
+
id: String(runtime.runtime_id ?? ""),
|
|
11541
|
+
kind: runtime.kind === "executor" ? "device" : String(runtime.kind ?? ""),
|
|
11542
|
+
name: String(runtime.name ?? ""),
|
|
11543
|
+
state: runtime.closed === true ? "closed" : "open",
|
|
11544
|
+
online: runtime.online === true ? "yes" : runtime.online === false ? "no" : "",
|
|
11545
|
+
expires: time(runtime.expires_at_ms),
|
|
11546
|
+
allows: allows(runtime.workdir_roots, runtime.read_only === true ? "ro" : "rw", runtime.computer, runtime.baseline),
|
|
11547
|
+
agents: objects(runtime.assigned_to).map((agent) => `${agent.enabled === true ? "*" : ""}${agent.agent_id}${agent.default === true ? " (default)" : ""}`).join(", ")
|
|
11548
|
+
}));
|
|
11549
|
+
}
|
|
11550
|
+
function splitAgentRuntimes(records) {
|
|
11551
|
+
const current = records.filter((record) => record.lifecycle !== "retired");
|
|
11552
|
+
return {
|
|
11553
|
+
current: [...current.filter((record) => record.runtime_id === "private"), ...current.filter((record) => record.runtime_id !== "private")],
|
|
11554
|
+
history: records.filter((record) => record.lifecycle === "retired")
|
|
11555
|
+
};
|
|
11556
|
+
}
|
|
11557
|
+
function agentRuntimeRows(records, settings) {
|
|
11558
|
+
const { current, history } = splitAgentRuntimes(records);
|
|
11559
|
+
return [...current, ...history].map((record) => {
|
|
11560
|
+
const caps = record.caps ?? {};
|
|
11561
|
+
const grant = record.grant ?? {};
|
|
11562
|
+
const usage2 = record.usage ?? {};
|
|
11563
|
+
const connector = record.connector ?? {};
|
|
11564
|
+
const retired = record.lifecycle === "retired";
|
|
11565
|
+
return {
|
|
11566
|
+
id: String(record.runtime_id ?? ""),
|
|
11567
|
+
name: String(record.name ?? ""),
|
|
11568
|
+
type: String(connector.type ?? ""),
|
|
11569
|
+
state: retired ? "retired" : record.enabled === false ? "off" : String(record.availability ?? "on"),
|
|
11570
|
+
default: !retired && (record.default === true || record.runtime_id === settings.default_runtime_id) ? "*" : "",
|
|
11571
|
+
os: String(caps.os ?? ""),
|
|
11572
|
+
allows: allows(grant.roots, strings(grant.ops).join(",") || "-", grant.computer, caps.baseline),
|
|
11573
|
+
expires: time(grant.expires_at_ms),
|
|
11574
|
+
sessions: String(usage2.sessions_total ?? 0),
|
|
11575
|
+
workspaces: String(usage2.workspaces ?? 0),
|
|
11576
|
+
last_used: time(usage2.last_used_at_ms)
|
|
11577
|
+
};
|
|
11578
|
+
});
|
|
11579
|
+
}
|
|
11580
|
+
function directoryRows(runtimes, directory) {
|
|
11581
|
+
return runtimes.map((runtime) => ({
|
|
11582
|
+
id: String(runtime.runtime_id ?? ""),
|
|
11583
|
+
name: String(runtime.name ?? ""),
|
|
11584
|
+
type: runtime.kind === "executor" ? "device" : String(runtime.kind ?? ""),
|
|
11585
|
+
state: runtime.withdrawn === true ? "withdrawn" : runtime.enabled === true ? runtime.closed === true ? "closed" : "on" : "off",
|
|
11586
|
+
default: runtime.runtime_id === directory.default_runtime_id ? "*" : "",
|
|
11587
|
+
os: String(runtime.os ?? ""),
|
|
11588
|
+
allows: allows(runtime.workdir_roots, runtime.read_only === true ? "ro" : "rw", runtime.computer, runtime.baseline),
|
|
11589
|
+
expires: time(runtime.expires_at_ms)
|
|
11590
|
+
}));
|
|
11591
|
+
}
|
|
11592
|
+
function impactText(agentId, impact) {
|
|
11593
|
+
const sessions = objects(impact.active_sessions);
|
|
11594
|
+
const todos = objects(impact.pending_todos);
|
|
11595
|
+
const workspaces = objects(impact.workspaces);
|
|
11596
|
+
const lines = [
|
|
11597
|
+
`Runtime ${impact.runtime_id} of ${agentId}: ${sessions.length} session(s) in progress, ${todos.length} Todo(s) waiting, ${workspaces.length} workspace(s)` + (impact.owner_default === true ? "; it is the default runtime" : "")
|
|
11598
|
+
];
|
|
11599
|
+
for (const session of sessions) {
|
|
11600
|
+
lines.push(` session ${session.session_id} [${session.kind}${session.class ? `/${session.class}` : ""}, ${session.run_state}] ${session.title ?? ""}`);
|
|
11601
|
+
}
|
|
11602
|
+
for (const todo of todos)
|
|
11603
|
+
lines.push(` todo ${todo.session_id}/${todo.todo_id} [${todo.status}] ${todo.title ?? ""}`);
|
|
11604
|
+
for (const workspace of workspaces) {
|
|
11605
|
+
lines.push(` workspace ${workspace.workspace_id} ${workspace.name ?? ""} ${workspace.directory ?? ""} [${workspace.lifecycle ?? ""}]`);
|
|
11606
|
+
}
|
|
11607
|
+
if (sessions.length > 0)
|
|
11608
|
+
lines.push(" It cannot be switched off or taken away while these sessions run.");
|
|
11609
|
+
return `${lines.join("\n")}
|
|
11610
|
+
`;
|
|
11611
|
+
}
|
|
11612
|
+
function deviceOf(given, runtimes) {
|
|
11613
|
+
const runtime = runtimes.find((item) => item.runtime_id === given || item.executor_id && item.executor_id === given);
|
|
11614
|
+
if (runtime ? runtime.kind !== "executor" : given === "host" || given === "private" || given.startsWith("node-")) {
|
|
11615
|
+
throw new UsageError("INVALID_ARGUMENT", `${given} is not a device: only device runtimes (${DEVICE_PREFIX}<executor_id>) are revoked; a node runtime is closed on its node`);
|
|
11616
|
+
}
|
|
11617
|
+
const executorId = runtime?.executor_id ? String(runtime.executor_id) : given.startsWith(DEVICE_PREFIX) ? given.slice(DEVICE_PREFIX.length) : given;
|
|
11618
|
+
return { runtime_id: runtime ? String(runtime.runtime_id) : `${DEVICE_PREFIX}${executorId}`, executor_id: executorId, ...runtime ? { runtime } : {} };
|
|
11619
|
+
}
|
|
11620
|
+
function reasonText(error) {
|
|
11621
|
+
const message2 = error instanceof Error ? error.message : String(error);
|
|
11622
|
+
const brace = message2.indexOf("{");
|
|
11623
|
+
if (brace < 0)
|
|
11624
|
+
return message2;
|
|
11625
|
+
try {
|
|
11626
|
+
const parsed = JSON.parse(message2.slice(brace));
|
|
11627
|
+
return typeof parsed.message === "string" ? parsed.message : message2;
|
|
11628
|
+
} catch {
|
|
11629
|
+
return message2;
|
|
11630
|
+
}
|
|
11631
|
+
}
|
|
11632
|
+
function serviceReason(error, prefix) {
|
|
11633
|
+
const message2 = reasonText(error);
|
|
11634
|
+
const at = message2.indexOf(`${prefix}:`);
|
|
11635
|
+
return at < 0 ? void 0 : message2.slice(at + prefix.length + 1).trim();
|
|
11636
|
+
}
|
|
11637
|
+
function unreachable(error) {
|
|
11638
|
+
const normalized = normalizeError(error);
|
|
11639
|
+
return normalized.code === "SERVICE_UNAVAILABLE" || normalized.code === "TIMEOUT" || normalized.message.toLowerCase().includes("rpc call error: 404");
|
|
11640
|
+
}
|
|
11641
|
+
function message(error) {
|
|
11642
|
+
return normalizeError(error).message;
|
|
11643
|
+
}
|
|
11644
|
+
async function confirm(ctx, verb, shown, question, details) {
|
|
11645
|
+
if (ctx.confirmed)
|
|
11646
|
+
return;
|
|
11647
|
+
if (ctx.config.nonInteractive || !ctx.io.inputIsTerminal) {
|
|
11648
|
+
throw new ToolError("CONFIRMATION_REQUIRED", `${verb} requires --yes in non-interactive execution`, EXIT_PERMISSION, false, details);
|
|
11649
|
+
}
|
|
11650
|
+
await ctx.io.stderr(shown);
|
|
11651
|
+
const answer = (await ctx.io.prompt(`${question} [y/N] `))?.trim().toLowerCase();
|
|
11652
|
+
if (answer !== "y" && answer !== "yes")
|
|
11653
|
+
throw new ToolError("CONFIRMATION_DECLINED", `${verb} was declined`, EXIT_PERMISSION);
|
|
11654
|
+
}
|
|
11655
|
+
function inProgress(verb, shown, details) {
|
|
11656
|
+
return new ToolError("SESSIONS_IN_PROGRESS", `${verb}: sessions still run on it; stop them or let them finish first
|
|
11657
|
+
${shown}`, EXIT_OPERATION, false, details);
|
|
11658
|
+
}
|
|
11659
|
+
async function controlPanel(ctx, method, params) {
|
|
11660
|
+
try {
|
|
11661
|
+
return expectObject$4(await callService(ctx, CONTROL_PANEL$1, method, params), method);
|
|
11662
|
+
} catch (error) {
|
|
11663
|
+
if (message(error).includes("agent_not_found")) {
|
|
11664
|
+
throw new ToolError("RESOURCE_NOT_FOUND", `Agent not found or not yours: ${params.agent_id}`);
|
|
11665
|
+
}
|
|
11666
|
+
for (const [prefix, code] of [["runtime_not_offered", "RUNTIME_NOT_OFFERED"], ["invalid_runtimes", "INVALID_RUNTIMES"]]) {
|
|
11667
|
+
const reason = serviceReason(error, prefix);
|
|
11668
|
+
if (reason !== void 0)
|
|
11669
|
+
throw new ToolError(code, reason, EXIT_OPERATION);
|
|
11670
|
+
}
|
|
11671
|
+
throw error;
|
|
11672
|
+
}
|
|
11673
|
+
}
|
|
11674
|
+
async function catalog(ctx) {
|
|
11675
|
+
const response = await controlPanel(ctx, "agent.runtime_catalog", {});
|
|
11676
|
+
return { response, runtimes: objects(response.runtimes) };
|
|
11677
|
+
}
|
|
11678
|
+
async function impactOf(ctx, agentId, runtimeId) {
|
|
11679
|
+
return expectObject$4(await callService(ctx, agentId, "runtimes.impact", { runtime_id: runtimeId }), "runtimes.impact");
|
|
11680
|
+
}
|
|
11681
|
+
function command(definition) {
|
|
11682
|
+
const { level, properties, required, ...rest } = definition;
|
|
11683
|
+
return {
|
|
11684
|
+
inputSchema: { type: "object", properties, required: required ?? [], additionalProperties: false },
|
|
11685
|
+
outputSchema: OBJECT_OUTPUT$7,
|
|
11686
|
+
resultSchemaVersion: 1,
|
|
11687
|
+
access: { mode: "fixed", level },
|
|
11688
|
+
asyncMode: "sync",
|
|
11689
|
+
requiresSession: true,
|
|
11690
|
+
...rest
|
|
11691
|
+
};
|
|
11692
|
+
}
|
|
11693
|
+
function createRuntimeModule() {
|
|
11694
|
+
return {
|
|
11695
|
+
name: "runtime",
|
|
11696
|
+
summary: "List the runtimes of your directory, assign them to Agents, and revoke devices",
|
|
11697
|
+
commands: [
|
|
11698
|
+
command({
|
|
11699
|
+
verb: "list",
|
|
11700
|
+
summary: "List the runtimes of your directory and the Agents each is assigned to",
|
|
11701
|
+
description: "Node runtimes (host, node-*) and devices (exec-<executor_id>). What a runtime allows (directories, ro|rw, computer use, baseline, expiry) is its own configuration. In the agents column `*` marks an Agent that has the runtime switched on and (default) the Agent whose default it is. A device is used by one Agent at a time.",
|
|
11702
|
+
level: "read",
|
|
11703
|
+
properties: {},
|
|
11704
|
+
examples: ["buckyos runtime list", "buckyos --output table runtime list"],
|
|
11705
|
+
handler: async (ctx) => {
|
|
11706
|
+
const { response, runtimes } = await catalog(ctx);
|
|
11707
|
+
return { ...response, runtimes: ctx.output.format === "table" ? catalogRows(runtimes) : runtimes };
|
|
11708
|
+
}
|
|
11709
|
+
}),
|
|
11710
|
+
command({
|
|
11711
|
+
verb: "assign",
|
|
11712
|
+
summary: "Assign a runtime of your directory to an Agent",
|
|
11713
|
+
description: "Records that the Agent may use the runtime, switched on unless --disabled. Nothing about what the runtime allows is set per Agent. A device another Agent has switched on is refused (RUNTIME_IN_USE): switch it off there first; this command never does that for you.",
|
|
11714
|
+
positionals: [{ name: "runtime_id", description: "Runtime id as `runtime list` prints it" }],
|
|
11715
|
+
options: [AGENT_OPTION, { name: "disabled", description: "Assign it switched off", type: "boolean" }],
|
|
11716
|
+
level: "write",
|
|
11717
|
+
properties: { runtime_id: ID$1, agent_id: ID$1, disabled: { type: "boolean" } },
|
|
11718
|
+
required: ["runtime_id", "agent_id"],
|
|
11719
|
+
examples: [
|
|
11720
|
+
"buckyos runtime assign host --agent jarvis.example.zone",
|
|
11721
|
+
"buckyos runtime assign exec-laptop --agent jarvis.example.zone --disabled"
|
|
11722
|
+
],
|
|
11723
|
+
handler: async (ctx, input) => await assign(ctx, input)
|
|
11724
|
+
}),
|
|
11725
|
+
command({
|
|
11726
|
+
verb: "unassign",
|
|
11727
|
+
summary: "Take a runtime away from an Agent",
|
|
11728
|
+
description: "Refused while sessions of the Agent run on the runtime (SESSIONS_IN_PROGRESS): stop them or let them finish first. The Agent keeps the record as history; the runtime stays in your directory. When the service of the Agent cannot be reached what runs there is unknown and only --yes removes the assignment, through the control panel.",
|
|
11729
|
+
positionals: [{ name: "runtime_id", description: "Runtime id" }],
|
|
11730
|
+
options: [AGENT_OPTION],
|
|
11731
|
+
level: "destructive",
|
|
11732
|
+
properties: { runtime_id: ID$1, agent_id: ID$1 },
|
|
11733
|
+
required: ["runtime_id", "agent_id"],
|
|
11734
|
+
examples: ["buckyos runtime unassign host --agent jarvis.example.zone"],
|
|
11735
|
+
handler: async (ctx, input) => await unassign(ctx, input)
|
|
11736
|
+
}),
|
|
11737
|
+
command({
|
|
11738
|
+
verb: "revoke",
|
|
11739
|
+
summary: "Revoke a device: it stops serving and is taken away from its Agents",
|
|
11740
|
+
description: "Devices only (exec-<executor_id>, or the executor id). Refused while sessions of the Agent using it run there (SESSIONS_IN_PROGRESS); otherwise shows the Agents the device is assigned to and asks; --yes skips the question.",
|
|
11741
|
+
positionals: [{ name: "runtime_id", description: "Device runtime id (exec-<executor_id>) or executor id" }],
|
|
11742
|
+
level: "destructive",
|
|
11743
|
+
properties: { runtime_id: ID$1 },
|
|
11744
|
+
required: ["runtime_id"],
|
|
11745
|
+
examples: ["buckyos runtime revoke exec-laptop", "buckyos --yes runtime revoke laptop"],
|
|
11746
|
+
handler: async (ctx, input) => await revoke(ctx, input)
|
|
11747
|
+
})
|
|
11748
|
+
]
|
|
11749
|
+
};
|
|
11750
|
+
}
|
|
11751
|
+
function agentRuntimeCommand() {
|
|
11752
|
+
return {
|
|
11753
|
+
verb: "runtime",
|
|
11754
|
+
summary: "The runtimes of one Agent: list them, switch one on or off, choose the default",
|
|
11755
|
+
description: 'list: the runtimes the Agent has now (its private one first), then the retired ones with their usage; from the control panel when the service of the Agent cannot be reached. enable / disable <runtime_id>: whether the Agent uses a runtime it was assigned; disable is refused while sessions run on it (SESSIONS_IN_PROGRESS). default <runtime_id|private>: the owner default runtime, the machine "my computer" means to the Agent (work it starts on its own runs on its private runtime). Runtimes are assigned with `buckyos runtime assign`.',
|
|
11756
|
+
positionals: [
|
|
11757
|
+
{ name: "action", description: AGENT_RUNTIME_ACTIONS.join(" | ") },
|
|
11758
|
+
{ name: "runtime_id", description: "Runtime id (enable, disable, default); `private` is the own runtime of the Agent", required: false }
|
|
11759
|
+
],
|
|
11760
|
+
options: [AGENT_OPTION],
|
|
11761
|
+
inputSchema: {
|
|
11762
|
+
type: "object",
|
|
11763
|
+
properties: { action: { type: "string", enum: AGENT_RUNTIME_ACTIONS }, runtime_id: ID$1, agent_id: ID$1 },
|
|
11764
|
+
required: ["action", "agent_id"],
|
|
11765
|
+
additionalProperties: false
|
|
11766
|
+
},
|
|
11767
|
+
outputSchema: OBJECT_OUTPUT$7,
|
|
11768
|
+
resultSchemaVersion: 1,
|
|
11769
|
+
access: { mode: "operation", operationIdField: "action", possibleLevels: ["read", "write"] },
|
|
11770
|
+
asyncMode: "sync",
|
|
11771
|
+
requiresSession: true,
|
|
11772
|
+
examples: [
|
|
11773
|
+
"buckyos agent runtime list --agent jarvis.example.zone",
|
|
11774
|
+
"buckyos agent runtime enable host --agent jarvis.example.zone",
|
|
11775
|
+
"buckyos agent runtime disable exec-laptop --agent jarvis.example.zone",
|
|
11776
|
+
"buckyos agent runtime default private --agent jarvis.example.zone"
|
|
11777
|
+
],
|
|
11778
|
+
handler: async (ctx, input) => {
|
|
11779
|
+
const agentId = agentIdFrom(input);
|
|
11780
|
+
const action = requiredInputString(input, "action");
|
|
11781
|
+
const runtimeId = inputString(input, "runtime_id");
|
|
11782
|
+
if (action === "list") {
|
|
11783
|
+
if (runtimeId)
|
|
11784
|
+
throw new UsageError("ARGUMENT_CONFLICT", "agent runtime list takes no runtime id");
|
|
11785
|
+
return await agentRuntimeList(ctx, agentId);
|
|
11786
|
+
}
|
|
11787
|
+
if (!runtimeId)
|
|
11788
|
+
throw new UsageError("MISSING_ARGUMENT", `agent runtime ${action} needs a runtime id`);
|
|
11789
|
+
if (action === "default") {
|
|
11790
|
+
const settings2 = await settingsSet(ctx, agentId, { runtime_id: runtimeId, default: true });
|
|
11791
|
+
return { agent_id: agentId, runtime_id: runtimeId, default: true, settings: settings2 };
|
|
11792
|
+
}
|
|
11793
|
+
if (action === "enable") {
|
|
11794
|
+
const settings2 = await settingsSet(ctx, agentId, { runtime_id: runtimeId, enabled: true });
|
|
11795
|
+
return { agent_id: agentId, runtime_id: runtimeId, enabled: true, settings: settings2 };
|
|
11796
|
+
}
|
|
11797
|
+
const settings = await settingsSet(ctx, agentId, { runtime_id: runtimeId, enabled: false });
|
|
11798
|
+
return { agent_id: agentId, runtime_id: runtimeId, enabled: false, settings };
|
|
11799
|
+
}
|
|
11800
|
+
};
|
|
11801
|
+
}
|
|
11802
|
+
async function settingsSet(ctx, agentId, params) {
|
|
11803
|
+
try {
|
|
11804
|
+
return expectObject$4(await callService(ctx, agentId, "runtimes.settings_set", params), "runtimes.settings_set");
|
|
11805
|
+
} catch (error) {
|
|
11806
|
+
throw runtimeError(error, agentId, String(params.runtime_id)) ?? error;
|
|
11807
|
+
}
|
|
11808
|
+
}
|
|
11809
|
+
function runtimeError(error, agentId, runtimeId) {
|
|
11810
|
+
const busy = serviceReason(error, "sessions_in_progress");
|
|
11811
|
+
if (busy !== void 0) {
|
|
11812
|
+
return new ToolError("SESSIONS_IN_PROGRESS", `${busy} (buckyos agent runtime list --agent ${agentId})`, EXIT_OPERATION);
|
|
11813
|
+
}
|
|
11814
|
+
const inUse = serviceReason(error, "runtime_in_use");
|
|
11815
|
+
if (inUse !== void 0) {
|
|
11816
|
+
const user = /in use by Agent `([^`]+)`/.exec(inUse)?.[1];
|
|
11817
|
+
return new ToolError(
|
|
11818
|
+
"RUNTIME_IN_USE",
|
|
11819
|
+
`${inUse}${user ? ` (buckyos agent runtime disable ${runtimeId} --agent ${user})` : ""}`,
|
|
11820
|
+
EXIT_OPERATION,
|
|
11821
|
+
false,
|
|
11822
|
+
user ? { in_use_by: user, disable_command: `buckyos agent runtime disable ${runtimeId} --agent ${user}` } : {}
|
|
11823
|
+
);
|
|
11824
|
+
}
|
|
11825
|
+
return void 0;
|
|
11826
|
+
}
|
|
11827
|
+
async function agentRuntimeList(ctx, agentId) {
|
|
11828
|
+
let records;
|
|
11829
|
+
let settings;
|
|
11830
|
+
try {
|
|
11831
|
+
const listed = await callService(ctx, agentId, "runtimes.list", {});
|
|
11832
|
+
if (!Array.isArray(listed))
|
|
11833
|
+
throw new ToolError("INVALID_SERVICE_RESPONSE", "runtimes.list must be an array");
|
|
11834
|
+
records = objects(listed);
|
|
11835
|
+
settings = expectObject$4(await callService(ctx, agentId, "runtimes.settings", {}), "runtimes.settings");
|
|
11836
|
+
} catch (error) {
|
|
11837
|
+
if (!unreachable(error))
|
|
11838
|
+
throw error;
|
|
11839
|
+
const directory = await controlPanel(ctx, "agent.runtime_directory", { agent_id: agentId });
|
|
11840
|
+
const assigned = objects(directory.runtimes).filter((runtime) => runtime.assigned === true);
|
|
11841
|
+
const { runtimes: _all, ...rest } = directory;
|
|
11842
|
+
return {
|
|
11843
|
+
agent_id: agentId,
|
|
11844
|
+
source: CONTROL_PANEL$1,
|
|
11845
|
+
note: `the service of ${agentId} cannot be reached (${message(error)}): these are its assignments in the control panel; availability, usage and retired runtimes are not known`,
|
|
11846
|
+
runtimes: ctx.output.format === "table" ? directoryRows(assigned, directory) : assigned,
|
|
11847
|
+
...rest
|
|
11848
|
+
};
|
|
11849
|
+
}
|
|
11850
|
+
const { current, history } = splitAgentRuntimes(records);
|
|
11851
|
+
return {
|
|
11852
|
+
agent_id: agentId,
|
|
11853
|
+
source: "agent",
|
|
11854
|
+
...ctx.output.format === "table" ? { runtimes: agentRuntimeRows(records, settings) } : { runtimes: current, history },
|
|
11855
|
+
default_runtime_id: settings.default_runtime_id ?? null,
|
|
11856
|
+
configured_default_runtime_id: settings.configured_default_runtime_id ?? null,
|
|
11857
|
+
settings: settings.runtimes ?? {}
|
|
11858
|
+
};
|
|
11859
|
+
}
|
|
11860
|
+
async function assign(ctx, input) {
|
|
11861
|
+
const agentId = agentIdFrom(input);
|
|
11862
|
+
const runtimeId = requiredInputString(input, "runtime_id");
|
|
11863
|
+
const enabled = input.disabled !== true;
|
|
11864
|
+
try {
|
|
11865
|
+
await controlPanel(ctx, "agent.update", { agent_id: agentId, runtimes: { [runtimeId]: { enabled } } });
|
|
11866
|
+
} catch (error) {
|
|
11867
|
+
const inUse = serviceReason(error, "runtime_in_use");
|
|
11868
|
+
if (inUse === void 0)
|
|
11869
|
+
throw error;
|
|
11870
|
+
let user = /in use by Agent `([^`]+)`/.exec(inUse)?.[1];
|
|
11871
|
+
let theirs = runtimeId;
|
|
11872
|
+
try {
|
|
11873
|
+
const device = deviceOf(runtimeId, (await catalog(ctx)).runtimes).runtime;
|
|
11874
|
+
const using = objects(device?.assigned_to).find((agent) => agent.enabled === true && agent.agent_id !== agentId);
|
|
11875
|
+
if (using) {
|
|
11876
|
+
user = String(using.agent_id);
|
|
11877
|
+
theirs = String(using.runtime_id ?? runtimeId);
|
|
11878
|
+
}
|
|
11879
|
+
} catch {
|
|
11880
|
+
}
|
|
11881
|
+
const disable = user ? `buckyos agent runtime disable ${theirs} --agent ${user}` : void 0;
|
|
11882
|
+
throw new ToolError(
|
|
11883
|
+
"RUNTIME_IN_USE",
|
|
11884
|
+
`${inUse}${disable ? `: ${disable}` : ""}`,
|
|
11885
|
+
EXIT_OPERATION,
|
|
11886
|
+
false,
|
|
11887
|
+
user ? { in_use_by: user, disable_command: disable } : {}
|
|
11888
|
+
);
|
|
11889
|
+
}
|
|
11890
|
+
return { agent_id: agentId, runtime_id: runtimeId, assigned: true, enabled };
|
|
11891
|
+
}
|
|
11892
|
+
async function unassign(ctx, input) {
|
|
11893
|
+
const agentId = agentIdFrom(input);
|
|
11894
|
+
const runtimeId = requiredInputString(input, "runtime_id");
|
|
11895
|
+
let impact;
|
|
11896
|
+
try {
|
|
11897
|
+
impact = await impactOf(ctx, agentId, runtimeId);
|
|
11898
|
+
} catch (error) {
|
|
11899
|
+
if (!unreachable(error))
|
|
11900
|
+
throw error;
|
|
11901
|
+
const why = `the service of ${agentId} cannot be reached (${message(error)}): what it has in progress on ${runtimeId} is unknown`;
|
|
11902
|
+
if (!ctx.confirmed) {
|
|
11903
|
+
throw new ToolError(
|
|
11904
|
+
"AGENT_SERVICE_UNAVAILABLE",
|
|
11905
|
+
`${why}. Nothing was changed; --yes removes the assignment through the control panel anyway`,
|
|
11906
|
+
EXIT_UNAVAILABLE,
|
|
11907
|
+
true
|
|
11908
|
+
);
|
|
11909
|
+
}
|
|
11910
|
+
await controlPanel(ctx, "agent.update", { agent_id: agentId, runtimes: { [runtimeId]: null } });
|
|
11911
|
+
return { agent_id: agentId, runtime_id: runtimeId, removed: true, via: CONTROL_PANEL$1, impact: null, warning: why };
|
|
11912
|
+
}
|
|
11913
|
+
if (impact.blocking === true)
|
|
11914
|
+
throw inProgress("runtime unassign", impactText(agentId, impact), { impact });
|
|
11915
|
+
let settings;
|
|
11916
|
+
try {
|
|
11917
|
+
settings = expectObject$4(await callService(ctx, agentId, "runtimes.remove", { runtime_id: runtimeId }), "runtimes.remove");
|
|
11918
|
+
} catch (error) {
|
|
11919
|
+
throw runtimeError(error, agentId, runtimeId) ?? error;
|
|
11920
|
+
}
|
|
11921
|
+
return { agent_id: agentId, runtime_id: runtimeId, removed: true, via: "agent", impact, settings };
|
|
11922
|
+
}
|
|
11923
|
+
async function revoke(ctx, input) {
|
|
11924
|
+
const given = requiredInputString(input, "runtime_id");
|
|
11925
|
+
const device = deviceOf(given, (await catalog(ctx)).runtimes);
|
|
11926
|
+
const assigned = objects(device.runtime?.assigned_to);
|
|
11927
|
+
const lines = [
|
|
11928
|
+
device.runtime ? `Device ${device.runtime_id} (${device.runtime.name ?? device.executor_id}) is assigned to ${assigned.length} Agent(s)` : `Device ${device.runtime_id} is not in your runtime directory: nothing is known about its Agents`,
|
|
11929
|
+
...assigned.map((agent) => ` ${agent.enabled === true ? "*" : " "} ${agent.agent_id}${agent.default === true ? " (default)" : ""}`)
|
|
11930
|
+
];
|
|
11931
|
+
const impacts = [];
|
|
11932
|
+
for (const agent of assigned.filter((item) => item.enabled === true)) {
|
|
11933
|
+
const agentId = String(agent.agent_id);
|
|
11934
|
+
try {
|
|
11935
|
+
const impact = await impactOf(ctx, agentId, String(agent.runtime_id ?? device.runtime_id));
|
|
11936
|
+
impacts.push({ agent_id: agentId, impact });
|
|
11937
|
+
lines.push(impactText(agentId, impact).trimEnd());
|
|
11938
|
+
} catch (error) {
|
|
11939
|
+
impacts.push({ agent_id: agentId, impact: null, error: message(error) });
|
|
11940
|
+
lines.push(` what ${agentId} has in progress on it is unknown: ${message(error)}`);
|
|
11941
|
+
}
|
|
11942
|
+
}
|
|
11943
|
+
if (impacts.some((item) => item.impact?.blocking === true)) {
|
|
11944
|
+
throw inProgress("runtime revoke", `${lines.join("\n")}
|
|
11945
|
+
`, { assigned_to: assigned, impacts });
|
|
11946
|
+
}
|
|
11947
|
+
await confirm(ctx, "runtime revoke", `${lines.join("\n")}
|
|
11948
|
+
`, `Revoke ${device.runtime_id} and take it away from its Agents?`, {
|
|
11949
|
+
assigned_to: assigned,
|
|
11950
|
+
impacts
|
|
11951
|
+
});
|
|
11952
|
+
const revoked = await controlPanel(ctx, "executor.device.revoke", { executor_id: device.executor_id });
|
|
11953
|
+
return { runtime_id: device.runtime_id, executor_id: device.executor_id, revoked: true, assigned_to: assigned, impacts, ...revoked };
|
|
11954
|
+
}
|
|
10479
11955
|
const CONTROL_PANEL = "control-panel";
|
|
10480
11956
|
const OBJECT_OUTPUT$6 = { type: "object", additionalProperties: true };
|
|
10481
11957
|
const AGENT_POSITIONAL = {
|
|
@@ -10492,7 +11968,7 @@ const PROFILE_FIELDS = ["display_name", "bio"];
|
|
|
10492
11968
|
function createAgentModule() {
|
|
10493
11969
|
return {
|
|
10494
11970
|
name: "agent",
|
|
10495
|
-
summary: "List Agents
|
|
11971
|
+
summary: "List Agents, read or change their profiles, and manage the runtimes each one uses",
|
|
10496
11972
|
commands: [
|
|
10497
11973
|
{
|
|
10498
11974
|
verb: "list",
|
|
@@ -10611,7 +12087,8 @@ function createAgentModule() {
|
|
|
10611
12087
|
profile: expectObject$4(after.profile, "agent.profile.set profile")
|
|
10612
12088
|
};
|
|
10613
12089
|
}
|
|
10614
|
-
}
|
|
12090
|
+
},
|
|
12091
|
+
agentRuntimeCommand()
|
|
10615
12092
|
]
|
|
10616
12093
|
};
|
|
10617
12094
|
}
|
|
@@ -10619,8 +12096,8 @@ async function callAgent(ctx, method, params) {
|
|
|
10619
12096
|
try {
|
|
10620
12097
|
return expectObject$4(await callService(ctx, CONTROL_PANEL, method, params), method);
|
|
10621
12098
|
} catch (error) {
|
|
10622
|
-
const
|
|
10623
|
-
if (
|
|
12099
|
+
const message2 = error instanceof Error ? error.message : String(error);
|
|
12100
|
+
if (message2.includes("agent_not_found")) {
|
|
10624
12101
|
throw new ToolError("RESOURCE_NOT_FOUND", `Agent not found or not yours: ${params.agent_id}`);
|
|
10625
12102
|
}
|
|
10626
12103
|
throw error;
|
|
@@ -11182,10 +12659,10 @@ async function call$2(ctx, method, params) {
|
|
|
11182
12659
|
try {
|
|
11183
12660
|
return await callService(ctx, SERVICE$1, method, params);
|
|
11184
12661
|
} catch (error) {
|
|
11185
|
-
const
|
|
11186
|
-
const code = BUCKET_ERROR_CODES.find((c) =>
|
|
12662
|
+
const message2 = error instanceof Error ? error.message : String(error);
|
|
12663
|
+
const code = BUCKET_ERROR_CODES.find((c) => message2.includes(`${c}: `));
|
|
11187
12664
|
if (code)
|
|
11188
|
-
throw new ToolError(`BUCKET_${code.toUpperCase()}`,
|
|
12665
|
+
throw new ToolError(`BUCKET_${code.toUpperCase()}`, message2);
|
|
11189
12666
|
throw error;
|
|
11190
12667
|
}
|
|
11191
12668
|
}
|
|
@@ -12468,10 +13945,10 @@ const pullCommand = {
|
|
|
12468
13945
|
}
|
|
12469
13946
|
};
|
|
12470
13947
|
async function pikgVerb(ctx, verb, input) {
|
|
12471
|
-
const
|
|
12472
|
-
if (!
|
|
13948
|
+
const command2 = createPikgModule().commands.find((c) => c.verb === verb);
|
|
13949
|
+
if (!command2)
|
|
12473
13950
|
throw new ToolError("INTERNAL", `pikg ${verb} is missing`);
|
|
12474
|
-
return expectObject$4(await
|
|
13951
|
+
return expectObject$4(await command2.handler(ctx, input), `pikg ${verb}`);
|
|
12475
13952
|
}
|
|
12476
13953
|
async function uploadPackage(ctx, path) {
|
|
12477
13954
|
const bucket_id = `user/aiworkspace/${ctx.principal.id}/exports`;
|
|
@@ -12961,26 +14438,26 @@ class BuckyOSToolApplication {
|
|
|
12961
14438
|
`);
|
|
12962
14439
|
return EXIT_SUCCESS;
|
|
12963
14440
|
}
|
|
12964
|
-
const
|
|
14441
|
+
const command2 = this.registry.get(invocation.module, invocation.verb);
|
|
12965
14442
|
if (invocation.global.help || invocation.actionArgv.includes("--help") || invocation.actionArgv.includes("-h")) {
|
|
12966
|
-
await this.#stdio.stdout(`${commandHelp(this.registry,
|
|
14443
|
+
await this.#stdio.stdout(`${commandHelp(this.registry, command2)}
|
|
12967
14444
|
`);
|
|
12968
14445
|
return EXIT_SUCCESS;
|
|
12969
14446
|
}
|
|
12970
|
-
if (
|
|
12971
|
-
assertNoSessionOptions(invocation.global,
|
|
12972
|
-
const setup = await this.#resolveForCommand(
|
|
14447
|
+
if (command2.execution === "local")
|
|
14448
|
+
assertNoSessionOptions(invocation.global, command2);
|
|
14449
|
+
const setup = await this.#resolveForCommand(command2, invocation.global);
|
|
12973
14450
|
const inputObject = invocation.global.input ? await this.#readInputObject(invocation.global.input) : void 0;
|
|
12974
|
-
const parsed = parseCommandArgs(
|
|
12975
|
-
if (setup.resolved.output === "raw" && !
|
|
14451
|
+
const parsed = parseCommandArgs(command2, invocation.actionArgv, inputObject);
|
|
14452
|
+
if (setup.resolved.output === "raw" && !command2.supportsRawOutput) {
|
|
12976
14453
|
throw new UsageError(
|
|
12977
14454
|
"RAW_OUTPUT_UNSUPPORTED",
|
|
12978
|
-
`${
|
|
14455
|
+
`${command2.module} ${command2.verb} does not support raw output`
|
|
12979
14456
|
);
|
|
12980
14457
|
}
|
|
12981
|
-
const session =
|
|
14458
|
+
const session = command2.requiresSession ? await this.#createSession(setup.resolved) : void 0;
|
|
12982
14459
|
return await this.#executeAndEmit(
|
|
12983
|
-
|
|
14460
|
+
command2,
|
|
12984
14461
|
parsed.input,
|
|
12985
14462
|
setup.resolved,
|
|
12986
14463
|
setup.store,
|
|
@@ -13037,19 +14514,19 @@ class BuckyOSToolApplication {
|
|
|
13037
14514
|
async #executeInteractiveLine(tokens, signal, frozen, store, session) {
|
|
13038
14515
|
if (tokens.length < 2)
|
|
13039
14516
|
throw new UsageError("COMMAND_REQUIRED", "enter <module> <verb>");
|
|
13040
|
-
const
|
|
14517
|
+
const command2 = this.registry.get(tokens[0], tokens[1]);
|
|
13041
14518
|
const actionArgv = tokens.slice(2);
|
|
13042
14519
|
if (actionArgv.includes("--help") || actionArgv.includes("-h")) {
|
|
13043
|
-
await this.#stdio.stdout(`${commandHelp(this.registry,
|
|
14520
|
+
await this.#stdio.stdout(`${commandHelp(this.registry, command2)}
|
|
13044
14521
|
`);
|
|
13045
14522
|
return;
|
|
13046
14523
|
}
|
|
13047
|
-
const preliminary = parseCommandArgs(
|
|
14524
|
+
const preliminary = parseCommandArgs(command2, actionArgv, void 0, true, true);
|
|
13048
14525
|
if (preliminary.scoped.input === "-") {
|
|
13049
14526
|
throw new UsageError("STDIN_UNAVAILABLE", "--input - is not available inside --cli");
|
|
13050
14527
|
}
|
|
13051
14528
|
const inputObject = preliminary.scoped.input ? await this.#readInputObject(preliminary.scoped.input) : void 0;
|
|
13052
|
-
const parsed = parseCommandArgs(
|
|
14529
|
+
const parsed = parseCommandArgs(command2, actionArgv, inputObject, true);
|
|
13053
14530
|
const config = {
|
|
13054
14531
|
...frozen,
|
|
13055
14532
|
output: parsed.scoped.output ?? frozen.output,
|
|
@@ -13059,22 +14536,22 @@ class BuckyOSToolApplication {
|
|
|
13059
14536
|
wait: parsed.scoped.wait ?? false,
|
|
13060
14537
|
yes: parsed.scoped.yes ?? false
|
|
13061
14538
|
};
|
|
13062
|
-
if (config.output === "raw" && !
|
|
14539
|
+
if (config.output === "raw" && !command2.supportsRawOutput) {
|
|
13063
14540
|
throw new UsageError(
|
|
13064
14541
|
"RAW_OUTPUT_UNSUPPORTED",
|
|
13065
|
-
`${
|
|
14542
|
+
`${command2.module} ${command2.verb} does not support raw output`
|
|
13066
14543
|
);
|
|
13067
14544
|
}
|
|
13068
|
-
await this.#executeAndEmit(
|
|
14545
|
+
await this.#executeAndEmit(command2, parsed.input, config, store, session, true, signal);
|
|
13069
14546
|
}
|
|
13070
|
-
async #executeAndEmit(
|
|
14547
|
+
async #executeAndEmit(command2, input, config, store, session, interactive, signal) {
|
|
13071
14548
|
const traceId = config.traceId ?? crypto.randomUUID();
|
|
13072
14549
|
const startedAt = Date.now();
|
|
13073
14550
|
try {
|
|
13074
|
-
if (
|
|
14551
|
+
if (command2.requiresSession && !session) {
|
|
13075
14552
|
throw new ToolError("AUTH_REQUIRED", "authenticated session is required", 3);
|
|
13076
14553
|
}
|
|
13077
|
-
if (
|
|
14554
|
+
if (command2.requiresSession)
|
|
13078
14555
|
await session.authentication.ensureValid();
|
|
13079
14556
|
const principal = session?.authentication.current().principal ?? {
|
|
13080
14557
|
id: "local",
|
|
@@ -13082,8 +14559,8 @@ class BuckyOSToolApplication {
|
|
|
13082
14559
|
authentication: "mock"
|
|
13083
14560
|
};
|
|
13084
14561
|
const context = {
|
|
13085
|
-
command: { module:
|
|
13086
|
-
definition:
|
|
14562
|
+
command: { module: command2.module, verb: command2.verb },
|
|
14563
|
+
definition: command2,
|
|
13087
14564
|
connection: session?.connection ?? {
|
|
13088
14565
|
zone: config.zone ?? "local",
|
|
13089
14566
|
endpoint: config.endpoint ?? "local://",
|
|
@@ -13100,7 +14577,7 @@ class BuckyOSToolApplication {
|
|
|
13100
14577
|
io: {
|
|
13101
14578
|
stdout: (value) => this.#stdio.stdout(value),
|
|
13102
14579
|
stderr: (value) => this.#stdio.stderr(value),
|
|
13103
|
-
prompt: (
|
|
14580
|
+
prompt: (message2) => this.#stdio.prompt?.(message2) ?? Promise.resolve(null),
|
|
13104
14581
|
inputIsTerminal: this.#stdio.inputIsTerminal?.() ?? false
|
|
13105
14582
|
},
|
|
13106
14583
|
interactive,
|
|
@@ -13109,9 +14586,9 @@ class BuckyOSToolApplication {
|
|
|
13109
14586
|
configStore: store,
|
|
13110
14587
|
session: session?.authentication
|
|
13111
14588
|
};
|
|
13112
|
-
const data = await
|
|
14589
|
+
const data = await command2.handler(context, input);
|
|
13113
14590
|
try {
|
|
13114
|
-
validateSchema(data,
|
|
14591
|
+
validateSchema(data, command2.outputSchema, "output");
|
|
13115
14592
|
} catch (error) {
|
|
13116
14593
|
throw new ToolError(
|
|
13117
14594
|
"INVALID_HANDLER_OUTPUT",
|
|
@@ -13120,7 +14597,7 @@ class BuckyOSToolApplication {
|
|
|
13120
14597
|
);
|
|
13121
14598
|
}
|
|
13122
14599
|
const envelope = successEnvelope(data, {
|
|
13123
|
-
command: `${
|
|
14600
|
+
command: `${command2.module}.${command2.verb}`,
|
|
13124
14601
|
trace_id: traceId,
|
|
13125
14602
|
duration_ms: Date.now() - startedAt
|
|
13126
14603
|
});
|
|
@@ -13131,7 +14608,7 @@ class BuckyOSToolApplication {
|
|
|
13131
14608
|
} catch (error) {
|
|
13132
14609
|
const normalized = normalizeError(error);
|
|
13133
14610
|
const envelope = errorEnvelope(normalized, {
|
|
13134
|
-
command: `${
|
|
14611
|
+
command: `${command2.module}.${command2.verb}`,
|
|
13135
14612
|
trace_id: traceId,
|
|
13136
14613
|
duration_ms: Date.now() - startedAt
|
|
13137
14614
|
});
|
|
@@ -13143,13 +14620,13 @@ class BuckyOSToolApplication {
|
|
|
13143
14620
|
return normalized.exitCode;
|
|
13144
14621
|
}
|
|
13145
14622
|
}
|
|
13146
|
-
async #resolveForCommand(
|
|
13147
|
-
if (
|
|
14623
|
+
async #resolveForCommand(command2, global) {
|
|
14624
|
+
if (command2.requiresSession || command2.module === "config" && command2.verb === "check") {
|
|
13148
14625
|
const setup = await resolveConfig(global, this.#environment, {
|
|
13149
14626
|
cwd: this.#cwd,
|
|
13150
14627
|
homeDir: this.#homeDir
|
|
13151
14628
|
});
|
|
13152
|
-
if (
|
|
14629
|
+
if (command2.requiresSession) {
|
|
13153
14630
|
setup.resolved = await applyImplicitDeviceIdentity(setup.resolved, this.#environment);
|
|
13154
14631
|
}
|
|
13155
14632
|
return setup;
|
|
@@ -13235,10 +14712,11 @@ function createRegistry(pikgDependencies, appDependencies, logDependencies, diag
|
|
|
13235
14712
|
registry.register(createObjModule());
|
|
13236
14713
|
registry.register(createExecutorModule());
|
|
13237
14714
|
registry.register(createExtToolsModule());
|
|
14715
|
+
registry.register(createRuntimeModule());
|
|
13238
14716
|
registry.register(createAiwsModule());
|
|
13239
14717
|
return registry;
|
|
13240
14718
|
}
|
|
13241
|
-
function assertNoSessionOptions(global,
|
|
14719
|
+
function assertNoSessionOptions(global, command2) {
|
|
13242
14720
|
for (const [name, value] of [
|
|
13243
14721
|
["profile", global.profile],
|
|
13244
14722
|
["zone", global.zone],
|
|
@@ -13250,7 +14728,7 @@ function assertNoSessionOptions(global, command) {
|
|
|
13250
14728
|
if (value !== void 0) {
|
|
13251
14729
|
throw new UsageError(
|
|
13252
14730
|
"ARGUMENT_CONFLICT",
|
|
13253
|
-
`--${name} cannot be combined with the local command ${
|
|
14731
|
+
`--${name} cannot be combined with the local command ${command2.module} ${command2.verb}`
|
|
13254
14732
|
);
|
|
13255
14733
|
}
|
|
13256
14734
|
}
|
|
@@ -13290,28 +14768,28 @@ function moduleHelp(registry, moduleName) {
|
|
|
13290
14768
|
`${module.name}: ${module.summary}`,
|
|
13291
14769
|
"",
|
|
13292
14770
|
"Commands:",
|
|
13293
|
-
...module.commands.map((
|
|
14771
|
+
...module.commands.map((command2) => ` ${command2.verb.padEnd(18)} ${command2.summary}`)
|
|
13294
14772
|
].join("\n");
|
|
13295
14773
|
}
|
|
13296
|
-
function commandHelp(registry,
|
|
14774
|
+
function commandHelp(registry, command2) {
|
|
13297
14775
|
return [
|
|
13298
|
-
|
|
14776
|
+
command2.summary,
|
|
13299
14777
|
"",
|
|
13300
|
-
`Usage: ${registry.syntax(
|
|
13301
|
-
...
|
|
13302
|
-
...(
|
|
14778
|
+
`Usage: ${registry.syntax(command2)}`,
|
|
14779
|
+
...command2.description ? ["", command2.description] : [],
|
|
14780
|
+
...(command2.positionals?.length ?? 0) > 0 ? [
|
|
13303
14781
|
"",
|
|
13304
14782
|
"Arguments:",
|
|
13305
|
-
...
|
|
14783
|
+
...command2.positionals.map(
|
|
13306
14784
|
(position) => ` ${position.name.padEnd(20)} ${position.description}`
|
|
13307
14785
|
)
|
|
13308
14786
|
] : [],
|
|
13309
|
-
...(
|
|
14787
|
+
...(command2.options?.length ?? 0) > 0 ? [
|
|
13310
14788
|
"",
|
|
13311
14789
|
"Options:",
|
|
13312
|
-
...
|
|
14790
|
+
...command2.options.map((option) => ` --${option.name.padEnd(18)} ${option.description}`)
|
|
13313
14791
|
] : [],
|
|
13314
|
-
...(
|
|
14792
|
+
...(command2.examples?.length ?? 0) > 0 ? ["", "Examples:", ...command2.examples.map((example) => ` ${example}`)] : []
|
|
13315
14793
|
].join("\n");
|
|
13316
14794
|
}
|
|
13317
14795
|
function defaultStdio() {
|
|
@@ -13319,7 +14797,7 @@ function defaultStdio() {
|
|
|
13319
14797
|
stdout: async (value) => await getHost().stdout(value),
|
|
13320
14798
|
stderr: async (value) => await getHost().stderr(value),
|
|
13321
14799
|
readStdin: async () => await getHost().readStdin(),
|
|
13322
|
-
prompt: async (
|
|
14800
|
+
prompt: async (message2) => await getHost().readLine(message2),
|
|
13323
14801
|
inputIsTerminal: () => getHost().inputIsTerminal()
|
|
13324
14802
|
};
|
|
13325
14803
|
}
|
|
@@ -13590,14 +15068,14 @@ class NodeHost {
|
|
|
13590
15068
|
throw translateNodeError(error, destination);
|
|
13591
15069
|
}
|
|
13592
15070
|
}
|
|
13593
|
-
async run(
|
|
13594
|
-
this.assertCommand(
|
|
13595
|
-
return await capture(
|
|
15071
|
+
async run(command2, args) {
|
|
15072
|
+
this.assertCommand(command2);
|
|
15073
|
+
return await capture(command2, args);
|
|
13596
15074
|
}
|
|
13597
|
-
async runGzip(
|
|
13598
|
-
this.assertCommand(
|
|
15075
|
+
async runGzip(command2, args, destination) {
|
|
15076
|
+
this.assertCommand(command2);
|
|
13599
15077
|
await this.assertPath(destination, "write", false);
|
|
13600
|
-
const child = spawn(
|
|
15078
|
+
const child = spawn(command2, args, { stdio: ["ignore", "pipe", "pipe"], shell: false });
|
|
13601
15079
|
const stderr = [];
|
|
13602
15080
|
child.stderr.on("data", (chunk) => stderr.push(new Uint8Array(chunk)));
|
|
13603
15081
|
try {
|
|
@@ -13686,9 +15164,9 @@ class NodeHost {
|
|
|
13686
15164
|
close: () => reader.close()
|
|
13687
15165
|
};
|
|
13688
15166
|
}
|
|
13689
|
-
assertCommand(
|
|
13690
|
-
if (!this.policy.subprocesses.includes(
|
|
13691
|
-
throw new HostError("PermissionDenied", `subprocess is not allowed: ${
|
|
15167
|
+
assertCommand(command2) {
|
|
15168
|
+
if (!this.policy.subprocesses.includes(command2)) {
|
|
15169
|
+
throw new HostError("PermissionDenied", `subprocess is not allowed: ${command2}`);
|
|
13692
15170
|
}
|
|
13693
15171
|
}
|
|
13694
15172
|
async assertPath(candidate, operation2, resolveLinks = true) {
|
|
@@ -13773,9 +15251,9 @@ function fileInfo(value) {
|
|
|
13773
15251
|
ino: value.ino ?? null
|
|
13774
15252
|
};
|
|
13775
15253
|
}
|
|
13776
|
-
async function capture(
|
|
15254
|
+
async function capture(command2, args) {
|
|
13777
15255
|
return await new Promise((resolve2, reject) => {
|
|
13778
|
-
const child = spawn(
|
|
15256
|
+
const child = spawn(command2, args, { stdio: ["ignore", "pipe", "pipe"], shell: false });
|
|
13779
15257
|
const stdout = [];
|
|
13780
15258
|
const stderr = [];
|
|
13781
15259
|
child.stdout.on("data", (chunk) => stdout.push(new Uint8Array(chunk)));
|