@indigoai-us/hq-cli 5.345.248 → 5.345.251
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 +143 -0
- package/contracts/host-canary-release.json +3 -3
- package/dist/command-catalog.generated.d.ts +288 -9
- package/dist/command-catalog.generated.js +355 -9
- package/dist/commands/bot.js +5 -1
- package/dist/commands/core-job-run-native.js +4 -0
- package/dist/commands/core-knowledge-prefs.d.ts +1 -1
- package/dist/commands/core-knowledge-prefs.js +1 -16
- package/dist/commands/core.js +0 -2
- package/dist/commands/daemon.js +21 -0
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +9 -4
- package/dist/commands/ontology-graph.d.ts +11 -3
- package/dist/commands/ontology-graph.js +138 -14
- package/dist/commands/sources.js +26 -8
- package/dist/commands/sync-core.js +6 -0
- package/dist/fast-scaffold.js +1 -3
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +281 -256
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +47 -0
- package/dist/lib/bot/fleet-cron.d.ts +2 -0
- package/dist/lib/bot/fleet-cron.js +5 -0
- package/dist/lib/daemon/installed-cli-restart.d.ts +57 -0
- package/dist/lib/daemon/installed-cli-restart.js +114 -0
- package/dist/lib/daemon/legacy-journal-gate.d.ts +32 -0
- package/dist/lib/daemon/legacy-journal-gate.js +102 -0
- package/dist/lib/daemon/machine-checks.d.ts +7 -0
- package/dist/lib/daemon/machine-checks.js +10 -0
- package/dist/lib/daemon/run.d.ts +3 -1
- package/dist/lib/daemon/run.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/coverage.d.ts +99 -19
- package/dist/lib/hook-engine/coverage.js +269 -35
- package/dist/lib/hook-engine/native-stop-compatibility.json +9 -4
- package/dist/lib/hook-engine/registration-identity.d.ts +5 -0
- package/dist/lib/hook-engine/registration-identity.js +1 -1
- package/dist/lib/hook-engine/resolve.d.ts +23 -0
- package/dist/lib/hook-engine/resolve.js +48 -1
- package/dist/lib/hook-engine/stable-heal.d.ts +87 -0
- package/dist/lib/hook-engine/stable-heal.js +214 -0
- package/dist/lib/hot-channels/graph-context.d.ts +26 -1
- package/dist/lib/hot-channels/graph-context.js +80 -10
- package/dist/lib/hot-channels/run.d.ts +1 -0
- package/dist/lib/hot-channels/signals-pass.js +9 -4
- package/dist/lib/ontology-graph/model/files.d.ts +4 -0
- package/dist/lib/ontology-graph/model/files.js +23 -0
- package/dist/lib/ontology-graph/model/index.d.ts +11 -1
- package/dist/lib/ontology-graph/model/index.js +42 -18
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +9 -1
- package/dist/lib/ontology-graph/model/pass-tasks.js +7 -4
- package/dist/lib/ontology-graph/model/pass.d.ts +5 -0
- package/dist/lib/ontology-graph/model/pass.js +8 -8
- package/dist/lib/ontology-graph/model/pending-items.d.ts +31 -0
- package/dist/lib/ontology-graph/model/pending-items.js +113 -0
- package/dist/lib/ontology-graph/model/step.d.ts +48 -1
- package/dist/lib/ontology-graph/model/step.js +205 -36
- package/dist/lib/ontology-graph/model/tasks.d.ts +17 -1
- package/dist/lib/ontology-graph/model/tasks.js +28 -8
- package/dist/lib/ontology-graph/org/derive.d.ts +2 -0
- package/dist/lib/ontology-graph/org/derive.js +9 -2
- package/dist/lib/ontology-graph/org/index.d.ts +35 -6
- package/dist/lib/ontology-graph/org/index.js +136 -19
- package/dist/lib/ontology-graph/org/text.d.ts +2 -0
- package/dist/lib/ontology-graph/org/text.js +6 -0
- package/dist/lib/ontology-graph/org/types.d.ts +5 -0
- package/dist/lib/ontology-graph/pages/render.d.ts +2 -0
- package/dist/lib/ontology-graph/pages/render.js +11 -4
- package/dist/lib/ontology-graph/read/brief.d.ts +13 -3
- package/dist/lib/ontology-graph/read/brief.js +312 -62
- package/dist/lib/ontology-graph/read/index.d.ts +1 -1
- package/dist/lib/ontology-graph/read/index.js +14 -3
- package/dist/lib/ontology-graph/read/names.d.ts +6 -1
- package/dist/lib/ontology-graph/read/names.js +8 -3
- package/dist/lib/ontology-graph/read/reader-setting.d.ts +2 -0
- package/dist/lib/ontology-graph/read/reader-setting.js +4 -1
- package/dist/lib/ontology-graph/remodel/index.d.ts +174 -0
- package/dist/lib/ontology-graph/remodel/index.js +450 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +47 -1
- package/dist/lib/ontology-graph/replay/engine.js +68 -2
- package/dist/lib/ontology-graph/replay/index.d.ts +2 -1
- package/dist/lib/ontology-graph/replay/index.js +114 -8
- package/dist/lib/ontology-graph/schema/authority.d.ts +43 -0
- package/dist/lib/ontology-graph/schema/authority.js +39 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +1 -1
- package/dist/lib/ontology-graph/schema/index.js +1 -1
- package/dist/lib/ontology-graph/setup/index.d.ts +88 -0
- package/dist/lib/ontology-graph/setup/index.js +489 -0
- package/dist/lib/ontology-graph/types.d.ts +28 -0
- package/dist/lib/ontology-graph/types.js +5 -0
- package/dist/lib/signals/failure-alert.js +4 -5
- package/dist/lib/signals/steps/adapters.js +3 -0
- package/dist/lib/sync-core/engine-holds.d.ts +1 -1
- package/dist/lib/sync-core/engine-holds.js +12 -2
- package/dist/lib/sync-core/hand-back.d.ts +2 -1
- package/dist/lib/sync-core/hand-back.js +16 -2
- package/dist/lib/sync-core/legacy-journal-export-child.d.ts +2 -0
- package/dist/lib/sync-core/legacy-journal-export-child.js +24 -0
- package/dist/lib/sync-core/legacy-journal-export.d.ts +39 -0
- package/dist/lib/sync-core/legacy-journal-export.js +241 -0
- package/dist/lib/sync-core/legacy-journal-reader.d.ts +15 -0
- package/dist/lib/sync-core/legacy-journal-reader.js +56 -0
- package/dist/lib/sync-core/reconcile.d.ts +3 -0
- package/dist/lib/sync-core/reconcile.js +43 -3
- package/dist/utils/cli-telemetry.d.ts +1 -0
- package/dist/utils/cli-telemetry.js +6 -3
- package/dist/utils/hook-engine-rollup.d.ts +96 -0
- package/dist/utils/hook-engine-rollup.js +725 -0
- package/dist/utils/sync-person.d.ts +15 -0
- package/dist/utils/sync-person.js +74 -0
- package/package.json +8 -8
- package/scripts/install-hook-engine.mjs +4 -0
- package/assets/scaffold/core/scripts/knowledge-prefs.sh +0 -55
|
@@ -26,6 +26,29 @@ export declare function assertPinnedHookEngineMatches(engine: EnginePackage): vo
|
|
|
26
26
|
export declare function findHookEngine(options?: EngineOptions): EnginePackage | null;
|
|
27
27
|
/** Never truncate or replace a running Windows executable. */
|
|
28
28
|
export declare function installHookEngine(options?: EngineOptions): string | null;
|
|
29
|
+
/** A `stable` link that no longer names the engine this CLI pins. */
|
|
30
|
+
export interface StaleStableEngine {
|
|
31
|
+
/** `~/.hq/bin/hq-hook/stable`. */
|
|
32
|
+
stable: string;
|
|
33
|
+
/** The engine this CLI pins. */
|
|
34
|
+
pinned: string;
|
|
35
|
+
/** The version folder the link resolves to now; null when it dangles (that folder is gone). */
|
|
36
|
+
resolved: string | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Read only. The `stable` link core.next registrations name, when it is a link
|
|
40
|
+
* that does not resolve to this CLI's pinned engine: an update pinned a new
|
|
41
|
+
* engine and nothing has re-run the gated reconcile (`hq reindex`) yet. Null
|
|
42
|
+
* when there is no link (core.next was never switched on), when `stable` is not
|
|
43
|
+
* a link (the doctor reports that), when this platform has no engine package,
|
|
44
|
+
* or when the link names the pinned engine.
|
|
45
|
+
*
|
|
46
|
+
* Only `hq reindex` moves the link: it re-checks the new engine against the
|
|
47
|
+
* host canary gate, its capabilities and the holds before a host keeps its
|
|
48
|
+
* new-core registrations. Moving it anywhere else would let those
|
|
49
|
+
* registrations run an engine nothing checked.
|
|
50
|
+
*/
|
|
51
|
+
export declare function staleStableEngine(options?: EngineOptions): StaleStableEngine | null;
|
|
29
52
|
/** master-hook.sh reads this one-line file with shell builtins to find the
|
|
30
53
|
* pinned engine without starting Node (US-021 bridge). It always names the
|
|
31
54
|
* engine of the CLI that wrote it, so a CLI update retargets it. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, renameSync, rmSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
@@ -115,6 +115,53 @@ export function installHookEngine(options = {}) {
|
|
|
115
115
|
writeHookEnginePointer(engine.pinned, options);
|
|
116
116
|
return engine.pinned;
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Read only. The `stable` link core.next registrations name, when it is a link
|
|
120
|
+
* that does not resolve to this CLI's pinned engine: an update pinned a new
|
|
121
|
+
* engine and nothing has re-run the gated reconcile (`hq reindex`) yet. Null
|
|
122
|
+
* when there is no link (core.next was never switched on), when `stable` is not
|
|
123
|
+
* a link (the doctor reports that), when this platform has no engine package,
|
|
124
|
+
* or when the link names the pinned engine.
|
|
125
|
+
*
|
|
126
|
+
* Only `hq reindex` moves the link: it re-checks the new engine against the
|
|
127
|
+
* host canary gate, its capabilities and the holds before a host keeps its
|
|
128
|
+
* new-core registrations. Moving it anywhere else would let those
|
|
129
|
+
* registrations run an engine nothing checked.
|
|
130
|
+
*/
|
|
131
|
+
export function staleStableEngine(options = {}) {
|
|
132
|
+
const stable = join(options.home ?? homedir(), '.hq', 'bin', 'hq-hook', 'stable');
|
|
133
|
+
try {
|
|
134
|
+
if (!lstatSync(stable).isSymbolicLink())
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error.code === 'ENOENT')
|
|
139
|
+
return null;
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
const engine = findHookEngine(options);
|
|
143
|
+
if (!engine)
|
|
144
|
+
return null;
|
|
145
|
+
let resolved;
|
|
146
|
+
try {
|
|
147
|
+
resolved = realpathSync(stable);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (error.code !== 'ENOENT')
|
|
151
|
+
throw error;
|
|
152
|
+
resolved = null;
|
|
153
|
+
}
|
|
154
|
+
// The link names the version folder (host-registration.ts linkStableEngine).
|
|
155
|
+
let folder = engine.pinnedDirectory;
|
|
156
|
+
try {
|
|
157
|
+
folder = realpathSync(engine.pinnedDirectory);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (error.code !== 'ENOENT')
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
return resolved === folder ? null : { stable, pinned: engine.pinned, resolved };
|
|
164
|
+
}
|
|
118
165
|
/** master-hook.sh reads this one-line file with shell builtins to find the
|
|
119
166
|
* pinned engine without starting Node (US-021 bridge). It always names the
|
|
120
167
|
* engine of the CLI that wrote it, so a CLI update retargets it. */
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* After an update, heal the `stable` link core.next registrations name by
|
|
3
|
+
* re-running the gated reconcile, never by moving the link directly.
|
|
4
|
+
*
|
|
5
|
+
* `npm install -g @indigoai-us/hq-cli` pins the new engine and rewrites the
|
|
6
|
+
* `current` pointer. `stable` keeps naming the previous engine until
|
|
7
|
+
* `hq reindex` runs; until then read-only resolution refuses it and the doctor
|
|
8
|
+
* fails. The first real `hq` command after an update starts `hq reindex
|
|
9
|
+
* --repo-root <root>` in the background for each HQ root this machine
|
|
10
|
+
* registers on the new core. That is the same reconcile a person runs by hand:
|
|
11
|
+
* the host canary gate, the engine's capabilities and the holds decide per host
|
|
12
|
+
* whether its registrations stay on the new core or go back to the old
|
|
13
|
+
* dispatcher, and it moves `stable`. Until it has run, `stable` keeps the
|
|
14
|
+
* previous engine, which passed its own checks.
|
|
15
|
+
*
|
|
16
|
+
* The postinstall moves nothing ([`staleStableEngine`] only reports).
|
|
17
|
+
*
|
|
18
|
+
* The roots come from the `--hq-root` arguments in the user-scope hook files,
|
|
19
|
+
* so this starts an unattended `hq reindex` in any folder named there. That is
|
|
20
|
+
* no new boundary: only someone who can already write those files (and so
|
|
21
|
+
* already choose what every hook runs) can plant a root.
|
|
22
|
+
*
|
|
23
|
+
* `fleet-local` registrations are not host-canary gated (by design; see
|
|
24
|
+
* host-registration.ts `hostCanaryGate`), so on a fleet box the heal moves them
|
|
25
|
+
* to the new engine at the first command after an update, as a manual
|
|
26
|
+
* reindex would.
|
|
27
|
+
*/
|
|
28
|
+
import { type SpawnOptions } from 'node:child_process';
|
|
29
|
+
import { type EngineOptions, type StaleStableEngine } from './resolve.js';
|
|
30
|
+
/** Set in the reindex the heal starts, so that process does not start another. */
|
|
31
|
+
export declare const STABLE_HEAL_ENV = "HQ_STABLE_HEAL";
|
|
32
|
+
/**
|
|
33
|
+
* Removed from the reindex's environment so the host canary gate applies in
|
|
34
|
+
* full: host-registration.ts `REINDEX_FROM_HOOK_ENV` (keeps every host on its
|
|
35
|
+
* current core) and canary-gate.ts `SKIP_CANARY_GATE_ENV` (bypasses the gate).
|
|
36
|
+
* Spelled out here so the start-up path does not load those modules;
|
|
37
|
+
* stable-heal.test.ts checks they match.
|
|
38
|
+
*/
|
|
39
|
+
export declare const GATE_WEAKENING_ENV: readonly ["HQ_REINDEX_FROM_HOOK", "HQ_SKIP_HOST_CANARY_GATE"];
|
|
40
|
+
/** A heal for the same pinned engine is not started again within this window. */
|
|
41
|
+
export declare const STABLE_HEAL_RETRY_MS: number;
|
|
42
|
+
export interface StableHealOptions {
|
|
43
|
+
home?: string;
|
|
44
|
+
env?: NodeJS.ProcessEnv;
|
|
45
|
+
cwd?: string;
|
|
46
|
+
platform?: NodeJS.Platform;
|
|
47
|
+
/** Engine lookup overrides (tests). */
|
|
48
|
+
lookup?: Pick<EngineOptions, 'arch' | 'version' | 'resolvePackage'>;
|
|
49
|
+
now?: () => number;
|
|
50
|
+
/** The Node executable and the CLI entry the reindex runs with. */
|
|
51
|
+
execPath?: string;
|
|
52
|
+
cliEntry?: string;
|
|
53
|
+
spawn?: (command: string, args: readonly string[], options: SpawnOptions) => {
|
|
54
|
+
unref(): void;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface StableHealResult {
|
|
58
|
+
stale: StaleStableEngine | null;
|
|
59
|
+
/** The HQ roots a reindex was started for; empty when none was started. */
|
|
60
|
+
roots: string[];
|
|
61
|
+
/** Why no reindex was started, when stale and none was. */
|
|
62
|
+
skipped?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The HQ roots to reconcile: each root a user-scope hook file (Claude Code,
|
|
66
|
+
* Codex, Grok Build) registers on the new core, and this machine's HQ root
|
|
67
|
+
* (`HQ_ROOT`, the root around the current folder, or the installer's record),
|
|
68
|
+
* whose project files and fleet profiles may name `stable` too. Only existing
|
|
69
|
+
* folders, each once.
|
|
70
|
+
*/
|
|
71
|
+
export declare function stableHealRoots(home: string, env: NodeJS.ProcessEnv, cwd: string, platform: NodeJS.Platform): string[];
|
|
72
|
+
/**
|
|
73
|
+
* Append a heal that threw to `~/.hq/logs/stable-heal.log`. The command the
|
|
74
|
+
* person ran goes on, and stderr stays clean for the hooks that call hq; the
|
|
75
|
+
* doctor still reports the stale link until a reindex moves it.
|
|
76
|
+
*/
|
|
77
|
+
export declare function recordStableHealFailure(error: unknown, home?: string, now?: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* Start the gated reconcile for every HQ root when `stable` no longer names
|
|
80
|
+
* this CLI's pinned engine. Once per pinned engine per hour, whatever the
|
|
81
|
+
* outcome, so a reindex that cannot finish (another holds the root's lock, the
|
|
82
|
+
* gate refuses) does not run on every command. The child runs plain
|
|
83
|
+
* `hq reindex --repo-root <root> --lock-timeout 0` one root after another,
|
|
84
|
+
* with the variables that would weaken the gate removed from its environment.
|
|
85
|
+
*/
|
|
86
|
+
export declare function healStableEngine(options?: StableHealOptions): StableHealResult;
|
|
87
|
+
//# sourceMappingURL=stable-heal.d.ts.map
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* After an update, heal the `stable` link core.next registrations name by
|
|
3
|
+
* re-running the gated reconcile, never by moving the link directly.
|
|
4
|
+
*
|
|
5
|
+
* `npm install -g @indigoai-us/hq-cli` pins the new engine and rewrites the
|
|
6
|
+
* `current` pointer. `stable` keeps naming the previous engine until
|
|
7
|
+
* `hq reindex` runs; until then read-only resolution refuses it and the doctor
|
|
8
|
+
* fails. The first real `hq` command after an update starts `hq reindex
|
|
9
|
+
* --repo-root <root>` in the background for each HQ root this machine
|
|
10
|
+
* registers on the new core. That is the same reconcile a person runs by hand:
|
|
11
|
+
* the host canary gate, the engine's capabilities and the holds decide per host
|
|
12
|
+
* whether its registrations stay on the new core or go back to the old
|
|
13
|
+
* dispatcher, and it moves `stable`. Until it has run, `stable` keeps the
|
|
14
|
+
* previous engine, which passed its own checks.
|
|
15
|
+
*
|
|
16
|
+
* The postinstall moves nothing ([`staleStableEngine`] only reports).
|
|
17
|
+
*
|
|
18
|
+
* The roots come from the `--hq-root` arguments in the user-scope hook files,
|
|
19
|
+
* so this starts an unattended `hq reindex` in any folder named there. That is
|
|
20
|
+
* no new boundary: only someone who can already write those files (and so
|
|
21
|
+
* already choose what every hook runs) can plant a root.
|
|
22
|
+
*
|
|
23
|
+
* `fleet-local` registrations are not host-canary gated (by design; see
|
|
24
|
+
* host-registration.ts `hostCanaryGate`), so on a fleet box the heal moves them
|
|
25
|
+
* to the new engine at the first command after an update, as a manual
|
|
26
|
+
* reindex would.
|
|
27
|
+
*/
|
|
28
|
+
import { spawn as nodeSpawn } from 'node:child_process';
|
|
29
|
+
import * as fs from 'node:fs';
|
|
30
|
+
import { homedir } from 'node:os';
|
|
31
|
+
import * as path from 'node:path';
|
|
32
|
+
import { CORE_NEXT_LINK, hqRootArgument, userHookSettingsFile } from './registration-identity.js';
|
|
33
|
+
import { staleStableEngine } from './resolve.js';
|
|
34
|
+
import { resolveDefaultHqRoot } from '../../utils/hq-root-resolver.js';
|
|
35
|
+
/** Set in the reindex the heal starts, so that process does not start another. */
|
|
36
|
+
export const STABLE_HEAL_ENV = 'HQ_STABLE_HEAL';
|
|
37
|
+
/**
|
|
38
|
+
* Removed from the reindex's environment so the host canary gate applies in
|
|
39
|
+
* full: host-registration.ts `REINDEX_FROM_HOOK_ENV` (keeps every host on its
|
|
40
|
+
* current core) and canary-gate.ts `SKIP_CANARY_GATE_ENV` (bypasses the gate).
|
|
41
|
+
* Spelled out here so the start-up path does not load those modules;
|
|
42
|
+
* stable-heal.test.ts checks they match.
|
|
43
|
+
*/
|
|
44
|
+
export const GATE_WEAKENING_ENV = ['HQ_REINDEX_FROM_HOOK', 'HQ_SKIP_HOST_CANARY_GATE'];
|
|
45
|
+
/** A heal for the same pinned engine is not started again within this window. */
|
|
46
|
+
export const STABLE_HEAL_RETRY_MS = 60 * 60 * 1000;
|
|
47
|
+
function statePath(home) {
|
|
48
|
+
return path.join(home, '.hq', 'state', 'stable-heal.json');
|
|
49
|
+
}
|
|
50
|
+
function readState(home) {
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(fs.readFileSync(statePath(home), 'utf8'));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error.code === 'ENOENT' || error instanceof SyntaxError)
|
|
56
|
+
return null;
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function writeState(home, pinned, at) {
|
|
61
|
+
const file = statePath(home);
|
|
62
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
63
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
64
|
+
fs.writeFileSync(temp, `${JSON.stringify({ pinned, at })}\n`);
|
|
65
|
+
fs.renameSync(temp, file);
|
|
66
|
+
}
|
|
67
|
+
/** Every `--hq-root` named by a new-core entry anywhere in `doc`. */
|
|
68
|
+
function coreNextRootsIn(doc, out) {
|
|
69
|
+
if (Array.isArray(doc)) {
|
|
70
|
+
for (const item of doc)
|
|
71
|
+
coreNextRootsIn(item, out);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!doc || typeof doc !== 'object')
|
|
75
|
+
return;
|
|
76
|
+
const entry = doc;
|
|
77
|
+
if (typeof entry.command === 'string' && CORE_NEXT_LINK.test(entry.command)) {
|
|
78
|
+
const root = hqRootArgument(entry);
|
|
79
|
+
if (root)
|
|
80
|
+
out.push(root);
|
|
81
|
+
}
|
|
82
|
+
for (const value of Object.values(entry))
|
|
83
|
+
coreNextRootsIn(value, out);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The HQ roots to reconcile: each root a user-scope hook file (Claude Code,
|
|
87
|
+
* Codex, Grok Build) registers on the new core, and this machine's HQ root
|
|
88
|
+
* (`HQ_ROOT`, the root around the current folder, or the installer's record),
|
|
89
|
+
* whose project files and fleet profiles may name `stable` too. Only existing
|
|
90
|
+
* folders, each once.
|
|
91
|
+
*/
|
|
92
|
+
export function stableHealRoots(home, env, cwd, platform) {
|
|
93
|
+
const named = [];
|
|
94
|
+
const files = [
|
|
95
|
+
userHookSettingsFile('claude', home, env),
|
|
96
|
+
userHookSettingsFile('codex', home, env),
|
|
97
|
+
path.join(home, '.grok', 'hooks', 'hq-hq-bridge.json'),
|
|
98
|
+
];
|
|
99
|
+
for (const file of files) {
|
|
100
|
+
let text;
|
|
101
|
+
try {
|
|
102
|
+
text = fs.readFileSync(file, 'utf8');
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error.code === 'ENOENT')
|
|
106
|
+
continue;
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
let doc;
|
|
110
|
+
try {
|
|
111
|
+
doc = JSON.parse(text);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// An unreadable hook file names no root; reindex reports it.
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
coreNextRootsIn(doc, named);
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
named.push(resolveDefaultHqRoot({ onMissing: 'throw', env, cwd, home, platform }));
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// No HQ root on this machine beyond the ones the hook files name.
|
|
124
|
+
}
|
|
125
|
+
const seen = new Set();
|
|
126
|
+
const roots = [];
|
|
127
|
+
for (const root of named) {
|
|
128
|
+
let real;
|
|
129
|
+
try {
|
|
130
|
+
real = fs.realpathSync(root);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (!fs.statSync(real).isDirectory() || seen.has(real))
|
|
136
|
+
continue;
|
|
137
|
+
seen.add(real);
|
|
138
|
+
roots.push(root);
|
|
139
|
+
}
|
|
140
|
+
return roots;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Append a heal that threw to `~/.hq/logs/stable-heal.log`. The command the
|
|
144
|
+
* person ran goes on, and stderr stays clean for the hooks that call hq; the
|
|
145
|
+
* doctor still reports the stale link until a reindex moves it.
|
|
146
|
+
*/
|
|
147
|
+
export function recordStableHealFailure(error, home = homedir(), now = Date.now()) {
|
|
148
|
+
try {
|
|
149
|
+
const logDir = path.join(home, '.hq', 'logs');
|
|
150
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
151
|
+
fs.appendFileSync(path.join(logDir, 'stable-heal.log'), `${new Date(now).toISOString()} heal failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Nowhere left to record it; hq doctor reports the stale link.
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Start the gated reconcile for every HQ root when `stable` no longer names
|
|
159
|
+
* this CLI's pinned engine. Once per pinned engine per hour, whatever the
|
|
160
|
+
* outcome, so a reindex that cannot finish (another holds the root's lock, the
|
|
161
|
+
* gate refuses) does not run on every command. The child runs plain
|
|
162
|
+
* `hq reindex --repo-root <root> --lock-timeout 0` one root after another,
|
|
163
|
+
* with the variables that would weaken the gate removed from its environment.
|
|
164
|
+
*/
|
|
165
|
+
export function healStableEngine(options = {}) {
|
|
166
|
+
const env = options.env ?? process.env;
|
|
167
|
+
const home = options.home ?? homedir();
|
|
168
|
+
const platform = options.platform ?? process.platform;
|
|
169
|
+
if (env[STABLE_HEAL_ENV] === '1')
|
|
170
|
+
return { stale: null, roots: [], skipped: 'already inside a heal' };
|
|
171
|
+
// Windows keeps shell registrations (coreNextOffReason); no new-core entry names stable there.
|
|
172
|
+
if (platform === 'win32')
|
|
173
|
+
return { stale: null, roots: [], skipped: 'Windows keeps shell registration' };
|
|
174
|
+
const stale = staleStableEngine({ ...options.lookup, home, platform });
|
|
175
|
+
if (!stale)
|
|
176
|
+
return { stale: null, roots: [] };
|
|
177
|
+
const now = (options.now ?? Date.now)();
|
|
178
|
+
const last = readState(home);
|
|
179
|
+
if (last && last.pinned === stale.pinned && typeof last.at === 'number' && now - last.at >= 0 && now - last.at < STABLE_HEAL_RETRY_MS) {
|
|
180
|
+
return { stale, roots: [], skipped: 'a heal for this engine started less than an hour ago' };
|
|
181
|
+
}
|
|
182
|
+
const roots = stableHealRoots(home, env, options.cwd ?? process.cwd(), platform);
|
|
183
|
+
if (!roots.length)
|
|
184
|
+
return { stale, roots: [], skipped: 'no HQ root to reconcile' };
|
|
185
|
+
const cliEntry = options.cliEntry ?? process.argv[1];
|
|
186
|
+
if (!cliEntry)
|
|
187
|
+
return { stale, roots: [], skipped: 'no CLI entry to run' };
|
|
188
|
+
writeState(home, stale.pinned, now);
|
|
189
|
+
const childEnv = { ...env, [STABLE_HEAL_ENV]: '1', HQ_INSTALL_FOLLOWUP: '1' };
|
|
190
|
+
for (const name of GATE_WEAKENING_ENV)
|
|
191
|
+
delete childEnv[name];
|
|
192
|
+
const logDir = path.join(home, '.hq', 'logs');
|
|
193
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
194
|
+
const log = fs.openSync(path.join(logDir, 'stable-heal.log'), 'a');
|
|
195
|
+
try {
|
|
196
|
+
fs.writeSync(log, `${new Date(now).toISOString()} stable ${stale.resolved ?? '(dangling)'} -> pinned ${stale.pinned}; hq reindex for ${roots.join(', ')}\n`);
|
|
197
|
+
const script = [
|
|
198
|
+
"const { spawnSync } = require('node:child_process');",
|
|
199
|
+
'const [cli, ...roots] = process.argv.slice(1);',
|
|
200
|
+
"for (const root of roots) spawnSync(process.execPath, [cli, 'reindex', '--repo-root', root, '--lock-timeout', '0'], { stdio: 'inherit' });",
|
|
201
|
+
].join('\n');
|
|
202
|
+
const child = (options.spawn ?? nodeSpawn)(options.execPath ?? process.execPath, ['-e', script, cliEntry, ...roots], {
|
|
203
|
+
detached: true,
|
|
204
|
+
stdio: ['ignore', log, log],
|
|
205
|
+
env: childEnv,
|
|
206
|
+
});
|
|
207
|
+
child.unref();
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
fs.closeSync(log);
|
|
211
|
+
}
|
|
212
|
+
return { stale, roots };
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=stable-heal.js.map
|
|
@@ -22,6 +22,12 @@ export interface PackEntity {
|
|
|
22
22
|
phrases: string[];
|
|
23
23
|
/** One-word names as the graph writes them, matched with exact case. */
|
|
24
24
|
words: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Identity keys the document writes that belong to this entity alone: a
|
|
27
|
+
* Slack id as written, an email in lower case. A key two visible entities
|
|
28
|
+
* share is never here.
|
|
29
|
+
*/
|
|
30
|
+
keys: string[];
|
|
25
31
|
/** The line in the prompt block. */
|
|
26
32
|
line: string;
|
|
27
33
|
}
|
|
@@ -86,6 +92,13 @@ export interface SignalText {
|
|
|
86
92
|
body?: string;
|
|
87
93
|
/** `entity_refs` from the model's reply, when the reply format carries them. Untrusted. */
|
|
88
94
|
modelRefs?: unknown;
|
|
95
|
+
/** The signal's type. Only `participant_contribution` reads `speakerKeys`. */
|
|
96
|
+
type?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Identity keys of the people who wrote the source document, from its own
|
|
99
|
+
* frontmatter (the Slack ids of a thread's participants). Never from the model.
|
|
100
|
+
*/
|
|
101
|
+
speakerKeys?: readonly string[];
|
|
89
102
|
}
|
|
90
103
|
/**
|
|
91
104
|
* The `entity_refs` for one produced signal: ids from the pack and nothing
|
|
@@ -93,9 +106,21 @@ export interface SignalText {
|
|
|
93
106
|
*
|
|
94
107
|
* With `modelRefs`, the model's choice is kept after dropping every id that is
|
|
95
108
|
* not in the pack. Without, an entity is chosen when the signal's own title or
|
|
96
|
-
* body names it, by the same rules that put it in the pack
|
|
109
|
+
* body names it, by the same rules that put it in the pack: one of its names,
|
|
110
|
+
* or an identity key the document wrote for it (whole token; a Slack id with
|
|
111
|
+
* exact case). A `participant_contribution` from a document with one writer
|
|
112
|
+
* also links to that writer, who is in the pack by their key, because the
|
|
113
|
+
* model often writes such a signal without naming them in full.
|
|
97
114
|
*/
|
|
98
115
|
export declare function entityRefsFromPack(pack: ContextPack | null | undefined, signal: SignalText, cap?: number): string[];
|
|
116
|
+
/**
|
|
117
|
+
* Signal text with each raw Slack id replaced by the name of the pack entity
|
|
118
|
+
* that holds it (`<@U…>` and `@U…` too). The name is the entity's name in the
|
|
119
|
+
* graph, found by a key that belongs to that entity alone; nothing here comes
|
|
120
|
+
* from the model. An id the pack does not hold, and every email, is left as
|
|
121
|
+
* written. The id stays on the signal as an `entity_refs` item.
|
|
122
|
+
*/
|
|
123
|
+
export declare function renderPackNames(pack: ContextPack | null | undefined, text: string): string;
|
|
99
124
|
/**
|
|
100
125
|
* Host-side write: sets `entity_refs` on a signal's frontmatter from the pack.
|
|
101
126
|
* Leaves the key absent when no entity is named. Returns the refs written.
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
* 2. After: `entityRefsFromPack()` chooses the `entity_refs` of each produced
|
|
13
13
|
* signal from the pack and nothing else, and `writeEntityRefs()` puts them
|
|
14
14
|
* in the signal's frontmatter. An id the model returns that is not in the
|
|
15
|
-
* pack is dropped.
|
|
15
|
+
* pack is dropped. A signal links to a pack entity when its own text
|
|
16
|
+
* writes one of the entity's names, or the identity key (Slack id, email)
|
|
17
|
+
* by which the document named that entity. `renderPackNames()` then writes
|
|
18
|
+
* the entity's name where the signal text has a raw Slack id.
|
|
16
19
|
*
|
|
17
20
|
* It replaces the name matcher of PR 3473 (`ENTITY_MATCH_RULE`,
|
|
18
21
|
* `matchEntityRefs`). Matching rules here:
|
|
@@ -35,7 +38,7 @@
|
|
|
35
38
|
* for the company (`openSignalsGraphContext` returns null otherwise).
|
|
36
39
|
*/
|
|
37
40
|
import * as path from "node:path";
|
|
38
|
-
import { originTier } from "../ontology-graph/schema/index.js";
|
|
41
|
+
import { isUnverifiedGuess, originTier } from "../ontology-graph/schema/index.js";
|
|
39
42
|
import { GraphCompanyMismatchError, GraphCompanyStampError, GraphCompanyUnclaimedError, assertGraphWritableFor, openGraphStore, resolveGraphRoot } from "../ontology-graph/store/index.js";
|
|
40
43
|
import { COMPANY_AUDIENCE, } from "../ontology-graph/types.js";
|
|
41
44
|
import { graphExists, loadReadIndex, normalizeName, rowVisible, visible, } from "../ontology-graph/read/graph-index.js";
|
|
@@ -133,6 +136,22 @@ function typeRank(type) {
|
|
|
133
136
|
const at = TYPE_ORDER.indexOf(type);
|
|
134
137
|
return at === -1 ? TYPE_ORDER.length : at;
|
|
135
138
|
}
|
|
139
|
+
const EMAIL_KEY = /^[^@\s]+@[^@\s]+$/;
|
|
140
|
+
/** An identity key as the pack stores it: an email in lower case, a Slack id as written. */
|
|
141
|
+
function storedKey(written) {
|
|
142
|
+
return EMAIL_KEY.test(written) ? written.toLowerCase() : written;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Matches an identity key as a whole token. A Slack id is matched with exact
|
|
146
|
+
* case and an email without regard to case; neither matches inside a longer
|
|
147
|
+
* word, id or address.
|
|
148
|
+
*/
|
|
149
|
+
function keyPattern(key, flags = "") {
|
|
150
|
+
const escaped = escapeRegExp(key);
|
|
151
|
+
return EMAIL_KEY.test(key)
|
|
152
|
+
? new RegExp(`(?<![\\p{L}\\p{N}._%+-])${escaped}(?![\\p{L}\\p{N}_-]|\\.[\\p{L}\\p{N}])`, `iu${flags}`)
|
|
153
|
+
: new RegExp(`(?<![\\p{L}\\p{N}_])${escaped}(?![\\p{L}\\p{N}_])`, `u${flags}`);
|
|
154
|
+
}
|
|
136
155
|
/** The words of a text, as written and normalized, in order. */
|
|
137
156
|
function words(text) {
|
|
138
157
|
const raw = [];
|
|
@@ -157,15 +176,19 @@ function findEntities(session, text, filter) {
|
|
|
157
176
|
const found = new Map();
|
|
158
177
|
let ambiguous = 0;
|
|
159
178
|
let refused = 0;
|
|
160
|
-
const note = (entity, reason) => {
|
|
161
|
-
|
|
162
|
-
if (!held)
|
|
163
|
-
|
|
179
|
+
const note = (entity, reason, key) => {
|
|
180
|
+
let held = found.get(entity.id);
|
|
181
|
+
if (!held) {
|
|
182
|
+
held = { entity, reason, count: 1, keys: new Set() };
|
|
183
|
+
found.set(entity.id, held);
|
|
184
|
+
}
|
|
164
185
|
else {
|
|
165
186
|
held.count += 1;
|
|
166
187
|
if (REASON_RANK[reason] < REASON_RANK[held.reason])
|
|
167
188
|
held.reason = reason;
|
|
168
189
|
}
|
|
190
|
+
if (key !== undefined)
|
|
191
|
+
held.keys.add(storedKey(key));
|
|
169
192
|
};
|
|
170
193
|
const candidates = (list) => {
|
|
171
194
|
const out = [];
|
|
@@ -181,7 +204,7 @@ function findEntities(session, text, filter) {
|
|
|
181
204
|
for (const match of scanned.matchAll(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}|\b[UW][A-Z0-9]{8,11}\b/g)) {
|
|
182
205
|
const hits = candidates(index.byKey.get(match[0].toLowerCase()));
|
|
183
206
|
if (hits.length === 1 && hits[0])
|
|
184
|
-
note(hits[0], "identity_key");
|
|
207
|
+
note(hits[0], "identity_key", match[0]);
|
|
185
208
|
else if (hits.length > 1)
|
|
186
209
|
ambiguous += 1;
|
|
187
210
|
}
|
|
@@ -236,6 +259,9 @@ function mainEdges(session, ref, filter, cap) {
|
|
|
236
259
|
return rows
|
|
237
260
|
.filter((stored) => stored.row.kind === "E" && !stored.row.valid.to && rowVisible(stored.audience, filter))
|
|
238
261
|
.filter((stored) => session.schema.link_types[stored.row.verb]?.class === "state")
|
|
262
|
+
// An employer a model guessed at low confidence is not sent to the next model as a relationship:
|
|
263
|
+
// a pack line carries no origin or confidence, so it would read as established.
|
|
264
|
+
.filter((stored) => !isUnverifiedGuess(stored.row, { edges: true }))
|
|
239
265
|
.filter((stored) => {
|
|
240
266
|
const target = session.index.entities[session.index.byId.get(stored.row.target) ?? -1];
|
|
241
267
|
return target !== undefined && visible(target, filter);
|
|
@@ -314,6 +340,7 @@ export function buildContextPack(session, input) {
|
|
|
314
340
|
reason: entry.reason,
|
|
315
341
|
count: entry.count,
|
|
316
342
|
...packForms(entity, session, allowed),
|
|
343
|
+
keys: [...entry.keys],
|
|
317
344
|
line,
|
|
318
345
|
});
|
|
319
346
|
}
|
|
@@ -336,13 +363,30 @@ export function appendPackToDocument(text, pack) {
|
|
|
336
363
|
function escapeRegExp(text) {
|
|
337
364
|
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
338
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* The one pack person who wrote the document, when the document has exactly
|
|
368
|
+
* one writer and their key belongs to exactly one pack entity. A document with
|
|
369
|
+
* two or more writers has no sole speaker, even when only one of them resolves.
|
|
370
|
+
*/
|
|
371
|
+
function soleSpeaker(pack, speakerKeys) {
|
|
372
|
+
const keys = [...new Set((speakerKeys ?? []).map((key) => storedKey(key.trim())).filter((key) => key.length > 0))];
|
|
373
|
+
const only = keys.length === 1 ? keys[0] : undefined;
|
|
374
|
+
if (only === undefined)
|
|
375
|
+
return undefined;
|
|
376
|
+
const speakers = pack.entities.filter((entity) => entity.type === "person" && entity.keys.includes(only));
|
|
377
|
+
return speakers.length === 1 ? speakers[0] : undefined;
|
|
378
|
+
}
|
|
339
379
|
/**
|
|
340
380
|
* The `entity_refs` for one produced signal: ids from the pack and nothing
|
|
341
381
|
* else, in pack order, at most `cap`.
|
|
342
382
|
*
|
|
343
383
|
* With `modelRefs`, the model's choice is kept after dropping every id that is
|
|
344
384
|
* not in the pack. Without, an entity is chosen when the signal's own title or
|
|
345
|
-
* body names it, by the same rules that put it in the pack
|
|
385
|
+
* body names it, by the same rules that put it in the pack: one of its names,
|
|
386
|
+
* or an identity key the document wrote for it (whole token; a Slack id with
|
|
387
|
+
* exact case). A `participant_contribution` from a document with one writer
|
|
388
|
+
* also links to that writer, who is in the pack by their key, because the
|
|
389
|
+
* model often writes such a signal without naming them in full.
|
|
346
390
|
*/
|
|
347
391
|
export function entityRefsFromPack(pack, signal, cap = MAX_SIGNAL_ENTITY_REFS) {
|
|
348
392
|
if (!pack || pack.entities.length === 0)
|
|
@@ -353,17 +397,43 @@ export function entityRefsFromPack(pack, signal, cap = MAX_SIGNAL_ENTITY_REFS) {
|
|
|
353
397
|
}
|
|
354
398
|
const own = [signal.title, signal.body ?? ""].filter((part) => part.length > 0).join("\n");
|
|
355
399
|
const normalized = ` ${normalizeName(own)} `;
|
|
400
|
+
const speaker = signal.type === "participant_contribution" ? soleSpeaker(pack, signal.speakerKeys) : undefined;
|
|
356
401
|
const refs = [];
|
|
357
402
|
for (const entity of pack.entities) {
|
|
358
403
|
if (refs.length >= cap)
|
|
359
404
|
break;
|
|
360
|
-
const named = entity
|
|
361
|
-
entity.
|
|
405
|
+
const named = entity === speaker ||
|
|
406
|
+
entity.phrases.some((phrase) => normalized.includes(` ${phrase} `)) ||
|
|
407
|
+
entity.words.some((word) => new RegExp(`(^|[^\\p{L}\\p{N}])${escapeRegExp(word)}($|[^\\p{L}\\p{N}])`, "u").test(own)) ||
|
|
408
|
+
entity.keys.some((key) => keyPattern(key).test(own));
|
|
362
409
|
if (named)
|
|
363
410
|
refs.push(entity.id);
|
|
364
411
|
}
|
|
365
412
|
return refs;
|
|
366
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* Signal text with each raw Slack id replaced by the name of the pack entity
|
|
416
|
+
* that holds it (`<@U…>` and `@U…` too). The name is the entity's name in the
|
|
417
|
+
* graph, found by a key that belongs to that entity alone; nothing here comes
|
|
418
|
+
* from the model. An id the pack does not hold, and every email, is left as
|
|
419
|
+
* written. The id stays on the signal as an `entity_refs` item.
|
|
420
|
+
*/
|
|
421
|
+
export function renderPackNames(pack, text) {
|
|
422
|
+
if (!pack || text.length === 0)
|
|
423
|
+
return text;
|
|
424
|
+
let out = text;
|
|
425
|
+
for (const entity of pack.entities) {
|
|
426
|
+
if (entity.name.length === 0)
|
|
427
|
+
continue;
|
|
428
|
+
for (const key of entity.keys) {
|
|
429
|
+
if (EMAIL_KEY.test(key))
|
|
430
|
+
continue;
|
|
431
|
+
const bare = keyPattern(key, "g").source;
|
|
432
|
+
out = out.replace(new RegExp(`<@${escapeRegExp(key)}(?:\\|[^>]*)?>|@?${bare}`, "gu"), () => entity.name);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return out;
|
|
436
|
+
}
|
|
367
437
|
/**
|
|
368
438
|
* Host-side write: sets `entity_refs` on a signal's frontmatter from the pack.
|
|
369
439
|
* Leaves the key absent when no entity is named. Returns the refs written.
|
|
@@ -161,6 +161,7 @@ export interface OnDemandSyncReport {
|
|
|
161
161
|
runId: string | null;
|
|
162
162
|
/** True when the HQ session was gone before anything ran; nothing was written. */
|
|
163
163
|
signInRequired: boolean;
|
|
164
|
+
noPersonIdentity?: boolean;
|
|
164
165
|
/** True when another sync for this person and company was running; nothing ran. */
|
|
165
166
|
skipped?: boolean;
|
|
166
167
|
/** The signed-in person's cursor directory key (`_cursors/@{personKey}`); unset when nobody is signed in. */
|
|
@@ -101,7 +101,7 @@ import * as path from "node:path";
|
|
|
101
101
|
import { fileURLToPath } from "node:url";
|
|
102
102
|
import * as yaml from "js-yaml";
|
|
103
103
|
import { audienceKey, COMPANY_AUDIENCE_KEY } from "./audience.js";
|
|
104
|
-
import { appendPackToDocument, openSignalsGraphContext, writeEntityRefs, } from "./graph-context.js";
|
|
104
|
+
import { appendPackToDocument, openSignalsGraphContext, renderPackNames, writeEntityRefs, } from "./graph-context.js";
|
|
105
105
|
import { assertVaultPath } from "../signals/write-guard.js";
|
|
106
106
|
import { assertPayloadRef, assertSafeSegment, writeFileAtomic } from "./landing.js";
|
|
107
107
|
import { fleetFailureClass, fleetFailureMessage, runFleetComplete } from "./fleet-complete.js";
|
|
@@ -1411,7 +1411,11 @@ export function createClaudeSignalsPass(options) {
|
|
|
1411
1411
|
// Only a meeting transcript payload has timed segments to cite.
|
|
1412
1412
|
const segments = input.payloadRef?.startsWith("sources/meetings/") && input.payloadText !== undefined
|
|
1413
1413
|
? transcriptSegments(input.payloadText) : new Map();
|
|
1414
|
+
const pack = packs.get(item.file);
|
|
1415
|
+
// The thread's writers, from the landed document's own frontmatter.
|
|
1416
|
+
const speakerKeys = typeof pointer.slack_participants === "string" ? pointer.slack_participants.split(",") : [];
|
|
1414
1417
|
for (const signal of signals) {
|
|
1418
|
+
// The id is made from the model's own title, so a later change of a name in the graph keeps it.
|
|
1415
1419
|
const id = signalId(sourceRef, signal.type, signal.title);
|
|
1416
1420
|
const key = `${signalTypeDir(item.audienceKey, signal.type)}/${id}.md`;
|
|
1417
1421
|
rows.push({ signal_id: id, type: signal.type, source_ref: sourceRef, key, written_at: at });
|
|
@@ -1422,7 +1426,8 @@ export function createClaudeSignalsPass(options) {
|
|
|
1422
1426
|
signal_id: id,
|
|
1423
1427
|
type: signal.type,
|
|
1424
1428
|
source_ref: sourceRef,
|
|
1425
|
-
|
|
1429
|
+
// A raw Slack id the pack resolves is written as the person's name.
|
|
1430
|
+
canonical_content: renderPackNames(pack, signal.title),
|
|
1426
1431
|
audience_key: item.audienceKey,
|
|
1427
1432
|
origin: SIGNAL_ORIGIN,
|
|
1428
1433
|
written_at: at,
|
|
@@ -1438,12 +1443,12 @@ export function createClaudeSignalsPass(options) {
|
|
|
1438
1443
|
if (citation !== undefined)
|
|
1439
1444
|
frontmatter.citations = [citation];
|
|
1440
1445
|
// Host-side: ids come from the document's pack and nowhere else.
|
|
1441
|
-
writeEntityRefs(frontmatter,
|
|
1446
|
+
writeEntityRefs(frontmatter, pack, { title: signal.title, body: signal.body, type: signal.type, speakerKeys });
|
|
1442
1447
|
if (input.payloadRef !== undefined)
|
|
1443
1448
|
frontmatter.payload_ref = input.payloadRef;
|
|
1444
1449
|
if (input.fallback !== undefined)
|
|
1445
1450
|
frontmatter.payload_fallback = input.fallback;
|
|
1446
|
-
const text = `---\n${yaml.dump(frontmatter, { lineWidth: -1, noRefs: true }).trimEnd()}\n---\n## ${heading(signal.type)}\n\n${signal.body || signal.title}\n`;
|
|
1451
|
+
const text = `---\n${yaml.dump(frontmatter, { lineWidth: -1, noRefs: true }).trimEnd()}\n---\n## ${heading(signal.type)}\n\n${renderPackNames(pack, signal.body || signal.title)}\n`;
|
|
1447
1452
|
await beforeWrite();
|
|
1448
1453
|
// Cloud-extracted signals arriving by upload/garden are out of scope.
|
|
1449
1454
|
prepareSignalPublication(options.hqRoot, options.company, {
|