@dreamlake/dreamlake-cli 0.98.0 → 0.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/api/index.d.ts +212 -10
  2. package/dist/api/index.js +6 -0
  3. package/dist/api/native-experiments.d.ts +77 -0
  4. package/dist/api/native-experiments.js +31 -0
  5. package/dist/api/sessions.d.ts +240 -7
  6. package/dist/api/sessions.js +56 -1
  7. package/dist/api/skills.d.ts +122 -0
  8. package/dist/api/skills.js +220 -0
  9. package/dist/cli/experiments/index.js +2 -0
  10. package/dist/cli/experiments/native-commands.d.ts +13 -0
  11. package/dist/cli/experiments/native-commands.js +88 -0
  12. package/dist/cli/help-examples.generated.js +22 -5
  13. package/dist/cli/hosts/inventory.d.ts +28 -0
  14. package/dist/cli/hosts/inventory.js +68 -3
  15. package/dist/cli/hosts/picker.d.ts +34 -0
  16. package/dist/cli/hosts/picker.js +116 -0
  17. package/dist/cli/hosts/ssh.d.ts +16 -0
  18. package/dist/cli/hosts/ssh.js +47 -3
  19. package/dist/cli/index.js +2 -0
  20. package/dist/cli/session-affiliation.js +3 -2
  21. package/dist/cli/sessions/affiliation.d.ts +12 -1
  22. package/dist/cli/sessions/affiliation.js +37 -0
  23. package/dist/cli/sessions/control.d.ts +11 -0
  24. package/dist/cli/sessions/control.js +49 -4
  25. package/dist/cli/sessions/index.js +70 -17
  26. package/dist/cli/sessions/live.d.ts +85 -0
  27. package/dist/cli/sessions/live.js +258 -0
  28. package/dist/cli/sessions/runner/exec.d.ts +118 -6
  29. package/dist/cli/sessions/runner/exec.js +298 -47
  30. package/dist/cli/sessions/runner/native.js +4 -1
  31. package/dist/cli/sessions/runner/serve.d.ts +37 -2
  32. package/dist/cli/sessions/runner/serve.js +273 -28
  33. package/dist/cli/sessions/wrap.d.ts +63 -0
  34. package/dist/cli/sessions/wrap.js +226 -0
  35. package/dist/cli/skill/index.d.ts +19 -1
  36. package/dist/cli/skill/index.js +65 -12
  37. package/dist/cli/skill/read.d.ts +25 -0
  38. package/dist/cli/skill/read.js +65 -0
  39. package/dist/cli/skill/registry.d.ts +95 -0
  40. package/dist/cli/skill/registry.js +284 -0
  41. package/dist/cli/skill/reminders.js +2 -1
  42. package/dist/cli/version.d.ts +1 -1
  43. package/dist/cli/version.js +1 -1
  44. package/package.json +9 -9
