@exedev/t3exe 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -52,7 +52,7 @@ The same operations are on the command line: `t3exe create`, `ls`, `rm`, `pause`
52
52
  ## Cleanup
53
53
 
54
54
  exe.dev VMs run until deleted, so t3exe cleans up after itself. Every minute it asks each VM's T3 Code
55
- whether a thread there is busy. A VM with no busy thread for `idleMinutes` (default 15) is deleted, or
55
+ whether a thread there is busy, including tasks delegated to it. A VM with no busy thread for `idleMinutes` (default 15) is deleted, or
56
56
  paused if `onIdle` is `pause`. Every VM is deleted `ttlMinutes` (default 480) after it was created, unless it
57
57
  has `keepAlive`.
58
58
 
package/dist/manager.js CHANGED
@@ -14,6 +14,24 @@ export const DEFAULTS = {
14
14
  };
15
15
  /** Thread statuses that mean an agent is (or is about to be) working, or waits on an approval. */
16
16
  const BUSY = new Set(["preparing", "queued", "starting", "running", "waiting"]);
17
+ /**
18
+ * Prints the VM's live threads as JSON. `t3 thread list` leaves out delegated threads,
19
+ * which is what a task sent here with delegate_task is, so this reads the server's
20
+ * orchestration snapshot instead, with a read-only token kept on the VM.
21
+ */
22
+ const THREADS_SCRIPT = `set -u
23
+ t3="$HOME/.local/bin/t3" token="$HOME/.t3exe/read-token" out="$HOME/.t3exe/shell.json"
24
+ issue() { (umask 077 && "$t3" auth session issue --base-dir "$HOME/.t3" --scope orchestration:read --ttl 30d --label "t3exe idle check" --token-only >"$token.new" && mv "$token.new" "$token"); }
25
+ get() { curl -sS -m 30 -o "$out" -w '%{http_code}' -H "Authorization: Bearer $(cat "$token" 2>/dev/null)" -H 'x-t3-orchestration-protocol: 2' http://127.0.0.1:${PORT}/api/orchestration/shell; }
26
+ [ -s "$token" ] || issue
27
+ code=$(get)
28
+ if [ "$code" = 401 ]; then issue && code=$(get); fi
29
+ [ "$code" = 200 ] || { echo "GET /api/orchestration/shell: HTTP $code: $(head -c 300 "$out" 2>/dev/null)" >&2; exit 1; }
30
+ jq -c '[.threads[] | select(.archivedAt == null and .deletedAt == null) | {id, status, activityRunStatus, pendingRuntimeRequest: (.pendingRuntimeRequest != null)}]' "$out"`;
31
+ /** Whether any thread is working, about to work, or waiting on an approval. */
32
+ export function anyBusy(threads) {
33
+ return threads.some((t) => BUSY.has(t.status ?? "") || BUSY.has(t.activityRunStatus ?? "") || t.pendingRuntimeRequest === true);
34
+ }
17
35
  /** Abandon a creation after this long: its process is gone. */
18
36
  const CREATE_TIMEOUT_MS = 30 * 60_000;
19
37
  const SETUP_SCRIPT = readFileSync(new URL("../vm/setup.sh", import.meta.url), "utf8");
@@ -163,13 +181,12 @@ export class Manager {
163
181
  };
164
182
  });
165
183
  }
166
- /** Whether any thread in the VM's project is busy. */
184
+ /** Whether any thread on the VM is busy, including tasks delegated to it over the link. */
167
185
  async busy(record, signal) {
168
- const command = `~/.local/bin/t3 thread list --base-dir ~/.t3 --json --project ${quote(record.projectId ?? "")}`;
169
- const { exitCode, stdout, stderr } = await this.exe.vm(record.name).ssh(command, { signal });
186
+ const { exitCode, stdout, stderr } = await this.exe.vm(record.name).ssh(THREADS_SCRIPT, { signal });
170
187
  if (exitCode !== 0)
171
- throw new Error(`t3 thread list on ${record.name}: ${stderr.trim()}`);
172
- return JSON.parse(stdout).some((t) => BUSY.has(t.status));
188
+ throw new Error(`reading threads on ${record.name}: ${stderr.trim()}`);
189
+ return anyBusy(JSON.parse(stdout));
173
190
  }
174
191
  /** Applies each VM's TTL and idle policy once. */
175
192
  async reap(now = Date.now()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exedev/t3exe",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "MCP server and CLI that run T3 Code agents on exe.dev VMs, linked to your T3 Code as environments.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -29,7 +29,8 @@
29
29
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
30
30
  "typecheck": "tsc --noEmit",
31
31
  "start": "node bin/t3exe.mjs",
32
- "prepublishOnly": "npm run typecheck && npm run build"
32
+ "prepublishOnly": "npm run typecheck && npm test && npm run build",
33
+ "test": "node --test \"test/*.test.ts\""
33
34
  },
34
35
  "dependencies": {
35
36
  "@exedev/sdk": "^0.4.1",