buckyos 0.7.170 → 0.7.177

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/cli/core/app.ts +2 -0
  2. package/cli/core/argv.ts +45 -239
  3. package/cli/core/command.ts +3 -35
  4. package/cli/dist/cli.mjs +2151 -673
  5. package/cli/dist/cli.mjs.map +1 -1
  6. package/cli/modules/agent.ts +3 -1
  7. package/cli/modules/app.ts +13 -2
  8. package/cli/modules/pikg.ts +70 -1
  9. package/cli/modules/runtime.ts +497 -0
  10. package/cli/modules/skill.ts +583 -161
  11. package/cli/modules/skill_lint.ts +462 -0
  12. package/cli/version.ts +1 -1
  13. package/dist/account-7a7bde6f.mjs +105 -0
  14. package/dist/account-7a7bde6f.mjs.map +1 -0
  15. package/dist/account-b12ac6b9.js +2 -0
  16. package/dist/account-b12ac6b9.js.map +1 -0
  17. package/dist/aicc-67851c41.mjs +582 -0
  18. package/dist/aicc-67851c41.mjs.map +1 -0
  19. package/dist/aicc-ccb36ef7.js +2 -0
  20. package/dist/aicc-ccb36ef7.js.map +1 -0
  21. package/dist/aiworkspace_client.d.ts +36 -2
  22. package/dist/aiworkspace_client.d.ts.map +1 -1
  23. package/dist/app-frame.cjs +1 -1
  24. package/dist/app-frame.cjs.map +1 -1
  25. package/dist/app-frame.d.ts +56 -1
  26. package/dist/app-frame.d.ts.map +1 -1
  27. package/dist/app-frame.mjs +285 -4
  28. package/dist/app-frame.mjs.map +1 -1
  29. package/dist/browser.cjs +1 -1
  30. package/dist/browser.cjs.map +1 -1
  31. package/dist/browser.d.ts +4 -0
  32. package/dist/browser.d.ts.map +1 -1
  33. package/dist/browser.mjs +218 -194
  34. package/dist/browser.mjs.map +1 -1
  35. package/dist/content.cjs +1 -1
  36. package/dist/content.cjs.map +1 -1
  37. package/dist/content.d.ts +77 -0
  38. package/dist/content.d.ts.map +1 -1
  39. package/dist/content.mjs +65 -0
  40. package/dist/content.mjs.map +1 -1
  41. package/dist/content_objid-1aff74b6.js +2 -0
  42. package/dist/content_objid-1aff74b6.js.map +1 -0
  43. package/dist/content_objid-9232bcaf.mjs +29 -0
  44. package/dist/content_objid-9232bcaf.mjs.map +1 -0
  45. package/dist/content_objid.d.ts +15 -0
  46. package/dist/content_objid.d.ts.map +1 -0
  47. package/dist/did_object_client-6a1b108a.js +2 -0
  48. package/dist/did_object_client-6a1b108a.js.map +1 -0
  49. package/dist/did_object_client-7fa36f90.mjs +87 -0
  50. package/dist/did_object_client-7fa36f90.mjs.map +1 -0
  51. package/dist/did_object_client.d.ts +39 -0
  52. package/dist/did_object_client.d.ts.map +1 -0
  53. package/dist/executor_client-7ce0ddc7.js +13 -0
  54. package/dist/executor_client-7ce0ddc7.js.map +1 -0
  55. package/dist/{executor_client-5f4d0468.mjs → executor_client-bfc8a1e1.mjs} +308 -752
  56. package/dist/executor_client-bfc8a1e1.mjs.map +1 -0
  57. package/dist/executor_client.d.ts +129 -0
  58. package/dist/executor_client.d.ts.map +1 -1
  59. package/dist/index.cjs +1 -1
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.ts +3 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.mjs +218 -199
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/internal/command_args.d.ts +67 -0
  66. package/dist/internal/command_args.d.ts.map +1 -0
  67. package/dist/krpc_client-26c2dc8b.js +2 -0
  68. package/dist/krpc_client-26c2dc8b.js.map +1 -0
  69. package/dist/krpc_client-673448e5.mjs +173 -0
  70. package/dist/krpc_client-673448e5.mjs.map +1 -0
  71. package/dist/krpc_client.d.ts +5 -1
  72. package/dist/krpc_client.d.ts.map +1 -1
  73. package/dist/{ndn_types-ab30fac0.mjs → ndn_types-0fac2499.mjs} +115 -215
  74. package/dist/ndn_types-0fac2499.mjs.map +1 -0
  75. package/dist/ndn_types-5b138882.js +2 -0
  76. package/dist/ndn_types-5b138882.js.map +1 -0
  77. package/dist/node.cjs +1 -1
  78. package/dist/node.cjs.map +1 -1
  79. package/dist/node.mjs +201 -194
  80. package/dist/node.mjs.map +1 -1
  81. package/dist/object_url-8fb5a7bf.js +2 -0
  82. package/dist/object_url-8fb5a7bf.js.map +1 -0
  83. package/dist/object_url-f72c1704.mjs +412 -0
  84. package/dist/object_url-f72c1704.mjs.map +1 -0
  85. package/dist/openai-ae2978de.mjs +163 -0
  86. package/dist/openai-ae2978de.mjs.map +1 -0
  87. package/dist/openai-f560d518.js +2 -0
  88. package/dist/openai-f560d518.js.map +1 -0
  89. package/dist/provision.cjs +6 -6
  90. package/dist/provision.cjs.map +1 -1
  91. package/dist/provision.mjs +4 -3
  92. package/dist/provision.mjs.map +1 -1
  93. package/dist/site_manager-11a7a468.mjs +6410 -0
  94. package/dist/site_manager-11a7a468.mjs.map +1 -0
  95. package/dist/site_manager-334b1a51.js +2 -0
  96. package/dist/site_manager-334b1a51.js.map +1 -0
  97. package/dist/{tus_client-b231b248.js → tus_client-809c90ab.js} +2 -2
  98. package/dist/{tus_client-b231b248.js.map → tus_client-809c90ab.js.map} +1 -1
  99. package/dist/{tus_client-d1ffe2d6.mjs → tus_client-893a3287.mjs} +2 -2
  100. package/dist/{tus_client-d1ffe2d6.mjs.map → tus_client-893a3287.mjs.map} +1 -1
  101. package/dist/xllm/core/action_parser.d.ts +15 -0
  102. package/dist/xllm/core/action_parser.d.ts.map +1 -0
  103. package/dist/xllm/core/behavior_loop.d.ts +20 -0
  104. package/dist/xllm/core/behavior_loop.d.ts.map +1 -0
  105. package/dist/xllm/core/behavior_result.d.ts +11 -0
  106. package/dist/xllm/core/behavior_result.d.ts.map +1 -0
  107. package/dist/xllm/core/config.d.ts +62 -0
  108. package/dist/xllm/core/config.d.ts.map +1 -0
  109. package/dist/xllm/core/context_window.d.ts +15 -0
  110. package/dist/xllm/core/context_window.d.ts.map +1 -0
  111. package/dist/xllm/core/deps.d.ts +97 -0
  112. package/dist/xllm/core/deps.d.ts.map +1 -0
  113. package/dist/xllm/core/errors.d.ts +94 -0
  114. package/dist/xllm/core/errors.d.ts.map +1 -0
  115. package/dist/xllm/core/interrupt.d.ts +31 -0
  116. package/dist/xllm/core/interrupt.d.ts.map +1 -0
  117. package/dist/xllm/core/json.d.ts +11 -0
  118. package/dist/xllm/core/json.d.ts.map +1 -0
  119. package/dist/xllm/core/json_check.d.ts +17 -0
  120. package/dist/xllm/core/json_check.d.ts.map +1 -0
  121. package/dist/xllm/core/loop.d.ts +135 -0
  122. package/dist/xllm/core/loop.d.ts.map +1 -0
  123. package/dist/xllm/core/messages.d.ts +18 -0
  124. package/dist/xllm/core/messages.d.ts.map +1 -0
  125. package/dist/xllm/core/observer.d.ts +14 -0
  126. package/dist/xllm/core/observer.d.ts.map +1 -0
  127. package/dist/xllm/core/open_runtime.d.ts +22 -0
  128. package/dist/xllm/core/open_runtime.d.ts.map +1 -0
  129. package/dist/xllm/core/prepare.d.ts +54 -0
  130. package/dist/xllm/core/prepare.d.ts.map +1 -0
  131. package/dist/xllm/core/prompt.d.ts +40 -0
  132. package/dist/xllm/core/prompt.d.ts.map +1 -0
  133. package/dist/xllm/core/protocol.d.ts +15 -0
  134. package/dist/xllm/core/protocol.d.ts.map +1 -0
  135. package/dist/xllm/core/result.d.ts +12 -0
  136. package/dist/xllm/core/result.d.ts.map +1 -0
  137. package/dist/xllm/core/run.d.ts +198 -0
  138. package/dist/xllm/core/run.d.ts.map +1 -0
  139. package/dist/xllm/core/rust_text.d.ts +20 -0
  140. package/dist/xllm/core/rust_text.d.ts.map +1 -0
  141. package/dist/xllm/core/site_policy.d.ts +5 -0
  142. package/dist/xllm/core/site_policy.d.ts.map +1 -0
  143. package/dist/xllm/core/store.d.ts +60 -0
  144. package/dist/xllm/core/store.d.ts.map +1 -0
  145. package/dist/xllm/core/suspension.d.ts +13 -0
  146. package/dist/xllm/core/suspension.d.ts.map +1 -0
  147. package/dist/xllm/core/tokenizer.d.ts +8 -0
  148. package/dist/xllm/core/tokenizer.d.ts.map +1 -0
  149. package/dist/xllm/core/types.d.ts +826 -0
  150. package/dist/xllm/core/types.d.ts.map +1 -0
  151. package/dist/xllm/core/xml.d.ts +19 -0
  152. package/dist/xllm/core/xml.d.ts.map +1 -0
  153. package/dist/xllm/dev/openai.d.ts +17 -0
  154. package/dist/xllm/dev/openai.d.ts.map +1 -0
  155. package/dist/xllm/dev/scripted.d.ts +46 -0
  156. package/dist/xllm/dev/scripted.d.ts.map +1 -0
  157. package/dist/xllm/dev.d.ts +5 -0
  158. package/dist/xllm/dev.d.ts.map +1 -0
  159. package/dist/xllm/hosts/browser/store.d.ts +41 -0
  160. package/dist/xllm/hosts/browser/store.d.ts.map +1 -0
  161. package/dist/xllm/hosts/deno/deno_api.d.ts +103 -0
  162. package/dist/xllm/hosts/deno/deno_api.d.ts.map +1 -0
  163. package/dist/xllm/hosts/deno/identity.d.ts +29 -0
  164. package/dist/xllm/hosts/deno/identity.d.ts.map +1 -0
  165. package/dist/xllm/hosts/deno/index.d.ts +47 -0
  166. package/dist/xllm/hosts/deno/index.d.ts.map +1 -0
  167. package/dist/xllm/hosts/deno/native_runtime.d.ts +93 -0
  168. package/dist/xllm/hosts/deno/native_runtime.d.ts.map +1 -0
  169. package/dist/xllm/hosts/deno/native_tools.d.ts +105 -0
  170. package/dist/xllm/hosts/deno/native_tools.d.ts.map +1 -0
  171. package/dist/xllm/hosts/deno/provider.d.ts +13 -0
  172. package/dist/xllm/hosts/deno/provider.d.ts.map +1 -0
  173. package/dist/xllm/hosts/deno/store.d.ts +60 -0
  174. package/dist/xllm/hosts/deno/store.d.ts.map +1 -0
  175. package/dist/xllm/index.d.ts +48 -0
  176. package/dist/xllm/index.d.ts.map +1 -0
  177. package/dist/xllm/providers/aicc.d.ts +22 -0
  178. package/dist/xllm/providers/aicc.d.ts.map +1 -0
  179. package/dist/xllm/providers/timeout.d.ts +12 -0
  180. package/dist/xllm/providers/timeout.d.ts.map +1 -0
  181. package/dist/xllm/runtime/compress.d.ts +149 -0
  182. package/dist/xllm/runtime/compress.d.ts.map +1 -0
  183. package/dist/xllm/runtime/did_object_resources.d.ts +21 -0
  184. package/dist/xllm/runtime/did_object_resources.d.ts.map +1 -0
  185. package/dist/xllm/runtime/hints.d.ts +23 -0
  186. package/dist/xllm/runtime/hints.d.ts.map +1 -0
  187. package/dist/xllm/runtime/site.d.ts +22 -0
  188. package/dist/xllm/runtime/site.d.ts.map +1 -0
  189. package/dist/xllm/runtime/site_manager.d.ts +38 -0
  190. package/dist/xllm/runtime/site_manager.d.ts.map +1 -0
  191. package/dist/xllm/runtime/site_tools.d.ts +76 -0
  192. package/dist/xllm/runtime/site_tools.d.ts.map +1 -0
  193. package/dist/xllm/runtime/step_renderer.d.ts +54 -0
  194. package/dist/xllm/runtime/step_renderer.d.ts.map +1 -0
  195. package/dist/xllm/runtime/task_model.d.ts +64 -0
  196. package/dist/xllm/runtime/task_model.d.ts.map +1 -0
  197. package/dist/xllm/runtime/tool_result.d.ts +39 -0
  198. package/dist/xllm/runtime/tool_result.d.ts.map +1 -0
  199. package/dist/xllm/runtime/types.d.ts +99 -0
  200. package/dist/xllm/runtime/types.d.ts.map +1 -0
  201. package/dist/xllm.cjs +2 -0
  202. package/dist/xllm.cjs.map +1 -0
  203. package/dist/xllm.mjs +1167 -0
  204. package/dist/xllm.mjs.map +1 -0
  205. package/dist/xllm_deno.cjs +2 -0
  206. package/dist/xllm_deno.cjs.map +1 -0
  207. package/dist/xllm_deno.mjs +2487 -0
  208. package/dist/xllm_deno.mjs.map +1 -0
  209. package/dist/xllm_dev.cjs +2 -0
  210. package/dist/xllm_dev.cjs.map +1 -0
  211. package/dist/xllm_dev.mjs +70 -0
  212. package/dist/xllm_dev.mjs.map +1 -0
  213. package/package.json +22 -1
  214. package/src/internal/command_args.ts +268 -0
  215. package/dist/executor_client-1ee523cf.js +0 -13
  216. package/dist/executor_client-1ee523cf.js.map +0 -1
  217. package/dist/executor_client-5f4d0468.mjs.map +0 -1
  218. package/dist/ndn_types-8c2696d5.js +0 -2
  219. package/dist/ndn_types-8c2696d5.js.map +0 -1
  220. package/dist/ndn_types-ab30fac0.mjs.map +0 -1
