werkmeister-core 0.90.1 → 0.90.3
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/CHANGELOG.md +16 -0
- package/README.md +0 -4
- package/dist/config.d.ts +9 -0
- package/dist/config.js +40 -2
- package/dist/fixture_fakes.d.ts +2 -0
- package/dist/fixture_fakes.js +6 -2
- package/dist/fixture_workspace.d.ts +14 -0
- package/dist/fixture_workspace.js +38 -2
- package/dist/generate.js +36 -8
- package/dist/harness/claude/cli.d.ts +5 -0
- package/dist/harness/claude/cli.js +13 -1
- package/dist/pr_lifecycle.d.ts +2 -2
- package/dist/pr_lifecycle.js +2 -2
- package/dist/sandbox.d.ts +6 -5
- package/dist/sandbox.js +13 -6
- package/dist/sdk.d.ts +1 -7
- package/dist/sdk.js +1 -7
- package/package.json +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# sandbox-core
|
|
2
2
|
|
|
3
|
+
## 0.90.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4941f67: `with-fixture-workspace` takes `--running <file>` and `--queue <feature>[,<feature>]...`, so a capacity wait runs through the built CLI. Each `--running` line (`feature<TAB>workspace<TAB>startedAt<TAB>memoryBytes<TAB>nanoCpus`) is a container the fixture's fake `docker ps -q` / `docker inspect` show the scheduler as running; the workspace is a folder name created empty in the fixture, so the holder is a person's and never preempted. `--queue` seeds `scheduler/queue.json`. With `--config` `budget: { cpus: 6 }` and a 6-CPU holder, `feature up` exits 75 naming the holder, and `budget status` lists it under Running. `withFixtureWorkspace` takes the same as `containers` and `queue`.
|
|
8
|
+
- b61338b: `with-fixture-workspace` and `withFixtureWorkspace` point the dead daemon address (`WERKMEISTER_HOST`) at a port just bound and closed, instead of `127.0.0.1:1`, which fetch rejects as a "bad port" (a TypeError with no `cause.code`) before connecting. A fixture run now sees a refused connection (`ECONNREFUSED`), as with a real stopped daemon, so the refused, restart and fallback paths can be exercised through the fixture.
|
|
9
|
+
|
|
10
|
+
## 0.90.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 592f35a: `@anthropic-ai/claude-agent-sdk` is now an optional peer dependency of werkmeister-core, so `npm i werkmeister-core` no longer installs it or its ~240 MB `claude-agent-sdk-<platform>` binary. Only the `ask` helpers (refine, issue distillation, the Jira MCP fallback) load it; without it, `askOrThrow` fails with "Asking Claude needs the Claude Agent SDK, which is not installed" and the install command, and `ask`/`askJson` return null as for any other failure. Install it beside core to use them. The `werkmeister` CLI still depends on it.
|
|
15
|
+
- 9eef5be: An npm-installed werkmeister-core finds the CLI package without `WERKMEISTER_ROOT`. When no werkmeister checkout sits above core, `sandboxRoot()` (and with it `infraRoot()` and every function that starts or creates things, such as `up` and `createWorkspace`) and the CLI-wrapper lookup follow the `werkmeister` on PATH to its package, e.g. `$(npm root -g)/werkmeister`. A `werkmeister` on PATH whose nearest `package.json` is not named `werkmeister` is skipped. `WERKMEISTER_ROOT` still overrides, and a checkout still wins over the global install.
|
|
16
|
+
|
|
17
|
+
The lookup follows symlinked bins (npm global installs, `npm link`), not pnpm's shell-script shims; set `WERKMEISTER_ROOT` there. Anything that resolves the CLI wrapper through core without `WERKMEISTER_ROOT`, such as the VS Code extension and the dashboard, now also falls back to the `werkmeister` on PATH before `~/.local/bin/werkmeister`, where it used to stop with an error.
|
|
18
|
+
|
|
3
19
|
## 0.90.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -31,10 +31,6 @@ for (const ws of workspaces) {
|
|
|
31
31
|
|
|
32
32
|
The daemon's operations are reached with `callTool`. The full API is at [werkmeister.io/sdk](https://werkmeister.io/sdk/).
|
|
33
33
|
|
|
34
|
-
## Limits
|
|
35
|
-
|
|
36
|
-
Functions that start or create things (`up`, `createWorkspace` …) need `WERKMEISTER_ROOT` set to the CLI package directory, for example `$(npm root -g)/werkmeister`, until [SW-695](https://jory-group.atlassian.net/browse/SW-695).
|
|
37
|
-
|
|
38
34
|
## Licence
|
|
39
35
|
|
|
40
36
|
Apache-2.0. See `LICENSE` and `NOTICE`.
|
package/dist/config.d.ts
CHANGED
|
@@ -385,6 +385,15 @@ export declare function getVolumeBaseNames(): string[];
|
|
|
385
385
|
* around it — which is why `WERKMEISTER_ROOT` ranks first rather than as a fallback.
|
|
386
386
|
*/
|
|
387
387
|
export declare function sandboxRoot(): string;
|
|
388
|
+
/**
|
|
389
|
+
* SW-695: the package directory of the `werkmeister` on *pathEnv*, for an
|
|
390
|
+
* npm-installed core with no checkout around it. The bin's realpath lands in the
|
|
391
|
+
* package (an npm global, or a checkout's apps/cli linked onto PATH); the nearest
|
|
392
|
+
* package.json must name it `werkmeister`, so another tool's `werkmeister` is skipped.
|
|
393
|
+
* shortcut: symlinked bins on PATH only, so pnpm's shell-script shims and a GUI process with a
|
|
394
|
+
* stripped PATH miss it; WERKMEISTER_ROOT covers both.
|
|
395
|
+
*/
|
|
396
|
+
export declare function installedCliPackage(pathEnv?: string): string | null;
|
|
388
397
|
/**
|
|
389
398
|
* The `infra/` dir holding compose files, templates, the proxy UI, schemas and
|
|
390
399
|
* skills. All versioned code — the machine-specific registry files live in
|
package/dist/config.js
CHANGED
|
@@ -624,8 +624,46 @@ export function sandboxRoot() {
|
|
|
624
624
|
break;
|
|
625
625
|
dir = parent;
|
|
626
626
|
}
|
|
627
|
-
|
|
628
|
-
|
|
627
|
+
const installed = installedCliPackage();
|
|
628
|
+
if (installed)
|
|
629
|
+
return installed;
|
|
630
|
+
throw new Error("Could not locate the werkmeister CLI package. Install it (npm install -g werkmeister) " +
|
|
631
|
+
"or set WERKMEISTER_ROOT to its package directory (a checkout's apps/cli).");
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* SW-695: the package directory of the `werkmeister` on *pathEnv*, for an
|
|
635
|
+
* npm-installed core with no checkout around it. The bin's realpath lands in the
|
|
636
|
+
* package (an npm global, or a checkout's apps/cli linked onto PATH); the nearest
|
|
637
|
+
* package.json must name it `werkmeister`, so another tool's `werkmeister` is skipped.
|
|
638
|
+
* shortcut: symlinked bins on PATH only, so pnpm's shell-script shims and a GUI process with a
|
|
639
|
+
* stripped PATH miss it; WERKMEISTER_ROOT covers both.
|
|
640
|
+
*/
|
|
641
|
+
export function installedCliPackage(pathEnv = process.env.PATH ?? "") {
|
|
642
|
+
for (const binDir of pathEnv.split(path.delimiter)) {
|
|
643
|
+
if (!binDir)
|
|
644
|
+
continue;
|
|
645
|
+
let dir;
|
|
646
|
+
try {
|
|
647
|
+
dir = path.dirname(fs.realpathSync(path.join(binDir, "werkmeister")));
|
|
648
|
+
}
|
|
649
|
+
catch {
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
for (; dir !== path.dirname(dir); dir = path.dirname(dir)) {
|
|
653
|
+
const pkg = path.join(dir, "package.json");
|
|
654
|
+
if (!fs.existsSync(pkg))
|
|
655
|
+
continue;
|
|
656
|
+
try {
|
|
657
|
+
if (JSON.parse(fs.readFileSync(pkg, "utf8")).name === "werkmeister")
|
|
658
|
+
return dir;
|
|
659
|
+
}
|
|
660
|
+
catch {
|
|
661
|
+
// an unreadable package.json is no CLI package
|
|
662
|
+
}
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return null;
|
|
629
667
|
}
|
|
630
668
|
/**
|
|
631
669
|
* The `infra/` dir holding compose files, templates, the proxy UI, schemas and
|
package/dist/fixture_fakes.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface FakeWorld {
|
|
|
26
26
|
rules?: unknown[];
|
|
27
27
|
/** Containers the fake docker shows as running, to the gate's `ps --format {{.Names}}…` only. */
|
|
28
28
|
running?: string[];
|
|
29
|
+
/** `docker inspect` lines (`feature\tworkdir\tstartedAt\tmemory\tnanoCpus`) the scheduler reads as running features (SW-685). */
|
|
30
|
+
containers?: string[];
|
|
29
31
|
/** Set: `docker exec` runs its last argument (the gate row's command) with `sh -c` here and exits with its code. Absent: exit 0. */
|
|
30
32
|
execCwd?: string;
|
|
31
33
|
}
|
package/dist/fixture_fakes.js
CHANGED
|
@@ -10,7 +10,8 @@ import * as path from "node:path";
|
|
|
10
10
|
// Unknown verbs exit 1, so a code path a fake doesn't cover fails loudly (SW-148).
|
|
11
11
|
// `pr list` prints nothing: pr open's --jq leaves no URL when no PR is open.
|
|
12
12
|
// Only the gate's `ps --format {{.Names}}\t{{.State}}` sees running containers; every other `ps`
|
|
13
|
-
// (-q/-aq by label) finds none, so no teardown of a pre-rename project runs on a fake hit.
|
|
13
|
+
// (-q/-aq by label) finds none, so no teardown of a pre-rename project runs on a fake hit. Only the
|
|
14
|
+
// scheduler's exact feature-label `ps -q` and its NanoCpus `inspect` see `containers` (SW-685).
|
|
14
15
|
const FAKE_JS = `import { spawnSync } from "node:child_process";
|
|
15
16
|
import * as fs from "node:fs";
|
|
16
17
|
const [, , tool, dir, ...args] = process.argv;
|
|
@@ -66,8 +67,11 @@ if (tool === "gh") {
|
|
|
66
67
|
switch (args[0]) {
|
|
67
68
|
case "ps":
|
|
68
69
|
if (args.some((a) => a.includes("{{.Names}}"))) out((world.running ?? []).map((c) => c + "\\trunning\\n").join(""));
|
|
70
|
+
else if (args.join(" ") === "ps -q --filter label=com.werkmeister.feature") out((world.containers ?? []).map((_, i) => "c" + i + "\\n").join(""));
|
|
71
|
+
break;
|
|
72
|
+
case "inspect":
|
|
73
|
+
out(args[1] === "--format" && args[2].includes("NanoCpus") ? (world.containers ?? []).map((l) => l + "\\n").join("") : "false\\n");
|
|
69
74
|
break;
|
|
70
|
-
case "inspect": out("false\\n"); break;
|
|
71
75
|
case "exec":
|
|
72
76
|
if (world.execCwd) process.exit(spawnSync("sh", ["-c", args.at(-1)], { cwd: world.execCwd, stdio: "inherit" }).status ?? 1);
|
|
73
77
|
break;
|
|
@@ -49,6 +49,20 @@ export interface FixtureOptions {
|
|
|
49
49
|
changeBranch?: string;
|
|
50
50
|
/** Top-level keys added to the fixture's config.yaml, e.g. `{ budget: { host_load: 0.01 } }` (SW-670); fixturePreset refuses any key but CONFIG_KEYS. */
|
|
51
51
|
config?: Record<string, unknown>;
|
|
52
|
+
/** Containers the fake docker shows the scheduler as running, so a start can wait for capacity (SW-685). */
|
|
53
|
+
containers?: FixtureContainer[];
|
|
54
|
+
/** Features in the waiting queue, `scheduler/queue.json` (SW-685). */
|
|
55
|
+
queue?: string[];
|
|
56
|
+
}
|
|
57
|
+
/** One running container as `docker inspect` reports it to the scheduler. */
|
|
58
|
+
export interface FixtureContainer {
|
|
59
|
+
feature: string;
|
|
60
|
+
/** A folder name, created empty under the fixture's workspaces root: a person's workspace, never preempted. */
|
|
61
|
+
workspace: string;
|
|
62
|
+
startedAt: string;
|
|
63
|
+
/** Bytes reserved. */
|
|
64
|
+
memory: number;
|
|
65
|
+
nanoCpus: number;
|
|
52
66
|
}
|
|
53
67
|
export interface FixturePresets {
|
|
54
68
|
/** An approved PR for a one-file change in packages/lib, with `demo-lib` running, for `pr gate`. */
|
|
@@ -13,6 +13,8 @@ import { dotDir } from "./dot_dir.js";
|
|
|
13
13
|
import { writeFakes } from "./fixture_fakes.js";
|
|
14
14
|
import { gitEnv } from "./proc.js";
|
|
15
15
|
import { prDir, stageDirs, templateFor } from "./strategies/icm_templates.js";
|
|
16
|
+
// Names become folders under the fixture and lines in the fakes, from a pre-approved wrapper's input.
|
|
17
|
+
const NAME = /^[a-z0-9][a-z0-9-]*$/;
|
|
16
18
|
// The only config.yaml keys --config may add: others (jira, github_ingest, paths…) reach real services or repos from a pre-approved run.
|
|
17
19
|
const CONFIG_KEYS = ["budget"];
|
|
18
20
|
export const FIXTURE_FEATURE = "demo";
|
|
@@ -76,6 +78,20 @@ export function fixturePreset({ gate, bare, change, ...opts }) {
|
|
|
76
78
|
const refused = Object.keys(opts.config ?? {}).filter((k) => !CONFIG_KEYS.includes(k));
|
|
77
79
|
if (refused.length)
|
|
78
80
|
throw new Error(`--config may not set ${refused.join(", ")}: only ${CONFIG_KEYS.join(", ")}`);
|
|
81
|
+
for (const c of opts.containers ?? []) {
|
|
82
|
+
const bad = !NAME.test(c.feature)
|
|
83
|
+
? c.feature
|
|
84
|
+
: !NAME.test(c.workspace)
|
|
85
|
+
? c.workspace
|
|
86
|
+
: Number.isNaN(Date.parse(c.startedAt))
|
|
87
|
+
? c.startedAt
|
|
88
|
+
: [c.memory, c.nanoCpus].find((n) => !Number.isSafeInteger(n) || n < 0);
|
|
89
|
+
if (bad !== undefined)
|
|
90
|
+
throw new Error(`--running: bad value ${JSON.stringify(bad)}: feature and workspace are lowercase names, startedAt a date, memory and nanoCpus whole numbers`);
|
|
91
|
+
}
|
|
92
|
+
const badName = opts.queue?.find((f) => !NAME.test(f));
|
|
93
|
+
if (badName !== undefined)
|
|
94
|
+
throw new Error(`--queue: bad feature ${JSON.stringify(badName)}: lowercase names, comma-separated`);
|
|
79
95
|
const libChange = "packages/lib/index.js";
|
|
80
96
|
const gateChange = change ?? (opts.fragmentChange === undefined ? libChange : undefined);
|
|
81
97
|
if (gate && opts.services && gateChange === libChange) {
|
|
@@ -207,11 +223,19 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
|
|
|
207
223
|
// leasesPath() beside configFile: the env that points it here isn't set yet in this process.
|
|
208
224
|
write(path.join(path.dirname(configFile), "scheduler", "leases.json"), JSON.stringify(leases));
|
|
209
225
|
}
|
|
226
|
+
if (opts.queue)
|
|
227
|
+
write(path.join(path.dirname(configFile), "scheduler", "queue.json"), JSON.stringify(opts.queue));
|
|
228
|
+
const containers = (opts.containers ?? []).map((c) => {
|
|
229
|
+
const ws = path.join(root, "ws", c.workspace);
|
|
230
|
+
fs.mkdirSync(ws, { recursive: true });
|
|
231
|
+
return [c.feature, ws, c.startedAt, c.memory, c.nanoCpus].join("\t");
|
|
232
|
+
});
|
|
210
233
|
const home = path.join(root, "home");
|
|
211
234
|
fs.mkdirSync(home);
|
|
212
235
|
const fakes = writeFakes(path.join(root, "bin"), {
|
|
213
236
|
prUrl: `https://github.com/${FIXTURE_REPO_SLUG}/pull/1`,
|
|
214
237
|
running: opts.running ?? [],
|
|
238
|
+
containers,
|
|
215
239
|
prState: opts.merged ? "MERGED" : undefined,
|
|
216
240
|
issue: yml["issue_id"] ? FIXTURE_ISSUE : undefined,
|
|
217
241
|
// shortcut: every exec runs in the first code repo; map container → repo when a fixture has two.
|
|
@@ -247,15 +271,27 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
|
|
|
247
271
|
GH_TOKEN: "",
|
|
248
272
|
GITHUB_TOKEN: "",
|
|
249
273
|
// Dead even when the caller's shell exports the real daemon's address (SW-264, SW-426).
|
|
250
|
-
WERKMEISTER_HOST: opts.daemon ??
|
|
274
|
+
WERKMEISTER_HOST: opts.daemon ?? closedPortUrl(),
|
|
275
|
+
// A refused daemon is retried for a restart gap (15 s default): each fixture step would wait it out (SW-708).
|
|
276
|
+
WERKMEISTER_DAEMON_RETRY_MS: process.env["WERKMEISTER_DAEMON_RETRY_MS"] || "500",
|
|
251
277
|
},
|
|
252
278
|
};
|
|
253
279
|
}
|
|
280
|
+
// A port just bound and closed, so a call is refused (ECONNREFUSED) like a stopped daemon: fetch
|
|
281
|
+
// rejects port 1 as a "bad port" before connecting (SW-708). Sync, since seedFixture is.
|
|
282
|
+
// shortcut: another process can take the port between close and use; hold a socket if that flakes.
|
|
283
|
+
function closedPortUrl() {
|
|
284
|
+
const port = execFileSync(process.execPath, [
|
|
285
|
+
"-e",
|
|
286
|
+
"const s=require('net').createServer().listen(0,'127.0.0.1',()=>{process.stdout.write(String(s.address().port));s.close()})",
|
|
287
|
+
]).toString();
|
|
288
|
+
return `http://127.0.0.1:${port}`;
|
|
289
|
+
}
|
|
254
290
|
const SCRIPT = `#!/bin/sh
|
|
255
291
|
# Generated by \`werkmeister workspace init\` (SW-292); rerun it to regenerate.
|
|
256
292
|
# Runs this workspace's own built werkmeister CLI against a seeded fixture workspace, removed on exit:
|
|
257
293
|
# temp HOME and registry, a local bare origin, logging fakes for gh and docker, dead Docker and daemon.
|
|
258
|
-
# usage: with-fixture-workspace [--no-wait] [--gate] [--bare] [--daemon] [--exec-runs] [--merged] [--behind] [--slots-full] [--issue <ref>] [--pr-field <key>=<value>]... [--workspace <file>] [--config <file>] [--services <file>] [--fragment <file>] [--change <path>] [--change-base <file>] [--change-branch <file>] [--fragment-change <file>] [--print <file>]... <werkmeister args> [--then <werkmeister args>]...
|
|
294
|
+
# usage: with-fixture-workspace [--no-wait] [--gate] [--bare] [--daemon] [--exec-runs] [--merged] [--behind] [--slots-full] [--running <file>] [--queue <feature>[,<feature>]...] [--issue <ref>] [--pr-field <key>=<value>]... [--workspace <file>] [--config <file>] [--services <file>] [--fragment <file>] [--change <path>] [--change-base <file>] [--change-branch <file>] [--fragment-change <file>] [--print <file>]... <werkmeister args> [--then <werkmeister args>]...
|
|
259
295
|
# It only ever runs that CLI, never another command, so one allow rule can cover it (SW-172, SW-231);
|
|
260
296
|
# --exec-runs, given first, also runs the registry's rows on the host, so the workspace asks before it (SW-473).
|
|
261
297
|
ws=$(cd "$(dirname "$0")/../.." && pwd -P) || exit 1
|
package/dist/generate.js
CHANGED
|
@@ -1145,8 +1145,10 @@ function featureCookieRegexp(name) {
|
|
|
1145
1145
|
* VALUE, selects which one serves the request, so any number of workspaces
|
|
1146
1146
|
* share the hostname concurrently.
|
|
1147
1147
|
* A request with neither — or one naming a feature that doesn't run this
|
|
1148
|
-
* service — falls through to `upstream
|
|
1149
|
-
*
|
|
1148
|
+
* service — falls through to `upstream`, the remote tunnel when there is one.
|
|
1149
|
+
* A local-only host has no tunnel (SW-704): a request selecting nothing gets
|
|
1150
|
+
* the first feature by name (`fallback`), marked by an X-Werkmeister-Served-By
|
|
1151
|
+
* response header, and one whose selection matches nothing gets a 404.
|
|
1150
1152
|
*
|
|
1151
1153
|
* Selecting on the cookie rather than picking a single winner is what makes
|
|
1152
1154
|
* concurrent workstreams work. It also stops a torn-down-but-still-registered
|
|
@@ -1155,7 +1157,8 @@ function featureCookieRegexp(name) {
|
|
|
1155
1157
|
*
|
|
1156
1158
|
* Returns `[{hostname, service, upstream, features?}, ...]`, where `features` is
|
|
1157
1159
|
* `[{name, upstream, matcher, cookie_regexp}, ...]`, omitted entirely when no
|
|
1158
|
-
* feature declares the service so the template renders the static form
|
|
1160
|
+
* feature declares the service so the template renders the static form, and
|
|
1161
|
+
* `fallback` is set only on a local-only host.
|
|
1159
1162
|
*/
|
|
1160
1163
|
function buildHostRouters(allFeatures, servicesConfig) {
|
|
1161
1164
|
const routers = [];
|
|
@@ -1192,8 +1195,9 @@ function buildHostRouters(allFeatures, servicesConfig) {
|
|
|
1192
1195
|
// Prefer the remote tunnel as the no-cookie default: it is always live, and
|
|
1193
1196
|
// picking a local feature here is what used to let a dead workspace own the
|
|
1194
1197
|
// hostname. Local-only services have no remote face, so they still fall back
|
|
1195
|
-
// to a feature rather than losing the site block entirely
|
|
1196
|
-
const
|
|
1198
|
+
// to a feature rather than losing the site block entirely, named in `fallback`.
|
|
1199
|
+
const fallback = rc.remoteUpstream ? undefined : candidates[0];
|
|
1200
|
+
const defaultUpstream = rc.remoteUpstream ?? fallback?.upstream;
|
|
1197
1201
|
// No feature and no fallback -> nothing to proxy to, skip.
|
|
1198
1202
|
if (!defaultUpstream) {
|
|
1199
1203
|
continue;
|
|
@@ -1203,10 +1207,27 @@ function buildHostRouters(allFeatures, servicesConfig) {
|
|
|
1203
1207
|
service: svcName,
|
|
1204
1208
|
upstream: defaultUpstream,
|
|
1205
1209
|
...(candidates.length ? { features: candidates } : {}),
|
|
1210
|
+
...(fallback ? { fallback: fallback.name } : {}),
|
|
1206
1211
|
});
|
|
1207
1212
|
}
|
|
1208
1213
|
return routers;
|
|
1209
1214
|
}
|
|
1215
|
+
/** Local-only default (SW-704): nothing selected -> the marked fallback; a selection matching nothing -> 404. Mirrors Caddyfile.njk. */
|
|
1216
|
+
function fallbackLines(feature, upstream) {
|
|
1217
|
+
return [
|
|
1218
|
+
" @no_selection {",
|
|
1219
|
+
" not header X-Feature *",
|
|
1220
|
+
" not header_regexp Cookie (?:^|;\\s*)X-Feature=",
|
|
1221
|
+
" }",
|
|
1222
|
+
" handle @no_selection {",
|
|
1223
|
+
` header X-Werkmeister-Served-By "${feature} (fallback: no feature selected)"`,
|
|
1224
|
+
` reverse_proxy ${upstream}`,
|
|
1225
|
+
" }",
|
|
1226
|
+
" handle /* {",
|
|
1227
|
+
' respond "No running feature named in X-Feature serves {host}; pick one at /__werkmeister" 404',
|
|
1228
|
+
" }",
|
|
1229
|
+
];
|
|
1230
|
+
}
|
|
1210
1231
|
/** Render host-router site blocks (built-in fallback path). */
|
|
1211
1232
|
function hostRouterLines(routers) {
|
|
1212
1233
|
const lines = [];
|
|
@@ -1235,6 +1256,7 @@ function hostRouterLines(routers) {
|
|
|
1235
1256
|
for (const f of features) {
|
|
1236
1257
|
lines.push(` @${f["matcher"]}_header header X-Feature ${f["name"]}`);
|
|
1237
1258
|
lines.push(` handle @${f["matcher"]}_header {`);
|
|
1259
|
+
lines.push(` header X-Werkmeister-Served-By ${f["name"]}`);
|
|
1238
1260
|
lines.push(` reverse_proxy ${f["upstream"]}`);
|
|
1239
1261
|
lines.push(" }");
|
|
1240
1262
|
}
|
|
@@ -1243,6 +1265,7 @@ function hostRouterLines(routers) {
|
|
|
1243
1265
|
lines.push(` # X-Feature=${f["name"]} -> that workspace's containers.`);
|
|
1244
1266
|
lines.push(` @${f["matcher"]} header_regexp Cookie ${f["cookie_regexp"]}`);
|
|
1245
1267
|
lines.push(` handle @${f["matcher"]} {`);
|
|
1268
|
+
lines.push(` header X-Werkmeister-Served-By ${f["name"]}`);
|
|
1246
1269
|
lines.push(` reverse_proxy ${f["upstream"]} {`);
|
|
1247
1270
|
lines.push(` header_up X-Feature ${f["name"]}`);
|
|
1248
1271
|
lines.push(" }");
|
|
@@ -1262,9 +1285,14 @@ function hostRouterLines(routers) {
|
|
|
1262
1285
|
// `/*` rather than a bare `handle`: the more specific selector sibling
|
|
1263
1286
|
// still wins, and the structural lint's bare-vs-scoped route-drop guard stays
|
|
1264
1287
|
// meaningful instead of firing on every generated file.
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1288
|
+
if (r["fallback"]) {
|
|
1289
|
+
lines.push(...fallbackLines(r["fallback"], r["upstream"]));
|
|
1290
|
+
}
|
|
1291
|
+
else {
|
|
1292
|
+
lines.push(" handle /* {");
|
|
1293
|
+
lines.push(` reverse_proxy ${r["upstream"]}`);
|
|
1294
|
+
lines.push(" }");
|
|
1295
|
+
}
|
|
1268
1296
|
lines.push("}");
|
|
1269
1297
|
lines.push("");
|
|
1270
1298
|
}
|
|
@@ -22,6 +22,11 @@ export declare function extractJson(out: string): string | null;
|
|
|
22
22
|
type AskOpts = {
|
|
23
23
|
tools?: boolean;
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* SW-694: the SDK is an optional peer of core, so "not installed" becomes an install
|
|
27
|
+
* hint; any other load failure (a broken install) keeps its own error.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sdkLoadError(e: unknown): unknown;
|
|
25
30
|
/** The structured answer in a result message, or the WorkspaceError that says why there is none. */
|
|
26
31
|
export declare function fromResult(m: SDKResultMessage): Record<string, unknown>;
|
|
27
32
|
/** One run, the answer or null on any failure. */
|
|
@@ -59,6 +59,16 @@ export function extractJson(out) {
|
|
|
59
59
|
const fenced = /```(?:json)?\s*([\s\S]*?)```/i.exec(out);
|
|
60
60
|
return fenced ? slice(fenced[1]) : whole;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* SW-694: the SDK is an optional peer of core, so "not installed" becomes an install
|
|
64
|
+
* hint; any other load failure (a broken install) keeps its own error.
|
|
65
|
+
*/
|
|
66
|
+
export function sdkLoadError(e) {
|
|
67
|
+
return e?.code === "ERR_MODULE_NOT_FOUND"
|
|
68
|
+
? new WorkspaceError("Asking Claude needs the Claude Agent SDK, which is not installed. " +
|
|
69
|
+
"Install it beside werkmeister-core with: npm install @anthropic-ai/claude-agent-sdk")
|
|
70
|
+
: e;
|
|
71
|
+
}
|
|
62
72
|
/** `ask`'s answer as one string field: no tag scraping. */
|
|
63
73
|
const TEXT_SCHEMA = {
|
|
64
74
|
type: "object",
|
|
@@ -74,7 +84,9 @@ const TEXT_SCHEMA = {
|
|
|
74
84
|
*/
|
|
75
85
|
async function runQuery(prompt, schema, opts) {
|
|
76
86
|
// Loaded on use: the MCP server imports this module at start, and the SDK is heavy.
|
|
77
|
-
const { query } = await import("@anthropic-ai/claude-agent-sdk")
|
|
87
|
+
const { query } = await import("@anthropic-ai/claude-agent-sdk").catch((e) => {
|
|
88
|
+
throw sdkLoadError(e);
|
|
89
|
+
});
|
|
78
90
|
const abortController = new AbortController();
|
|
79
91
|
const timer = setTimeout(() => abortController.abort(), 120_000);
|
|
80
92
|
try {
|
package/dist/pr_lifecycle.d.ts
CHANGED
|
@@ -298,7 +298,7 @@ export declare function deliverHeadless(cb: PrCallback): Promise<string[]>;
|
|
|
298
298
|
/**
|
|
299
299
|
* `werkmeister pr watch` (desktop: false) and the werkmeister mod's timer (desktop: true): one
|
|
300
300
|
* pass over every workspace. Headless claims are delivered here; desktop claims are returned
|
|
301
|
-
* for the mod to send through the app, then one idle-reaper pass
|
|
301
|
+
* for the mod to send through the app, then one idle-reaper pass. Never merges and
|
|
302
302
|
* never closes out.
|
|
303
303
|
*/
|
|
304
304
|
export declare function watchPrs(opts: {
|
|
@@ -384,7 +384,7 @@ export declare function openTerminalSessions(ws: string, run?: Run, ownedDir?: s
|
|
|
384
384
|
/**
|
|
385
385
|
* The one end-of-workspace verb (#160). Shipped: close the issue, write closeout.md, remove, delete
|
|
386
386
|
* the merged branches. With *abandon*: record the reason, leave the issue, remove (which pushes every
|
|
387
|
-
* branch) and keep the branches. With *noPr
|
|
387
|
+
* branch) and keep the branches. With *noPr*: the work changed no repo, so close as done
|
|
388
388
|
* with the reason instead of a PR.
|
|
389
389
|
*/
|
|
390
390
|
export declare function closeOut(name: string, opts?: {
|
package/dist/pr_lifecycle.js
CHANGED
|
@@ -2065,7 +2065,7 @@ async function fixLeftBehind(dir, deps) {
|
|
|
2065
2065
|
/**
|
|
2066
2066
|
* `werkmeister pr watch` (desktop: false) and the werkmeister mod's timer (desktop: true): one
|
|
2067
2067
|
* pass over every workspace. Headless claims are delivered here; desktop claims are returned
|
|
2068
|
-
* for the mod to send through the app, then one idle-reaper pass
|
|
2068
|
+
* for the mod to send through the app, then one idle-reaper pass. Never merges and
|
|
2069
2069
|
* never closes out.
|
|
2070
2070
|
*/
|
|
2071
2071
|
export async function watchPrs(opts, deps = defaultDeps(), send = deliverHeadless, idleLock = path.join(sandboxHome(), "idle-stop.lock")) {
|
|
@@ -2451,7 +2451,7 @@ export async function openTerminalSessions(ws, run = execRun, ownedDir = vscodeT
|
|
|
2451
2451
|
/**
|
|
2452
2452
|
* The one end-of-workspace verb (#160). Shipped: close the issue, write closeout.md, remove, delete
|
|
2453
2453
|
* the merged branches. With *abandon*: record the reason, leave the issue, remove (which pushes every
|
|
2454
|
-
* branch) and keep the branches. With *noPr
|
|
2454
|
+
* branch) and keep the branches. With *noPr*: the work changed no repo, so close as done
|
|
2455
2455
|
* with the reason instead of a PR.
|
|
2456
2456
|
*/
|
|
2457
2457
|
export async function closeOut(name, opts = {}, deps = defaultDeps()) {
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -52,7 +52,8 @@ export interface CreateResult {
|
|
|
52
52
|
* that shells out to the CLI (dashboard, MCP servers) must come through here rather than hand-rolling its own order.
|
|
53
53
|
*
|
|
54
54
|
* Order: $WERKMEISTER_BIN → $WERKMEISTER_ROOT/werkmeister → walk up from this module to the
|
|
55
|
-
* checkout root that owns the CLI package → the
|
|
55
|
+
* checkout root that owns the CLI package → the installed CLI package of the `werkmeister`
|
|
56
|
+
* on PATH (SW-695, for an npm-installed core) → the `~/.local/bin/werkmeister` symlink.
|
|
56
57
|
*
|
|
57
58
|
* WERKMEISTER_ROOT is the machine-global pointer at the *running* checkout: `werkmeister
|
|
58
59
|
* config` generates it into `~/.werkmeister/env.sh`, which `~/.zshenv` and the
|
|
@@ -60,8 +61,8 @@ export interface CreateResult {
|
|
|
60
61
|
* two resolve to whichever checkout happens to be nearest or globally linked,
|
|
61
62
|
* which is the wrong one as soon as you work out of a feature worktree.
|
|
62
63
|
*
|
|
63
|
-
*
|
|
64
|
-
* environment a GUI-launched process inherits.
|
|
64
|
+
* Every step but the installed-CLI one is a path lookup, not a PATH lookup — robust to
|
|
65
|
+
* the stripped environment a GUI-launched process inherits.
|
|
65
66
|
*/
|
|
66
67
|
export declare function resolveSandboxBin(opts?: {
|
|
67
68
|
from?: string;
|
|
@@ -165,7 +166,7 @@ export interface WorkspaceEntry {
|
|
|
165
166
|
/** {@link lifecycleOf}'s state: PR files only, no network. */
|
|
166
167
|
lifecycle: Lifecycle;
|
|
167
168
|
}
|
|
168
|
-
/** start_session's arguments for the workspace at `dir
|
|
169
|
+
/** start_session's arguments for the workspace at `dir`: the pane's ▶ Start work and `werkmeister workspace prompt --args`. */
|
|
169
170
|
export declare function startArgs(dir: string): Promise<StartArgs>;
|
|
170
171
|
/**
|
|
171
172
|
* List the workspaces (immediate subdirectories) under the workspaces root,
|
|
@@ -834,7 +835,7 @@ export declare function resumeClaudeInTerminal(name: string, sessionId?: string,
|
|
|
834
835
|
/** Where it opened. */
|
|
835
836
|
launcher: Launcher;
|
|
836
837
|
}>;
|
|
837
|
-
/** Opens a Terminal window following the workspace's container logs, for the pane's Logs
|
|
838
|
+
/** Opens a Terminal window following the workspace's container logs, for the pane's Logs. */
|
|
838
839
|
export declare function followLogsInTerminal(name: string): Promise<{
|
|
839
840
|
/** The feature (from the workspace's `.env`) whose logs the Terminal follows. */
|
|
840
841
|
feature: string;
|
package/dist/sandbox.js
CHANGED
|
@@ -41,7 +41,7 @@ export { childEnv } from "./tool_bins.js";
|
|
|
41
41
|
// Type-only: erased at build, so this adds nothing to the bundle.
|
|
42
42
|
import { isOneShotService, projectName } from "./compose.js";
|
|
43
43
|
import { INFRA_PROJECT, K8S_FORWARDS_CONTAINER } from "./compose_infra.js";
|
|
44
|
-
import { dotDir, envVar, forwardSpecs, loadServices, portsYamlPath, sandboxHome, servicesYamlPath, slotPortRange, workspacesRoot, } from "./config.js";
|
|
44
|
+
import { dotDir, envVar, forwardSpecs, installedCliPackage, loadServices, portsYamlPath, sandboxHome, servicesYamlPath, slotPortRange, workspacesRoot, } from "./config.js";
|
|
45
45
|
import { containerRunning, projectContainers } from "./docker.js";
|
|
46
46
|
import { WorkspaceError } from "./errors.js";
|
|
47
47
|
import { buildFormSchema } from "./form_schema.js";
|
|
@@ -88,7 +88,8 @@ async function isDir(p) {
|
|
|
88
88
|
* that shells out to the CLI (dashboard, MCP servers) must come through here rather than hand-rolling its own order.
|
|
89
89
|
*
|
|
90
90
|
* Order: $WERKMEISTER_BIN → $WERKMEISTER_ROOT/werkmeister → walk up from this module to the
|
|
91
|
-
* checkout root that owns the CLI package → the
|
|
91
|
+
* checkout root that owns the CLI package → the installed CLI package of the `werkmeister`
|
|
92
|
+
* on PATH (SW-695, for an npm-installed core) → the `~/.local/bin/werkmeister` symlink.
|
|
92
93
|
*
|
|
93
94
|
* WERKMEISTER_ROOT is the machine-global pointer at the *running* checkout: `werkmeister
|
|
94
95
|
* config` generates it into `~/.werkmeister/env.sh`, which `~/.zshenv` and the
|
|
@@ -96,8 +97,8 @@ async function isDir(p) {
|
|
|
96
97
|
* two resolve to whichever checkout happens to be nearest or globally linked,
|
|
97
98
|
* which is the wrong one as soon as you work out of a feature worktree.
|
|
98
99
|
*
|
|
99
|
-
*
|
|
100
|
-
* environment a GUI-launched process inherits.
|
|
100
|
+
* Every step but the installed-CLI one is a path lookup, not a PATH lookup — robust to
|
|
101
|
+
* the stripped environment a GUI-launched process inherits.
|
|
101
102
|
*/
|
|
102
103
|
export async function resolveSandboxBin(opts = {}) {
|
|
103
104
|
const explicit = envVar("BIN");
|
|
@@ -120,6 +121,12 @@ export async function resolveSandboxBin(opts = {}) {
|
|
|
120
121
|
break;
|
|
121
122
|
dir = parent;
|
|
122
123
|
}
|
|
124
|
+
const installed = installedCliPackage();
|
|
125
|
+
if (installed) {
|
|
126
|
+
const cand = path.join(installed, "werkmeister");
|
|
127
|
+
if (await isExecutable(cand))
|
|
128
|
+
return cand;
|
|
129
|
+
}
|
|
123
130
|
const local = path.join(os.homedir(), ".local", "bin", "werkmeister");
|
|
124
131
|
if (await isExecutable(local))
|
|
125
132
|
return local;
|
|
@@ -622,7 +629,7 @@ async function readWorkspaceConfig(workspaceDir) {
|
|
|
622
629
|
};
|
|
623
630
|
}
|
|
624
631
|
}
|
|
625
|
-
/** start_session's arguments for the workspace at `dir
|
|
632
|
+
/** start_session's arguments for the workspace at `dir`: the pane's ▶ Start work and `werkmeister workspace prompt --args`. */
|
|
626
633
|
export async function startArgs(dir) {
|
|
627
634
|
return buildStartArgs({ name: path.basename(dir), ...(await readWorkspaceConfig(dir)) });
|
|
628
635
|
}
|
|
@@ -2494,7 +2501,7 @@ export async function resumeClaudeInTerminal(name, sessionId, fresh = false, pro
|
|
|
2494
2501
|
const opened = await openClaudeSession(`cd ${shellQuote(target)} && ${harnessFor(target).resumeCommand(resumeId, model, prompt)}`, claudeLaunchUri({ workspace: path.basename(target), sessionId: resumeId, prompt }), true, launcher);
|
|
2495
2502
|
return { path: target, sessionId: resumeId, launcher: opened };
|
|
2496
2503
|
}
|
|
2497
|
-
/** Opens a Terminal window following the workspace's container logs, for the pane's Logs
|
|
2504
|
+
/** Opens a Terminal window following the workspace's container logs, for the pane's Logs. */
|
|
2498
2505
|
export async function followLogsInTerminal(name) {
|
|
2499
2506
|
const target = await resolveWorkspaceDir(name);
|
|
2500
2507
|
const feature = await readEnvValue(target, "FEATURE");
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
* Only `werkmeister-core/sdk` is public API and follows semver. Every other entry point, including
|
|
5
|
-
* the package root (`werkmeister-core`) and subpaths like `werkmeister-core/config`, is internal to
|
|
6
|
-
* werkmeister and can change in any release. `werkmeister-core` is versioned in lockstep with the
|
|
7
|
-
* werkmeister CLI: install the same version as the CLI you run. While the version is 0.x, a breaking
|
|
8
|
-
* change to `werkmeister-core/sdk` comes in a minor release, and its changelog entry says so.
|
|
2
|
+
* The exported functions, types and errors of the werkmeister SDK.
|
|
9
3
|
* @module
|
|
10
4
|
*/
|
|
11
5
|
export { clearNotice } from "./agent_state.js";
|
package/dist/sdk.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
* Only `werkmeister-core/sdk` is public API and follows semver. Every other entry point, including
|
|
5
|
-
* the package root (`werkmeister-core`) and subpaths like `werkmeister-core/config`, is internal to
|
|
6
|
-
* werkmeister and can change in any release. `werkmeister-core` is versioned in lockstep with the
|
|
7
|
-
* werkmeister CLI: install the same version as the CLI you run. While the version is 0.x, a breaking
|
|
8
|
-
* change to `werkmeister-core/sdk` comes in a minor release, and its changelog entry says so.
|
|
2
|
+
* The exported functions, types and errors of the werkmeister SDK.
|
|
9
3
|
* @module
|
|
10
4
|
*/
|
|
11
5
|
export { clearNotice } from "./agent_state.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "werkmeister-core",
|
|
3
|
-
"version": "0.90.
|
|
3
|
+
"version": "0.90.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "werkmeister's shared library. Its public API is werkmeister-core/sdk; every other entry point is internal.",
|
|
@@ -104,7 +104,6 @@
|
|
|
104
104
|
"./worktrees": "./dist/worktrees.js"
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"@anthropic-ai/claude-agent-sdk": "^0.3.288",
|
|
108
107
|
"@types/dockerode": "^4.0.1",
|
|
109
108
|
"@types/tar-fs": "^2.0.4",
|
|
110
109
|
"ajv": "^8.20.0",
|
|
@@ -114,7 +113,17 @@
|
|
|
114
113
|
"tar-fs": "^2.1.5",
|
|
115
114
|
"yaml": "^2.9.0"
|
|
116
115
|
},
|
|
116
|
+
"//peerDependencies": "SW-694: only the lazy ask helpers load the agent SDK, and it pulls a ~240 MB platform binary, so a library install leaves it out.",
|
|
117
|
+
"peerDependencies": {
|
|
118
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.288"
|
|
119
|
+
},
|
|
120
|
+
"peerDependenciesMeta": {
|
|
121
|
+
"@anthropic-ai/claude-agent-sdk": {
|
|
122
|
+
"optional": true
|
|
123
|
+
}
|
|
124
|
+
},
|
|
117
125
|
"devDependencies": {
|
|
126
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.288",
|
|
118
127
|
"@types/node": "^22.10.0",
|
|
119
128
|
"@types/nunjucks": "^3.2.6",
|
|
120
129
|
"typedoc": "0.28.20",
|