@moondeck/station 1.0.7 → 1.0.9
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/images/standard/Dockerfile +3 -1
- package/images/standard/container/uai-init +66 -9
- package/lib/initial-attachment-command.ts +22 -0
- package/lib/initial-attachments.ts +71 -0
- package/lib/task-environment/machine-task-up.ts +81 -0
- package/lib/task-environment/workspace-files.ts +68 -0
- package/package.json +9 -1
- package/src/engine-models.ts +5 -3
- package/src/index.ts +12 -0
- package/src/initial-attachments.ts +74 -0
- package/src/main.ts +5 -0
- package/src/protocol.ts +3 -0
|
@@ -34,6 +34,7 @@ ENV MISE_VERSION=2026.11.1
|
|
|
34
34
|
|
|
35
35
|
# Qualified agent builds. These are execution-contract pins: per-command env
|
|
36
36
|
# freshness is requalified before any of them moves.
|
|
37
|
+
ENV UAI_CLAUDE_CODE_VERSION=2.1.322
|
|
37
38
|
ENV UAI_CODEX_CLI_VERSION=0.164.0
|
|
38
39
|
ENV UAI_CURSOR_AGENT_VERSION=2026.10.22-27dcf5f
|
|
39
40
|
ENV UAI_GROK_CLI_VERSION=1.0.70
|
|
@@ -277,7 +278,7 @@ RUN bash -lc '\
|
|
|
277
278
|
. /opt/asdf/asdf.sh; \
|
|
278
279
|
COREPACK_VERSION="$(sed -n "1p" /usr/local/share/uai/corepack-version)"; \
|
|
279
280
|
printf "%s" "$COREPACK_VERSION" | grep -Eq "^[0-9]+\\.[0-9]+\\.[0-9]+$"; \
|
|
280
|
-
npm install -g @anthropic-ai/claude-code "@openai/codex@$UAI_CODEX_CLI_VERSION" "corepack@$COREPACK_VERSION" \
|
|
281
|
+
npm install -g "@anthropic-ai/claude-code@$UAI_CLAUDE_CODE_VERSION" "@openai/codex@$UAI_CODEX_CLI_VERSION" "corepack@$COREPACK_VERSION" \
|
|
281
282
|
--registry=https://registry.npmjs.org/ \
|
|
282
283
|
--userconfig=/dev/null \
|
|
283
284
|
--globalconfig=/dev/uai-empty-npmrc; \
|
|
@@ -285,6 +286,7 @@ RUN bash -lc '\
|
|
|
285
286
|
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method standalone --prefix /home/node/.local; \
|
|
286
287
|
asdf reshim nodejs; \
|
|
287
288
|
test "$(codex --version)" = "codex-cli $UAI_CODEX_CLI_VERSION"; \
|
|
289
|
+
test "$(claude --version)" = "$UAI_CLAUDE_CODE_VERSION (Claude Code)"; \
|
|
288
290
|
'
|
|
289
291
|
|
|
290
292
|
# Optional agent CLIs — installed ONLY when the host has them configured
|
|
@@ -371,16 +371,73 @@ if [ -f "$HOME/.ssh/id_ed25519.pub" ]; then
|
|
|
371
371
|
/usr/bin/git config --global tag.gpgsign true
|
|
372
372
|
fi
|
|
373
373
|
|
|
374
|
-
# Attribution policy: never co-author with the agents. Claude Code
|
|
375
|
-
# `
|
|
376
|
-
#
|
|
377
|
-
#
|
|
374
|
+
# Attribution policy: never co-author with the agents. Claude Code 2.x reads
|
|
375
|
+
# `attribution` ({commit,pr}: "" hides that attribution; sessionUrl: false drops
|
|
376
|
+
# the session link); older CLIs read the deprecated `includeCoAuthoredBy: false`.
|
|
377
|
+
# Both are MERGED into the user settings on every run: another writer (credential
|
|
378
|
+
# materialization, an image layer, a previous run) may have created the file
|
|
379
|
+
# first, and every other key in it is left exactly as found. Only a MISSING file
|
|
380
|
+
# is created. An existing file is left byte-for-byte alone (with a warning) when
|
|
381
|
+
# it is a symlink, not a regular file, or not exactly one JSON object (empty,
|
|
382
|
+
# whitespace-only and several concatenated documents all count as invalid).
|
|
383
|
+
# The result is written to an unpredictable, exclusively created (mktemp, 0600)
|
|
384
|
+
# sibling and renamed into place, so a pre-placed symlink cannot redirect the
|
|
385
|
+
# write, the file never gets a wider mode than it had (it may hold credentials
|
|
386
|
+
# in `env`), and the temp file is removed on every path. Codex is covered by the
|
|
378
387
|
# orchestrator's system preamble.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
388
|
+
cc_dir="$HOME/.claude"
|
|
389
|
+
cc_settings="$cc_dir/settings.json"
|
|
390
|
+
cc_tmp=""
|
|
391
|
+
cc_skip() { log "warning: leaving $cc_settings untouched: $1"; }
|
|
392
|
+
cc_merge() {
|
|
393
|
+
jq -s '
|
|
394
|
+
if length == 1 and (.[0] | type) == "object" then .[0]
|
|
395
|
+
else error("not exactly one JSON object") end
|
|
396
|
+
| .includeCoAuthoredBy = false
|
|
397
|
+
| .attribution = (
|
|
398
|
+
(if (.attribution | type) == "object" then .attribution else {} end)
|
|
399
|
+
+ {commit: "", pr: "", sessionUrl: false}
|
|
400
|
+
)'
|
|
401
|
+
}
|
|
402
|
+
mkdir -p "$cc_dir" 2>/dev/null || true
|
|
403
|
+
if [ -L "$cc_settings" ]; then
|
|
404
|
+
cc_skip "it is a symlink"
|
|
405
|
+
elif [ -e "$cc_settings" ] && [ ! -f "$cc_settings" ]; then
|
|
406
|
+
cc_skip "it is not a regular file"
|
|
407
|
+
else
|
|
408
|
+
cc_tmp="$(umask 077; mktemp "$cc_dir/settings.json.XXXXXX" 2>/dev/null)" || cc_tmp=""
|
|
409
|
+
if [ -z "$cc_tmp" ]; then
|
|
410
|
+
cc_skip "could not create a temporary file in $cc_dir"
|
|
411
|
+
elif [ -e "$cc_settings" ]; then
|
|
412
|
+
if cc_merge < "$cc_settings" > "$cc_tmp" 2>/dev/null; then
|
|
413
|
+
if cmp -s "$cc_tmp" "$cc_settings"; then
|
|
414
|
+
:
|
|
415
|
+
else
|
|
416
|
+
# Same mode as the file being replaced (the temp file is 0600); never wider.
|
|
417
|
+
# If the mode cannot be copied, do not replace: the 0600 temp file would
|
|
418
|
+
# change the original's mode.
|
|
419
|
+
if ! chmod --reference="$cc_settings" "$cc_tmp" 2>/dev/null; then
|
|
420
|
+
cc_skip "could not copy its mode to the replacement"
|
|
421
|
+
elif mv -f "$cc_tmp" "$cc_settings" 2>/dev/null; then
|
|
422
|
+
cc_tmp=""
|
|
423
|
+
log "ensured ~/.claude/settings.json attribution policy (no co-author trailers)"
|
|
424
|
+
else
|
|
425
|
+
cc_skip "could not replace it"
|
|
426
|
+
fi
|
|
427
|
+
fi
|
|
428
|
+
else
|
|
429
|
+
cc_skip "not exactly one JSON object (or unreadable)"
|
|
430
|
+
fi
|
|
431
|
+
else
|
|
432
|
+
# Missing: create it, never replacing a file that appears meanwhile (ln fails if it exists).
|
|
433
|
+
if printf '{}' | cc_merge > "$cc_tmp" 2>/dev/null \
|
|
434
|
+
&& ln "$cc_tmp" "$cc_settings" 2>/dev/null; then
|
|
435
|
+
log "seeded ~/.claude/settings.json (no co-author trailers)"
|
|
436
|
+
else
|
|
437
|
+
cc_skip "could not create it"
|
|
438
|
+
fi
|
|
439
|
+
fi
|
|
440
|
+
[ -z "$cc_tmp" ] || rm -f -- "$cc_tmp"
|
|
384
441
|
fi
|
|
385
442
|
fi
|
|
386
443
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { parseInitialAttachmentInput } from "../src/initial-attachments";
|
|
2
|
+
import { abortInitialAttachment, receiveInitialAttachment, type InitialAttachmentEnvironment } from "./initial-attachments";
|
|
3
|
+
|
|
4
|
+
/** The production command gate, shared with its boundary tests. */
|
|
5
|
+
export async function handleInitialAttachmentCommand(
|
|
6
|
+
value: unknown,
|
|
7
|
+
dependencies: {
|
|
8
|
+
runTaskLifecycle<T>(taskId: string, work: () => Promise<T>): Promise<T>;
|
|
9
|
+
getTask(taskId: string): { runEpoch?: number; statusMirror: string | null } | null | undefined;
|
|
10
|
+
environment(taskId: string): Promise<InitialAttachmentEnvironment | null>;
|
|
11
|
+
},
|
|
12
|
+
): Promise<{ exists: boolean } | undefined> {
|
|
13
|
+
const input = parseInitialAttachmentInput(value);
|
|
14
|
+
return dependencies.runTaskLifecycle(input.taskId, async () => {
|
|
15
|
+
if (input.operation === "abort") { await abortInitialAttachment(input); return; }
|
|
16
|
+
const task = dependencies.getTask(input.taskId);
|
|
17
|
+
if (!task || task.runEpoch !== input.runEpoch || task.statusMirror !== "running") throw new Error("Initial attachment runtime changed; retry startup");
|
|
18
|
+
const environment = await dependencies.environment(input.taskId);
|
|
19
|
+
if (!environment) throw new Error("Initial attachments require an available task environment");
|
|
20
|
+
return receiveInitialAttachment(input, environment);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** Chunked cloud bytes, staged outside the workspace, published before launch. */
|
|
2
|
+
import { mkdtemp, open, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { parseInitialAttachmentInput, initialAttachmentParts, type InitialAttachmentWriteInput } from "../src/initial-attachments";
|
|
6
|
+
import type { TaskEnvironmentHandle } from "./task-environment/types";
|
|
7
|
+
import { writeContainedRuntimeFile } from "./task-environment/workspace-files";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
interface Transfer { runEpoch: number; taskId: string; path: string; size: number; offset: number; directory: string; timer: NodeJS.Timeout; busy: boolean; preserveExisting: boolean }
|
|
11
|
+
const transfers = new Map<string, Transfer>();
|
|
12
|
+
const receiving = new Set<string>();
|
|
13
|
+
async function discard(id: string, transfer: Transfer): Promise<void> {
|
|
14
|
+
clearTimeout(transfer.timer);
|
|
15
|
+
transfers.delete(id);
|
|
16
|
+
await rm(transfer.directory, { recursive: true, force: true });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Cleanup is safe even after teardown/epoch change: it touches only the
|
|
20
|
+
* staging transfer bound to this exact task and run, never the workspace. */
|
|
21
|
+
export async function abortInitialAttachment(input: InitialAttachmentWriteInput): Promise<void> {
|
|
22
|
+
parseInitialAttachmentInput(input);
|
|
23
|
+
const current = transfers.get(input.transferId);
|
|
24
|
+
if (current && current.taskId === input.taskId && current.runEpoch === input.runEpoch && !current.busy) await discard(input.transferId, current);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type InitialAttachmentEnvironment = Pick<TaskEnvironmentHandle, "exec" | "descriptor">;
|
|
28
|
+
|
|
29
|
+
export async function receiveInitialAttachment(input: InitialAttachmentWriteInput, environment: InitialAttachmentEnvironment): Promise<{ exists: boolean } | undefined> {
|
|
30
|
+
parseInitialAttachmentInput(input);
|
|
31
|
+
const parts = initialAttachmentParts(input.path);
|
|
32
|
+
if (input.operation === "probe") return { exists: await writeContainedRuntimeFile(environment, parts, new Uint8Array(), "probe") };
|
|
33
|
+
if (input.operation === "abort") { await abortInitialAttachment(input); return; }
|
|
34
|
+
const bytes = Buffer.from(input.dataBase64, "base64");
|
|
35
|
+
if (bytes.toString("base64") !== input.dataBase64 || input.offset + bytes.length > input.size || (bytes.length === 0 && input.size !== 0)) throw new Error("Invalid initial attachment chunk");
|
|
36
|
+
if (receiving.has(input.transferId)) throw new Error("Initial attachment transfer is busy");
|
|
37
|
+
receiving.add(input.transferId);
|
|
38
|
+
try {
|
|
39
|
+
let transfer = transfers.get(input.transferId);
|
|
40
|
+
if (!transfer) {
|
|
41
|
+
if (input.offset !== 0 || transfers.size >= 8) throw new Error("Initial attachment transfer unavailable; retry startup");
|
|
42
|
+
const directory = await mkdtemp(join(tmpdir(), "moondeck-initial-"));
|
|
43
|
+
const timer = setTimeout(() => { const current = transfers.get(input.transferId); if (current && !current.busy) void discard(input.transferId, current).catch((error) => console.error("Initial attachment staging cleanup failed", error)); }, 10 * 60_000);
|
|
44
|
+
timer.unref();
|
|
45
|
+
transfer = { runEpoch: input.runEpoch, taskId: input.taskId, path: input.path, size: input.size, offset: 0, directory, timer, busy: false, preserveExisting: input.preserveExisting === true };
|
|
46
|
+
transfers.set(input.transferId, transfer);
|
|
47
|
+
}
|
|
48
|
+
if (transfer.runEpoch !== input.runEpoch || transfer.busy || transfer.taskId !== input.taskId || transfer.path !== input.path || transfer.size !== input.size || transfer.offset !== input.offset || transfer.preserveExisting !== (input.preserveExisting === true)) {
|
|
49
|
+
// A foreign task/run must not cancel another transfer. A bad repeat from
|
|
50
|
+
// the same owner is terminal and should release the staging slot now.
|
|
51
|
+
if (transfer.taskId === input.taskId && transfer.runEpoch === input.runEpoch && !transfer.busy) await discard(input.transferId, transfer);
|
|
52
|
+
throw new Error("Initial attachment transfer does not match");
|
|
53
|
+
}
|
|
54
|
+
transfer.busy = true;
|
|
55
|
+
try {
|
|
56
|
+
const staged = join(transfer.directory, "bytes");
|
|
57
|
+
const file = await open(staged, input.offset === 0 ? "wx" : "a", 0o600);
|
|
58
|
+
try { await file.writeFile(bytes); } finally { await file.close(); }
|
|
59
|
+
transfer.offset += bytes.length;
|
|
60
|
+
if (transfer.offset === transfer.size) {
|
|
61
|
+
const content = await readFile(staged);
|
|
62
|
+
if (content.length !== transfer.size) throw new Error("Incomplete initial attachment");
|
|
63
|
+
await writeContainedRuntimeFile(environment, parts, content, transfer.preserveExisting ? "preserve" : "replace");
|
|
64
|
+
await discard(input.transferId, transfer);
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
await discard(input.transferId, transfer);
|
|
68
|
+
throw error;
|
|
69
|
+
} finally { transfer.busy = false; if (transfers.has(input.transferId)) transfer.timer.refresh(); }
|
|
70
|
+
} finally { receiving.delete(input.transferId); }
|
|
71
|
+
}
|
|
@@ -602,6 +602,75 @@ async function seedEditorSettings(
|
|
|
602
602
|
});
|
|
603
603
|
}
|
|
604
604
|
|
|
605
|
+
/** Merge the no-co-author attribution policy into the machine's Claude user
|
|
606
|
+
* settings (machines do not run uai-init, which does the same for containers;
|
|
607
|
+
* keep the two in step). Only a MISSING file is created. An existing file is
|
|
608
|
+
* left byte-for-byte alone (exit 3, reason on stderr) when it is a symlink, not
|
|
609
|
+
* a regular file, or not exactly one JSON object (empty, whitespace-only and
|
|
610
|
+
* concatenated documents are all invalid). The result goes to an
|
|
611
|
+
* unpredictable, exclusively created (mode 0600) sibling and is renamed into
|
|
612
|
+
* place, so a pre-placed symlink cannot redirect the write, the file keeps its
|
|
613
|
+
* existing mode (it may hold credentials in env; never widened), and the temp
|
|
614
|
+
* file is removed on every path. */
|
|
615
|
+
const CLAUDE_ATTRIBUTION_MERGE_JS = `
|
|
616
|
+
const fs = require("fs"), path = require("path"), crypto = require("crypto");
|
|
617
|
+
const p = process.argv[1];
|
|
618
|
+
const dir = path.dirname(p);
|
|
619
|
+
const untouched = (why) => { console.error("leaving " + p + " untouched: " + why); process.exit(3); };
|
|
620
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
621
|
+
let st = null;
|
|
622
|
+
try { st = fs.lstatSync(p); } catch (e) { if (e.code !== "ENOENT") untouched(String(e.code)); }
|
|
623
|
+
if (st && st.isSymbolicLink()) untouched("it is a symlink");
|
|
624
|
+
if (st && !st.isFile()) untouched("it is not a regular file");
|
|
625
|
+
let s = {}, original = null;
|
|
626
|
+
if (st) {
|
|
627
|
+
try { original = fs.readFileSync(p, "utf8"); } catch (e) { untouched("unreadable"); }
|
|
628
|
+
try { s = JSON.parse(original); } catch (e) { untouched("not exactly one JSON object"); }
|
|
629
|
+
if (!s || typeof s !== "object" || Array.isArray(s)) untouched("not a JSON object");
|
|
630
|
+
}
|
|
631
|
+
s.includeCoAuthoredBy = false;
|
|
632
|
+
const a = s.attribution && typeof s.attribution === "object" && !Array.isArray(s.attribution) ? s.attribution : {};
|
|
633
|
+
s.attribution = { ...a, commit: "", pr: "", sessionUrl: false };
|
|
634
|
+
const out = JSON.stringify(s, null, 2) + "\\n";
|
|
635
|
+
if (out === original) process.exit(0);
|
|
636
|
+
const tmp = path.join(dir, "settings.json." + crypto.randomBytes(8).toString("hex") + ".tmp");
|
|
637
|
+
let fd = null, failed = null;
|
|
638
|
+
try {
|
|
639
|
+
fd = fs.openSync(tmp, "wx", 0o600);
|
|
640
|
+
fs.writeFileSync(fd, out);
|
|
641
|
+
fs.fchmodSync(fd, st ? st.mode & 0o777 : 0o600);
|
|
642
|
+
fs.closeSync(fd); fd = null;
|
|
643
|
+
if (st) fs.renameSync(tmp, p); else fs.linkSync(tmp, p);
|
|
644
|
+
} catch (e) {
|
|
645
|
+
failed = e;
|
|
646
|
+
} finally {
|
|
647
|
+
if (fd !== null) { try { fs.closeSync(fd); } catch (e) {} }
|
|
648
|
+
try { fs.unlinkSync(tmp); } catch (e) {}
|
|
649
|
+
}
|
|
650
|
+
if (failed) untouched(String(failed.code || failed.message));
|
|
651
|
+
`;
|
|
652
|
+
|
|
653
|
+
export async function ensureClaudeAttributionPolicy(
|
|
654
|
+
handle: TaskEnvironmentHandle<unknown>,
|
|
655
|
+
): Promise<void> {
|
|
656
|
+
const result = await handle.exec({
|
|
657
|
+
argv: [
|
|
658
|
+
"node",
|
|
659
|
+
"-e",
|
|
660
|
+
CLAUDE_ATTRIBUTION_MERGE_JS,
|
|
661
|
+
"/home/node/.claude/settings.json",
|
|
662
|
+
],
|
|
663
|
+
projectEnvProfile: "maintenance",
|
|
664
|
+
timeoutMs: GIT_STEP_TIMEOUT_MS,
|
|
665
|
+
maxOutputBytes: STEP_OUTPUT_BYTES,
|
|
666
|
+
});
|
|
667
|
+
if (result.exitCode !== 0) {
|
|
668
|
+
throw new Error(
|
|
669
|
+
`claude attribution merge exited ${result.exitCode}: ${Buffer.from(result.stderr).toString("utf8").trim()}`,
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
605
674
|
const execFileAsync = promisify(execFile);
|
|
606
675
|
/** Shared-files snapshots are reference docs, not repos; a tree past this
|
|
607
676
|
* is skipped with a warning rather than ballooning host memory. */
|
|
@@ -1204,6 +1273,18 @@ export function createMachineHostTaskEnvironmentProvider(
|
|
|
1204
1273
|
}
|
|
1205
1274
|
}
|
|
1206
1275
|
|
|
1276
|
+
// Attribution policy (no Claude co-author trailers) — uai-init does
|
|
1277
|
+
// this for containers; machines never run it. Best-effort.
|
|
1278
|
+
await stage(
|
|
1279
|
+
ensureClaudeAttributionPolicy(own).catch((error: unknown) => {
|
|
1280
|
+
console.warn(
|
|
1281
|
+
`[machine] task ${request.taskId}: claude attribution policy failed: ${
|
|
1282
|
+
error instanceof Error ? error.message : String(error)
|
|
1283
|
+
}`,
|
|
1284
|
+
);
|
|
1285
|
+
}),
|
|
1286
|
+
);
|
|
1287
|
+
|
|
1207
1288
|
// Editor pane: code-server on the machine (same flags as uai-init's
|
|
1208
1289
|
// container launch), idempotent across provision re-runs and resume.
|
|
1209
1290
|
// Best-effort — a missing binary degrades the Editor tab, never the task.
|
|
@@ -683,3 +683,71 @@ export function hostWorkspaceWrite(
|
|
|
683
683
|
): Promise<void> {
|
|
684
684
|
return writeContainedFile(hostWorkspaceRoot, workspacePathParts(descriptor, path), bytes);
|
|
685
685
|
}
|
|
686
|
+
|
|
687
|
+
// Runs as the task user inside its Linux runtime. Pin every directory; refuse
|
|
688
|
+
// links and special files. Rename a new inode instead of truncating a hardlink.
|
|
689
|
+
// No shell interpolation, cloud URL, credential, or task-supplied code.
|
|
690
|
+
const ATOMIC_WORKSPACE_WRITER = String.raw`
|
|
691
|
+
(() => {
|
|
692
|
+
const fs = require('node:fs');
|
|
693
|
+
const [root, path, mode] = process.argv.slice(1);
|
|
694
|
+
const parts = JSON.parse(path);
|
|
695
|
+
const C = fs.constants;
|
|
696
|
+
let dir = fs.openSync(root, C.O_RDONLY | C.O_DIRECTORY | C.O_NOFOLLOW);
|
|
697
|
+
let pending;
|
|
698
|
+
try {
|
|
699
|
+
for (const part of parts.slice(0, -1)) {
|
|
700
|
+
const at = '/proc/self/fd/' + dir + '/' + part;
|
|
701
|
+
if (mode !== 'probe') { try { fs.mkdirSync(at); } catch (e) { if (e.code !== 'EEXIST') throw e; } }
|
|
702
|
+
const next = fs.openSync(at, C.O_RDONLY | C.O_DIRECTORY | C.O_NOFOLLOW);
|
|
703
|
+
fs.closeSync(dir); dir = next;
|
|
704
|
+
}
|
|
705
|
+
const target = '/proc/self/fd/' + dir + '/' + parts.at(-1);
|
|
706
|
+
let exists = false;
|
|
707
|
+
const inspect = () => { const st = fs.lstatSync(target); if (!st.isFile() || st.nlink !== 1) throw Error('unsafe attachment target'); };
|
|
708
|
+
try { inspect(); exists = true; }
|
|
709
|
+
catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
710
|
+
if (mode === 'probe') { process.stdout.write(exists ? 'present' : 'missing'); return; }
|
|
711
|
+
if (mode === 'preserve' && exists) { fs.readFileSync(0); return; }
|
|
712
|
+
pending = '/proc/self/fd/' + dir + '/.initial-' + require('node:crypto').randomUUID();
|
|
713
|
+
const fd = fs.openSync(pending, C.O_WRONLY | C.O_CREAT | C.O_EXCL | C.O_NOFOLLOW, 0o644);
|
|
714
|
+
try { fs.writeFileSync(fd, fs.readFileSync(0)); } finally { fs.closeSync(fd); }
|
|
715
|
+
if (mode === 'preserve') {
|
|
716
|
+
try { fs.linkSync(pending, target); } catch (e) { if (e.code !== 'EEXIST') throw e; inspect(); }
|
|
717
|
+
fs.unlinkSync(pending);
|
|
718
|
+
} else fs.renameSync(pending, target);
|
|
719
|
+
pending = undefined;
|
|
720
|
+
} catch (e) {
|
|
721
|
+
if (mode === 'probe' && e.code === 'ENOENT') process.stdout.write('missing');
|
|
722
|
+
else throw e;
|
|
723
|
+
} finally {
|
|
724
|
+
if (pending) fs.unlinkSync(pending);
|
|
725
|
+
fs.closeSync(dir);
|
|
726
|
+
}
|
|
727
|
+
})();
|
|
728
|
+
`;
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
/** Atomically publish bytes through the task user in its Linux runtime.
|
|
732
|
+
* Unlike a shell redirect, this refuses symlink components and hardlinks;
|
|
733
|
+
* unlike host-side mkdir, it is also contained on macOS-hosted providers. */
|
|
734
|
+
export async function writeContainedRuntimeFile(
|
|
735
|
+
environment: Pick<TaskEnvironmentHandle, "exec" | "descriptor">,
|
|
736
|
+
parts: readonly string[],
|
|
737
|
+
bytes: Uint8Array,
|
|
738
|
+
mode: "replace" | "preserve" | "probe" = "replace",
|
|
739
|
+
): Promise<boolean> {
|
|
740
|
+
checkedParts(parts);
|
|
741
|
+
const result = await environment.exec({
|
|
742
|
+
argv: ["node", "-e", ATOMIC_WORKSPACE_WRITER, environment.descriptor.workspacePath, JSON.stringify(parts), mode],
|
|
743
|
+
projectEnvProfile: "maintenance",
|
|
744
|
+
stdin: bytes,
|
|
745
|
+
timeoutMs: 120_000,
|
|
746
|
+
maxOutputBytes: 4096,
|
|
747
|
+
});
|
|
748
|
+
if (result.exitCode !== 0) throw new Error(`Could not safely write a workspace file: ${Buffer.from(result.stderr).toString("utf8")}`);
|
|
749
|
+
if (mode !== "probe") return true;
|
|
750
|
+
const status = Buffer.from(result.stdout).toString("utf8");
|
|
751
|
+
if (status !== "present" && status !== "missing") throw new Error("Invalid workspace probe response");
|
|
752
|
+
return status === "present";
|
|
753
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moondeck/station",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Moondeck Station: runs Moondeck tasks in containers on a machine you control.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Moondeck <team@moondeck.io>",
|
|
@@ -104,6 +104,14 @@
|
|
|
104
104
|
"./never-proxied-domains": {
|
|
105
105
|
"types": "./src/never-proxied-domains.ts",
|
|
106
106
|
"default": "./src/never-proxied-domains.ts"
|
|
107
|
+
},
|
|
108
|
+
"./initial-attachments": {
|
|
109
|
+
"types": "./src/initial-attachments.ts",
|
|
110
|
+
"default": "./src/initial-attachments.ts"
|
|
111
|
+
},
|
|
112
|
+
"./initial-attachment-materialization": {
|
|
113
|
+
"types": "./lib/initial-attachments.ts",
|
|
114
|
+
"default": "./lib/initial-attachments.ts"
|
|
107
115
|
}
|
|
108
116
|
},
|
|
109
117
|
"scripts": {
|
package/src/engine-models.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* here has no guide entry. Pure data: no runtime imports.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// Claude Code's aliases, which follow its own model table
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// Claude Code's aliases, which follow its own model table: fable = Claude
|
|
9
|
+
// Fable 5.2 as of Claude Code 2.1.321 (the images pin 2.1.322 via
|
|
10
|
+
// UAI_CLAUDE_CODE_VERSION; read 2026-11-10), opus = Opus 5.5, sonnet = Sonnet
|
|
11
|
+
// 5.5, haiku = Haiku 5.5. The CLI version decides which model an alias runs,
|
|
12
|
+
// so update this list and the pin together.
|
|
11
13
|
export const CLAUDE_MODELS: readonly string[] = ["fable", "opus", "sonnet", "haiku"];
|
|
12
14
|
|
|
13
15
|
// Codex model slugs accepted via `-c model=<slug>`. Keep the newest version of
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
prepareTaskGithubGitCredential,
|
|
55
55
|
type TaskGithubGitCredential,
|
|
56
56
|
} from "../lib/github-git-auth";
|
|
57
|
+
import { handleInitialAttachmentCommand } from "../lib/initial-attachment-command";
|
|
57
58
|
import { readAttachment, writeAttachment } from "../lib/attachments";
|
|
58
59
|
import { readFileSync } from "node:fs";
|
|
59
60
|
import { resolve } from "node:path";
|
|
@@ -2334,6 +2335,17 @@ export const hostCommands: HostCommands = {
|
|
|
2334
2335
|
}
|
|
2335
2336
|
},
|
|
2336
2337
|
|
|
2338
|
+
async initialAttachmentWrite(ctx, input) {
|
|
2339
|
+
logCommand(ctx, "initialAttachmentWrite", input.taskId, input.operation ?? "write");
|
|
2340
|
+
try {
|
|
2341
|
+
return ok(await handleInitialAttachmentCommand(input, {
|
|
2342
|
+
runTaskLifecycle: (taskId, work) => getOrchestrator().runTaskLifecycle(taskId, work),
|
|
2343
|
+
getTask: getHostTask,
|
|
2344
|
+
environment: reconstructHostTaskEnvironment,
|
|
2345
|
+
}));
|
|
2346
|
+
} catch (error) { return failFromUnknown(error); }
|
|
2347
|
+
},
|
|
2348
|
+
|
|
2337
2349
|
async attachmentWrite(ctx, input) {
|
|
2338
2350
|
logCommand(ctx, "attachmentWrite", input.taskId, input.filename);
|
|
2339
2351
|
try {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Only explicit personal brief-upload references are startup inputs. */
|
|
2
|
+
export const INITIAL_ATTACHMENT_CHUNK = 3 * 1024 * 1024;
|
|
3
|
+
export const INITIAL_ATTACHMENT_MAX = 200 * 1024 * 1024;
|
|
4
|
+
export const INITIAL_ATTACHMENT_FEATURE = "initial-attachments-v1";
|
|
5
|
+
const PREFIX = "/workspace/files/me/";
|
|
6
|
+
|
|
7
|
+
export function initialAttachmentParts(path: string): string[] {
|
|
8
|
+
if (!path.startsWith(PREFIX)) throw new Error("Invalid initial attachment path");
|
|
9
|
+
const parts = path.slice(PREFIX.length).split("/");
|
|
10
|
+
if (parts.length !== 3 || parts[0] !== "task-uploads" ||
|
|
11
|
+
!/^[a-z0-9][a-z0-9-]{0,99}$/.test(parts[1]!) ||
|
|
12
|
+
!/^[A-Za-z0-9._-]+$/.test(parts[2]!) || [".", ".."].includes(parts[2]!)) {
|
|
13
|
+
throw new Error("Invalid initial attachment path");
|
|
14
|
+
}
|
|
15
|
+
return ["files", "me", ...parts];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function initialAttachmentPaths(texts: readonly (string | null | undefined)[]): string[] {
|
|
19
|
+
const paths = new Set<string>();
|
|
20
|
+
for (const text of texts) {
|
|
21
|
+
// Chat treats fenced/inline code and escaped delimiters as literal text.
|
|
22
|
+
// Explicit references elsewhere (including within prose) are attachments.
|
|
23
|
+
let fenced = false;
|
|
24
|
+
const visible: string[] = [];
|
|
25
|
+
for (const line of (text ?? "").split("\n")) {
|
|
26
|
+
if (fenced && /^\s*```+\s*$/.test(line)) { fenced = false; continue; }
|
|
27
|
+
if (!fenced && /^\s*```+/.test(line)) { fenced = true; continue; }
|
|
28
|
+
if (fenced) continue;
|
|
29
|
+
visible.push(line);
|
|
30
|
+
}
|
|
31
|
+
const rendered = visible.join("\n").replace(/\\[\\`*_{}[\]()#+\-.!~>|]/g, " ").replace(/`[^`]+`/g, " ");
|
|
32
|
+
const refs = /\[image:\s*([^\]\r\n]+)\]|\[[^\]\r\n]+\]\(([^)\s]+)\)/g;
|
|
33
|
+
for (const match of rendered.matchAll(refs)) {
|
|
34
|
+
const path = (match[1] ?? match[2])!.trim();
|
|
35
|
+
// Other personal links are ordinary chat references, not brief uploads.
|
|
36
|
+
// A malformed reference inside the upload namespace still fails closed.
|
|
37
|
+
if (path !== `${PREFIX}task-uploads` && !path.startsWith(`${PREFIX}task-uploads/`)) continue;
|
|
38
|
+
initialAttachmentParts(path);
|
|
39
|
+
paths.add(path);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return [...paths];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface InitialAttachmentWriteInput {
|
|
46
|
+
operation?: "probe" | "abort";
|
|
47
|
+
preserveExisting?: boolean;
|
|
48
|
+
taskId: string;
|
|
49
|
+
runEpoch: number;
|
|
50
|
+
transferId: string;
|
|
51
|
+
path: string;
|
|
52
|
+
offset: number;
|
|
53
|
+
size: number;
|
|
54
|
+
dataBase64: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Used by bridge dispatch and the receiver; malformed commands never acquire a lifecycle slot. */
|
|
58
|
+
export function parseInitialAttachmentInput(value: unknown): InitialAttachmentWriteInput {
|
|
59
|
+
if (!value || typeof value !== "object") throw new Error("Invalid initial attachment transfer");
|
|
60
|
+
const input = value as InitialAttachmentWriteInput;
|
|
61
|
+
if (typeof input.taskId !== "string" || !/^[a-zA-Z0-9-]{1,100}$/.test(input.taskId) ||
|
|
62
|
+
typeof input.path !== "string" ||
|
|
63
|
+
!Number.isSafeInteger(input.runEpoch) || input.runEpoch < 0 ||
|
|
64
|
+
typeof input.transferId !== "string" || !/^[a-zA-Z0-9-]{1,100}$/.test(input.transferId) ||
|
|
65
|
+
![undefined, "probe", "abort"].includes(input.operation) ||
|
|
66
|
+
(input.preserveExisting !== undefined && typeof input.preserveExisting !== "boolean") ||
|
|
67
|
+
typeof input.dataBase64 !== "string" || input.dataBase64.length > Math.ceil(INITIAL_ATTACHMENT_CHUNK / 3) * 4 ||
|
|
68
|
+
!Number.isSafeInteger(input.offset) || input.offset < 0 ||
|
|
69
|
+
!Number.isSafeInteger(input.size) || input.size < 0 || input.size > INITIAL_ATTACHMENT_MAX) {
|
|
70
|
+
throw new Error("Invalid initial attachment transfer");
|
|
71
|
+
}
|
|
72
|
+
initialAttachmentParts(input.path);
|
|
73
|
+
return input;
|
|
74
|
+
}
|
package/src/main.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env tsx
|
|
2
|
+
import { parseInitialAttachmentInput } from "./initial-attachments";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { stationAgentCliAdvertisable } from "../lib/agent-cli";
|
|
4
5
|
import {
|
|
@@ -1641,6 +1642,7 @@ function buildCapabilities(): HostCapabilities {
|
|
|
1641
1642
|
protocolFeatures: [
|
|
1642
1643
|
PREVIEW_UPSTREAM_PROTOCOL_FEATURE,
|
|
1643
1644
|
"host-workspace-file-read-v1",
|
|
1645
|
+
"initial-attachments-v1",
|
|
1644
1646
|
ASSIGNMENT_EVIDENCE_PROTOCOL_FEATURE,
|
|
1645
1647
|
FIRST_TURN_DEDUP_PROTOCOL_FEATURE,
|
|
1646
1648
|
LEAD_EVIDENCE_PROTOCOL_FEATURE,
|
|
@@ -4801,6 +4803,8 @@ async function dispatchCommand(
|
|
|
4801
4803
|
return hostCommands.taskProjectCompensate(ctx, expectTaskProjectFence(args[0], "task project compensate input"));
|
|
4802
4804
|
case "taskProjectStatus":
|
|
4803
4805
|
return hostCommands.taskProjectStatus(ctx, expectTaskProjectStatusInput(args, 0));
|
|
4806
|
+
case "initialAttachmentWrite":
|
|
4807
|
+
return hostCommands.initialAttachmentWrite(ctx, parseInitialAttachmentInput(args[0]));
|
|
4804
4808
|
case "attachmentWrite":
|
|
4805
4809
|
return hostCommands.attachmentWrite(
|
|
4806
4810
|
ctx,
|
|
@@ -5831,6 +5835,7 @@ const HOST_COMMAND_NAMES = {
|
|
|
5831
5835
|
taskProjectActivate: true,
|
|
5832
5836
|
taskProjectCompensate: true,
|
|
5833
5837
|
taskProjectStatus: true,
|
|
5838
|
+
initialAttachmentWrite: true,
|
|
5834
5839
|
attachmentWrite: true,
|
|
5835
5840
|
attachmentRead: true,
|
|
5836
5841
|
workspaceFileRead: true,
|
package/src/protocol.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InitialAttachmentWriteInput } from "./initial-attachments";
|
|
1
2
|
export * from "./custom-connections";
|
|
2
3
|
export * from "./preview-upstream";
|
|
3
4
|
import type { PreviewUpstream } from "./preview-upstream";
|
|
@@ -53,6 +54,7 @@ export enum HostErrorCode {
|
|
|
53
54
|
NoSuchAgent = "no_such_agent",
|
|
54
55
|
NoSuchPermission = "no_such_permission",
|
|
55
56
|
HostUnavailable = "host_unavailable",
|
|
57
|
+
InitialAttachmentsUnsupported = "initial_attachments_unsupported",
|
|
56
58
|
Internal = "internal",
|
|
57
59
|
PayloadTooLarge = "payload_too_large",
|
|
58
60
|
}
|
|
@@ -4958,6 +4960,7 @@ export interface HostCommands {
|
|
|
4958
4960
|
ctx: CommandContext,
|
|
4959
4961
|
input: TaskProjectStatusInput,
|
|
4960
4962
|
): Promise<HostCommandResult<TaskProjectStatusResult>>;
|
|
4963
|
+
initialAttachmentWrite(ctx: CommandContext, input: InitialAttachmentWriteInput): Promise<HostCommandResult<{ exists: boolean } | undefined>>;
|
|
4961
4964
|
attachmentWrite(
|
|
4962
4965
|
ctx: CommandContext,
|
|
4963
4966
|
input: { taskId: string; filename: string; dataBase64: string },
|