@@ -1,18 +1,30 @@
1
- import type { CommandModule, JsonSchema, OptionDefinition } from '../core/command.ts'
1
+ import type { CommandDefinition, CommandModule, JsonSchema, OptionDefinition } from '../core/command.ts'
2
2
  import type { CommandContext } from '../core/context.ts'
3
- import { EXIT_INTERNAL, EXIT_PERMISSION, ToolError, UsageError } from '../core/errors.ts'
4
- import { callService, requiredInputString } from '../core/service.ts'
5
- import { getHost } from '../runtime/host.ts'
3
+ import { EXIT_INTERNAL, EXIT_PERMISSION, EXIT_UNAVAILABLE, ToolError, UsageError } from '../core/errors.ts'
4
+ import { callService, inputString, requiredInputString } from '../core/service.ts'
5
+ import { getHost, isHostError } from '../runtime/host.ts'
6
+ import { type AppModuleDependencies, classifySource, downloadPikg, isDidSource } from './app.ts'
6
7
  import { openZip, readTarGz, readZipEntry, sha256Bytes } from './pikg_archive.ts'
7
8
  import { inspectPikg } from './pikg_protocol.ts'
9
+ import { lintSkillPackage, readSkillDirectory, SKILL_DIRS, SKILL_KINDS, type SkillPackageFile } from './skill_lint.ts'
8
10
 