@@ -0,0 +1,284 @@
1
+ // Where `skill read` and `skill list` get skill CONTENT from.
2
+ //
3
+ // Two sources, one shape. `local` is the bundle this CLI carries — what
4
+ // `skills.lock` pinned at build time: `dreamlake-cli/` plus the catalog
5
+ // snapshot — and works offline. `remote` is the server's read-only /skills
6
+ // registry (`src/api/skills.ts`), which serves the bundle the SERVER pins.
7
+ // Both answer with the `{ tag, commit }` that produced the bytes, so a reader
8
+ // can always say which revision it read, and a remote answer whose pin differs
9
+ // from this CLI's is reported once on stderr — never treated as a failure.
10
+ // Both also hold the bytes to that pin: the remote source to the server's file
11
+ // index and ETag (`skills.ts`), the local source to the embedded manifest's
12
+ // per-file hashes, so a vendored file that was edited after the build is never
13
+ // attributed to the commit it no longer matches.
14
+ //
15
+ // Selection: `--local` and `--remote` are explicit; with neither, a saved login
16
+ // means remote and no login means local. In that default mode a registry that
17
+ // cannot answer at all (unreachable, 5xx, an expired token) falls back to the
18
+ // local bundle with a warning; a typed refusal about the skill itself
19
+ // (not found, bad path, binary file) never does, because the local copy would
20
+ // answer a different question.
21
+ import { ApiError, createTransport } from "../../api/client.js";
22
+ import { DEFAULT_SKILL_FILE, requireSkillPath, SKILL_NAME, SkillsError, skillsApi, } from "../../api/skills.js";
23
+ import { resolveRemote, resolveToken } from "../config.js";
24
+ import { telemetryHeaders } from "../telemetry.js";
25
+ import { bundledBytes, embeddedCatalog, embeddedManifest, fmtVersion, listBundledSkills, resolveBundleDir, versionsEqual, } from "./catalog.js";
26
+ import { sha256 } from "./files.js";
27
+ /** `kind` is the CLI's kebab-case identity; `code` is the server's, when the refusal is one the registry defines. */
28
+ export class RegistryError extends Error {
29
+ kind;
30
+ code;
31
+ constructor(message, kind, code) {
32
+ super(message);
33
+ this.kind = kind;
34
+ this.code = code;
35
+ this.name = "RegistryError";
36
+ }
37
+ }
38
+ /** Failures that say nothing about the skill asked for: the registry could not answer at all. */
39
+ const AVAILABILITY_KINDS = new Set(["registry-unreachable", "unauthorized", "skills-unavailable", "skills-lock-mismatch"]);
40
+ export function isAvailabilityFailure(error) {
41
+ return error instanceof RegistryError && AVAILABILITY_KINDS.has(error.kind);
42
+ }
43
+ const kebab = (code) => code.replace(/_/g, "-");
44
+ // ─── local: the embedded bundle ──────────────────────────────────────────────
45
+ function snapshot(bundleDir) {
46
+ try {
47
+ return embeddedCatalog(bundleDir);
48
+ }
49
+ catch {
50
+ return null;
51
+ }
52
+ }
53
+ function noBundle() {
54
+ return new RegistryError("no bundled skills found — this build ships none. Log in and use --remote, or point DREAMLAKE_SKILLS_DIR at a skills/ directory.", "no-bundle");
55
+ }
56
+ /** The version the embedded bundle was cut from, as its manifest records it. */
57
+ export function localVersion(bundleDir = resolveBundleDir()) {
58
+ try {
59
+ const manifest = bundleDir ? embeddedManifest(bundleDir) : null;
60
+ return { tag: manifest?.tag ?? null, commit: manifest?.commit ?? null };
61
+ }
62
+ catch {
63
+ return { tag: null, commit: null };
64
+ }
65
+ }
66
+ /** The manifest's index of one skill: `<relative path>` → sha256, from its `<skill>/<path>` keys. */
67
+ function indexedFiles(manifest, name) {
68
+ const prefix = `${name}/`;
69
+ const index = new Map();
70
+ for (const key of Object.keys(manifest.files).sort()) {
71
+ if (key.startsWith(prefix))
72
+ index.set(key.slice(prefix.length), manifest.files[key]);
73
+ }
74
+ return index;
75
+ }
76
+ /** The bundle is not what its manifest pinned: a file edited after the build, or gone. Reinstalling or `--remote` answers for the pin. */
77
+ function mismatch(what) {
78
+ return new RegistryError(`${what}; reinstall the CLI, or read it from the server with --remote`, "skill-file-mismatch");
79
+ }
80
+ function embeddedNames(bundleDir) {
81
+ try {
82
+ return bundleDir ? listBundledSkills(bundleDir) : [];
83
+ }
84
+ catch {
85
+ return [];
86
+ }
87
+ }
88
+ export function localList() {
89
+ const bundleDir = resolveBundleDir();
90
+ if (!bundleDir)
91
+ throw noBundle();
92
+ const embedded = embeddedNames(bundleDir);
93
+ const version = localVersion(bundleDir);
94
+ const catalog = snapshot(bundleDir) ?? {
95
+ schema: 1,
96
+ version: version.tag ?? version.commit ?? "",
97
+ skills: Object.fromEntries(embedded.map((name) => [name, { description: "", requires: [] }])),
98
+ renamed: {},
99
+ };
100
+ return { source: "local", version, catalog, embedded };
101
+ }
102
+ export function localRead(input) {
103
+ const bundleDir = resolveBundleDir();
104
+ if (!bundleDir)
105
+ throw noBundle();
106
+ if (!SKILL_NAME.test(input.skill))
107
+ throw new RegistryError(`unknown skill ${input.skill}`, "skill-not-found", "skill_not_found");
108
+ // The same validation and normalisation the API applies before a request, so both sources answer for the same path.
109
+ let path;
110
+ try {
111
+ path = requireSkillPath(input.path ?? DEFAULT_SKILL_FILE);
112
+ }
113
+ catch {
114
+ throw new RegistryError(`invalid path ${input.path}: use a relative path inside the skill, like actions/read.md`, "skill-path-invalid", "skill_path_invalid");
115
+ }
116
+ const catalog = snapshot(bundleDir);
117
+ const name = catalog?.renamed[input.skill] ?? input.skill;
118
+ const embedded = embeddedNames(bundleDir);
119
+ if (!embedded.includes(name)) {
120
+ if (catalog?.skills[name]) {
121
+ throw new RegistryError(`${name} is in the catalog but this CLI embeds only ${embedded.join(", ") || "nothing"}; read it from the server with --remote`, "not-embedded", "skill_not_found");
122
+ }
123
+ throw new RegistryError(`unknown skill ${input.skill}`, "skill-not-found", "skill_not_found");
124
+ }
125
+ // The manifest, not the directory, is the index: what the build pinned is what is listed and what may be read.
126
+ const manifest = embeddedManifest(bundleDir);
127
+ const version = { tag: manifest.tag, commit: manifest.commit };
128
+ const index = indexedFiles(manifest, name);
129
+ const pin = `the embedded manifest (${describeVersion(version)})`;
130
+ if (index.size === 0)
131
+ throw mismatch(`${name} is in the bundle but ${pin} indexes none of its files`);
132
+ const expected = index.get(path);
133
+ if (expected === undefined)
134
+ throw new RegistryError(`${name} has no file ${path}`, "skill-file-not-found", "skill_file_not_found");
135
+ let bytes;
136
+ try {
137
+ bytes = bundledBytes(bundleDir, name, path);
138
+ }
139
+ catch {
140
+ throw mismatch(`${name}/${path} is indexed by ${pin} but missing from the bundle`);
141
+ }
142
+ const digest = sha256(bytes);
143
+ if (digest !== expected)
144
+ throw mismatch(`${name}/${path} does not match ${pin}: the bundled file was changed after the build`);
145
+ let content;
146
+ try {
147
+ // `ignoreBOM`: a leading byte order mark is content — it is in the bytes `digest` covers, so it stays in `content`.
148
+ content = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
149
+ }
150
+ catch {
151
+ throw new RegistryError(`${name}/${path} is not a text file`, "skill-file-binary", "skill_file_binary");
152
+ }
153
+ const files = [...index.keys()];
154
+ return {
155
+ source: "local",
156
+ ...version,
157
+ skill: name,
158
+ ...(name !== input.skill ? { renamedFrom: input.skill } : {}),
159
+ path,
160
+ sha256: digest,
161
+ content,
162
+ files,
163
+ filesTotal: files.length,
164
+ filesTruncated: false,
165
+ };
166
+ }
167
+ /** The active login, or null when there is none (machine identity carries no human token). */
168
+ export function remoteConnection() {
169
+ let token;
170
+ try {
171
+ token = resolveToken();
172
+ }
173
+ catch {
174
+ return null;
175
+ }
176
+ if (!token)
177
+ return null;
178
+ return { remote: resolveRemote(), token };
179
+ }
180
+ /** The shared API transport with the CLI's telemetry preference attached. */
181
+ export function remoteTransport(c) {
182
+ const base = createTransport({ remote: c.remote, token: c.token });
183
+ const decorate = (options) => ({ ...options, headers: { ...telemetryHeaders(), ...options?.headers } });
184
+ return {
185
+ request: (method, path, options) => base.request(method, path, decorate(options)),
186
+ raw: (method, path, options) => base.raw(method, path, decorate(options)),
187
+ };
188
+ }
189
+ export const remoteSkills = (c) => skillsApi(remoteTransport(c));
190
+ function registryFailure(error) {
191
+ if (error instanceof SkillsError) {
192
+ const detail = {
193
+ skills_unavailable: "the server could not load its skills bundle",
194
+ skills_lock_mismatch: "the server's skills bundle does not match its skills.lock",
195
+ skill_not_found: "the server has no such skill",
196
+ skill_file_not_found: "the skill has no such file",
197
+ skill_path_invalid: "invalid path: use a relative path inside the skill, like actions/read.md",
198
+ skill_file_binary: "that file is not text",
199
+ skill_result_too_large: "the server could not fit the answer in one page",
200
+ skill_range_invalid: "the server refused the page offset",
201
+ };
202
+ throw new RegistryError(`${detail[error.code]} (${error.code})`, kebab(error.code), error.code);
203
+ }
204
+ if (error instanceof ApiError) {
205
+ const unauthorized = error.status === 401 || error.status === 403;
206
+ throw new RegistryError(unauthorized ? `the server refused the saved login (${error.status} ${error.code}); run 'dreamlake login'` : `the skills registry answered (${error.status}) ${error.code}`, unauthorized ? "unauthorized" : "registry-unreachable");
207
+ }
208
+ throw new RegistryError(`cannot reach the skills registry: ${error.message}`, "registry-unreachable");
209
+ }
210
+ export async function remoteList(c) {
211
+ const answer = await remoteSkills(c).list().catch(registryFailure);
212
+ const catalog = {
213
+ schema: 1,
214
+ version: answer.version.tag,
215
+ skills: Object.fromEntries(answer.skills.map((s) => [s.name, { description: s.description, requires: s.requires, tools: s.tools, files: s.files }])),
216
+ renamed: answer.renamed,
217
+ };
218
+ return { source: "remote", version: answer.version, catalog, embedded: embeddedNames(resolveBundleDir()) };
219
+ }
220
+ export async function remoteRead(c, input) {
221
+ const result = await remoteSkills(c).read(input).catch(registryFailure);
222
+ return { source: "remote", ...result };
223
+ }
224
+ export function chooseSource(opts) {
225
+ if (opts.local && opts.remote)
226
+ return new RegistryError("--local and --remote are mutually exclusive", "invalid-source");
227
+ if (opts.local)
228
+ return { source: "local", explicit: true, connection: null };
229
+ const connection = remoteConnection();
230
+ if (opts.remote) {
231
+ if (!connection)
232
+ return new RegistryError("--remote needs a login: run 'dreamlake login', or read the embedded copy with --local", "not-logged-in");
233
+ return { source: "remote", explicit: true, connection };
234
+ }
235
+ return connection ? { source: "remote", explicit: false, connection } : { source: "local", explicit: false, connection: null };
236
+ }
237
+ /** `v2026.10.29.1 (7d13e08e9260)`, or just the short commit for a commit pin. */
238
+ export function describeVersion(v) {
239
+ const short = v.commit ? v.commit.slice(0, 12) : null;
240
+ if (v.tag)
241
+ return short ? `${fmtVersion(v.tag)} (${short})` : fmtVersion(v.tag);
242
+ return short ?? "unversioned";
243
+ }
244
+ /** One stderr line when the server's pin is not this CLI's; null when they agree or the CLI has no bundle. */
245
+ export function pinMismatchLine(remote) {
246
+ const local = localVersion();
247
+ if (!local.tag && !local.commit)
248
+ return null;
249
+ const same = local.commit && remote.commit ? local.commit === remote.commit : versionsEqual(local.tag, remote.tag);
250
+ if (same)
251
+ return null;
252
+ return `skills pin differs: this CLI embeds ${describeVersion(local)}; the server answered ${describeVersion(remote)}`;
253
+ }
254
+ /**
255
+ * Read from the chosen source. In default mode a registry that cannot answer
256
+ * falls back to the local bundle and `fellBack` says why.
257
+ */
258
+ export async function readFrom(chosen, input) {
259
+ if (chosen.source === "local")
260
+ return { result: localRead(input), mismatch: null, fellBack: null };
261
+ try {
262
+ const result = await remoteRead(chosen.connection, input);
263
+ return { result, mismatch: pinMismatchLine(result), fellBack: null };
264
+ }
265
+ catch (error) {
266
+ if (chosen.explicit || !isAvailabilityFailure(error))
267
+ throw error;
268
+ return { result: localRead(input), mismatch: null, fellBack: error.message };
269
+ }
270
+ }
271
+ /** The same for the list. */
272
+ export async function listFrom(chosen) {
273
+ if (chosen.source === "local")
274
+ return { result: localList(), mismatch: null, fellBack: null };
275
+ try {
276
+ const result = await remoteList(chosen.connection);
277
+ return { result, mismatch: pinMismatchLine(result.version), fellBack: null };
278
+ }
279
+ catch (error) {
280
+ if (chosen.explicit || !isAvailabilityFailure(error))
281
+ throw error;
282
+ return { result: localList(), mismatch: null, fellBack: error.message };
283
+ }
284
+ }
@@ -88,7 +88,8 @@ export function remindAfterInstall(version) {
88
88
  try {
89
89
  const entries = [];
90
90
  for (const agent of agents) {
91
- const result = spawnSync(versionPath(version), ["skill", "list", "--agent", agent, "--json"], {
91
+ // `--local`: the embedded snapshot only, never a server round-trip with a 3s budget.
92
+ const result = spawnSync(versionPath(version), ["skill", "list", "--agent", agent, "--local", "--json"], {
92
93
  encoding: "utf8", timeout: 3000, maxBuffer: 1024 * 1024,
93
94
  env: { ...process.env, DREAMLAKE_SKILLS_DIR: undefined, DREAMLAKE_UPDATE_BACKGROUND: "1", DREAMLAKE_DISABLE_AUTOUPDATER: "1" },
94
95
  stdio: ["ignore", "pipe", "pipe"],
@@ -1 +1 @@
1
- export declare const VERSION = "0.98.0";
1
+ export declare const VERSION = "0.100.0";
@@ -6,4 +6,4 @@
6
6
  // value means a binary that re-installs the same version forever.
7
7
  //
8
8
  // Editing this by hand does nothing for a release; bump package.json.
9
- export const VERSION = "0.98.0";
9
+ export const VERSION = "0.100.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.98.0",
3
+ "version": "0.100.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dreamlake-ai/dreamlake-cli.git"
@@ -35,13 +35,13 @@
35
35
  "node": ">=18"
36
36
  },
37
37
  "optionalDependencies": {
38
- "@dreamlake/dreamlake-cli-darwin-arm64": "0.98.0",
39
- "@dreamlake/dreamlake-cli-darwin-x64": "0.98.0",
40
- "@dreamlake/dreamlake-cli-linux-x64": "0.98.0",
41
- "@dreamlake/dreamlake-cli-linux-arm64": "0.98.0",
42
- "@dreamlake/dreamlake-cli-linux-x64-musl": "0.98.0",
43
- "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.98.0",
44
- "@dreamlake/dreamlake-cli-win32-x64": "0.98.0",
45
- "@dreamlake/dreamlake-cli-win32-arm64": "0.98.0"
38
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.100.0",
39
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.100.0",
40
+ "@dreamlake/dreamlake-cli-linux-x64": "0.100.0",
41
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.100.0",
42
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.100.0",
43
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.100.0",
44
+ "@dreamlake/dreamlake-cli-win32-x64": "0.100.0",
45
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.100.0"
46
46
  }
47
47
  }