@hearsay-tools/squawk 0.18.0-dev.6646 → 0.18.0-dev.6683
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ci-wait/tool-catalog.js +1 -1
- package/dist/ci-wait/tool-catalog.js.map +1 -1
- package/dist/contract/attention.d.ts +8 -0
- package/dist/contract/index.js +14 -0
- package/dist/contract/runs.d.ts +15 -0
- package/dist/delegation/conversations.d.ts +4 -2
- package/dist/delegation/park-notice.d.ts +5 -1
- package/dist/delegation/park-notice.js +7 -0
- package/dist/delegation/park-notice.js.map +1 -1
- package/dist/delegation/routes.d.ts +4 -4
- package/dist/delegation/scratch-cleanup.js +6 -3
- package/dist/delegation/scratch-cleanup.js.map +1 -1
- package/dist/delegation/transport.d.ts +16 -16
- package/dist/home/command.js +1 -1
- package/dist/home/command.js.map +1 -1
- package/dist/jobs/cli.js +4 -2
- package/dist/jobs/cli.js.map +1 -1
- package/dist/jobs/job.d.ts +7 -0
- package/dist/jobs/job.js +32 -3
- package/dist/jobs/job.js.map +1 -1
- package/dist/runs/agent-tmpdir.d.ts +3 -2
- package/dist/runs/agent-tmpdir.js +11 -4
- package/dist/runs/agent-tmpdir.js.map +1 -1
- package/dist/runs/automation-runs.js +4 -3
- package/dist/runs/automation-runs.js.map +1 -1
- package/dist/runs/conversation-members.js +3 -2
- package/dist/runs/conversation-members.js.map +1 -1
- package/dist/runs/guarded-json-sql.d.ts +8 -0
- package/dist/runs/guarded-json-sql.js +11 -0
- package/dist/runs/guarded-json-sql.js.map +1 -0
- package/dist/runs/run-database-peer-page.js +3 -4
- package/dist/runs/run-database-peer-page.js.map +1 -1
- package/dist/runs/run-database-version.d.ts +1 -1
- package/dist/runs/run-database-version.js +2 -1
- package/dist/runs/run-database-version.js.map +1 -1
- package/dist/runs/run-database.js +5 -4
- package/dist/runs/run-database.js.map +1 -1
- package/dist/runs/run-exits.d.ts +15 -6
- package/dist/runs/run-exits.js +13 -4
- package/dist/runs/run-exits.js.map +1 -1
- package/dist/runs/run-index.js +1 -2
- package/dist/runs/run-index.js.map +1 -1
- package/dist/runs/store.d.ts +11 -5
- package/dist/runs/store.js +21 -20
- package/dist/runs/store.js.map +1 -1
- package/dist/serve-boot.d.ts +1 -2
- package/dist/serve-command.js +25 -15
- package/dist/serve-command.js.map +1 -1
- package/dist/serve-stop.d.ts +41 -0
- package/dist/serve-stop.js +42 -0
- package/dist/serve-stop.js.map +1 -0
- package/dist/server/checkout.d.ts +1 -1
- package/dist/server/health-cache.d.ts +39 -0
- package/dist/server/health-cache.js +66 -0
- package/dist/server/health-cache.js.map +1 -0
- package/dist/server/server.d.ts +1825 -1807
- package/dist/server/server.js +17 -63
- package/dist/server/server.js.map +1 -1
- package/dist/server-install/platforms/macosx-migration.js +1 -1
- package/dist/server-install/platforms/macosx-migration.js.map +1 -1
- package/dist/server-install/platforms/ubuntu-vps-migration.js +1 -1
- package/dist/server-install/platforms/ubuntu-vps-migration.js.map +1 -1
- package/dist/workflows/continuation-admission.d.ts +2 -1
- package/dist/workflows/run/prompts.js +1 -1
- package/dist/workflows/run/prompts.js.map +1 -1
- package/dist/workflows/run/run-settlement.d.ts +10 -0
- package/dist/workflows/run/run-settlement.js +39 -5
- package/dist/workflows/run/run-settlement.js.map +1 -1
- package/dist/workflows/run/step-loop.js +1 -1
- package/dist/workflows/run/step-loop.js.map +1 -1
- package/dist/workflows/run/wait-engine.d.ts +2 -1
- package/dist/workflows/run/worker-questions.d.ts +3 -2
- package/dist/workflows/run/worker-questions.js +6 -5
- package/dist/workflows/run/worker-questions.js.map +1 -1
- package/dist/workflows/run-states.js +1 -1
- package/dist/workflows/run-states.js.map +1 -1
- package/package.json +4 -4
- package/scripts/measure-transcript-facts-health.mjs +13 -6
- package/web/dist/assets/activity-motion-DhLXb8Pt.js +2 -0
- package/web/dist/assets/{activity-route--Qj4NT9h.js → activity-route-CpwAMYLn.js} +1 -1
- package/web/dist/assets/{agent-accounts-BxpWcFS3.js → agent-accounts-Bc0LJ4SB.js} +1 -1
- package/web/dist/assets/attention-BF8NA1XM.js +1 -0
- package/web/dist/assets/{commit-diff-panel-DOgakNKv.js → commit-diff-panel-B1KZl0GP.js} +1 -1
- package/web/dist/assets/{diff-MoyKcT8Q.js → diff-Ci-qd1lU.js} +2 -2
- package/web/dist/assets/{diff-view-BFQcOCEf.js → diff-view-CWZElKoD.js} +1 -1
- package/web/dist/assets/{file-preview-BancpZHA.js → file-preview-CoWRr13R.js} +1 -1
- package/web/dist/assets/{git-toolbar-ClMasBRM.js → git-toolbar-BYIni94R.js} +1 -1
- package/web/dist/assets/{github-BVZ01nJq.js → github-CAPNq5vY.js} +1 -1
- package/web/dist/assets/{global-activity-route-DTgywy--.js → global-activity-route-DLEwsMA7.js} +1 -1
- package/web/dist/assets/index-CpwAOct4.js +17 -0
- package/web/dist/assets/{preview-pane-connected-B5PCWA9a.js → preview-pane-connected-CGw_9VuF.js} +2 -2
- package/web/dist/assets/{project-router-CiB1O_5A.js → project-router-oKsNlPN6.js} +1 -1
- package/web/dist/assets/{project-scope-context-CSPQyWoO.js → project-scope-context-BBVJVcJp.js} +1 -1
- package/web/dist/assets/{prompt-template-menu-VwBcsbqE.js → prompt-template-menu-BZTz2mIG.js} +1 -1
- package/web/dist/assets/queries-Be8VyHam.js +1 -0
- package/web/dist/assets/{reference-chip-DT-_ninM.js → reference-chip-Ht4xX9-k.js} +1 -1
- package/web/dist/assets/{repo-git-7KuJaDRk.js → repo-git-CzVLCWig.js} +1 -1
- package/web/dist/assets/{report-reader-CgY75QM2.js → report-reader-iTBkUgg-.js} +1 -1
- package/web/dist/assets/reports-BJF1Cl3C.js +1 -0
- package/web/dist/assets/run-header-BxB6gyt1.js +2 -0
- package/web/dist/assets/{skills-Dnrta_-m.js → skills-DvgHKWgK.js} +1 -1
- package/web/dist/assets/{tab-link-BPBiho7-.js → tab-link-Buy1fRFO.js} +1 -1
- package/web/dist/assets/{task-changes-C6sDd3Le.js → task-changes-CStxhLFG.js} +1 -1
- package/web/dist/assets/{task-commits-CQHxnFJ5.js → task-commits-DhpOAdOf.js} +1 -1
- package/web/dist/assets/{task-files-DK8Demuc.js → task-files-COmKUUfN.js} +1 -1
- package/web/dist/assets/{task-github-item-DgmmFFtN.js → task-github-item-BNLeAz58.js} +1 -1
- package/web/dist/assets/{task-thread-Dg9VWJq6.js → task-thread-DjSFvEQe.js} +6 -6
- package/web/dist/assets/{thread-state-DIMUAyFk.js → thread-state-B5tTsVNm.js} +1 -1
- package/web/dist/assets/use-desktop-BPWIJ0Kw.js +1 -0
- package/web/dist/assets/{use-hand-to-agent-state-D-yaVRRx.js → use-hand-to-agent-state-Ce6QW2j_.js} +1 -1
- package/web/dist/assets/{useInfiniteQuery-Q8eFXz-L.js → useInfiniteQuery-Yn58_Fkn.js} +1 -1
- package/web/dist/assets/useQuery-C1xFF0nd.js +1 -0
- package/web/dist/assets/{workflows-W_uriBcj.js → workflows-CN8uKYnY.js} +1 -1
- package/web/dist/assets/{ws-B-tB133E.js → ws-DbXGHAke.js} +1 -1
- package/web/dist/index.html +12 -12
- package/web/dist/assets/activity-motion-CEnf2rDh.js +0 -2
- package/web/dist/assets/attention-BDa7opY9.js +0 -1
- package/web/dist/assets/index-CsOa03VW.js +0 -17
- package/web/dist/assets/queries-pj368bmB.js +0 -1
- package/web/dist/assets/reports-CxTUchWh.js +0 -1
- package/web/dist/assets/run-header-BcX23gw7.js +0 -2
- package/web/dist/assets/use-desktop-Bq_Qh5ur.js +0 -1
- package/web/dist/assets/useQuery-BoLjCS2U.js +0 -1
package/dist/serve-boot.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function reconcileServeWorktrees(repoRoot: string, repo: Awaited<
|
|
|
20
20
|
} | undefined, home: Home): Promise<void>;
|
|
21
21
|
export declare function recoverServeProject(store: RunStore, manager: RunManager, providerRuntimeAuth: ProviderRuntimeAuthObserver, delegation: DelegationController, bootProjectId?: string, recover?: typeof recoverWithProviderRuntimeAuthObservation): Promise<void>;
|
|
22
22
|
export declare function warnServeBind(bindHost: string | undefined, port: number): void;
|
|
23
|
-
type StoppableServer = Pick<ReturnType<typeof startServer>, 'shutdownForRestart'>;
|
|
23
|
+
export type StoppableServer = Pick<ReturnType<typeof startServer>, 'shutdownForRestart'>;
|
|
24
24
|
/** How long a stop waits for the server's own shutdown. A socket the listener still holds, or a
|
|
25
25
|
* step that hangs, must not keep this process, its store or its agents alive. */
|
|
26
26
|
export declare const STOP_SERVE_BOUND_MS = 5000;
|
|
@@ -39,4 +39,3 @@ export interface StopServeOptions {
|
|
|
39
39
|
*/
|
|
40
40
|
export declare function stopServe(server: StoppableServer, signal?: NodeJS.Signals, opts?: StopServeOptions): Promise<void>;
|
|
41
41
|
export declare function printServeBanner(version: string, repoRoot: string, repo: Awaited<ReturnType<typeof getRepoInfo>>, checks: Awaited<ReturnType<typeof detectEnvironment>>, url: string): void;
|
|
42
|
-
export {};
|
package/dist/serve-command.js
CHANGED
|
@@ -27,6 +27,7 @@ import { CockpitOwnership } from './server/cockpit-ownership.js';
|
|
|
27
27
|
import { recoverProjectMigration } from './project-migration/recovery.js';
|
|
28
28
|
import { moveProjectWhenIdle } from './project-migration/auto.js';
|
|
29
29
|
import { acquireServeListener, onTerminal, ignoreHangupOffTerminal, waitForHealth } from './serve-listener.js';
|
|
30
|
+
import { installServeStop } from './serve-stop.js';
|
|
30
31
|
/** The new scoped package has no binary named after it, so npx needs its `hsq` binary named. */
|
|
31
32
|
function restartCommand(pkgName) {
|
|
32
33
|
const identity = npmPackageIdentity(pkgName);
|
|
@@ -42,6 +43,20 @@ export const defaultServeDeps = {
|
|
|
42
43
|
export async function serveCommand(home, repoRoot, preferredPort, openBrowser, bindHost, deps) {
|
|
43
44
|
const ownership = new deps.CockpitOwnership();
|
|
44
45
|
deps.process.once('exit', () => ownership.releaseAll());
|
|
46
|
+
const stop = installServeStop(deps);
|
|
47
|
+
try {
|
|
48
|
+
await bootServe(home, repoRoot, preferredPort, openBrowser, bindHost, deps, ownership, stop);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// A stop closes the store under a boot step; that step's failure is not the boot's.
|
|
52
|
+
if (!stop.stopping)
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
// The stop ends the process; returning earlier would let the CLI exit before the agents hear it.
|
|
56
|
+
await stop.stopped;
|
|
57
|
+
}
|
|
58
|
+
async function bootServe(home, repoRoot, preferredPort, openBrowser, bindHost, deps, ownership, stop) {
|
|
59
|
+
const { parts } = stop;
|
|
45
60
|
// An unfinished project migration finishes before anything reads the project; the claim it
|
|
46
61
|
// takes is the one boot keeps. A failure ends the boot with why.
|
|
47
62
|
await deps.recoverProjectMigration(repoRoot, { ownership, keep: true });
|
|
@@ -51,6 +66,7 @@ export async function serveCommand(home, repoRoot, preferredPort, openBrowser, b
|
|
|
51
66
|
// Hold the real listener before workspace writes, recovery or background resources.
|
|
52
67
|
// A probe followed by a later bind would allow another cwd to win in between.
|
|
53
68
|
const listener = await deps.acquireServeListener(preferredPort, bindHost);
|
|
69
|
+
parts.listener = listener;
|
|
54
70
|
const bootProjectId = await deps.initWorkspace(repoRoot, home);
|
|
55
71
|
// ONE workspace semaphore for the whole process (spec 2026-07-20, step 2.5):
|
|
56
72
|
// the boot manager and every lazily-built project context count their runs
|
|
@@ -61,6 +77,7 @@ export async function serveCommand(home, repoRoot, preferredPort, openBrowser, b
|
|
|
61
77
|
// keepLive + recover() (#367): runs that were queued/running/waiting when
|
|
62
78
|
// the previous process exited are re-queued or resumed instead of failed.
|
|
63
79
|
const store = deps.openBootStore(repoRoot);
|
|
80
|
+
parts.store = store;
|
|
64
81
|
// Before recovery (#589): the runs recovery re-queues, resumes or fails are exactly the
|
|
65
82
|
// transitions an opted-in bot is waiting for. Deliveries wait until startServer knows its port.
|
|
66
83
|
const taskWebhooks = new deps.TaskWebhooks({ home });
|
|
@@ -68,6 +85,7 @@ export async function serveCommand(home, repoRoot, preferredPort, openBrowser, b
|
|
|
68
85
|
// ONE preview host for the whole process (#781), like the semaphore: ports are host-global, so
|
|
69
86
|
// `port_held` must see every project's servers. Off unless `CEZ_PREVIEW=1`.
|
|
70
87
|
const previewHost = deps.previewToolEnabled() ? new deps.PreviewHost({ home }) : undefined;
|
|
88
|
+
parts.previewHost = previewHost;
|
|
71
89
|
// The port the cockpit bound, once `startServer` listens; the preview tool refuses it.
|
|
72
90
|
let boundPort;
|
|
73
91
|
const squawkPort = () => boundPort;
|
|
@@ -85,6 +103,7 @@ export async function serveCommand(home, repoRoot, preferredPort, openBrowser, b
|
|
|
85
103
|
sweepBranches: (keep) => void deps.sweepMergedBranches({ root: repoRoot, store, manager, home }, { keep, minIntervalMs: SWEEP_MIN_INTERVAL_MS }),
|
|
86
104
|
});
|
|
87
105
|
const delegation = await deps.DelegationController.start(deps.workerCleanup);
|
|
106
|
+
parts.delegation = delegation;
|
|
88
107
|
delegation.attachProject({ id: bootProjectId ?? 'default', root: repoRoot, store, manager, home });
|
|
89
108
|
const providerAuth = new deps.ProviderAuthService();
|
|
90
109
|
const discovery = deps.createHostDiscovery(repoRoot, providerAuth, home);
|
|
@@ -97,7 +116,12 @@ export async function serveCommand(home, repoRoot, preferredPort, openBrowser, b
|
|
|
97
116
|
const checks = await deps.detectEnvironment();
|
|
98
117
|
const repo = await deps.getRepoInfo(repoRoot);
|
|
99
118
|
await deps.reconcileServeWorktrees(repoRoot, repo, store, manager, previewHost, undefined, home);
|
|
119
|
+
// A stopping boot starts no agent and serves nothing: the stop closes what boot built so far.
|
|
120
|
+
if (stop.stopping)
|
|
121
|
+
return;
|
|
100
122
|
await deps.recoverServeProject(store, manager, providerRuntimeAuth, delegation, bootProjectId);
|
|
123
|
+
if (stop.stopping)
|
|
124
|
+
return;
|
|
101
125
|
// Update discovery (#368) — fire-and-forget; the banner prints whenever the
|
|
102
126
|
// registry answers and /api/v1/health reports it as `latestVersion`.
|
|
103
127
|
const pkgName = deps.readOwnName();
|
|
@@ -132,6 +156,7 @@ export async function serveCommand(home, repoRoot, preferredPort, openBrowser, b
|
|
|
132
156
|
squawkPort,
|
|
133
157
|
toolActivity,
|
|
134
158
|
}, port, listener);
|
|
159
|
+
parts.server = server;
|
|
135
160
|
if (!server.listening)
|
|
136
161
|
await deps.once(server, 'listening');
|
|
137
162
|
const address = server.address();
|
|
@@ -142,21 +167,6 @@ export async function serveCommand(home, repoRoot, preferredPort, openBrowser, b
|
|
|
142
167
|
const url = `http://${boundHost.includes(':') ? `[${boundHost}]` : boundHost}:${boundPort}`;
|
|
143
168
|
ownership.publishUrl(url);
|
|
144
169
|
deps.printServeBanner(version, repoRoot, repo, checks, url);
|
|
145
|
-
// One stop per process: a repeated signal must not start a second teardown over the first.
|
|
146
|
-
let stopping = false;
|
|
147
|
-
const shutdown = (signal) => {
|
|
148
|
-
if (stopping)
|
|
149
|
-
return;
|
|
150
|
-
stopping = true;
|
|
151
|
-
void deps.stopServe(server, signal, { store }).finally(() => deps.process.exit(0));
|
|
152
|
-
};
|
|
153
|
-
deps.process.on('SIGINT', () => shutdown('SIGINT'));
|
|
154
|
-
deps.process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
155
|
-
if (deps.onTerminal())
|
|
156
|
-
deps.process.on('SIGHUP', () => shutdown('SIGHUP'));
|
|
157
|
-
else
|
|
158
|
-
deps.ignoreHangupOffTerminal();
|
|
159
|
-
deps.watchSupervisor(() => shutdown('SIGTERM'));
|
|
160
170
|
// Open the browser only once the server actually answers, so the first
|
|
161
171
|
// paint is the cockpit and never a connection error.
|
|
162
172
|
if (openBrowser) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve-command.js","sourceRoot":"","sources":["../src/serve-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1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O,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACpG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IACzB,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAClC,MAAM,GAAG,GAAG,UAAU,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,SAAS,IAAI,SAAS,EAAE,CAAC;IAE5F,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAE1B,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAE5D,uEAAuE;IACvE,qDAAqD;IACrD,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,GAAG,gBAAgB,EAAE,KAAK,CAAC,CAAC;QACxE,IAAI,OAAO;YAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Server } from 'node:http';
|
|
2
|
+
import type { DelegationController } from './delegation/provision.ts';
|
|
3
|
+
import type { PreviewHost } from './preview/host.ts';
|
|
4
|
+
import type { RunStore } from './runs/store.ts';
|
|
5
|
+
import type { StoppableServer, StopServeOptions } from './serve-boot.ts';
|
|
6
|
+
/** What `serve` has built so far. Boot fills each field as the part comes to exist. */
|
|
7
|
+
export interface ServeParts {
|
|
8
|
+
listener?: Pick<Server, 'close' | 'closeAllConnections'>;
|
|
9
|
+
store?: Pick<RunStore, 'close'>;
|
|
10
|
+
delegation?: Pick<DelegationController, 'close'>;
|
|
11
|
+
previewHost?: Pick<PreviewHost, 'close'> | undefined;
|
|
12
|
+
/** Set once `startServer` returned: its own shutdown then stops every part above. */
|
|
13
|
+
server?: StoppableServer;
|
|
14
|
+
}
|
|
15
|
+
export interface ServeStopDeps {
|
|
16
|
+
process: {
|
|
17
|
+
on(event: NodeJS.Signals, listener: () => void): unknown;
|
|
18
|
+
exit(code?: number): unknown;
|
|
19
|
+
};
|
|
20
|
+
stopServe: (server: StoppableServer, signal: NodeJS.Signals, opts: StopServeOptions) => Promise<void>;
|
|
21
|
+
onTerminal: () => boolean;
|
|
22
|
+
ignoreHangupOffTerminal: () => void;
|
|
23
|
+
watchSupervisor: (onLost: () => void) => unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface ServeStop {
|
|
26
|
+
readonly parts: ServeParts;
|
|
27
|
+
/** True once a signal started the stop: boot then starts nothing more. */
|
|
28
|
+
readonly stopping: boolean;
|
|
29
|
+
/** The stop in progress, which ends the process; undefined while none started. */
|
|
30
|
+
readonly stopped: Promise<void> | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The shutdown of a serve that has not started its server yet: the parts that exist, store last. */
|
|
33
|
+
export declare function partialServe(parts: ServeParts): StoppableServer;
|
|
34
|
+
/**
|
|
35
|
+
* Install serve's stop before the first boot step that can start a process
|
|
36
|
+
* (hearsay-tools/cezarion#991). Recovery resumes agents in their own process groups, so a signal
|
|
37
|
+
* that arrived before this handler ended Squawk by the default action and left those agents
|
|
38
|
+
* running. The stop shuts down what exists at the signal and forwards it to the agent groups
|
|
39
|
+
* last, through `stopServe`. One stop per process: a repeated signal does not start a second one.
|
|
40
|
+
*/
|
|
41
|
+
export declare function installServeStop(deps: ServeStopDeps): ServeStop;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** The shutdown of a serve that has not started its server yet: the parts that exist, store last. */
|
|
2
|
+
export function partialServe(parts) {
|
|
3
|
+
return {
|
|
4
|
+
shutdownForRestart: async () => {
|
|
5
|
+
await parts.previewHost?.close().catch(() => undefined);
|
|
6
|
+
await parts.delegation?.close().catch(() => undefined);
|
|
7
|
+
parts.listener?.close();
|
|
8
|
+
parts.listener?.closeAllConnections();
|
|
9
|
+
parts.store?.close();
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Install serve's stop before the first boot step that can start a process
|
|
15
|
+
* (hearsay-tools/cezarion#991). Recovery resumes agents in their own process groups, so a signal
|
|
16
|
+
* that arrived before this handler ended Squawk by the default action and left those agents
|
|
17
|
+
* running. The stop shuts down what exists at the signal and forwards it to the agent groups
|
|
18
|
+
* last, through `stopServe`. One stop per process: a repeated signal does not start a second one.
|
|
19
|
+
*/
|
|
20
|
+
export function installServeStop(deps) {
|
|
21
|
+
const parts = {};
|
|
22
|
+
let stopped;
|
|
23
|
+
const stop = (signal) => {
|
|
24
|
+
if (stopped)
|
|
25
|
+
return;
|
|
26
|
+
stopped = deps.stopServe(parts.server ?? partialServe(parts), signal, { store: parts.store })
|
|
27
|
+
.finally(() => { deps.process.exit(0); });
|
|
28
|
+
};
|
|
29
|
+
deps.process.on('SIGINT', () => stop('SIGINT'));
|
|
30
|
+
deps.process.on('SIGTERM', () => stop('SIGTERM'));
|
|
31
|
+
if (deps.onTerminal())
|
|
32
|
+
deps.process.on('SIGHUP', () => stop('SIGHUP'));
|
|
33
|
+
else
|
|
34
|
+
deps.ignoreHangupOffTerminal();
|
|
35
|
+
deps.watchSupervisor(() => stop('SIGTERM'));
|
|
36
|
+
return {
|
|
37
|
+
parts,
|
|
38
|
+
get stopping() { return stopped !== undefined; },
|
|
39
|
+
get stopped() { return stopped; },
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=serve-stop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-stop.js","sourceRoot":"","sources":["../src/serve-stop.ts"],"names":[],"mappings":"AAgCA,qGAAqG;AACrG,MAAM,UAAU,YAAY,CAAC,KAAiB;IAC5C,OAAO;QACL,kBAAkB,EAAE,KAAK,IAAI,EAAE;YAC7B,MAAM,KAAK,CAAC,WAAW,EAAE,K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EAAE,CAAC;IACpC,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC5C,OAAO;QACL,KAAK;QACL,IAAI,QAAQ,KAAK,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC;QAChD,IAAI,OAAO,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side health cache (stale-while-revalidate). The snapshot reads Git and workspace state,
|
|
3
|
+
* and each Git read spawns a child process on the server loop. Paying that on the browser's FIRST
|
|
4
|
+
* `GET /api/health` is the few-seconds-blank the cockpit showed at load, so the live server computes
|
|
5
|
+
* the snapshot at its own pace: the GET and the WS `health` topic serve the cached value at once and
|
|
6
|
+
* revalidate behind the response, and the cache is pre-warmed at boot.
|
|
7
|
+
*/
|
|
8
|
+
/** How often a read starts a revalidation. */
|
|
9
|
+
export declare const HEALTH_TTL_MS = 5000;
|
|
10
|
+
/**
|
|
11
|
+
* The staleness CEILING, a different job from the TTL. The TTL decides how often a revalidation
|
|
12
|
+
* starts; on its own it bounds nothing, because the revalidation is fire-and-forget. While a cockpit
|
|
13
|
+
* holds the `health` topic the publisher's interval keeps the cache warm — but the normal state of a
|
|
14
|
+
* background `hsq serve` is NO subscriber, and then nothing refreshes the cache at all: the next GET,
|
|
15
|
+
* an hour later, would answer with the boot pre-warm's payload. `repo.branch` going stale there is
|
|
16
|
+
* hearsay-tools/cezarion#369, so past this age the read waits for the compute.
|
|
17
|
+
*/
|
|
18
|
+
export declare const HEALTH_MAX_STALE_MS = 60000;
|
|
19
|
+
export interface HealthCache<T> {
|
|
20
|
+
/** Compute a new snapshot. Concurrent callers share ONE compute rather than racing two. */
|
|
21
|
+
refresh(): Promise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* The cached payload, revalidated behind the read when stale, awaited when too old or absent.
|
|
24
|
+
* `serveCached` shapes only a payload served from the cache; a computed one is returned as is.
|
|
25
|
+
*/
|
|
26
|
+
read(serveCached?: (payload: T) => T): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Change the cached payload without a new snapshot, after any cold snapshot finishes. The cache
|
|
29
|
+
* keeps its age, so the fields it did not change keep their TTL and staleness ceiling. With no
|
|
30
|
+
* cached payload it computes one.
|
|
31
|
+
*/
|
|
32
|
+
patch(update: (payload: T) => T): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export declare function createHealthCache<T>(options: {
|
|
35
|
+
snapshot: () => Promise<T>;
|
|
36
|
+
/** Called only when the serialized payload changed. */
|
|
37
|
+
publish: (payload: T) => void;
|
|
38
|
+
now?: () => number;
|
|
39
|
+
}): HealthCache<T>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side health cache (stale-while-revalidate). The snapshot reads Git and workspace state,
|
|
3
|
+
* and each Git read spawns a child process on the server loop. Paying that on the browser's FIRST
|
|
4
|
+
* `GET /api/health` is the few-seconds-blank the cockpit showed at load, so the live server computes
|
|
5
|
+
* the snapshot at its own pace: the GET and the WS `health` topic serve the cached value at once and
|
|
6
|
+
* revalidate behind the response, and the cache is pre-warmed at boot.
|
|
7
|
+
*/
|
|
8
|
+
/** How often a read starts a revalidation. */
|
|
9
|
+
export const HEALTH_TTL_MS = 5_000;
|
|
10
|
+
/**
|
|
11
|
+
* The staleness CEILING, a different job from the TTL. The TTL decides how often a revalidation
|
|
12
|
+
* starts; on its own it bounds nothing, because the revalidation is fire-and-forget. While a cockpit
|
|
13
|
+
* holds the `health` topic the publisher's interval keeps the cache warm — but the normal state of a
|
|
14
|
+
* background `hsq serve` is NO subscriber, and then nothing refreshes the cache at all: the next GET,
|
|
15
|
+
* an hour later, would answer with the boot pre-warm's payload. `repo.branch` going stale there is
|
|
16
|
+
* hearsay-tools/cezarion#369, so past this age the read waits for the compute.
|
|
17
|
+
*/
|
|
18
|
+
export const HEALTH_MAX_STALE_MS = 60_000;
|
|
19
|
+
export function createHealthCache(options) {
|
|
20
|
+
const now = options.now ?? Date.now;
|
|
21
|
+
let cache;
|
|
22
|
+
let inFlight;
|
|
23
|
+
const store = (payload, at) => {
|
|
24
|
+
const body = JSON.stringify(payload);
|
|
25
|
+
const changed = body !== cache?.body;
|
|
26
|
+
cache = { at, payload, body };
|
|
27
|
+
if (changed)
|
|
28
|
+
options.publish(payload);
|
|
29
|
+
};
|
|
30
|
+
const refresh = () => {
|
|
31
|
+
if (inFlight)
|
|
32
|
+
return inFlight;
|
|
33
|
+
inFlight = (async () => {
|
|
34
|
+
try {
|
|
35
|
+
const payload = await options.snapshot();
|
|
36
|
+
store(payload, now());
|
|
37
|
+
return payload;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
inFlight = undefined;
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
43
|
+
return inFlight;
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
refresh,
|
|
47
|
+
async read(serveCached = (payload) => payload) {
|
|
48
|
+
if (!cache)
|
|
49
|
+
return refresh();
|
|
50
|
+
const age = now() - cache.at;
|
|
51
|
+
if (age > HEALTH_MAX_STALE_MS)
|
|
52
|
+
return refresh();
|
|
53
|
+
if (age > HEALTH_TTL_MS)
|
|
54
|
+
void refresh().catch(() => { });
|
|
55
|
+
return serveCached(cache.payload);
|
|
56
|
+
},
|
|
57
|
+
async patch(update) {
|
|
58
|
+
await inFlight?.catch(() => { });
|
|
59
|
+
if (cache)
|
|
60
|
+
store(update(cache.payload), cache.at);
|
|
61
|
+
else
|
|
62
|
+
await refresh();
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=health-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health-cache.js","sourceRoot":"","sources":["../../src/server/health-cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8CAA8C;AAC9C,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