@indigoai-us/hq-cli 5.345.226 → 5.345.230
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 +156 -0
- package/dist/command-catalog.generated.d.ts +376 -11
- package/dist/command-catalog.generated.js +451 -11
- package/dist/commands/auth.d.ts +2 -2
- package/dist/commands/auth.js +3 -3
- package/dist/commands/core-delegate-w1b.js +92 -69
- package/dist/commands/core-delegate.d.ts +19 -1
- package/dist/commands/core-delegate.js +411 -6
- package/dist/commands/core-dm-bind-native.js +2 -1
- package/dist/commands/core-handoff.d.ts +5 -0
- package/dist/commands/core-handoff.js +1008 -14
- package/dist/commands/core-pin-native.d.ts +1 -0
- package/dist/commands/core-pin-native.js +3 -15
- package/dist/commands/core-register-project-native.d.ts +6 -0
- package/dist/commands/core-register-project-native.js +182 -52
- package/dist/commands/core-work-mesh-bind-trusted-native.js +4 -9
- package/dist/commands/daemon.js +2 -2
- package/dist/commands/index-cmd.d.ts +3 -1
- package/dist/commands/index-cmd.js +12 -0
- package/dist/commands/lanes-checks.js +1 -1
- package/dist/commands/lanes-session-start.d.ts +1 -2
- package/dist/commands/lanes-session-start.js +9 -145
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +94 -27
- package/dist/commands/link.d.ts +8 -3
- package/dist/commands/link.js +14 -17
- package/dist/commands/mcp-registration.d.ts +65 -7
- package/dist/commands/mcp-registration.js +289 -51
- package/dist/commands/mesh.d.ts +12 -0
- package/dist/commands/mesh.js +92 -10
- package/dist/commands/reindex.js +6 -0
- package/dist/commands/repo.d.ts +13 -0
- package/dist/commands/repo.js +39 -1
- package/dist/commands/sync-mode.d.ts +3 -1
- package/dist/commands/sync-mode.js +11 -1
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +1473 -1043
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lazy-commands.js +3 -4
- package/dist/lib/checkpoint-ontology/entity-file.js +4 -4
- package/dist/lib/checkpoint-ontology/merge-copies.js +7 -11
- package/dist/lib/checkpoint-ontology/plan.js +2 -1
- package/dist/lib/core-utils/archive-old-threads.js +5 -2
- package/dist/lib/core-utils/session-company.d.ts +13 -1
- package/dist/lib/core-utils/session-company.js +75 -4
- package/dist/lib/core-utils/worktree-resume.d.ts +6 -0
- package/dist/lib/core-utils/worktree-resume.js +8 -4
- package/dist/lib/daemon/background-qos.d.ts +7 -0
- package/dist/lib/daemon/background-qos.js +13 -0
- package/dist/lib/daemon/catalog.d.ts +9 -0
- package/dist/lib/daemon/catalog.js +8 -1
- package/dist/lib/daemon/hook-requests-acl-suggest.d.ts +18 -0
- package/dist/lib/daemon/hook-requests-acl-suggest.js +245 -0
- package/dist/lib/daemon/hook-requests-conduct-link.d.ts +20 -0
- package/dist/lib/daemon/hook-requests-conduct-link.js +105 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +32 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.js +214 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.d.ts +44 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.js +292 -0
- package/dist/lib/daemon/hook-requests-mesh.d.ts +54 -0
- package/dist/lib/daemon/hook-requests-mesh.js +559 -0
- package/dist/lib/daemon/hook-requests.d.ts +354 -8
- package/dist/lib/daemon/hook-requests.js +1330 -46
- package/dist/lib/daemon/machine-checks.d.ts +12 -2
- package/dist/lib/daemon/machine-checks.js +27 -10
- package/dist/lib/daemon/merge-sections.d.ts +24 -2
- package/dist/lib/daemon/merge-sections.js +58 -16
- package/dist/lib/daemon/ops/policy.js +4 -2
- package/dist/lib/daemon/resolver.js +9 -2
- package/dist/lib/daemon/run.d.ts +11 -7
- package/dist/lib/daemon/run.js +168 -24
- package/dist/lib/daemon/search-index-worker-v1.d.ts +2 -0
- package/dist/lib/daemon/search-index-worker-v1.js +25 -0
- package/dist/lib/daemon/session-registry.d.ts +0 -1
- package/dist/lib/daemon/session-registry.js +0 -3
- package/dist/lib/daemon/supervisor.d.ts +3 -1
- package/dist/lib/daemon/supervisor.js +1 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +59 -4
- package/dist/lib/daemon/tcc-eperm.js +110 -8
- package/dist/lib/doctor/fix/process-identity.d.ts +20 -2
- package/dist/lib/doctor/fix/process-identity.js +48 -5
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/hook-engine/canary-gate.js +1 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
- package/dist/lib/hot-channels/adapters/attio.js +2 -1
- package/dist/lib/hot-channels/adapters/meetings.js +2 -1
- package/dist/lib/lanes/company-outposts.d.ts +37 -0
- package/dist/lib/lanes/company-outposts.js +164 -0
- package/dist/lib/lanes/liveness.d.ts +6 -0
- package/dist/lib/lanes/liveness.js +49 -8
- package/dist/lib/lanes/orphan-report.d.ts +15 -0
- package/dist/lib/lanes/orphan-report.js +223 -0
- package/dist/lib/lanes/orphan-sweep.d.ts +26 -0
- package/dist/lib/lanes/orphan-sweep.js +152 -0
- package/dist/lib/lanes/reaper.d.ts +2 -0
- package/dist/lib/lanes/reaper.js +11 -8
- package/dist/lib/lanes/reconcile.d.ts +8 -7
- package/dist/lib/lanes/reconcile.js +39 -0
- package/dist/lib/mesh/live/backfill-held.d.ts +13 -0
- package/dist/lib/mesh/live/backfill-held.js +23 -0
- package/dist/lib/mesh/live/daemon/mode.d.ts +8 -4
- package/dist/lib/mesh/live/daemon/mode.js +8 -4
- package/dist/lib/mesh/live/daemon/run.d.ts +14 -3
- package/dist/lib/mesh/live/daemon/run.js +116 -7
- package/dist/lib/mesh/live/direct-drain.d.ts +123 -0
- package/dist/lib/mesh/live/direct-drain.js +315 -0
- package/dist/lib/mesh/live/emit-replay.d.ts +10 -0
- package/dist/lib/mesh/live/emit-replay.js +10 -0
- package/dist/lib/mesh/live/flush.d.ts +15 -0
- package/dist/lib/mesh/live/flush.js +27 -0
- package/dist/lib/mesh/live/liveness-carry.d.ts +45 -0
- package/dist/lib/mesh/live/liveness-carry.js +141 -0
- package/dist/lib/mesh/live/spool.d.ts +19 -0
- package/dist/lib/mesh/live/spool.js +80 -0
- package/dist/lib/safe-store.d.ts +2 -0
- package/dist/lib/safe-store.js +8 -6
- package/dist/lib/search-index/index.d.ts +9 -3
- package/dist/lib/search-index/index.js +35 -10
- package/dist/lib/search-index/worker-process.d.ts +9 -0
- package/dist/lib/search-index/worker-process.js +171 -0
- package/dist/lib/session-company-lock.d.ts +3 -1
- package/dist/lib/session-company-lock.js +3 -2
- package/dist/utils/delegate-command-supervisor.d.ts +3 -0
- package/dist/utils/delegate-command-supervisor.js +44 -0
- package/dist/utils/delegate-lock.d.ts +12 -0
- package/dist/utils/delegate-lock.js +88 -0
- package/dist/utils/frontmatter.d.ts +27 -0
- package/dist/utils/frontmatter.js +33 -0
- package/dist/utils/hook-trust.d.ts +1 -0
- package/dist/utils/hook-trust.js +18 -2
- package/dist/utils/host-registration.d.ts +13 -1
- package/dist/utils/host-registration.js +98 -5
- package/dist/utils/package-use-lease.d.ts +1 -1
- package/dist/utils/package-use-lease.js +15 -7
- package/docs/anywhere-runtime.md +17 -0
- package/package.json +9 -8
- package/scripts/check-function-manifest.mjs +17 -3
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { runShareSuggestionState } from "../../commands/core-share-suggestion-state-native.js";
|
|
5
|
+
import { multiCompanySessionLockRecordedOn } from "../core-utils/session-company.js";
|
|
6
|
+
// Also session-scope-capability.sh's lock-set member rule.
|
|
7
|
+
const SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
8
|
+
// beta.124's path company, `^companies\/([a-z][a-z0-9_-]*)\/`: no length cap.
|
|
9
|
+
const ARTIFACT_COMPANY = /^[a-z][a-z0-9_-]*$/;
|
|
10
|
+
const PATH_SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
11
|
+
const PROJECT = /^[A-Za-z0-9_-]+$/;
|
|
12
|
+
const SESSION = /^[A-Za-z0-9_-]{1,128}$/;
|
|
13
|
+
const APP = /^[A-Za-z0-9_-]{1,128}$/;
|
|
14
|
+
const TRIGGERS = new Set([
|
|
15
|
+
"write", "edit", "multiedit", "deploy", "handoff", "checkpoint", "explicit-share",
|
|
16
|
+
"run-project-complete", "execute-task-complete",
|
|
17
|
+
]);
|
|
18
|
+
function record(value) {
|
|
19
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
20
|
+
? value
|
|
21
|
+
: undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* beta.124's artifact rule. A path's company is its lowercase segment; for a
|
|
25
|
+
* Bash path any other segment is read as the session's company (`primary`),
|
|
26
|
+
* so it classifies only when it is that company. With `primary` null (the
|
|
27
|
+
* note check) a Bash path's segment need only be a slug.
|
|
28
|
+
*/
|
|
29
|
+
function classify(file, primary, trigger, threadHandoff) {
|
|
30
|
+
if (file.length > 1024 || file.includes("\\")
|
|
31
|
+
|| Array.from(file).some(character => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127))
|
|
32
|
+
return undefined;
|
|
33
|
+
const parts = file.split("/");
|
|
34
|
+
if (parts.some(part => !part || part === "." || part === ".."))
|
|
35
|
+
return undefined;
|
|
36
|
+
if (/(revenue|mrr|salary|forecast|payroll|ssn)/i.test(parts.at(-1)))
|
|
37
|
+
return undefined;
|
|
38
|
+
const [prefix, company, area, project, deliverables] = parts;
|
|
39
|
+
const edit = ["write", "edit", "multiedit"].includes(trigger);
|
|
40
|
+
const owner = company && (ARTIFACT_COMPANY.test(company)
|
|
41
|
+
|| (!edit && (primary === null ? PATH_SEGMENT.test(company) : company === primary)));
|
|
42
|
+
if (prefix === "companies" && owner) {
|
|
43
|
+
if (area === "data" && parts.length >= 4)
|
|
44
|
+
return { company, project: "", artifactClass: "vault_data" };
|
|
45
|
+
if (area === "projects" && project && PROJECT.test(project) && deliverables === "deliverables" && parts.length >= 6) {
|
|
46
|
+
return { company, project, artifactClass: "vault_data" };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (prefix === "workspace" && parts.length >= 3 && (company === "threads" || company === "checkpoints")) {
|
|
50
|
+
if (edit)
|
|
51
|
+
return undefined;
|
|
52
|
+
const artifactClass = company === "threads" && (threadHandoff || trigger === "handoff") ? "handoff" : "checkpoint";
|
|
53
|
+
return { company: primary ?? "", project: "", artifactClass };
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* At most twelve normalized references. Raw tool input and output cannot be part of a note.
|
|
59
|
+
* A well-formed path the release could not have suggested is skipped; the rest of the note is kept.
|
|
60
|
+
*/
|
|
61
|
+
export function parseShareCandidates(value) {
|
|
62
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > 12)
|
|
63
|
+
return undefined;
|
|
64
|
+
const result = [];
|
|
65
|
+
for (const item of value) {
|
|
66
|
+
const row = record(item);
|
|
67
|
+
if (!row)
|
|
68
|
+
return undefined;
|
|
69
|
+
const keys = Object.keys(row).length;
|
|
70
|
+
if (row.kind === "path" && typeof row.path === "string" && typeof row.trigger === "string"
|
|
71
|
+
&& ((keys === 3 && row.threadHandoff === undefined)
|
|
72
|
+
|| (keys === 4 && row.threadHandoff === true && row.path.startsWith("workspace/threads/")))
|
|
73
|
+
&& TRIGGERS.has(row.trigger)) {
|
|
74
|
+
if (!classify(row.path, null, row.trigger, row.threadHandoff))
|
|
75
|
+
continue;
|
|
76
|
+
result.push({ kind: "path", path: row.path, trigger: row.trigger,
|
|
77
|
+
...(row.threadHandoff ? { threadHandoff: true } : {}) });
|
|
78
|
+
}
|
|
79
|
+
else if (row.kind === "deploy" && typeof row.appId === "string" && APP.test(row.appId)
|
|
80
|
+
&& keys === 3 && Array.isArray(row.companies) && row.companies.length <= 12
|
|
81
|
+
&& row.companies.every((slug) => typeof slug === "string" && SLUG.test(slug))) {
|
|
82
|
+
result.push({ kind: "deploy", appId: row.appId, companies: row.companies });
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
function regularEntry(file, directory, allowMissing = false) {
|
|
90
|
+
try {
|
|
91
|
+
const stat = fs.lstatSync(file);
|
|
92
|
+
return directory ? stat.isDirectory() : stat.isFile();
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return allowMissing && error.code === "ENOENT";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// beta.124's session company: the first meta.yaml line
|
|
99
|
+
// `^company_slug:[[:space:]]*"?([A-Za-z0-9_-]+)"?[[:space:]]*$`. No length cap, no folder check.
|
|
100
|
+
const META_COMPANY = /^company_slug:[\t\v\f\r ]*"?([A-Za-z0-9_-]+)"?[\t\v\f\r ]*$/;
|
|
101
|
+
/**
|
|
102
|
+
* beta.124's `session_scope_read_companies <root> <session>` for the main
|
|
103
|
+
* thread. An unreadable, foreign or malformed capability gives no companies;
|
|
104
|
+
* a set counts only while the multi-company session lock is on, and only its
|
|
105
|
+
* members that are real company folders (or `personal`) are kept.
|
|
106
|
+
*/
|
|
107
|
+
function capabilityCompanies(root, session, capabilityPath, env) {
|
|
108
|
+
let value;
|
|
109
|
+
try {
|
|
110
|
+
value = record(JSON.parse(fs.readFileSync(capabilityPath, "utf8")));
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
const agent = value?.agent_id;
|
|
116
|
+
if (!value || value.session_id !== session
|
|
117
|
+
|| !(agent === undefined || agent === null || agent === false || agent === ""))
|
|
118
|
+
return [];
|
|
119
|
+
const primary = value.company_slug;
|
|
120
|
+
if (typeof primary !== "string" || !SLUG.test(primary))
|
|
121
|
+
return [];
|
|
122
|
+
const hasSet = Object.hasOwn(value, "company_slugs");
|
|
123
|
+
const set = value.company_slugs;
|
|
124
|
+
if (hasSet && !(Array.isArray(set) && set.length > 0
|
|
125
|
+
&& set.every((slug) => typeof slug === "string" && SLUG.test(slug))
|
|
126
|
+
&& set[0] === primary && new Set(set).size === set.length
|
|
127
|
+
&& ((primary === "personal" && set.length === 1) || (primary !== "personal" && !set.includes("personal")))))
|
|
128
|
+
return [];
|
|
129
|
+
const real = (slug) => slug === "personal" || regularEntry(path.join(root, "companies", slug), true);
|
|
130
|
+
const slugs = hasSet ? set : [primary];
|
|
131
|
+
if (slugs.length <= 1 || !multiCompanySessionLockRecordedOn(primary, env))
|
|
132
|
+
return real(primary) ? [primary] : [];
|
|
133
|
+
return slugs.filter(real);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* beta.124's company rule (Corey ruling, 2026-11-18: widen to match the
|
|
137
|
+
* shell). `company` is the session's meta.yaml company; `allowed` is the
|
|
138
|
+
* capability's lock set, or `[company]` when that set is empty or absent.
|
|
139
|
+
* A suggestion grants nothing: the consumer still asks before any share.
|
|
140
|
+
*/
|
|
141
|
+
function lockedCompanies(root, session, env) {
|
|
142
|
+
if (!SESSION.test(session) || session.startsWith("hqd-"))
|
|
143
|
+
return undefined;
|
|
144
|
+
const workspace = path.join(root, "workspace");
|
|
145
|
+
const sessions = path.join(workspace, "sessions");
|
|
146
|
+
const sessionDir = path.join(sessions, session);
|
|
147
|
+
const metaPath = path.join(sessionDir, "meta.yaml");
|
|
148
|
+
const capabilityPath = path.join(sessionDir, "scope-capability.json");
|
|
149
|
+
if (![workspace, sessions, sessionDir, path.join(root, "companies")].every(dir => regularEntry(dir, true))
|
|
150
|
+
|| !regularEntry(metaPath, false)
|
|
151
|
+
|| !regularEntry(capabilityPath, false, true))
|
|
152
|
+
return undefined;
|
|
153
|
+
const company = fs.readFileSync(metaPath, "utf8").split("\n")
|
|
154
|
+
.map(line => META_COMPANY.exec(line)?.[1]).find(Boolean);
|
|
155
|
+
if (!company)
|
|
156
|
+
return undefined;
|
|
157
|
+
const locked = regularEntry(capabilityPath, false) ? capabilityCompanies(root, session, capabilityPath, env) : [];
|
|
158
|
+
return { company, allowed: locked.length ? locked : [company] };
|
|
159
|
+
}
|
|
160
|
+
function people(root, company) {
|
|
161
|
+
const dir = path.join(root, "companies", company, "people");
|
|
162
|
+
if (!regularEntry(dir, true))
|
|
163
|
+
return [];
|
|
164
|
+
return fs.readdirSync(dir).sort().flatMap(slug => {
|
|
165
|
+
if (!SLUG.test(slug) || !regularEntry(path.join(dir, slug), true))
|
|
166
|
+
return [];
|
|
167
|
+
const file = path.join(dir, slug, "meta.yaml");
|
|
168
|
+
if (!regularEntry(file, false) || fs.statSync(file).size > 32768)
|
|
169
|
+
return [];
|
|
170
|
+
const text = fs.readFileSync(file, "utf8");
|
|
171
|
+
const id = (/^\s*cognito_sub:\s*"?([^"\r\n]*)"?\s*$/m.exec(text)?.[1] ?? "").trim() || slug;
|
|
172
|
+
const field = (name) => new RegExp(`^${name}:\\s*(.+)$`, "m").exec(text)?.[1]?.trim().replace(/^"|"$/g, "");
|
|
173
|
+
return [{ id, name: field("name") || slug, role: field("role") || "" }];
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function select(root, primary, allowed, items) {
|
|
177
|
+
for (const item of items) {
|
|
178
|
+
const fingerprint = (company, cls, value) => createHash("sha256").update(`${company}|${cls}|${value}`).digest("hex");
|
|
179
|
+
let selected;
|
|
180
|
+
let artifact;
|
|
181
|
+
let trigger;
|
|
182
|
+
if (item.kind === "deploy") {
|
|
183
|
+
const matches = [...new Set(item.companies.filter(company => allowed.includes(company)))];
|
|
184
|
+
const company = matches.length === 1 ? matches[0] : matches.length === 0 && allowed.length === 1 ? allowed[0] : undefined;
|
|
185
|
+
if (!company)
|
|
186
|
+
continue;
|
|
187
|
+
selected = { company, project: "", artifactClass: "deployable" };
|
|
188
|
+
artifact = { app_id: item.appId, label: `deploy:${item.appId}`, surface: "deploy" };
|
|
189
|
+
trigger = "deploy";
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const target = classify(item.path, primary, item.trigger, item.threadHandoff);
|
|
193
|
+
if (!target || !allowed.includes(target.company))
|
|
194
|
+
continue;
|
|
195
|
+
selected = target;
|
|
196
|
+
artifact = { path: item.path, label: path.posix.basename(item.path), surface: "vault" };
|
|
197
|
+
trigger = item.trigger;
|
|
198
|
+
}
|
|
199
|
+
const localPeople = people(root, selected.company);
|
|
200
|
+
return JSON.stringify({
|
|
201
|
+
company: selected.company, project: selected.project, trigger, action_kind: "share-suggestion",
|
|
202
|
+
suggested_permission: "read", recommended_surface: artifact.surface,
|
|
203
|
+
artifact: {
|
|
204
|
+
...artifact, class: selected.artifactClass, permission: "read",
|
|
205
|
+
fingerprint: fingerprint(selected.company, selected.artifactClass, item.kind === "deploy" ? item.appId : item.path),
|
|
206
|
+
},
|
|
207
|
+
candidate_hints: {
|
|
208
|
+
sources: [...(localPeople.length ? ["local roster"] : []), "owners", "participants", "recent collaborators"],
|
|
209
|
+
local_people: localPeople, needs_assistant_resolution: true,
|
|
210
|
+
},
|
|
211
|
+
recipients: localPeople.slice(0, 3),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
/** Write only the existing local suggestion state. The consumer still must request approval to share. */
|
|
217
|
+
export function executeAclSuggestion(root, session, candidates, env, now) {
|
|
218
|
+
try {
|
|
219
|
+
const lock = lockedCompanies(root, session, env);
|
|
220
|
+
const payload = lock && select(root, lock.company, lock.allowed, candidates);
|
|
221
|
+
if (!payload)
|
|
222
|
+
return 0;
|
|
223
|
+
const orchestrator = path.join(root, "workspace", "orchestrator");
|
|
224
|
+
const folder = path.join(orchestrator, "share-suggestions");
|
|
225
|
+
if (![orchestrator, folder].every(dir => regularEntry(dir, true, true))
|
|
226
|
+
|| ![session + ".json", session + ".json.tmp", "history.jsonl", "suppressions.jsonl"]
|
|
227
|
+
.every(name => regularEntry(path.join(folder, name), false, true)))
|
|
228
|
+
return 1;
|
|
229
|
+
const deps = { root, now, env };
|
|
230
|
+
const check = runShareSuggestionState(["is-suppressed", session], payload, deps);
|
|
231
|
+
if (check.code || check.stderr)
|
|
232
|
+
return 1;
|
|
233
|
+
if (check.stdout === "true")
|
|
234
|
+
return 0;
|
|
235
|
+
if (check.stdout)
|
|
236
|
+
return 1;
|
|
237
|
+
const result = runShareSuggestionState(["enqueue", session], payload, deps);
|
|
238
|
+
return result.stderr ? 1 : result.code;
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// The note fails without putting a path or an identity in the daemon log.
|
|
242
|
+
return 1;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=hook-requests-acl-suggest.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type HookRequest, type HookRequestResult } from "./hook-requests.js";
|
|
2
|
+
export type ConductLinkKind = "conduct-lanes-link-deliver" | "conduct-link-inherit";
|
|
3
|
+
export type ConductLinkOperation = {
|
|
4
|
+
kind: ConductLinkKind;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
};
|
|
7
|
+
/** The root's hook script each kind runs, with the event the adapter gave it. */
|
|
8
|
+
export declare const CONDUCT_LINK_SCRIPTS: Readonly<Record<ConductLinkKind, string>>;
|
|
9
|
+
/** The adapter ran both through its PostToolUse dispatch (`dispatch_settings_hooks "PostToolUse" "Agent"`). */
|
|
10
|
+
export declare const CONDUCT_LINK_EVENT = "PostToolUse";
|
|
11
|
+
export declare function isConductLinkKind(kind: unknown): kind is ConductLinkKind;
|
|
12
|
+
/** The operation in a conduct note's `args`, or undefined for anything the hook does not write. */
|
|
13
|
+
export declare function parseConductLink(kind: ConductLinkKind, args: Record<string, unknown>, session: unknown): ConductLinkOperation | undefined;
|
|
14
|
+
/** Run the root's hook script for one conduct note (see the file comment). */
|
|
15
|
+
export declare function runConductLink(request: HookRequest, operation: ConductLinkOperation, base: NodeJS.ProcessEnv, options: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
timeoutMs: number;
|
|
18
|
+
killGraceMs: number;
|
|
19
|
+
}): Promise<HookRequestResult>;
|
|
20
|
+
//# sourceMappingURL=hook-requests-conduct-link.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two programs the Codex adapter started at SubagentStop for conduct
|
|
3
|
+
* links, run by the daemon instead (standing rule b; `conduct_lanes_link_deliver`
|
|
4
|
+
* and `conduct_link_inherit_settle` in crates/hq-hook/src/daemon_req.rs).
|
|
5
|
+
*
|
|
6
|
+
* The hq-core v16.0.47 Codex adapter (`hq-codex-hook-adapter.sh`, its
|
|
7
|
+
* `SubagentStop)` arm) fed the completed lifecycle payload through the root's
|
|
8
|
+
* Agent-matched PostToolUse hooks. Two of them start programs:
|
|
9
|
+
*
|
|
10
|
+
* - `conduct-lanes-link-deliver`: `.claude/hooks/conduct-lanes-link-deliver.sh
|
|
11
|
+
* PostToolUse`, which for a root session with a
|
|
12
|
+
* `workspace/lanes-links/by-session/<sid>` pointer runs
|
|
13
|
+
* `hq lanes link _deliver --event PostToolUse` with the payload on stdin.
|
|
14
|
+
* - `conduct-link-inherit`: `.claude/hooks/conduct-link-inherit.sh PostToolUse`,
|
|
15
|
+
* which runs `node core/scripts/lib/conduct-link-inherit.mjs PostToolUse
|
|
16
|
+
* <root>`; its `settle` joins a pending claim of the session to its conduct
|
|
17
|
+
* link once the session's companies are bound, and sweeps stale claims.
|
|
18
|
+
*
|
|
19
|
+
* Each reads only `session_id` from a root payload, so that is all the note
|
|
20
|
+
* carries (`args.session_id`, also the note's session). The daemon runs the
|
|
21
|
+
* root's own hook script, `bash <root>/.claude/hooks/<script> PostToolUse`,
|
|
22
|
+
* with `{"session_id": <sid>}` on stdin:
|
|
23
|
+
*
|
|
24
|
+
* - The program and its arguments are an argv array, no shell; the session id
|
|
25
|
+
* reaches the script only inside the JSON on stdin.
|
|
26
|
+
* - A root without the script: done, nothing is started (the adapter's
|
|
27
|
+
* launcher found no file and went on).
|
|
28
|
+
* - `HQ_ROOT` and `CLAUDE_PROJECT_DIR` are the note's root, as the adapter's
|
|
29
|
+
* launcher set them. The daemon's own `HQ_HOOK_AGENT_ID` is not the
|
|
30
|
+
* session's and is removed: the writer decided the event was a root's before
|
|
31
|
+
* it left the note.
|
|
32
|
+
* - Output is not read: the adapter's `emit_context` has no SubagentStop
|
|
33
|
+
* shape, so what the hooks printed was dropped there too.
|
|
34
|
+
* - Exit status ignored when the script ended by itself (both scripts exit 0
|
|
35
|
+
* on every path); a run stopped at the limit or by a daemon stop is a failed
|
|
36
|
+
* try.
|
|
37
|
+
*/
|
|
38
|
+
import * as fs from "node:fs";
|
|
39
|
+
import * as path from "node:path";
|
|
40
|
+
// A cycle with hook-requests.ts, which dispatches to this module: each side uses the other only inside functions.
|
|
41
|
+
import { spawnRequestProgram } from "./hook-requests.js";
|
|
42
|
+
/** The root's hook script each kind runs, with the event the adapter gave it. */
|
|
43
|
+
export const CONDUCT_LINK_SCRIPTS = {
|
|
44
|
+
"conduct-lanes-link-deliver": ".claude/hooks/conduct-lanes-link-deliver.sh",
|
|
45
|
+
"conduct-link-inherit": ".claude/hooks/conduct-link-inherit.sh",
|
|
46
|
+
};
|
|
47
|
+
/** The adapter ran both through its PostToolUse dispatch (`dispatch_settings_hooks "PostToolUse" "Agent"`). */
|
|
48
|
+
export const CONDUCT_LINK_EVENT = "PostToolUse";
|
|
49
|
+
/**
|
|
50
|
+
* A session id a conduct note carries (`conduct_session` in daemon_req.rs): the
|
|
51
|
+
* scripts' own `^[A-Za-z0-9._-]+$`, not `.` or `..`, at most 512 characters.
|
|
52
|
+
*/
|
|
53
|
+
const CONDUCT_SESSION = /^[A-Za-z0-9._-]{1,512}$/;
|
|
54
|
+
export function isConductLinkKind(kind) {
|
|
55
|
+
return kind === "conduct-lanes-link-deliver" || kind === "conduct-link-inherit";
|
|
56
|
+
}
|
|
57
|
+
/** The operation in a conduct note's `args`, or undefined for anything the hook does not write. */
|
|
58
|
+
export function parseConductLink(kind, args, session) {
|
|
59
|
+
const keys = Object.keys(args);
|
|
60
|
+
if (keys.length !== 1 || keys[0] !== "session_id")
|
|
61
|
+
return undefined;
|
|
62
|
+
const sessionId = args.session_id;
|
|
63
|
+
if (typeof sessionId !== "string" || !CONDUCT_SESSION.test(sessionId) || sessionId === "." || sessionId === ".."
|
|
64
|
+
|| sessionId !== session)
|
|
65
|
+
return undefined;
|
|
66
|
+
return { kind, sessionId };
|
|
67
|
+
}
|
|
68
|
+
/** Run the root's hook script for one conduct note (see the file comment). */
|
|
69
|
+
export async function runConductLink(request, operation, base, options) {
|
|
70
|
+
const script = path.join(request.root, CONDUCT_LINK_SCRIPTS[operation.kind]);
|
|
71
|
+
try {
|
|
72
|
+
if (!fs.statSync(script).isFile())
|
|
73
|
+
return { code: 0 };
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return { code: 0 };
|
|
77
|
+
}
|
|
78
|
+
const env = { ...base };
|
|
79
|
+
delete env.HQ_HOOK_AGENT_ID;
|
|
80
|
+
Object.assign(env, { HQ_ROOT: request.root, CLAUDE_PROJECT_DIR: request.root, HQ_HOOK_REQUEST_ID: request.id });
|
|
81
|
+
const input = JSON.stringify({ session_id: operation.sessionId });
|
|
82
|
+
return new Promise(resolve => {
|
|
83
|
+
if (options.signal?.aborted) {
|
|
84
|
+
resolve({ code: 1 });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const { child, settle } = spawnRequestProgram("bash", [script, CONDUCT_LINK_EVENT], {
|
|
88
|
+
cwd: request.root, env, windowsHide: true, stdio: ["pipe", "ignore", "ignore"],
|
|
89
|
+
}, { timeoutMs: options.timeoutMs, killGraceMs: options.killGraceMs, ...(options.signal ? { signal: options.signal } : {}) });
|
|
90
|
+
// A script that exits before it reads leaves a closed pipe; its exit status is the result.
|
|
91
|
+
child.stdin?.on("error", () => undefined);
|
|
92
|
+
child.stdin?.end(input);
|
|
93
|
+
let settled = false;
|
|
94
|
+
const done = (exited) => {
|
|
95
|
+
if (settled)
|
|
96
|
+
return;
|
|
97
|
+
settled = true;
|
|
98
|
+
const ended = settle();
|
|
99
|
+
resolve({ code: !ended && exited ? 0 : 1 });
|
|
100
|
+
};
|
|
101
|
+
child.once("error", () => done(false));
|
|
102
|
+
child.once("close", (code, signal) => done(code !== null && signal === null));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=hook-requests-conduct-link.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type HookRequest, type HookRequestResult } from "./hook-requests.js";
|
|
2
|
+
export type FleetSessionStartOperation = {
|
|
3
|
+
kind: "fleet-session-start";
|
|
4
|
+
fleetHome: string | null;
|
|
5
|
+
cache: string | null;
|
|
6
|
+
marker: boolean;
|
|
7
|
+
skip: string[];
|
|
8
|
+
budget: string | null;
|
|
9
|
+
helperLight: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** The folder under the fleet home that holds the session-start caches. */
|
|
12
|
+
export declare const FLEET_SESSION_START_CACHE_DIR = "cache/hook-session-start";
|
|
13
|
+
/** The in-flight marker in `<root>/workspace/sessions/<session>/`. */
|
|
14
|
+
export declare const FLEET_SESSION_START_MARKER = ".hq-fleet-local-session-start-running";
|
|
15
|
+
/** The longest the engine runs for one note. */
|
|
16
|
+
export declare const FLEET_SESSION_START_KILL_MS = 60000;
|
|
17
|
+
/** The operation in a note's `kind` and `args`, or undefined for anything the hook does not write. */
|
|
18
|
+
export declare function parseFleetSessionStart(kind: unknown, args: Record<string, unknown>, session: string): FleetSessionStartOperation | undefined;
|
|
19
|
+
/** The pinned engine master-hook.sh would start, or undefined. */
|
|
20
|
+
export declare function pinnedHookEngine(home: string): string | undefined;
|
|
21
|
+
/** `context_text` as the engine printed it: `{"context": text}`, or nothing. */
|
|
22
|
+
export declare function printedContext(stdout: string): string | undefined;
|
|
23
|
+
export interface FleetSessionStartOptions {
|
|
24
|
+
env?: NodeJS.ProcessEnv;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
killGraceMs?: number;
|
|
28
|
+
home?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Run one `fleet-session-start` note. */
|
|
31
|
+
export declare function runFleetSessionStart(request: HookRequest, operation: FleetSessionStartOperation, options: FleetSessionStartOptions): Promise<HookRequestResult>;
|
|
32
|
+
//# sourceMappingURL=hook-requests-fleet-session-start.d.ts.map
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fleet-local adapter's background SessionStart dispatch, done by the
|
|
3
|
+
* daemon (hq-core-rust US-050 c2; `fleet-session-start` in daemon_req.rs).
|
|
4
|
+
*
|
|
5
|
+
* The released adapter (hq-fleet-local v0.4.33, `run_session_start_hooks`,
|
|
6
|
+
* fixture lines 1219-1266) takes a per-chat-kind cache lock, writes an
|
|
7
|
+
* in-flight marker in the session folder, and starts its settings dispatch
|
|
8
|
+
* in a detached subshell. That subshell writes the context the commands
|
|
9
|
+
* printed to `<fleet home>/cache/hook-session-start/<name>`, then removes the
|
|
10
|
+
* marker and the lock. The native hook starts nothing detached (standing
|
|
11
|
+
* rule b). It takes the lock, writes the marker, and leaves this note, with
|
|
12
|
+
* the hook's payload as the note's body.
|
|
13
|
+
*
|
|
14
|
+
* The daemon runs the dispatch with the pinned native engine, using the
|
|
15
|
+
* pointer master-hook.sh reads (`~/.hq/bin/hq-hook/current`). It runs
|
|
16
|
+
* `hq-hook fleet-settings SessionStart --hq-root <root>` (conductor ruling
|
|
17
|
+
* W3-03 Q6): only the fleet-local-settings member's dispatch, in the
|
|
18
|
+
* foreground, never the whole SessionStart chain. The payload goes on stdin,
|
|
19
|
+
* and the note's `fleetHome` and `skip` fields as `HQ_FLEET_HOME` and
|
|
20
|
+
* `HQ_FLEET_LOCAL_HOOK_SKIP` (ruling Q4). Its `budget` and `helperLight`
|
|
21
|
+
* fields go as `HQ_FLEET_LOCAL_HOOK_BUDGET_SECONDS` and
|
|
22
|
+
* `HQ_FLEET_LOCAL_HELPER_LIGHT`, which the adapter's background run
|
|
23
|
+
* inherited from the hook. The engine prints
|
|
24
|
+
* `{"context": ...}`. The subcommand re-reads the root's settings file and
|
|
25
|
+
* starts a command only if every file it starts resolves to a real path under
|
|
26
|
+
* the HQ root, as the daemon checks a `fleet-local-settings` note at drain.
|
|
27
|
+
* The context goes to the cache atomically. Then the marker and the lock are
|
|
28
|
+
* removed, always, also when the run failed, so a prompt does not wait for a
|
|
29
|
+
* dispatch that no longer runs.
|
|
30
|
+
*
|
|
31
|
+
* Where the adapter has no cache (no fleet home, its background switch off,
|
|
32
|
+
* a chat-kind key the hook does not read), the hook leaves the note with
|
|
33
|
+
* `cache: null`: the daemon runs the commands once and drops their context.
|
|
34
|
+
*
|
|
35
|
+
* A note is data. The cache is a single file name of the shape the hook
|
|
36
|
+
* writes (`<platform>-session-<id>.txt`), so the daemon writes only under
|
|
37
|
+
* `<fleetHome>/cache/hook-session-start/`. It removes only that file's
|
|
38
|
+
* `.lock` folder (when empty, like the adapter's `rmdir`) and the session
|
|
39
|
+
* folder's in-flight marker.
|
|
40
|
+
*/
|
|
41
|
+
import * as fs from "node:fs";
|
|
42
|
+
import * as os from "node:os";
|
|
43
|
+
import * as path from "node:path";
|
|
44
|
+
// A cycle with hook-requests.ts, which dispatches to this module: each side uses the other only inside functions.
|
|
45
|
+
import { spawnRequestProgram } from "./hook-requests.js";
|
|
46
|
+
/** The folder under the fleet home that holds the session-start caches. */
|
|
47
|
+
export const FLEET_SESSION_START_CACHE_DIR = "cache/hook-session-start";
|
|
48
|
+
/** The in-flight marker in `<root>/workspace/sessions/<session>/`. */
|
|
49
|
+
export const FLEET_SESSION_START_MARKER = ".hq-fleet-local-session-start-running";
|
|
50
|
+
/** The longest the engine runs for one note. */
|
|
51
|
+
export const FLEET_SESSION_START_KILL_MS = 60_000;
|
|
52
|
+
const STDOUT_MAX_BYTES = 1024 * 1024;
|
|
53
|
+
const PATH_MAX_BYTES = 1024;
|
|
54
|
+
const SKIP_MAX = 256;
|
|
55
|
+
const WORD = /^[A-Za-z0-9._-]+$/;
|
|
56
|
+
const CACHE = /^[A-Za-z0-9._-]+-session-[A-Za-z0-9._-]+\.txt$/;
|
|
57
|
+
const SKIP_WORD = /^[A-Za-z0-9._-]{1,128}$/;
|
|
58
|
+
/** A u64 in decimal, as the hook writes the budget. */
|
|
59
|
+
const BUDGET = /^(0|[1-9][0-9]{0,19})$/;
|
|
60
|
+
const plainName = (text) => WORD.test(text) && text !== "." && text !== "..";
|
|
61
|
+
/** The operation in a note's `kind` and `args`, or undefined for anything the hook does not write. */
|
|
62
|
+
export function parseFleetSessionStart(kind, args, session) {
|
|
63
|
+
if (kind !== "fleet-session-start")
|
|
64
|
+
return undefined;
|
|
65
|
+
const keys = Object.keys(args).sort();
|
|
66
|
+
if (keys.join(",") !== "budget,cache,fleetHome,helperLight,marker,skip")
|
|
67
|
+
return undefined;
|
|
68
|
+
const { fleetHome, cache, marker, skip, budget, helperLight } = args;
|
|
69
|
+
if (fleetHome !== null && (typeof fleetHome !== "string" || !path.isAbsolute(fleetHome) || fleetHome.includes("\0")
|
|
70
|
+
|| Buffer.byteLength(fleetHome) > PATH_MAX_BYTES))
|
|
71
|
+
return undefined;
|
|
72
|
+
if (cache !== null && (typeof cache !== "string" || cache.length > 255 || !CACHE.test(cache)))
|
|
73
|
+
return undefined;
|
|
74
|
+
// A cache lives under a fleet home; a marker is only written beside a cache lock.
|
|
75
|
+
if (cache !== null && fleetHome === null)
|
|
76
|
+
return undefined;
|
|
77
|
+
if (typeof marker !== "boolean" || (marker && cache === null))
|
|
78
|
+
return undefined;
|
|
79
|
+
// The hook writes a marker only for a session id it can name a folder by.
|
|
80
|
+
if (marker && !plainName(session))
|
|
81
|
+
return undefined;
|
|
82
|
+
if (!Array.isArray(skip) || skip.length > SKIP_MAX || !skip.every(word => typeof word === "string" && SKIP_WORD.test(word)))
|
|
83
|
+
return undefined;
|
|
84
|
+
if (budget !== null && (typeof budget !== "string" || !BUDGET.test(budget)))
|
|
85
|
+
return undefined;
|
|
86
|
+
if (typeof helperLight !== "boolean")
|
|
87
|
+
return undefined;
|
|
88
|
+
return { kind, fleetHome, cache, marker, skip: skip, budget, helperLight };
|
|
89
|
+
}
|
|
90
|
+
/** The pinned engine master-hook.sh would start, or undefined. */
|
|
91
|
+
export function pinnedHookEngine(home) {
|
|
92
|
+
let named;
|
|
93
|
+
try {
|
|
94
|
+
named = fs.readFileSync(path.join(home, ".hq", "bin", "hq-hook", "current"), "utf8").split("\n")[0] ?? "";
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
if (!named || !path.isAbsolute(named))
|
|
100
|
+
return undefined;
|
|
101
|
+
try {
|
|
102
|
+
fs.accessSync(named, fs.constants.X_OK);
|
|
103
|
+
return fs.statSync(named).isFile() ? named : undefined;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** `context_text` as the engine printed it: `{"context": text}`, or nothing. */
|
|
110
|
+
export function printedContext(stdout) {
|
|
111
|
+
if (stdout.trim() === "")
|
|
112
|
+
return "";
|
|
113
|
+
try {
|
|
114
|
+
const value = JSON.parse(stdout);
|
|
115
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
116
|
+
const context = value.context;
|
|
117
|
+
if (context === undefined)
|
|
118
|
+
return "";
|
|
119
|
+
if (typeof context === "string")
|
|
120
|
+
return context;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch { /* not one JSON document */ }
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
/** `write_atomically`: a temporary file beside the target, renamed over it. */
|
|
127
|
+
function writeAtomically(target, text) {
|
|
128
|
+
try {
|
|
129
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
130
|
+
const stage = `${target}.${process.pid}`;
|
|
131
|
+
try {
|
|
132
|
+
fs.writeFileSync(stage, text, { mode: 0o600 });
|
|
133
|
+
fs.renameSync(stage, target);
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
fs.rmSync(stage, { force: true });
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Run one `fleet-session-start` note. */
|
|
145
|
+
export async function runFleetSessionStart(request, operation, options) {
|
|
146
|
+
const cache = operation.fleetHome !== null && operation.cache !== null
|
|
147
|
+
? path.join(operation.fleetHome, FLEET_SESSION_START_CACHE_DIR, operation.cache) : undefined;
|
|
148
|
+
const finish = () => {
|
|
149
|
+
// The adapter's background: the marker goes, then its exit trap's `rmdir "$cache.lock"`.
|
|
150
|
+
if (operation.marker)
|
|
151
|
+
fs.rmSync(path.join(request.root, "workspace", "sessions", request.session, FLEET_SESSION_START_MARKER), { force: true });
|
|
152
|
+
if (cache)
|
|
153
|
+
try {
|
|
154
|
+
fs.rmdirSync(`${cache}.lock`);
|
|
155
|
+
}
|
|
156
|
+
catch { /* gone, or not an empty folder */ }
|
|
157
|
+
};
|
|
158
|
+
try {
|
|
159
|
+
const base = { ...(options.env ?? process.env) };
|
|
160
|
+
const home = options.home ?? base.HOME ?? os.homedir();
|
|
161
|
+
const engine = pinnedHookEngine(home);
|
|
162
|
+
if (!engine || !request.body)
|
|
163
|
+
return { code: 1 };
|
|
164
|
+
// Only the note decides the adapter's switches: none of the daemon's own reach the engine.
|
|
165
|
+
for (const name of Object.keys(base))
|
|
166
|
+
if (name.startsWith("HQ_FLEET_LOCAL_") || name === "HQ_FLEET_HOME")
|
|
167
|
+
delete base[name];
|
|
168
|
+
const env = {
|
|
169
|
+
...base, HQ_HOOK_REQUEST_ID: request.id,
|
|
170
|
+
...(operation.fleetHome !== null ? { HQ_FLEET_HOME: operation.fleetHome } : {}),
|
|
171
|
+
...(operation.skip.length ? { HQ_FLEET_LOCAL_HOOK_SKIP: operation.skip.join(" ") } : {}),
|
|
172
|
+
...(operation.budget !== null ? { HQ_FLEET_LOCAL_HOOK_BUDGET_SECONDS: operation.budget } : {}),
|
|
173
|
+
HQ_FLEET_LOCAL_HELPER_LIGHT: operation.helperLight ? "1" : "0",
|
|
174
|
+
};
|
|
175
|
+
const ran = await new Promise(resolve => {
|
|
176
|
+
if (options.signal?.aborted) {
|
|
177
|
+
resolve({ code: 1, ended: true, stdout: "" });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const { child, settle } = spawnRequestProgram(engine, ["fleet-settings", "SessionStart", "--hq-root", request.root], {
|
|
181
|
+
cwd: request.root, env, windowsHide: true, stdio: ["pipe", "pipe", "ignore"],
|
|
182
|
+
}, { timeoutMs: options.timeoutMs ?? FLEET_SESSION_START_KILL_MS, killGraceMs: options.killGraceMs, signal: options.signal });
|
|
183
|
+
child.stdin?.on("error", () => undefined);
|
|
184
|
+
child.stdin?.end(request.body);
|
|
185
|
+
let out = "";
|
|
186
|
+
child.stdout?.setEncoding("utf8");
|
|
187
|
+
child.stdout?.on("data", (text) => { if (out.length < STDOUT_MAX_BYTES)
|
|
188
|
+
out += text; });
|
|
189
|
+
child.stdout?.on("error", () => undefined);
|
|
190
|
+
let settled = false;
|
|
191
|
+
const done = (code) => {
|
|
192
|
+
if (settled)
|
|
193
|
+
return;
|
|
194
|
+
settled = true;
|
|
195
|
+
const ended = settle();
|
|
196
|
+
resolve({ code: ended && code === 0 ? 1 : code, ended, stdout: out });
|
|
197
|
+
};
|
|
198
|
+
child.once("error", () => done(1));
|
|
199
|
+
child.once("close", code => done(code ?? 1));
|
|
200
|
+
});
|
|
201
|
+
// An engine ended at its limit (or a daemon stop) writes nothing, as a killed subshell's trap never ran.
|
|
202
|
+
if (ran.ended)
|
|
203
|
+
return { code: 1 };
|
|
204
|
+
const context = printedContext(ran.stdout);
|
|
205
|
+
// A refusal or unreadable output: no cache, and the same answer next time, so no retry.
|
|
206
|
+
if (ran.code !== 0 || context === undefined || !cache)
|
|
207
|
+
return { code: 0 };
|
|
208
|
+
return { code: writeAtomically(cache, context) ? 0 : 1 };
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
finish();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=hook-requests-fleet-session-start.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type MeshToolWritesOperation = {
|
|
2
|
+
kind: "mesh-tool-writes";
|
|
3
|
+
action: "bind";
|
|
4
|
+
sessionId: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
workMeshHome: string;
|
|
7
|
+
backoffSec: number;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "mesh-tool-writes";
|
|
10
|
+
action: "prd-sync";
|
|
11
|
+
sessionId: string;
|
|
12
|
+
workMeshHome: string;
|
|
13
|
+
};
|
|
14
|
+
/** prd-sync runs per flight, a bound on a dirty file rewritten forever. */
|
|
15
|
+
export declare const MESH_TOOL_WRITES_MAX_RUNS = 64;
|
|
16
|
+
/** The longest a program of a flight runs before its group is told to end. */
|
|
17
|
+
export declare const MESH_TOOL_WRITES_KILL_MS = 60000;
|
|
18
|
+
/** The operation of a `mesh-tool-writes` note's `args`, or undefined for anything the hook does not write. */
|
|
19
|
+
export declare function parseMeshToolWrites(args: Record<string, unknown>, session: string): MeshToolWritesOperation | undefined;
|
|
20
|
+
export interface MeshToolWritesOptions {
|
|
21
|
+
nodeBinary: string;
|
|
22
|
+
hqBinary: string;
|
|
23
|
+
/** The HQ root of the note, already checked against the daemon's own. */
|
|
24
|
+
root: string;
|
|
25
|
+
env?: NodeJS.ProcessEnv;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
killGraceMs?: number;
|
|
29
|
+
now?: () => number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The path `prd-sync --file` may be given for a dirty file's text: the
|
|
33
|
+
* text must be an absolute path with no `..` segment that resolves (links
|
|
34
|
+
* followed) to an existing file under the real HQ root at
|
|
35
|
+
* `companies/<co>/projects/<p>/prd.json`, with plain company and project
|
|
36
|
+
* names. The answer is that file under `root` as given; undefined (refuse)
|
|
37
|
+
* for anything else or anything that cannot be resolved.
|
|
38
|
+
*/
|
|
39
|
+
export declare function prdFileUnderRoot(file: string, root: string): string | undefined;
|
|
40
|
+
/** Run one `mesh-tool-writes` note. Always done (code 0); see the module comment. */
|
|
41
|
+
export declare function runMeshToolWrites(operation: MeshToolWritesOperation, options: MeshToolWritesOptions): Promise<{
|
|
42
|
+
code: number;
|
|
43
|
+
}>;
|
|
44
|
+
//# sourceMappingURL=hook-requests-mesh-tool-writes.d.ts.map
|