@indigoai-us/hq-cli 5.345.226 → 5.345.228
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 +142 -0
- package/dist/command-catalog.generated.d.ts +137 -0
- package/dist/command-catalog.generated.js +164 -0
- package/dist/commands/auth.d.ts +2 -2
- package/dist/commands/auth.js +3 -3
- package/dist/commands/core-delegate-w1b.js +92 -69
- package/dist/commands/core-delegate.d.ts +19 -1
- package/dist/commands/core-delegate.js +411 -6
- package/dist/commands/core-dm-bind-native.js +2 -1
- package/dist/commands/core-handoff.d.ts +5 -0
- package/dist/commands/core-handoff.js +1008 -14
- package/dist/commands/core-pin-native.d.ts +1 -0
- package/dist/commands/core-pin-native.js +3 -15
- package/dist/commands/core-register-project-native.d.ts +6 -0
- package/dist/commands/core-register-project-native.js +182 -52
- package/dist/commands/core-work-mesh-bind-trusted-native.js +4 -9
- package/dist/commands/daemon.js +2 -2
- package/dist/commands/index-cmd.d.ts +3 -1
- package/dist/commands/index-cmd.js +12 -0
- package/dist/commands/lanes-checks.js +1 -1
- package/dist/commands/lanes-session-start.d.ts +1 -2
- package/dist/commands/lanes-session-start.js +9 -145
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +94 -27
- package/dist/commands/link.d.ts +8 -3
- package/dist/commands/link.js +14 -17
- package/dist/commands/mcp-registration.d.ts +65 -7
- package/dist/commands/mcp-registration.js +289 -51
- package/dist/commands/mesh.d.ts +12 -0
- package/dist/commands/mesh.js +92 -10
- package/dist/commands/reindex.js +6 -0
- package/dist/commands/repo.d.ts +13 -0
- package/dist/commands/repo.js +39 -1
- package/dist/commands/sync-mode.d.ts +3 -1
- package/dist/commands/sync-mode.js +11 -1
- package/dist/lazy-commands.js +3 -4
- package/dist/lib/checkpoint-ontology/entity-file.js +4 -4
- package/dist/lib/checkpoint-ontology/merge-copies.js +7 -11
- package/dist/lib/checkpoint-ontology/plan.js +2 -1
- package/dist/lib/core-utils/archive-old-threads.js +5 -2
- package/dist/lib/core-utils/session-company.d.ts +13 -1
- package/dist/lib/core-utils/session-company.js +75 -4
- package/dist/lib/core-utils/worktree-resume.d.ts +6 -0
- package/dist/lib/core-utils/worktree-resume.js +8 -4
- package/dist/lib/daemon/background-qos.d.ts +7 -0
- package/dist/lib/daemon/background-qos.js +13 -0
- package/dist/lib/daemon/catalog.d.ts +9 -0
- package/dist/lib/daemon/catalog.js +8 -1
- package/dist/lib/daemon/hook-requests-acl-suggest.d.ts +18 -0
- package/dist/lib/daemon/hook-requests-acl-suggest.js +245 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +32 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.js +214 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.d.ts +44 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.js +292 -0
- package/dist/lib/daemon/hook-requests-mesh.d.ts +54 -0
- package/dist/lib/daemon/hook-requests-mesh.js +559 -0
- package/dist/lib/daemon/hook-requests.d.ts +349 -8
- package/dist/lib/daemon/hook-requests.js +1312 -46
- package/dist/lib/daemon/machine-checks.d.ts +12 -2
- package/dist/lib/daemon/machine-checks.js +27 -10
- package/dist/lib/daemon/merge-sections.d.ts +24 -2
- package/dist/lib/daemon/merge-sections.js +58 -16
- package/dist/lib/daemon/ops/policy.js +4 -2
- package/dist/lib/daemon/resolver.js +9 -2
- package/dist/lib/daemon/run.d.ts +11 -7
- package/dist/lib/daemon/run.js +168 -24
- package/dist/lib/daemon/search-index-worker-v1.d.ts +2 -0
- package/dist/lib/daemon/search-index-worker-v1.js +25 -0
- package/dist/lib/daemon/session-registry.d.ts +0 -1
- package/dist/lib/daemon/session-registry.js +0 -3
- package/dist/lib/daemon/supervisor.d.ts +3 -1
- package/dist/lib/daemon/supervisor.js +1 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +59 -4
- package/dist/lib/daemon/tcc-eperm.js +110 -8
- package/dist/lib/doctor/fix/process-identity.d.ts +20 -2
- package/dist/lib/doctor/fix/process-identity.js +48 -5
- package/dist/lib/hook-engine/canary-gate.js +1 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
- package/dist/lib/hot-channels/adapters/attio.js +2 -1
- package/dist/lib/hot-channels/adapters/meetings.js +2 -1
- package/dist/lib/lanes/company-outposts.d.ts +37 -0
- package/dist/lib/lanes/company-outposts.js +164 -0
- package/dist/lib/lanes/liveness.d.ts +6 -0
- package/dist/lib/lanes/liveness.js +49 -8
- package/dist/lib/lanes/orphan-report.d.ts +15 -0
- package/dist/lib/lanes/orphan-report.js +223 -0
- package/dist/lib/lanes/orphan-sweep.d.ts +26 -0
- package/dist/lib/lanes/orphan-sweep.js +152 -0
- package/dist/lib/lanes/reaper.d.ts +2 -0
- package/dist/lib/lanes/reaper.js +11 -8
- package/dist/lib/lanes/reconcile.d.ts +8 -7
- package/dist/lib/lanes/reconcile.js +39 -0
- package/dist/lib/mesh/live/backfill-held.d.ts +13 -0
- package/dist/lib/mesh/live/backfill-held.js +23 -0
- package/dist/lib/mesh/live/daemon/mode.d.ts +8 -4
- package/dist/lib/mesh/live/daemon/mode.js +8 -4
- package/dist/lib/mesh/live/daemon/run.d.ts +14 -3
- package/dist/lib/mesh/live/daemon/run.js +116 -7
- package/dist/lib/mesh/live/direct-drain.d.ts +123 -0
- package/dist/lib/mesh/live/direct-drain.js +315 -0
- package/dist/lib/mesh/live/emit-replay.d.ts +10 -0
- package/dist/lib/mesh/live/emit-replay.js +10 -0
- package/dist/lib/mesh/live/flush.d.ts +15 -0
- package/dist/lib/mesh/live/flush.js +27 -0
- package/dist/lib/mesh/live/liveness-carry.d.ts +45 -0
- package/dist/lib/mesh/live/liveness-carry.js +141 -0
- package/dist/lib/mesh/live/spool.d.ts +19 -0
- package/dist/lib/mesh/live/spool.js +80 -0
- package/dist/lib/safe-store.d.ts +2 -0
- package/dist/lib/safe-store.js +8 -6
- package/dist/lib/search-index/index.d.ts +9 -3
- package/dist/lib/search-index/index.js +35 -10
- package/dist/lib/search-index/worker-process.d.ts +9 -0
- package/dist/lib/search-index/worker-process.js +171 -0
- package/dist/lib/session-company-lock.d.ts +3 -1
- package/dist/lib/session-company-lock.js +3 -2
- package/dist/utils/delegate-command-supervisor.d.ts +3 -0
- package/dist/utils/delegate-command-supervisor.js +44 -0
- package/dist/utils/delegate-lock.d.ts +12 -0
- package/dist/utils/delegate-lock.js +88 -0
- package/dist/utils/frontmatter.d.ts +27 -0
- package/dist/utils/frontmatter.js +33 -0
- package/dist/utils/hook-trust.d.ts +1 -0
- package/dist/utils/hook-trust.js +18 -2
- package/dist/utils/host-registration.d.ts +13 -1
- package/dist/utils/host-registration.js +98 -5
- package/dist/utils/package-use-lease.d.ts +1 -1
- package/dist/utils/package-use-lease.js +15 -7
- package/docs/anywhere-runtime.md +17 -0
- package/package.json +8 -7
- package/scripts/check-function-manifest.mjs +17 -3
package/dist/commands/repo.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ import { Command } from "commander";
|
|
|
8
8
|
* ordering, and quoting in the rest of the file are left as they were. The
|
|
9
9
|
* result is parsed back before writing; if the entry does not show up where
|
|
10
10
|
* expected, nothing is written.
|
|
11
|
+
*
|
|
12
|
+
* Folder-to-company has one store (US-030 c3): the registry that `hq link`
|
|
13
|
+
* writes and `hq resolve-company`, hqd and the MCP tool read. After the
|
|
14
|
+
* manifest write, `hq repo add` seeds that registry from the manifest the way
|
|
15
|
+
* `hq install --global` does, so the new checkout resolves at once. Seeding
|
|
16
|
+
* never replaces an `hq link` entry.
|
|
11
17
|
*/
|
|
12
18
|
export declare const MANIFEST_RELATIVE_PATH: string;
|
|
13
19
|
export declare function manifestRepos(text: string, company: string): string[] | null;
|
|
@@ -28,12 +34,19 @@ export interface RepoAddOptions {
|
|
|
28
34
|
visibility: "private" | "public";
|
|
29
35
|
name?: string;
|
|
30
36
|
dryRun?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Registry file to seed after the manifest write (the `hq link` store).
|
|
39
|
+
* Unset seeds nothing; the command passes the user's registry.
|
|
40
|
+
*/
|
|
41
|
+
registryFile?: string;
|
|
31
42
|
}
|
|
32
43
|
export interface RepoAddResult {
|
|
33
44
|
entry: string;
|
|
34
45
|
linked: boolean;
|
|
35
46
|
manifestChanged: boolean;
|
|
36
47
|
warnings: string[];
|
|
48
|
+
/** True when the registry was seeded from the manifest after the write. */
|
|
49
|
+
registrySeeded?: boolean;
|
|
37
50
|
}
|
|
38
51
|
/** Register a checkout. Throws a user-facing Error on any refusal. */
|
|
39
52
|
export declare function runRepoAdd(opts: RepoAddOptions): RepoAddResult;
|
package/dist/commands/repo.js
CHANGED
|
@@ -3,6 +3,8 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import * as yaml from "js-yaml";
|
|
5
5
|
import { findHqRoot } from "../utils/manifest.js";
|
|
6
|
+
import { readRegistry, registryFile, resolveCompanyForDir } from "../lib/registry/registry.js";
|
|
7
|
+
import { seedRegistryFromHqRoot } from "./link.js";
|
|
6
8
|
/**
|
|
7
9
|
* `hq repo add <path> --company <slug>` — register a git checkout with HQ:
|
|
8
10
|
* link it into `repos/<private|public>/<name>` and list it under
|
|
@@ -12,6 +14,12 @@ import { findHqRoot } from "../utils/manifest.js";
|
|
|
12
14
|
* ordering, and quoting in the rest of the file are left as they were. The
|
|
13
15
|
* result is parsed back before writing; if the entry does not show up where
|
|
14
16
|
* expected, nothing is written.
|
|
17
|
+
*
|
|
18
|
+
* Folder-to-company has one store (US-030 c3): the registry that `hq link`
|
|
19
|
+
* writes and `hq resolve-company`, hqd and the MCP tool read. After the
|
|
20
|
+
* manifest write, `hq repo add` seeds that registry from the manifest the way
|
|
21
|
+
* `hq install --global` does, so the new checkout resolves at once. Seeding
|
|
22
|
+
* never replaces an `hq link` entry.
|
|
15
23
|
*/
|
|
16
24
|
export const MANIFEST_RELATIVE_PATH = path.join("companies", "manifest.yaml");
|
|
17
25
|
function indentOf(line) {
|
|
@@ -271,7 +279,36 @@ export function runRepoAdd(opts) {
|
|
|
271
279
|
if (manifestChanged)
|
|
272
280
|
writeManifestAtomically(manifestPath, manifestText, nextText);
|
|
273
281
|
}
|
|
274
|
-
|
|
282
|
+
const result = { entry, linked: linkPath !== null, manifestChanged, warnings };
|
|
283
|
+
if (!opts.dryRun && opts.registryFile !== undefined) {
|
|
284
|
+
result.registrySeeded = seedRegistryAfterAdd(hqRoot, opts.registryFile, sourceReal, opts.company, warnings);
|
|
285
|
+
}
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Seed the folder-to-company registry from the manifest just written. The
|
|
290
|
+
* manifest write has already happened, so a registry failure is a warning,
|
|
291
|
+
* not an error: `hq install --global` or `hq link --seed-manifest` repairs it.
|
|
292
|
+
*/
|
|
293
|
+
function seedRegistryAfterAdd(hqRoot, file, checkout, company, warnings) {
|
|
294
|
+
try {
|
|
295
|
+
seedRegistryFromHqRoot(hqRoot, { file });
|
|
296
|
+
}
|
|
297
|
+
catch (err) {
|
|
298
|
+
warnings.push(`The HQ registry was not updated (${err instanceof Error ? err.message : String(err)}). ` +
|
|
299
|
+
`Run \`hq link --seed-manifest ${hqRoot}\` to update it.`);
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
const bound = resolveCompanyForDir(readRegistry(file), checkout);
|
|
304
|
+
if (bound.company && bound.company !== company) {
|
|
305
|
+
warnings.push(`${checkout} is linked to ${bound.company} with \`hq link\`; hq resolve-company keeps answering ${bound.company} until that link is removed (\`hq unlink\`).`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
// The seed above read and wrote this file; a failed re-read changes nothing written.
|
|
310
|
+
}
|
|
311
|
+
return true;
|
|
275
312
|
}
|
|
276
313
|
function isDanglingSymlink(p) {
|
|
277
314
|
try {
|
|
@@ -312,6 +349,7 @@ export function registerRepoCommand(program) {
|
|
|
312
349
|
visibility: opts.public ? "public" : "private",
|
|
313
350
|
name: opts.name,
|
|
314
351
|
dryRun: opts.dryRun,
|
|
352
|
+
registryFile: registryFile(),
|
|
315
353
|
});
|
|
316
354
|
for (const w of result.warnings)
|
|
317
355
|
console.warn(chalk.yellow("Warning:"), w);
|
|
@@ -95,7 +95,9 @@ export declare function validateMode(mode: string): SyncMode;
|
|
|
95
95
|
* throws — auto-detect is best-effort.
|
|
96
96
|
*/
|
|
97
97
|
export declare function readActiveCompanySlug(hqRoot: string): string | undefined;
|
|
98
|
-
/**
|
|
98
|
+
/** Validate portable, company-relative sync prefixes without normalizing them. */
|
|
99
|
+
export declare function validateCustomPaths(entries: readonly string[] | undefined): void;
|
|
100
|
+
/** Parse `--paths a/,b/c/` into validated, trimmed non-empty entries. */
|
|
99
101
|
export declare function parseCustomPaths(raw: string | undefined): string[] | undefined;
|
|
100
102
|
/**
|
|
101
103
|
* Resolve a membership by company slug, then PUT the new sync-mode. Returns
|
|
@@ -69,7 +69,15 @@ export function readActiveCompanySlug(hqRoot) {
|
|
|
69
69
|
return undefined;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
/**
|
|
72
|
+
/** Validate portable, company-relative sync prefixes without normalizing them. */
|
|
73
|
+
export function validateCustomPaths(entries) {
|
|
74
|
+
for (const entry of entries ?? []) {
|
|
75
|
+
if (!entry || entry.includes("..") || /^[\\/]/.test(entry) || /^[A-Za-z]:/.test(entry)) {
|
|
76
|
+
throw new Error("Custom sync paths must be relative paths without parent ('..') components.");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Parse `--paths a/,b/c/` into validated, trimmed non-empty entries. */
|
|
73
81
|
export function parseCustomPaths(raw) {
|
|
74
82
|
if (!raw)
|
|
75
83
|
return undefined;
|
|
@@ -77,6 +85,7 @@ export function parseCustomPaths(raw) {
|
|
|
77
85
|
.split(",")
|
|
78
86
|
.map((s) => s.trim())
|
|
79
87
|
.filter((s) => s.length > 0);
|
|
88
|
+
validateCustomPaths(parts);
|
|
80
89
|
return parts.length > 0 ? parts : undefined;
|
|
81
90
|
}
|
|
82
91
|
// ── Orchestrators (pure, injectable — driven by tests) ──────────────────────
|
|
@@ -87,6 +96,7 @@ export function parseCustomPaths(raw) {
|
|
|
87
96
|
*/
|
|
88
97
|
export async function setSyncMode(options) {
|
|
89
98
|
const { mode, companySlug, customPaths, vaultClient } = options;
|
|
99
|
+
validateCustomPaths(customPaths);
|
|
90
100
|
// 1. Find the caller's membership for this company.
|
|
91
101
|
const memberships = await vaultClient.listMyMemberships();
|
|
92
102
|
// Resolve slug → uid via entity.get on each membership's companyUid in
|
package/dist/lazy-commands.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Argument, Command, Option } from "commander";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
2
|
import { homedir } from "node:os";
|
|
4
|
-
import { dirname,
|
|
3
|
+
import { dirname, resolve, sep } from "node:path";
|
|
5
4
|
import { COMMAND_CATALOG } from "./command-catalog.generated.js";
|
|
6
5
|
import { installUnknownCommandSuggestions } from "./unknown-command.js";
|
|
7
6
|
import { restoreRuntimeText } from "./utils/catalog-runtime-paths.js";
|
|
8
7
|
import { STILL_USE_FLAG } from "./utils/command-usage.js";
|
|
8
|
+
import { isHqRoot } from "./utils/hq-roots-core.js";
|
|
9
9
|
import { MissingRegistrationPlanError } from "./utils/registration-plan-error.js";
|
|
10
10
|
const commandCatalog = COMMAND_CATALOG;
|
|
11
11
|
/**
|
|
@@ -91,8 +91,7 @@ function runtimeHqRoot() {
|
|
|
91
91
|
return resolve(configured);
|
|
92
92
|
return findRuntimeHqRoot(resolve(process.cwd()));
|
|
93
93
|
}
|
|
94
|
-
export function findRuntimeHqRoot(start, parentOf = dirname, isRoot =
|
|
95
|
-
(existsSync(join(directory, ".claude")) || existsSync(join(directory, "core")) || existsSync(join(directory, "personal")))) {
|
|
94
|
+
export function findRuntimeHqRoot(start, parentOf = dirname, isRoot = isHqRoot) {
|
|
96
95
|
let directory = start;
|
|
97
96
|
for (;;) {
|
|
98
97
|
if (isRoot(directory))
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { isDeepStrictEqual } from "node:util";
|
|
15
15
|
import yaml from "js-yaml";
|
|
16
|
+
import { splitFrontmatterBlock } from "../../utils/frontmatter.js";
|
|
16
17
|
import { entityId } from "./identity.js";
|
|
17
18
|
// Same delimiters as hq-pro `parser.ts`.
|
|
18
19
|
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
@@ -333,11 +334,10 @@ function backRefTarget(href) {
|
|
|
333
334
|
export function appendBackRefs(fullContent, refs) {
|
|
334
335
|
if (refs.length === 0)
|
|
335
336
|
return { content: fullContent, added: 0 };
|
|
336
|
-
const
|
|
337
|
-
if (!
|
|
337
|
+
const split = splitFrontmatterBlock(fullContent);
|
|
338
|
+
if (!split)
|
|
338
339
|
return { content: fullContent, added: 0 };
|
|
339
|
-
const frontmatter =
|
|
340
|
-
const body = fmMatch[2];
|
|
340
|
+
const { frontmatter, body } = split;
|
|
341
341
|
const sectionMatch = /(^|\n)(##\s+Relationships\s*\n)([\s\S]*?)(?=\n##\s|\s*$)/.exec(body);
|
|
342
342
|
const existing = new Set();
|
|
343
343
|
if (sectionMatch) {
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
import * as fs from "node:fs";
|
|
51
51
|
import * as path from "node:path";
|
|
52
52
|
import { isDeepStrictEqual } from "node:util";
|
|
53
|
+
import { matchFrontmatter, splitFrontmatterBlock } from "../../utils/frontmatter.js";
|
|
53
54
|
import { freshAliases, ownNames } from "./aliases.js";
|
|
54
55
|
import { entitiesRoot, safeWriteFile } from "./company.js";
|
|
55
56
|
import { appendBackRefs, OWNED_KEYS, parseEntityFile, patchEntityFile, setIdentityKeys } from "./entity-file.js";
|
|
@@ -82,10 +83,6 @@ function sectionLines(body) {
|
|
|
82
83
|
const match = /(^|\n)##\s+Relationships\s*\n([\s\S]*?)(?=\n##\s|$)/.exec(body);
|
|
83
84
|
return match ? match[2].split(/\r?\n/).map((line) => line.trimEnd()) : [];
|
|
84
85
|
}
|
|
85
|
-
function splitBody(content) {
|
|
86
|
-
const match = /^(---\r?\n[\s\S]*?\r?\n---\r?\n?)([\s\S]*)$/.exec(content);
|
|
87
|
-
return match ? { frontmatter: match[1], body: match[2] } : null;
|
|
88
|
-
}
|
|
89
86
|
/**
|
|
90
87
|
* A line of the copy whose every link points at the copy itself or at its
|
|
91
88
|
* original. Moved to the original it would link the survivor to itself or to
|
|
@@ -97,8 +94,8 @@ function isPairSelfLine(line, pair) {
|
|
|
97
94
|
}
|
|
98
95
|
/** Relationship lines of the copy that the original lacks (back-references and self links excluded). */
|
|
99
96
|
function missingRelationshipLines(originalContent, copyContent, pair) {
|
|
100
|
-
const original =
|
|
101
|
-
const copy =
|
|
97
|
+
const original = splitFrontmatterBlock(originalContent);
|
|
98
|
+
const copy = splitFrontmatterBlock(copyContent);
|
|
102
99
|
if (!original || !copy)
|
|
103
100
|
return [];
|
|
104
101
|
const have = new Set(original.body.split(/\r?\n/).map((line) => line.trimEnd()));
|
|
@@ -115,7 +112,7 @@ function missingRelationshipLines(originalContent, copyContent, pair) {
|
|
|
115
112
|
function appendRelationshipLines(content, lines) {
|
|
116
113
|
if (lines.length === 0)
|
|
117
114
|
return content;
|
|
118
|
-
const parts =
|
|
115
|
+
const parts = splitFrontmatterBlock(content);
|
|
119
116
|
const body = parts.body;
|
|
120
117
|
const section = /(^|\n)(##\s+Relationships\s*\n)([\s\S]*?)(?=\n##\s|\s*$)/.exec(body);
|
|
121
118
|
let next;
|
|
@@ -403,12 +400,11 @@ function relink(fromRel, content, copy, original) {
|
|
|
403
400
|
return `](${target.slice(0, cut + 1)}${encoded}${fragment})`;
|
|
404
401
|
});
|
|
405
402
|
}
|
|
406
|
-
const FRONT_RE = /^---\r?\n([\s\S]*?)\r?\n---(\r?\n|$)/;
|
|
407
403
|
const REL_REF = /^(\s*(?:- )?[A-Za-z_][A-Za-z0-9_]*:\s*)(["']?)(\.\.\/[^"'\n]+?\.md)\2\s*$/;
|
|
408
404
|
const WIKI_LINK = /\[\[(ontology\/entities\/[^\]|\n]+?)(\|[^\]\n]*)?\]\]/g;
|
|
409
405
|
const PATH_LINE = /^(\s*(?:- )?path:\s*)(["']?)(ontology\/entities\/[^"'\n]+?\.md)\2\s*$/;
|
|
410
406
|
function frontLines(content) {
|
|
411
|
-
const match =
|
|
407
|
+
const match = matchFrontmatter(content);
|
|
412
408
|
if (!match)
|
|
413
409
|
return null;
|
|
414
410
|
return { start: match.index + match[0].indexOf(match[1]), lines: match[1].split(/\r?\n/) };
|
|
@@ -727,11 +723,11 @@ function mergeCopy(index, pair, siblings, originalContent, copyContent, now) {
|
|
|
727
723
|
});
|
|
728
724
|
if (!patched.ok)
|
|
729
725
|
return patched.reason;
|
|
730
|
-
const have = new Set(
|
|
726
|
+
const have = new Set(splitFrontmatterBlock(patched.content)?.body.split(/\r?\n/).map((line) => line.trim()) ?? []);
|
|
731
727
|
// The copy's `# Name` heading is not content: its name moves to an alias.
|
|
732
728
|
// The `## Relationships` heading is not content either: its lines count one by one.
|
|
733
729
|
const heading = `# ${copyEntity.canonical_name}`;
|
|
734
|
-
const leftover = (
|
|
730
|
+
const leftover = (splitFrontmatterBlock(copyContent)?.body.split(/\r?\n/) ?? [])
|
|
735
731
|
.map((line) => line.trim())
|
|
736
732
|
.filter((line) => line !== "" &&
|
|
737
733
|
line !== heading &&
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
11
|
import * as fs from "node:fs";
|
|
12
12
|
import * as path from "node:path";
|
|
13
|
+
import { matchFrontmatter } from "../../utils/frontmatter.js";
|
|
13
14
|
import { writeCompanyBrief } from "./company-brief.js";
|
|
14
15
|
import { resolveOntologyCompany, safeWriteFile, stateRoot } from "./company.js";
|
|
15
16
|
import { startMultiWriterRun } from "./multi-writer.js";
|
|
@@ -459,7 +460,7 @@ const READ_COPY_DIR = "ontology-inputs";
|
|
|
459
460
|
*/
|
|
460
461
|
export function stripAnnotations(text) {
|
|
461
462
|
let out = text;
|
|
462
|
-
const front =
|
|
463
|
+
const front = matchFrontmatter(text);
|
|
463
464
|
if (front && /^entities:/m.test(front[1])) {
|
|
464
465
|
let inList = false;
|
|
465
466
|
const body = front[1]
|
|
@@ -40,10 +40,13 @@ export function archiveOldThreads(args = [], options = {}) {
|
|
|
40
40
|
return 2;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
// One reading of the clock for the whole run: the gate and the cutoff must
|
|
44
|
+
// agree on the day even when the run crosses midnight.
|
|
45
|
+
const at = now();
|
|
43
46
|
const touchfile = path.join(hqRoot, "workspace/.last-archive-run");
|
|
44
47
|
if (gated && fs.existsSync(touchfile)) {
|
|
45
48
|
const mtime = Math.floor(fs.statSync(touchfile).mtimeMs / 1000);
|
|
46
|
-
const seconds = Math.floor(
|
|
49
|
+
const seconds = Math.floor(at.getTime() / 1000);
|
|
47
50
|
if (seconds - mtime < 86_400) {
|
|
48
51
|
line(stderr, "archive-old-threads: gated (ran <24h ago, skipping)");
|
|
49
52
|
return 0;
|
|
@@ -52,7 +55,7 @@ export function archiveOldThreads(args = [], options = {}) {
|
|
|
52
55
|
const threadsDir = path.join(hqRoot, "workspace/threads");
|
|
53
56
|
const archiveRoot = path.join(threadsDir, "archive");
|
|
54
57
|
fs.mkdirSync(archiveRoot, { recursive: true });
|
|
55
|
-
const cutoff = cutoffStamp(
|
|
58
|
+
const cutoff = cutoffStamp(at, cutoffDays);
|
|
56
59
|
// `ls workspace/threads/T-*.json`: top level only, name-ordered, archive/ excluded.
|
|
57
60
|
let names;
|
|
58
61
|
try {
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifest listing only counts while companies/<slug> does not exist yet
|
|
3
|
+
* (lstat ENOENT, so no dangling symlink either) and no case-insensitive
|
|
4
|
+
* match among real company directories. That lets /newcompany bind before
|
|
5
|
+
* creating the folder without skipping the symlink and case-alias guards.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isPendingManifestCompany(root: string, slug: string): boolean;
|
|
1
8
|
/** Reads the active session's company lock without importing the full hq-session command. */
|
|
2
9
|
export declare function sessionCompanySlugs(root: string, env?: NodeJS.ProcessEnv, multiCompanyLockEnabled?: boolean): string[];
|
|
3
10
|
/**
|
|
@@ -21,7 +28,12 @@ export declare function multiCompanySessionLockRecordedOn(primary: string, env?:
|
|
|
21
28
|
* `hq-session.sh get company_slugs`.
|
|
22
29
|
*
|
|
23
30
|
* Returns [] unless `company_slug` names a real (non-symlink) directory under
|
|
24
|
-
* companies
|
|
31
|
+
* companies/, or is listed in companies/manifest.yaml with no companies/<slug>
|
|
32
|
+
* path yet and no case-alias of another company folder. A pending manifest
|
|
33
|
+
* listing is enough so /newcompany can create companies/<slug>/ after binding
|
|
34
|
+
* the session to that slug (feedback_96cb3024). A symlink or case alias at
|
|
35
|
+
* that slug still fails closed. Listed companies that are neither a real
|
|
36
|
+
* directory nor a pending manifest slug are dropped.
|
|
25
37
|
* hqd's own synthetic `hqd-*` check sessions are ignored, so a caller cannot
|
|
26
38
|
* borrow the binding hqd wrote for a different check. The session folder and
|
|
27
39
|
* its meta.yaml must both be real entries, not symlinks: a symlinked session
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
+
import { readCompaniesManifestMap } from "../work-context/repo-remote.js";
|
|
4
5
|
import { resolveSessionId } from "./session-id.js";
|
|
5
6
|
function metaValue(contents, key) {
|
|
6
7
|
for (const line of contents.split("\n")) {
|
|
@@ -52,6 +53,71 @@ function isExactCompanyDirectory(root, slug) {
|
|
|
52
53
|
}
|
|
53
54
|
return false;
|
|
54
55
|
}
|
|
56
|
+
/** True when companies/manifest.yaml lists this slug, even before its folder exists. */
|
|
57
|
+
function isListedInManifest(root, slug) {
|
|
58
|
+
const map = readCompaniesManifestMap(root);
|
|
59
|
+
return Boolean(map && Object.prototype.hasOwnProperty.call(map, slug));
|
|
60
|
+
}
|
|
61
|
+
function pathExists(target) {
|
|
62
|
+
try {
|
|
63
|
+
fs.lstatSync(target);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const code = error.code;
|
|
68
|
+
if (code === "ENOENT")
|
|
69
|
+
return false;
|
|
70
|
+
if (code === "ENOTDIR" || code === "EACCES" || code === "ELOOP")
|
|
71
|
+
return true;
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** True when a differently cased real company directory already exists. */
|
|
76
|
+
function hasCaseAlias(root, slug) {
|
|
77
|
+
const companies = path.join(root, "companies");
|
|
78
|
+
const fold = slug.toLowerCase();
|
|
79
|
+
try {
|
|
80
|
+
for (const entry of fs.readdirSync(companies)) {
|
|
81
|
+
if (entry === slug || entry.toLowerCase() !== fold)
|
|
82
|
+
continue;
|
|
83
|
+
const candidate = path.join(companies, entry);
|
|
84
|
+
try {
|
|
85
|
+
if (!fs.statSync(candidate).isDirectory() || fs.lstatSync(candidate).isSymbolicLink())
|
|
86
|
+
continue;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
const code = error.code;
|
|
91
|
+
if (code !== "ENOENT" && code !== "ENOTDIR" && code !== "EACCES" && code !== "ELOOP")
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const code = error.code;
|
|
98
|
+
if (code !== "ENOENT" && code !== "ENOTDIR" && code !== "EACCES" && code !== "ELOOP")
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Manifest listing only counts while companies/<slug> does not exist yet
|
|
105
|
+
* (lstat ENOENT, so no dangling symlink either) and no case-insensitive
|
|
106
|
+
* match among real company directories. That lets /newcompany bind before
|
|
107
|
+
* creating the folder without skipping the symlink and case-alias guards.
|
|
108
|
+
*/
|
|
109
|
+
export function isPendingManifestCompany(root, slug) {
|
|
110
|
+
if (!isListedInManifest(root, slug))
|
|
111
|
+
return false;
|
|
112
|
+
if (pathExists(path.join(root, "companies", slug)))
|
|
113
|
+
return false;
|
|
114
|
+
if (hasCaseAlias(root, slug))
|
|
115
|
+
return false;
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
function isUsableCompanyBind(root, slug) {
|
|
119
|
+
return isExactCompanyDirectory(root, slug) || isPendingManifestCompany(root, slug);
|
|
120
|
+
}
|
|
55
121
|
/** Reads the active session's company lock without importing the full hq-session command. */
|
|
56
122
|
export function sessionCompanySlugs(root, env = process.env, multiCompanyLockEnabled = false) {
|
|
57
123
|
const sessionId = resolveSessionId(root, env);
|
|
@@ -74,7 +140,7 @@ export function sessionCompanySlugs(root, env = process.env, multiCompanyLockEna
|
|
|
74
140
|
const primary = metaValue(contents, "company_slug");
|
|
75
141
|
return primary ? [primary] : [];
|
|
76
142
|
}
|
|
77
|
-
return listedCompanySlugs(contents).filter((slug) => slug === "personal" ||
|
|
143
|
+
return listedCompanySlugs(contents).filter((slug) => slug === "personal" || isUsableCompanyBind(root, slug));
|
|
78
144
|
}
|
|
79
145
|
/**
|
|
80
146
|
* Whether the multi-company session lock is on for a session whose primary
|
|
@@ -113,7 +179,12 @@ const SESSION_DIR_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
|
|
|
113
179
|
* `hq-session.sh get company_slugs`.
|
|
114
180
|
*
|
|
115
181
|
* Returns [] unless `company_slug` names a real (non-symlink) directory under
|
|
116
|
-
* companies
|
|
182
|
+
* companies/, or is listed in companies/manifest.yaml with no companies/<slug>
|
|
183
|
+
* path yet and no case-alias of another company folder. A pending manifest
|
|
184
|
+
* listing is enough so /newcompany can create companies/<slug>/ after binding
|
|
185
|
+
* the session to that slug (feedback_96cb3024). A symlink or case alias at
|
|
186
|
+
* that slug still fails closed. Listed companies that are neither a real
|
|
187
|
+
* directory nor a pending manifest slug are dropped.
|
|
117
188
|
* hqd's own synthetic `hqd-*` check sessions are ignored, so a caller cannot
|
|
118
189
|
* borrow the binding hqd wrote for a different check. The session folder and
|
|
119
190
|
* its meta.yaml must both be real entries, not symlinks: a symlinked session
|
|
@@ -143,12 +214,12 @@ export function sessionMetaCompanies(root, sessionId, env = process.env) {
|
|
|
143
214
|
const primary = metaValue(contents, "company_slug");
|
|
144
215
|
if (!primary || primary === "personal" || !/^[A-Za-z0-9_-]+$/.test(primary))
|
|
145
216
|
return [];
|
|
146
|
-
if (!
|
|
217
|
+
if (!isUsableCompanyBind(root, primary))
|
|
147
218
|
return [];
|
|
148
219
|
if (!multiCompanySessionLockRecordedOn(primary, env))
|
|
149
220
|
return [primary];
|
|
150
221
|
const others = listedCompanySlugs(contents)
|
|
151
|
-
.filter((slug) => slug !== primary && slug !== "personal" &&
|
|
222
|
+
.filter((slug) => slug !== primary && slug !== "personal" && isUsableCompanyBind(root, slug));
|
|
152
223
|
return [primary, ...others];
|
|
153
224
|
}
|
|
154
225
|
//# sourceMappingURL=session-company.js.map
|
|
@@ -10,6 +10,12 @@ export type CoreIo = {
|
|
|
10
10
|
cwd?: string;
|
|
11
11
|
now?: () => Date;
|
|
12
12
|
randomBytes?: (size: number) => Buffer;
|
|
13
|
+
/**
|
|
14
|
+
* Arms a timer and returns a function that disarms it. Defaults to
|
|
15
|
+
* setTimeout/clearTimeout; tests inject it to end a stalled URL check
|
|
16
|
+
* without waiting out the real 15 s limit.
|
|
17
|
+
*/
|
|
18
|
+
armTimer?: (onExpire: () => void, ms: number) => () => void;
|
|
13
19
|
};
|
|
14
20
|
export declare function worktreeGcPathKey(value: string): string;
|
|
15
21
|
export declare function runWorktreeGc(args: readonly string[], hqRoot: string, io?: CoreIo): number;
|
|
@@ -16,6 +16,10 @@ const stderr = (io, value) => (io.stderr ?? ((v) => process.stderr.write(v)))(va
|
|
|
16
16
|
const envOf = (io) => io.env ?? process.env;
|
|
17
17
|
const nowOf = (io) => (io.now ?? (() => new Date()))();
|
|
18
18
|
const randomBytesOf = (io, size) => (io.randomBytes ?? randomBytes)(size);
|
|
19
|
+
const defaultArmTimer = (onExpire, ms) => {
|
|
20
|
+
const timer = setTimeout(onExpire, ms);
|
|
21
|
+
return () => clearTimeout(timer);
|
|
22
|
+
};
|
|
19
23
|
const stripTrailingNewlines = (value) => value.replace(/\n+$/u, "");
|
|
20
24
|
function git(args, options = {}) {
|
|
21
25
|
const childEnv = options.env;
|
|
@@ -1026,9 +1030,9 @@ function isReadable(file) {
|
|
|
1026
1030
|
function joinShellPath(root, value) {
|
|
1027
1031
|
return value.startsWith("/") ? value : `${root}/${value}`;
|
|
1028
1032
|
}
|
|
1029
|
-
async function urlIsPresent(url) {
|
|
1033
|
+
async function urlIsPresent(url, io) {
|
|
1030
1034
|
const controller = new AbortController();
|
|
1031
|
-
const
|
|
1035
|
+
const disarm = (io.armTimer ?? defaultArmTimer)(() => controller.abort(), 15_000);
|
|
1032
1036
|
try {
|
|
1033
1037
|
let current;
|
|
1034
1038
|
try {
|
|
@@ -1060,7 +1064,7 @@ async function urlIsPresent(url) {
|
|
|
1060
1064
|
return false;
|
|
1061
1065
|
}
|
|
1062
1066
|
finally {
|
|
1063
|
-
|
|
1067
|
+
disarm();
|
|
1064
1068
|
}
|
|
1065
1069
|
}
|
|
1066
1070
|
async function drainResponseBody(response) {
|
|
@@ -1222,7 +1226,7 @@ export async function runVerifyStoryDeliverables(args, hqRoot, io = {}) {
|
|
|
1222
1226
|
ok = git(["-C", repo, "cat-file", "-e", `${value}^{commit}`], { env }).status === 0;
|
|
1223
1227
|
}
|
|
1224
1228
|
else if (kind === "url")
|
|
1225
|
-
ok = offline === "1" || await urlIsPresent(value);
|
|
1229
|
+
ok = offline === "1" || await urlIsPresent(value, io);
|
|
1226
1230
|
if (ok)
|
|
1227
1231
|
present.push(reference);
|
|
1228
1232
|
else
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefix a unit's command with `taskpolicy -b` on macOS. taskpolicy execs the
|
|
3
|
+
* command in place, so the pid the supervisor tracks is the unit itself, and
|
|
4
|
+
* PRIO_DARWIN_BG is inherited by everything the unit spawns (qmd included).
|
|
5
|
+
*/
|
|
6
|
+
export declare function backgroundQosCommand(command: [string, string[]], backgroundQos: boolean, platform?: NodeJS.Platform | string, exists?: (file: string) => boolean): [string, string[]];
|
|
7
|
+
//# sourceMappingURL=background-qos.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
const DARWIN_TASKPOLICY = "/usr/sbin/taskpolicy";
|
|
3
|
+
/**
|
|
4
|
+
* Prefix a unit's command with `taskpolicy -b` on macOS. taskpolicy execs the
|
|
5
|
+
* command in place, so the pid the supervisor tracks is the unit itself, and
|
|
6
|
+
* PRIO_DARWIN_BG is inherited by everything the unit spawns (qmd included).
|
|
7
|
+
*/
|
|
8
|
+
export function backgroundQosCommand(command, backgroundQos, platform = process.platform, exists = fs.existsSync) {
|
|
9
|
+
if (!backgroundQos || platform !== "darwin" || !exists(DARWIN_TASKPOLICY))
|
|
10
|
+
return command;
|
|
11
|
+
return [DARWIN_TASKPOLICY, ["-b", command[0], ...command[1]]];
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=background-qos.js.map
|
|
@@ -42,9 +42,16 @@ type UnitCommand = {
|
|
|
42
42
|
} | {
|
|
43
43
|
type: "internal";
|
|
44
44
|
task: InternalTask;
|
|
45
|
+
} | {
|
|
46
|
+
type: "worker";
|
|
47
|
+
task: "search-index";
|
|
45
48
|
};
|
|
46
49
|
/** Work the daemon does in its own process on a schedule, without starting a child. */
|
|
47
50
|
export type InternalTask = "rotate-logs" | "lanes-reconcile";
|
|
51
|
+
/** Compatibility path for installations that do not contain the versioned worker. */
|
|
52
|
+
export declare function legacySearchIndexCommand(root: string | undefined): Extract<UnitCommand, {
|
|
53
|
+
type: "hq";
|
|
54
|
+
}>;
|
|
48
55
|
interface UnitBlock {
|
|
49
56
|
/** `waiting` clears when requirements appear; `unavailable` needs a newer CLI; `paused` needs an explicit resume. */
|
|
50
57
|
state: "waiting" | "unavailable" | "paused";
|
|
@@ -182,6 +189,8 @@ export interface PlanContext {
|
|
|
182
189
|
lanesReconcileInProcess?: boolean;
|
|
183
190
|
/** The active hq-cloud sync runner owns post-sync QMD indexing. */
|
|
184
191
|
searchIndexOwnedBySyncRunner?: boolean;
|
|
192
|
+
/** Whether the daemon can hand package protection to a scheduled worker. */
|
|
193
|
+
searchIndexWorkerAvailable?: boolean;
|
|
185
194
|
/** Sync runner children already started by this daemon before their lease is written. */
|
|
186
195
|
daemonSyncRunnerPids?: ReadonlySet<number>;
|
|
187
196
|
/** The protocol-event heartbeat watchdog timeout for the sync runner. */
|
|
@@ -93,6 +93,10 @@ export function enabledServices(machineType, overrides) {
|
|
|
93
93
|
};
|
|
94
94
|
return SERVICE_NAMES.filter((s) => wanted(s) || implied(s));
|
|
95
95
|
}
|
|
96
|
+
/** Compatibility path for installations that do not contain the versioned worker. */
|
|
97
|
+
export function legacySearchIndexCommand(root) {
|
|
98
|
+
return { type: "hq", args: ["index", "sync", "--hq-root", root ?? ""] };
|
|
99
|
+
}
|
|
96
100
|
export const FLEET_BOT_STOP_GRACE_MS = 30_000;
|
|
97
101
|
export const FLEET_BOTS_UPDATE_UNIT = "fleet-bots-update";
|
|
98
102
|
export const FLEET_BOTS_UPDATE_INTERVAL_SEC = 30 * 60;
|
|
@@ -460,7 +464,10 @@ function planService(service, ctx) {
|
|
|
460
464
|
kind: "scheduled",
|
|
461
465
|
intervalSec: 900,
|
|
462
466
|
initialDelaySec: 120,
|
|
463
|
-
command:
|
|
467
|
+
command: ctx.searchIndexWorkerAvailable === false
|
|
468
|
+
? legacySearchIndexCommand(ctx.hqRoot)
|
|
469
|
+
: { type: "worker", task: "search-index" },
|
|
470
|
+
env: ctx.hqRoot ? { HQ_ROOT: ctx.hqRoot } : {},
|
|
464
471
|
// A full qmd pass rereads every indexed file; at default priority it
|
|
465
472
|
// got HQ listed under macOS "Using Significant Energy".
|
|
466
473
|
backgroundQos: true,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type ShareCandidate = {
|
|
2
|
+
kind: "deploy";
|
|
3
|
+
appId: string;
|
|
4
|
+
companies: string[];
|
|
5
|
+
} | {
|
|
6
|
+
kind: "path";
|
|
7
|
+
path: string;
|
|
8
|
+
trigger: string;
|
|
9
|
+
threadHandoff?: true;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* At most twelve normalized references. Raw tool input and output cannot be part of a note.
|
|
13
|
+
* A well-formed path the release could not have suggested is skipped; the rest of the note is kept.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseShareCandidates(value: unknown): ShareCandidate[] | undefined;
|
|
16
|
+
/** Write only the existing local suggestion state. The consumer still must request approval to share. */
|
|
17
|
+
export declare function executeAclSuggestion(root: string, session: string, candidates: ShareCandidate[], env: NodeJS.ProcessEnv, now?: () => Date): number;
|
|
18
|
+
//# sourceMappingURL=hook-requests-acl-suggest.d.ts.map
|