@indigoai-us/hq-cli 5.155.0 → 5.157.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/CHANGELOG.md +39 -0
- package/dist/command-catalog.generated.d.ts +4 -1
- package/dist/command-catalog.generated.js +5 -1
- package/dist/commands/agent-mcp.d.ts +1 -3
- package/dist/commands/agent-mcp.js +5 -26
- package/dist/commands/bot.js +13 -2
- package/dist/commands/lanes.js +94 -18
- package/dist/commands/mesh.js +35 -8
- package/dist/lib/agent-kit/attachment-download.d.ts +24 -0
- package/dist/lib/agent-kit/attachment-download.js +47 -0
- package/dist/lib/agent-kit/inbox-state.d.ts +6 -2
- package/dist/lib/agent-kit/inbox-state.js +6 -2
- package/dist/lib/agent-kit/mcp/attachments.d.ts +28 -1
- package/dist/lib/agent-kit/mcp/attachments.js +48 -2
- package/dist/lib/agent-kit/mcp/tools.js +13 -19
- package/dist/lib/bot/api.d.ts +9 -0
- package/dist/lib/bot/attachments.d.ts +45 -0
- package/dist/lib/bot/attachments.js +89 -0
- package/dist/lib/bot/paths.d.ts +5 -0
- package/dist/lib/bot/paths.js +7 -0
- package/dist/lib/bot/run.d.ts +7 -0
- package/dist/lib/bot/run.js +34 -4
- package/dist/lib/bot/runtime/claude.d.ts +1 -0
- package/dist/lib/bot/runtime/claude.js +6 -0
- package/dist/lib/bot/runtime/types.d.ts +8 -0
- package/dist/lib/lanes/mesh-events.d.ts +7 -3
- package/dist/lib/lanes/mesh-events.js +116 -20
- package/dist/lib/lanes/reconcile.js +55 -1
- package/dist/lib/lanes/watcher.js +27 -14
- package/dist/lib/mesh/api.d.ts +27 -1
- package/dist/lib/mesh/api.js +41 -12
- package/dist/lib/mesh/project-board.d.ts +1 -0
- package/dist/lib/mesh/project-board.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.157.0] — 2026-09-24
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Local bots (`hq bot run`) now receive HQ chat attachments. The runner reads
|
|
10
|
+
`attachments` on each inbox item, downloads every file with the bot's own
|
|
11
|
+
machine identity through the same checks `hq_attachment_fetch` uses (chat
|
|
12
|
+
attachment path only, DM must include the bot, company must be one of the
|
|
13
|
+
bot's own, 26 MiB cap), and saves it under `~/.hq/bots/<name>/attachments/`
|
|
14
|
+
(dir 0700, files 0600). The turn text lists each file's name, type, size and
|
|
15
|
+
local path, with small text files inlined; a file that could not be fetched
|
|
16
|
+
gets a one-line reason, which is also logged. A message that is only an
|
|
17
|
+
attachment is answered instead of being acked and dropped. Claude turns get
|
|
18
|
+
`--add-dir` for the attachments folder so gated permission modes can read it.
|
|
19
|
+
The MIME type is also read from the server's `kind` field.
|
|
20
|
+
|
|
21
|
+
## [5.156.0] — 2026-09-24
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- Project-thread lookup treats an omitted server `kind` as the project thread,
|
|
26
|
+
preventing duplicate project threads when a newer lane thread is present.
|
|
27
|
+
- Lane admission reservations are refreshed after Work Mesh lane-thread
|
|
28
|
+
registration so slow registration cannot age the reservation before spawn.
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- `hq mesh project register --channel` and `project set --channel` can bind an
|
|
33
|
+
existing channel to project events. `hq mesh check --project` shows lane
|
|
34
|
+
identity and status, including terminal lane threads.
|
|
35
|
+
- Lane mesh threads keep a stable lane id across resume and account moves.
|
|
36
|
+
Events include the worker profile, model, account, parent lane, and senior
|
|
37
|
+
owner. Stop and dead-host recovery events close terminal threads.
|
|
38
|
+
|
|
39
|
+
### Tests
|
|
40
|
+
|
|
41
|
+
- Cover server-shaped project-thread results and reservation timing after
|
|
42
|
+
lane-thread registration.
|
|
43
|
+
|
|
5
44
|
## [5.155.0] — 2026-09-24
|
|
6
45
|
|
|
7
46
|
### Fixed
|
|
@@ -5708,6 +5708,9 @@ export declare const COMMAND_CATALOG: readonly [{
|
|
|
5708
5708
|
}, {
|
|
5709
5709
|
readonly flags: "--repo <path[@branch]>";
|
|
5710
5710
|
readonly description: "Repository binding (repeatable)";
|
|
5711
|
+
}, {
|
|
5712
|
+
readonly flags: "--channel <channelId>";
|
|
5713
|
+
readonly description: "Bind the project to an existing company or project channel";
|
|
5711
5714
|
}, {
|
|
5712
5715
|
readonly flags: "--create";
|
|
5713
5716
|
readonly description: "Create the Board view when the GET is a 404";
|
|
@@ -5754,7 +5757,7 @@ export declare const COMMAND_CATALOG: readonly [{
|
|
|
5754
5757
|
readonly description: "Company slug or cloud uid";
|
|
5755
5758
|
}, {
|
|
5756
5759
|
readonly flags: "--channel <channelId>";
|
|
5757
|
-
readonly description: "
|
|
5760
|
+
readonly description: "Bind the project to an existing company or project channel";
|
|
5758
5761
|
}, {
|
|
5759
5762
|
readonly flags: "--json";
|
|
5760
5763
|
readonly description: "Print machine-readable JSON";
|
|
@@ -7367,6 +7367,10 @@ export const COMMAND_CATALOG = [
|
|
|
7367
7367
|
"flags": "--repo <path[@branch]>",
|
|
7368
7368
|
"description": "Repository binding (repeatable)"
|
|
7369
7369
|
},
|
|
7370
|
+
{
|
|
7371
|
+
"flags": "--channel <channelId>",
|
|
7372
|
+
"description": "Bind the project to an existing company or project channel"
|
|
7373
|
+
},
|
|
7370
7374
|
{
|
|
7371
7375
|
"flags": "--create",
|
|
7372
7376
|
"description": "Create the Board view when the GET is a 404"
|
|
@@ -7427,7 +7431,7 @@ export const COMMAND_CATALOG = [
|
|
|
7427
7431
|
},
|
|
7428
7432
|
{
|
|
7429
7433
|
"flags": "--channel <channelId>",
|
|
7430
|
-
"description": "
|
|
7434
|
+
"description": "Bind the project to an existing company or project channel"
|
|
7431
7435
|
},
|
|
7432
7436
|
{
|
|
7433
7437
|
"flags": "--json",
|
|
@@ -9,18 +9,16 @@
|
|
|
9
9
|
* hq binary with the machine-identity env pinned.
|
|
10
10
|
*/
|
|
11
11
|
import { Command } from "commander";
|
|
12
|
-
import type { Readable } from "node:stream";
|
|
13
12
|
import { McpServer } from "../lib/agent-kit/mcp/jsonrpc.js";
|
|
14
13
|
import { type HqRunResult, type McpToolClients } from "../lib/agent-kit/mcp/tools.js";
|
|
15
14
|
import { type AgentKitPaths } from "../lib/agent-kit/paths.js";
|
|
16
15
|
import type { ExternalMachineCreds } from "../lib/agent-kit/creds.js";
|
|
16
|
+
export { readBounded } from "../lib/agent-kit/attachment-download.js";
|
|
17
17
|
export declare const AGENT_MCP_SERVER_NAME = "hq-agent";
|
|
18
18
|
export declare const AGENT_MCP_INSTRUCTIONS: string;
|
|
19
19
|
export declare const HQ_SUBPROCESS_TIMEOUT_MS = 120000;
|
|
20
20
|
export declare function defaultRunHq(nodeBinary: string, hqBinary: string, env: NodeJS.ProcessEnv): (args: string[]) => Promise<HqRunResult>;
|
|
21
21
|
export declare function defaultMcpClients(creds: ExternalMachineCreds, credsPath: string, paths?: Pick<AgentKitPaths, "inboxDir" | "attachmentsDir">): McpToolClients;
|
|
22
|
-
/** Drain a stream into memory, refusing past `max` bytes. */
|
|
23
|
-
export declare function readBounded(body: Readable, max: number): Promise<Buffer>;
|
|
24
22
|
export declare function createAgentMcpServer(clients: McpToolClients): McpServer;
|
|
25
23
|
export declare function registerAgentMcpCommand(agent: Command): void;
|
|
26
24
|
//# sourceMappingURL=agent-mcp.d.ts.map
|
|
@@ -12,15 +12,15 @@ import { spawn } from "node:child_process";
|
|
|
12
12
|
import * as os from "node:os";
|
|
13
13
|
import { CLI_VERSION } from "../cli-version.js";
|
|
14
14
|
import { ensureCognitoToken } from "../utils/cognito-session.js";
|
|
15
|
-
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
16
15
|
import { getCompanyUid, vaultApiFetch } from "../utils/vault-api.js";
|
|
17
|
-
import { createCompanyPresignClient } from "./files-browse.js";
|
|
18
|
-
import { MAX_ATTACHMENT_BYTES } from "../lib/agent-kit/mcp/attachments.js";
|
|
19
16
|
import { McpServer } from "../lib/agent-kit/mcp/jsonrpc.js";
|
|
17
|
+
import { createVaultObjectDownloader } from "../lib/agent-kit/attachment-download.js";
|
|
20
18
|
import { buildAgentMcpTools } from "../lib/agent-kit/mcp/tools.js";
|
|
21
19
|
import { readKitConfig } from "../lib/agent-kit/kit-config.js";
|
|
22
20
|
import { agentKitPaths } from "../lib/agent-kit/paths.js";
|
|
23
21
|
import { requireExternalCreds } from "./agent-kit.js";
|
|
22
|
+
// Re-exported for callers that imported it from here before it moved.
|
|
23
|
+
export { readBounded } from "../lib/agent-kit/attachment-download.js";
|
|
24
24
|
export const AGENT_MCP_SERVER_NAME = "hq-agent";
|
|
25
25
|
export const AGENT_MCP_INSTRUCTIONS = "You are acting inside HQ as an enrolled external agent. Tools run as that machine identity: " +
|
|
26
26
|
"hq_whoami (identity), hq_search / hq_files_list / hq_files_read (company vault), " +
|
|
@@ -78,14 +78,8 @@ export function defaultMcpClients(creds, credsPath, paths = agentKitPaths(os.hom
|
|
|
78
78
|
throw err;
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const client = createCompanyPresignClient({ token: await getToken(), companyUid: scopeUid, baseUrl: creds.apiBaseUrl });
|
|
84
|
-
const res = await client.send(new GetObjectCommand({ Bucket: scopeUid, Key: key }));
|
|
85
|
-
if (!res.Body)
|
|
86
|
-
throw new Error(`no body returned for '${key}'`);
|
|
87
|
-
return readBounded(res.Body, MAX_ATTACHMENT_BYTES);
|
|
88
|
-
},
|
|
81
|
+
// Same presign path `hq files cat` uses; the vault API's per-key ACL decides.
|
|
82
|
+
downloadVaultObject: createVaultObjectDownloader({ getToken, baseUrl: creds.apiBaseUrl }),
|
|
89
83
|
apiJson: async (token, path, init) => {
|
|
90
84
|
const res = await vaultApiFetch({
|
|
91
85
|
token,
|
|
@@ -100,21 +94,6 @@ export function defaultMcpClients(creds, credsPath, paths = agentKitPaths(os.hom
|
|
|
100
94
|
},
|
|
101
95
|
};
|
|
102
96
|
}
|
|
103
|
-
/** Drain a stream into memory, refusing past `max` bytes. */
|
|
104
|
-
export async function readBounded(body, max) {
|
|
105
|
-
const chunks = [];
|
|
106
|
-
let total = 0;
|
|
107
|
-
for await (const chunk of body) {
|
|
108
|
-
const b = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
109
|
-
total += b.length;
|
|
110
|
-
if (total > max) {
|
|
111
|
-
body.destroy();
|
|
112
|
-
throw new Error(`object exceeds the ${max}-byte attachment limit`);
|
|
113
|
-
}
|
|
114
|
-
chunks.push(b);
|
|
115
|
-
}
|
|
116
|
-
return Buffer.concat(chunks);
|
|
117
|
-
}
|
|
118
97
|
export function createAgentMcpServer(clients) {
|
|
119
98
|
return new McpServer({
|
|
120
99
|
name: AGENT_MCP_SERVER_NAME,
|
package/dist/commands/bot.js
CHANGED
|
@@ -25,6 +25,7 @@ import { hasPromotionHold, promotionHoldSummary } from "../lib/bot/promotion-hol
|
|
|
25
25
|
* list (online flag), and rm. Secrets are never printed.
|
|
26
26
|
*/
|
|
27
27
|
import { promoteLocalBot } from "../lib/bot/promote.js";
|
|
28
|
+
import { createVaultObjectDownloader } from "../lib/agent-kit/attachment-download.js";
|
|
28
29
|
import { addBotToCompanies, describeCompanyFailures, removeBotFromCompanies } from "./bot-companies.js";
|
|
29
30
|
import { registerBotContinuityCommand } from "./bot-continuity.js";
|
|
30
31
|
import { registerBotJobsCommand } from "./bot-jobs.js";
|
|
@@ -680,9 +681,19 @@ async function runBotResident(nameArg) {
|
|
|
680
681
|
console.log(orphanBotRunMessage(name, outcome));
|
|
681
682
|
return;
|
|
682
683
|
}
|
|
683
|
-
const
|
|
684
|
+
const token = botTokenSupplier(dir);
|
|
685
|
+
const api = new BotApi({ token });
|
|
684
686
|
const owner = new OwnerContextCache(() => lookupOwnerContext(config.ownerUid), Date.now, undefined, config.ownerUid);
|
|
685
|
-
const handle = await runBot({
|
|
687
|
+
const handle = await runBot({
|
|
688
|
+
dir,
|
|
689
|
+
config,
|
|
690
|
+
api,
|
|
691
|
+
runtime: runtimeFor(config.runtime),
|
|
692
|
+
ownerContext: () => owner.get(),
|
|
693
|
+
// Chat attachments are fetched with the bot's own machine identity against
|
|
694
|
+
// the same API its inbox and posts use (BotApi has no baseUrl override either).
|
|
695
|
+
downloadAttachment: createVaultObjectDownloader({ getToken: token }),
|
|
696
|
+
});
|
|
686
697
|
await handle.done;
|
|
687
698
|
void name;
|
|
688
699
|
}
|
package/dist/commands/lanes.js
CHANGED
|
@@ -18,7 +18,7 @@ import { buildOutpostLaneCommand, buildOutpostPickupCommand, createOutpostsClien
|
|
|
18
18
|
import { parseUserYaml } from "../utils/user-yaml-error.js";
|
|
19
19
|
import { vaultApiFetch } from "../utils/vault-api.js";
|
|
20
20
|
import { openMeshTransport } from "../lib/mesh/client.js";
|
|
21
|
-
import { createLaneMesh, emitLaneDecisionEvents, } from "../lib/lanes/mesh-events.js";
|
|
21
|
+
import { createLaneMesh, emitLaneDecisionEvents, emitLaneTerminalStateEvent, laneMeshEventIdentity, } from "../lib/lanes/mesh-events.js";
|
|
22
22
|
import { sessionIdFromEnv } from "../lib/mesh/live/session-identity.js";
|
|
23
23
|
import { AccountResolutionError, compareLaneQueueOrder, coveredLaneIds, DEFAULT_ACCOUNT_HOMES, LANE_PROVIDERS, LANE_STATES, PROVIDER_HOME_ENV, QUESTION_STATUSES, SENIOR_KINDS, accountStatus, appendCappedHistory, canonicalizeHome, createLane, decideAdmission, defaultLivenessDeps, defaultSystemdUserDir, defaultThrottleDeps, installDrainHook, installReconcileTimer, providerPathEnv, probeDrainHookRegistration, isLanesError, isLaneVersionConflict, isTerminalLaneState, listAccountStatuses, listLaneIds, listQuestionIds, listSessionLiveness, loadLanesConfig, laneRunsHere, MAX_LANE_DEPTH, MONITOR_ERROR_EXIT_CODE, MONITOR_ENGINES, MONITOR_MAX_TIMEOUT_MS, MONITOR_UNCOVERED_EXIT_CODE, MAX_WATCHED_LANES, monitorReminderText, readLiveMonitorEvidence, resolveMachineIdentity as lookupMachineIdentity, loadLivenessIndex, parseLaneProvider, parseLaneState, parseLivenessState, parseQuestionStatus, parseSeniorKind, readDaemonPresenceConnected, readLane, retryUpdateLane, readQuestion, resolveAccount, resolveLaneWorker, ignoredWorkerProfileFields, loadWorkerProfile, runReconcilePass, runLaneWatch, sessionLiveness, tryReadLane, uninstallReconcileTimer, updateLane, updateQuestion, writeLanesConfig, appendDropboxMessage, answerDropboxMessage, deliveryRefusalReason, resumeCommandRefusal, dropboxDir, dropboxInboxPath, laneAcceptsDropboxDelivery, laneAcceptsOperatorMessage, laneDeliveryMechanism, hasActiveAdmissionReservation, hasActivePendingResume, hasRecordedSessionId, hasEarlierEligibleQueuedLane, laneAdmissionCapReason, providerSupportsSessionResume, withLaneAdmissionLock, laneIdForAnswerDelivery, operatorMessageRefusalReason, raiseLaneQuestion, sha256Text, writeQuestionBody, } from "../lib/lanes/index.js";
|
|
24
24
|
import { activeLaneStories, laneStories, laneStory, storyWarning, } from "../lib/lanes/stories.js";
|
|
@@ -1150,18 +1150,45 @@ function askDeliveryFailedPath(hqRoot, laneId) {
|
|
|
1150
1150
|
return path.join(runDir(hqRoot, laneId), "ask_delivery_failed.json");
|
|
1151
1151
|
}
|
|
1152
1152
|
async function emitLaneMeshEvent(ctx, company, threadId, event, payload) {
|
|
1153
|
-
if (!
|
|
1153
|
+
if (!company)
|
|
1154
|
+
return;
|
|
1155
|
+
let targetThreadId = threadId;
|
|
1156
|
+
let eventPayload = payload;
|
|
1157
|
+
const laneId = typeof payload.lane_id === "string" ? payload.lane_id.trim() : "";
|
|
1158
|
+
if (laneId && ctx.mesh.ensureLaneThread) {
|
|
1159
|
+
const lane = readLane(ctx.hqRoot(), laneId);
|
|
1160
|
+
const ready = await ensureLaneThreadRecord(ctx, lane, lane.project_id, lane.story_id, "running");
|
|
1161
|
+
targetThreadId = ready.thread_id;
|
|
1162
|
+
eventPayload = { ...laneMeshEventIdentity(ready), ...payload };
|
|
1163
|
+
}
|
|
1164
|
+
if (!targetThreadId)
|
|
1154
1165
|
return;
|
|
1155
|
-
await ctx.mesh.appendThreadEvent(company,
|
|
1166
|
+
await ctx.mesh.appendThreadEvent(company, targetThreadId, event, eventPayload);
|
|
1167
|
+
}
|
|
1168
|
+
async function emitLaneTerminalStateSoft(ctx, lane) {
|
|
1169
|
+
if (lane.state !== "failed" && lane.state !== "interrupted" &&
|
|
1170
|
+
lane.state !== "cancelled" && lane.state !== "killed")
|
|
1171
|
+
return;
|
|
1172
|
+
try {
|
|
1173
|
+
await emitLaneTerminalStateEvent(ctx.mesh, lane, lane.state, lane.terminal_reason, AbortSignal.timeout(10_000));
|
|
1174
|
+
}
|
|
1175
|
+
catch (err) {
|
|
1176
|
+
process.stderr.write(`hq lanes: terminal mesh update failed for ${lane.lane_id}: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
1177
|
+
}
|
|
1156
1178
|
}
|
|
1157
1179
|
async function emitLaneStartedForStories(ctx, company, lane, threadId) {
|
|
1158
|
-
|
|
1180
|
+
const ready = ctx.mesh.ensureLaneThread
|
|
1181
|
+
? await ensureLaneThreadRecord(ctx, lane, lane.project_id, lane.story_id, "running")
|
|
1182
|
+
: lane;
|
|
1183
|
+
const stableThreadId = ready.thread_id ?? threadId;
|
|
1184
|
+
if (!stableThreadId)
|
|
1159
1185
|
return;
|
|
1160
1186
|
const failures = [];
|
|
1161
|
-
for (const story of laneStories(
|
|
1187
|
+
for (const story of laneStories(ready)) {
|
|
1162
1188
|
try {
|
|
1163
|
-
await emitLaneMeshEvent(ctx, company,
|
|
1164
|
-
|
|
1189
|
+
await emitLaneMeshEvent(ctx, company, stableThreadId, "lane_started", {
|
|
1190
|
+
...laneMeshEventIdentity(ready),
|
|
1191
|
+
lane_id: ready.lane_id,
|
|
1165
1192
|
project_id: story.project_id,
|
|
1166
1193
|
story_id: story.story_id,
|
|
1167
1194
|
});
|
|
@@ -1630,9 +1657,8 @@ async function runCreate(ctx, opts) {
|
|
|
1630
1657
|
(profileAccounts === undefined || profileAccounts.includes(id)))
|
|
1631
1658
|
.map(([id]) => id))]
|
|
1632
1659
|
: undefined;
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
: undefined;
|
|
1660
|
+
// The lane id is created in `persist`; its Work Mesh thread is ensured
|
|
1661
|
+
// immediately afterward from that stable identity.
|
|
1636
1662
|
const persist = async () => {
|
|
1637
1663
|
let admission;
|
|
1638
1664
|
let validation;
|
|
@@ -1712,7 +1738,6 @@ async function runCreate(ctx, opts) {
|
|
|
1712
1738
|
added_at: createdAt,
|
|
1713
1739
|
updated_at: createdAt,
|
|
1714
1740
|
})),
|
|
1715
|
-
thread_id: threadId,
|
|
1716
1741
|
depth: laneDepth,
|
|
1717
1742
|
senior,
|
|
1718
1743
|
senior_history: [],
|
|
@@ -1765,7 +1790,35 @@ async function runCreate(ctx, opts) {
|
|
|
1765
1790
|
else {
|
|
1766
1791
|
persisted = await withLaneAdmissionLock(hqRoot, provider, persist, ctx.sleep);
|
|
1767
1792
|
}
|
|
1768
|
-
|
|
1793
|
+
let lane = persisted.lane;
|
|
1794
|
+
const { admission, validation } = persisted;
|
|
1795
|
+
if (meshCompany) {
|
|
1796
|
+
try {
|
|
1797
|
+
lane = await ensureLaneThreadRecord(ctx, lane);
|
|
1798
|
+
}
|
|
1799
|
+
catch {
|
|
1800
|
+
try {
|
|
1801
|
+
lane = casUpdateLane(ctx.hqRoot(), lane.lane_id, (current) => ({
|
|
1802
|
+
...current,
|
|
1803
|
+
state: "failed",
|
|
1804
|
+
queued_reason: undefined,
|
|
1805
|
+
terminal_reason: "mesh_thread_registration_failed",
|
|
1806
|
+
}));
|
|
1807
|
+
}
|
|
1808
|
+
catch {
|
|
1809
|
+
throw new LanesError("mesh_thread_registration_failed", `Work Mesh lane registration failed for ${lane.lane_id}, and its local record could not be marked terminal.`, { lane_id: lane.lane_id });
|
|
1810
|
+
}
|
|
1811
|
+
throw new LanesError("mesh_thread_registration_failed", `Work Mesh lane registration failed; lane ${lane.lane_id} was marked failed.`, { lane_id: lane.lane_id, state: lane.state });
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
// Thread registration runs after persistence; anchor the reservation after
|
|
1815
|
+
// its network work so a slow response cannot age the slot before spawn.
|
|
1816
|
+
if (meshCompany && admission.action === "start" && lane.admission_reserved_at) {
|
|
1817
|
+
lane = casUpdateLane(ctx.hqRoot(), lane.lane_id, (current) => ({
|
|
1818
|
+
...current,
|
|
1819
|
+
admission_reserved_at: ctx.now().toISOString(),
|
|
1820
|
+
}));
|
|
1821
|
+
}
|
|
1769
1822
|
const dest = runDir(hqRoot, lane.lane_id);
|
|
1770
1823
|
ensureDir(path.join(dest, "logs"));
|
|
1771
1824
|
ensureDir(path.join(dest, "envelopes"));
|
|
@@ -1802,7 +1855,7 @@ async function runCreate(ctx, opts) {
|
|
|
1802
1855
|
locateTranscript: ctx.locateTranscript,
|
|
1803
1856
|
});
|
|
1804
1857
|
if (meshCompany)
|
|
1805
|
-
await emitLaneStartedForStories(ctx, meshCompany, started,
|
|
1858
|
+
await emitLaneStartedForStories(ctx, meshCompany, started, started.thread_id);
|
|
1806
1859
|
}
|
|
1807
1860
|
else if (outpostId) {
|
|
1808
1861
|
started = await dispatchCreatedOutpostLane(ctx, {
|
|
@@ -1864,13 +1917,15 @@ async function dispatchCreatedOutpostLane(ctx, input) {
|
|
|
1864
1917
|
const dispatched = await ctx.dispatchOutpostExec({ outpostId, command });
|
|
1865
1918
|
const remote = parseRemotePickupJson(dispatched.stdout);
|
|
1866
1919
|
if (remote?.error === "outpost_self_target") {
|
|
1867
|
-
|
|
1920
|
+
const cancelled = casUpdateLane(hqRoot, lane.lane_id, (current) => ({
|
|
1868
1921
|
...current,
|
|
1869
1922
|
state: "cancelled",
|
|
1870
1923
|
queued_reason: undefined,
|
|
1871
1924
|
terminal_reason: "outpost_self_target",
|
|
1872
1925
|
outpost_command_id: dispatched.commandId,
|
|
1873
1926
|
}));
|
|
1927
|
+
await emitLaneTerminalStateSoft(ctx, cancelled);
|
|
1928
|
+
return cancelled;
|
|
1874
1929
|
}
|
|
1875
1930
|
const stdoutTrimmed = dispatched.stdout.trim();
|
|
1876
1931
|
if (remote === null && stdoutTrimmed !== "" && dispatched.status !== "Success") {
|
|
@@ -1882,6 +1937,7 @@ async function dispatchCreatedOutpostLane(ctx, input) {
|
|
|
1882
1937
|
stderr: dispatched.stderr.slice(0, 2000),
|
|
1883
1938
|
parse_error: "unparseable_pickup_stdout",
|
|
1884
1939
|
});
|
|
1940
|
+
await emitLaneTerminalStateSoft(ctx, failed);
|
|
1885
1941
|
throw new LanesError(DISPATCH_TERMINAL_REASON, "Outpost pickup command failed", {
|
|
1886
1942
|
outpost_id: outpostId,
|
|
1887
1943
|
lane_id: failed.lane_id,
|
|
@@ -1899,6 +1955,7 @@ async function dispatchCreatedOutpostLane(ctx, input) {
|
|
|
1899
1955
|
status: dispatched.status,
|
|
1900
1956
|
stderr: dispatched.stderr.slice(0, 2000),
|
|
1901
1957
|
});
|
|
1958
|
+
await emitLaneTerminalStateSoft(ctx, failed);
|
|
1902
1959
|
throw new LanesError(DISPATCH_TERMINAL_REASON, "Outpost pickup command failed", {
|
|
1903
1960
|
outpost_id: outpostId,
|
|
1904
1961
|
lane_id: failed.lane_id,
|
|
@@ -1923,6 +1980,7 @@ async function dispatchCreatedOutpostLane(ctx, input) {
|
|
|
1923
1980
|
outpost_id: outpostId,
|
|
1924
1981
|
message,
|
|
1925
1982
|
});
|
|
1983
|
+
await emitLaneTerminalStateSoft(ctx, failed);
|
|
1926
1984
|
throw new LanesError(DISPATCH_TERMINAL_REASON, `Failed to dispatch lane to Outpost ${outpostId}: ${message}`, {
|
|
1927
1985
|
outpost_id: outpostId,
|
|
1928
1986
|
lane_id: failed.lane_id,
|
|
@@ -2126,6 +2184,7 @@ async function runPickup(ctx, opts) {
|
|
|
2126
2184
|
env: ctx.env,
|
|
2127
2185
|
});
|
|
2128
2186
|
if (isTerminalLaneState(afterAccount.state)) {
|
|
2187
|
+
await emitLaneTerminalStateSoft(ctx, afterAccount);
|
|
2129
2188
|
printJson({
|
|
2130
2189
|
ok: true,
|
|
2131
2190
|
action: "pickup",
|
|
@@ -3150,17 +3209,32 @@ function callerMayVerifyStory(ctx, lane) {
|
|
|
3150
3209
|
return false;
|
|
3151
3210
|
return sessionIdFromEnv(ctx.env) === lane.senior.id;
|
|
3152
3211
|
}
|
|
3153
|
-
async function ensureStoryThread(ctx, lane, projectId) {
|
|
3212
|
+
async function ensureStoryThread(ctx, lane, projectId, storyId = lane.story_id) {
|
|
3213
|
+
const company = lane.mesh_company ?? lane.company;
|
|
3214
|
+
if (!company)
|
|
3215
|
+
return lane;
|
|
3216
|
+
return ensureLaneThreadRecord(ctx, lane, projectId, storyId);
|
|
3217
|
+
}
|
|
3218
|
+
async function ensureLaneThreadRecord(ctx, lane, projectId = lane.project_id, storyId = lane.story_id, laneStatus = lane.state) {
|
|
3154
3219
|
const company = lane.mesh_company ?? lane.company;
|
|
3155
3220
|
if (!company)
|
|
3156
3221
|
return lane;
|
|
3157
|
-
const
|
|
3158
|
-
|
|
3222
|
+
const descriptorLane = { ...lane, project_id: projectId, story_id: storyId };
|
|
3223
|
+
const threadId = ctx.mesh.ensureLaneThread
|
|
3224
|
+
? await ctx.mesh.ensureLaneThread(company, descriptorLane, laneStatus)
|
|
3225
|
+
: await ctx.mesh.ensureProjectThread(company, projectId);
|
|
3226
|
+
if (threadId === lane.thread_id && !lane.thread_id.startsWith("proj-"))
|
|
3159
3227
|
return lane;
|
|
3160
|
-
|
|
3228
|
+
const updated = casUpdateLane(ctx.hqRoot(), lane.lane_id, (current) => ({
|
|
3161
3229
|
...current,
|
|
3162
3230
|
thread_id: threadId,
|
|
3163
3231
|
}));
|
|
3232
|
+
// The CAS changes the lane version. Refresh once so the server descriptor
|
|
3233
|
+
// and the durable local record converge before the worker starts.
|
|
3234
|
+
if (ctx.mesh.ensureLaneThread) {
|
|
3235
|
+
await ctx.mesh.ensureLaneThread(company, { ...updated, project_id: projectId, story_id: storyId }, laneStatus);
|
|
3236
|
+
}
|
|
3237
|
+
return updated;
|
|
3164
3238
|
}
|
|
3165
3239
|
async function emitStoryTransition(ctx, lane, projectId, storyId, event, status, payload = {}) {
|
|
3166
3240
|
const company = lane.mesh_company ?? lane.company;
|
|
@@ -3174,6 +3248,7 @@ async function emitStoryTransition(ctx, lane, projectId, storyId, event, status,
|
|
|
3174
3248
|
project_id: projectId,
|
|
3175
3249
|
story_id: storyId,
|
|
3176
3250
|
...payload,
|
|
3251
|
+
lane_status: lane.state,
|
|
3177
3252
|
});
|
|
3178
3253
|
await ctx.mesh.patchStoryStatus(company, projectId, storyId, status === "blocked" ? "in_progress" : status);
|
|
3179
3254
|
}
|
|
@@ -3514,6 +3589,7 @@ async function runStop(ctx, laneId) {
|
|
|
3514
3589
|
sleepMs: ctx.stopSleepMs,
|
|
3515
3590
|
});
|
|
3516
3591
|
}
|
|
3592
|
+
await emitLaneTerminalStateSoft(ctx, updated);
|
|
3517
3593
|
const cancelled = cancelPendingQuestionsForLane(hqRoot, laneId, at);
|
|
3518
3594
|
printJson({
|
|
3519
3595
|
ok: true,
|
package/dist/commands/mesh.js
CHANGED
|
@@ -59,14 +59,22 @@ export function formatCheckLines(threads, company, projectId) {
|
|
|
59
59
|
const scope = projectId
|
|
60
60
|
? `${company.companySlug || company.companyUid}/${projectId}`
|
|
61
61
|
: company.companySlug || company.companyUid;
|
|
62
|
-
const lines = [`Work mesh: ${threads.length}
|
|
62
|
+
const lines = [`Work mesh: ${threads.length} thread(s) for ${scope}`];
|
|
63
63
|
for (const thread of threads.slice(0, 8)) {
|
|
64
64
|
const owner = thread.ownerUid ? ` owner=${thread.ownerUid}` : "";
|
|
65
65
|
const summary = thread.progressSummary ||
|
|
66
66
|
thread.sourceSignalSummary ||
|
|
67
67
|
thread.blockedReason ||
|
|
68
68
|
"";
|
|
69
|
-
|
|
69
|
+
const lane = thread.kind === "lane" ? thread.lane : undefined;
|
|
70
|
+
const laneDetails = lane
|
|
71
|
+
? ` lane=${lane.laneId} laneStatus=${thread.laneStatus ?? "unknown"}` +
|
|
72
|
+
` story=${lane.storyId ?? "unknown"} profile=${lane.workerProfile ?? "unknown"}` +
|
|
73
|
+
` model=${lane.model ?? "unknown"} account=${lane.account ?? "unknown"}` +
|
|
74
|
+
`${lane.parentLaneId ? ` parent=${lane.parentLaneId}` : ""}`
|
|
75
|
+
: "";
|
|
76
|
+
const machine = thread.senderMachineUid ? ` machine=${thread.senderMachineUid}` : "";
|
|
77
|
+
lines.push(`- ${thread.threadStatus ?? "unknown"} ${thread.threadId ?? "?"}${owner}${machine}${laneDetails}${summary ? `: ${summary}` : ""}`);
|
|
70
78
|
}
|
|
71
79
|
return lines;
|
|
72
80
|
}
|
|
@@ -320,6 +328,9 @@ function mergeProjectRepos(current, planned) {
|
|
|
320
328
|
return [...planned, ...current.filter((repo) => !plannedPaths.has(repo.path))];
|
|
321
329
|
}
|
|
322
330
|
async function runProjectSet(projectId, opts) {
|
|
331
|
+
if (opts.channel !== undefined && !opts.channel.trim()) {
|
|
332
|
+
fail("PROJECT_CHANNEL_INVALID: --channel must be a non-empty channel id.");
|
|
333
|
+
}
|
|
323
334
|
if (opts.storiesFile && opts.storiesJson) {
|
|
324
335
|
fail("Pass only one of --stories-file or --stories-json.");
|
|
325
336
|
}
|
|
@@ -358,6 +369,7 @@ async function runProjectSet(projectId, opts) {
|
|
|
358
369
|
const principalUid = await resolveMeshPrincipalUid(token, loadCachedTokens());
|
|
359
370
|
const PROJECT_CHANGED = "The Board changed while you were editing. Re-run to pick up the latest.";
|
|
360
371
|
let view;
|
|
372
|
+
let registration;
|
|
361
373
|
if (!current) {
|
|
362
374
|
const ensured = await ensureProjectBoard({
|
|
363
375
|
token,
|
|
@@ -367,10 +379,12 @@ async function runProjectSet(projectId, opts) {
|
|
|
367
379
|
description: opts.description !== undefined ? opts.description : source?.description ?? "",
|
|
368
380
|
stories: source?.stories ?? [],
|
|
369
381
|
repos: explicitRepos ?? source?.repos ?? [],
|
|
382
|
+
channelId: opts.channel,
|
|
370
383
|
});
|
|
371
384
|
view = ensured.view;
|
|
385
|
+
registration = ensured.registration;
|
|
372
386
|
}
|
|
373
|
-
else {
|
|
387
|
+
else if (opts.name !== undefined || opts.description !== undefined || source !== undefined || explicitRepos !== undefined) {
|
|
374
388
|
try {
|
|
375
389
|
view = await putProjectView(token, company.companyUid, projectId, {
|
|
376
390
|
name: opts.name?.trim() || source?.name || current.name,
|
|
@@ -395,18 +409,30 @@ async function runProjectSet(projectId, opts) {
|
|
|
395
409
|
throw err;
|
|
396
410
|
}
|
|
397
411
|
}
|
|
412
|
+
else {
|
|
413
|
+
view = current;
|
|
414
|
+
}
|
|
415
|
+
if (current && opts.channel !== undefined) {
|
|
416
|
+
registration = await registerMeshProject(token, company.companyUid, projectId, opts.channel);
|
|
417
|
+
}
|
|
398
418
|
if (!current && opts.create) {
|
|
399
419
|
noteCallingSessionBound(view.projectId, company);
|
|
400
420
|
}
|
|
401
421
|
if (opts.json) {
|
|
402
|
-
console.log(JSON.stringify({
|
|
422
|
+
console.log(JSON.stringify({
|
|
423
|
+
ok: true,
|
|
424
|
+
action: "project.set",
|
|
425
|
+
principalUid,
|
|
426
|
+
...view,
|
|
427
|
+
...(registration ? { registration } : {}),
|
|
428
|
+
}, null, 2));
|
|
403
429
|
return;
|
|
404
430
|
}
|
|
405
431
|
console.log(`Work mesh: project ${view.projectId} set (${view.name}; ${view.stories.length} stories)`);
|
|
406
432
|
}
|
|
407
433
|
async function runProjectRegister(projectId, opts) {
|
|
408
|
-
if (opts.channel
|
|
409
|
-
fail("--channel
|
|
434
|
+
if (opts.channel !== undefined && !opts.channel.trim()) {
|
|
435
|
+
fail("PROJECT_CHANNEL_INVALID: --channel must be a non-empty channel id.");
|
|
410
436
|
}
|
|
411
437
|
const { token, company } = await withCompany(opts);
|
|
412
438
|
const principalUid = await resolveMeshPrincipalUid(token, loadCachedTokens());
|
|
@@ -425,7 +451,7 @@ async function runProjectRegister(projectId, opts) {
|
|
|
425
451
|
}
|
|
426
452
|
let registration;
|
|
427
453
|
try {
|
|
428
|
-
registration = await registerMeshProject(token, company.companyUid, projectId);
|
|
454
|
+
registration = await registerMeshProject(token, company.companyUid, projectId, opts.channel);
|
|
429
455
|
}
|
|
430
456
|
catch (err) {
|
|
431
457
|
const failure = err;
|
|
@@ -1787,6 +1813,7 @@ export function registerMeshCommand(program) {
|
|
|
1787
1813
|
.option("--stories-json <json>", "Story array or JSON object with userStories")
|
|
1788
1814
|
.option("--repos-json <json>", "Repository array, such as [{path,branch}]")
|
|
1789
1815
|
.option("--repo <path[@branch]>", "Repository binding (repeatable)", collectRepeatable)
|
|
1816
|
+
.option("--channel <channelId>", "Bind the project to an existing company or project channel")
|
|
1790
1817
|
.option("--create", "Create the Board view when the GET is a 404")
|
|
1791
1818
|
.option("--json", "Print machine-readable JSON")
|
|
1792
1819
|
.action((projectId, opts) => wrap(() => runProjectSet(projectId, opts))());
|
|
@@ -1801,7 +1828,7 @@ export function registerMeshCommand(program) {
|
|
|
1801
1828
|
.command("register <projectId>")
|
|
1802
1829
|
.description("Register an existing Board and bind its project channel; use project ensure to create or repair a Board")
|
|
1803
1830
|
.requiredOption("--company <slug|uid>", "Company slug or cloud uid")
|
|
1804
|
-
.option("--channel <channelId>", "
|
|
1831
|
+
.option("--channel <channelId>", "Bind the project to an existing company or project channel")
|
|
1805
1832
|
.option("--json", "Print machine-readable JSON")
|
|
1806
1833
|
.action((projectId, opts) => wrap(() => runProjectRegister(projectId, opts))());
|
|
1807
1834
|
mesh
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault object download for chat attachments, shared by `hq agent mcp`
|
|
3
|
+
* (hq_attachment_fetch) and the local bot runner (`hq bot run`).
|
|
4
|
+
*
|
|
5
|
+
* Bytes come through the same vault presign path `hq files cat` uses
|
|
6
|
+
* (`createCompanyPresignClient` → POST /v1/files/presign) with the caller's own
|
|
7
|
+
* machine token, so the server's per-key ACL stays the authority. The body is
|
|
8
|
+
* read with a hard byte cap so a crafted key cannot pull a large object into
|
|
9
|
+
* memory.
|
|
10
|
+
*/
|
|
11
|
+
import type { Readable } from "node:stream";
|
|
12
|
+
export type VaultObjectDownloader = (scopeUid: string, key: string) => Promise<Buffer>;
|
|
13
|
+
/** Drain a stream into memory, refusing past `max` bytes. */
|
|
14
|
+
export declare function readBounded(body: Readable, max: number): Promise<Buffer>;
|
|
15
|
+
/**
|
|
16
|
+
* A downloader bound to one identity. `baseUrl` pins the API the token is sent
|
|
17
|
+
* to (an enrolled agent passes its own `apiBaseUrl`; undefined = the default
|
|
18
|
+
* vault API, the same one the caller's other API calls use).
|
|
19
|
+
*/
|
|
20
|
+
export declare function createVaultObjectDownloader(opts: {
|
|
21
|
+
getToken: () => Promise<string>;
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
}): VaultObjectDownloader;
|
|
24
|
+
//# sourceMappingURL=attachment-download.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault object download for chat attachments, shared by `hq agent mcp`
|
|
3
|
+
* (hq_attachment_fetch) and the local bot runner (`hq bot run`).
|
|
4
|
+
*
|
|
5
|
+
* Bytes come through the same vault presign path `hq files cat` uses
|
|
6
|
+
* (`createCompanyPresignClient` → POST /v1/files/presign) with the caller's own
|
|
7
|
+
* machine token, so the server's per-key ACL stays the authority. The body is
|
|
8
|
+
* read with a hard byte cap so a crafted key cannot pull a large object into
|
|
9
|
+
* memory.
|
|
10
|
+
*/
|
|
11
|
+
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
12
|
+
import { createCompanyPresignClient } from "../../commands/files-browse.js";
|
|
13
|
+
import { MAX_ATTACHMENT_BYTES } from "./mcp/attachments.js";
|
|
14
|
+
/** Drain a stream into memory, refusing past `max` bytes. */
|
|
15
|
+
export async function readBounded(body, max) {
|
|
16
|
+
const chunks = [];
|
|
17
|
+
let total = 0;
|
|
18
|
+
for await (const chunk of body) {
|
|
19
|
+
const b = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
20
|
+
total += b.length;
|
|
21
|
+
if (total > max) {
|
|
22
|
+
body.destroy();
|
|
23
|
+
throw new Error(`object exceeds the ${max}-byte attachment limit`);
|
|
24
|
+
}
|
|
25
|
+
chunks.push(b);
|
|
26
|
+
}
|
|
27
|
+
return Buffer.concat(chunks);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A downloader bound to one identity. `baseUrl` pins the API the token is sent
|
|
31
|
+
* to (an enrolled agent passes its own `apiBaseUrl`; undefined = the default
|
|
32
|
+
* vault API, the same one the caller's other API calls use).
|
|
33
|
+
*/
|
|
34
|
+
export function createVaultObjectDownloader(opts) {
|
|
35
|
+
return async (scopeUid, key) => {
|
|
36
|
+
const client = createCompanyPresignClient({
|
|
37
|
+
token: await opts.getToken(),
|
|
38
|
+
companyUid: scopeUid,
|
|
39
|
+
...(opts.baseUrl ? { baseUrl: opts.baseUrl } : {}),
|
|
40
|
+
});
|
|
41
|
+
const res = await client.send(new GetObjectCommand({ Bucket: scopeUid, Key: key }));
|
|
42
|
+
if (!res.Body)
|
|
43
|
+
throw new Error(`no body returned for '${key}'`);
|
|
44
|
+
return readBounded(res.Body, MAX_ATTACHMENT_BYTES);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=attachment-download.js.map
|
|
@@ -30,11 +30,15 @@ export interface InboxAttachment {
|
|
|
30
30
|
companyUid?: string;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* The file references on an inbox entry
|
|
33
|
+
* The file references on an inbox entry (a mirrored kit entry or a bot
|
|
34
|
+
* runner's raw inbox item), plural `attachments[]` first and the
|
|
34
35
|
* legacy singular `attachment` as a fallback. Entries without a `vaultPath` are
|
|
35
36
|
* dropped: a reference the bot cannot fetch is worse than none. Pure.
|
|
36
37
|
*/
|
|
37
|
-
export declare function inboxEntryAttachments(e: MirroredInboxEntry
|
|
38
|
+
export declare function inboxEntryAttachments(e: MirroredInboxEntry | {
|
|
39
|
+
attachments?: unknown;
|
|
40
|
+
attachment?: unknown;
|
|
41
|
+
}): InboxAttachment[];
|
|
38
42
|
/**
|
|
39
43
|
* Compact view for bots: who, when, which channel, the text, and any attached
|
|
40
44
|
* files. The attachments belong here because this summary IS the message as far
|