9
11
  const OBJECT_OUTPUT: JsonSchema = { type: 'object', additionalProperties: true }
10
- const SKILL_KINDS = ['cmd', 'goal']
11
12
  const SKILLS_SUB_PKG = 'agent_skills'
12
- const SKILL_DIRS = ['cmd_skills', 'goal_skills', 'tools']
13
+ const SKILL_SCOPES = ['ui', 'work']
14
+ const IMPORT_SCOPES = ['work', 'ui', 'plan']
15
+ const SOURCE_KINDS = ['pikg', 'dir', 'url', 'did']
13
16
  const MAX_SKILL_PAYLOAD_BYTES = 64 * 1024 * 1024
17
+ const MAX_IMPORT_TEXT_BYTES = 512 * 1024
14
18
  const AGENT_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
15
19
 
20
+ export interface SkillModuleDependencies {
21
+ /** Downloads a skill PIKG (`skill install <url>`). */
22
+ download?: AppModuleDependencies['download']
23
+ /** Fetches the text `skill import <url>` hands to the Agent. */
24
+ fetchText?: (url: URL, signal: AbortSignal) => Promise<string>
25
+ readStdin?: () => Promise<string>
26
+ }
27
+
16
28
  const AGENT_OPTION: OptionDefinition = {
17
29
  name: 'agent',
18
30
  property: 'agent_id',
@@ -25,137 +37,473 @@ const KIND_OPTION: OptionDefinition = {
25
37
  name: 'kind',
26
38
  description: 'Skill kind',
27
39
  type: 'string',
28
- enum: SKILL_KINDS,
40
+ enum: [...SKILL_KINDS],
41
+ }
42
+
43
+ const RUNTIME_OPTION: OptionDefinition = {
44
+ name: 'runtime',
45
+ property: 'runtime_id',
46
+ description: 'Runtime id (default: the private runtime)',
47
+ type: 'string',
48
+ }
49
+
50
+ const AGENT_PROPERTY: JsonSchema = { type: 'string', minLength: 1 }
51
+ const NAME_PROPERTY: JsonSchema = { type: 'string', minLength: 1 }
52
+ const KIND_PROPERTY: JsonSchema = { type: 'string', enum: [...SKILL_KINDS] }
53
+
54
+ function command(
55
+ definition: Pick<CommandDefinition, 'verb' | 'summary' | 'handler'> & Partial<CommandDefinition> & {
56
+ level: 'read' | 'write' | 'destructive'
57
+ properties: Record<string, JsonSchema>
58
+ required?: string[]
59
+ },
60
+ ): CommandDefinition {
61
+ const { level, properties, required, ...rest } = definition
62
+ return {
63
+ options: [AGENT_OPTION],
64
+ inputSchema: {
65
+ type: 'object',
66
+ properties: { agent_id: AGENT_PROPERTY, ...properties },
67
+ required: ['agent_id', ...(required ?? [])],
68
+ additionalProperties: false,
69
+ },
70
+ outputSchema: OBJECT_OUTPUT,
71
+ resultSchemaVersion: 1,
72
+ access: { mode: 'fixed', level },
73
+ asyncMode: 'sync',
74
+ requiresSession: true,
75
+ ...rest,
76
+ }
29
77
  }
30
78
 
31
- export function createSkillModule(): CommandModule {
79
+ export function createSkillModule(dependencies: SkillModuleDependencies = {}): CommandModule {
32
80
  return {
33
81
  name: 'skill',
34
- summary: 'List, install, and remove the cmd/goal skills of an Agent',
82
+ summary: 'List, install, enable, and remove the work/plan/goal skills of an Agent',
35
83
  commands: [
36
- {
84
+ command({
37
85
  verb: 'list',
38
86
  summary: 'List the skills of an Agent',
39
- options: [AGENT_OPTION, KIND_OPTION],
40
- inputSchema: {
41
- type: 'object',
42
- properties: {
43
- agent_id: { type: 'string', minLength: 1 },
44
- kind: { type: 'string', enum: SKILL_KINDS },
45
- },
46
- required: ['agent_id'],
47
- additionalProperties: false,
87
+ description:
88
+ '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.',
89
+ options: [
90
+ AGENT_OPTION,
91
+ KIND_OPTION,
92
+ { name: 'scope', description: 'Work skills whose scope includes this', type: 'string', enum: SKILL_SCOPES },
93
+ { name: 'all', description: 'Include skills that are not enabled, and drafts', type: 'boolean' },
94
+ { name: 'stats', description: 'Include usage', type: 'boolean' },
95
+ ],
96
+ level: 'read',
97
+ properties: {
98
+ kind: KIND_PROPERTY,
99
+ scope: { type: 'string', enum: SKILL_SCOPES },
100
+ all: { type: 'boolean' },
101
+ stats: { type: 'boolean' },
48
102
  },
49
- outputSchema: OBJECT_OUTPUT,
50
- resultSchemaVersion: 1,
51
- access: { mode: 'fixed', level: 'read' },
52
- asyncMode: 'sync',
53
- requiresSession: true,
54
103
  examples: [
55
104
  'buckyos skill list --agent jarvis.example.zone',
56
- 'buckyos skill list --agent jarvis.example.zone --kind cmd',
105
+ 'buckyos skill list --agent jarvis.example.zone --kind work --scope ui',
106
+ 'buckyos skill list --agent jarvis.example.zone --all --stats',
57
107
  ],
58
- handler: async (ctx, input) => {
59
- const agentId = agentIdFrom(input)
60
- const kind = typeof input.kind === 'string' ? input.kind : undefined
61
- const skills = await listSkills(ctx, agentId, kind)
62
- return { agent_id: agentId, ...(kind ? { kind } : {}), total: skills.length, skills }
63
- },
64
- },
65
- {
108
+ handler: async (ctx, input) => await listCommand(ctx, input),
109
+ }),
110
+ command({
66
111
  verb: 'status',
67
- summary: 'The commands each cmd skill relies on, on a runtime of the Agent, and the extension package that would bring what is missing',
68
- options: [
69
- AGENT_OPTION,
70
- { name: 'runtime', property: 'runtime_id', description: 'Runtime id (default: the private runtime)', type: 'string' },
71
- ],
72
- inputSchema: {
73
- type: 'object',
74
- properties: { agent_id: { type: 'string', minLength: 1 }, runtime_id: { type: 'string', minLength: 1 } },
75
- required: ['agent_id'],
76
- additionalProperties: false,
77
- },
78
- outputSchema: OBJECT_OUTPUT,
79
- resultSchemaVersion: 1,
80
- access: { mode: 'fixed', level: 'read' },
81
- asyncMode: 'sync',
82
- requiresSession: true,
112
+ summary:
113
+ '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',
114
+ options: [AGENT_OPTION, RUNTIME_OPTION],
115
+ level: 'read',
116
+ properties: { runtime_id: { type: 'string', minLength: 1 } },
83
117
  examples: ['buckyos skill status --agent jarvis.example.zone --runtime host'],
84
- handler: async (ctx, input) => await callService<Record<string, unknown>>(ctx, agentIdFrom(input), 'skills.status', { runtime_id: input.runtime_id ?? null }),
85
- },
86
- {
118
+ handler: async (ctx, input) =>
119
+ await callService<Record<string, unknown>>(ctx, agentIdFrom(input), 'skills.status', {
120
+ runtime_id: input.runtime_id ?? null,
121
+ }),
122
+ }),
123
+ command({
87
124
  verb: 'install',
88
- summary: 'Install the skills of a skill PIKG into an Agent',
125
+ summary: 'Install skills into an Agent: plan, confirm, install',
89
126
  description:
90
- 'Verifies the PIKG offline, requires app_type agent_skills, and sends the files of its agent_skills sub package (cmd_skills/, goal_skills/, tools/) to the Agent. Sessions created before keep their frozen manuals.',
91
- positionals: [{ name: 'pikg_path', description: 'Local skill .pikg file' }],
127
+ '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.',
128
+ positionals: [{ name: 'source', description: 'Skill .pikg file, skill directory, or HTTP(S) URL', required: false }],
92
129
  options: [
93
130
  AGENT_OPTION,
94
- {
95
- name: 'replace',
96
- description: 'Replace skills of the same names from another package',
97
- type: 'boolean',
98
- },
131
+ { name: 'from', description: 'Force source type', type: 'string', enum: SOURCE_KINDS },
132
+ { name: 'draft', description: 'Install this draft of the AgentRoot (skills_drafts/<slug>) instead of a source', type: 'string' },
133
+ { ...RUNTIME_OPTION, description: 'Runtime the commands the manuals name are checked against in the plan (default: the private runtime)' },
134
+ { name: 'replace', description: 'Replace skills of the same names from another package', type: 'boolean' },
99
135
  ],
100
- inputSchema: {
101
- type: 'object',
102
- properties: {
103
- pikg_path: { type: 'string', minLength: 1 },
104
- agent_id: { type: 'string', minLength: 1 },
105
- replace: { type: 'boolean' },
106
- },
107
- required: ['pikg_path', 'agent_id'],
108
- additionalProperties: false,
136
+ level: 'write',
137
+ properties: {
138
+ source: { type: 'string', minLength: 1 },
139
+ from: { type: 'string', enum: SOURCE_KINDS },
140
+ draft: { type: 'string', minLength: 1 },
141
+ runtime_id: { type: 'string', minLength: 1 },
142
+ replace: { type: 'boolean' },
109
143
  },
110
- outputSchema: OBJECT_OUTPUT,
111
- resultSchemaVersion: 1,
112
- access: { mode: 'fixed', level: 'write' },
113
- asyncMode: 'sync',
114
- requiresSession: true,
115
144
  examples: [
116
145
  'buckyos skill install ./dapp_dist/hello-skills-0.1.0.pikg --agent jarvis.example.zone',
117
- 'buckyos skill install ./hello-skills-0.2.0.pikg --agent jarvis.example.zone --replace',
146
+ 'buckyos --yes skill install ./skills --agent jarvis.example.zone --replace',
147
+ 'buckyos skill install https://example.com/hello-skills-0.1.0.pikg --agent jarvis.example.zone',
148
+ 'buckyos skill install --draft notes-to-slides --agent jarvis.example.zone',
118
149
  ],
119
- handler: async (ctx, input) => await installSkills(ctx, input),
120
- },
121
- {
150
+ handler: async (ctx, input) => await installCommand(ctx, input, dependencies),
151
+ }),
152
+ command({
122
153
  verb: 'remove',
123
154
  summary: 'Remove an installed skill from an Agent',
155
+ description: 'Only installed and imported skills can be removed. Without --kind the kind is looked up by name.',
156
+ positionals: [{ name: 'name', description: 'Skill name' }],
157
+ options: [AGENT_OPTION, KIND_OPTION],
158
+ level: 'destructive',
159
+ properties: { name: NAME_PROPERTY, kind: KIND_PROPERTY },
160
+ required: ['name'],
161
+ examples: ['buckyos --yes skill remove hello --agent jarvis.example.zone --kind work'],
162
+ handler: async (ctx, input) => {
163
+ const agentId = agentIdFrom(input)
164
+ const name = requiredInputString(input, 'name')
165
+ const kind = await kindOf(ctx, agentId, name, input)
166
+ await confirm(ctx, 'skill remove', `Remove ${kind} skill ${name} from ${agentId}?`)
167
+ const removed = await callService<unknown>(ctx, agentId, 'skills.remove', { kind, name })
168
+ return { agent_id: agentId, removed: expectObject(removed, 'skills.remove') }
169
+ },
170
+ }),
171
+ command({
172
+ verb: 'disable',
173
+ summary: 'Disable a skill of an Agent: no new session takes it',
124
174
  description:
125
- 'Only installed skills can be removed. Without --kind the kind is looked up by name.',
175
+ 'Any skill can be disabled, package ones included. Running sessions keep what they froze. Without --kind the kind is looked up by name.',
176
+ positionals: [{ name: 'name', description: 'Skill name' }],
177
+ options: [AGENT_OPTION, KIND_OPTION, { name: 'reason', description: 'Why, for the record', type: 'string' }],
178
+ level: 'write',
179
+ properties: { name: NAME_PROPERTY, kind: KIND_PROPERTY, reason: { type: 'string' } },
180
+ required: ['name'],
181
+ examples: ['buckyos skill disable aigc_video --agent jarvis.example.zone --reason "no provider"'],
182
+ handler: async (ctx, input) => await setEnabled(ctx, input, false),
183
+ }),
184
+ command({
185
+ verb: 'enable',
186
+ summary: 'Enable a disabled skill of an Agent',
126
187
  positionals: [{ name: 'name', description: 'Skill name' }],
127
188
  options: [AGENT_OPTION, KIND_OPTION],
128
- inputSchema: {
129
- type: 'object',
130
- properties: {
131
- name: { type: 'string', minLength: 1 },
132
- agent_id: { type: 'string', minLength: 1 },
133
- kind: { type: 'string', enum: SKILL_KINDS },
134
- },
135
- required: ['name', 'agent_id'],
136
- additionalProperties: false,
189
+ level: 'write',
190
+ properties: { name: NAME_PROPERTY, kind: KIND_PROPERTY },
191
+ required: ['name'],
192
+ examples: ['buckyos skill enable aigc_video --agent jarvis.example.zone'],
193
+ handler: async (ctx, input) => await setEnabled(ctx, input, true),
194
+ }),
195
+ command({
196
+ verb: 'ui-list',
197
+ summary: 'The work skills every new conversation (UI session) of the Agent takes',
198
+ level: 'read',
199
+ properties: {},
200
+ examples: ['buckyos skill ui-list --agent jarvis.example.zone'],
201
+ handler: async (ctx, input) => {
202
+ const agentId = agentIdFrom(input)
203
+ return { agent_id: agentId, ...await uiGet(ctx, agentId) }
137
204
  },
138
- outputSchema: OBJECT_OUTPUT,
139
- resultSchemaVersion: 1,
140
- access: { mode: 'fixed', level: 'destructive' },
141
- asyncMode: 'sync',
142
- requiresSession: true,
143
- examples: ['buckyos --yes skill remove hello --agent jarvis.example.zone --kind cmd'],
144
- handler: async (ctx, input) => await removeSkill(ctx, input),
145
- },
205
+ }),
206
+ command({
207
+ verb: 'ui-add',
208
+ summary: 'Add a skill whose scope includes ui to the conversations of the Agent',
209
+ description:
210
+ 'Takes effect in conversations created afterwards. The result gives total_bytes: every conversation carries that much manual text.',
211
+ positionals: [{ name: 'name', description: 'Skill name' }],
212
+ level: 'write',
213
+ properties: { name: NAME_PROPERTY },
214
+ required: ['name'],
215
+ examples: ['buckyos skill ui-add share --agent jarvis.example.zone'],
216
+ handler: async (ctx, input) => await uiChange(ctx, input, true),
217
+ }),
218
+ command({
219
+ verb: 'ui-remove',
220
+ summary: 'Take a skill out of the conversations of the Agent',
221
+ positionals: [{ name: 'name', description: 'Skill name' }],
222
+ level: 'write',
223
+ properties: { name: NAME_PROPERTY },
224
+ required: ['name'],
225
+ examples: ['buckyos skill ui-remove share --agent jarvis.example.zone'],
226
+ handler: async (ctx, input) => await uiChange(ctx, input, false),
227
+ }),
228
+ command({
229
+ verb: 'import',
230
+ summary: 'Hand a text to the Agent to turn into a skill draft',
231
+ description:
232
+ '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>.',
233
+ positionals: [{ name: 'source', description: 'Text file, HTTP(S) URL, or - for stdin' }],
234
+ options: [
235
+ AGENT_OPTION,
236
+ { name: 'name', description: 'Slug of the draft', type: 'string' },
237
+ { name: 'scope', description: 'What to make of it', type: 'string', enum: IMPORT_SCOPES },
238
+ { ...RUNTIME_OPTION, description: 'Runtime the commands the text names are checked on (default: the private runtime)' },
239
+ ],
240
+ level: 'write',
241
+ properties: {
242
+ source: { type: 'string', minLength: 1 },
243
+ name: { type: 'string', minLength: 1 },
244
+ scope: { type: 'string', enum: IMPORT_SCOPES },
245
+ runtime_id: { type: 'string', minLength: 1 },
246
+ },
247
+ required: ['source'],
248
+ examples: [
249
+ 'buckyos skill import ./notes/release-checklist.md --agent jarvis.example.zone --name release_checklist',
250
+ 'cat howto.md | buckyos skill import - --agent jarvis.example.zone --scope plan',
251
+ ],
252
+ handler: async (ctx, input) => await importCommand(ctx, input, dependencies),
253
+ }),
254
+ command({
255
+ verb: 'drafts',
256
+ summary: 'List the skill drafts of an Agent that wait for the owner',
257
+ level: 'read',
258
+ properties: {},
259
+ examples: ['buckyos skill drafts --agent jarvis.example.zone'],
260
+ handler: async (ctx, input) => {
261
+ const agentId = agentIdFrom(input)
262
+ const drafts = await listDrafts(ctx, agentId)
263
+ return { agent_id: agentId, total: drafts.length, drafts }
264
+ },
265
+ }),
266
+ command({
267
+ verb: 'draft-show',
268
+ summary: 'Show a skill draft, or one of its files',
269
+ positionals: [{ name: 'slug', description: 'Draft slug' }],
270
+ options: [AGENT_OPTION, { name: 'file', description: 'Draft-relative path of a file to print', type: 'string' }],
271
+ level: 'read',
272
+ properties: { slug: NAME_PROPERTY, file: { type: 'string', minLength: 1 } },
273
+ required: ['slug'],
274
+ examples: [
275
+ 'buckyos skill draft-show release_checklist --agent jarvis.example.zone',
276
+ 'buckyos skill draft-show release_checklist --file cmd_skills/release_checklist/SKILL.md --agent jarvis.example.zone',
277
+ ],
278
+ handler: async (ctx, input) => {
279
+ const agentId = agentIdFrom(input)
280
+ const slug = requiredInputString(input, 'slug')
281
+ const file = inputString(input, 'file')
282
+ if (file) {
283
+ const shown = expectObject(await callService<unknown>(ctx, agentId, 'skills.draft_file', { slug, file }), 'skills.draft_file')
284
+ return { agent_id: agentId, slug, file, text: shown.text }
285
+ }
286
+ const draft = (await listDrafts(ctx, agentId)).find((item) => item.slug === slug)
287
+ if (!draft) throw new ToolError('RESOURCE_NOT_FOUND', `Agent ${agentId} has no skill draft ${slug}`)
288
+ return { agent_id: agentId, ...draft, install_command: `buckyos skill install --draft ${slug} --agent ${agentId}` }
289
+ },
290
+ }),
291
+ command({
292
+ verb: 'draft-discard',
293
+ summary: 'Delete a skill draft',
294
+ positionals: [{ name: 'slug', description: 'Draft slug' }],
295
+ level: 'destructive',
296
+ properties: { slug: NAME_PROPERTY },
297
+ required: ['slug'],
298
+ examples: ['buckyos --yes skill draft-discard release_checklist --agent jarvis.example.zone'],
299
+ handler: async (ctx, input) => {
300
+ const agentId = agentIdFrom(input)
301
+ const slug = requiredInputString(input, 'slug')
302
+ await confirm(ctx, 'skill draft-discard', `Discard skill draft ${slug} of ${agentId}?`)
303
+ await callService<unknown>(ctx, agentId, 'skills.draft_discard', { slug })
304
+ return { agent_id: agentId, discarded: slug }
305
+ },
306
+ }),
146
307
  ],
147
308
  }
148
309
  }
149
310
 
150
- async function installSkills(
311
+ async function listCommand(ctx: CommandContext, input: Record<string, unknown>): Promise<Record<string, unknown>> {
312
+ const agentId = agentIdFrom(input)
313
+ const scope = inputString(input, 'scope')
314
+ let kind = inputString(input, 'kind')
315
+ if (scope) {
316
+ if (kind && kind !== 'work') throw new UsageError('ARGUMENT_CONFLICT', `--scope selects work skills; a ${kind} skill has no scope`)
317
+ kind = 'work'
318
+ }
319
+ const listed = (await listSkills(ctx, agentId, kind)).filter((skill) => {
320
+ if (!scope) return true
321
+ const own = typeof skill.scope === 'string' ? skill.scope.split(',').map((word) => word.trim()) : ['work']
322
+ return own.includes(scope)
323
+ })
324
+ const shown = input.all === true ? listed : listed.filter((skill) => skill.enabled !== false)
325
+ const stats = input.stats === true
326
+ const skills = stats ? shown : shown.map(({ usage: _usage, ...skill }) => skill)
327
+ const result: Record<string, unknown> = {
328
+ agent_id: agentId,
329
+ ...(kind ? { kind } : {}),
330
+ ...(scope ? { scope } : {}),
331
+ total: skills.length,
332
+ not_enabled: listed.length - listed.filter((skill) => skill.enabled !== false).length,
333
+ skills,
334
+ }
335
+ if (stats) {
336
+ const state = expectObject(await callService<unknown>(ctx, agentId, 'skills.state', {}), 'skills.state')
337
+ const usage = state.usage && typeof state.usage === 'object' ? state.usage as Record<string, unknown> : {}
338
+ result.usage_none = usage.none ?? { frozen: 0, last_ms: 0 }
339
+ }
340
+ if (input.all === true) result.drafts = await listDrafts(ctx, agentId)
341
+ return result
342
+ }
343
+
344
+ async function setEnabled(ctx: CommandContext, input: Record<string, unknown>, enabled: boolean): Promise<Record<string, unknown>> {
345
+ const agentId = agentIdFrom(input)
346
+ const name = requiredInputString(input, 'name')
347
+ const kind = await kindOf(ctx, agentId, name, input)
348
+ const reason = inputString(input, 'reason')
349
+ const skill = await callService<unknown>(ctx, agentId, 'skills.set_enabled', {
350
+ kind,
351
+ name,
352
+ enabled,
353
+ ...(reason ? { reason } : {}),
354
+ })
355
+ return { agent_id: agentId, skill: expectObject(skill, 'skills.set_enabled') }
356
+ }
357
+
358
+ async function uiGet(ctx: CommandContext, agentId: string): Promise<Record<string, unknown> & { names: string[] }> {
359
+ const ui = expectObject(await callService<unknown>(ctx, agentId, 'skills.ui_get', {}), 'skills.ui_get')
360
+ if (!Array.isArray(ui.names)) invalidResponse('skills.ui_get')
361
+ return { ...ui, names: (ui.names as unknown[]).map(String) }
362
+ }
363
+
364
+ async function uiChange(ctx: CommandContext, input: Record<string, unknown>, add: boolean): Promise<Record<string, unknown>> {
365
+ const agentId = agentIdFrom(input)
366
+ const name = requiredInputString(input, 'name')
367
+ const current = await uiGet(ctx, agentId)
368
+ const has = current.names.includes(name)
369
+ if (!add && !has) {
370
+ throw new ToolError('RESOURCE_NOT_FOUND', `${name} is not among the UI skills of ${agentId} (${current.names.join(', ') || 'none'})`)
371
+ }
372
+ if (add && has) return { agent_id: agentId, changed: false, ...current }
373
+ const names = add ? [...current.names, name] : current.names.filter((item) => item !== name)
374
+ const ui = expectObject(await callService<unknown>(ctx, agentId, 'skills.ui_set', { names }), 'skills.ui_set')
375
+ return { agent_id: agentId, changed: true, ...ui }
376
+ }
377
+
378
+ interface SkillSource {
379
+ summary: Record<string, unknown>
380
+ params: Record<string, unknown>
381
+ extra: Record<string, unknown>
382
+ }
383
+
384
+ async function installCommand(
151
385
  ctx: CommandContext,
152
386
  input: Record<string, unknown>,
387
+ dependencies: SkillModuleDependencies,
153
388
  ): Promise<Record<string, unknown>> {
154
389
  const agentId = agentIdFrom(input)
155
- const raw = requiredInputString(input, 'pikg_path')
156
- const path = getHost().path.isAbsolute(raw)
157
- ? getHost().path.resolve(raw)
158
- : getHost().path.resolve(ctx.cwd, raw)
390
+ const source = await skillSource(ctx, input, dependencies)
391
+ const runtimeId = inputString(input, 'runtime_id')
392
+ const runtime = runtimeId ? { runtime_id: runtimeId } : {}
393
+ const plan = expectObject(
394
+ await callService<unknown>(ctx, agentId, 'skills.install_plan', { ...source.params, ...runtime }),
395
+ 'skills.install_plan',
396
+ )
397
+ const planDigest = plan.plan_digest
398
+ if (typeof planDigest !== 'string' || !planDigest) invalidResponse('skills.install_plan')
399
+ if (!ctx.confirmed) {
400
+ if (ctx.config.nonInteractive || !ctx.io.inputIsTerminal) {
401
+ throw new ToolError(
402
+ 'CONFIRMATION_REQUIRED',
403
+ `skill install requires --yes in non-interactive execution (risk: ${riskLevel(plan)})`,
404
+ EXIT_PERMISSION,
405
+ false,
406
+ { plan },
407
+ )
408
+ }
409
+ await ctx.io.stderr(planText(plan))
410
+ await confirm(ctx, 'skill install', `Install into ${agentId} (risk: ${riskLevel(plan)})?`)
411
+ }
412
+ const report = expectObject(
413
+ await callService<unknown>(ctx, agentId, 'skills.install', {
414
+ ...source.params,
415
+ plan_digest: planDigest,
416
+ replace: input.replace === true,
417
+ }),
418
+ 'skills.install',
419
+ )
420
+ return { agent_id: agentId, source: source.summary, ...source.extra, plan, ...report }
421
+ }
422
+
423
+ function riskLevel(plan: Record<string, unknown>): string {
424
+ const risk = plan.risk && typeof plan.risk === 'object' ? plan.risk as Record<string, unknown> : {}
425
+ return typeof risk.level === 'string' ? risk.level : 'unknown'
426
+ }
427
+
428
+ function planText(plan: Record<string, unknown>): string {
429
+ const lines = [`Install plan: ${plan.package}${plan.version ? ` ${plan.version}` : ''} (${plan.digest})`]
430
+ for (const item of Array.isArray(plan.skills) ? plan.skills : []) {
431
+ const skill = item as Record<string, unknown>
432
+ const scope = typeof skill.scope === 'string' ? ` [${skill.scope}]` : ''
433
+ const replaces = skill.replaces ? `; replaces the ${skill.replaces} skill` : ''
434
+ const commands = Array.isArray(skill.commands) && skill.commands.length ? `; commands: ${skill.commands.join(', ')}` : ''
435
+ lines.push(` ${skill.kind} ${skill.name}${scope}: ${skill.description ?? ''}${commands}${replaces}`)
436
+ }
437
+ if (plan.checked_runtime_id) lines.push(`Commands checked on runtime: ${plan.checked_runtime_id}`)
438
+ for (const item of Array.isArray(plan.command_status) ? plan.command_status : []) {
439
+ const entry = item as Record<string, unknown>
440
+ const status = entry.status && typeof entry.status === 'object' ? entry.status as Record<string, unknown> : {}
441
+ if (status.state !== 'partial') continue
442
+ const states = status.commands && typeof status.commands === 'object' ? status.commands as Record<string, { present?: boolean }> : {}
443
+ const missing = Object.keys(states).filter((name) => states[name]?.present === false)
444
+ const packages = (Array.isArray(status.recommended_packages) ? status.recommended_packages : [])
445
+ .map((pkg) => String((pkg as Record<string, unknown>).id))
446
+ const none = Array.isArray(status.no_package) ? status.no_package.map(String) : []
447
+ lines.push(
448
+ ` ${entry.name}: missing ${missing.join(', ')}` +
449
+ (packages.length ? `; extension packages that bring them: ${packages.join(', ')} (buckyos ext-tools enable)` : '') +
450
+ (none.length ? `; no package provides ${none.join(', ')}` : ''),
451
+ )
452
+ }
453
+ const risk = plan.risk && typeof plan.risk === 'object' ? plan.risk as Record<string, unknown> : {}
454
+ lines.push(`Risk: ${riskLevel(plan)}`)
455
+ for (const item of Array.isArray(risk.findings) ? risk.findings : []) {
456
+ const finding = item as Record<string, unknown>
457
+ lines.push(` [${finding.level}] ${finding.code} ${finding.where}: ${finding.note}`)
458
+ }
459
+ return `${lines.join('\n')}\n`
460
+ }
461
+
462
+ async function skillSource(
463
+ ctx: CommandContext,
464
+ input: Record<string, unknown>,
465
+ dependencies: SkillModuleDependencies,
466
+ ): Promise<SkillSource> {
467
+ const host = getHost()
468
+ const draft = inputString(input, 'draft')
469
+ const raw = inputString(input, 'source')
470
+ const forced = inputString(input, 'from')
471
+ if (draft) {
472
+ if (raw || forced) throw new UsageError('ARGUMENT_CONFLICT', '--draft takes no <source> and no --from: the Agent reads the draft itself')
473
+ return { summary: { kind: 'draft', draft }, params: { draft }, extra: {} }
474
+ }
475
+ if (!raw) throw new UsageError('MISSING_ARGUMENT', 'a <source> or --draft <slug> is required')
476
+ const local = host.path.isAbsolute(raw) ? host.path.resolve(raw) : host.path.resolve(ctx.cwd, raw)
477
+ let directory = forced === 'dir'
478
+ if (!forced && !/^https?:\/\//i.test(raw) && !isDidSource(raw)) {
479
+ try {
480
+ directory = (await host.stat(local)).isDirectory
481
+ } catch (error) {
482
+ if (!isHostError(error, 'NotFound')) throw error
483
+ }
484
+ }
485
+ if (directory) return await directorySource(local)
486
+
487
+ const classified = await classifySource(ctx, { source: raw, ...(forced ? { from: forced === 'did' ? 'catalog' : forced } : {}) })
488
+ if (classified.kind === 'catalog') {
489
+ throw new ToolError(
490
+ 'SKILL_SOURCE_UNSUPPORTED',
491
+ `${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`,
492
+ EXIT_UNAVAILABLE,
493
+ )
494
+ }
495
+ if (classified.kind === 'pikg') return await pikgSource(classified.path, { kind: 'pikg', path: classified.path })
496
+ await host.mkdir(ctx.configStore.root, { recursive: true, mode: 0o700 })
497
+ const temporary = await host.makeTempDir({ dir: ctx.configStore.root, prefix: '.skill-pikg-' })
498
+ try {
499
+ const snapshot = await downloadPikg(classified.url, host.path.join(temporary, 'source.pikg'), dependencies.download, ctx.signal)
500
+ return await pikgSource(snapshot.path, { kind: 'url', url: snapshot.display })
501
+ } finally {
502
+ await host.remove(temporary, { recursive: true }).catch(() => {})
503
+ }
504
+ }
505
+
506
+ async function pikgSource(path: string, summary: Record<string, unknown>): Promise<SkillSource> {
159
507
  const inspection = await inspectPikg(path)
160
508
  if (inspection.app.app_type !== SKILLS_SUB_PKG) {
161
509
  throw new UsageError(
@@ -166,92 +514,166 @@ async function installSkills(
166
514
  const payload = inspection.subpackages.find((item) => item.key === SKILLS_SUB_PKG)
167
515
  ?.payload as { path: string; digest: string }
168
516
  const archive = await openZip(path)
169
- const bytes = await readZipEntry(
170
- archive,
171
- archive.byName.get(payload.path)!,
172
- MAX_SKILL_PAYLOAD_BYTES,
173
- )
517
+ const bytes = await readZipEntry(archive, archive.byName.get(payload.path)!, MAX_SKILL_PAYLOAD_BYTES)
174
518
  if (`sha256:${sha256Bytes(bytes)}` !== payload.digest) {
175
519
  throw new ToolError('INVALID_PACKAGE', 'PIKG changed after it was verified')
176
520
  }
177
- const files: Record<string, { content: string; executable: boolean }> = {}
521
+ const files = new Map<string, SkillPackageFile>()
178
522
  const ignored: string[] = []
179
523
  for (const entry of await readTarGz(bytes, MAX_SKILL_PAYLOAD_BYTES)) {
180
- if (!SKILL_DIRS.includes(entry.path.split('/')[0])) {
181
- ignored.push(entry.path)
182
- continue
183
- }
184
- files[entry.path] = { content: base64(entry.bytes), executable: entry.executable }
524
+ if (SKILL_DIRS.includes(entry.path.split('/')[0])) files.set(entry.path, { bytes: entry.bytes })
525
+ else ignored.push(entry.path)
185
526
  }
186
- const skillPackage = {
187
- package: inspection.app.name,
188
- version: inspection.app.version,
189
- pikg_digest: inspection.pikg_digest,
190
- files,
527
+ return {
528
+ summary,
529
+ params: {
530
+ package: {
531
+ package: inspection.app.name,
532
+ version: inspection.app.version,
533
+ pikg_digest: inspection.pikg_digest,
534
+ files: packageFiles(files),
535
+ },
536
+ },
537
+ extra: { pikg_digest: inspection.pikg_digest, ...(ignored.length ? { ignored_files: ignored } : {}) },
191
538
  }
192
- const result = await callService<unknown>(ctx, agentId, 'skills.install', {
193
- package: skillPackage,
194
- replace: input.replace === true,
195
- })
196
- // Advice, after the fact: a skill is never refused for a command it does not find.
197
- const commands = await callService<Record<string, unknown>>(ctx, agentId, 'skills.install_plan', { package: skillPackage }).catch(() => null)
539
+ }
540
+
541
+ async function directorySource(path: string): Promise<SkillSource> {
542
+ const host = getHost()
543
+ let root: string
544
+ let read: Awaited<ReturnType<typeof readSkillDirectory>>
545
+ try {
546
+ root = await host.realPath(path)
547
+ if (!(await host.stat(root)).isDirectory) throw new Error('not a directory')
548
+ read = await readSkillDirectory(root, MAX_SKILL_PAYLOAD_BYTES)
549
+ } catch (error) {
550
+ throw new UsageError('INVALID_SKILL_SOURCE', `${path}: ${error instanceof Error ? error.message : String(error)}`)
551
+ }
552
+ const name = host.path.basename(root)
553
+ const invalid = lintSkillPackage(name, read.files).findings.find((finding) => finding.level === 'error')
554
+ if (invalid) throw new UsageError('INVALID_SKILL_PACKAGE', invalid.note)
198
555
  return {
199
- agent_id: agentId,
200
- pikg_path: inspection.pikg_path,
201
- pikg_digest: inspection.pikg_digest,
202
- ...expectObject(result, 'skills.install'),
203
- ...(ignored.length ? { ignored_files: ignored } : {}),
204
- ...(commands ? { commands } : {}),
556
+ summary: { kind: 'dir', path: root },
557
+ params: { package: { package: name, version: '', files: packageFiles(read.files) } },
558
+ extra: read.ignored.length ? { ignored_files: read.ignored } : {},
205
559
  }
206
560
  }
207
561
 
208
- async function removeSkill(
562
+ function packageFiles(files: Map<string, SkillPackageFile>): Record<string, { content: string }> {
563
+ const out: Record<string, { content: string }> = {}
564
+ for (const path of [...files.keys()].sort()) out[path] = { content: base64(files.get(path)!.bytes) }
565
+ return out
566
+ }
567
+
568
+ async function importCommand(
209
569
  ctx: CommandContext,
210
570
  input: Record<string, unknown>,
571
+ dependencies: SkillModuleDependencies,
211
572
  ): Promise<Record<string, unknown>> {
573
+ const host = getHost()
212
574
  const agentId = agentIdFrom(input)
213
- const name = requiredInputString(input, 'name')
214
- let kind = typeof input.kind === 'string' ? input.kind : undefined
215
- if (!kind) {
216
- const kinds = (await listSkills(ctx, agentId)).filter((skill) => skill.name === name)
217
- .map((skill) => String(skill.kind))
218
- if (kinds.length === 0) {
219
- throw new ToolError('RESOURCE_NOT_FOUND', `Agent ${agentId} has no skill named ${name}`)
220
- }
221
- if (kinds.length > 1) {
222
- throw new UsageError('AMBIGUOUS_SKILL', `${name} is both a cmd and a goal skill; use --kind`)
575
+ const raw = requiredInputString(input, 'source')
576
+ let text: string
577
+ let source: string
578
+ if (raw === '-') {
579
+ text = await (dependencies.readStdin ?? (() => host.readStdin()))()
580
+ source = 'stdin'
581
+ } else if (/^https?:\/\//i.test(raw)) {
582
+ let url: URL
583
+ try {
584
+ url = new URL(raw)
585
+ } catch {
586
+ throw new UsageError('INVALID_ARGUMENT', `invalid URL: ${raw}`)
223
587
  }
224
- kind = kinds[0]
225
- }
226
- if (!ctx.confirmed) {
227
- if (ctx.config.nonInteractive || !ctx.io.inputIsTerminal) {
228
- throw new ToolError(
229
- 'CONFIRMATION_REQUIRED',
230
- 'skill remove requires --yes in non-interactive execution',
231
- EXIT_PERMISSION,
232
- )
588
+ if (url.username || url.password) throw new UsageError('INVALID_ARGUMENT', 'the URL must not contain credentials')
589
+ try {
590
+ text = await (dependencies.fetchText ?? fetchText)(url, ctx.signal)
591
+ } catch (error) {
592
+ if (error instanceof ToolError) throw error
593
+ ctx.signal.throwIfAborted()
594
+ throw new ToolError('SKILL_IMPORT_FETCH_FAILED', `failed to fetch ${url.origin}${url.pathname}: ${error instanceof Error ? error.message : String(error)}`, EXIT_UNAVAILABLE, true)
233
595
  }
234
- const answer = (await ctx.io.prompt(`Remove ${kind} skill ${name} from ${agentId}? [y/N] `))
235
- ?.trim().toLowerCase()
236
- if (answer !== 'y' && answer !== 'yes') {
237
- throw new ToolError('CONFIRMATION_DECLINED', 'skill remove was declined', EXIT_PERMISSION)
596
+ source = `${url.origin}${url.pathname}`
597
+ } else {
598
+ const path = host.path.isAbsolute(raw) ? host.path.resolve(raw) : host.path.resolve(ctx.cwd, raw)
599
+ try {
600
+ text = new TextDecoder('utf-8', { fatal: true }).decode(await host.readFile(path))
601
+ } catch (error) {
602
+ throw new UsageError('FILE_ACCESS_FAILED', `failed to read ${raw} as UTF-8 text: ${error instanceof Error ? error.message : String(error)}`)
238
603
  }
604
+ source = host.path.basename(path)
605
+ }
606
+ if (!text.trim()) throw new UsageError('INVALID_ARGUMENT', 'the text to import is empty')
607
+ if (new TextEncoder().encode(text).length > MAX_IMPORT_TEXT_BYTES) {
608
+ throw new UsageError('INVALID_ARGUMENT', `the text to import is larger than ${MAX_IMPORT_TEXT_BYTES} bytes`)
609
+ }
610
+ const name = inputString(input, 'name')
611
+ const scope = inputString(input, 'scope')
612
+ const runtimeId = inputString(input, 'runtime_id')
613
+ const started = expectObject(
614
+ await callService<unknown>(ctx, agentId, 'skills.import', {
615
+ text,
616
+ ...(name ? { name } : {}),
617
+ ...(scope ? { scope } : {}),
618
+ source,
619
+ ...(runtimeId ? { runtime_id: runtimeId } : {}),
620
+ }),
621
+ 'skills.import',
622
+ )
623
+ return {
624
+ agent_id: agentId,
625
+ source,
626
+ ...started,
627
+ installed: false,
628
+ note:
629
+ '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.',
630
+ drafts_command: `buckyos skill drafts --agent ${agentId}`,
631
+ install_command: `buckyos skill install --draft ${name ?? '<slug>'} --agent ${agentId}`,
239
632
  }
240
- const removed = await callService<unknown>(ctx, agentId, 'skills.remove', { kind, name })
241
- return { agent_id: agentId, removed: expectObject(removed, 'skills.remove') }
242
633
  }
243
634
 
244
- async function listSkills(
245
- ctx: CommandContext,
246
- agentId: string,
247
- kind?: string,
248
- ): Promise<Record<string, unknown>[]> {
635
+ async function fetchText(url: URL, signal: AbortSignal): Promise<string> {
636
+ const response = await fetch(url, { method: 'GET', redirect: 'follow', signal })
637
+ if (!response.ok) {
638
+ await response.body?.cancel()
639
+ throw new ToolError('SKILL_IMPORT_FETCH_FAILED', `the URL returned HTTP ${response.status}`, EXIT_UNAVAILABLE, response.status >= 500)
640
+ }
641
+ return await response.text()
642
+ }
643
+
644
+ async function confirm(ctx: CommandContext, verb: string, question: string): Promise<void> {
645
+ if (ctx.confirmed) return
646
+ if (ctx.config.nonInteractive || !ctx.io.inputIsTerminal) {
647
+ throw new ToolError('CONFIRMATION_REQUIRED', `${verb} requires --yes in non-interactive execution`, EXIT_PERMISSION)
648
+ }
649
+ const answer = (await ctx.io.prompt(`${question} [y/N] `))?.trim().toLowerCase()
650
+ if (answer !== 'y' && answer !== 'yes') {
651
+ throw new ToolError('CONFIRMATION_DECLINED', `${verb} was declined`, EXIT_PERMISSION)
652
+ }
653
+ }
654
+
655
+ async function kindOf(ctx: CommandContext, agentId: string, name: string, input: Record<string, unknown>): Promise<string> {
656
+ const given = inputString(input, 'kind')
657
+ if (given) return given
658
+ const kinds = (await listSkills(ctx, agentId)).filter((skill) => skill.name === name).map((skill) => String(skill.kind))
659
+ if (kinds.length === 0) throw new ToolError('RESOURCE_NOT_FOUND', `Agent ${agentId} has no skill named ${name}`)
660
+ if (kinds.length > 1) throw new UsageError('AMBIGUOUS_SKILL', `${name} is a ${kinds.join(' and a ')} skill; use --kind`)
661
+ return kinds[0]
662
+ }
663
+
664
+ async function listSkills(ctx: CommandContext, agentId: string, kind?: string): Promise<Record<string, unknown>[]> {
249
665
  const skills = await callService<unknown>(ctx, agentId, 'skills.list', kind ? { kind } : {})
250
666
  if (!Array.isArray(skills)) invalidResponse('skills.list')
251
667
  return (skills as unknown[]).map((skill) => expectObject(skill, 'skills.list'))
252
668
  }
253
669
 
254
- function agentIdFrom(input: Record<string, unknown>): string {
670
+ async function listDrafts(ctx: CommandContext, agentId: string): Promise<Record<string, unknown>[]> {
671
+ const drafts = await callService<unknown>(ctx, agentId, 'skills.drafts', {})
672
+ if (!Array.isArray(drafts)) invalidResponse('skills.drafts')
673
+ return (drafts as unknown[]).map((draft) => expectObject(draft, 'skills.drafts'))
674
+ }
675
+
676
+ export function agentIdFrom(input: Record<string, unknown>): string {
255
677
  const agentId = requiredInputString(input, 'agent_id')
256
678
  if (!AGENT_ID.test(agentId)) {
257
679
  throw new UsageError('INVALID_AGENT_ID', `invalid Agent ID: ${agentId}`)