@indigoai-us/hq-cli 5.345.251 → 5.345.252
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 +112 -0
- package/assets/scaffold/core/scripts/hq-session.sh +9 -0
- package/contracts/host-canary-release.json +9 -3
- package/dist/command-catalog.generated.d.ts +121 -1
- package/dist/command-catalog.generated.js +148 -1
- package/dist/commands/bot.js +7 -2
- package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
- package/dist/commands/core-hq-session-binding.d.ts +140 -0
- package/dist/commands/core-hq-session-binding.js +363 -0
- package/dist/commands/core-hq-session-native.d.ts +23 -0
- package/dist/commands/core-hq-session-native.js +59 -9
- package/dist/commands/core-stop-autosave.js +1 -1
- package/dist/commands/core.js +10 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +42 -5
- package/dist/commands/files.js +1 -1
- package/dist/commands/install-global.js +4 -2
- package/dist/commands/logout.js +4 -0
- package/dist/commands/ontology-graph.d.ts +2 -0
- package/dist/commands/ontology-graph.js +33 -0
- package/dist/commands/report.js +35 -2
- package/dist/commands/storage-gate.js +1 -1
- package/dist/commands/vault-retention-flag.js +2 -1
- package/dist/commands/whoami.js +1 -1
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/agent-kit/mcp/tools.js +48 -0
- package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
- package/dist/lib/bot/fleet-cron.d.ts +35 -0
- package/dist/lib/bot/fleet-cron.js +54 -12
- package/dist/lib/bot/fleet-local.d.ts +18 -0
- package/dist/lib/bot/fleet-local.js +51 -5
- package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
- package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
- package/dist/lib/bot/signals-engine-flag.js +1 -1
- package/dist/lib/cli-invite-nudge.js +1 -1
- package/dist/lib/client-version.d.ts +2 -0
- package/dist/lib/client-version.js +24 -0
- package/dist/lib/company-flag-gate.d.ts +30 -0
- package/dist/lib/company-flag-gate.js +104 -0
- package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
- package/dist/lib/daemon/flag.js +2 -1
- package/dist/lib/daemon/legacy-journal-gate.js +3 -1
- package/dist/lib/daemon/shared-flag-reads.js +1 -1
- package/dist/lib/doctor/checks/host-core.js +22 -4
- package/dist/lib/doctor/checks/jq.d.ts +27 -6
- package/dist/lib/doctor/checks/jq.js +46 -8
- package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
- package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
- package/dist/lib/flag-client-gate-headers.d.ts +38 -0
- package/dist/lib/flag-client-gate-headers.js +62 -0
- package/dist/lib/flag-client-headers.d.ts +15 -0
- package/dist/lib/flag-client-headers.js +25 -0
- 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/flag-registry-worker.js +35 -0
- package/dist/lib/flag-registry.d.ts +1 -20
- package/dist/lib/flag-registry.js +5 -81
- package/dist/lib/hook-engine/adapter-core-pin.d.ts +29 -0
- package/dist/lib/hook-engine/adapter-core-pin.js +29 -0
- package/dist/lib/hook-engine/coverage.d.ts +50 -1
- package/dist/lib/hook-engine/coverage.js +111 -7
- package/dist/lib/hook-engine/reconcile.js +3 -2
- package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
- package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
- package/dist/lib/hot-channels/signal-changes.js +683 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
- package/dist/lib/hot-channels/signals-pass.js +232 -12
- package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
- package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
- package/dist/lib/lanes/registry-flag.js +2 -1
- package/dist/lib/lanes/spawn.js +11 -1
- package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
- package/dist/lib/mesh/live/binding-intent.js +201 -0
- package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
- package/dist/lib/mesh/live/binding-receipt.js +365 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
- package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
- package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
- package/dist/lib/mesh/live/daemon/install.js +2 -1
- package/dist/lib/mesh/live/daemon/presence.js +9 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
- package/dist/lib/mesh/live/daemon/run.js +33 -1
- package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
- package/dist/lib/ontology-graph/lineage/index.js +1027 -0
- package/dist/lib/ontology-graph/model/index.d.ts +54 -0
- package/dist/lib/ontology-graph/model/index.js +112 -0
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +75 -0
- package/dist/lib/ontology-graph/model/pass-tasks.js +166 -0
- package/dist/lib/ontology-graph/model/pass.d.ts +6 -0
- package/dist/lib/ontology-graph/model/pass.js +9 -2
- package/dist/lib/ontology-graph/model/pending-items.d.ts +8 -0
- package/dist/lib/ontology-graph/model/pending-items.js +24 -1
- package/dist/lib/ontology-graph/model/step.d.ts +1 -1
- package/dist/lib/ontology-graph/model/tasks.d.ts +11 -3
- package/dist/lib/ontology-graph/model/tasks.js +20 -7
- package/dist/lib/ontology-graph/read/brief.js +41 -6
- package/dist/lib/ontology-graph/read/index.d.ts +4 -0
- package/dist/lib/ontology-graph/read/index.js +173 -29
- package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
- package/dist/lib/ontology-graph/read/lineage.js +262 -0
- package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
- package/dist/lib/ontology-graph/replay/engine.js +213 -8
- package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
- package/dist/lib/ontology-graph/replay/extractors.js +25 -1
- package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
- package/dist/lib/ontology-graph/replay/index.js +9 -3
- package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
- package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
- package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
- package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +1 -0
- package/dist/lib/ontology-graph/schema/index.js +1 -0
- package/dist/lib/ontology-graph/setup/index.js +13 -3
- package/dist/lib/search-index/index.d.ts +33 -1
- package/dist/lib/search-index/index.js +180 -25
- package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
- package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
- package/dist/lib/signals/adapters-catalog.js +1 -1
- package/dist/lib/sync-core/engine-holds.d.ts +1 -0
- package/dist/lib/sync-core/engine-holds.js +26 -0
- package/dist/lib/sync-core/engine-home.d.ts +3 -0
- package/dist/lib/sync-core/engine-home.js +41 -1
- package/dist/lib/sync-core/flag.js +2 -1
- package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
- package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
- package/dist/lib/sync-core/legacy-journal-export.js +120 -55
- package/dist/lib/sync-core/reconcile.d.ts +2 -1
- package/dist/lib/sync-core/reconcile.js +30 -5
- package/dist/lib/sync-invalid-entity-warning.js +2 -1
- package/dist/lib/windows/install-followup.d.ts +41 -0
- package/dist/lib/windows/install-followup.js +87 -0
- package/dist/lib/windows/jq.d.ts +59 -0
- package/dist/lib/windows/jq.js +154 -3
- package/dist/lib/windows/user-path.d.ts +5 -0
- package/dist/lib/windows/user-path.js +1 -1
- package/dist/lib/work-context/auto-bind.d.ts +12 -0
- package/dist/lib/work-context/auto-bind.js +49 -3
- package/dist/lib/work-context/organize.d.ts +4 -2
- package/dist/lib/work-context/organize.js +18 -8
- package/dist/lib/work-context/reconcile.js +16 -1
- package/dist/main.js +12 -1
- package/dist/utils/client-health-contract.d.ts +30 -0
- package/dist/utils/client-health-contract.js +111 -0
- package/dist/utils/client-health.d.ts +5 -2
- package/dist/utils/client-health.js +74 -5
- package/dist/utils/exclusive-lock.d.ts +5 -1
- package/dist/utils/exclusive-lock.js +9 -2
- package/dist/utils/host-registration.d.ts +7 -0
- package/dist/utils/host-registration.js +10 -1
- package/dist/utils/pid.d.ts +31 -0
- package/dist/utils/pid.js +65 -0
- package/dist/utils/resident-package-preload.js +12 -4
- package/dist/utils/sentry-fingerprint.js +3 -0
- package/package.json +8 -8
- package/scripts/install-hook-engine.mjs +5 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ChangeDropReason } from "./signal-changes.js";
|
|
1
2
|
import type { BotRuntimeId } from "../bot/config.js";
|
|
2
3
|
import { type SpawnLike } from "../bot/runtime/index.js";
|
|
3
4
|
import type { HotChannelRunResult, WriteGuard } from "./loop.js";
|
|
@@ -151,6 +152,8 @@ export declare const DEFAULT_MAX_SIGNAL_DOCS = 40;
|
|
|
151
152
|
export declare const BAD_OUTPUT_ATTEMPTS = 3;
|
|
152
153
|
/** Documents in a row with unusable replies after which the pass stops. */
|
|
153
154
|
export declare const BAD_OUTPUT_STOP_AFTER = 3;
|
|
155
|
+
/** Documents in a row that may time out before the pass stops and fails. */
|
|
156
|
+
export declare const TIMEOUT_STOP_AFTER = 3;
|
|
154
157
|
/** Payload bytes sent to claude per document (200 KB). A longer payload is cut with a marker. */
|
|
155
158
|
export declare const MAX_PAYLOAD_BYTES: number;
|
|
156
159
|
export interface BoundedRun {
|
|
@@ -183,6 +186,25 @@ export interface ClaudeSignalsPassOptions {
|
|
|
183
186
|
maxDocs?: number;
|
|
184
187
|
/** Defaults to `{hqRoot}/core/scripts/ontology-source-worklist.sh`. */
|
|
185
188
|
worklistScript?: string;
|
|
189
|
+
/**
|
|
190
|
+
* Told once per document whose signals were written: how many earlier items
|
|
191
|
+
* were shown to the model, and how many `changes` entries were kept and
|
|
192
|
+
* dropped, by reason. Entries that came with no item shown are counted here
|
|
193
|
+
* under `no_block` and are not written to the signal file. A report only; a
|
|
194
|
+
* throw is ignored.
|
|
195
|
+
*/
|
|
196
|
+
onChanges?: (report: {
|
|
197
|
+
file: string;
|
|
198
|
+
shown: number;
|
|
199
|
+
kept: number;
|
|
200
|
+
dropped: number;
|
|
201
|
+
reasons: Partial<Record<ChangeDropReason, number>>;
|
|
202
|
+
}) => void;
|
|
203
|
+
/**
|
|
204
|
+
* Random hex of `bytes` bytes for the labels and the delimiter token of the
|
|
205
|
+
* earlier-items block. Defaults to `crypto.randomBytes`; set in tests only.
|
|
206
|
+
*/
|
|
207
|
+
changeToken?: (bytes: number) => string;
|
|
186
208
|
/** Defaults to the shipped `prompts/signals-pass.md`. */
|
|
187
209
|
promptFile?: string;
|
|
188
210
|
now?: () => Date;
|
|
@@ -270,6 +292,8 @@ interface ParsedSignal {
|
|
|
270
292
|
update?: string;
|
|
271
293
|
/** `HH:MM:SS` start of the transcript line the signal rests on, as the model copied it. */
|
|
272
294
|
at?: string;
|
|
295
|
+
/** `changes` as the model wrote it. Untrusted: validated against the document before anything is written. */
|
|
296
|
+
changes?: unknown;
|
|
273
297
|
}
|
|
274
298
|
/**
|
|
275
299
|
* The timed segments of a meeting transcript, keyed by start time in ms: each
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { prepareSignalPublication, flushSignalPublications } from "../bot/jobs/signal-to-lane.js";
|
|
2
|
+
import { CHANGE_SIGNAL_TYPES, MAX_TIME_LOOKUPS, SOURCE_HEAD_BYTES, appendEarlierItems, changeFields, describeDropped, isVaultSource, loadEarlierItems, pickEarlierItems, readHeadFields, sourceDocTime, validateChanges, } from "./signal-changes.js";
|
|
2
3
|
/**
|
|
3
4
|
* The local signals pass (US-011). After each hot-channel adapter run, the
|
|
4
5
|
* pass takes the adapter's channel through the ontology worklist, asks
|
|
@@ -24,6 +25,18 @@ import { prepareSignalPublication, flushSignalPublications } from "../bot/jobs/s
|
|
|
24
25
|
* MAX_PAYLOAD_BYTES. A payload outside `sources/`, missing or unreadable falls
|
|
25
26
|
* back to the pointer alone, and the reason is warned and kept on the signal.
|
|
26
27
|
*
|
|
28
|
+
* Lineage (signal-changes.ts): each document is sent with a bounded list of
|
|
29
|
+
* earlier open decisions, action items, commitments and risks of the same
|
|
30
|
+
* audience that it may change, picked by rule and appended as data to the
|
|
31
|
+
* same turn. A signal in the reply may carry `changes`; the host validates
|
|
32
|
+
* each entry (target shown, older, another source, quote in the document body
|
|
33
|
+
* and tied to the target) and writes what holds to the signal's frontmatter.
|
|
34
|
+
* No extra model call is made. During a run the list is kept current: a
|
|
35
|
+
* document's new open items are added and the targets it changed are removed
|
|
36
|
+
* once its signals are written, so later documents of the run see both. The
|
|
37
|
+
* run's document order is not changed for this; signal-changes.ts says what
|
|
38
|
+
* that leaves out.
|
|
39
|
+
*
|
|
27
40
|
* Runtime: an HQ Fleet Executive bot's own login first (fleet-complete.ts).
|
|
28
41
|
* When `fleetComplete` names a Claude or Codex Fleet bot whose
|
|
29
42
|
* `hq-fleet-local` helper is installed, every document goes through
|
|
@@ -78,11 +91,15 @@ import { prepareSignalPublication, flushSignalPublications } from "../bot/jobs/s
|
|
|
78
91
|
* Unusable replies: a document whose reply is `claude-bad-output` is sent
|
|
79
92
|
* again, up to BAD_OUTPUT_ATTEMPTS calls in all. If every reply is unusable the
|
|
80
93
|
* pass leaves that document for a later run, goes on to the next one, and
|
|
81
|
-
* fails with `claude-bad-output` at the end.
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
94
|
+
* fails with `claude-bad-output` at the end. A per-document timeout
|
|
95
|
+
* (`claude-timeout` / `codex-timeout`) is the same skip: the document stays
|
|
96
|
+
* unmarked, the warn line names it, and the pass goes on. A long meeting must
|
|
97
|
+
* not fail the rest of the day's signals (feedback_454d69b8). Auth preflight
|
|
98
|
+
* timeout still stops the pass. Every other failure class stops the pass at
|
|
99
|
+
* once, because it would fail the next document the same way. A reply with no
|
|
100
|
+
* stdout is not sent again, and BAD_OUTPUT_STOP_AFTER documents in a row with
|
|
101
|
+
* unusable replies stop the pass, for the same reason. So a run makes at most
|
|
102
|
+
* the document cap (`maxDocs`) × BAD_OUTPUT_ATTEMPTS calls, and
|
|
86
103
|
* BAD_OUTPUT_STOP_AFTER × BAD_OUTPUT_ATTEMPTS when every reply is unusable.
|
|
87
104
|
*/
|
|
88
105
|
import { splitFrontmatterBody } from "../../utils/frontmatter.js";
|
|
@@ -101,7 +118,7 @@ import * as path from "node:path";
|
|
|
101
118
|
import { fileURLToPath } from "node:url";
|
|
102
119
|
import * as yaml from "js-yaml";
|
|
103
120
|
import { audienceKey, COMPANY_AUDIENCE_KEY } from "./audience.js";
|
|
104
|
-
import { appendPackToDocument, openSignalsGraphContext, renderPackNames, writeEntityRefs, } from "./graph-context.js";
|
|
121
|
+
import { appendPackToDocument, openSignalsGraphContext, entityRefsFromPack, renderPackNames, writeEntityRefs, } from "./graph-context.js";
|
|
105
122
|
import { assertVaultPath } from "../signals/write-guard.js";
|
|
106
123
|
import { assertPayloadRef, assertSafeSegment, writeFileAtomic } from "./landing.js";
|
|
107
124
|
import { fleetFailureClass, fleetFailureMessage, runFleetComplete } from "./fleet-complete.js";
|
|
@@ -309,6 +326,8 @@ export const DEFAULT_MAX_SIGNAL_DOCS = 40;
|
|
|
309
326
|
export const BAD_OUTPUT_ATTEMPTS = 3;
|
|
310
327
|
/** Documents in a row with unusable replies after which the pass stops. */
|
|
311
328
|
export const BAD_OUTPUT_STOP_AFTER = 3;
|
|
329
|
+
/** Documents in a row that may time out before the pass stops and fails. */
|
|
330
|
+
export const TIMEOUT_STOP_AFTER = 3;
|
|
312
331
|
/** Payload bytes sent to claude per document (200 KB). A longer payload is cut with a marker. */
|
|
313
332
|
export const MAX_PAYLOAD_BYTES = 200 * 1024;
|
|
314
333
|
/** Output kept per child stream. A longer reply is bad output. */
|
|
@@ -797,6 +816,8 @@ export function parseSignalsReply(reply, runtime) {
|
|
|
797
816
|
body: s.body.trim(),
|
|
798
817
|
...(s.update ? { update: s.update } : {}),
|
|
799
818
|
...(at !== undefined ? { at } : {}),
|
|
819
|
+
// Kept as sent. A malformed `changes` is dropped at write time and never fails the reply.
|
|
820
|
+
...(s.changes !== undefined && s.changes !== null ? { changes: s.changes } : {}),
|
|
800
821
|
};
|
|
801
822
|
});
|
|
802
823
|
}
|
|
@@ -975,6 +996,130 @@ export function createClaudeSignalsPass(options) {
|
|
|
975
996
|
return input;
|
|
976
997
|
}
|
|
977
998
|
};
|
|
999
|
+
// Earlier items a document may change (signal-changes.ts). The open items of
|
|
1000
|
+
// an audience are listed once per pass, from that audience's signal files.
|
|
1001
|
+
const earlierByAudience = new Map();
|
|
1002
|
+
// When a source document happened. NaN: its frontmatter does not parse.
|
|
1003
|
+
const sourceTimes = new Map();
|
|
1004
|
+
const shownFor = new Map();
|
|
1005
|
+
const scanLimitWarned = new Set();
|
|
1006
|
+
const mismatchWarned = new Set();
|
|
1007
|
+
let cappedDocuments = 0;
|
|
1008
|
+
// Counted for the run and told in one line each when a pass call ends.
|
|
1009
|
+
let unparsedSources = 0;
|
|
1010
|
+
let noBlockChanges = 0;
|
|
1011
|
+
const sourceTime = (ref) => {
|
|
1012
|
+
let known = sourceTimes.get(ref);
|
|
1013
|
+
if (!known) {
|
|
1014
|
+
// The head of the file only. readHeadFields never rejects, so no rejection is kept here.
|
|
1015
|
+
known = readHeadFields(path.join(vaultRoot, ref), SOURCE_HEAD_BYTES).then((fields) => {
|
|
1016
|
+
if (fields === null) {
|
|
1017
|
+
unparsedSources += 1;
|
|
1018
|
+
return Number.NaN;
|
|
1019
|
+
}
|
|
1020
|
+
// `when` or `created_at`, else what a Slack thread carries. Never the file's modification time.
|
|
1021
|
+
return sourceDocTime(fields, ref);
|
|
1022
|
+
});
|
|
1023
|
+
sourceTimes.set(ref, known);
|
|
1024
|
+
}
|
|
1025
|
+
return known;
|
|
1026
|
+
};
|
|
1027
|
+
/**
|
|
1028
|
+
* When an earlier item's source happened: its source document's time, else
|
|
1029
|
+
* when the signal was written. NaN when a source document that dates it
|
|
1030
|
+
* cannot be parsed: the item is then left out, and the others are still
|
|
1031
|
+
* compared.
|
|
1032
|
+
*/
|
|
1033
|
+
const earlierTime = async (earlier) => {
|
|
1034
|
+
for (const ref of earlier.datedBy) {
|
|
1035
|
+
const at = await sourceTime(ref);
|
|
1036
|
+
if (Number.isNaN(at) || Number.isFinite(at))
|
|
1037
|
+
return at;
|
|
1038
|
+
}
|
|
1039
|
+
return earlier.writtenMs;
|
|
1040
|
+
};
|
|
1041
|
+
const withEarlier = async (item, document, packed) => {
|
|
1042
|
+
try {
|
|
1043
|
+
let listing = earlierByAudience.get(item.audienceKey);
|
|
1044
|
+
if (!listing) {
|
|
1045
|
+
listing = loadEarlierItems(vaultRoot, item.audienceKey);
|
|
1046
|
+
earlierByAudience.set(item.audienceKey, listing);
|
|
1047
|
+
}
|
|
1048
|
+
const { items, truncated, total, scanned, mismatched } = await listing;
|
|
1049
|
+
if (mismatched > 0 && !mismatchWarned.has(item.audienceKey)) {
|
|
1050
|
+
mismatchWarned.add(item.audienceKey);
|
|
1051
|
+
warn(`signals pass: audience ${item.audienceKey}: skipped ${String(mismatched)} signal ${mismatched === 1 ? "file that carries" : "files that carry"} another audience_key`);
|
|
1052
|
+
}
|
|
1053
|
+
if (truncated && !scanLimitWarned.has(item.audienceKey)) {
|
|
1054
|
+
scanLimitWarned.add(item.audienceKey);
|
|
1055
|
+
warn(`signals pass: audience ${item.audienceKey} has ${String(total)} signal files of the compared types; the earlier-items scan read the newest ${String(scanned)}, and items in the rest are not compared`);
|
|
1056
|
+
}
|
|
1057
|
+
const pointer = splitFrontmatter(await fs.readFile(path.join(vaultRoot, item.file), "utf8")).frontmatter;
|
|
1058
|
+
const at = sourceDocTime(pointer, item.file);
|
|
1059
|
+
const documentMs = Number.isFinite(at) ? at : now().getTime();
|
|
1060
|
+
const sourceRefs = [
|
|
1061
|
+
item.file,
|
|
1062
|
+
...(document.payloadRef !== undefined ? [document.payloadRef] : []),
|
|
1063
|
+
...(typeof pointer.signal_source_ref === "string" ? [pointer.signal_source_ref] : []),
|
|
1064
|
+
];
|
|
1065
|
+
const entityIds = packs.get(item.file)?.entities.map((entity) => entity.id);
|
|
1066
|
+
const { shown, nonce, lookupsCapped } = await pickEarlierItems(items, {
|
|
1067
|
+
// The document itself: the appended graph context is not compared.
|
|
1068
|
+
documentText: document.text,
|
|
1069
|
+
sourceRefs,
|
|
1070
|
+
documentMs,
|
|
1071
|
+
...(entityIds ? { entityIds } : {}),
|
|
1072
|
+
timeOf: earlierTime,
|
|
1073
|
+
...(options.changeToken ? { token: options.changeToken } : {}),
|
|
1074
|
+
});
|
|
1075
|
+
if (lookupsCapped)
|
|
1076
|
+
cappedDocuments += 1;
|
|
1077
|
+
shownFor.set(item.file, { shown, nonce, documentMs, sourceRefs });
|
|
1078
|
+
return shown.length > 0 ? { ...packed, text: appendEarlierItems(packed.text, shown, nonce) } : packed;
|
|
1079
|
+
}
|
|
1080
|
+
catch {
|
|
1081
|
+
// The earlier items are context only: the document is sent without them.
|
|
1082
|
+
shownFor.delete(item.file);
|
|
1083
|
+
return packed;
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
/** The files of a document as sent, before any data was appended: the landed document, then its payload. */
|
|
1087
|
+
const documentParts = (input) => {
|
|
1088
|
+
if (input.payloadText === undefined)
|
|
1089
|
+
return [input.text];
|
|
1090
|
+
const head = input.text.slice(0, input.text.length - input.payloadText.length).replace(/--- payload: [^\n]* ---\n$/, "");
|
|
1091
|
+
return [head, input.payloadText];
|
|
1092
|
+
};
|
|
1093
|
+
/**
|
|
1094
|
+
* Keeps the audience's list current once a document's signals are written:
|
|
1095
|
+
* its new open items are added and the targets it changed are removed, so
|
|
1096
|
+
* the documents after it in this run see both.
|
|
1097
|
+
*/
|
|
1098
|
+
const noteWritten = async (audience, opened, closed) => {
|
|
1099
|
+
if (opened.length === 0 && closed.size === 0)
|
|
1100
|
+
return;
|
|
1101
|
+
const listing = await earlierByAudience.get(audience)?.catch(() => undefined);
|
|
1102
|
+
// Not listed yet: the first listing reads these signals from their files.
|
|
1103
|
+
if (!listing)
|
|
1104
|
+
return;
|
|
1105
|
+
const known = new Set(listing.items.map((entry) => entry.id));
|
|
1106
|
+
listing.items = [...listing.items, ...opened.filter((entry) => !known.has(entry.id))].filter((entry) => !closed.has(entry.id));
|
|
1107
|
+
};
|
|
1108
|
+
/** One line each for what was counted over the run rather than per document. */
|
|
1109
|
+
const tellChangeCounts = () => {
|
|
1110
|
+
if (unparsedSources > 0) {
|
|
1111
|
+
warn(`signals pass: ${String(unparsedSources)} source ${unparsedSources === 1 ? "document" : "documents"} of earlier items could not be parsed; the items they date were not compared`);
|
|
1112
|
+
unparsedSources = 0;
|
|
1113
|
+
}
|
|
1114
|
+
if (cappedDocuments > 0) {
|
|
1115
|
+
warn(`signals pass: ${String(cappedDocuments)} ${cappedDocuments === 1 ? "document" : "documents"} matched more earlier items than the ${String(MAX_TIME_LOOKUPS)} whose source dates are looked up per document; the rest were not compared`);
|
|
1116
|
+
cappedDocuments = 0;
|
|
1117
|
+
}
|
|
1118
|
+
if (noBlockChanges > 0) {
|
|
1119
|
+
warn(`signals pass: ${String(noBlockChanges)} changes ${noBlockChanges === 1 ? "entry" : "entries"} came with no earlier items shown; not written`);
|
|
1120
|
+
noBlockChanges = 0;
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
978
1123
|
const runtimeSpawn = options.runtimeSpawn ?? defaultSpawn;
|
|
979
1124
|
const codexBot = () => {
|
|
980
1125
|
try {
|
|
@@ -1254,7 +1399,7 @@ export function createClaudeSignalsPass(options) {
|
|
|
1254
1399
|
return { items: dated.map((d) => d.item), pending: true };
|
|
1255
1400
|
};
|
|
1256
1401
|
const extract = async (item, document) => {
|
|
1257
|
-
const input = withPack(item, document);
|
|
1402
|
+
const input = await withEarlier(item, document, withPack(item, document));
|
|
1258
1403
|
for (let attempt = 1;; attempt += 1) {
|
|
1259
1404
|
try {
|
|
1260
1405
|
return await extractOnce(item, input);
|
|
@@ -1412,6 +1557,13 @@ export function createClaudeSignalsPass(options) {
|
|
|
1412
1557
|
const segments = input.payloadRef?.startsWith("sources/meetings/") && input.payloadText !== undefined
|
|
1413
1558
|
? transcriptSegments(input.payloadText) : new Map();
|
|
1414
1559
|
const pack = packs.get(item.file);
|
|
1560
|
+
const earlier = shownFor.get(item.file);
|
|
1561
|
+
const changeTotals = { kept: 0, dropped: 0, reasons: {} };
|
|
1562
|
+
const parts = documentParts(input);
|
|
1563
|
+
const documentAt = sourceDocTime(pointer, item.file);
|
|
1564
|
+
// Targets changed and open items written by this document, for the documents after it.
|
|
1565
|
+
const taken = new Set();
|
|
1566
|
+
const opened = [];
|
|
1415
1567
|
// The thread's writers, from the landed document's own frontmatter.
|
|
1416
1568
|
const speakerKeys = typeof pointer.slack_participants === "string" ? pointer.slack_participants.split(",") : [];
|
|
1417
1569
|
for (const signal of signals) {
|
|
@@ -1444,6 +1596,25 @@ export function createClaudeSignalsPass(options) {
|
|
|
1444
1596
|
frontmatter.citations = [citation];
|
|
1445
1597
|
// Host-side: ids come from the document's pack and nowhere else.
|
|
1446
1598
|
writeEntityRefs(frontmatter, pack, { title: signal.title, body: signal.body, type: signal.type, speakerKeys });
|
|
1599
|
+
// Host-side: a target is one of the earlier items shown for this document, and the quote is in the
|
|
1600
|
+
// body of the document as it was before any data was appended.
|
|
1601
|
+
const validation = validateChanges(signal.changes, signal.type, {
|
|
1602
|
+
shown: earlier?.shown ?? [],
|
|
1603
|
+
...(earlier?.nonce ? { nonce: earlier.nonce } : {}),
|
|
1604
|
+
documentParts: parts,
|
|
1605
|
+
documentMs: earlier?.documentMs ?? Number.NEGATIVE_INFINITY,
|
|
1606
|
+
sourceRefs: earlier?.sourceRefs ?? [item.file],
|
|
1607
|
+
...(pack ? { entitiesIn: (text) => entityRefsFromPack(pack, { title: text }, Number.POSITIVE_INFINITY) } : {}),
|
|
1608
|
+
taken,
|
|
1609
|
+
});
|
|
1610
|
+
Object.assign(frontmatter, changeFields(validation));
|
|
1611
|
+
for (const change of validation.kept)
|
|
1612
|
+
taken.add(change.target);
|
|
1613
|
+
changeTotals.kept += validation.kept.length;
|
|
1614
|
+
changeTotals.dropped += validation.droppedTotal;
|
|
1615
|
+
for (const [reason, count] of Object.entries(validation.dropped)) {
|
|
1616
|
+
changeTotals.reasons[reason] = (changeTotals.reasons[reason] ?? 0) + count;
|
|
1617
|
+
}
|
|
1447
1618
|
if (input.payloadRef !== undefined)
|
|
1448
1619
|
frontmatter.payload_ref = input.payloadRef;
|
|
1449
1620
|
if (input.fallback !== undefined)
|
|
@@ -1460,6 +1631,34 @@ export function createClaudeSignalsPass(options) {
|
|
|
1460
1631
|
await appendSignalIndex(vaultRoot, at.slice(0, 10), [rows[rows.length - 1]]);
|
|
1461
1632
|
flushSignalPublications(options.hqRoot, options.company);
|
|
1462
1633
|
written += 1;
|
|
1634
|
+
if (CHANGE_SIGNAL_TYPES.includes(signal.type)) {
|
|
1635
|
+
opened.push({
|
|
1636
|
+
id,
|
|
1637
|
+
type: signal.type,
|
|
1638
|
+
title: String(frontmatter.canonical_content).replace(/\s+/g, " ").trim(),
|
|
1639
|
+
sourceRef,
|
|
1640
|
+
datedBy: [input.payloadRef, sourceRef].filter(isVaultSource),
|
|
1641
|
+
writtenMs: Date.parse(at),
|
|
1642
|
+
entityRefs: Array.isArray(frontmatter.entity_refs) ? frontmatter.entity_refs : [],
|
|
1643
|
+
...(Number.isFinite(documentAt) ? { knownMs: documentAt } : {}),
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
await noteWritten(item.audienceKey, opened.filter((entry) => entry.title.length > 0), taken);
|
|
1648
|
+
// Entries that came with no item shown are counted for the run, not per document and not in the file.
|
|
1649
|
+
const unshown = changeTotals.reasons.no_block ?? 0;
|
|
1650
|
+
noBlockChanges += unshown;
|
|
1651
|
+
if (changeTotals.dropped > unshown) {
|
|
1652
|
+
const shownReasons = { ...changeTotals.reasons };
|
|
1653
|
+
delete shownReasons.no_block;
|
|
1654
|
+
// Reasons and counts only: the entries are model output built from the document.
|
|
1655
|
+
warn(`signals pass: ${item.file}: dropped ${String(changeTotals.dropped - unshown)} changes ${changeTotals.dropped - unshown === 1 ? "entry" : "entries"} (${describeDropped(shownReasons)})`);
|
|
1656
|
+
}
|
|
1657
|
+
try {
|
|
1658
|
+
options.onChanges?.({ file: item.file, shown: earlier?.shown.length ?? 0, ...changeTotals });
|
|
1659
|
+
}
|
|
1660
|
+
catch {
|
|
1661
|
+
// A report only; it never changes the pass's outcome.
|
|
1463
1662
|
}
|
|
1464
1663
|
await beforeWrite();
|
|
1465
1664
|
await appendSignalIndex(vaultRoot, at.slice(0, 10), rows);
|
|
@@ -1473,6 +1672,12 @@ export function createClaudeSignalsPass(options) {
|
|
|
1473
1672
|
let badOutput;
|
|
1474
1673
|
let badDocs = 0;
|
|
1475
1674
|
let badInARow = 0;
|
|
1675
|
+
// Per-document timeouts are skipped, but a provider outage makes every call
|
|
1676
|
+
// hang: stop after TIMEOUT_STOP_AFTER in a row, and fail the pass when
|
|
1677
|
+
// documents timed out and none succeeded.
|
|
1678
|
+
let firstTimeout;
|
|
1679
|
+
let timeoutInARow = 0;
|
|
1680
|
+
let docsOk = 0;
|
|
1476
1681
|
const badOutputFailure = () => badDocs === 1 && badOutput !== undefined
|
|
1477
1682
|
? badOutput
|
|
1478
1683
|
: new SignalsPassError(`${signalsRuntime()}-bad-output`, `${badDocs} documents had unusable ${signalsRuntime()} replies; first: ${badOutput?.message ?? ""}`);
|
|
@@ -1531,15 +1736,25 @@ export function createClaudeSignalsPass(options) {
|
|
|
1531
1736
|
signals = await extract(item, input);
|
|
1532
1737
|
}
|
|
1533
1738
|
catch (err) {
|
|
1534
|
-
if (!(err instanceof SignalsPassError) || err.failure !== "bad-output")
|
|
1739
|
+
if (!(err instanceof SignalsPassError) || (err.failure !== "bad-output" && err.failure !== "timeout"))
|
|
1535
1740
|
throw err;
|
|
1536
|
-
// One document's unusable reply
|
|
1537
|
-
// behind it. It stays unmarked (or pending)
|
|
1538
|
-
//
|
|
1741
|
+
// One document's unusable reply or per-document timeout must not
|
|
1742
|
+
// hold back the documents behind it. It stays unmarked (or pending)
|
|
1743
|
+
// for a later run. Timeout does not fail the pass: a long meeting
|
|
1744
|
+
// is not a global outage. Bad output still fails once the rest
|
|
1745
|
+
// are done.
|
|
1746
|
+
warn(`signals pass: ${item.file}: ${err.message}; left for a later run`);
|
|
1747
|
+
if (err.failure === "timeout") {
|
|
1748
|
+
firstTimeout ??= err;
|
|
1749
|
+
timeoutInARow += 1;
|
|
1750
|
+
if (timeoutInARow >= TIMEOUT_STOP_AFTER)
|
|
1751
|
+
throw firstTimeout;
|
|
1752
|
+
continue;
|
|
1753
|
+
}
|
|
1754
|
+
timeoutInARow = 0;
|
|
1539
1755
|
badOutput ??= err;
|
|
1540
1756
|
badDocs += 1;
|
|
1541
1757
|
badInARow += 1;
|
|
1542
|
-
warn(`signals pass: ${item.file}: ${err.message}; left for a later run`);
|
|
1543
1758
|
// Several documents in a row means the cause is not one document
|
|
1544
1759
|
// (an unrecognised provider message, a changed reply format), so
|
|
1545
1760
|
// the rest would fail the same way.
|
|
@@ -1548,6 +1763,8 @@ export function createClaudeSignalsPass(options) {
|
|
|
1548
1763
|
continue;
|
|
1549
1764
|
}
|
|
1550
1765
|
badInARow = 0;
|
|
1766
|
+
timeoutInARow = 0;
|
|
1767
|
+
docsOk += 1;
|
|
1551
1768
|
progress.written += await write(item, input, signals, beforeWrite);
|
|
1552
1769
|
if (item.fromWorklist) {
|
|
1553
1770
|
await runWorklist(["--company", options.company, "--channel", channel, "--mark-done", item.file]);
|
|
@@ -1560,6 +1777,8 @@ export function createClaudeSignalsPass(options) {
|
|
|
1560
1777
|
}
|
|
1561
1778
|
if (badOutput !== undefined)
|
|
1562
1779
|
throw badOutputFailure();
|
|
1780
|
+
if (firstTimeout !== undefined && docsOk === 0)
|
|
1781
|
+
throw firstTimeout;
|
|
1563
1782
|
};
|
|
1564
1783
|
return async (result, guard) => {
|
|
1565
1784
|
const progress = { written: 0 };
|
|
@@ -1581,6 +1800,7 @@ export function createClaudeSignalsPass(options) {
|
|
|
1581
1800
|
throw err;
|
|
1582
1801
|
}
|
|
1583
1802
|
finally {
|
|
1803
|
+
tellChangeCounts();
|
|
1584
1804
|
await codexTeardown();
|
|
1585
1805
|
}
|
|
1586
1806
|
return progress.written;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createFlagClient } from "
|
|
1
|
+
import { createHqFlagClient as createFlagClient } from "../flag-client-headers.js";
|
|
2
2
|
export declare const OUTPOST_WORKTREE_PRUNER_FLAG = "outpost.worktree-pruner";
|
|
3
3
|
export declare const OUTPOST_WORKTREE_PRUNER_FLAG_FALLBACK = false;
|
|
4
4
|
export declare const OUTPOST_WORKTREE_PRUNER_FLAG_TIMEOUT_MS = 5000;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadCachedTokens } from "@indigoai-us/hq-cloud";
|
|
2
|
-
import { createFlagClient } from "
|
|
2
|
+
import { createHqFlagClient as createFlagClient } from "../flag-client-headers.js";
|
|
3
3
|
import { resolveFlagRegistryEndpoint } from "../flag-registry-endpoint.js";
|
|
4
4
|
export const OUTPOST_WORKTREE_PRUNER_FLAG = "outpost.worktree-pruner";
|
|
5
5
|
export const OUTPOST_WORKTREE_PRUNER_FLAG_FALLBACK = false;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readLocalOverride, } from "@indigoai-us/hq-flags-client";
|
|
2
|
+
import { createHqFlagClient as createFlagClient } from "../flag-client-headers.js";
|
|
2
3
|
import * as fs from "node:fs";
|
|
3
4
|
import * as path from "node:path";
|
|
4
5
|
import { FLAG_REGISTRY_DEFAULT_ENDPOINT, resolveFlagRegistryEndpoint, } from "../flag-registry-endpoint.js";
|
package/dist/lib/lanes/spawn.js
CHANGED
|
@@ -1087,7 +1087,17 @@ export function readPidRecord(filePath) {
|
|
|
1087
1087
|
}
|
|
1088
1088
|
}
|
|
1089
1089
|
export function writePidRecord(filePath, rec) {
|
|
1090
|
-
|
|
1090
|
+
// Temp file then rename, so a reader never sees an empty or partial pid (hq-cli#3626).
|
|
1091
|
+
ensureDir(path.dirname(filePath));
|
|
1092
|
+
const temp = path.join(path.dirname(filePath), `.${path.basename(filePath)}.${process.pid}.${Date.now()}.tmp`);
|
|
1093
|
+
try {
|
|
1094
|
+
fs.writeFileSync(temp, formatPidRecord(rec), "utf8");
|
|
1095
|
+
fs.renameSync(temp, filePath);
|
|
1096
|
+
}
|
|
1097
|
+
catch (err) {
|
|
1098
|
+
fs.rmSync(temp, { force: true });
|
|
1099
|
+
throw err;
|
|
1100
|
+
}
|
|
1091
1101
|
}
|
|
1092
1102
|
export function probePidRecord(rec, isAlive = defaultPidIsAlive, readStarttime = readProcStarttime) {
|
|
1093
1103
|
const recorded = rec.starttime ?? null;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bind intents: the hook's confirmation that a session is binding itself.
|
|
3
|
+
*
|
|
4
|
+
* `hq core hq-session` cannot tell a session's own id from one a child
|
|
5
|
+
* process inherited from its parent, because both arrive as the same
|
|
6
|
+
* environment variable. The hook host can: a PreToolUse payload carries the
|
|
7
|
+
* real `session_id` and `tool_use_id`, set by the host and not by the shell.
|
|
8
|
+
* The native scope guard (crates/hq-hook/src/scope, the port of
|
|
9
|
+
* mandatory-scope-authorizer.sh) writes one intent file when it allows a
|
|
10
|
+
* Bash call that runs `hq-session.sh set company_slug`, `add company` or
|
|
11
|
+
* `remove company` for the payload's own session:
|
|
12
|
+
*
|
|
13
|
+
* <work mesh root>/bindings/intents/<session>.<tool_use_id>
|
|
14
|
+
* {"v":1,"session":"…","call":"…","action":"bind","company":"acme","at":"<ISO>"}
|
|
15
|
+
*
|
|
16
|
+
* The CLI consumes a matching intent once (atomic rename, then delete) and
|
|
17
|
+
* only then writes a receipt for an id the environment names. Nothing here
|
|
18
|
+
* writes intents: until the hook does, no intent exists and nothing changes.
|
|
19
|
+
*
|
|
20
|
+
* A plain shell export cannot produce an intent. A process running as the
|
|
21
|
+
* member can write the file, as it can write a receipt line; neither is
|
|
22
|
+
* tamper-evident. The guard here is against crediting the wrong session by
|
|
23
|
+
* accident, not against the member.
|
|
24
|
+
*/
|
|
25
|
+
import { type BindingAction, type BindingPaths } from "./binding-receipt.js";
|
|
26
|
+
export declare const INTENTS_DIRNAME = "intents";
|
|
27
|
+
/** An intent older than this does not confirm a change. */
|
|
28
|
+
export declare const BIND_INTENT_MAX_AGE_MS = 120000;
|
|
29
|
+
/** Intents and claimed leftovers older than this are removed. */
|
|
30
|
+
export declare const BIND_INTENT_PRUNE_AGE_MS: number;
|
|
31
|
+
export interface BindIntent {
|
|
32
|
+
v: 1;
|
|
33
|
+
session: string;
|
|
34
|
+
call: string;
|
|
35
|
+
action: Exclude<BindingAction, "source">;
|
|
36
|
+
/** The company the command names; empty for an unbind. */
|
|
37
|
+
company: string;
|
|
38
|
+
at: string;
|
|
39
|
+
}
|
|
40
|
+
export declare function bindIntentsDir(options?: BindingPaths): string;
|
|
41
|
+
/** The file name the hook writes for a session and call, or null for ids it may not use. */
|
|
42
|
+
export declare function bindIntentFileName(sessionId: string, call: string): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Consume one intent that confirms this change: same session, action and
|
|
45
|
+
* company, timed at most {@link BIND_INTENT_MAX_AGE_MS} before `at` and not
|
|
46
|
+
* after it (beyond a small skew), a plain file whose name matches its
|
|
47
|
+
* content, owned by this user and writable by no one else, in a folder that
|
|
48
|
+
* is the same. A candidate is picked by reading it, claimed by an atomic
|
|
49
|
+
* rename (so two commands cannot both use it), and the claimed file is read
|
|
50
|
+
* and checked again: what counts is what was claimed. The claimed file is
|
|
51
|
+
* deleted either way. Returns the intent, or null.
|
|
52
|
+
*/
|
|
53
|
+
export declare function consumeBindIntent(change: {
|
|
54
|
+
sessionId: string;
|
|
55
|
+
action: BindIntent["action"];
|
|
56
|
+
company: string;
|
|
57
|
+
at: Date;
|
|
58
|
+
}, options?: BindingPaths): BindIntent | null;
|
|
59
|
+
/** Remove intents and claimed leftovers older than {@link BIND_INTENT_PRUNE_AGE_MS}. Never throws. */
|
|
60
|
+
export declare function pruneBindIntents(options?: BindingPaths): void;
|
|
61
|
+
//# sourceMappingURL=binding-intent.d.ts.map
|