@indigoai-us/hq-cli 5.345.219 → 5.345.221
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 +170 -0
- package/dist/command-catalog.generated.d.ts +169 -3
- package/dist/command-catalog.generated.js +206 -3
- package/dist/commands/auth.js +4 -1
- package/dist/commands/bot-runtime.d.ts +18 -5
- package/dist/commands/bot-runtime.js +29 -12
- package/dist/commands/bot.d.ts +85 -0
- package/dist/commands/bot.js +245 -16
- package/dist/commands/cloud.d.ts +16 -0
- package/dist/commands/cloud.js +112 -102
- package/dist/commands/core-checkpoint-native.d.ts +13 -0
- package/dist/commands/core-checkpoint-native.js +167 -52
- package/dist/commands/core-hook-registration-plan.js +5 -4
- package/dist/commands/core-stop-autosave.d.ts +21 -0
- package/dist/commands/core-stop-autosave.js +300 -0
- package/dist/commands/core.js +2 -0
- package/dist/commands/daemon.d.ts +5 -0
- package/dist/commands/daemon.js +52 -9
- package/dist/commands/doctor-usage.d.ts +5 -0
- package/dist/commands/doctor-usage.js +25 -0
- package/dist/commands/env.d.ts +49 -4
- package/dist/commands/env.js +355 -5
- package/dist/commands/integrations.js +84 -3
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +87 -3
- package/dist/commands/packs.js +23 -0
- package/dist/commands/pkg-update.d.ts +6 -0
- package/dist/commands/pkg-update.js +15 -7
- package/dist/commands/run.js +55 -45
- package/dist/commands/sources.js +4 -3
- package/dist/commands/sync-core.d.ts +1 -0
- package/dist/commands/sync-core.js +77 -3
- package/dist/commands/whoami.js +96 -80
- package/dist/lib/bot/config.d.ts +17 -0
- package/dist/lib/bot/config.js +13 -0
- package/dist/lib/bot/fleet-cron.js +29 -4
- package/dist/lib/bot/fleet-local.d.ts +30 -2
- package/dist/lib/bot/fleet-local.js +60 -1
- package/dist/lib/bot/grok-login-scope.d.ts +36 -0
- package/dist/lib/bot/grok-login-scope.js +93 -0
- package/dist/lib/bot/inflight.d.ts +9 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
- package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
- package/dist/lib/bot/legacy-provider-login.js +28 -22
- package/dist/lib/bot/run.d.ts +29 -5
- package/dist/lib/bot/run.js +203 -1
- package/dist/lib/bot/runtime-sign-in-check.js +6 -1
- package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
- package/dist/lib/bot/signals-try-now.d.ts +76 -0
- package/dist/lib/bot/signals-try-now.js +111 -0
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
- package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
- package/dist/lib/capacity/scheduler.d.ts +8 -0
- package/dist/lib/capacity/scheduler.js +5 -2
- package/dist/lib/core-utils/sentry-report.js +2 -0
- package/dist/lib/daemon/machine-checks.d.ts +22 -1
- package/dist/lib/daemon/machine-checks.js +54 -12
- package/dist/lib/daemon/run.js +71 -8
- package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
- package/dist/lib/daemon/runtime-notifications.js +50 -0
- package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
- package/dist/lib/daemon/stop-autosave-lock.js +166 -0
- package/dist/lib/daemon/stop-autosave.d.ts +28 -0
- package/dist/lib/daemon/stop-autosave.js +111 -0
- package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
- package/dist/lib/daemon/stop-diagnostics.js +136 -0
- package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
- package/dist/lib/daemon/stop-job-executor.js +126 -0
- package/dist/lib/daemon/stop-jobs.d.ts +93 -0
- package/dist/lib/daemon/stop-jobs.js +599 -0
- package/dist/lib/doctor/checks/fleet-hook-core.d.ts +9 -1
- package/dist/lib/doctor/checks/fleet-hook-core.js +39 -15
- package/dist/lib/doctor/checks/host-core.js +1 -1
- package/dist/lib/environment/access-probes.d.ts +234 -0
- package/dist/lib/environment/access-probes.js +918 -0
- package/dist/lib/environment/profile.d.ts +15 -2
- package/dist/lib/environment/profile.js +55 -20
- package/dist/lib/environment/rfc3339.d.ts +8 -0
- package/dist/lib/environment/rfc3339.js +26 -0
- package/dist/lib/environment/work-requirements.d.ts +169 -0
- package/dist/lib/environment/work-requirements.js +389 -0
- package/dist/lib/hook-engine/coverage.d.ts +137 -7
- package/dist/lib/hook-engine/coverage.js +1424 -4
- package/dist/lib/hook-engine/fleet-registration.d.ts +17 -5
- package/dist/lib/hook-engine/fleet-registration.js +53 -17
- package/dist/lib/hook-engine/git-stop-config.json +513 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
- package/dist/lib/hook-engine/reconcile.js +2 -2
- package/dist/lib/hot-channels/alert.d.ts +10 -1
- package/dist/lib/hot-channels/alert.js +38 -8
- package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
- package/dist/lib/hot-channels/signals-claude-login.js +96 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +143 -17
- package/dist/lib/hot-channels/signals-pass.js +324 -17
- package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
- package/dist/lib/hot-channels/signals-runtime.js +82 -0
- package/dist/lib/install/hook-target.js +1 -1
- package/dist/lib/lanes/host-capacity.d.ts +26 -2
- package/dist/lib/lanes/host-capacity.js +17 -2
- package/dist/lib/lanes/host-compute.d.ts +90 -0
- package/dist/lib/lanes/host-compute.js +185 -0
- package/dist/lib/lanes/index.d.ts +2 -0
- package/dist/lib/lanes/index.js +1 -0
- package/dist/lib/lanes/reconcile.js +22 -1
- package/dist/lib/lanes/resource-usage.d.ts +155 -0
- package/dist/lib/lanes/resource-usage.js +589 -0
- package/dist/lib/lanes/run-size.d.ts +46 -0
- package/dist/lib/lanes/run-size.js +197 -0
- package/dist/lib/lanes/store.js +27 -0
- package/dist/lib/lanes/throttle.d.ts +36 -1
- package/dist/lib/lanes/throttle.js +47 -10
- package/dist/lib/lanes/types.d.ts +40 -0
- package/dist/lib/lanes/types.js +2 -2
- package/dist/lib/lanes/watcher.js +13 -4
- package/dist/lib/lanes/worker-process.d.ts +25 -2
- package/dist/lib/lanes/worker-process.js +71 -19
- package/dist/lib/placement/match.d.ts +192 -0
- package/dist/lib/placement/match.js +667 -0
- package/dist/lib/safe-store.d.ts +14 -0
- package/dist/lib/safe-store.js +77 -4
- package/dist/lib/search-index/index.d.ts +88 -4
- package/dist/lib/search-index/index.js +299 -25
- package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
- package/dist/lib/search-index/max-doc-bytes.js +48 -23
- package/dist/lib/signals/codex-lockdown.d.ts +79 -0
- package/dist/lib/signals/codex-lockdown.js +271 -0
- package/dist/lib/signals/codex-login.d.ts +37 -0
- package/dist/lib/signals/codex-login.js +83 -0
- package/dist/lib/signals/engine.d.ts +28 -0
- package/dist/lib/signals/engine.js +77 -0
- package/dist/lib/signals/reply.d.ts +48 -0
- package/dist/lib/signals/reply.js +94 -12
- package/dist/lib/signals/run-record.js +6 -1
- package/dist/lib/signals/settings.d.ts +5 -0
- package/dist/lib/signals/settings.js +2 -0
- package/dist/lib/signals/steps/adapters.js +6 -0
- package/dist/lib/signals/steps/extract.d.ts +135 -12
- package/dist/lib/signals/steps/extract.js +416 -84
- package/dist/lib/signals/steps/types.d.ts +21 -0
- package/dist/lib/sync-core/engine-home.d.ts +41 -2
- package/dist/lib/sync-core/engine-home.js +132 -19
- package/dist/lib/sync-core/reconcile.js +1 -1
- package/dist/lib/sync-core/release-compare.d.ts +7 -0
- package/dist/lib/sync-core/release-compare.js +16 -0
- package/dist/lib/sync-core/release.d.ts +2 -1
- package/dist/lib/sync-core/release.js +2 -10
- package/dist/lib/sync-core/rollout-state.d.ts +2 -1
- package/dist/lib/sync-core/rollout-state.js +5 -2
- package/dist/lib/sync-core/vault-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/run/schema-env-overrides.d.ts +24 -0
- package/dist/run/schema-env-overrides.js +72 -0
- package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
- package/dist/utils/auth-session-check.d.ts +16 -0
- package/dist/utils/auth-session-check.js +16 -0
- package/dist/utils/client-health-contract.d.ts +6 -0
- package/dist/utils/client-health-contract.js +13 -0
- package/dist/utils/client-health.d.ts +7 -0
- package/dist/utils/client-health.js +22 -1
- package/dist/utils/command-usage.d.ts +40 -0
- package/dist/utils/command-usage.js +61 -0
- package/dist/utils/duplicate-command-usage.d.ts +72 -0
- package/dist/utils/duplicate-command-usage.js +125 -0
- package/dist/utils/host-registration.d.ts +1 -1
- package/dist/utils/host-registration.js +6 -1
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/sentry-fingerprint.js +9 -0
- package/dist/utils/windows-bash.d.ts +2 -0
- package/dist/utils/windows-bash.js +2 -1
- package/package.json +15 -10
- package/scripts/bench-core-compare.mjs +313 -0
- package/scripts/bench-core.mjs +399 -12
- package/scripts/check-function-manifest.mjs +121 -7
- package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
- package/dist/commands/__fixtures__/access-vault.js +0 -166
- package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
- package/dist/commands/__fixtures__/make-tar.js +0 -102
- package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
- package/dist/commands/secrets-public-types.test-d.js +0 -18
- package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
- package/dist/lib/decisions/fixtures/us001.js +0 -21
- package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
- package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
- package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
- package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
- package/dist/lib/fingerprint/fixtures.d.ts +0 -19
- package/dist/lib/fingerprint/fixtures.js +0 -61
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
- package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
- package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
- package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
- package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
- package/scripts/hook-engine-manifest.mjs +0 -22
- package/scripts/mesh-daemon-if-stale.mjs +0 -20
|
@@ -109,6 +109,155 @@ export class QmdCollectionExistsError extends QmdExitError {
|
|
|
109
109
|
this.collectionName = collectionName;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* qmd's `collection add` exited non-zero because ANOTHER collection already
|
|
114
|
+
* covers exactly this path and pattern (qmd 2.5.3 prints "A collection already
|
|
115
|
+
* exists for this path and pattern:" and then `Name: <other> (qmd://<other>/)`).
|
|
116
|
+
* For unmanaged names, reconciliation skips its own add, prints a notice and
|
|
117
|
+
* carries on. HQ-managed name collisions remain fatal and captured. Before
|
|
118
|
+
* this, the duplicate aborted the whole `hq index sync`, so no collection was
|
|
119
|
+
* ever updated again on that machine (HQ-CLI-GJ).
|
|
120
|
+
*/
|
|
121
|
+
export class QmdCollectionPathTakenError extends QmdExitError {
|
|
122
|
+
existingName;
|
|
123
|
+
name = 'QmdCollectionPathTakenError';
|
|
124
|
+
constructor(message, args, status, stdout, stderr, existingName) {
|
|
125
|
+
super(message, args, status, stdout, stderr);
|
|
126
|
+
this.existingName = existingName;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* hq or its qmd child was refused READ access to the HQ folder: EPERM/EACCES on
|
|
131
|
+
* `uv_cwd` (qmd's process.cwd() in the HQ root), or on a scandir/open of a path
|
|
132
|
+
* inside the HQ root. On macOS an EPERM there is the privacy (TCC) gate on a
|
|
133
|
+
* protected location such as Documents, Desktop or iCloud Drive. The message is
|
|
134
|
+
* the platform-specific remedy; the carrier is thrown marked expected, so the
|
|
135
|
+
* boundary prints it and skips capture (HQ-CLI-EJ, HQ-CLI-FV, HQ-CLI-BV,
|
|
136
|
+
* HQ-CLI-FF).
|
|
137
|
+
*/
|
|
138
|
+
export class QmdAccessDeniedError extends QmdExitError {
|
|
139
|
+
deniedPath;
|
|
140
|
+
errnoCode;
|
|
141
|
+
syscall;
|
|
142
|
+
name = 'QmdAccessDeniedError';
|
|
143
|
+
constructor(message, args, status, stdout, stderr, deniedPath, errnoCode, syscall) {
|
|
144
|
+
super(message, args, status, stdout, stderr);
|
|
145
|
+
this.deniedPath = deniedPath;
|
|
146
|
+
this.errnoCode = errnoCode;
|
|
147
|
+
this.syscall = syscall;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* qmd could not create or write its own settings folder (QMD_CONFIG_DIR,
|
|
152
|
+
* $XDG_CONFIG_HOME/qmd or ~/.config/qmd): EPERM/EACCES on a path at or above
|
|
153
|
+
* that folder. The user's account cannot write there, typically because the
|
|
154
|
+
* folder was created by a command run with sudo. Thrown marked expected with
|
|
155
|
+
* the remedy as its message (HQ-CLI-GJ).
|
|
156
|
+
*/
|
|
157
|
+
export class QmdConfigUnwritableError extends QmdExitError {
|
|
158
|
+
configDir;
|
|
159
|
+
errnoCode;
|
|
160
|
+
name = 'QmdConfigUnwritableError';
|
|
161
|
+
constructor(message, args, status, stdout, stderr, configDir, errnoCode) {
|
|
162
|
+
super(message, args, status, stdout, stderr);
|
|
163
|
+
this.configDir = configDir;
|
|
164
|
+
this.errnoCode = errnoCode;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* qmd's SQLite index file is damaged (SQLITE_CORRUPT / SQLITE_NOTADB). qmd
|
|
169
|
+
* reports it as "sqlite-vec extension is unavailable ... Install Homebrew
|
|
170
|
+
* SQLite", which cannot fix a damaged file. hq names the file and the rebuild
|
|
171
|
+
* step instead. Still captured, because a trend of damaged index files would
|
|
172
|
+
* point at a writer bug (HQ-CLI-EJ).
|
|
173
|
+
*/
|
|
174
|
+
export class QmdStoreCorruptError extends QmdExitError {
|
|
175
|
+
storeFile;
|
|
176
|
+
name = 'QmdStoreCorruptError';
|
|
177
|
+
constructor(message, args, status, stdout, stderr, storeFile) {
|
|
178
|
+
super(message, args, status, stdout, stderr);
|
|
179
|
+
this.storeFile = storeFile;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Parse an unambiguous fatal Node permission error from stderr, for example
|
|
184
|
+
* `Error: EPERM: operation not permitted, uv_cwd` or
|
|
185
|
+
* `[Error: EACCES: permission denied, mkdir '/home/u/.config/qmd']`.
|
|
186
|
+
* Incidental warnings and output containing another thrown error stay captured.
|
|
187
|
+
*/
|
|
188
|
+
export function parseQmdPermissionFailure(text) {
|
|
189
|
+
const errors = text.match(/^\[?(?:[A-Za-z_$][\w$]*Error|Error):[^\r\n]*/gm);
|
|
190
|
+
if (errors?.length !== 1)
|
|
191
|
+
return undefined;
|
|
192
|
+
const match = /^\[?Error: (EPERM|EACCES): [^\n,]*, ([a-z_]+)(?: '([^'\n]+)')?(?:\]?\s*\{?)?$/.exec(errors[0]);
|
|
193
|
+
if (!match)
|
|
194
|
+
return undefined;
|
|
195
|
+
const code = match[1];
|
|
196
|
+
const syscall = match[2] ?? '';
|
|
197
|
+
return match[3] ? { code, syscall, path: match[3] } : { code, syscall };
|
|
198
|
+
}
|
|
199
|
+
function isSameOrInside(candidate, parent) {
|
|
200
|
+
const relative = path.relative(comparablePath(path.resolve(parent)), comparablePath(path.resolve(candidate)));
|
|
201
|
+
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
|
|
202
|
+
}
|
|
203
|
+
/** qmd's global settings folder for this env (no project-local `.qmd/`). */
|
|
204
|
+
function qmdGlobalConfigDir(env) {
|
|
205
|
+
const configPath = resolveQmdConfigPath({
|
|
206
|
+
env: { ...env, HOME: env.HOME ?? env.USERPROFILE ?? os.homedir() },
|
|
207
|
+
});
|
|
208
|
+
return configPath ? path.dirname(configPath) : undefined;
|
|
209
|
+
}
|
|
210
|
+
/** Remedy for a refused read of the HQ folder, worded for the platform. */
|
|
211
|
+
export function qmdAccessDeniedMessage(deniedPath, code, platform = process.platform) {
|
|
212
|
+
if (platform === 'darwin' && code === 'EPERM') {
|
|
213
|
+
return (`macOS blocked hq's search index from reading ${deniedPath} (operation not permitted). ` +
|
|
214
|
+
'Your HQ folder is probably in a privacy-protected location such as Documents, Desktop or iCloud Drive, ' +
|
|
215
|
+
'and the app that runs hq has not been given access to it. Allow it in System Settings > Privacy & Security > ' +
|
|
216
|
+
'Full Disk Access (or Files and Folders), or move your HQ folder out of that location, then run: hq index sync');
|
|
217
|
+
}
|
|
218
|
+
if (platform === 'win32') {
|
|
219
|
+
return (`hq's search index could not read ${deniedPath} (access denied). Check that your Windows account can read ` +
|
|
220
|
+
'that folder and that Controlled folder access or OneDrive is not blocking it, then run: hq index sync');
|
|
221
|
+
}
|
|
222
|
+
if (code === 'EPERM') {
|
|
223
|
+
// EPERM is not a file-mode refusal on Linux and other Unix systems: it comes
|
|
224
|
+
// from an immutable attribute or a security module.
|
|
225
|
+
return (`hq's search index could not read ${deniedPath} (operation not permitted). This is not a file permission ` +
|
|
226
|
+
'setting: the folder or a file in it may be marked immutable (lsattr), or a security policy such as SELinux ' +
|
|
227
|
+
'or AppArmor may be blocking it. Clear that block, then run: hq index sync');
|
|
228
|
+
}
|
|
229
|
+
return (`hq's search index could not read ${deniedPath} (permission denied). Give your user read access to that folder, ` +
|
|
230
|
+
'then run: hq index sync');
|
|
231
|
+
}
|
|
232
|
+
/** Remedy for a qmd settings folder the user cannot write. */
|
|
233
|
+
export function qmdConfigUnwritableMessage(configDir, deniedPath, syscall, platform = process.platform) {
|
|
234
|
+
// A failed mkdir means the PARENT could not be written; anything else names the
|
|
235
|
+
// path itself.
|
|
236
|
+
const fixTarget = syscall === 'mkdir' ? path.dirname(deniedPath) : deniedPath;
|
|
237
|
+
const lead = `qmd could not save its search settings in ${configDir} because your user cannot write to ${fixTarget}, ` +
|
|
238
|
+
'so hq could not register its search collections. ';
|
|
239
|
+
if (platform === 'win32') {
|
|
240
|
+
// Windows has no sudo; the usual cause is another account or an elevated prompt.
|
|
241
|
+
return (lead +
|
|
242
|
+
'This usually happens when the folder was created by another account or from an administrator prompt. ' +
|
|
243
|
+
'Set QMD_CONFIG_DIR to a folder owned by your Windows account where you have Full control ' +
|
|
244
|
+
'(Properties > Security), then run: hq index sync');
|
|
245
|
+
}
|
|
246
|
+
return (lead +
|
|
247
|
+
'Set QMD_CONFIG_DIR to a folder owned by your user where you have write access, then run: hq index sync');
|
|
248
|
+
}
|
|
249
|
+
function qmdStoreFile(env, cwd) {
|
|
250
|
+
try {
|
|
251
|
+
const base = cwd ?? os.homedir();
|
|
252
|
+
if (env.INDEX_PATH)
|
|
253
|
+
return path.resolve(base, env.INDEX_PATH);
|
|
254
|
+
return path.join(resolveQmdStoreDir(env, base), 'index.sqlite');
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const QMD_STORE_CORRUPT = /database disk image is malformed|\bSQLITE_CORRUPT\b|file is not a database|\bSQLITE_NOTADB\b/;
|
|
112
261
|
/**
|
|
113
262
|
* qmd did NOT exit — it was KILLED BY A SIGNAL before it finished (spawnSync
|
|
114
263
|
* reports `status: null` with a non-null `signal`). hq-cli passes qmd no timeout
|
|
@@ -567,6 +716,10 @@ function invocationBin(invocation) {
|
|
|
567
716
|
function invocationKey(invocation) {
|
|
568
717
|
return [invocation.command, ...invocation.prefixArgs].join('');
|
|
569
718
|
}
|
|
719
|
+
/** Output cap for captured qmd stdout/stderr. Node's spawnSync default is 1 MiB,
|
|
720
|
+
* which overflowed as ENOBUFS on a ~189k-document index (`hq index status` /
|
|
721
|
+
* `hq index sync`, feedback_48c6252c). */
|
|
722
|
+
const QMD_SPAWN_MAX_BUFFER = 64 * 1024 * 1024;
|
|
570
723
|
/** Default low-level spawn: `spawnSync` with captured utf8 output. */
|
|
571
724
|
const defaultSpawn = (cmd, args, options) => {
|
|
572
725
|
const result = spawnSync(cmd, args, {
|
|
@@ -576,6 +729,7 @@ const defaultSpawn = (cmd, args, options) => {
|
|
|
576
729
|
timeout: options.timeout,
|
|
577
730
|
killSignal: options.killSignal,
|
|
578
731
|
shell: options.shell,
|
|
732
|
+
maxBuffer: QMD_SPAWN_MAX_BUFFER,
|
|
579
733
|
});
|
|
580
734
|
return {
|
|
581
735
|
status: result.status,
|
|
@@ -1046,7 +1200,7 @@ function isExpectedQmdCallerFailure(args, stderr) {
|
|
|
1046
1200
|
return false;
|
|
1047
1201
|
}
|
|
1048
1202
|
/** Normalise a spawn result and raise the typed qmd failures. */
|
|
1049
|
-
function finishRunQmd(result, bin, args, attribution) {
|
|
1203
|
+
function finishRunQmd(result, bin, args, attribution, context = {}) {
|
|
1050
1204
|
const normalized = {
|
|
1051
1205
|
status: result.status,
|
|
1052
1206
|
stdout: result.stdout ?? '',
|
|
@@ -1096,7 +1250,12 @@ function finishRunQmd(result, bin, args, attribution) {
|
|
|
1096
1250
|
commandExists === false) {
|
|
1097
1251
|
throw new QmdBinaryMissingError(`Unable to execute qmd: its Node interpreter (${attribution.command}) could not be executed: ${normalized.error.message}`, diagnostics);
|
|
1098
1252
|
}
|
|
1099
|
-
// (c)
|
|
1253
|
+
// (c) OUTPUT BUFFER. spawnSync raises ENOBUFS when captured stdout/stderr
|
|
1254
|
+
// exceeds maxBuffer. That is not a missing qmd binary — the process ran.
|
|
1255
|
+
if (errnoCode === 'ENOBUFS') {
|
|
1256
|
+
throw new QmdBinaryMissingError(`qmd produced more output than hq index can buffer (${QMD_SPAWN_MAX_BUFFER} bytes, ENOBUFS). The search index is large; this is not a missing qmd binary.`, diagnostics);
|
|
1257
|
+
}
|
|
1258
|
+
// (d) RESIDUAL: an ENOENT the fix cannot attribute (a genuinely missing
|
|
1100
1259
|
// qmd, or a race where the directory/interpreter reappeared) or any other
|
|
1101
1260
|
// spawn errno (EACCES/EINVAL/…). Keep today's class and message byte-for-
|
|
1102
1261
|
// byte, and attach the bounded diagnostics so the next occurrence carries
|
|
@@ -1240,6 +1399,41 @@ function finishRunQmd(result, bin, args, attribution) {
|
|
|
1240
1399
|
if (isQmdModelDownloadError({ stderr: normalized.stderr, stdout: normalized.stdout })) {
|
|
1241
1400
|
throw new QmdModelDownloadError(`qmd ${subcommand} could not run: a model download did not finish (its partial file disappeared)`, args, normalized.status, normalized.stdout, normalized.stderr);
|
|
1242
1401
|
}
|
|
1402
|
+
// qmd died on a PERMISSION error from Node. Two shapes are the caller's
|
|
1403
|
+
// machine, not an hq defect, and get a typed carrier with a remedy:
|
|
1404
|
+
// - a read refused inside the HQ root, including qmd's own process.cwd()
|
|
1405
|
+
// (`uv_cwd`) in it: macOS privacy (TCC) on Documents/Desktop/iCloud, or
|
|
1406
|
+
// folder permissions (HQ-CLI-EJ, HQ-CLI-FV, HQ-CLI-BV, HQ-CLI-FF);
|
|
1407
|
+
// - qmd's settings folder cannot be created or written (HQ-CLI-GJ).
|
|
1408
|
+
// Any other permission failure keeps the generic, captured QmdExitError.
|
|
1409
|
+
// Reads qmd's own captured streams only, never the synthesized message.
|
|
1410
|
+
const permission = parseQmdPermissionFailure(normalized.stderr);
|
|
1411
|
+
if (permission) {
|
|
1412
|
+
const platform = context.platform ?? process.platform;
|
|
1413
|
+
const deniedPath = permission.syscall === 'uv_cwd' ? context.cwd : permission.path;
|
|
1414
|
+
// open alone does not distinguish a read from a write. Require a read
|
|
1415
|
+
// stack frame; ambiguous open failures remain reportable.
|
|
1416
|
+
const isRead = ['uv_cwd', 'scandir', 'stat', 'lstat'].includes(permission.syscall) ||
|
|
1417
|
+
(permission.syscall === 'open' && /^\s+at (?:async )?(?:Object\.)?readFile(?:Sync)?\b/m.test(normalized.stderr));
|
|
1418
|
+
if (isRead && deniedPath && context.cwd && isSameOrInside(deniedPath, context.cwd)) {
|
|
1419
|
+
throw markExpectedUserError(new QmdAccessDeniedError(qmdAccessDeniedMessage(deniedPath, permission.code, platform), args, normalized.status, normalized.stdout, normalized.stderr, deniedPath, permission.code, permission.syscall));
|
|
1420
|
+
}
|
|
1421
|
+
const configDir = qmdGlobalConfigDir(context.env ?? process.env);
|
|
1422
|
+
if (permission.path &&
|
|
1423
|
+
configDir &&
|
|
1424
|
+
// A recursive mkdir reports the first ANCESTOR it could not create, so an
|
|
1425
|
+
// ancestor counts only for mkdir.
|
|
1426
|
+
(isSameOrInside(permission.path, configDir) ||
|
|
1427
|
+
(permission.syscall === 'mkdir' && isSameOrInside(configDir, permission.path)))) {
|
|
1428
|
+
throw markExpectedUserError(new QmdConfigUnwritableError(qmdConfigUnwritableMessage(configDir, permission.path, permission.syscall, platform), args, normalized.status, normalized.stdout, normalized.stderr, configDir, permission.code));
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
if (QMD_STORE_CORRUPT.test(`${normalized.stderr}\n${normalized.stdout}`)) {
|
|
1432
|
+
const storeFile = qmdStoreFile(context.env ?? process.env, context.cwd);
|
|
1433
|
+
throw new QmdStoreCorruptError(`qmd ${subcommand} could not run: hq's local search index${storeFile ? ` (${storeFile})` : ''} is damaged ` +
|
|
1434
|
+
'(SQLite reports the database file is malformed). It only holds data rebuilt from your HQ files: ' +
|
|
1435
|
+
'delete that file, then run: hq index sync', args, normalized.status, normalized.stdout, normalized.stderr, storeFile);
|
|
1436
|
+
}
|
|
1243
1437
|
if (/(?:collection|qmd:\/\/).*(?:not found|does not exist|unknown)|(?:not found|does not exist).*collection/i.test(classifyText)) {
|
|
1244
1438
|
throw new QmdCollectionMissingError(message, args, normalized.status, normalized.stdout, normalized.stderr);
|
|
1245
1439
|
}
|
|
@@ -1247,14 +1441,18 @@ function finishRunQmd(result, bin, args, attribution) {
|
|
|
1247
1441
|
// owns (`Collection '<name>' already exists.`). Reconciliation treats this
|
|
1248
1442
|
// exact shape as already-satisfied (HQ-CLI-Q). The DIFFERENT path+pattern
|
|
1249
1443
|
// duplicate ("A collection already exists for this path and pattern:") names
|
|
1250
|
-
// another collection and carries no quoted-name form, so it never matches
|
|
1251
|
-
//
|
|
1252
|
-
// isTTY) and any surrounding ANSI sits outside this
|
|
1253
|
-
// match is robust either way.
|
|
1444
|
+
// another collection and carries no quoted-name form, so it never matches
|
|
1445
|
+
// here; it is typed QmdCollectionPathTakenError below. Colour is off under
|
|
1446
|
+
// capture (qmd gates on isTTY) and any surrounding ANSI sits outside this
|
|
1447
|
+
// substring, so the plain match is robust either way.
|
|
1254
1448
|
const alreadyExists = /Collection '([^']+)' already exists\./.exec(classifyText);
|
|
1255
1449
|
if (alreadyExists) {
|
|
1256
1450
|
throw new QmdCollectionExistsError(message, args, normalized.status, normalized.stdout, normalized.stderr, alreadyExists[1]);
|
|
1257
1451
|
}
|
|
1452
|
+
const pathTaken = /A collection already exists for this path and pattern:[\s\S]*?Name:\s*(.+?)\s+\(qmd:\/\//.exec(classifyText);
|
|
1453
|
+
if (pathTaken?.[1]) {
|
|
1454
|
+
throw new QmdCollectionPathTakenError(message, args, normalized.status, normalized.stdout, normalized.stderr, pathTaken[1]);
|
|
1455
|
+
}
|
|
1258
1456
|
const exitError = new QmdExitError(message, args, normalized.status, normalized.stdout, normalized.stderr);
|
|
1259
1457
|
if (isExpectedQmdCallerFailure(args, normalized.stderr)) {
|
|
1260
1458
|
throw markExpectedUserError(exitError);
|
|
@@ -1263,7 +1461,7 @@ function finishRunQmd(result, bin, args, attribution) {
|
|
|
1263
1461
|
}
|
|
1264
1462
|
function finishRunQmdWithDiagnostics(result, bin, args, options, attribution) {
|
|
1265
1463
|
try {
|
|
1266
|
-
return finishRunQmd(result, bin, args, attribution);
|
|
1464
|
+
return finishRunQmd(result, bin, args, attribution, { cwd: options.cwd, env: options.env, platform: options.platform });
|
|
1267
1465
|
}
|
|
1268
1466
|
catch (error) {
|
|
1269
1467
|
if (error instanceof QmdExitError) {
|
|
@@ -1329,10 +1527,29 @@ export function runQmd(args, options = {}) {
|
|
|
1329
1527
|
exists: options.exists,
|
|
1330
1528
|
});
|
|
1331
1529
|
}
|
|
1530
|
+
/**
|
|
1531
|
+
* List a folder for collection derivation. A path that is missing or is not a
|
|
1532
|
+
* folder (a file, or a symlink to one, named `knowledge` or `projects`) has
|
|
1533
|
+
* nothing to index, so it lists as empty instead of throwing ENOTDIR out of
|
|
1534
|
+
* the whole sync (HQ-CLI-ED). A refused read becomes the typed, expected
|
|
1535
|
+
* QmdAccessDeniedError with the platform remedy. Anything else still throws.
|
|
1536
|
+
*/
|
|
1537
|
+
function readCollectionDir(directory) {
|
|
1538
|
+
try {
|
|
1539
|
+
return fs.readdirSync(directory, { withFileTypes: true });
|
|
1540
|
+
}
|
|
1541
|
+
catch (error) {
|
|
1542
|
+
const code = error?.code;
|
|
1543
|
+
if (code === 'ENOENT' || code === 'ENOTDIR')
|
|
1544
|
+
return [];
|
|
1545
|
+
if (code === 'EPERM' || code === 'EACCES') {
|
|
1546
|
+
throw markExpectedUserError(new QmdAccessDeniedError(qmdAccessDeniedMessage(directory, code), [], null, '', '', directory, code, 'scandir'));
|
|
1547
|
+
}
|
|
1548
|
+
throw error;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1332
1551
|
function containsIndexedMarkdown(directory) {
|
|
1333
|
-
|
|
1334
|
-
return false;
|
|
1335
|
-
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
1552
|
+
for (const entry of readCollectionDir(directory)) {
|
|
1336
1553
|
const child = path.join(directory, entry.name);
|
|
1337
1554
|
if (entry.isDirectory() && containsIndexedMarkdown(child))
|
|
1338
1555
|
return true;
|
|
@@ -1342,9 +1559,7 @@ function containsIndexedMarkdown(directory) {
|
|
|
1342
1559
|
return false;
|
|
1343
1560
|
}
|
|
1344
1561
|
function containsProjectSource(directory) {
|
|
1345
|
-
|
|
1346
|
-
return false;
|
|
1347
|
-
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
1562
|
+
for (const entry of readCollectionDir(directory)) {
|
|
1348
1563
|
const child = path.join(directory, entry.name);
|
|
1349
1564
|
if (entry.isDirectory() && containsProjectSource(child))
|
|
1350
1565
|
return true;
|
|
@@ -1357,9 +1572,7 @@ function containsProjectSource(directory) {
|
|
|
1357
1572
|
export const ASSET_COLLECTION_MASK = '**/*.hqcloud';
|
|
1358
1573
|
const ASSET_SCAN_SKIP_DIRS = new Set(['.git', 'node_modules']);
|
|
1359
1574
|
function containsAssetPlaceholder(directory) {
|
|
1360
|
-
|
|
1361
|
-
return false;
|
|
1362
|
-
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
1575
|
+
for (const entry of readCollectionDir(directory)) {
|
|
1363
1576
|
const child = path.join(directory, entry.name);
|
|
1364
1577
|
if (entry.isDirectory()) {
|
|
1365
1578
|
if (!ASSET_SCAN_SKIP_DIRS.has(entry.name) && containsAssetPlaceholder(child))
|
|
@@ -1375,11 +1588,9 @@ function containsAssetPlaceholder(directory) {
|
|
|
1375
1588
|
export function deriveCollections(hqRoot) {
|
|
1376
1589
|
const root = path.resolve(hqRoot);
|
|
1377
1590
|
const companiesDir = path.join(root, 'companies');
|
|
1378
|
-
const companies =
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
.sort((a, b) => a.name.localeCompare(b.name))
|
|
1382
|
-
: [];
|
|
1591
|
+
const companies = readCollectionDir(companiesDir)
|
|
1592
|
+
.filter((entry) => entry.isDirectory())
|
|
1593
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
1383
1594
|
const collections = [];
|
|
1384
1595
|
for (const entry of companies) {
|
|
1385
1596
|
const knowledge = path.join(companiesDir, entry.name, 'knowledge');
|
|
@@ -1521,15 +1732,22 @@ function isPreviousHqManagedPath(hqRoot, collection, configuredPath) {
|
|
|
1521
1732
|
* NOT a failure. Reconciliation still issues the `context add`, whose qmd-side
|
|
1522
1733
|
* resyncConfig re-syncs YAML into SQLite and heals the divergence that provoked
|
|
1523
1734
|
* the retry, then continues with later collections; such a pre-existing
|
|
1524
|
-
* collection is excluded from the returned list.
|
|
1525
|
-
*
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
1735
|
+
* collection is excluded from the returned list.
|
|
1736
|
+
*
|
|
1737
|
+
* An unmanaged path+pattern duplicate is not fatal: the files are indexed under
|
|
1738
|
+
* that name, but scoped search misses them. Print a notice, skip this add and
|
|
1739
|
+
* its `context add`, and continue. It used to abort the whole sync, so
|
|
1740
|
+
* `qmd update` never ran again on that machine (HQ-CLI-GJ).
|
|
1741
|
+
*
|
|
1742
|
+
* Every other qmd failure still propagates: a same-name duplicate that named a
|
|
1743
|
+
* different collection, a missing collection, a `context add` failure, a
|
|
1744
|
+
* missing/unbuilt qmd binary. HQ-CLI-Q (Sentry 7670823899).
|
|
1528
1745
|
*/
|
|
1529
1746
|
export function reconcileCollections(hqRoot, options = {}) {
|
|
1530
1747
|
const runOptions = { bin: options.bin, runner: options.runner, cwd: hqRoot };
|
|
1531
1748
|
const registered = listRegisteredCollections(hqRoot, runOptions);
|
|
1532
1749
|
const expected = deriveCollections(hqRoot);
|
|
1750
|
+
const managedNames = new Set(expected.map((collection) => collection.name));
|
|
1533
1751
|
const repairPathDrift = options.repairPathDrift ?? false;
|
|
1534
1752
|
const configured = repairPathDrift ? configuredCollections(hqRoot) : new Map();
|
|
1535
1753
|
const stale = repairPathDrift
|
|
@@ -1555,6 +1773,31 @@ export function reconcileCollections(hqRoot, options = {}) {
|
|
|
1555
1773
|
created.push(collection);
|
|
1556
1774
|
}
|
|
1557
1775
|
catch (error) {
|
|
1776
|
+
if (error instanceof QmdCollectionPathTakenError) {
|
|
1777
|
+
// Reserve the company-slug namespace, including -projects/-assets and
|
|
1778
|
+
// personal-knowledge, even when that company's folders are absent here.
|
|
1779
|
+
// A collision can otherwise expose one company's files under another.
|
|
1780
|
+
if (managedNames.has(error.existingName) || isSafeQmdCollectionName(error.existingName))
|
|
1781
|
+
throw error;
|
|
1782
|
+
// Shown once per folder and covering collection, so background syncs do
|
|
1783
|
+
// not repeat it on every run.
|
|
1784
|
+
const noticesFile = options.noticesFile === undefined ? defaultNoticesFile(hqRoot) : options.noticesFile;
|
|
1785
|
+
const noticeKey = `${collection.name}\u0000${error.existingName}\u0000${collection.path}`;
|
|
1786
|
+
const seenNotices = readSeenNotices(noticesFile);
|
|
1787
|
+
if (!seenNotices.has(noticeKey)) {
|
|
1788
|
+
const writeStderr = options.writeStderr ?? ((text) => process.stderr.write(text));
|
|
1789
|
+
const removalGuidance = isSafeQmdCollectionName(error.existingName)
|
|
1790
|
+
? `run: qmd collection remove ${error.existingName}, then: hq index sync. `
|
|
1791
|
+
: `remove the qmd collection named ${JSON.stringify(error.existingName)} using qmd, then synchronize the HQ index again. `;
|
|
1792
|
+
writeStderr(`hq: ${collection.path} is already indexed by the qmd collection '${error.existingName}', ` +
|
|
1793
|
+
`so hq did not add it again as '${collection.name}'. Scoped search misses this folder until the other collection is removed. ` +
|
|
1794
|
+
`To use hq's name instead, ${removalGuidance}` +
|
|
1795
|
+
'This notice is shown once.\n');
|
|
1796
|
+
seenNotices.add(noticeKey);
|
|
1797
|
+
writeSeenNotices(noticesFile, seenNotices);
|
|
1798
|
+
}
|
|
1799
|
+
continue;
|
|
1800
|
+
}
|
|
1558
1801
|
// Only the exact same-name duplicate for THIS collection is already
|
|
1559
1802
|
// satisfied. Anything else — including a same-name duplicate that names a
|
|
1560
1803
|
// different collection — stays fatal.
|
|
@@ -1568,6 +1811,37 @@ export function reconcileCollections(hqRoot, options = {}) {
|
|
|
1568
1811
|
}
|
|
1569
1812
|
return created;
|
|
1570
1813
|
}
|
|
1814
|
+
function isSafeQmdCollectionName(name) {
|
|
1815
|
+
return /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name);
|
|
1816
|
+
}
|
|
1817
|
+
function defaultNoticesFile(hqRoot) {
|
|
1818
|
+
return path.join(hqRoot, '.hq', 'search-index-notices.json');
|
|
1819
|
+
}
|
|
1820
|
+
/** Read the set of one-time reconcile notices already shown. Best-effort. */
|
|
1821
|
+
function readSeenNotices(file) {
|
|
1822
|
+
if (!file)
|
|
1823
|
+
return new Set();
|
|
1824
|
+
try {
|
|
1825
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
1826
|
+
const shown = isRecord(parsed) && Array.isArray(parsed.shown) ? parsed.shown : [];
|
|
1827
|
+
return new Set(shown.filter((value) => typeof value === 'string'));
|
|
1828
|
+
}
|
|
1829
|
+
catch {
|
|
1830
|
+
return new Set();
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
/** Record shown notices. Best-effort: a read-only `.hq/` only means the notice repeats. */
|
|
1834
|
+
function writeSeenNotices(file, shown) {
|
|
1835
|
+
if (!file)
|
|
1836
|
+
return;
|
|
1837
|
+
try {
|
|
1838
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
1839
|
+
fs.writeFileSync(file, `${JSON.stringify({ shown: [...shown].sort() }, null, 2)}\n`);
|
|
1840
|
+
}
|
|
1841
|
+
catch {
|
|
1842
|
+
/* the notice repeats next run; indexing is unaffected */
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1571
1845
|
export function listRegisteredCollections(hqRoot, options = {}) {
|
|
1572
1846
|
const result = runQmd(['collection', 'list'], { ...options, cwd: options.cwd ?? hqRoot });
|
|
1573
1847
|
return new Set([...result.stdout.matchAll(/qmd:\/\/([^/\s]+)/g)].map((match) => match[1]));
|
|
@@ -98,15 +98,26 @@ export declare function resolveIndexMaxDocBytes(opts?: {
|
|
|
98
98
|
readFile?: (p: string) => string;
|
|
99
99
|
existsFile?: (p: string) => boolean;
|
|
100
100
|
}): number;
|
|
101
|
+
/**
|
|
102
|
+
* How a collection mask maps onto a size-cap walk.
|
|
103
|
+
*
|
|
104
|
+
* `prefix` is a relative directory (no glob syntax). `recursive` is true for
|
|
105
|
+
* `**` and false for a single-directory `*`. Unrecognised masks return `null`
|
|
106
|
+
* so the walk is skipped: treating them as "every file, unbounded depth"
|
|
107
|
+
* walked home-rooted collections and wrote hundreds of thousands of ignores.
|
|
108
|
+
*/
|
|
109
|
+
export type CollectionMaskPlan = {
|
|
110
|
+
prefix: string;
|
|
111
|
+
recursive: boolean;
|
|
112
|
+
extensions: Set<string>;
|
|
113
|
+
};
|
|
114
|
+
export declare function parseCollectionMask(mask: string): CollectionMaskPlan | null;
|
|
101
115
|
/**
|
|
102
116
|
* Extensions a qmd mask selects, lowercased and without the dot.
|
|
103
117
|
*
|
|
104
|
-
* HQ registers
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* `null`, meaning "match every file" — the cap then applies to the whole
|
|
108
|
-
* collection, which is the safe direction: we may ignore a file qmd would not
|
|
109
|
-
* have indexed (a no-op) rather than miss one it would.
|
|
118
|
+
* HQ registers recursive (`**\/*.md`, `**\/*.{md,json}`) and shallow (`*.md`,
|
|
119
|
+
* `docs/*.md`) masks. An unrecognised mask returns `null`; callers must skip
|
|
120
|
+
* the size walk rather than treat that as "every file".
|
|
110
121
|
*/
|
|
111
122
|
export declare function maskExtensions(mask: string): Set<string> | null;
|
|
112
123
|
/** Injected filesystem seam, so the walk is testable without a real tree. */
|
|
@@ -174,25 +174,42 @@ function parseNonNegativeInt(value) {
|
|
|
174
174
|
const n = Number(trimmed);
|
|
175
175
|
return Number.isSafeInteger(n) ? n : null;
|
|
176
176
|
}
|
|
177
|
+
const MASK_PREFIX_HAS_GLOB = /[\\*?[\]{}()!+@|]/;
|
|
178
|
+
function extensionsFromMaskGroups(brace, single) {
|
|
179
|
+
if (brace !== undefined) {
|
|
180
|
+
const exts = new Set(brace.split(",").map((ext) => ext.trim().toLowerCase()).filter(Boolean));
|
|
181
|
+
return exts.size > 0 ? exts : null;
|
|
182
|
+
}
|
|
183
|
+
if (single)
|
|
184
|
+
return new Set([single.toLowerCase()]);
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
export function parseCollectionMask(mask) {
|
|
188
|
+
const trimmed = mask.trim();
|
|
189
|
+
const recursive = /^(?:(.+?)\/)?\*\*\/\*\.(?:\{([^}]+)\}|([A-Za-z0-9]+))$/.exec(trimmed);
|
|
190
|
+
const shallow = recursive
|
|
191
|
+
? null
|
|
192
|
+
: /^(?:(.+?)\/)?\*\.(?:\{([^}]+)\}|([A-Za-z0-9]+))$/.exec(trimmed);
|
|
193
|
+
const hit = recursive ?? shallow;
|
|
194
|
+
if (!hit)
|
|
195
|
+
return null;
|
|
196
|
+
const prefix = hit[1] ?? "";
|
|
197
|
+
if (prefix && MASK_PREFIX_HAS_GLOB.test(prefix))
|
|
198
|
+
return null;
|
|
199
|
+
const extensions = extensionsFromMaskGroups(hit[2], hit[3]);
|
|
200
|
+
if (!extensions)
|
|
201
|
+
return null;
|
|
202
|
+
return { prefix, recursive: recursive !== null, extensions };
|
|
203
|
+
}
|
|
177
204
|
/**
|
|
178
205
|
* Extensions a qmd mask selects, lowercased and without the dot.
|
|
179
206
|
*
|
|
180
|
-
* HQ registers
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* `null`, meaning "match every file" — the cap then applies to the whole
|
|
184
|
-
* collection, which is the safe direction: we may ignore a file qmd would not
|
|
185
|
-
* have indexed (a no-op) rather than miss one it would.
|
|
207
|
+
* HQ registers recursive (`**\/*.md`, `**\/*.{md,json}`) and shallow (`*.md`,
|
|
208
|
+
* `docs/*.md`) masks. An unrecognised mask returns `null`; callers must skip
|
|
209
|
+
* the size walk rather than treat that as "every file".
|
|
186
210
|
*/
|
|
187
211
|
export function maskExtensions(mask) {
|
|
188
|
-
|
|
189
|
-
if (braced) {
|
|
190
|
-
return new Set(braced[1].split(",").map((ext) => ext.trim().toLowerCase()).filter(Boolean));
|
|
191
|
-
}
|
|
192
|
-
const single = /^\*\*\/\*\.([A-Za-z0-9]+)$/.exec(mask);
|
|
193
|
-
if (single)
|
|
194
|
-
return new Set([single[1].toLowerCase()]);
|
|
195
|
-
return null;
|
|
212
|
+
return parseCollectionMask(mask)?.extensions ?? null;
|
|
196
213
|
}
|
|
197
214
|
const defaultScanIo = {
|
|
198
215
|
readdirSync: (directory) => fs.readdirSync(directory, { withFileTypes: true }),
|
|
@@ -238,11 +255,19 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
|
|
|
238
255
|
const evaluated = new Set();
|
|
239
256
|
if (maxBytes <= 0)
|
|
240
257
|
return { oversized: [], evaluated, complete: true };
|
|
241
|
-
const
|
|
258
|
+
const plan = parseCollectionMask(mask);
|
|
259
|
+
// Unrecognised mask: do not walk. Matching "everything" is what filled
|
|
260
|
+
// `*.md` collections rooted at $HOME with hundreds of thousands of ignores.
|
|
261
|
+
if (!plan)
|
|
262
|
+
return { oversized: [], evaluated, complete: true };
|
|
242
263
|
const pruned = new Set(prunePrefixes);
|
|
243
264
|
const found = [];
|
|
244
265
|
let complete = true;
|
|
245
|
-
const
|
|
266
|
+
const startRelative = plan.prefix;
|
|
267
|
+
const startDirectory = plan.prefix
|
|
268
|
+
? path.join(collectionPath, ...plan.prefix.split("/"))
|
|
269
|
+
: collectionPath;
|
|
270
|
+
const walk = (directory, relative, descend) => {
|
|
246
271
|
let entries;
|
|
247
272
|
try {
|
|
248
273
|
entries = io.readdirSync(directory);
|
|
@@ -256,20 +281,20 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
|
|
|
256
281
|
continue;
|
|
257
282
|
const childRelative = relative ? `${relative}/${entry.name}` : entry.name;
|
|
258
283
|
if (entry.isDirectory()) {
|
|
284
|
+
if (!descend)
|
|
285
|
+
continue;
|
|
259
286
|
if (EXCLUDED_DIRECTORIES.has(entry.name))
|
|
260
287
|
continue;
|
|
261
288
|
if (pruned.has(childRelative))
|
|
262
289
|
continue;
|
|
263
|
-
walk(path.join(directory, entry.name), childRelative);
|
|
290
|
+
walk(path.join(directory, entry.name), childRelative, true);
|
|
264
291
|
continue;
|
|
265
292
|
}
|
|
266
293
|
if (!entry.isFile())
|
|
267
294
|
continue;
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
295
|
+
const ext = path.extname(entry.name).slice(1).toLowerCase();
|
|
296
|
+
if (!plan.extensions.has(ext))
|
|
297
|
+
continue;
|
|
273
298
|
const literal = escapeGlobLiteral(childRelative);
|
|
274
299
|
try {
|
|
275
300
|
const { size } = io.statSync(path.join(directory, entry.name));
|
|
@@ -282,7 +307,7 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
|
|
|
282
307
|
}
|
|
283
308
|
}
|
|
284
309
|
};
|
|
285
|
-
walk(
|
|
310
|
+
walk(startDirectory, startRelative, plan.recursive);
|
|
286
311
|
return {
|
|
287
312
|
oversized: found.sort((left, right) => left.localeCompare(right)),
|
|
288
313
|
evaluated,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Every Codex feature that gives the model a tool or reaches outside the turn. */
|
|
2
|
+
export declare const CODEX_LOCKDOWN_DISABLED_FEATURES: readonly string[];
|
|
3
|
+
/**
|
|
4
|
+
* Config overrides (`-c`) that are not features: web search off (the value is
|
|
5
|
+
* checked; a wrong one fails config load), and codex's bundled skills off.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CODEX_LOCKDOWN_CONFIG: readonly string[];
|
|
8
|
+
/** `--disable <feature>` for every locked feature, then the `-c` overrides. */
|
|
9
|
+
export declare function codexLockdownFlags(): string[];
|
|
10
|
+
/**
|
|
11
|
+
* The only variables a locked Codex turn has. HOME is the turn's own empty
|
|
12
|
+
* temp dir; CODEX_HOME is the bot's own Codex login dir (./codex-login.ts),
|
|
13
|
+
* used in place and never copied.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CODEX_LOCKDOWN_ENV_ALLOWLIST: readonly string[];
|
|
16
|
+
/** The environment of a locked Codex turn: PATH and LANG from `base`, HOME and CODEX_HOME from `dirs`. */
|
|
17
|
+
export declare function codexLockdownEnv(base: NodeJS.ProcessEnv, dirs: {
|
|
18
|
+
home: string;
|
|
19
|
+
codexHome: string;
|
|
20
|
+
}): NodeJS.ProcessEnv;
|
|
21
|
+
/** The account's home from the password database, which $HOME (and so os.homedir()) can hide. Undefined when it cannot be read. */
|
|
22
|
+
export declare function passwdHome(): string | undefined;
|
|
23
|
+
/** Every home a grant must stay out of: os.homedir(), $HOME and the passwd home, without duplicates. */
|
|
24
|
+
export declare function lockdownHomes(env?: NodeJS.ProcessEnv, passwd?: string | undefined): string[];
|
|
25
|
+
/** First line of HQ's provider wrapper scripts (src/lib/install/provider-wrappers.ts). */
|
|
26
|
+
export declare const HQ_PROVIDER_WRAPPER_MARKER = "# hq-anywhere provider sign-in wrapper";
|
|
27
|
+
/** True when the file is one of HQ's provider wrapper scripts (it names the marker in its first 256 bytes). */
|
|
28
|
+
export declare function isHqProviderWrapper(file: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The real codex executable, as a realpath. A name is looked up on PATH and
|
|
31
|
+
* every entry that is HQ's provider wrapper, or resolves under ~/.hq, is
|
|
32
|
+
* walked past. A path is used as given, and refused when it is such a
|
|
33
|
+
* wrapper. Null when no real codex is found.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveRealCodexBinary(bin: string, envPath: string | undefined, homes: readonly string[]): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Why a read grant is unsafe, or null when it is safe. Unsafe: the filesystem
|
|
38
|
+
* root; a home or any parent of one; ~/.hq, anything under it or any parent
|
|
39
|
+
* of it; a home's dot dir (~/.codex, ~/.claude, ...) or anything under one,
|
|
40
|
+
* except codex's own standalone release tree (~/.codex/packages/), which
|
|
41
|
+
* holds no login; any other folder inside a home that is not an npm
|
|
42
|
+
* `@openai/codex` package root (its package.json names it), so a codex
|
|
43
|
+
* dropped into ~/Downloads never grants ~/Downloads; the codex login dir,
|
|
44
|
+
* anything inside it, or any parent of it; anything that overlaps the HQ
|
|
45
|
+
* root.
|
|
46
|
+
*/
|
|
47
|
+
export declare function unsafeCodexGrantReason(grant: string, input: {
|
|
48
|
+
homes: readonly string[];
|
|
49
|
+
hqRoot: string;
|
|
50
|
+
loginDir?: string;
|
|
51
|
+
}): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* The codex binary's own install dir from its realpath: the package root for
|
|
54
|
+
* an npm install (`.../@openai/codex` for `.../@openai/codex/bin/codex.js`,
|
|
55
|
+
* which holds the native binary under node_modules), else the binary's own
|
|
56
|
+
* folder, or that folder's parent when it is named `bin`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function codexInstallDir(realBin: string): string;
|
|
59
|
+
export type CodexLockdownTarget = {
|
|
60
|
+
ok: true;
|
|
61
|
+
binary: string;
|
|
62
|
+
installDir: string;
|
|
63
|
+
} | {
|
|
64
|
+
ok: false;
|
|
65
|
+
error: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Resolve the real codex and its install dir, failing closed: no real codex,
|
|
69
|
+
* or an install dir that is not a safe grant, is an error and no turn runs.
|
|
70
|
+
*/
|
|
71
|
+
export declare function resolveCodexLockdownTarget(bin: string, input: {
|
|
72
|
+
envPath: string | undefined;
|
|
73
|
+
homes: readonly string[];
|
|
74
|
+
hqRoot: string;
|
|
75
|
+
loginDir?: string;
|
|
76
|
+
}): CodexLockdownTarget;
|
|
77
|
+
/** TOML inline table for a locked turn's permission profile: read the platform minimum, the install dir and the empty work dir; write nothing. */
|
|
78
|
+
export declare function codexLockdownFilesystem(installDir: string, workDir: string): string;
|
|
79
|
+
//# sourceMappingURL=codex-lockdown.d.ts.map
|