@edspencer/paddock 0.80.0 → 0.81.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/package.json +1 -1
- package/packages/server/dist/app.d.ts +7 -0
- package/packages/server/dist/app.js +1 -1
- package/packages/server/dist/auth.d.ts +3 -2
- package/packages/server/dist/auth.js +11 -0
- package/packages/server/dist/background-live.d.ts +17 -0
- package/packages/server/dist/background-live.js +24 -0
- package/packages/server/dist/busy.d.ts +96 -0
- package/packages/server/dist/busy.js +88 -0
- package/packages/server/dist/cli/args.d.ts +20 -4
- package/packages/server/dist/cli/args.js +120 -7
- package/packages/server/dist/cli/busy-command.d.ts +58 -0
- package/packages/server/dist/cli/busy-command.js +108 -0
- package/packages/server/dist/cli/busy.d.ts +69 -0
- package/packages/server/dist/cli/busy.js +150 -0
- package/packages/server/dist/cli/output.d.ts +52 -0
- package/packages/server/dist/cli/output.js +84 -0
- package/packages/server/dist/cli/paddock.js +16 -2
- package/packages/server/dist/cli/service/index.d.ts +12 -0
- package/packages/server/dist/cli/service/index.js +38 -4
- package/packages/server/dist/cli/service/launchd.d.ts +15 -1
- package/packages/server/dist/cli/service/launchd.js +116 -18
- package/packages/server/dist/herdctl.d.ts +19 -0
- package/packages/server/dist/herdctl.js +26 -0
- package/packages/server/dist/routes/meta.js +45 -0
- package/packages/server/dist/runtime-file.d.ts +26 -0
- package/packages/server/dist/runtime-file.js +91 -0
- package/packages/server/dist/start.d.ts +33 -0
- package/packages/server/dist/start.js +115 -8
- package/packages/server/dist/ws-context.d.ts +9 -0
- package/packages/server/dist/ws-turn.js +1 -0
- package/packages/server/package.json +1 -1
- package/packages/web/dist/assets/{DeleteProjectDialog-DHczLhwQ.js → DeleteProjectDialog-D8oIJ8HC.js} +1 -1
- package/packages/web/dist/assets/DiscoverPage-CQlzxsn4.js +2 -0
- package/packages/web/dist/assets/{DiscoverView-DtTOpTji.js → DiscoverView-o0KCr3aB.js} +1 -1
- package/packages/web/dist/assets/{InstanceConfigPage-BRoBh1C1.js → InstanceConfigPage-RSJz7oL3.js} +1 -1
- package/packages/web/dist/assets/{MarkdownRenderer-DJf8IJuk.js → MarkdownRenderer-39mafH8b.js} +1 -1
- package/packages/web/dist/assets/{ProjectRedirect-EioguUKW.js → ProjectRedirect-Bq7GVguY.js} +1 -1
- package/packages/web/dist/assets/{ProjectView-BiKnGfk6.js → ProjectView-BoBIru1g.js} +3 -3
- package/packages/web/dist/assets/{ProjectsGrid-D6kfaIal.js → ProjectsGrid-mJ4gqbr6.js} +1 -1
- package/packages/web/dist/assets/{RootHome-DpcyuV6e.js → RootHome-C0kwFyYp.js} +1 -1
- package/packages/web/dist/assets/{Surfaces-CHM29PhP.js → Surfaces-MkhXlB8z.js} +1 -1
- package/packages/web/dist/assets/{arc-fiqD05Hu.js → arc-DExlwAwO.js} +1 -1
- package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-BuuB2Nkf.js → architectureDiagram-3BPJPVTR-CZly3W79.js} +1 -1
- package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-DQMBuzfi.js → blockDiagram-GPEHLZMM-AgES73i3.js} +1 -1
- package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-BKN0UxCH.js → c4Diagram-AAUBKEIU-N9mD8Pfk.js} +1 -1
- package/packages/web/dist/assets/channel-ExsAG7qT.js +2 -0
- package/packages/web/dist/assets/{chunk-2J33WTMH-DW37EupX.js → chunk-2J33WTMH-Dsx_kfUl.js} +1 -1
- package/packages/web/dist/assets/{chunk-4BX2VUAB-Dyv7zV_c.js → chunk-4BX2VUAB-BQjqcjPj.js} +1 -1
- package/packages/web/dist/assets/{chunk-55IACEB6-DzMR0dOk.js → chunk-55IACEB6-CCxpYQpY.js} +1 -1
- package/packages/web/dist/assets/{chunk-727SXJPM-BdZ3Sor8.js → chunk-727SXJPM-DpFRdnUa.js} +1 -1
- package/packages/web/dist/assets/{chunk-AQP2D5EJ-B4i7_og0.js → chunk-AQP2D5EJ-D2BAlzoO.js} +1 -1
- package/packages/web/dist/assets/{chunk-FMBD7UC4-jcTr85it.js → chunk-FMBD7UC4-BFaMRzUF.js} +1 -1
- package/packages/web/dist/assets/{chunk-ND2GUHAM-fgMsadqB.js → chunk-ND2GUHAM-B9NGJ9xZ.js} +1 -1
- package/packages/web/dist/assets/{chunk-QZHKN3VN-bJNHYS1W.js → chunk-QZHKN3VN-CF1IHyMS.js} +1 -1
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-si7g9okq.js +2 -0
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-si7g9okq.js +2 -0
- package/packages/web/dist/assets/{core-Bk4KFrmN.js → core-XjElsvQ7.js} +1 -1
- package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-BIqCSlQy.js → cose-bilkent-S5V4N54A-CF972Flx.js} +1 -1
- package/packages/web/dist/assets/{dagre-BM42HDAG-6nyhtVQz.js → dagre-BM42HDAG-DsneI8YE.js} +1 -1
- package/packages/web/dist/assets/{diagram-2AECGRRQ-CjizfipR.js → diagram-2AECGRRQ-BHyrVzIk.js} +1 -1
- package/packages/web/dist/assets/{diagram-5GNKFQAL-DlgB5vWb.js → diagram-5GNKFQAL-Dj4q8xEi.js} +1 -1
- package/packages/web/dist/assets/{diagram-KO2AKTUF-CNC9qanV.js → diagram-KO2AKTUF-BHe3Puv_.js} +1 -1
- package/packages/web/dist/assets/{diagram-LMA3HP47-DSJ-s9lh.js → diagram-LMA3HP47-wzt6G2FE.js} +1 -1
- package/packages/web/dist/assets/{diagram-OG6HWLK6-C9FoHBDg.js → diagram-OG6HWLK6-CZMbMRJq.js} +1 -1
- package/packages/web/dist/assets/{documentTitle-Cj_AY97j.js → documentTitle-BwTIA8rI.js} +1 -1
- package/packages/web/dist/assets/{erDiagram-TEJ5UH35-z6gku4Yt.js → erDiagram-TEJ5UH35-Dtu14BL1.js} +1 -1
- package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-Dl5c_FgU.js → flowDiagram-I6XJVG4X-T34ql9j0.js} +1 -1
- package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-CIscJ-Dt.js → ganttDiagram-6RSMTGT7-DQLOeCXK.js} +1 -1
- package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-CvttOXM_.js → gitGraphDiagram-PVQCEYII-Bk11zea6.js} +1 -1
- package/packages/web/dist/assets/{index-DN82do6Z.js → index-CvaWErFv.js} +2 -2
- package/packages/web/dist/assets/{infoDiagram-5YYISTIA-dzWYdDJj.js → infoDiagram-5YYISTIA-CsE83lu0.js} +1 -1
- package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-8yX9k4bo.js → ishikawaDiagram-YF4QCWOH-DNVgA93n.js} +1 -1
- package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-BmitzJDR.js → journeyDiagram-JHISSGLW-CLpSNjM3.js} +1 -1
- package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-BZmIkfkW.js → kanban-definition-UN3LZRKU-BRzuXcKr.js} +1 -1
- package/packages/web/dist/assets/{linear-BBLXE4o7.js → linear-BxOawONt.js} +1 -1
- package/packages/web/dist/assets/{mermaid.core-mSKff4yu.js → mermaid.core-Dvs1QCcz.js} +4 -4
- package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-BWAUa4CP.js → mindmap-definition-RKZ34NQL-Dmt7pYwF.js} +1 -1
- package/packages/web/dist/assets/{pieDiagram-4H26LBE5-VmVdiL4C.js → pieDiagram-4H26LBE5-BHiZaJD-.js} +1 -1
- package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-Dybfv6NU.js → quadrantDiagram-W4KKPZXB-U0A1noRE.js} +1 -1
- package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-BPnOvB7w.js → requirementDiagram-4Y6WPE33-CZLsr6yi.js} +1 -1
- package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-YXIEmKw7.js → sankeyDiagram-5OEKKPKP-BTlLGILU.js} +1 -1
- package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-DintIRUe.js → sequenceDiagram-3UESZ5HK-DpSS_Gb1.js} +1 -1
- package/packages/web/dist/assets/{stateDiagram-AJRCARHV-eMsjahWp.js → stateDiagram-AJRCARHV-D9srE-tV.js} +1 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-AxWqsDh-.js +2 -0
- package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-as4zRCPn.js → timeline-definition-PNZ67QCA-BYQ5CKab.js} +1 -1
- package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-CPzvUkM0.js → vennDiagram-CIIHVFJN-B4W2CtSV.js} +1 -1
- package/packages/web/dist/assets/{wardley-L42UT6IY-q6moXj5g.js → wardley-L42UT6IY--XUV7GvD.js} +1 -1
- package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-BsEEb9Gm.js → wardleyDiagram-YWT4CUSO-Bl2VIEGY.js} +1 -1
- package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-DSgZlcZW.js → xychartDiagram-2RQKCTM6-Bj2H9Rcf.js} +1 -1
- package/packages/web/dist/index.html +1 -1
- package/packages/web/dist/sw.js +1 -1
- package/packages/web/dist/assets/DiscoverPage-BSGSzTEs.js +0 -2
- package/packages/web/dist/assets/channel-B7yh6Su_.js +0 -2
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-DIlhMPgi.js +0 -2
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-DIlhMPgi.js +0 -2
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-CpAOGzbO.js +0 -2
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import { GitService } from "./git.js";
|
|
|
17
17
|
import { GithubAuth } from "./github-auth.js";
|
|
18
18
|
import { type Transcriber } from "./transcribe.js";
|
|
19
19
|
import type { SessionHub } from "./session-hub.js";
|
|
20
|
+
import type { BackgroundRegistry } from "./background-live.js";
|
|
20
21
|
import { SweepService } from "./sweep.js";
|
|
21
22
|
import { ArchiveStore } from "./archive.js";
|
|
22
23
|
import { StarStore } from "./star.js";
|
|
@@ -57,6 +58,12 @@ export interface BuiltApp {
|
|
|
57
58
|
* same way, via the route context).
|
|
58
59
|
*/
|
|
59
60
|
hub: SessionHub;
|
|
61
|
+
/**
|
|
62
|
+
* The live background-work registry (#604), exposed for the same reason `hub`
|
|
63
|
+
* is — it is WS-layer state a non-socket caller has to read. `GET /api/busy`
|
|
64
|
+
* reaches it through the route context; a test reaches it here.
|
|
65
|
+
*/
|
|
66
|
+
background: BackgroundRegistry;
|
|
60
67
|
/** Tear down the fleet + close the server (no process.exit, for tests). */
|
|
61
68
|
close: () => Promise<void>;
|
|
62
69
|
}
|
|
@@ -440,5 +440,5 @@ export async function buildApp(opts = {}) {
|
|
|
440
440
|
// `hub` rides along like every other built piece: it is the WS layer's turn
|
|
441
441
|
// bookkeeping, and the only place a caller can observe or annotate a turn
|
|
442
442
|
// without a live socket (see SessionHub.noteCancel).
|
|
443
|
-
return { app, cfg, projects, herdctl, git, githubAuth, sweep, archive, star, readState, unread, parentDetach, runProvenance, queuedMessage, transcriber, events, triggers, hub: chatHandler.managementOpsContext.hub, close };
|
|
443
|
+
return { app, cfg, projects, herdctl, git, githubAuth, sweep, archive, star, readState, unread, parentDetach, runProvenance, queuedMessage, transcriber, events, triggers, hub: chatHandler.managementOpsContext.hub, background: chatHandler.managementOpsContext.background, close };
|
|
444
444
|
}
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
* rejects missing/invalid/expired tokens with 401.
|
|
20
20
|
*
|
|
21
21
|
* Paddock's health route (`/api/health`) is always exempt so the proxy and
|
|
22
|
-
* monitoring can poll a server that is otherwise locked down
|
|
23
|
-
*
|
|
22
|
+
* monitoring can poll a server that is otherwise locked down, as is the CLI
|
|
23
|
+
* contract's `/api/busy` — which carries counts and nothing else. Only
|
|
24
|
+
* registered routes may be exempted — see HEALTH_PATHS below for why (#569).
|
|
24
25
|
*
|
|
25
26
|
* Registered in app.ts BEFORE the routes so the `onRequest` hook guards every
|
|
26
27
|
* REST + WS request. The decorator + hook are added directly to the root app
|
|
@@ -16,6 +16,17 @@ import { createRemoteJWKSet, jwtVerify, } from "jose";
|
|
|
16
16
|
*/
|
|
17
17
|
export const HEALTH_PATHS = new Set([
|
|
18
18
|
"/api/health", // paddock's own health route (routes/meta.ts)
|
|
19
|
+
// The CLI contract's busy check (SPEC §4, §8). Exempt for the same reason
|
|
20
|
+
// health is, and safe for a reason health does not need: the answer is three
|
|
21
|
+
// integers and the version, with no chat title, session id or project name in
|
|
22
|
+
// it — SPEC §10 keeps `reasons` out until there is a way for a caller to prove
|
|
23
|
+
// it is local. `paddock service stop`, `paddock update` and Watchtower's
|
|
24
|
+
// pre-update hook all ask it with no credential to offer, and a 401 would be
|
|
25
|
+
// read by `cli/busy.ts` as exit 1 rather than as "not busy" — so gating it
|
|
26
|
+
// would fail every stop on an authenticated instance.
|
|
27
|
+
//
|
|
28
|
+
// If this answer ever grows a label, this line has to be revisited with it.
|
|
29
|
+
"/api/busy", // routes/meta.ts
|
|
19
30
|
]);
|
|
20
31
|
/**
|
|
21
32
|
* Strip the query string and trailing slash so exemption matching is robust.
|
|
@@ -110,6 +110,23 @@ export declare class BackgroundRegistry {
|
|
|
110
110
|
}[];
|
|
111
111
|
/** Does this session have live background work? The #604 predicate. */
|
|
112
112
|
isBusy(sessionId: string): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* How many live background tasks there are, across the sessions `keep`
|
|
115
|
+
* accepts.
|
|
116
|
+
*
|
|
117
|
+
* The `/api/busy` check (CLI contract SPEC §4) passes herdctl's SDK liveness
|
|
118
|
+
* as `keep`, for the reason the per-process caveat in the module header gives:
|
|
119
|
+
* nothing resets this set when a one-shot `claude` exits, so on
|
|
120
|
+
* `driveMode: batch` a finished turn's tasks sit here indefinitely. Filtering
|
|
121
|
+
* on a live session is what stops a stale entry reporting a batch instance
|
|
122
|
+
* busy for good — and it costs nothing in `session` mode, where the reaper
|
|
123
|
+
* holds a session open precisely BECAUSE it has background work.
|
|
124
|
+
*
|
|
125
|
+
* Counted rather than listed so the busy check allocates nothing per task
|
|
126
|
+
* (§4: in-memory, well under a second). {@link snapshot} is the one that
|
|
127
|
+
* builds arrays, and it is for the connect-time frame.
|
|
128
|
+
*/
|
|
129
|
+
liveTaskCount(keep?: (sessionId: string) => boolean): number;
|
|
113
130
|
/**
|
|
114
131
|
* Forget a session's set. Called when the session's process restarts or its
|
|
115
132
|
* stream ends — see the per-process caveat in the module header.
|
|
@@ -142,6 +142,30 @@ export class BackgroundRegistry {
|
|
|
142
142
|
const e = this.bySession.get(sessionId);
|
|
143
143
|
return !!e && e.tasks.size > 0;
|
|
144
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* How many live background tasks there are, across the sessions `keep`
|
|
147
|
+
* accepts.
|
|
148
|
+
*
|
|
149
|
+
* The `/api/busy` check (CLI contract SPEC §4) passes herdctl's SDK liveness
|
|
150
|
+
* as `keep`, for the reason the per-process caveat in the module header gives:
|
|
151
|
+
* nothing resets this set when a one-shot `claude` exits, so on
|
|
152
|
+
* `driveMode: batch` a finished turn's tasks sit here indefinitely. Filtering
|
|
153
|
+
* on a live session is what stops a stale entry reporting a batch instance
|
|
154
|
+
* busy for good — and it costs nothing in `session` mode, where the reaper
|
|
155
|
+
* holds a session open precisely BECAUSE it has background work.
|
|
156
|
+
*
|
|
157
|
+
* Counted rather than listed so the busy check allocates nothing per task
|
|
158
|
+
* (§4: in-memory, well under a second). {@link snapshot} is the one that
|
|
159
|
+
* builds arrays, and it is for the connect-time frame.
|
|
160
|
+
*/
|
|
161
|
+
liveTaskCount(keep = () => true) {
|
|
162
|
+
let n = 0;
|
|
163
|
+
for (const [sessionId, e] of this.bySession) {
|
|
164
|
+
if (e.tasks.size > 0 && keep(sessionId))
|
|
165
|
+
n += e.tasks.size;
|
|
166
|
+
}
|
|
167
|
+
return n;
|
|
168
|
+
}
|
|
145
169
|
/**
|
|
146
170
|
* Forget a session's set. Called when the session's process restarts or its
|
|
147
171
|
* stream ends — see the per-process caveat in the module header.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `GET /api/busy` answers (CLI contract SPEC §4, ROADMAP "Busy, per tool").
|
|
3
|
+
*
|
|
4
|
+
* ## What "busy" means here
|
|
5
|
+
*
|
|
6
|
+
* Only work **a restart would lose or cut short** — the kind someone would be
|
|
7
|
+
* annoyed to find killed. For Paddock that is three things, and the ROADMAP row
|
|
8
|
+
* names them:
|
|
9
|
+
*
|
|
10
|
+
* - **`chat`** — a chat turn running. This is the one that matters: a turn is a
|
|
11
|
+
* live `claude` subprocess writing a transcript, and `herdctl.stop()` ends it
|
|
12
|
+
* with `waitForJobs: false`. A fired trigger or a cron schedule is NOT a
|
|
13
|
+
* fourth kind, because every one of them runs as a first-class chat on the
|
|
14
|
+
* hub (`ws-triggers.ts` — one `startAgentTurn` for every trigger type), so it
|
|
15
|
+
* is already counted here.
|
|
16
|
+
* - **`background`** — background work a live SDK session is still holding
|
|
17
|
+
* after its turn ended (#604): a `run_in_background` shell, a sub-agent, a
|
|
18
|
+
* `Monitor`. These outlive the `Turn` record, so the hub cannot see them.
|
|
19
|
+
* - **`job`** — herdctl's scheduler running a job. Paddock routes a keeper's
|
|
20
|
+
* schedule fire back onto the hub, so in practice this double-counts with
|
|
21
|
+
* `chat` for the window where both are true; a count that is occasionally
|
|
22
|
+
* high by one is the right failure direction for a check whose answer is
|
|
23
|
+
* "wait a moment".
|
|
24
|
+
*
|
|
25
|
+
* ## What is deliberately NOT busy
|
|
26
|
+
*
|
|
27
|
+
* - **Idle live sessions.** A session the reaper is holding open with no turn
|
|
28
|
+
* and no background task resumes after a restart; that is the whole point of
|
|
29
|
+
* a resumable session.
|
|
30
|
+
* - **The post-turn sweeper.** It is re-runnable from its watermark, so losing
|
|
31
|
+
* one is a re-sweep rather than lost work. The ROADMAP row leaves it out too.
|
|
32
|
+
* - **Open browsers.** A page reconnects to `/ws` and replays.
|
|
33
|
+
*
|
|
34
|
+
* ## Cheap, and in-memory only
|
|
35
|
+
*
|
|
36
|
+
* §4 requires this to read in-memory state, never walk the disk, and answer in
|
|
37
|
+
* well under a second — it is called by Watchtower's pre-update hook and by
|
|
38
|
+
* every `service stop`. So each source here is a `Map.size` or a filtered
|
|
39
|
+
* iteration over one, and {@link collectBusy} is synchronous.
|
|
40
|
+
*
|
|
41
|
+
* That rules out the obvious source for `job`. `fleetStatus().counts.runningJobs`
|
|
42
|
+
* is what the ROADMAP names, and `FleetStatus` is built by `getAgentInfo()`,
|
|
43
|
+
* which **reads the fleet state file off disk** on every call (herdctl's
|
|
44
|
+
* `StatusQueries.readFleetStateSnapshot`) — the same re-parse that was 61% of
|
|
45
|
+
* this server's CPU once. `counts.runningJobs` reduces to
|
|
46
|
+
* `Σ scheduler.getRunningJobCount(agent)`, and the scheduler also publishes
|
|
47
|
+
* `getTotalRunningJobCount()` over the same in-memory map, so Paddock asks the
|
|
48
|
+
* scheduler directly for an identical number with no file read.
|
|
49
|
+
*
|
|
50
|
+
* ## No labels, ids or titles
|
|
51
|
+
*
|
|
52
|
+
* Counts only, for every caller, until SPEC §10's first question (how a CLI
|
|
53
|
+
* proves it is local) is designed. That is why this route needs no auth: there
|
|
54
|
+
* is nothing in the answer to protect. A chat's TITLE would be a different
|
|
55
|
+
* matter, and is exactly what `reasons` will carry once there is a way to know
|
|
56
|
+
* who is asking — so nothing here may grow a string field by accident.
|
|
57
|
+
*/
|
|
58
|
+
/** The non-zero kinds the CLI's message names: `Paddock is busy: 2 chats are running.` */
|
|
59
|
+
export interface BusyCounts {
|
|
60
|
+
/** Chat turns running — a human turn, a fired trigger, a cron fire. */
|
|
61
|
+
chat: number;
|
|
62
|
+
/** Background tasks live sessions are still holding after their turn (#604). */
|
|
63
|
+
background: number;
|
|
64
|
+
/** herdctl scheduler jobs in flight. */
|
|
65
|
+
job: number;
|
|
66
|
+
}
|
|
67
|
+
/** The `/api/busy` body (SPEC §4). */
|
|
68
|
+
export interface BusyBody {
|
|
69
|
+
busy: boolean;
|
|
70
|
+
version: string;
|
|
71
|
+
counts: BusyCounts;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The three in-memory readings, injected so the computation is unit-testable
|
|
75
|
+
* without a fleet, a hub or a socket. Each must be cheap enough to call on every
|
|
76
|
+
* request — see the module header.
|
|
77
|
+
*/
|
|
78
|
+
export interface BusySources {
|
|
79
|
+
/** Sessions with a running turn: `hub.runningSessions().length`. */
|
|
80
|
+
runningChats: () => number;
|
|
81
|
+
/** Live background tasks, counted only in sessions whose SDK session is live. */
|
|
82
|
+
backgroundTasks: () => number;
|
|
83
|
+
/** Scheduler jobs running right now. */
|
|
84
|
+
runningJobs: () => number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Read the three counts and decide busy.
|
|
88
|
+
*
|
|
89
|
+
* `busy` is `counts` having any non-zero member rather than a separately
|
|
90
|
+
* computed predicate, so the sentence the CLI prints can never disagree with the
|
|
91
|
+
* boolean it printed it for. A source that throws counts as zero: a busy check
|
|
92
|
+
* that 500s is worse than one that under-reports, because a 500 is read by
|
|
93
|
+
* `busy-client.ts` as "something answered, but not as Paddock's busy check" —
|
|
94
|
+
* exit 1 — which fails a `service stop` outright instead of letting it proceed.
|
|
95
|
+
*/
|
|
96
|
+
export declare function collectBusy(sources: BusySources, version: string): BusyBody;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `GET /api/busy` answers (CLI contract SPEC §4, ROADMAP "Busy, per tool").
|
|
3
|
+
*
|
|
4
|
+
* ## What "busy" means here
|
|
5
|
+
*
|
|
6
|
+
* Only work **a restart would lose or cut short** — the kind someone would be
|
|
7
|
+
* annoyed to find killed. For Paddock that is three things, and the ROADMAP row
|
|
8
|
+
* names them:
|
|
9
|
+
*
|
|
10
|
+
* - **`chat`** — a chat turn running. This is the one that matters: a turn is a
|
|
11
|
+
* live `claude` subprocess writing a transcript, and `herdctl.stop()` ends it
|
|
12
|
+
* with `waitForJobs: false`. A fired trigger or a cron schedule is NOT a
|
|
13
|
+
* fourth kind, because every one of them runs as a first-class chat on the
|
|
14
|
+
* hub (`ws-triggers.ts` — one `startAgentTurn` for every trigger type), so it
|
|
15
|
+
* is already counted here.
|
|
16
|
+
* - **`background`** — background work a live SDK session is still holding
|
|
17
|
+
* after its turn ended (#604): a `run_in_background` shell, a sub-agent, a
|
|
18
|
+
* `Monitor`. These outlive the `Turn` record, so the hub cannot see them.
|
|
19
|
+
* - **`job`** — herdctl's scheduler running a job. Paddock routes a keeper's
|
|
20
|
+
* schedule fire back onto the hub, so in practice this double-counts with
|
|
21
|
+
* `chat` for the window where both are true; a count that is occasionally
|
|
22
|
+
* high by one is the right failure direction for a check whose answer is
|
|
23
|
+
* "wait a moment".
|
|
24
|
+
*
|
|
25
|
+
* ## What is deliberately NOT busy
|
|
26
|
+
*
|
|
27
|
+
* - **Idle live sessions.** A session the reaper is holding open with no turn
|
|
28
|
+
* and no background task resumes after a restart; that is the whole point of
|
|
29
|
+
* a resumable session.
|
|
30
|
+
* - **The post-turn sweeper.** It is re-runnable from its watermark, so losing
|
|
31
|
+
* one is a re-sweep rather than lost work. The ROADMAP row leaves it out too.
|
|
32
|
+
* - **Open browsers.** A page reconnects to `/ws` and replays.
|
|
33
|
+
*
|
|
34
|
+
* ## Cheap, and in-memory only
|
|
35
|
+
*
|
|
36
|
+
* §4 requires this to read in-memory state, never walk the disk, and answer in
|
|
37
|
+
* well under a second — it is called by Watchtower's pre-update hook and by
|
|
38
|
+
* every `service stop`. So each source here is a `Map.size` or a filtered
|
|
39
|
+
* iteration over one, and {@link collectBusy} is synchronous.
|
|
40
|
+
*
|
|
41
|
+
* That rules out the obvious source for `job`. `fleetStatus().counts.runningJobs`
|
|
42
|
+
* is what the ROADMAP names, and `FleetStatus` is built by `getAgentInfo()`,
|
|
43
|
+
* which **reads the fleet state file off disk** on every call (herdctl's
|
|
44
|
+
* `StatusQueries.readFleetStateSnapshot`) — the same re-parse that was 61% of
|
|
45
|
+
* this server's CPU once. `counts.runningJobs` reduces to
|
|
46
|
+
* `Σ scheduler.getRunningJobCount(agent)`, and the scheduler also publishes
|
|
47
|
+
* `getTotalRunningJobCount()` over the same in-memory map, so Paddock asks the
|
|
48
|
+
* scheduler directly for an identical number with no file read.
|
|
49
|
+
*
|
|
50
|
+
* ## No labels, ids or titles
|
|
51
|
+
*
|
|
52
|
+
* Counts only, for every caller, until SPEC §10's first question (how a CLI
|
|
53
|
+
* proves it is local) is designed. That is why this route needs no auth: there
|
|
54
|
+
* is nothing in the answer to protect. A chat's TITLE would be a different
|
|
55
|
+
* matter, and is exactly what `reasons` will carry once there is a way to know
|
|
56
|
+
* who is asking — so nothing here may grow a string field by accident.
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* Read the three counts and decide busy.
|
|
60
|
+
*
|
|
61
|
+
* `busy` is `counts` having any non-zero member rather than a separately
|
|
62
|
+
* computed predicate, so the sentence the CLI prints can never disagree with the
|
|
63
|
+
* boolean it printed it for. A source that throws counts as zero: a busy check
|
|
64
|
+
* that 500s is worse than one that under-reports, because a 500 is read by
|
|
65
|
+
* `busy-client.ts` as "something answered, but not as Paddock's busy check" —
|
|
66
|
+
* exit 1 — which fails a `service stop` outright instead of letting it proceed.
|
|
67
|
+
*/
|
|
68
|
+
export function collectBusy(sources, version) {
|
|
69
|
+
const counts = {
|
|
70
|
+
chat: safeCount(sources.runningChats),
|
|
71
|
+
background: safeCount(sources.backgroundTasks),
|
|
72
|
+
job: safeCount(sources.runningJobs),
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
busy: counts.chat > 0 || counts.background > 0 || counts.job > 0,
|
|
76
|
+
version,
|
|
77
|
+
counts,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function safeCount(read) {
|
|
81
|
+
try {
|
|
82
|
+
const n = read();
|
|
83
|
+
return Number.isInteger(n) && n > 0 ? n : 0;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -71,6 +71,16 @@ export interface CliOptions {
|
|
|
71
71
|
follow?: boolean;
|
|
72
72
|
/** `service logs`: how many lines to print first (`-n`, default 50). */
|
|
73
73
|
lines?: number;
|
|
74
|
+
/**
|
|
75
|
+
* `service stop` / `service restart`: go ahead even though the instance is
|
|
76
|
+
* busy (SPEC §1, §4).
|
|
77
|
+
*
|
|
78
|
+
* The refusal it skips is the only thing it skips. It does not change what the
|
|
79
|
+
* busy check printed — a forced stop prints the same sentence, prefixed
|
|
80
|
+
* `Overriding:` — and in wave C2 it will not skip `update`'s health check or
|
|
81
|
+
* its rollback either.
|
|
82
|
+
*/
|
|
83
|
+
force?: boolean;
|
|
74
84
|
}
|
|
75
85
|
/**
|
|
76
86
|
* A failure with an exit code attached (SPEC §2).
|
|
@@ -125,7 +135,7 @@ export type ConfigAction = (typeof CONFIG_ACTIONS)[number];
|
|
|
125
135
|
* Paddock and Managers, every existing service unit's `ExecStart` names it, and
|
|
126
136
|
* it is in two years of other people's scripts. They parse to the same command.
|
|
127
137
|
*/
|
|
128
|
-
export declare const VERBS: readonly ["serve", "start", "service", "config"];
|
|
138
|
+
export declare const VERBS: readonly ["serve", "start", "service", "config", "busy"];
|
|
129
139
|
/**
|
|
130
140
|
* A parsed invocation: which verb, plus the flags that followed it.
|
|
131
141
|
*
|
|
@@ -144,6 +154,11 @@ export type Command = {
|
|
|
144
154
|
verb: "config";
|
|
145
155
|
action: ConfigAction | undefined;
|
|
146
156
|
opts: CliOptions;
|
|
157
|
+
}
|
|
158
|
+
/** `busy` takes no action — it is one question with one answer (SPEC §1). */
|
|
159
|
+
| {
|
|
160
|
+
verb: "busy";
|
|
161
|
+
opts: CliOptions;
|
|
147
162
|
};
|
|
148
163
|
/**
|
|
149
164
|
* Split a leading verb off the argv, then parse the rest as flags.
|
|
@@ -196,7 +211,8 @@ export declare function explainListenError(err: unknown, host: string, port: str
|
|
|
196
211
|
* bury the one line explaining what went wrong. The full text is one
|
|
197
212
|
* `--help` away, and the last line here says so.
|
|
198
213
|
*/
|
|
199
|
-
export declare const USAGE_SYNOPSIS = "Usage\n paddock [serve] [options] run the server in this terminal\n paddock service <action> [options] install|uninstall|status|start|stop|restart|logs\n paddock config <show|eject> [options] what this instance's config resolved to\n paddock -v | --version print the version and exit\n paddock -h | --help the full help";
|
|
200
|
-
export declare const USAGE = "paddock \u2014 run a Paddock instance locally\n\nUsage\n npx @edspencer/paddock [options] run the server (the default)\n paddock serve [options] the same thing, said out loud\n (`paddock start` is a permanent alias)\n paddock service install [options] run it in the background from login\n paddock service uninstall stop it and remove the unit\n paddock service status [--json] installed? running? which version?\n paddock service start start an installed service\n paddock service stop
|
|
201
|
-
export declare const SERVICE_USAGE = "paddock service \u2014 keep Paddock running in the background\n\nUsage\n paddock service install [options] register it and start it now\n paddock service uninstall stop it and deregister it\n paddock service status [--json] is it registered, is it running, which\n version, where are the logs\n paddock service start start an installed service that is stopped\n paddock service stop
|
|
214
|
+
export declare const USAGE_SYNOPSIS = "Usage\n paddock [serve] [options] run the server in this terminal\n paddock service <action> [options] install|uninstall|status|start|stop|restart|logs\n paddock busy [--json] is the running instance busy?\n paddock config <show|eject> [options] what this instance's config resolved to\n paddock -v | --version print the version and exit\n paddock -h | --help the full help";
|
|
215
|
+
export declare const USAGE = "paddock \u2014 run a Paddock instance locally\n\nUsage\n npx @edspencer/paddock [options] run the server (the default)\n paddock serve [options] the same thing, said out loud\n (`paddock start` is a permanent alias)\n paddock service install [options] run it in the background from login\n paddock service uninstall stop it and remove the unit\n paddock service status [--json] installed? running? which version?\n paddock service start start an installed service\n paddock service stop [--force] stop it, leave it installed\n paddock service restart [--force] stop it and start it again\n paddock service logs [-f] [-n <lines>] the service's log\n (`paddock service --help`)\n paddock busy [--json] is it busy? exit 0 no, 75 yes, 3\n nothing answering\n (`paddock busy --help`)\n paddock config show [--resolved] what this instance's config resolved\n to, and where each value came from\n paddock config eject [--write] freeze that resolution into\n paddock.config.yaml\n (`paddock config --help`)\n\nOptions\n -p, --port <port> HTTP/WS port (default 7233, or $PORT)\n --host <host> Bind address (default 127.0.0.1)\n -d, --data-dir <path> Projects + state (default ~/.paddock, or $PADDOCK_DATA_DIR)\n -o, --open Open the app in your browser once it is listening\n --verbose Show the server's own logs (quiet by default)\n -v, --version Print the Paddock version and exit\n -h, --help Show this help\n\nExit codes\n 0 done; running and answering; not busy\n 1 failed\n 2 usage: an unknown command or flag, or a bad value\n 3 not running: installed, but not running or not answering; nothing answers\n 4 not installed: there is no service unit\n 75 busy: refused, and why was printed. Try later, or use --force\n\nOpening your own directories\n Where you run this from does not matter \u2014 the instance is decided by its data\n dir alone. Directories are added inside the app, on the Discover screen: it\n reads your Claude Code history, lists the directories you have worked in, and\n links the ones you tick as projects. A new instance opens on it.\n\n Importing a directory does not write into it. No .paddock/, no .chats/, no\n .gitignore edits, no CLAUDE.md \u2014 the project record and the copied transcripts\n both live in the data dir, and the project just points at the path. Your own\n ~/.claude transcripts are copied, never moved or deleted, so your terminal\n `claude` keeps working exactly as before.\n\nCredentials\n Paddock drives Claude Code, so it needs Claude credentials \u2014 and if you\n already use Claude Code on this machine, it uses the login you already have.\n That is a macOS Keychain entry on a Mac, or your ~/.claude/.credentials.json\n elsewhere (symlinked in, never copied). Reading a login writes nothing.\n\n Otherwise: a CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY in the environment,\n or a one-off `CLAUDE_CONFIG_DIR=<data-dir>/claude-home claude login`. With no\n login at all anywhere, run `claude setup-token`. Paddock says at startup when\n it can find none.\n\nPosture profiles\n One key picks how much Paddock shares and how much its agents may do:\n\n profile: balanced # paranoid | balanced | yolo (PADDOCK_PROFILE)\n\n paranoid shares nothing but the login and turns every capability off \u2014 the\n behaviour Paddock had before profiles existed. balanced (the default)\n inherits the CAPABILITIES your CLI already has \u2014 instructions, MCP servers,\n plugins \u2014 and adds the read-only self-management tools, while keeping your\n chat history Paddock's own. yolo turns the rest on: your transcripts, host\n hooks, the write and project tools, schedule mutation, deeper spawning, the\n browser.\n\n A profile only sets defaults \u2014 any single key still overrides it, and an\n individual key in the config file beats PADDOCK_PROFILE in the environment.\n Profiles never touch your port, bind address, auth or model list: yolo does\n NOT open the bind or relax auth, which stay a separate, explicit decision.\n\n What host actually reaches depends on the machine \u2014 a workstation has a real\n ~/.claude, a container usually has none. The profile sets the levers, the\n environment sets the blast radius.\n\n To see what your profile actually expanded to on THIS machine, with the layer\n each value came from: paddock config show --resolved\n\nSharing your Claude Code state\n Apart from that login, Paddock writes nothing outside its data dir by\n default: transcripts go to each project's .chats/, and your ~/.claude is read\n for config only. Each thing it can share is one key in\n <data-dir>/paddock.config.yaml, and each defaults to whatever your profile\n says (see Posture profiles below):\n\n claude:\n transcripts: host # own | host host on yolo only\n credentials: host # own | host host on every profile\n instructions: host # own | host own on paranoid, else host\n hooks: host # own | host host on yolo only\n mcpServers: host # own | host own on paranoid, else host\n\n transcripts: host makes a chat and a `claude --resume` in the same directory\n the same file, live in both directions; deleting such a chat in Paddock\n releases it rather than removing it, because it is your history rather than\n Paddock's copy. credentials: own is the opt-out from sharing the login above.\n\n instructions: host loads your ~/.claude CLAUDE.md, agents/, commands/ and\n plugins/. On from balanced up, so your curated CLAUDE.md does reach Paddock's\n agents; profile: paranoid or instructions: own keeps it out. Each project's\n own CLAUDE.md applies either way.\n\n hooks: host runs the shell commands your ~/.claude/settings.json binds to\n tool use. Off by default \u2014 inheriting someone's hooks is not something to\n discover after the fact. Its other keys (permissions, model, statusline)\n apply either way: under hooks: own Paddock writes its own settings.json\n carrying them with hooks dropped, regenerated at startup.\n\n mcpServers: host attaches the MCP servers declared in your ~/.claude.json \u2014\n the top-level ones, plus a project's own when its directory matches. To give\n this instance a server your machine doesn't have, declare it instead in a\n sibling mcpServers: block of the same file; use env:VAR_NAME anywhere a\n string goes so tokens stay out of it. That keeps a token out of the file, not\n out of `ps`: leave driveMode on its default (session) for a server holding\n one, since batch passes the definition to claude as a command-line argument.\n\nYour data\n Everything lives in one directory \u2014 ~/.paddock unless you pass --data-dir.\n Projects, chat transcripts and settings all persist there between runs. Move\n that directory to move your instance; delete it to start over. Nothing is\n stored anywhere else.\n\nNotes\n Binds loopback with authentication disabled, which is safe for a laptop. To\n expose it on a network, set PADDOCK_AUTH_MODE first \u2014 Paddock refuses to bind\n a routable interface wide open. See AUTH.md.\n\nDocs: https://github.com/edspencer/paddock";
|
|
216
|
+
export declare const SERVICE_USAGE = "paddock service \u2014 keep Paddock running in the background\n\nUsage\n paddock service install [options] register it and start it now\n paddock service uninstall stop it and deregister it\n paddock service status [--json] is it registered, is it running, which\n version, where are the logs\n paddock service start start an installed service that is stopped\n paddock service stop [--force] stop it, and leave it installed\n paddock service restart [--force] stop it and start it again, re-reading config\n paddock service logs [-f] [-n <n>] the service's log (the last 50 lines)\n\nOptions (logs)\n -f, --follow keep printing what gets appended, until Ctrl-C\n -n, --lines <n> how many lines to print first (default 50)\n\nOptions (stop, restart)\n --force stop it even though it is busy\n\nBusy\n `stop` and `restart` ask the running instance whether it is busy first, and\n refuse with exit 75 if it is \u2014 a chat turn in flight, a background task, a\n scheduled job. `paddock busy` asks the same question on its own.\n\n Being refused is the useful case: a restart kills a chat turn mid-sentence,\n and the turn cannot be resumed from where it was. Wait, or --force.\n\n `uninstall` does not ask. Removing the service is an explicit act, and\n someone uninstalling it has already decided.\n\nOptions (install only \u2014 recorded in the generated unit)\n -p, --port <port> HTTP/WS port (default 7233)\n --host <host> Bind address (default 127.0.0.1)\n -d, --data-dir <path> Only if you want an instance SEPARATE from your\n terminal one. Left out of the unit when you omit it\n AND `PADDOCK_DATA_DIR` is unset in this shell, so\n `paddock service` and a bare `paddock` are the same\n ~/.paddock instance reached two ways. If\n `PADDOCK_DATA_DIR` IS set here, that path is recorded\n in the unit \u2014 the service would otherwise point\n somewhere your terminal does not.\n --verbose Record the server's own logs, not just warnings\n\nAt login, not at boot\n This registers a per-USER service \u2014 a launchd LaunchAgent on macOS, a\n `systemd --user` unit on Linux \u2014 so it runs as you, with your own Claude\n login. That is not incidental: on macOS your Claude login is a Keychain item\n that only a logged-in user session can read. A boot-time system daemon has no\n such session and could not use it.\n\n So Paddock starts when you LOG IN, not when the machine boots. After a\n restart that nobody logs into, Paddock is not running. That is the design, not\n a fault.\n\n On Linux, a user service is also stopped when you log out. To keep it up:\n\n loginctl enable-linger $USER\n\nWhere it lives\n macOS ~/Library/LaunchAgents/net.edspencer.paddock.plist\n Linux ~/.config/systemd/user/paddock.service\n\n Both write stdout and stderr to ONE file, <data-dir>/logs/service.log, which\n is what `paddock service logs` reads. Not the journal on Linux: a volatile\n journal has nothing in it after the reboot you are asking about, and one file\n means one answer to \"where are the logs\" on every OS. Paddock rotates it\n itself at 8 MB, keeping three older generations beside it.\n\nExit codes\n 0 it is installed, running and answering\n 3 installed, but not running or not answering\n 4 not installed: there is no unit (status, logs, start, stop, restart)\n 1 something failed\n 2 usage: an unknown action or flag, or a bad value\n 75 busy, and --force was not given (stop, restart)\n\nInstalled from npx?\n `service install` refuses. An npx cache path is hash-keyed and npm may prune\n it, so the unit would work until it silently didn't, at some future login.\n Install properly first:\n\n npm i -g @edspencer/paddock && paddock service install\n\nA note on access\n Paddock binds loopback with authentication off, which is right for a laptop.\n A service is up for as long as you are logged in rather than as long as a\n terminal tab, so that window is longer \u2014 but it is not wider: any local\n process that could reach the port could already read the same Claude login as\n you. Set PADDOCK_AUTH_MODE if you want a credential on it anyway.\n\nDocs: https://github.com/edspencer/paddock";
|
|
217
|
+
export declare const BUSY_USAGE = "paddock busy \u2014 is the running instance in the middle of something?\n\nUsage\n paddock busy ask, and say so in a sentence\n paddock busy --json the same answer as one JSON document\n paddock busy -d <path> ask a particular instance\n\nExit codes \u2014 this command is FOR its exit code\n 0 not busy. Nothing a restart would cut short.\n 75 busy. What is running was printed.\n 3 nothing answered. No instance is running, so there is nothing to wait for.\n 1 something answered, but not as Paddock's busy check.\n\nOptions\n -d, --data-dir <path> Which instance to ask (default ~/.paddock, or\n $PADDOCK_DATA_DIR) \u2014 the same rule `paddock serve`\n uses, so the two always mean the same instance\n --json One JSON document on stdout: running, busy, url,\n version, counts. Prose goes to stderr\n -h, --help Show this help\n\nWhat counts as busy\n Only work a restart would LOSE or cut short:\n\n chat a chat turn running \u2014 a human turn, a fired trigger, a cron\n fire. A turn is a live claude subprocess writing a transcript,\n and it cannot be resumed from where it was interrupted.\n background a background task a live session is still holding after its\n turn ended: a background shell, a sub-agent, a Monitor.\n job a scheduled job herdctl is running.\n\n Not busy: an idle session (it resumes), an open browser tab (it reconnects),\n a pending curation sweep (it re-runs from its watermark).\n\nWhere to run it from\n From a terminal. A Paddock chat that runs this is itself one of the chat turns\n it counts, so it will always see itself as busy \u2014 and `service stop --force`\n from inside a chat stops the service that is running the chat, which does not\n come back with an explanation. That is why the refusal says so.\n\nFor scripts, containers and Watchtower\n `busy` is there for callers with no service to ask. 75 is EX_TEMPFAIL, which\n is the code Watchtower's pre-update hook reads as \"skip this one\":\n\n labels:\n com.centurylinklabs.watchtower.lifecycle.pre-update: paddock busy\n\n An Ansible task does the same thing with a retry. Nothing here contacts the\n network or the npm registry, and the question is answered from memory \u2014 it is\n cheap enough to ask in a loop.\n\nHow it finds the instance\n `<data-dir>/runtime.json`, written 0600 when the server starts listening and\n removed when it stops. There is no fallback to a default port: guessing one\n would ask whatever else happened to be listening there, and get an answer.\n\n A Paddock from before this feature shipped writes no such file, so it reads as\n not running (exit 3). Upgrade it and restart it once.\n\nDocs: https://github.com/edspencer/paddock";
|
|
202
218
|
export declare const CONFIG_USAGE = "paddock config \u2014 what this instance's configuration actually resolved to\n\nUsage\n paddock config show the decisions: your profile, the keys your\n config file sets, the variables your\n environment sets\n paddock config show --resolved EVERY effective value, and which layer it\n came from\n paddock config show --json the same report as JSON, long values in\n full (sensitive ones still hidden)\n paddock config eject what freezing that resolution into\n paddock.config.yaml would write \u2014 a\n preview; writes nothing\n paddock config eject --write actually write it\n\nOptions\n -d, --data-dir <path> Which instance to inspect (default ~/.paddock, or\n $PADDOCK_DATA_DIR) \u2014 the same rule `paddock start`\n uses, so the two always read the same instance\n --resolved show: every field, not just the ones someone set\n --json show: the whole report as JSON (implies --resolved's\n scope)\n --show-sensitive show: print the values of fields marked sensitive\n --write eject: apply the plan. Without it, eject only prints\n --include-env eject: also freeze values an environment variable\n currently supplies (see below \u2014 off by default)\n -h, --help Show this help\n\nWhere a value can come from\n Config resolves in four layers, and each row of --resolved names the one that\n won:\n\n default Paddock's built-in default.\n profile (<name>) Your posture profile. The twelve levers a profile governs\n have no code default of their own any more \u2014 the profile\n IS their default \u2014 so this is a distinct answer from\n \"default\", and switching profile would change it.\n file A key in paddock.config.yaml.\n env <NAME> An environment variable, which beats the file for the\n same key.\n\n One wrinkle worth knowing, and the command shows it plainly: an individual key\n in the FILE beats PADDOCK_PROFILE in the environment. Specific beats general \u2014\n PADDOCK_PROFILE speaks for the levers you did not mention.\n\nWhy show, and not just write it all into the file\n `show` is computed by the loader the server boots with, so it cannot drift\n from what the process would actually do. A materialized file can: it stops\n inheriting improved defaults, says nothing about the variables your container\n sets on top, and no longer describes the whole surface the day a lever is\n added. That is why the thin file is the default and `show` is the answer to\n \"what am I actually running?\".\n\n `eject` is there for when you want it written down anyway \u2014 frozen, in the\n file, reviewable in git. It is a real tradeoff rather than a better `show`,\n so it prints what it would cost you and writes nothing until you pass --write.\n\nWhat eject writes, and what it leaves alone\n It writes the posture levers your profile expanded to, plus the behavioural\n settings the Config screen already round-trips through this file. It does NOT\n write:\n\n the bindings port, host, data dir, projects root, state dir, web dist.\n These resolve to absolute paths on THIS machine, and the\n data dir resolves to the directory holding the file \u2014 so\n ejecting them makes the file unportable and unmountable.\n sensitive keys transcription.endpoint can carry credentials in its URL.\n Bulk-writing a secret-shaped value to disk should not be\n one keystroke away; write that key by hand.\n env-owned keys by default. An environment variable BEATS the file, so\n writing its value in changes nothing today and everything\n the day the variable goes away \u2014 a deferred, silent change\n of provenance. eject names each one it skipped instead.\n --include-env writes them, which is the right flag if you\n are deliberately migrating from env vars to a file.\n\n It always writes `profile:` as well, even though every key that profile\n governs is now explicit. That line is what a lever added in a FUTURE release\n falls back to: without it, a new capability toggle would resolve against the\n built-in default profile rather than the posture you actually ejected from.\n\n Your comments and any keys Paddock does not manage survive \u2014 the file is\n round-tripped, not regenerated \u2014 and the write is atomic.\n\nReading nothing, writing nothing\n `show` resolves config and prints it. It starts no server, contacts nothing,\n and writes no file \u2014 including the data dir itself, which it will report as\n missing rather than create. `eject` writes exactly one file, and only with\n --write.\n\n Values are printed to a terminal that often ends up pasted into an issue, so\n fields marked sensitive are shown as (hidden). None of them is a secret \u2014\n Paddock keeps secrets out of this surface entirely, so there is no API key or\n JWT signing material here to hide or reveal.\n\nDocs: https://github.com/edspencer/paddock";
|
|
@@ -88,7 +88,7 @@ export const CONFIG_ACTIONS = ["show", "eject"];
|
|
|
88
88
|
* Paddock and Managers, every existing service unit's `ExecStart` names it, and
|
|
89
89
|
* it is in two years of other people's scripts. They parse to the same command.
|
|
90
90
|
*/
|
|
91
|
-
export const VERBS = ["serve", "start", "service", "config"];
|
|
91
|
+
export const VERBS = ["serve", "start", "service", "config", "busy"];
|
|
92
92
|
/**
|
|
93
93
|
* Split an action off a verb's argv, then parse what follows as flags.
|
|
94
94
|
*
|
|
@@ -142,6 +142,30 @@ function parseAction(verb, actions, rest) {
|
|
|
142
142
|
* and load-bearing; it was only the example's error that was misdescribed.
|
|
143
143
|
*/
|
|
144
144
|
export function parseCommand(argv) {
|
|
145
|
+
const command = dispatch(argv);
|
|
146
|
+
// `--force` overrides the busy check (SPEC §1, §4) and nothing else, so it
|
|
147
|
+
// only means anything on the two commands that run one. Rejecting it
|
|
148
|
+
// everywhere else, rather than parsing and dropping it, is the difference
|
|
149
|
+
// between being told and guessing: the two readings of a quiet
|
|
150
|
+
// `service uninstall --force` are "it overrode something" and "it did
|
|
151
|
+
// nothing", and the exit code is 0 either way.
|
|
152
|
+
//
|
|
153
|
+
// Checked here, once, rather than in each command: a second copy of this rule
|
|
154
|
+
// is a second chance for the two to drift apart about what `--force` means.
|
|
155
|
+
if (command.opts.force === true &&
|
|
156
|
+
// `--help` wins, the same way it wins over a missing action above: asking
|
|
157
|
+
// for the usage is not a usage error.
|
|
158
|
+
!command.opts.help &&
|
|
159
|
+
!(command.verb === "service" && (command.action === "stop" || command.action === "restart"))) {
|
|
160
|
+
const what = command.verb === "service" && command.action !== undefined
|
|
161
|
+
? `\`service ${command.action}\``
|
|
162
|
+
: `\`${command.verb}\``;
|
|
163
|
+
throw new UsageError(`--force applies to \`service stop\` and \`service restart\` only, not ${what}.\n` +
|
|
164
|
+
"It overrides the busy check, and those are the two commands that run one.");
|
|
165
|
+
}
|
|
166
|
+
return command;
|
|
167
|
+
}
|
|
168
|
+
function dispatch(argv) {
|
|
145
169
|
const [first, ...rest] = argv;
|
|
146
170
|
if (first === "service") {
|
|
147
171
|
return { verb: "service", ...parseAction("service", SERVICE_ACTIONS, rest) };
|
|
@@ -149,6 +173,11 @@ export function parseCommand(argv) {
|
|
|
149
173
|
if (first === "config") {
|
|
150
174
|
return { verb: "config", ...parseAction("config", CONFIG_ACTIONS, rest) };
|
|
151
175
|
}
|
|
176
|
+
// `busy` (SPEC §1, §4). A top-level verb rather than a `service` action
|
|
177
|
+
// because its whole point is to be askable where there is no service to ask:
|
|
178
|
+
// a Docker container, a Watchtower pre-update hook, an Ansible task.
|
|
179
|
+
if (first === "busy")
|
|
180
|
+
return { verb: "busy", opts: parseArgs(rest) };
|
|
152
181
|
// `serve` and `start` are one command: see VERBS.
|
|
153
182
|
if (first === "serve" || first === "start")
|
|
154
183
|
return { verb: "serve", opts: parseArgs(rest) };
|
|
@@ -220,6 +249,10 @@ export function parseArgs(argv) {
|
|
|
220
249
|
case "--include-env":
|
|
221
250
|
opts.includeEnv = true;
|
|
222
251
|
break;
|
|
252
|
+
// `service stop` / `service restart`: override the busy check (SPEC §4).
|
|
253
|
+
case "--force":
|
|
254
|
+
opts.force = true;
|
|
255
|
+
break;
|
|
223
256
|
// `service logs` flags, the names `tail`, `journalctl` and every other
|
|
224
257
|
// log reader uses — this is not the place to be original.
|
|
225
258
|
case "-f":
|
|
@@ -293,6 +326,7 @@ export function explainListenError(err, host, port) {
|
|
|
293
326
|
export const USAGE_SYNOPSIS = `Usage
|
|
294
327
|
paddock [serve] [options] run the server in this terminal
|
|
295
328
|
paddock service <action> [options] install|uninstall|status|start|stop|restart|logs
|
|
329
|
+
paddock busy [--json] is the running instance busy?
|
|
296
330
|
paddock config <show|eject> [options] what this instance's config resolved to
|
|
297
331
|
paddock -v | --version print the version and exit
|
|
298
332
|
paddock -h | --help the full help`;
|
|
@@ -306,10 +340,13 @@ Usage
|
|
|
306
340
|
paddock service uninstall stop it and remove the unit
|
|
307
341
|
paddock service status [--json] installed? running? which version?
|
|
308
342
|
paddock service start start an installed service
|
|
309
|
-
paddock service stop
|
|
310
|
-
paddock service restart
|
|
343
|
+
paddock service stop [--force] stop it, leave it installed
|
|
344
|
+
paddock service restart [--force] stop it and start it again
|
|
311
345
|
paddock service logs [-f] [-n <lines>] the service's log
|
|
312
346
|
(\`paddock service --help\`)
|
|
347
|
+
paddock busy [--json] is it busy? exit 0 no, 75 yes, 3
|
|
348
|
+
nothing answering
|
|
349
|
+
(\`paddock busy --help\`)
|
|
313
350
|
paddock config show [--resolved] what this instance's config resolved
|
|
314
351
|
to, and where each value came from
|
|
315
352
|
paddock config eject [--write] freeze that resolution into
|
|
@@ -326,11 +363,12 @@ Options
|
|
|
326
363
|
-h, --help Show this help
|
|
327
364
|
|
|
328
365
|
Exit codes
|
|
329
|
-
0 done; running and answering
|
|
366
|
+
0 done; running and answering; not busy
|
|
330
367
|
1 failed
|
|
331
368
|
2 usage: an unknown command or flag, or a bad value
|
|
332
|
-
3 not running: installed, but not running or not answering
|
|
369
|
+
3 not running: installed, but not running or not answering; nothing answers
|
|
333
370
|
4 not installed: there is no service unit
|
|
371
|
+
75 busy: refused, and why was printed. Try later, or use --force
|
|
334
372
|
|
|
335
373
|
Opening your own directories
|
|
336
374
|
Where you run this from does not matter — the instance is decided by its data
|
|
@@ -438,14 +476,28 @@ Usage
|
|
|
438
476
|
paddock service status [--json] is it registered, is it running, which
|
|
439
477
|
version, where are the logs
|
|
440
478
|
paddock service start start an installed service that is stopped
|
|
441
|
-
paddock service stop
|
|
442
|
-
paddock service restart
|
|
479
|
+
paddock service stop [--force] stop it, and leave it installed
|
|
480
|
+
paddock service restart [--force] stop it and start it again, re-reading config
|
|
443
481
|
paddock service logs [-f] [-n <n>] the service's log (the last 50 lines)
|
|
444
482
|
|
|
445
483
|
Options (logs)
|
|
446
484
|
-f, --follow keep printing what gets appended, until Ctrl-C
|
|
447
485
|
-n, --lines <n> how many lines to print first (default 50)
|
|
448
486
|
|
|
487
|
+
Options (stop, restart)
|
|
488
|
+
--force stop it even though it is busy
|
|
489
|
+
|
|
490
|
+
Busy
|
|
491
|
+
\`stop\` and \`restart\` ask the running instance whether it is busy first, and
|
|
492
|
+
refuse with exit 75 if it is — a chat turn in flight, a background task, a
|
|
493
|
+
scheduled job. \`paddock busy\` asks the same question on its own.
|
|
494
|
+
|
|
495
|
+
Being refused is the useful case: a restart kills a chat turn mid-sentence,
|
|
496
|
+
and the turn cannot be resumed from where it was. Wait, or --force.
|
|
497
|
+
|
|
498
|
+
\`uninstall\` does not ask. Removing the service is an explicit act, and
|
|
499
|
+
someone uninstalling it has already decided.
|
|
500
|
+
|
|
449
501
|
Options (install only — recorded in the generated unit)
|
|
450
502
|
-p, --port <port> HTTP/WS port (default 7233)
|
|
451
503
|
--host <host> Bind address (default 127.0.0.1)
|
|
@@ -490,6 +542,7 @@ Exit codes
|
|
|
490
542
|
4 not installed: there is no unit (status, logs, start, stop, restart)
|
|
491
543
|
1 something failed
|
|
492
544
|
2 usage: an unknown action or flag, or a bad value
|
|
545
|
+
75 busy, and --force was not given (stop, restart)
|
|
493
546
|
|
|
494
547
|
Installed from npx?
|
|
495
548
|
\`service install\` refuses. An npx cache path is hash-keyed and npm may prune
|
|
@@ -505,6 +558,66 @@ A note on access
|
|
|
505
558
|
process that could reach the port could already read the same Claude login as
|
|
506
559
|
you. Set PADDOCK_AUTH_MODE if you want a credential on it anyway.
|
|
507
560
|
|
|
561
|
+
Docs: https://github.com/edspencer/paddock`;
|
|
562
|
+
export const BUSY_USAGE = `paddock busy — is the running instance in the middle of something?
|
|
563
|
+
|
|
564
|
+
Usage
|
|
565
|
+
paddock busy ask, and say so in a sentence
|
|
566
|
+
paddock busy --json the same answer as one JSON document
|
|
567
|
+
paddock busy -d <path> ask a particular instance
|
|
568
|
+
|
|
569
|
+
Exit codes — this command is FOR its exit code
|
|
570
|
+
0 not busy. Nothing a restart would cut short.
|
|
571
|
+
75 busy. What is running was printed.
|
|
572
|
+
3 nothing answered. No instance is running, so there is nothing to wait for.
|
|
573
|
+
1 something answered, but not as Paddock's busy check.
|
|
574
|
+
|
|
575
|
+
Options
|
|
576
|
+
-d, --data-dir <path> Which instance to ask (default ~/.paddock, or
|
|
577
|
+
\$PADDOCK_DATA_DIR) — the same rule \`paddock serve\`
|
|
578
|
+
uses, so the two always mean the same instance
|
|
579
|
+
--json One JSON document on stdout: running, busy, url,
|
|
580
|
+
version, counts. Prose goes to stderr
|
|
581
|
+
-h, --help Show this help
|
|
582
|
+
|
|
583
|
+
What counts as busy
|
|
584
|
+
Only work a restart would LOSE or cut short:
|
|
585
|
+
|
|
586
|
+
chat a chat turn running — a human turn, a fired trigger, a cron
|
|
587
|
+
fire. A turn is a live claude subprocess writing a transcript,
|
|
588
|
+
and it cannot be resumed from where it was interrupted.
|
|
589
|
+
background a background task a live session is still holding after its
|
|
590
|
+
turn ended: a background shell, a sub-agent, a Monitor.
|
|
591
|
+
job a scheduled job herdctl is running.
|
|
592
|
+
|
|
593
|
+
Not busy: an idle session (it resumes), an open browser tab (it reconnects),
|
|
594
|
+
a pending curation sweep (it re-runs from its watermark).
|
|
595
|
+
|
|
596
|
+
Where to run it from
|
|
597
|
+
From a terminal. A Paddock chat that runs this is itself one of the chat turns
|
|
598
|
+
it counts, so it will always see itself as busy — and \`service stop --force\`
|
|
599
|
+
from inside a chat stops the service that is running the chat, which does not
|
|
600
|
+
come back with an explanation. That is why the refusal says so.
|
|
601
|
+
|
|
602
|
+
For scripts, containers and Watchtower
|
|
603
|
+
\`busy\` is there for callers with no service to ask. 75 is EX_TEMPFAIL, which
|
|
604
|
+
is the code Watchtower's pre-update hook reads as "skip this one":
|
|
605
|
+
|
|
606
|
+
labels:
|
|
607
|
+
com.centurylinklabs.watchtower.lifecycle.pre-update: paddock busy
|
|
608
|
+
|
|
609
|
+
An Ansible task does the same thing with a retry. Nothing here contacts the
|
|
610
|
+
network or the npm registry, and the question is answered from memory — it is
|
|
611
|
+
cheap enough to ask in a loop.
|
|
612
|
+
|
|
613
|
+
How it finds the instance
|
|
614
|
+
\`<data-dir>/runtime.json\`, written 0600 when the server starts listening and
|
|
615
|
+
removed when it stops. There is no fallback to a default port: guessing one
|
|
616
|
+
would ask whatever else happened to be listening there, and get an answer.
|
|
617
|
+
|
|
618
|
+
A Paddock from before this feature shipped writes no such file, so it reads as
|
|
619
|
+
not running (exit 3). Upgrade it and restart it once.
|
|
620
|
+
|
|
508
621
|
Docs: https://github.com/edspencer/paddock`;
|
|
509
622
|
export const CONFIG_USAGE = `paddock config — what this instance's configuration actually resolved to
|
|
510
623
|
|