@dreamlake/dreamlake-cli 0.98.0 → 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.ts +212 -10
- package/dist/api/index.js +6 -0
- package/dist/api/native-experiments.d.ts +77 -0
- package/dist/api/native-experiments.js +31 -0
- package/dist/api/sessions.d.ts +240 -7
- package/dist/api/sessions.js +56 -1
- package/dist/api/skills.d.ts +122 -0
- package/dist/api/skills.js +220 -0
- package/dist/cli/experiments/index.js +2 -0
- package/dist/cli/experiments/native-commands.d.ts +13 -0
- package/dist/cli/experiments/native-commands.js +88 -0
- package/dist/cli/help-examples.generated.js +22 -5
- package/dist/cli/index.js +2 -0
- package/dist/cli/session-affiliation.js +3 -2
- package/dist/cli/sessions/affiliation.d.ts +12 -1
- package/dist/cli/sessions/affiliation.js +37 -0
- package/dist/cli/sessions/control.d.ts +11 -0
- package/dist/cli/sessions/control.js +49 -4
- package/dist/cli/sessions/index.js +70 -17
- package/dist/cli/sessions/live.d.ts +85 -0
- package/dist/cli/sessions/live.js +258 -0
- package/dist/cli/sessions/runner/exec.d.ts +118 -6
- package/dist/cli/sessions/runner/exec.js +298 -47
- package/dist/cli/sessions/runner/native.js +4 -1
- package/dist/cli/sessions/runner/serve.d.ts +37 -2
- package/dist/cli/sessions/runner/serve.js +273 -28
- package/dist/cli/sessions/wrap.d.ts +63 -0
- package/dist/cli/sessions/wrap.js +226 -0
- package/dist/cli/skill/index.d.ts +19 -1
- package/dist/cli/skill/index.js +65 -12
- package/dist/cli/skill/read.d.ts +25 -0
- package/dist/cli/skill/read.js +65 -0
- package/dist/cli/skill/registry.d.ts +95 -0
- package/dist/cli/skill/registry.js +284 -0
- package/dist/cli/skill/reminders.js +2 -1
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/** Skills registry: the server's pinned dreamlake-skills bundle, read-only.
|
|
2
|
+
*
|
|
3
|
+
* One business operation shared by three surfaces — `client.skills.read`,
|
|
4
|
+
* `dreamlake skill read` and the built-in agent's `dreamlake_skills_read` —
|
|
5
|
+
* with the same inputs, the same output fields and the same error codes.
|
|
6
|
+
* Every answer carries the bundle's `{ tag, commit }` so a caller can say
|
|
7
|
+
* which revision it read, and every content hash is verified against the
|
|
8
|
+
* skill's file index before it is returned.
|
|
9
|
+
*
|
|
10
|
+
* Server routes (dreamlake-server `routes/skills.ts`):
|
|
11
|
+
* GET /skills → SkillsList (ETag = commit)
|
|
12
|
+
* GET /skills/:skill → SkillDetail (manifest, SKILL.md body, file index)
|
|
13
|
+
* GET /skills/:skill/files/* → text/plain; ETag = content sha256; 304 on If-None-Match; 415 when binary
|
|
14
|
+
*/
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import { ApiError } from "./client.js";
|
|
17
|
+
/** Fields every read surface exposes. */
|
|
18
|
+
export const SKILL_READ_FIELDS = ["tag", "commit", "skill", "path", "sha256", "content", "files", "filesTotal", "filesTruncated"];
|
|
19
|
+
/** Present only when the request named a retired skill name. */
|
|
20
|
+
export const SKILL_READ_OPTIONAL_FIELDS = ["renamedFrom"];
|
|
21
|
+
/** Fields only the paged agent tool carries: the code-point window of the page. */
|
|
22
|
+
export const SKILL_READ_PAGING_FIELDS = ["start", "end", "total", "next", "complete"];
|
|
23
|
+
export const DEFAULT_SKILL_FILE = "SKILL.md";
|
|
24
|
+
/** The server's typed refusals and the status each one carries; the last two come only from the paged agent tool. */
|
|
25
|
+
export const SKILLS_ERROR_CODES = {
|
|
26
|
+
skills_unavailable: 503,
|
|
27
|
+
skills_lock_mismatch: 503,
|
|
28
|
+
skill_not_found: 404,
|
|
29
|
+
skill_file_not_found: 404,
|
|
30
|
+
skill_path_invalid: 400,
|
|
31
|
+
skill_file_binary: 415,
|
|
32
|
+
skill_result_too_large: 413,
|
|
33
|
+
skill_range_invalid: 400,
|
|
34
|
+
};
|
|
35
|
+
export const isSkillsErrorCode = (code) => typeof code === "string" && Object.hasOwn(SKILLS_ERROR_CODES, code);
|
|
36
|
+
/** A refusal the skills registry defines. `code` is the identity callers branch on. */
|
|
37
|
+
export class SkillsError extends ApiError {
|
|
38
|
+
code;
|
|
39
|
+
constructor(status, code, body = { error: code }, requestId) {
|
|
40
|
+
super(status, code, body, undefined, requestId);
|
|
41
|
+
this.code = code;
|
|
42
|
+
this.name = "SkillsError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Map a transport failure onto the typed refusal when it is one; other failures pass through. */
|
|
46
|
+
export function skillsFailure(error) {
|
|
47
|
+
if (error instanceof SkillsError)
|
|
48
|
+
return error;
|
|
49
|
+
if (error instanceof ApiError && isSkillsErrorCode(error.code)) {
|
|
50
|
+
return new SkillsError(error.status, error.code, error.body, error.requestId);
|
|
51
|
+
}
|
|
52
|
+
return error;
|
|
53
|
+
}
|
|
54
|
+
/** Skill names as the server validates them (`services/skillsBundle.ts`). */
|
|
55
|
+
export const SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
56
|
+
/** A relative, forward-slash path inside a skill: no `..`, no leading `/`, no empty segment. */
|
|
57
|
+
export const SKILL_FILE_PATH = /^[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*$/;
|
|
58
|
+
export const skillContentSha256 = (text) => createHash("sha256").update(text, "utf8").digest("hex");
|
|
59
|
+
const SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
60
|
+
/** `Response.text()` drops a leading byte order mark; the ETag and the index hash the bytes with it, so the body is decoded keeping it. */
|
|
61
|
+
const utf8KeepingBom = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
62
|
+
const responseText = async (response) => utf8KeepingBom.decode(await response.arrayBuffer());
|
|
63
|
+
const unquote = (etag) => (etag ?? "").replace(/^W\//, "").replace(/^"(.*)"$/, "$1");
|
|
64
|
+
export function requireSkillName(skill) {
|
|
65
|
+
if (!SKILL_NAME.test(skill))
|
|
66
|
+
throw new SkillsError(404, "skill_not_found");
|
|
67
|
+
return skill;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The path as the server resolves it (`services/skillsTar.ts` safeRelativePath):
|
|
71
|
+
* `.` segments dropped, `..` refused — so the `path` returned is the one the
|
|
72
|
+
* file index lists and the agent tool reports.
|
|
73
|
+
*/
|
|
74
|
+
export function requireSkillPath(path) {
|
|
75
|
+
if (!SKILL_FILE_PATH.test(path))
|
|
76
|
+
throw new SkillsError(400, "skill_path_invalid");
|
|
77
|
+
const parts = path.split("/").filter((segment) => segment !== ".");
|
|
78
|
+
if (parts.length === 0 || parts.includes(".."))
|
|
79
|
+
throw new SkillsError(400, "skill_path_invalid");
|
|
80
|
+
return parts.join("/");
|
|
81
|
+
}
|
|
82
|
+
function requireVersion(value) {
|
|
83
|
+
const v = value;
|
|
84
|
+
if (!v || typeof v.tag !== "string" || typeof v.commit !== "string" || !v.tag || !v.commit) {
|
|
85
|
+
throw new Error("skills registry answered without a version");
|
|
86
|
+
}
|
|
87
|
+
return { tag: v.tag, commit: v.commit };
|
|
88
|
+
}
|
|
89
|
+
function versionFromHeaders(headers, fallback) {
|
|
90
|
+
const tag = headers?.get("x-skills-tag"), commit = headers?.get("x-skills-commit");
|
|
91
|
+
if (tag && commit)
|
|
92
|
+
return { tag, commit };
|
|
93
|
+
if (fallback)
|
|
94
|
+
return fallback;
|
|
95
|
+
throw new Error("skills registry answered without a version");
|
|
96
|
+
}
|
|
97
|
+
const isPaged = (value) => !!value && typeof value === "object" && typeof value.content === "string";
|
|
98
|
+
export function skillsApi(t) {
|
|
99
|
+
const skillPath = (skill) => `/skills/${encodeURIComponent(requireSkillName(skill))}`;
|
|
100
|
+
const filePath = (skill, path) => `${skillPath(skill)}/files/${requireSkillPath(path).split("/").map(encodeURIComponent).join("/")}`;
|
|
101
|
+
/**
|
|
102
|
+
* GET one file. The route answers text/plain; a JSON answer in the agent
|
|
103
|
+
* tool's paged shape is followed through `next` so the result is always the
|
|
104
|
+
* whole file. The content is hashed and held to the ETag.
|
|
105
|
+
*/
|
|
106
|
+
async function fetchFile(skill, path, ifNoneMatch) {
|
|
107
|
+
if (!t.raw)
|
|
108
|
+
throw new Error("reading skill files needs a transport with raw responses");
|
|
109
|
+
const target = filePath(skill, path);
|
|
110
|
+
const headers = ifNoneMatch ? { "If-None-Match": ifNoneMatch } : undefined;
|
|
111
|
+
let seen;
|
|
112
|
+
const onHeaders = (h) => { seen = h; };
|
|
113
|
+
try {
|
|
114
|
+
let start = 0, content = "", etag = "";
|
|
115
|
+
let version;
|
|
116
|
+
for (;;) {
|
|
117
|
+
const response = await t.raw("GET", target, { headers, onHeaders, query: start > 0 ? { start } : undefined });
|
|
118
|
+
version = versionFromHeaders(response.headers, version);
|
|
119
|
+
etag ||= unquote(response.headers.get("etag"));
|
|
120
|
+
if (!/\bjson\b/i.test(response.headers.get("content-type") ?? "")) {
|
|
121
|
+
content += await responseText(response);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
const page = await response.json();
|
|
125
|
+
if (!isPaged(page))
|
|
126
|
+
throw new Error("skills registry answered with neither text nor a page");
|
|
127
|
+
content += page.content;
|
|
128
|
+
if (page.complete !== false || page.next === null || page.next === undefined)
|
|
129
|
+
break;
|
|
130
|
+
if (page.next <= start)
|
|
131
|
+
throw new Error("skills registry page did not advance");
|
|
132
|
+
start = page.next;
|
|
133
|
+
}
|
|
134
|
+
const digest = skillContentSha256(content);
|
|
135
|
+
if (etag && SHA256_HEX.test(etag) && etag !== digest)
|
|
136
|
+
throw new Error(`skill file ${path} does not hash to its ETag`);
|
|
137
|
+
return { status: 200, ...version, path, sha256: digest, content };
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error instanceof ApiError && error.status === 304) {
|
|
141
|
+
return { status: 304, ...versionFromHeaders(seen), path, sha256: unquote(seen?.get("etag")) || unquote(ifNoneMatch), content: null };
|
|
142
|
+
}
|
|
143
|
+
throw skillsFailure(error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** The pinned bundle's version, every skill's summary and the rename table. */
|
|
147
|
+
async function list() {
|
|
148
|
+
try {
|
|
149
|
+
const answer = await t.request("GET", "/skills");
|
|
150
|
+
if (!answer || !Array.isArray(answer.skills))
|
|
151
|
+
throw new Error("skills registry answered without a skill list");
|
|
152
|
+
return { version: requireVersion(answer.version), skills: answer.skills, renamed: answer.renamed ?? {} };
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
throw skillsFailure(error);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** One skill's manifest, SKILL.md body and file index. */
|
|
159
|
+
async function skill(name) {
|
|
160
|
+
try {
|
|
161
|
+
const answer = await t.request("GET", skillPath(name));
|
|
162
|
+
if (!answer || typeof answer.body !== "string" || !Array.isArray(answer.files)) {
|
|
163
|
+
throw new Error("skills registry answered without a skill body");
|
|
164
|
+
}
|
|
165
|
+
return { ...answer, version: requireVersion(answer.version) };
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
throw skillsFailure(error);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Read one whole file of a skill — `SKILL.md` unless `path` names another —
|
|
173
|
+
* with the bundle version and the content's sha256, verified against the
|
|
174
|
+
* skill's file index. The body of `SKILL.md` comes with the index in one
|
|
175
|
+
* request; any other path is a second request for that file.
|
|
176
|
+
*/
|
|
177
|
+
async function read(input) {
|
|
178
|
+
const path = requireSkillPath(input.path ?? DEFAULT_SKILL_FILE);
|
|
179
|
+
const detail = await skill(input.skill);
|
|
180
|
+
const entry = detail.files.find((f) => f.path === path);
|
|
181
|
+
if (!entry)
|
|
182
|
+
throw new SkillsError(404, "skill_file_not_found");
|
|
183
|
+
if (!entry.text)
|
|
184
|
+
throw new SkillsError(415, "skill_file_binary");
|
|
185
|
+
let content, digest;
|
|
186
|
+
if (path === DEFAULT_SKILL_FILE) {
|
|
187
|
+
content = detail.body;
|
|
188
|
+
digest = skillContentSha256(content);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
const file = await fetchFile(detail.name, path);
|
|
192
|
+
if (file.commit !== detail.version.commit) {
|
|
193
|
+
throw new Error(`skills bundle changed between requests (${detail.version.commit} → ${file.commit}); retry`);
|
|
194
|
+
}
|
|
195
|
+
content = file.content;
|
|
196
|
+
digest = file.sha256;
|
|
197
|
+
}
|
|
198
|
+
if (digest !== entry.sha256)
|
|
199
|
+
throw new Error(`skill file ${path} does not hash to the index sha256 ${entry.sha256}`);
|
|
200
|
+
return {
|
|
201
|
+
tag: detail.version.tag,
|
|
202
|
+
commit: detail.version.commit,
|
|
203
|
+
skill: detail.name,
|
|
204
|
+
...(detail.renamedFrom ? { renamedFrom: detail.renamedFrom } : {}),
|
|
205
|
+
path,
|
|
206
|
+
sha256: digest,
|
|
207
|
+
content,
|
|
208
|
+
files: detail.files.map((f) => f.path),
|
|
209
|
+
filesTotal: detail.files.length,
|
|
210
|
+
filesTruncated: false,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/** One file as text with its ETag, or `status: 304` when `ifNoneMatch` already names it. */
|
|
214
|
+
function file(input) {
|
|
215
|
+
const etag = input.ifNoneMatch === undefined ? undefined
|
|
216
|
+
: /^(W\/)?".*"$/.test(input.ifNoneMatch) ? input.ifNoneMatch : `"${input.ifNoneMatch}"`;
|
|
217
|
+
return fetchFile(input.skill, input.path, etag);
|
|
218
|
+
}
|
|
219
|
+
return { list, skill, read, file };
|
|
220
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HttpError, requestJson } from "../client.js";
|
|
2
2
|
import { resolveRemote, resolveToken } from "../config.js";
|
|
3
3
|
import { emitJson, fail } from "../helpers.js";
|
|
4
|
+
import { registerNativeExperimentCommands } from "./native-commands.js";
|
|
4
5
|
class BindingError extends Error {
|
|
5
6
|
code;
|
|
6
7
|
remediation;
|
|
@@ -147,6 +148,7 @@ export async function runExperiments(action, opts, selection) {
|
|
|
147
148
|
}
|
|
148
149
|
export function registerExperimentsCommand(program) {
|
|
149
150
|
const command = program.command("experiments").description("discover and explicitly bind an existing managed Dash workspace (JSON receipts)");
|
|
151
|
+
registerNativeExperimentCommands(command);
|
|
150
152
|
for (const action of ["workspaces", "binding", "connect", "disconnect"]) {
|
|
151
153
|
const sub = command.command(action)
|
|
152
154
|
.description({ workspaces: "list verified eligible Dash organization workspaces", binding: "inspect the current binding and revision", connect: "preview a workspace binding; --apply commits it", disconnect: "preview detaching; remote experiments and SDK access are retained" }[action])
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
type Action = "list" | "create" | "archive" | "restore" | "log" | "trash-list" | "delete" | "trash-restore";
|
|
3
|
+
interface Options {
|
|
4
|
+
namespace: string;
|
|
5
|
+
project: string;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
limit?: string;
|
|
8
|
+
cursor?: string;
|
|
9
|
+
level?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function runNativeExperiment(action: Action, opts: Options, subject?: string, message?: string): Promise<number>;
|
|
12
|
+
export declare function registerNativeExperimentCommands(parent: Command): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { HttpError, requestJson } from "../client.js";
|
|
2
|
+
import { resolveRemote, resolveToken } from "../config.js";
|
|
3
|
+
import { emitJson, fail } from "../helpers.js";
|
|
4
|
+
const id = /^[0-9a-f]{24}$/;
|
|
5
|
+
const key = /^[A-Za-z0-9_-]{1,128}$/;
|
|
6
|
+
export async function runNativeExperiment(action, opts, subject, message) {
|
|
7
|
+
try {
|
|
8
|
+
const token = resolveToken();
|
|
9
|
+
if (!token)
|
|
10
|
+
throw new Error("DreamLake login is required; run dreamlake login.");
|
|
11
|
+
if (!opts.namespace || !opts.project)
|
|
12
|
+
throw new Error("--namespace and --project are required.");
|
|
13
|
+
const base = `/native-experiments/ns/${encodeURIComponent(opts.namespace)}/projects/${encodeURIComponent(opts.project)}`;
|
|
14
|
+
const remote = resolveRemote();
|
|
15
|
+
if (action === "list" || action === "trash-list") {
|
|
16
|
+
const limit = opts.limit === undefined ? 50 : Number(opts.limit);
|
|
17
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100 ||
|
|
18
|
+
opts.limit !== undefined && !/^[1-9][0-9]*$/.test(opts.limit) ||
|
|
19
|
+
opts.cursor !== undefined && !id.test(opts.cursor))
|
|
20
|
+
throw new Error("Invalid list limit or cursor.");
|
|
21
|
+
emitJson(await requestJson(remote, `${base}/${action === "trash-list" ? "trash" : "runs"}`, { token, query: { limit,
|
|
22
|
+
...(opts.cursor ? { cursor: opts.cursor } : {}) }, redirect: "error" }));
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
if (!subject || !(action === "create" ? key : id).test(subject))
|
|
26
|
+
throw new Error(action === "create"
|
|
27
|
+
? "Run key must contain 1-128 letters, digits, underscores or hyphens."
|
|
28
|
+
: "Run ID must be a DreamLake native Experiment ID.");
|
|
29
|
+
if (action === "create") {
|
|
30
|
+
emitJson(await requestJson(remote, `${base}/runs/${encodeURIComponent(subject)}`, { token, method: "PUT", redirect: "error" }));
|
|
31
|
+
}
|
|
32
|
+
else if (action === "delete" || action === "trash-restore") {
|
|
33
|
+
emitJson(await requestJson(remote, `${base}/runs/${subject}${action === "trash-restore" ? "/restore" : ""}`, {
|
|
34
|
+
token, method: action === "delete" ? "DELETE" : "POST", redirect: "error"
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
else if (action === "archive" || action === "restore") {
|
|
38
|
+
emitJson(await requestJson(remote, `${base}/runs/${subject}`, { token, method: "PATCH",
|
|
39
|
+
json: { archived: action === "archive" }, redirect: "error" }));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
if (!message || !["info", "warn", "error", "debug", "fatal"].includes(opts.level ?? "info"))
|
|
43
|
+
throw new Error("Log requires a message and a valid --level.");
|
|
44
|
+
emitJson(await requestJson(remote, `${base}/runs/${subject}/logs`, { token, method: "POST", redirect: "error",
|
|
45
|
+
json: { entries: [{ timestamp: new Date().toISOString(), level: opts.level ?? "info", message }] } }));
|
|
46
|
+
}
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const code = error instanceof HttpError ? `NATIVE_HTTP_${error.status}` : "NATIVE_INVALID_REQUEST";
|
|
51
|
+
const message = error instanceof HttpError ? `Experiment request failed (HTTP ${error.status}). Inspect the run before retrying a write.` :
|
|
52
|
+
error instanceof Error ? error.message : "Experiment request failed.";
|
|
53
|
+
if (opts.json)
|
|
54
|
+
emitJson({ ok: false, error: { code, message } });
|
|
55
|
+
else
|
|
56
|
+
fail(`${code}: ${message}`);
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function registerNativeExperimentCommands(parent) {
|
|
61
|
+
const runs = parent.command("runs").description("DreamLake-native project Experiment runs");
|
|
62
|
+
const common = (command) => command.requiredOption("--namespace <slug>", "DreamLake namespace")
|
|
63
|
+
.requiredOption("--project <slug>", "DreamLake project")
|
|
64
|
+
.option("--json", "emit structured errors (success is JSON)");
|
|
65
|
+
common(runs.command("list").description("list active native runs"))
|
|
66
|
+
.option("--limit <count>", "page size, 1-100")
|
|
67
|
+
.option("--cursor <id>", "nextCursor from the previous page")
|
|
68
|
+
.action(async (opts) => { process.exitCode = await runNativeExperiment("list", opts); });
|
|
69
|
+
common(runs.command("create").description("create an idempotent native run by key").argument("<key>"))
|
|
70
|
+
.action(async (subject, opts) => { process.exitCode = await runNativeExperiment("create", opts, subject); });
|
|
71
|
+
for (const action of ["archive", "restore"])
|
|
72
|
+
common(runs.command(action).description(`${action} a native run`).argument("<run-id>"))
|
|
73
|
+
.action(async (subject, opts) => { process.exitCode = await runNativeExperiment(action, opts, subject); });
|
|
74
|
+
common(runs.command("delete").description("move a terminal native run to trash").argument("<run-id>"))
|
|
75
|
+
.action(async (subject, opts) => { process.exitCode = await runNativeExperiment("delete", opts, subject); });
|
|
76
|
+
const trash = runs.command("trash").description("list and restore deleted native runs");
|
|
77
|
+
common(trash.command("list").description("list deleted native runs"))
|
|
78
|
+
.option("--limit <count>", "page size, 1-100")
|
|
79
|
+
.option("--cursor <id>", "nextCursor from the previous page")
|
|
80
|
+
.action(async (opts) => { process.exitCode = await runNativeExperiment("trash-list", opts); });
|
|
81
|
+
common(trash.command("restore").description("restore a deleted native run").argument("<run-id>"))
|
|
82
|
+
.action(async (subject, opts) => { process.exitCode = await runNativeExperiment("trash-restore", opts, subject); });
|
|
83
|
+
common(runs.command("log").description("append one log entry to a native run").argument("<run-id>").argument("<message>"))
|
|
84
|
+
.option("--level <level>", "info, warn, error, debug or fatal", "info")
|
|
85
|
+
.action(async (subject, message, opts) => {
|
|
86
|
+
process.exitCode = await runNativeExperiment("log", opts, subject, message);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -20,6 +20,14 @@ export const helpExamples = {
|
|
|
20
20
|
"nymph access grant": "dreamlake nymph access grant upload --name alice/computers/laptop\ndreamlake nymph access grant command-execution --name alice/computers/laptop",
|
|
21
21
|
"nymph access revoke": "dreamlake nymph access revoke upload --name alice/computers/laptop\ndreamlake nymph access revoke command-execution --name alice/computers/laptop",
|
|
22
22
|
"nymph restart": "dreamlake nymph restart --name alice/computers/laptop",
|
|
23
|
+
"experiments runs list": "dreamlake experiments runs list --namespace fortyfive --project research",
|
|
24
|
+
"experiments runs create": "dreamlake experiments runs create trial_1 --namespace fortyfive --project research",
|
|
25
|
+
"experiments runs log": "dreamlake experiments runs log \"$RUN_ID\" \"training started\" --level info --namespace fortyfive --project research",
|
|
26
|
+
"experiments runs archive": "dreamlake experiments runs archive \"$RUN_ID\" --namespace fortyfive --project research",
|
|
27
|
+
"experiments runs restore": "dreamlake experiments runs restore \"$RUN_ID\" --namespace fortyfive --project research",
|
|
28
|
+
"experiments runs delete": "dreamlake experiments runs delete \"$RUN_ID\" --namespace fortyfive --project research",
|
|
29
|
+
"experiments runs trash list": "dreamlake experiments runs trash list --namespace fortyfive --project research",
|
|
30
|
+
"experiments runs trash restore": "dreamlake experiments runs trash restore \"$RUN_ID\" --namespace fortyfive --project research",
|
|
23
31
|
"experiments workspaces": "dreamlake experiments workspaces --namespace fortyfive --json",
|
|
24
32
|
"experiments binding": "dreamlake experiments binding --namespace fortyfive --json",
|
|
25
33
|
"experiments connect": "dreamlake experiments connect research --namespace fortyfive --json\n# Apply only after reviewing the preview. Use its actual revision, not this example's 0.\ndreamlake experiments connect \"$DASH_NAMESPACE_ID\" --namespace fortyfive --instance-id \"$DASH_INSTANCE_ID\" --apply --expected-revision 0 --json",
|
|
@@ -159,7 +167,9 @@ export const helpExamples = {
|
|
|
159
167
|
"service-accounts bind": "dreamlake service-accounts bind my-team/0123456789abcdef01234567 --enrollment 444444444444444444444444",
|
|
160
168
|
"service-accounts revoke": "dreamlake service-accounts revoke my-team/0123456789abcdef01234567",
|
|
161
169
|
"sessions visibility": "dreamlake sessions visibility <saved-id> --namespace <personal-namespace> --visibility private",
|
|
162
|
-
"sessions register": "dreamlake sessions register --provider codex --session <native-uuid> --cwd /absolute/repository --json\n# Explicit private override for a new registration:\ndreamlake sessions register --provider claude --session <native-uuid> --cwd /absolute/repository --visibility private --json",
|
|
170
|
+
"sessions register": "dreamlake sessions register --provider codex --session <native-uuid> --cwd /absolute/repository --json\n# Explicit private override for a new registration:\ndreamlake sessions register --provider claude --session <native-uuid> --cwd /absolute/repository --visibility private --json\n# From inside a Claude Code session: register it, print the saved ID and the control send recipe,\n# and write an env file other shells can source so their note/artifact writes link to it:\ndreamlake sessions register --provider claude --session \"${CLAUDE_SESSION_ID:-$CLAUDE_CODE_SESSION_ID}\" --cwd \"$PWD\" --visibility private --write-env \"$HOME/.dreamlake/sessions/current.env\"",
|
|
171
|
+
"claude": "# Interactive Claude Code, registered private before it starts, acceptEdits (workspace-write):\ndreamlake claude\n# One headless turn at plan level; everything after the wrapper's flags goes to claude unchanged:\ndreamlake claude --permission read-only -p \"Summarize the open PRs\" --model opus",
|
|
172
|
+
"codex": "dreamlake codex --permission full-access \"Fix the failing test\"",
|
|
163
173
|
"sessions link": "dreamlake sessions link SESSION_ID --namespace geyang \\\n --resource-namespace fortyfive --note NOTE_ID --json\ndreamlake sessions link SESSION_ID --namespace geyang \\\n --resource-namespace fortyfive --artifact loss-plot --json",
|
|
164
174
|
"sessions unlink": "dreamlake sessions unlink SESSION_ID --namespace geyang \\\n --resource-namespace fortyfive --artifact loss-plot --json",
|
|
165
175
|
"sessions resources": "dreamlake sessions resources SESSION_ID --namespace geyang --page-size 25 --json",
|
|
@@ -176,22 +186,29 @@ export const helpExamples = {
|
|
|
176
186
|
"sessions stop": "dreamlake sessions stop SESSION_ID --namespace geyang --yes --json",
|
|
177
187
|
"sessions sync": "dreamlake sessions sync --namespace geyang --target TARGET_ID --json\ndreamlake sessions sync --namespace geyang --all --json",
|
|
178
188
|
"sessions upload-conversation": "dreamlake sessions upload-conversation SESSION_ID --namespace geyang \\\n --file /absolute/path/to/conversation.jsonl --json",
|
|
179
|
-
"sessions serve": "dreamlake sessions serve\n# Handle one command and exit (useful in scripts and tests):\ndreamlake sessions serve --once --json",
|
|
189
|
+
"sessions serve": "dreamlake sessions serve\n# Handle one command and exit (useful in scripts and tests):\ndreamlake sessions serve --once --json\n# Let a person raise sessions on this runner up to full access (control restart --raise):\ndreamlake sessions serve --max-human-permission full-access",
|
|
180
190
|
"sessions runners": "dreamlake sessions runners",
|
|
181
191
|
"sessions control start": "dreamlake sessions control start --provider claude --repo /abs/repo --isolation worktree --branch feat/x --permission workspace-write --prompt \"Run the tests and report\" --name \"Test runner\"\n# Reuse the checkout as is, headless:\ndreamlake sessions control start --provider codex --repo /abs/repo --isolation repo --permission read-only --mode headless --prompt \"Summarize open TODOs\"",
|
|
182
|
-
"sessions control send": "dreamlake sessions control send <session-id> \"Please rebase on main and rerun CI\"\n# A
|
|
192
|
+
"sessions control send": "dreamlake sessions control send <session-id> \"Please rebase on main and rerun CI\"\n# A turn under a lower ceiling than the recorded level, for this turn only:\ndreamlake sessions control send <session-id> \"Summarize your state\" --permission read-only\n# A session registered without a level (sessions register, dreamlake claude) is refused until one is recorded:\ndreamlake sessions control restart <session-id> --permission workspace-write --raise",
|
|
183
193
|
"sessions control broadcast": "dreamlake sessions control broadcast \"Stop and summarize your state\" --session <id-1> <id-2>",
|
|
184
194
|
"sessions control resume": "dreamlake sessions control resume <session-id> --prompt \"Continue\"",
|
|
195
|
+
"sessions control restart": "# Lower a session to read-only and continue the same conversation:\ndreamlake sessions control restart <session-id> --permission read-only\n# Raising is the person's explicit ask; the runner must have been started with --max-human-permission:\ndreamlake sessions control restart <session-id> --permission full-access --raise --reason \"needs to run the deploy\"",
|
|
196
|
+
"sessions permission": "dreamlake sessions permission <session-id> read-only --reason \"review only\"",
|
|
185
197
|
"sessions control stop": "dreamlake sessions control stop <session-id> --yes",
|
|
186
198
|
"sessions control status": "dreamlake sessions control status <session-id>\ndreamlake sessions control sync <session-id>\ndreamlake sessions control subagents <session-id>",
|
|
187
199
|
"sessions control list": "dreamlake sessions control list --session <session-id>\ndreamlake sessions control wait <command-id> --wait 120\ndreamlake sessions control cancel <command-id>",
|
|
200
|
+
"sessions heartbeat": "# From a Claude Code hook (settings.json): the hook JSON on stdin names the session and the tool.\ndreamlake sessions heartbeat --state running --hook-stdin\n# From a script or another relay, for an explicit saved session:\ndreamlake sessions heartbeat --session <session-id> --state waiting-for-user --tool Bash",
|
|
201
|
+
"sessions event": "dreamlake sessions event --kind SubagentStart --hook-stdin\ndreamlake sessions event --session <session-id> --kind SubagentStop --subagent agent-abc --finished --tokens 1200",
|
|
202
|
+
"sessions tree": "dreamlake sessions tree <session-id>",
|
|
203
|
+
"sessions watch": "# One session, readable lines:\ndreamlake sessions watch --session <session-id>\n# Everything in the namespace, one JSON frame per line:\ndreamlake sessions watch --json",
|
|
188
204
|
"sessions archive": "dreamlake sessions rename <session-id> \"Flaky test hunt\"\ndreamlake sessions archive <session-id>\ndreamlake sessions unarchive <session-id>",
|
|
189
205
|
"sessions chat": "dreamlake sessions chat \"Which of my sessions need attention?\"\n# Allow lifecycle and messaging tools this turn:\ndreamlake sessions chat --control \"Send 'rebase on main' to the two Claude sessions working on notes\"",
|
|
190
206
|
"sessions tool-calls": "dreamlake sessions tool-calls <conversation-id>",
|
|
191
207
|
"dreamlake": "# Guided agent setup: choose agent and scope, install dreamlake-cli offline\ndreamlake init\n# Install more skills from the public release\ndreamlake skill install dreamlake-notes\n# Keep installed skills current\ndreamlake skill update",
|
|
192
208
|
"init": "dreamlake init\ndreamlake init --agent codex\ndreamlake init --agent claude --global\n# Claude Code and Codex: one copy in each agent's directory\ndreamlake init --agent all --global",
|
|
193
|
-
"skill": "dreamlake skill list\ndreamlake skill install dreamlake-notes\ndreamlake skill update\ndreamlake skill remove dreamlake-notes",
|
|
194
|
-
"skill list": "
|
|
209
|
+
"skill": "dreamlake skill list\ndreamlake skill read dreamlake-notes\ndreamlake skill install dreamlake-notes\ndreamlake skill update\ndreamlake skill remove dreamlake-notes",
|
|
210
|
+
"skill list": "# The server's registry when logged in, else the embedded snapshot\ndreamlake skill list\n# Choose the source; --local never uses the network\ndreamlake skill list --local\ndreamlake skill list --remote\n# Fetch the latest catalog and show it next to the installed versions\ndreamlake skill list --refresh\ndreamlake skill list --agent codex --json",
|
|
211
|
+
"skill read": "# SKILL.md, from the server's registry when logged in, else the embedded bundle\ndreamlake skill read dreamlake-notes\n# One file inside the skill\ndreamlake skill read dreamlake-notes --file actions/read.md\n# Choose the source; --json carries the same fields as the agent's dreamlake_skills_read\ndreamlake skill read dreamlake-cli --local --json\ndreamlake skill read dreamlake-scenes --remote",
|
|
195
212
|
"skill install": "# The embedded dreamlake-cli skill; offline when it matches the release\ndreamlake skill install dreamlake-cli\n# A catalog skill plus whatever it requires, from the latest release\ndreamlake skill install dreamlake-notes --agent codex\n# One copy for Claude Code and one for Codex\ndreamlake skill install dreamlake-notes --agent all --global\n# Replace files you edited with the release copies\ndreamlake skill install dreamlake-notes --force",
|
|
196
213
|
"skill update": "# Every skill with a manifest in the selected scope\ndreamlake skill update\ndreamlake skill update dreamlake-cli --global\n# Overwrite edited files; retired files you edited are still kept\ndreamlake skill update dreamlake-notes --force\n# Go back to an older release, or replace a copy whose version cannot be ordered\ndreamlake skill update dreamlake-notes --allow-downgrade",
|
|
197
214
|
"skill remove": "dreamlake skill remove dreamlake-notes\ndreamlake skill remove dreamlake-notes --agent codex --global --json",
|
package/dist/cli/index.js
CHANGED
|
@@ -39,6 +39,7 @@ import { registerNotesCommand } from "./notes/index.js";
|
|
|
39
39
|
import { registerDeclareCommand } from "./declare/index.js";
|
|
40
40
|
import { registerHostsCommand } from "./hosts/index.js";
|
|
41
41
|
import { registerSessionsCommand } from "./sessions/index.js";
|
|
42
|
+
import { registerAgentWrappers } from "./sessions/wrap.js";
|
|
42
43
|
import { registerInfraCommand } from "./infra/index.js";
|
|
43
44
|
import { registerVaultCommand } from "./vault/index.js";
|
|
44
45
|
import { registerAgentsCommand } from "./agents/index.js";
|
|
@@ -228,6 +229,7 @@ async function main(argv) {
|
|
|
228
229
|
registerNymphCommand(program);
|
|
229
230
|
registerHostsCommand(program);
|
|
230
231
|
registerSessionsCommand(program);
|
|
232
|
+
registerAgentWrappers(program);
|
|
231
233
|
registerInfraCommand(program);
|
|
232
234
|
registerRunsCommands(program);
|
|
233
235
|
registerJobsCommand(program);
|
|
@@ -7,8 +7,9 @@ export function sessionContext(env = process.env) {
|
|
|
7
7
|
const id = env.DREAMLAKE_TERMINAL_SESSION_ID, ns = env.DREAMLAKE_SESSION_NAMESPACE;
|
|
8
8
|
if (id)
|
|
9
9
|
return id && ns && objectId.test(id) && namespace.test(ns) ? { saved: { id, namespace: ns } } : null;
|
|
10
|
-
// Never infer a native identity from arbitrary agent/presence labels.
|
|
11
|
-
|
|
10
|
+
// Never infer a native identity from arbitrary agent/presence labels. Claude Code exports
|
|
11
|
+
// CLAUDE_CODE_SESSION_ID to its subprocesses; an explicit CLAUDE_SESSION_ID wins when both are set.
|
|
12
|
+
const codex = env.CODEX_THREAD_ID, claude = env.CLAUDE_SESSION_ID || env.CLAUDE_CODE_SESSION_ID;
|
|
12
13
|
if (codex && claude)
|
|
13
14
|
return null;
|
|
14
15
|
if (codex && uuid.test(codex))
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
|
-
import { type ResourceSessionRef } from '../session-affiliation.js';
|
|
2
|
+
import { type ResourceSessionRef, type SavedSessionRef } from '../session-affiliation.js';
|
|
3
|
+
/** The saved-session context `sessionContext()` reads first: a shell that sources this file links its
|
|
4
|
+
* note and artifact writes to the session without any native id in its environment. The assignments are
|
|
5
|
+
* `export`ed, because a plain `KEY=value` line only sets a shell variable that the `dreamlake` child
|
|
6
|
+
* process never receives. Private (0600). */
|
|
7
|
+
export declare function writeSessionEnvFile(path: string, session: SavedSessionRef): string;
|
|
8
|
+
/** Where the `/dreamlake` skill and the SessionStart hook keep the env file of a native session, so a hook
|
|
9
|
+
* that only knows the native id (Claude Code hands it over on stdin) can find the saved session. */
|
|
10
|
+
export declare const sessionEnvFilePath: (nativeId: string, home?: string) => string;
|
|
11
|
+
/** Read back exactly what `writeSessionEnvFile` wrote: the two exported, single-quoted assignments. Anything
|
|
12
|
+
* else — another shape, a value that is not a saved id or namespace, a missing file — is `null`, never a guess. */
|
|
13
|
+
export declare function readSessionEnvFile(path: string): SavedSessionRef | null;
|
|
3
14
|
export declare function resourceFromOptions(opts: {
|
|
4
15
|
note?: string;
|
|
5
16
|
artifact?: string;
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
+
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
1
4
|
import { resolveHostNamespace } from '../hosts/inventory.js';
|
|
2
5
|
import { affiliationPath } from '../session-affiliation.js';
|
|
3
6
|
import { connection, requestJson, sessionPath } from './api.js';
|
|
7
|
+
/** POSIX single-quoting: safe for any value, and identical in sh, bash and zsh. */
|
|
8
|
+
const shellQuoted = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
9
|
+
/** The saved-session context `sessionContext()` reads first: a shell that sources this file links its
|
|
10
|
+
* note and artifact writes to the session without any native id in its environment. The assignments are
|
|
11
|
+
* `export`ed, because a plain `KEY=value` line only sets a shell variable that the `dreamlake` child
|
|
12
|
+
* process never receives. Private (0600). */
|
|
13
|
+
export function writeSessionEnvFile(path, session) {
|
|
14
|
+
if (!/^[a-f0-9]{24}$/.test(session.id) || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(session.namespace))
|
|
15
|
+
throw new Error('Use an exact saved session ID and namespace for the env file');
|
|
16
|
+
const target = resolve(path);
|
|
17
|
+
mkdirSync(dirname(target), { recursive: true, mode: 0o700 });
|
|
18
|
+
writeFileSync(target, `export DREAMLAKE_TERMINAL_SESSION_ID=${shellQuoted(session.id)}\nexport DREAMLAKE_SESSION_NAMESPACE=${shellQuoted(session.namespace)}\n`, { mode: 0o600 });
|
|
19
|
+
chmodSync(target, 0o600);
|
|
20
|
+
return target;
|
|
21
|
+
}
|
|
22
|
+
/** Where the `/dreamlake` skill and the SessionStart hook keep the env file of a native session, so a hook
|
|
23
|
+
* that only knows the native id (Claude Code hands it over on stdin) can find the saved session. */
|
|
24
|
+
export const sessionEnvFilePath = (nativeId, home = homedir()) => join(home, '.dreamlake', 'sessions', `${nativeId.toLowerCase()}.env`);
|
|
25
|
+
/** Read back exactly what `writeSessionEnvFile` wrote: the two exported, single-quoted assignments. Anything
|
|
26
|
+
* else — another shape, a value that is not a saved id or namespace, a missing file — is `null`, never a guess. */
|
|
27
|
+
export function readSessionEnvFile(path) {
|
|
28
|
+
let text;
|
|
29
|
+
try {
|
|
30
|
+
text = readFileSync(path, 'utf8');
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (text.length > 4096)
|
|
36
|
+
return null;
|
|
37
|
+
const read = (key) => { const m = text.match(new RegExp(`^export ${key}='([^'\n]*)'$`, 'm')); return m ? m[1] : null; };
|
|
38
|
+
const id = read('DREAMLAKE_TERMINAL_SESSION_ID'), namespace = read('DREAMLAKE_SESSION_NAMESPACE');
|
|
39
|
+
return id && namespace && /^[a-f0-9]{24}$/.test(id) && /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(namespace) ? { id, namespace } : null;
|
|
40
|
+
}
|
|
4
41
|
export function resourceFromOptions(opts) {
|
|
5
42
|
if (Boolean(opts.note) === Boolean(opts.artifact))
|
|
6
43
|
throw new Error('Choose exactly one --note NOTE_ID or --artifact ARTIFACT_ID');
|
|
@@ -3,4 +3,15 @@
|
|
|
3
3
|
* over the TypeScript API (`src/api`), so behaviour, permissions and error
|
|
4
4
|
* codes are identical in both. */
|
|
5
5
|
import type { Command } from 'commander';
|
|
6
|
+
import { type PermissionLevel, type SessionsApi } from '../../api/index.js';
|
|
7
|
+
/** The raise rule, applied before anything is submitted. The server cannot tell a token holder from a
|
|
8
|
+
* person, so a raise carries `raise: true` only when a person asked: `--raise` on the command line AND a
|
|
9
|
+
* confirmation typed on a terminal. Without a terminal nobody can be asked, so a raise is refused: a script
|
|
10
|
+
* or an agent holding the token must not be able to widen a session on its own. Lowering or keeping the
|
|
11
|
+
* level sends no flag. */
|
|
12
|
+
export declare function raiseConfirmation(api: Pick<SessionsApi, 'get'>, sessionId: string, level: PermissionLevel, opts: {
|
|
13
|
+
raise?: boolean;
|
|
14
|
+
}, ask?: (message: string) => Promise<boolean>, interactive?: boolean): Promise<{
|
|
15
|
+
raise?: true;
|
|
16
|
+
}>;
|
|
6
17
|
export declare function registerSessionControl(group: Command): void;
|