@hasna/hooks 0.12.23 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/hooks/scratch-lifecycle.js +5 -5
- package/bin/hooks/stop-review.js +2 -2
- package/bin/hooks-mcp.js +1246 -1134
- package/bin/index.js +2160 -1836
- package/bin/native-safety-entry.js +37 -37
- package/bin/native-safety-worker.cjs +37 -37
- package/bin/serve.js +115 -111
- package/dist/index.js +1633 -1453
- package/dist/lib/installer.d.ts +44 -5
- package/dist/lib/manifest.d.ts +21 -0
- package/dist/lib/native-target.d.ts +11 -2
- package/dist/lib/registry.d.ts +12 -0
- package/dist/lib/target-adapters.d.ts +151 -0
- package/dist/lib/targets.d.ts +99 -0
- package/dist/native-readiness.js +11 -11
- package/dist/native-safety.js +9 -9
- package/dist/opencode-stop-plugin.js +5 -5
- package/dist/sdk/index.js +7 -7
- package/dist/storage.js +34 -34
- package/dist/sumi-stop-plugin.js +7 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -166,7 +166,7 @@ function up(db) {
|
|
|
166
166
|
db.exec(idx);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
var
|
|
169
|
+
var init__001_initial = __esm(() => {
|
|
170
170
|
init_schema();
|
|
171
171
|
});
|
|
172
172
|
|
|
@@ -195,7 +195,7 @@ function up2(db) {
|
|
|
195
195
|
throw err;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
-
var
|
|
198
|
+
var init__002_session_events = __esm(() => {
|
|
199
199
|
init_schema();
|
|
200
200
|
});
|
|
201
201
|
|
|
@@ -224,7 +224,7 @@ function up3(db) {
|
|
|
224
224
|
throw err;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
var
|
|
227
|
+
var init__003_user_prompt_submit_event = __esm(() => {
|
|
228
228
|
init_schema();
|
|
229
229
|
});
|
|
230
230
|
|
|
@@ -248,7 +248,7 @@ var CREATE_HOOKS_TABLE = `
|
|
|
248
248
|
last_verified_at TEXT
|
|
249
249
|
)
|
|
250
250
|
`, CREATE_HOOKS_INDEXES;
|
|
251
|
-
var
|
|
251
|
+
var init__004_hooks_table = __esm(() => {
|
|
252
252
|
CREATE_HOOKS_INDEXES = [
|
|
253
253
|
`CREATE INDEX IF NOT EXISTS idx_hooks_name ON hooks (name)`
|
|
254
254
|
];
|
|
@@ -279,7 +279,7 @@ function up5(db) {
|
|
|
279
279
|
throw err;
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
-
var
|
|
282
|
+
var init__005_subagent_start_event = __esm(() => {
|
|
283
283
|
init_schema();
|
|
284
284
|
});
|
|
285
285
|
|
|
@@ -311,11 +311,11 @@ function runMigrations(db) {
|
|
|
311
311
|
}
|
|
312
312
|
var MIGRATIONS;
|
|
313
313
|
var init_migrations = __esm(() => {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
314
|
+
init__001_initial();
|
|
315
|
+
init__002_session_events();
|
|
316
|
+
init__003_user_prompt_submit_event();
|
|
317
|
+
init__004_hooks_table();
|
|
318
|
+
init__005_subagent_start_event();
|
|
319
319
|
MIGRATIONS = [
|
|
320
320
|
{ version: "001_initial", up },
|
|
321
321
|
{ version: "002_session_events", up: up2 },
|
|
@@ -4424,113 +4424,113 @@ var init_types = __esm(() => {
|
|
|
4424
4424
|
// ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
|
|
4425
4425
|
var exports_external = {};
|
|
4426
4426
|
__export(exports_external, {
|
|
4427
|
-
|
|
4428
|
-
util: () => util,
|
|
4429
|
-
unknown: () => unknownType,
|
|
4430
|
-
union: () => unionType,
|
|
4431
|
-
undefined: () => undefinedType,
|
|
4432
|
-
tuple: () => tupleType,
|
|
4433
|
-
transformer: () => effectsType,
|
|
4434
|
-
symbol: () => symbolType,
|
|
4435
|
-
string: () => stringType,
|
|
4436
|
-
strictObject: () => strictObjectType,
|
|
4437
|
-
setErrorMap: () => setErrorMap,
|
|
4438
|
-
set: () => setType,
|
|
4439
|
-
record: () => recordType,
|
|
4440
|
-
quotelessJson: () => quotelessJson,
|
|
4441
|
-
promise: () => promiseType,
|
|
4442
|
-
preprocess: () => preprocessType,
|
|
4443
|
-
pipeline: () => pipelineType,
|
|
4444
|
-
ostring: () => ostring,
|
|
4445
|
-
optional: () => optionalType,
|
|
4446
|
-
onumber: () => onumber,
|
|
4447
|
-
oboolean: () => oboolean,
|
|
4448
|
-
objectUtil: () => objectUtil,
|
|
4449
|
-
object: () => objectType,
|
|
4450
|
-
number: () => numberType,
|
|
4451
|
-
nullable: () => nullableType,
|
|
4452
|
-
null: () => nullType,
|
|
4453
|
-
never: () => neverType,
|
|
4454
|
-
nativeEnum: () => nativeEnumType,
|
|
4455
|
-
nan: () => nanType,
|
|
4456
|
-
map: () => mapType,
|
|
4457
|
-
makeIssue: () => makeIssue,
|
|
4458
|
-
literal: () => literalType,
|
|
4459
|
-
lazy: () => lazyType,
|
|
4460
|
-
late: () => late,
|
|
4461
|
-
isValid: () => isValid,
|
|
4462
|
-
isDirty: () => isDirty,
|
|
4463
|
-
isAsync: () => isAsync,
|
|
4464
|
-
isAborted: () => isAborted,
|
|
4465
|
-
intersection: () => intersectionType,
|
|
4466
|
-
instanceof: () => instanceOfType,
|
|
4467
|
-
getParsedType: () => getParsedType,
|
|
4468
|
-
getErrorMap: () => getErrorMap,
|
|
4469
|
-
function: () => functionType,
|
|
4470
|
-
enum: () => enumType,
|
|
4471
|
-
effect: () => effectsType,
|
|
4472
|
-
discriminatedUnion: () => discriminatedUnionType,
|
|
4473
|
-
defaultErrorMap: () => en_default,
|
|
4474
|
-
datetimeRegex: () => datetimeRegex,
|
|
4475
|
-
date: () => dateType,
|
|
4476
|
-
custom: () => custom,
|
|
4477
|
-
coerce: () => coerce,
|
|
4478
|
-
boolean: () => booleanType,
|
|
4479
|
-
bigint: () => bigIntType,
|
|
4480
|
-
array: () => arrayType,
|
|
4481
|
-
any: () => anyType,
|
|
4482
|
-
addIssueToContext: () => addIssueToContext,
|
|
4483
|
-
ZodVoid: () => ZodVoid,
|
|
4484
|
-
ZodUnknown: () => ZodUnknown,
|
|
4485
|
-
ZodUnion: () => ZodUnion,
|
|
4486
|
-
ZodUndefined: () => ZodUndefined,
|
|
4487
|
-
ZodType: () => ZodType,
|
|
4488
|
-
ZodTuple: () => ZodTuple,
|
|
4489
|
-
ZodTransformer: () => ZodEffects,
|
|
4490
|
-
ZodSymbol: () => ZodSymbol,
|
|
4491
|
-
ZodString: () => ZodString,
|
|
4492
|
-
ZodSet: () => ZodSet,
|
|
4493
|
-
ZodSchema: () => ZodType,
|
|
4494
|
-
ZodRecord: () => ZodRecord,
|
|
4495
|
-
ZodReadonly: () => ZodReadonly,
|
|
4496
|
-
ZodPromise: () => ZodPromise,
|
|
4497
|
-
ZodPipeline: () => ZodPipeline,
|
|
4498
|
-
ZodParsedType: () => ZodParsedType,
|
|
4499
|
-
ZodOptional: () => ZodOptional,
|
|
4500
|
-
ZodObject: () => ZodObject,
|
|
4501
|
-
ZodNumber: () => ZodNumber,
|
|
4502
|
-
ZodNullable: () => ZodNullable,
|
|
4503
|
-
ZodNull: () => ZodNull,
|
|
4504
|
-
ZodNever: () => ZodNever,
|
|
4505
|
-
ZodNativeEnum: () => ZodNativeEnum,
|
|
4506
|
-
ZodNaN: () => ZodNaN,
|
|
4507
|
-
ZodMap: () => ZodMap,
|
|
4508
|
-
ZodLiteral: () => ZodLiteral,
|
|
4509
|
-
ZodLazy: () => ZodLazy,
|
|
4510
|
-
ZodIssueCode: () => ZodIssueCode,
|
|
4511
|
-
ZodIntersection: () => ZodIntersection,
|
|
4512
|
-
ZodFunction: () => ZodFunction,
|
|
4513
|
-
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
4514
|
-
ZodError: () => ZodError,
|
|
4515
|
-
ZodEnum: () => ZodEnum,
|
|
4516
|
-
ZodEffects: () => ZodEffects,
|
|
4517
|
-
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
4518
|
-
ZodDefault: () => ZodDefault,
|
|
4519
|
-
ZodDate: () => ZodDate,
|
|
4520
|
-
ZodCatch: () => ZodCatch,
|
|
4521
|
-
ZodBranded: () => ZodBranded,
|
|
4522
|
-
ZodBoolean: () => ZodBoolean,
|
|
4523
|
-
ZodBigInt: () => ZodBigInt,
|
|
4524
|
-
ZodArray: () => ZodArray,
|
|
4525
|
-
ZodAny: () => ZodAny,
|
|
4526
|
-
Schema: () => ZodType,
|
|
4527
|
-
ParseStatus: () => ParseStatus,
|
|
4528
|
-
OK: () => OK,
|
|
4529
|
-
NEVER: () => NEVER,
|
|
4530
|
-
INVALID: () => INVALID,
|
|
4531
|
-
EMPTY_PATH: () => EMPTY_PATH,
|
|
4427
|
+
BRAND: () => BRAND,
|
|
4532
4428
|
DIRTY: () => DIRTY,
|
|
4533
|
-
|
|
4429
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
4430
|
+
INVALID: () => INVALID,
|
|
4431
|
+
NEVER: () => NEVER,
|
|
4432
|
+
OK: () => OK,
|
|
4433
|
+
ParseStatus: () => ParseStatus,
|
|
4434
|
+
Schema: () => ZodType,
|
|
4435
|
+
ZodAny: () => ZodAny,
|
|
4436
|
+
ZodArray: () => ZodArray,
|
|
4437
|
+
ZodBigInt: () => ZodBigInt,
|
|
4438
|
+
ZodBoolean: () => ZodBoolean,
|
|
4439
|
+
ZodBranded: () => ZodBranded,
|
|
4440
|
+
ZodCatch: () => ZodCatch,
|
|
4441
|
+
ZodDate: () => ZodDate,
|
|
4442
|
+
ZodDefault: () => ZodDefault,
|
|
4443
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
4444
|
+
ZodEffects: () => ZodEffects,
|
|
4445
|
+
ZodEnum: () => ZodEnum,
|
|
4446
|
+
ZodError: () => ZodError,
|
|
4447
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
4448
|
+
ZodFunction: () => ZodFunction,
|
|
4449
|
+
ZodIntersection: () => ZodIntersection,
|
|
4450
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
4451
|
+
ZodLazy: () => ZodLazy,
|
|
4452
|
+
ZodLiteral: () => ZodLiteral,
|
|
4453
|
+
ZodMap: () => ZodMap,
|
|
4454
|
+
ZodNaN: () => ZodNaN,
|
|
4455
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
4456
|
+
ZodNever: () => ZodNever,
|
|
4457
|
+
ZodNull: () => ZodNull,
|
|
4458
|
+
ZodNullable: () => ZodNullable,
|
|
4459
|
+
ZodNumber: () => ZodNumber,
|
|
4460
|
+
ZodObject: () => ZodObject,
|
|
4461
|
+
ZodOptional: () => ZodOptional,
|
|
4462
|
+
ZodParsedType: () => ZodParsedType,
|
|
4463
|
+
ZodPipeline: () => ZodPipeline,
|
|
4464
|
+
ZodPromise: () => ZodPromise,
|
|
4465
|
+
ZodReadonly: () => ZodReadonly,
|
|
4466
|
+
ZodRecord: () => ZodRecord,
|
|
4467
|
+
ZodSchema: () => ZodType,
|
|
4468
|
+
ZodSet: () => ZodSet,
|
|
4469
|
+
ZodString: () => ZodString,
|
|
4470
|
+
ZodSymbol: () => ZodSymbol,
|
|
4471
|
+
ZodTransformer: () => ZodEffects,
|
|
4472
|
+
ZodTuple: () => ZodTuple,
|
|
4473
|
+
ZodType: () => ZodType,
|
|
4474
|
+
ZodUndefined: () => ZodUndefined,
|
|
4475
|
+
ZodUnion: () => ZodUnion,
|
|
4476
|
+
ZodUnknown: () => ZodUnknown,
|
|
4477
|
+
ZodVoid: () => ZodVoid,
|
|
4478
|
+
addIssueToContext: () => addIssueToContext,
|
|
4479
|
+
any: () => anyType,
|
|
4480
|
+
array: () => arrayType,
|
|
4481
|
+
bigint: () => bigIntType,
|
|
4482
|
+
boolean: () => booleanType,
|
|
4483
|
+
coerce: () => coerce,
|
|
4484
|
+
custom: () => custom,
|
|
4485
|
+
date: () => dateType,
|
|
4486
|
+
datetimeRegex: () => datetimeRegex,
|
|
4487
|
+
defaultErrorMap: () => en_default,
|
|
4488
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
4489
|
+
effect: () => effectsType,
|
|
4490
|
+
enum: () => enumType,
|
|
4491
|
+
function: () => functionType,
|
|
4492
|
+
getErrorMap: () => getErrorMap,
|
|
4493
|
+
getParsedType: () => getParsedType,
|
|
4494
|
+
instanceof: () => instanceOfType,
|
|
4495
|
+
intersection: () => intersectionType,
|
|
4496
|
+
isAborted: () => isAborted,
|
|
4497
|
+
isAsync: () => isAsync,
|
|
4498
|
+
isDirty: () => isDirty,
|
|
4499
|
+
isValid: () => isValid,
|
|
4500
|
+
late: () => late,
|
|
4501
|
+
lazy: () => lazyType,
|
|
4502
|
+
literal: () => literalType,
|
|
4503
|
+
makeIssue: () => makeIssue,
|
|
4504
|
+
map: () => mapType,
|
|
4505
|
+
nan: () => nanType,
|
|
4506
|
+
nativeEnum: () => nativeEnumType,
|
|
4507
|
+
never: () => neverType,
|
|
4508
|
+
null: () => nullType,
|
|
4509
|
+
nullable: () => nullableType,
|
|
4510
|
+
number: () => numberType,
|
|
4511
|
+
object: () => objectType,
|
|
4512
|
+
objectUtil: () => objectUtil,
|
|
4513
|
+
oboolean: () => oboolean,
|
|
4514
|
+
onumber: () => onumber,
|
|
4515
|
+
optional: () => optionalType,
|
|
4516
|
+
ostring: () => ostring,
|
|
4517
|
+
pipeline: () => pipelineType,
|
|
4518
|
+
preprocess: () => preprocessType,
|
|
4519
|
+
promise: () => promiseType,
|
|
4520
|
+
quotelessJson: () => quotelessJson,
|
|
4521
|
+
record: () => recordType,
|
|
4522
|
+
set: () => setType,
|
|
4523
|
+
setErrorMap: () => setErrorMap,
|
|
4524
|
+
strictObject: () => strictObjectType,
|
|
4525
|
+
string: () => stringType,
|
|
4526
|
+
symbol: () => symbolType,
|
|
4527
|
+
transformer: () => effectsType,
|
|
4528
|
+
tuple: () => tupleType,
|
|
4529
|
+
undefined: () => undefinedType,
|
|
4530
|
+
union: () => unionType,
|
|
4531
|
+
unknown: () => unknownType,
|
|
4532
|
+
util: () => util,
|
|
4533
|
+
void: () => voidType
|
|
4534
4534
|
});
|
|
4535
4535
|
var init_external = __esm(() => {
|
|
4536
4536
|
init_errors();
|
|
@@ -4624,21 +4624,21 @@ var init_semver = __esm(() => {
|
|
|
4624
4624
|
// src/lib/manifest.ts
|
|
4625
4625
|
var exports_manifest = {};
|
|
4626
4626
|
__export(exports_manifest, {
|
|
4627
|
-
|
|
4628
|
-
shortManifestName: () => shortManifestName,
|
|
4629
|
-
scriptRelFor: () => scriptRelFor,
|
|
4630
|
-
resolveScript: () => resolveScript,
|
|
4631
|
-
readCustomManifest: () => readCustomManifest,
|
|
4632
|
-
parseManifest: () => parseManifest,
|
|
4633
|
-
normalizeManifestName: () => normalizeManifestName,
|
|
4634
|
-
manifestSchema: () => manifestSchema,
|
|
4635
|
-
listCustomHooks: () => listCustomHooks,
|
|
4636
|
-
isInlineScript: () => isInlineScript,
|
|
4637
|
-
customHookDir: () => customHookDir,
|
|
4638
|
-
assertContained: () => assertContained,
|
|
4639
|
-
ScriptContainmentError: () => ScriptContainmentError,
|
|
4627
|
+
HOOK_NAME_RE: () => HOOK_NAME_RE,
|
|
4640
4628
|
HookIdentityError: () => HookIdentityError,
|
|
4641
|
-
|
|
4629
|
+
ScriptContainmentError: () => ScriptContainmentError,
|
|
4630
|
+
assertContained: () => assertContained,
|
|
4631
|
+
customHookDir: () => customHookDir,
|
|
4632
|
+
isInlineScript: () => isInlineScript,
|
|
4633
|
+
listCustomHooks: () => listCustomHooks,
|
|
4634
|
+
manifestSchema: () => manifestSchema,
|
|
4635
|
+
normalizeManifestName: () => normalizeManifestName,
|
|
4636
|
+
parseManifest: () => parseManifest,
|
|
4637
|
+
readCustomManifest: () => readCustomManifest,
|
|
4638
|
+
resolveScript: () => resolveScript,
|
|
4639
|
+
scriptRelFor: () => scriptRelFor,
|
|
4640
|
+
shortManifestName: () => shortManifestName,
|
|
4641
|
+
writeCustomHook: () => writeCustomHook
|
|
4642
4642
|
});
|
|
4643
4643
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync as readdirSync2, realpathSync, writeFileSync } from "fs";
|
|
4644
4644
|
import { basename, dirname, isAbsolute, join as join5, normalize, resolve as resolve2, sep } from "path";
|
|
@@ -4794,6 +4794,8 @@ var init_manifest = __esm(() => {
|
|
|
4794
4794
|
script_kind: exports_external.enum(["inline", "file"]).optional(),
|
|
4795
4795
|
args: exports_external.array(exports_external.string()).optional(),
|
|
4796
4796
|
nativeTargetDispatch: exports_external.boolean().optional(),
|
|
4797
|
+
requires_final_message: exports_external.boolean().optional(),
|
|
4798
|
+
requires_block: exports_external.boolean().optional(),
|
|
4797
4799
|
timeout_ms: exports_external.number().int().positive().optional(),
|
|
4798
4800
|
env: exports_external.record(exports_external.string(), exports_external.string()).optional()
|
|
4799
4801
|
});
|
|
@@ -4853,28 +4855,28 @@ var init_registry_artifact = __esm(() => {
|
|
|
4853
4855
|
// src/lib/store.ts
|
|
4854
4856
|
var exports_store = {};
|
|
4855
4857
|
__export(exports_store, {
|
|
4856
|
-
|
|
4857
|
-
verifyScriptHash: () => verifyScriptHash,
|
|
4858
|
-
upsertHookRecord: () => upsertHookRecord,
|
|
4859
|
-
sha256Of: () => sha256Of,
|
|
4860
|
-
sha256File: () => sha256File,
|
|
4861
|
-
setPinnedHook: () => setPinnedHook,
|
|
4862
|
-
retrustHook: () => retrustHook,
|
|
4863
|
-
removePinnedHook: () => removePinnedHook,
|
|
4864
|
-
removeHookRecord: () => removeHookRecord,
|
|
4865
|
-
removeHookFromStore: () => removeHookFromStore,
|
|
4866
|
-
readLock: () => readLock,
|
|
4867
|
-
pinInstalledHook: () => pinInstalledHook,
|
|
4868
|
-
markRegistryManaged: () => markRegistryManaged,
|
|
4869
|
-
listHookRecords: () => listHookRecords,
|
|
4870
|
-
getPinnedHook: () => getPinnedHook,
|
|
4871
|
-
getHookRecord: () => getHookRecord,
|
|
4858
|
+
LockFileError: () => LockFileError,
|
|
4872
4859
|
checkScriptHash: () => checkScriptHash,
|
|
4873
|
-
|
|
4860
|
+
getHookRecord: () => getHookRecord,
|
|
4861
|
+
getPinnedHook: () => getPinnedHook,
|
|
4862
|
+
listHookRecords: () => listHookRecords,
|
|
4863
|
+
markRegistryManaged: () => markRegistryManaged,
|
|
4864
|
+
pinInstalledHook: () => pinInstalledHook,
|
|
4865
|
+
readLock: () => readLock,
|
|
4866
|
+
removeHookFromStore: () => removeHookFromStore,
|
|
4867
|
+
removeHookRecord: () => removeHookRecord,
|
|
4868
|
+
removePinnedHook: () => removePinnedHook,
|
|
4869
|
+
retrustHook: () => retrustHook,
|
|
4870
|
+
setPinnedHook: () => setPinnedHook,
|
|
4871
|
+
sha256File: () => sha256File,
|
|
4872
|
+
sha256Of: () => sha256Of,
|
|
4873
|
+
upsertHookRecord: () => upsertHookRecord,
|
|
4874
|
+
verifyScriptHash: () => verifyScriptHash,
|
|
4875
|
+
writeLock: () => writeLock
|
|
4874
4876
|
});
|
|
4875
4877
|
import { createHash as createHash4 } from "crypto";
|
|
4876
4878
|
import { existsSync as existsSync8, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync2, renameSync, lstatSync as lstatSync3 } from "fs";
|
|
4877
|
-
import { join as
|
|
4879
|
+
import { join as join10 } from "path";
|
|
4878
4880
|
import { readFile } from "fs/promises";
|
|
4879
4881
|
import { randomBytes } from "crypto";
|
|
4880
4882
|
function sha256Of(input) {
|
|
@@ -4978,13 +4980,13 @@ function getPinnedHook(name) {
|
|
|
4978
4980
|
return readLock().hooks[name];
|
|
4979
4981
|
}
|
|
4980
4982
|
function registryManagedMarker(name) {
|
|
4981
|
-
return
|
|
4983
|
+
return join10(getHooksDataDir(), "registry-managed", sha256Of(name) + ".json");
|
|
4982
4984
|
}
|
|
4983
4985
|
function markRegistryManaged(name) {
|
|
4984
4986
|
const path = registryManagedMarker(name);
|
|
4985
4987
|
const content = JSON.stringify({ schema: 1, name }) + `
|
|
4986
4988
|
`;
|
|
4987
|
-
mkdirSync3(
|
|
4989
|
+
mkdirSync3(join10(getHooksDataDir(), "registry-managed"), { recursive: true, mode: 448 });
|
|
4988
4990
|
try {
|
|
4989
4991
|
writeFileSync2(path, content, { flag: "wx", mode: 384 });
|
|
4990
4992
|
} catch (error) {
|
|
@@ -5130,31 +5132,31 @@ var init_store = __esm(() => {
|
|
|
5130
5132
|
// src/lib/profiles.ts
|
|
5131
5133
|
var exports_profiles = {};
|
|
5132
5134
|
__export(exports_profiles, {
|
|
5133
|
-
|
|
5134
|
-
touchProfile: () => touchProfile,
|
|
5135
|
-
listProfiles: () => listProfiles,
|
|
5136
|
-
importProfiles: () => importProfiles,
|
|
5137
|
-
getProfilesDir: () => getProfilesDir,
|
|
5138
|
-
getProfile: () => getProfile,
|
|
5139
|
-
exportProfiles: () => exportProfiles,
|
|
5135
|
+
createProfile: () => createProfile,
|
|
5140
5136
|
deleteProfile: () => deleteProfile,
|
|
5141
|
-
|
|
5137
|
+
exportProfiles: () => exportProfiles,
|
|
5138
|
+
getProfile: () => getProfile,
|
|
5139
|
+
getProfilesDir: () => getProfilesDir,
|
|
5140
|
+
importProfiles: () => importProfiles,
|
|
5141
|
+
listProfiles: () => listProfiles,
|
|
5142
|
+
touchProfile: () => touchProfile,
|
|
5143
|
+
updateProfile: () => updateProfile
|
|
5142
5144
|
});
|
|
5143
|
-
import { existsSync as
|
|
5145
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync7, writeFileSync as writeFileSync7, readdirSync as readdirSync3, rmSync as rmSync3, cpSync as cpSync2 } from "fs";
|
|
5144
5146
|
import { join as join20 } from "path";
|
|
5145
5147
|
function getProfilesDir() {
|
|
5146
5148
|
const newDir = join20(getEffectiveDataRoot(), "profiles");
|
|
5147
5149
|
const oldDir = join20(getHomeDir(), ".hooks", "profiles");
|
|
5148
|
-
if (!
|
|
5149
|
-
|
|
5150
|
+
if (!existsSync12(newDir) && existsSync12(oldDir)) {
|
|
5151
|
+
mkdirSync6(newDir, { recursive: true });
|
|
5150
5152
|
cpSync2(oldDir, newDir, { recursive: true });
|
|
5151
5153
|
}
|
|
5152
5154
|
return newDir;
|
|
5153
5155
|
}
|
|
5154
5156
|
function ensureProfilesDir() {
|
|
5155
5157
|
const dir = getProfilesDir();
|
|
5156
|
-
if (!
|
|
5157
|
-
|
|
5158
|
+
if (!existsSync12(dir)) {
|
|
5159
|
+
mkdirSync6(dir, { recursive: true });
|
|
5158
5160
|
}
|
|
5159
5161
|
}
|
|
5160
5162
|
function profilePath(id) {
|
|
@@ -5177,30 +5179,30 @@ function createProfile(input2) {
|
|
|
5177
5179
|
if (input2.name) {
|
|
5178
5180
|
profile.name = input2.name;
|
|
5179
5181
|
}
|
|
5180
|
-
|
|
5182
|
+
writeFileSync7(profilePath(id), JSON.stringify(profile, null, 2) + `
|
|
5181
5183
|
`);
|
|
5182
5184
|
return profile;
|
|
5183
5185
|
}
|
|
5184
5186
|
function getProfile(id) {
|
|
5185
5187
|
const path = profilePath(id);
|
|
5186
5188
|
try {
|
|
5187
|
-
if (!
|
|
5189
|
+
if (!existsSync12(path))
|
|
5188
5190
|
return null;
|
|
5189
|
-
return JSON.parse(
|
|
5191
|
+
return JSON.parse(readFileSync7(path, "utf-8"));
|
|
5190
5192
|
} catch {
|
|
5191
5193
|
return null;
|
|
5192
5194
|
}
|
|
5193
5195
|
}
|
|
5194
5196
|
function listProfiles() {
|
|
5195
5197
|
const dir = getProfilesDir();
|
|
5196
|
-
if (!
|
|
5198
|
+
if (!existsSync12(dir))
|
|
5197
5199
|
return [];
|
|
5198
5200
|
try {
|
|
5199
|
-
const files =
|
|
5201
|
+
const files = readdirSync3(dir).filter((f) => f.endsWith(".json"));
|
|
5200
5202
|
const profiles = [];
|
|
5201
5203
|
for (const file2 of files) {
|
|
5202
5204
|
try {
|
|
5203
|
-
const content =
|
|
5205
|
+
const content = readFileSync7(join20(dir, file2), "utf-8");
|
|
5204
5206
|
profiles.push(JSON.parse(content));
|
|
5205
5207
|
} catch {}
|
|
5206
5208
|
}
|
|
@@ -5217,13 +5219,13 @@ function updateProfile(id, data) {
|
|
|
5217
5219
|
profile.name = data.name;
|
|
5218
5220
|
if (data.preferences !== undefined)
|
|
5219
5221
|
profile.preferences = data.preferences;
|
|
5220
|
-
|
|
5222
|
+
writeFileSync7(profilePath(id), JSON.stringify(profile, null, 2) + `
|
|
5221
5223
|
`);
|
|
5222
5224
|
return profile;
|
|
5223
5225
|
}
|
|
5224
5226
|
function deleteProfile(id) {
|
|
5225
5227
|
const path = profilePath(id);
|
|
5226
|
-
if (!
|
|
5228
|
+
if (!existsSync12(path))
|
|
5227
5229
|
return false;
|
|
5228
5230
|
try {
|
|
5229
5231
|
rmSync3(path);
|
|
@@ -5237,7 +5239,7 @@ function touchProfile(id) {
|
|
|
5237
5239
|
if (!profile)
|
|
5238
5240
|
return;
|
|
5239
5241
|
profile.last_seen_at = new Date().toISOString();
|
|
5240
|
-
|
|
5242
|
+
writeFileSync7(profilePath(id), JSON.stringify(profile, null, 2) + `
|
|
5241
5243
|
`);
|
|
5242
5244
|
}
|
|
5243
5245
|
function exportProfiles() {
|
|
@@ -5253,11 +5255,11 @@ function importProfiles(profiles) {
|
|
|
5253
5255
|
continue;
|
|
5254
5256
|
}
|
|
5255
5257
|
const path = profilePath(profile.agent_id);
|
|
5256
|
-
if (
|
|
5258
|
+
if (existsSync12(path)) {
|
|
5257
5259
|
skipped++;
|
|
5258
5260
|
continue;
|
|
5259
5261
|
}
|
|
5260
|
-
|
|
5262
|
+
writeFileSync7(path, JSON.stringify(profile, null, 2) + `
|
|
5261
5263
|
`);
|
|
5262
5264
|
imported++;
|
|
5263
5265
|
}
|
|
@@ -5269,16 +5271,16 @@ var init_profiles = __esm(() => {
|
|
|
5269
5271
|
|
|
5270
5272
|
// ../contracts/dist/client/transport.js
|
|
5271
5273
|
import { isIP } from "net";
|
|
5272
|
-
import { spawnSync } from "child_process";
|
|
5274
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
5273
5275
|
import { closeSync as closeSync23, fstatSync as fstatSync23, openSync as openSync23, readFileSync as readFileSync22 } from "fs";
|
|
5274
5276
|
import { O_NOFOLLOW as O_NOFOLLOW2, O_NONBLOCK as O_NONBLOCK2, O_RDONLY as O_RDONLY2 } from "constants";
|
|
5275
5277
|
import { hostname as osHostname } from "os";
|
|
5276
|
-
import { isAbsolute as isAbsolute9, join as
|
|
5278
|
+
import { isAbsolute as isAbsolute9, join as join210 } from "path";
|
|
5277
5279
|
import { createRequire as createRequire2 } from "module";
|
|
5278
5280
|
import { fileURLToPath as fileURLToPath22 } from "url";
|
|
5279
|
-
import { closeSync as closeSync5, fstatSync as fstatSync5, lstatSync as lstatSync16, openSync as openSync5, readFileSync as
|
|
5281
|
+
import { closeSync as closeSync5, fstatSync as fstatSync5, lstatSync as lstatSync16, openSync as openSync5, readFileSync as readFileSync18, realpathSync as realpathSync7, statSync as statSync2 } from "fs";
|
|
5280
5282
|
import { O_NOFOLLOW, O_NONBLOCK, O_RDONLY } from "constants";
|
|
5281
|
-
import { basename as
|
|
5283
|
+
import { basename as basename16, dirname as dirname23, join as join32, relative, sep as sep10 } from "path";
|
|
5282
5284
|
import { fileURLToPath as fileURLToPath4, pathToFileURL } from "url";
|
|
5283
5285
|
function envToken2(name) {
|
|
5284
5286
|
return name.toUpperCase().replace(/-/g, "_");
|
|
@@ -5353,13 +5355,13 @@ function o(e2, r2, t2) {
|
|
|
5353
5355
|
}
|
|
5354
5356
|
function entryPoint(directory3) {
|
|
5355
5357
|
const root = realpathSync7(directory3);
|
|
5356
|
-
const fd = openSync5(
|
|
5358
|
+
const fd = openSync5(join32(root, "package.json"), O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
5357
5359
|
let pkg;
|
|
5358
5360
|
try {
|
|
5359
5361
|
const stat2 = fstatSync5(fd);
|
|
5360
5362
|
if (!stat2.isFile() || stat2.size > MAX_PACKAGE_BYTES2)
|
|
5361
5363
|
throw new Error("Invalid Secrets package metadata");
|
|
5362
|
-
pkg = JSON.parse(
|
|
5364
|
+
pkg = JSON.parse(readFileSync18(fd, "utf8"));
|
|
5363
5365
|
} finally {
|
|
5364
5366
|
closeSync5(fd);
|
|
5365
5367
|
}
|
|
@@ -5373,18 +5375,18 @@ function entryPoint(directory3) {
|
|
|
5373
5375
|
if (/[\\%?#\0]/.test(target) || parts.some((part) => !part || part === "." || part === ".." || part === "node_modules")) {
|
|
5374
5376
|
throw new Error("Invalid Secrets import export");
|
|
5375
5377
|
}
|
|
5376
|
-
const file2 = realpathSync7(
|
|
5378
|
+
const file2 = realpathSync7(join32(root, ...parts));
|
|
5377
5379
|
const within = relative(root, file2);
|
|
5378
|
-
if (!within || within === ".." || within.startsWith(`..${sep10}`) || !
|
|
5380
|
+
if (!within || within === ".." || within.startsWith(`..${sep10}`) || !statSync2(file2).isFile()) {
|
|
5379
5381
|
throw new Error("Secrets import export escapes its package or is not a file");
|
|
5380
5382
|
}
|
|
5381
5383
|
return pathToFileURL(file2).href;
|
|
5382
5384
|
}
|
|
5383
5385
|
function resolveInstalledSecrets(parentUrl) {
|
|
5384
|
-
let directory3 =
|
|
5386
|
+
let directory3 = dirname23(fileURLToPath4(parentUrl));
|
|
5385
5387
|
for (;; ) {
|
|
5386
|
-
if (
|
|
5387
|
-
const candidate =
|
|
5388
|
+
if (basename16(directory3) !== "node_modules") {
|
|
5389
|
+
const candidate = join32(directory3, "node_modules", PACKAGE);
|
|
5388
5390
|
let absent = false;
|
|
5389
5391
|
try {
|
|
5390
5392
|
lstatSync16(candidate);
|
|
@@ -5396,7 +5398,7 @@ function resolveInstalledSecrets(parentUrl) {
|
|
|
5396
5398
|
if (!absent)
|
|
5397
5399
|
return entryPoint(candidate);
|
|
5398
5400
|
}
|
|
5399
|
-
const parent =
|
|
5401
|
+
const parent = dirname23(directory3);
|
|
5400
5402
|
if (parent === directory3)
|
|
5401
5403
|
throw new Error("Secrets SDK is not installed for this consumer");
|
|
5402
5404
|
directory3 = parent;
|
|
@@ -5415,14 +5417,14 @@ function hasnaHomeDir(env) {
|
|
|
5415
5417
|
if (override)
|
|
5416
5418
|
return override;
|
|
5417
5419
|
const home = homeDir(env);
|
|
5418
|
-
return home ?
|
|
5420
|
+
return home ? join210(home, HASNA_HOME_DIR) : null;
|
|
5419
5421
|
}
|
|
5420
5422
|
function appConfigDir(name, env) {
|
|
5421
5423
|
const configRoot = absoluteOverride(env, HASNA_CONFIG_HOME_ENV_KEY);
|
|
5422
5424
|
if (configRoot)
|
|
5423
|
-
return
|
|
5425
|
+
return join210(configRoot, name);
|
|
5424
5426
|
const root = hasnaHomeDir(env);
|
|
5425
|
-
return root ?
|
|
5427
|
+
return root ? join210(root, name, CONFIG_SUBDIR) : null;
|
|
5426
5428
|
}
|
|
5427
5429
|
function credentialDiskSourceList(name, env, profile = null) {
|
|
5428
5430
|
if (!SAFE_APP_SLUG.test(name))
|
|
@@ -5431,7 +5433,7 @@ function credentialDiskSourceList(name, env, profile = null) {
|
|
|
5431
5433
|
if (!directory3)
|
|
5432
5434
|
return [];
|
|
5433
5435
|
const file2 = profile ? `${CREDENTIALS_FILE}-${profile}` : CREDENTIALS_FILE;
|
|
5434
|
-
return [{ path:
|
|
5436
|
+
return [{ path: join210(directory3, file2), tier: "disk" }];
|
|
5435
5437
|
}
|
|
5436
5438
|
function credentialDiskSources(name, env) {
|
|
5437
5439
|
return credentialDiskSourceList(name, env, null).map((s) => s.path);
|
|
@@ -5439,10 +5441,10 @@ function credentialDiskSources(name, env) {
|
|
|
5439
5441
|
function profileDiskSources(name, env, profile) {
|
|
5440
5442
|
return credentialDiskSourceList(name, env, profile).map((s) => s.path);
|
|
5441
5443
|
}
|
|
5442
|
-
function parseEnvFile(
|
|
5444
|
+
function parseEnvFile(text2) {
|
|
5443
5445
|
const values = new Map;
|
|
5444
5446
|
const unusable = new Set;
|
|
5445
|
-
for (const rawLine of
|
|
5447
|
+
for (const rawLine of text2.split(/\r?\n/)) {
|
|
5446
5448
|
const line = rawLine.trim();
|
|
5447
5449
|
if (line.length === 0 || line.startsWith("#"))
|
|
5448
5450
|
continue;
|
|
@@ -5639,7 +5641,7 @@ function isAmbientEnvironment(env) {
|
|
|
5639
5641
|
return env === process.env || env[AMBIENT_ENVIRONMENT2] === true;
|
|
5640
5642
|
}
|
|
5641
5643
|
function defaultKeychainRunner(argv) {
|
|
5642
|
-
const result =
|
|
5644
|
+
const result = spawnSync4(KEYCHAIN_SECURITY_BIN, [...argv], {
|
|
5643
5645
|
encoding: "utf8",
|
|
5644
5646
|
stdio: ["ignore", "pipe", "pipe"],
|
|
5645
5647
|
timeout: KEYCHAIN_SPAWN_TIMEOUT_MS
|
|
@@ -5667,8 +5669,8 @@ function keychainAccount(env, options) {
|
|
|
5667
5669
|
const user = env.USER?.trim();
|
|
5668
5670
|
return user || null;
|
|
5669
5671
|
}
|
|
5670
|
-
function keychainFailureHint(
|
|
5671
|
-
const line =
|
|
5672
|
+
function keychainFailureHint(text2) {
|
|
5673
|
+
const line = text2.split(/\r?\n/).find((entry) => entry.trim().length > 0)?.trim() ?? "";
|
|
5672
5674
|
const clean = line.replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 200);
|
|
5673
5675
|
return clean ? `: ${clean}` : "";
|
|
5674
5676
|
}
|
|
@@ -6295,12 +6297,12 @@ var init_local_opt_in = __esm(() => {
|
|
|
6295
6297
|
// src/lib/db-writer.ts
|
|
6296
6298
|
var exports_db_writer = {};
|
|
6297
6299
|
__export(exports_db_writer, {
|
|
6298
|
-
|
|
6299
|
-
resolveHookEventSink: () => resolveHookEventSink,
|
|
6300
|
-
resolveEventType: () => resolveEventType,
|
|
6301
|
-
recordHookRun: () => recordHookRun,
|
|
6300
|
+
__resetHookEventSinkNotice: () => __resetHookEventSinkNotice,
|
|
6302
6301
|
normalizeEventType: () => normalizeEventType,
|
|
6303
|
-
|
|
6302
|
+
recordHookRun: () => recordHookRun,
|
|
6303
|
+
resolveEventType: () => resolveEventType,
|
|
6304
|
+
resolveHookEventSink: () => resolveHookEventSink,
|
|
6305
|
+
writeHookEvent: () => writeHookEvent
|
|
6304
6306
|
});
|
|
6305
6307
|
function resolveHookEventSink(env = process.env) {
|
|
6306
6308
|
if (isLocalStoreRefused())
|
|
@@ -6481,9 +6483,9 @@ var init_stop_review_context = __esm(() => {
|
|
|
6481
6483
|
});
|
|
6482
6484
|
|
|
6483
6485
|
// src/lib/hook-env.ts
|
|
6484
|
-
import { dirname as
|
|
6485
|
-
import { existsSync as
|
|
6486
|
-
import { tmpdir as
|
|
6486
|
+
import { dirname as dirname37, isAbsolute as isAbsolute35 } from "path";
|
|
6487
|
+
import { existsSync as existsSync18, realpathSync as realpathSync19, statSync as statSync3 } from "fs";
|
|
6488
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
6487
6489
|
function isDeniedEnvName(name) {
|
|
6488
6490
|
const upper = name.toUpperCase();
|
|
6489
6491
|
if (DENY_PREFIXES.some((prefix3) => upper.startsWith(prefix3)))
|
|
@@ -6517,22 +6519,22 @@ function isUnsafePathEntry(entry, home) {
|
|
|
6517
6519
|
}
|
|
6518
6520
|
};
|
|
6519
6521
|
const resolved = canonical10(entry);
|
|
6520
|
-
for (const root of [home,
|
|
6522
|
+
for (const root of [home, tmpdir3(), "/tmp", "/var/tmp"].filter((value) => Boolean(value))) {
|
|
6521
6523
|
const blocked = canonical10(root);
|
|
6522
6524
|
if (resolved === blocked || resolved.startsWith(blocked + "/"))
|
|
6523
6525
|
return true;
|
|
6524
6526
|
}
|
|
6525
6527
|
try {
|
|
6526
|
-
if ((
|
|
6528
|
+
if ((statSync3(entry).mode & 2) !== 0)
|
|
6527
6529
|
return true;
|
|
6528
6530
|
} catch {}
|
|
6529
6531
|
return false;
|
|
6530
6532
|
}
|
|
6531
6533
|
function sanitizeHookPath(pathValue, home) {
|
|
6532
6534
|
const baseline = PATH_BASELINE.slice();
|
|
6533
|
-
if (process.platform === "darwin" &&
|
|
6535
|
+
if (process.platform === "darwin" && existsSync18("/opt/homebrew/bin"))
|
|
6534
6536
|
baseline.push("/opt/homebrew/bin");
|
|
6535
|
-
const bunDir =
|
|
6537
|
+
const bunDir = dirname37(process.execPath);
|
|
6536
6538
|
const seen = new Set;
|
|
6537
6539
|
const out = [];
|
|
6538
6540
|
for (const dir of baseline) {
|
|
@@ -6660,15 +6662,15 @@ var init_hook_env = __esm(() => {
|
|
|
6660
6662
|
// src/lib/run.ts
|
|
6661
6663
|
var exports_run = {};
|
|
6662
6664
|
__export(exports_run, {
|
|
6663
|
-
|
|
6665
|
+
BUN_ISOLATION_FLAGS: () => BUN_ISOLATION_FLAGS,
|
|
6664
6666
|
HookTimeoutError: () => HookTimeoutError,
|
|
6665
|
-
|
|
6667
|
+
executeVerifiedScript: () => executeVerifiedScript
|
|
6666
6668
|
});
|
|
6667
6669
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
6668
|
-
import { rmSync as rmSync6, writeFileSync as
|
|
6669
|
-
import { basename as
|
|
6670
|
+
import { rmSync as rmSync6, writeFileSync as writeFileSync15 } from "fs";
|
|
6671
|
+
import { basename as basename19, dirname as dirname38, isAbsolute as isAbsolute36, join as join45 } from "path";
|
|
6670
6672
|
function extensionOf(scriptPath) {
|
|
6671
|
-
const base =
|
|
6673
|
+
const base = basename19(scriptPath);
|
|
6672
6674
|
const dot = base.lastIndexOf(".");
|
|
6673
6675
|
return dot > 0 ? base.slice(dot + 1) : "ts";
|
|
6674
6676
|
}
|
|
@@ -6680,9 +6682,9 @@ function shebangInterpreter(firstLine) {
|
|
|
6680
6682
|
return null;
|
|
6681
6683
|
const parts = rest.split(/\s+/);
|
|
6682
6684
|
if (parts[0] === "env" || parts[0] === "/usr/bin/env") {
|
|
6683
|
-
return parts[1] && parts[1] !== "-S" ?
|
|
6685
|
+
return parts[1] && parts[1] !== "-S" ? basename19(parts[1]) : parts[2] ? basename19(parts[2]) : null;
|
|
6684
6686
|
}
|
|
6685
|
-
return
|
|
6687
|
+
return basename19(parts[0]);
|
|
6686
6688
|
}
|
|
6687
6689
|
function interpreterFor(name, scriptPath, content) {
|
|
6688
6690
|
const ext = extensionOf(scriptPath);
|
|
@@ -6735,9 +6737,9 @@ async function readPipeWithDeadline(stream, deadlineMs) {
|
|
|
6735
6737
|
return chunks.join("");
|
|
6736
6738
|
}
|
|
6737
6739
|
async function executeVerifiedScript(options) {
|
|
6738
|
-
const scriptDir =
|
|
6740
|
+
const scriptDir = dirname38(options.scriptPath);
|
|
6739
6741
|
const interpreter = interpreterFor(options.name, options.scriptPath, options.content);
|
|
6740
|
-
const tempPath =
|
|
6742
|
+
const tempPath = join45(scriptDir, `.hooks-verified-${randomBytes3(12).toString("hex")}.${interpreter.tempExt}`);
|
|
6741
6743
|
let proc = null;
|
|
6742
6744
|
let timedOut = false;
|
|
6743
6745
|
const timeoutTimer = options.timeout ? setTimeout(() => {
|
|
@@ -6745,7 +6747,7 @@ async function executeVerifiedScript(options) {
|
|
|
6745
6747
|
killGroup(proc, { leaderAlive: proc !== null && proc.exitCode === null });
|
|
6746
6748
|
}, options.timeout) : null;
|
|
6747
6749
|
try {
|
|
6748
|
-
|
|
6750
|
+
writeFileSync15(tempPath, options.content, { flag: "wx", mode: 384 });
|
|
6749
6751
|
proc = Bun.spawn([...interpreter.command, isAbsolute36(tempPath) ? tempPath : `./${tempPath}`, ...options.args ?? []], {
|
|
6750
6752
|
stdin: new Response(options.stdin),
|
|
6751
6753
|
stdout: "pipe",
|
|
@@ -7921,9 +7923,9 @@ function getHook(name) {
|
|
|
7921
7923
|
return HOOKS.find((h) => h.name === name);
|
|
7922
7924
|
}
|
|
7923
7925
|
// src/lib/installer.ts
|
|
7924
|
-
import { existsSync as
|
|
7925
|
-
import { join as
|
|
7926
|
-
import { homedir as
|
|
7926
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync12, readFileSync as readFileSync13, readdirSync as readdirSync8, realpathSync as realpathSync4, rmdirSync as rmdirSync4, unlinkSync as unlinkSync6, writeFileSync as writeFileSync10 } from "fs";
|
|
7927
|
+
import { join as join24, dirname as dirname16, basename as basename12, resolve as resolve28 } from "path";
|
|
7928
|
+
import { homedir as homedir8 } from "os";
|
|
7927
7929
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
7928
7930
|
|
|
7929
7931
|
// src/lib/readiness-process.ts
|
|
@@ -8048,6 +8050,8 @@ function resolveHookMeta(name) {
|
|
|
8048
8050
|
matcher: "",
|
|
8049
8051
|
tags: ["custom"],
|
|
8050
8052
|
nativeTargetDispatch: manifest.nativeTargetDispatch,
|
|
8053
|
+
requiresFinalMessage: manifest.requires_final_message,
|
|
8054
|
+
requiresBlock: manifest.requires_block,
|
|
8051
8055
|
timeoutSeconds: manifest.timeout_ms === undefined ? undefined : Math.ceil(manifest.timeout_ms / 1000)
|
|
8052
8056
|
};
|
|
8053
8057
|
}
|
|
@@ -8530,8 +8534,243 @@ function retainedMementosRegistration(commands) {
|
|
|
8530
8534
|
return values[0];
|
|
8531
8535
|
}
|
|
8532
8536
|
|
|
8537
|
+
// src/lib/targets.ts
|
|
8538
|
+
import { homedir as homedir5 } from "os";
|
|
8539
|
+
import { dirname as dirname5, join as join9, resolve as resolve3 } from "path";
|
|
8540
|
+
var TARGET_NAMES = [
|
|
8541
|
+
"claude",
|
|
8542
|
+
"codex",
|
|
8543
|
+
"gemini",
|
|
8544
|
+
"codewith",
|
|
8545
|
+
"qwen",
|
|
8546
|
+
"muse",
|
|
8547
|
+
"kimi",
|
|
8548
|
+
"pi",
|
|
8549
|
+
"cursor",
|
|
8550
|
+
"opencode",
|
|
8551
|
+
"sumi"
|
|
8552
|
+
];
|
|
8553
|
+
var INSTALL_TARGET_NAMES = [
|
|
8554
|
+
"claude",
|
|
8555
|
+
"codex",
|
|
8556
|
+
"gemini",
|
|
8557
|
+
"codewith",
|
|
8558
|
+
"qwen",
|
|
8559
|
+
"muse",
|
|
8560
|
+
"kimi",
|
|
8561
|
+
"pi",
|
|
8562
|
+
"cursor"
|
|
8563
|
+
];
|
|
8564
|
+
function isTargetName(value) {
|
|
8565
|
+
return typeof value === "string" && TARGET_NAMES.includes(value);
|
|
8566
|
+
}
|
|
8567
|
+
var settingsJson = (dir) => (o) => o.scope === "project" ? join9(resolve3(o.cwd), dir, "settings.json") : join9(o.home, dir, "settings.json");
|
|
8568
|
+
var DEFINITIONS = {
|
|
8569
|
+
claude: {
|
|
8570
|
+
install: true,
|
|
8571
|
+
run: true,
|
|
8572
|
+
stopEvent: "Stop",
|
|
8573
|
+
canBlock: true,
|
|
8574
|
+
deliversFinalMessage: true,
|
|
8575
|
+
finalMessageField: "last_assistant_message",
|
|
8576
|
+
path: settingsJson(".claude")
|
|
8577
|
+
},
|
|
8578
|
+
codex: {
|
|
8579
|
+
install: true,
|
|
8580
|
+
run: true,
|
|
8581
|
+
stopEvent: "Stop",
|
|
8582
|
+
canBlock: true,
|
|
8583
|
+
deliversFinalMessage: true,
|
|
8584
|
+
finalMessageField: "last_assistant_message",
|
|
8585
|
+
path: (o) => o.scope === "project" ? join9(resolve3(o.cwd), ".codex", "hooks.json") : join9(o.home, ".codex", "hooks.json")
|
|
8586
|
+
},
|
|
8587
|
+
gemini: {
|
|
8588
|
+
install: true,
|
|
8589
|
+
run: true,
|
|
8590
|
+
stopEvent: "AfterAgent",
|
|
8591
|
+
canBlock: true,
|
|
8592
|
+
deliversFinalMessage: true,
|
|
8593
|
+
finalMessageField: "prompt_response",
|
|
8594
|
+
path: settingsJson(".gemini")
|
|
8595
|
+
},
|
|
8596
|
+
codewith: {
|
|
8597
|
+
install: true,
|
|
8598
|
+
run: true,
|
|
8599
|
+
stopEvent: "Stop",
|
|
8600
|
+
canBlock: true,
|
|
8601
|
+
deliversFinalMessage: true,
|
|
8602
|
+
finalMessageField: "last_assistant_message",
|
|
8603
|
+
path: (o) => o.scope === "project" ? join9(resolve3(o.cwd), ".codewith", "config.toml") : join9(o.home, ".codewith", "config.toml")
|
|
8604
|
+
},
|
|
8605
|
+
qwen: {
|
|
8606
|
+
install: true,
|
|
8607
|
+
run: true,
|
|
8608
|
+
stopEvent: "Stop",
|
|
8609
|
+
canBlock: true,
|
|
8610
|
+
deliversFinalMessage: true,
|
|
8611
|
+
finalMessageField: "last_assistant_message",
|
|
8612
|
+
path: settingsJson(".qwen")
|
|
8613
|
+
},
|
|
8614
|
+
muse: {
|
|
8615
|
+
install: true,
|
|
8616
|
+
run: true,
|
|
8617
|
+
stopEvent: "Stop",
|
|
8618
|
+
canBlock: true,
|
|
8619
|
+
deliversFinalMessage: true,
|
|
8620
|
+
finalMessageField: "last_assistant_message",
|
|
8621
|
+
installNote: "Muse receives the final message as a quoted JSON string; `hooks run --target muse` parses it once before the hook sees it.",
|
|
8622
|
+
path: (o) => join9(o.home, ".hasna", "hooks", "muse-plugins", o.hook ?? "")
|
|
8623
|
+
},
|
|
8624
|
+
kimi: {
|
|
8625
|
+
install: true,
|
|
8626
|
+
run: true,
|
|
8627
|
+
stopEvent: "Stop",
|
|
8628
|
+
canBlock: true,
|
|
8629
|
+
deliversFinalMessage: false,
|
|
8630
|
+
finalMessageNote: "Kimi's Stop payload carries only hook_event_name, session_id, cwd, client_type, session_title and stop_hook_active",
|
|
8631
|
+
path: (o) => join9(o.home, ".kimi-code", "config.toml")
|
|
8632
|
+
},
|
|
8633
|
+
pi: {
|
|
8634
|
+
install: true,
|
|
8635
|
+
run: true,
|
|
8636
|
+
stopEvent: "turn_end",
|
|
8637
|
+
canBlock: true,
|
|
8638
|
+
deliversFinalMessage: false,
|
|
8639
|
+
finalMessageNote: "the pi-hooks bridge sends only hook_event_name, session_id, cwd and stop_hook_active (transcript_path is declared but never populated)",
|
|
8640
|
+
installNote: "Pi runs hooks through the hasna-pi-hooks bridge: the config points at a Hooks profile, so registration is not by itself proof that a turn was held.",
|
|
8641
|
+
path: (o) => join9(o.home, ".pi", "agent", "state", "hasna-pi-hooks.config.json")
|
|
8642
|
+
},
|
|
8643
|
+
cursor: {
|
|
8644
|
+
install: true,
|
|
8645
|
+
run: true,
|
|
8646
|
+
stopEvent: "stop",
|
|
8647
|
+
canBlock: false,
|
|
8648
|
+
deliversFinalMessage: false,
|
|
8649
|
+
finalMessageNote: "Cursor's stop hook carries no assistant text",
|
|
8650
|
+
blockNote: "a block verdict is ignored, and only followup_message continues a turn (loop_limit 5)",
|
|
8651
|
+
installNote: "Cursor's stop hook cannot block the turn: a block verdict is ignored, and only followup_message continues a turn (loop_limit 5). The registration alone does not hold anything.",
|
|
8652
|
+
path: (o) => o.scope === "project" ? join9(resolve3(o.cwd), ".cursor", "hooks.json") : join9(o.home, ".cursor", "hooks.json")
|
|
8653
|
+
},
|
|
8654
|
+
opencode: {
|
|
8655
|
+
install: false,
|
|
8656
|
+
run: true,
|
|
8657
|
+
stopEvent: null,
|
|
8658
|
+
canBlock: false,
|
|
8659
|
+
deliversFinalMessage: false,
|
|
8660
|
+
blockNote: "opencode has no turn-end event to hold: session.prompt schedules a new agent-loop run instead of continuing the current turn",
|
|
8661
|
+
stopEventSubstitute: "opencode has only the session.idle bus event, which is observe-only and cannot hold the turn; `hooks install stop-review --target opencode` registers the managed observe-and-re-prompt plugin",
|
|
8662
|
+
path: (o) => {
|
|
8663
|
+
const xdg = o.env.XDG_CONFIG_HOME;
|
|
8664
|
+
const base = xdg && xdg.startsWith("/") ? xdg : join9(o.home, ".config");
|
|
8665
|
+
return join9(resolve3(base), "opencode", "opencode.json");
|
|
8666
|
+
}
|
|
8667
|
+
},
|
|
8668
|
+
sumi: {
|
|
8669
|
+
install: false,
|
|
8670
|
+
run: true,
|
|
8671
|
+
stopEvent: "Stop",
|
|
8672
|
+
canBlock: true,
|
|
8673
|
+
deliversFinalMessage: true,
|
|
8674
|
+
finalMessageField: "last_assistant_message",
|
|
8675
|
+
stopEventSubstitute: "Sumi stop review is registered through the managed path: `hooks install stop-review --target sumi`",
|
|
8676
|
+
path: (o) => join9(o.home, ".sumi", "plugins")
|
|
8677
|
+
}
|
|
8678
|
+
};
|
|
8679
|
+
function getTargetCapabilities(target, options = {}) {
|
|
8680
|
+
if (!isTargetName(target))
|
|
8681
|
+
return;
|
|
8682
|
+
const definition = DEFINITIONS[target];
|
|
8683
|
+
const resolved = {
|
|
8684
|
+
scope: options.scope ?? "global",
|
|
8685
|
+
home: options.home ?? homedir5(),
|
|
8686
|
+
cwd: options.cwd ?? process.cwd(),
|
|
8687
|
+
env: options.env ?? process.env,
|
|
8688
|
+
hook: options.hook
|
|
8689
|
+
};
|
|
8690
|
+
return {
|
|
8691
|
+
install: definition.install,
|
|
8692
|
+
run: definition.run,
|
|
8693
|
+
stopEvent: definition.stopEvent,
|
|
8694
|
+
canBlock: definition.canBlock,
|
|
8695
|
+
deliversFinalMessage: definition.deliversFinalMessage,
|
|
8696
|
+
configPath: definition.path(resolved)
|
|
8697
|
+
};
|
|
8698
|
+
}
|
|
8699
|
+
function musePluginRoot(options = {}) {
|
|
8700
|
+
return dirname5(getTargetCapabilities("muse", { ...options, hook: "bundle" }).configPath);
|
|
8701
|
+
}
|
|
8702
|
+
function targetInstallNote(target) {
|
|
8703
|
+
return isTargetName(target) ? DEFINITIONS[target].installNote : undefined;
|
|
8704
|
+
}
|
|
8705
|
+
function runTargetHelp() {
|
|
8706
|
+
return TARGET_NAMES.join(", ");
|
|
8707
|
+
}
|
|
8708
|
+
function blockingInstallTargets() {
|
|
8709
|
+
return INSTALL_TARGET_NAMES.filter((name) => DEFINITIONS[name].canBlock);
|
|
8710
|
+
}
|
|
8711
|
+
function installCapabilityRefusal(hook, target, requirement, options = {}) {
|
|
8712
|
+
const definition = isTargetName(target) ? DEFINITIONS[target] : undefined;
|
|
8713
|
+
if (!definition) {
|
|
8714
|
+
return `Refused: Unknown target '${target}'. Known targets: ${runTargetHelp()}.`;
|
|
8715
|
+
}
|
|
8716
|
+
const capabilities = getTargetCapabilities(target, options);
|
|
8717
|
+
if (requirement.requiresBlock && !capabilities.canBlock) {
|
|
8718
|
+
const others = [];
|
|
8719
|
+
if (!capabilities.install)
|
|
8720
|
+
others.push("no generic install path (install: false)");
|
|
8721
|
+
if (requirement.requiresFinalMessage && !capabilities.deliversFinalMessage)
|
|
8722
|
+
others.push("no final assistant message (deliversFinalMessage: false)");
|
|
8723
|
+
if (requirement.events.includes("Stop") && capabilities.stopEvent === null)
|
|
8724
|
+
others.push("no turn-end event (stopEvent: null)");
|
|
8725
|
+
const also = others.length === 0 ? "" : ` It also has ${others.join(" and ")}.`;
|
|
8726
|
+
return `Refused: '${hook}' declares requires_block, and target '${target}' cannot hold the turn (canBlock: false) \u2014 ${definition.blockNote ?? "a block verdict is ignored there"}.${also} ` + `Unblock it by installing on a target that can block (${blockingInstallTargets().join(", ")}), or by clearing requires_block in the hook's manifest.`;
|
|
8727
|
+
}
|
|
8728
|
+
if (requirement.requiresFinalMessage && !capabilities.deliversFinalMessage) {
|
|
8729
|
+
const others = [];
|
|
8730
|
+
if (!capabilities.install)
|
|
8731
|
+
others.push("no generic install path (install: false)");
|
|
8732
|
+
if (requirement.requiresBlock && !capabilities.canBlock)
|
|
8733
|
+
others.push("no turn-holding verdict (canBlock: false)");
|
|
8734
|
+
if (requirement.events.includes("Stop") && capabilities.stopEvent === null)
|
|
8735
|
+
others.push("no turn-end event (stopEvent: null)");
|
|
8736
|
+
const also = others.length === 0 ? "" : ` It also has ${others.join(" and ")}.`;
|
|
8737
|
+
return `Refused: '${hook}' declares requires_final_message, and target '${target}' does not deliver the assistant's final message (deliversFinalMessage: false) \u2014 ${definition.finalMessageNote ?? "its payload carries no assistant text"}.${also} ` + `Unblock it by installing on a target that delivers the message (${INSTALL_TARGET_NAMES.filter((name) => DEFINITIONS[name].deliversFinalMessage).join(", ")}), or by clearing requires_final_message in the hook's manifest.`;
|
|
8738
|
+
}
|
|
8739
|
+
if (!capabilities.install) {
|
|
8740
|
+
return `Refused: Hooks has no generic install path for target '${target}' (install: false). ${definition.stopEventSubstitute ?? `Supported install targets: ${INSTALL_TARGET_NAMES.join(", ")}.`}`;
|
|
8741
|
+
}
|
|
8742
|
+
if (requirement.events.includes("Stop") && capabilities.stopEvent === null) {
|
|
8743
|
+
return `Refused: '${hook}' runs on the Stop event, and target '${target}' has no turn-end event (stopEvent: null), so nothing would ever run it. ${definition.stopEventSubstitute ?? ""}`.trim();
|
|
8744
|
+
}
|
|
8745
|
+
return;
|
|
8746
|
+
}
|
|
8747
|
+
|
|
8748
|
+
// src/lib/native-target.ts
|
|
8749
|
+
var HOOK_RUN_TARGETS = TARGET_NAMES;
|
|
8750
|
+
function isHookRunTarget(value) {
|
|
8751
|
+
return typeof value === "string" && HOOK_RUN_TARGETS.includes(value);
|
|
8752
|
+
}
|
|
8753
|
+
function nativeTargetArgs(dispatch, target, args = []) {
|
|
8754
|
+
if (target !== undefined && !isHookRunTarget(target))
|
|
8755
|
+
throw new Error(`Invalid --target; expected one of ${HOOK_RUN_TARGETS.join(", ")}`);
|
|
8756
|
+
if (!dispatch)
|
|
8757
|
+
return [...args];
|
|
8758
|
+
if (!isHookRunTarget(target))
|
|
8759
|
+
throw new Error("This hook requires --target from its native registration");
|
|
8760
|
+
if (args.some((arg) => arg === "--harness" || arg.startsWith("--harness=")))
|
|
8761
|
+
throw new Error("nativeTargetDispatch owns the --harness argument; remove it from manifest args");
|
|
8762
|
+
return [...args, "--harness", target];
|
|
8763
|
+
}
|
|
8764
|
+
function nativeTargetCommandSuffix(dispatch, target) {
|
|
8765
|
+
if (!dispatch)
|
|
8766
|
+
return "";
|
|
8767
|
+
if (!isHookRunTarget(target))
|
|
8768
|
+
throw new Error("Native registration requires a supported target");
|
|
8769
|
+
return ` --target ${target}`;
|
|
8770
|
+
}
|
|
8771
|
+
|
|
8533
8772
|
// src/lib/registration.ts
|
|
8534
|
-
var REGISTRATION_COMMAND_RE =
|
|
8773
|
+
var REGISTRATION_COMMAND_RE = new RegExp(`^(?:hooks run ([\\w-]+)(?:\\s+--profile\\s+[\\w-]+)?(?:\\s+--target\\s+(?:${HOOK_RUN_TARGETS.join("|")}))?|hook-([\\w-]+))$`);
|
|
8535
8774
|
function registrationName(command) {
|
|
8536
8775
|
if (typeof command !== "string")
|
|
8537
8776
|
return;
|
|
@@ -8560,7 +8799,7 @@ init_store();
|
|
|
8560
8799
|
|
|
8561
8800
|
// src/lib/codex-settings.ts
|
|
8562
8801
|
import { closeSync as closeSync3, existsSync as existsSync9, lstatSync as lstatSync4, mkdirSync as mkdirSync4, openSync as openSync3, readFileSync as readFileSync6, renameSync as renameSync2, unlinkSync, writeFileSync as writeFileSync3 } from "fs";
|
|
8563
|
-
import { dirname as
|
|
8802
|
+
import { dirname as dirname6 } from "path";
|
|
8564
8803
|
import { createHash as createHash5, randomUUID } from "crypto";
|
|
8565
8804
|
var snapshots = new WeakMap;
|
|
8566
8805
|
function current(path) {
|
|
@@ -8619,7 +8858,7 @@ function writeCodexSettings(path, settings, expectedSha256, beforeWrite) {
|
|
|
8619
8858
|
` });
|
|
8620
8859
|
}
|
|
8621
8860
|
function writeHookSettingsPreimage(path, settings, before, beforeWrite) {
|
|
8622
|
-
mkdirSync4(
|
|
8861
|
+
mkdirSync4(dirname6(path), { recursive: true, mode: 448 });
|
|
8623
8862
|
const lock = `${path}.hooks-write.lock`;
|
|
8624
8863
|
let fd;
|
|
8625
8864
|
try {
|
|
@@ -8649,18 +8888,15 @@ function writeHookSettingsPreimage(path, settings, before, beforeWrite) {
|
|
|
8649
8888
|
// src/lib/claude-skills-coordination.ts
|
|
8650
8889
|
import { createHash as createHash8 } from "crypto";
|
|
8651
8890
|
import { existsSync as existsSync11, lstatSync as lstatSync9 } from "fs";
|
|
8652
|
-
import { homedir as
|
|
8653
|
-
import { join as
|
|
8891
|
+
import { homedir as homedir7 } from "os";
|
|
8892
|
+
import { join as join17, resolve as resolve9 } from "path";
|
|
8654
8893
|
|
|
8655
8894
|
// ../../node_modules/.bun/@hasna+skills@0.10.78+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
|
|
8656
8895
|
import { existsSync as existsSync10 } from "fs";
|
|
8657
|
-
import { homedir as
|
|
8658
|
-
import { join as
|
|
8896
|
+
import { homedir as homedir6 } from "os";
|
|
8897
|
+
import { join as join11, resolve as resolve4 } from "path";
|
|
8659
8898
|
import { homedir as pathsResolverHomedir2 } from "os";
|
|
8660
8899
|
import { join as pathsResolverJoin2 } from "path";
|
|
8661
|
-
import { createHash as createHash6 } from "crypto";
|
|
8662
|
-
import { existsSync as existsSync52, readdirSync as readdirSync3, readFileSync as readFileSync42, statSync as statSync4 } from "fs";
|
|
8663
|
-
import { join as join52, sep as sep2 } from "path";
|
|
8664
8900
|
import { createHash as createHash32 } from "crypto";
|
|
8665
8901
|
import { createHash as createHash22 } from "crypto";
|
|
8666
8902
|
import { closeSync as closeSync22, constants as constants22, fstatSync as fstatSync22, lstatSync as lstatSync42, openSync as openSync22, readSync } from "fs";
|
|
@@ -8670,14 +8906,14 @@ import { createHash as createHash42 } from "crypto";
|
|
|
8670
8906
|
import { basename as basename3, dirname as dirname42, isAbsolute as isAbsolute32, resolve as resolve32 } from "path";
|
|
8671
8907
|
import { createHash as createHash52 } from "crypto";
|
|
8672
8908
|
import { closeSync as closeSync32, constants as constants3, fstatSync as fstatSync3, lstatSync as lstatSync5, openSync as openSync32, readSync as readSync2 } from "fs";
|
|
8673
|
-
import { basename as basename4, dirname as dirname52, isAbsolute as isAbsolute4, resolve as
|
|
8909
|
+
import { basename as basename4, dirname as dirname52, isAbsolute as isAbsolute4, resolve as resolve42, sep as sep2 } from "path";
|
|
8674
8910
|
import { createHash as createHash30 } from "crypto";
|
|
8675
8911
|
import { lstatSync as lstatSync32, readFileSync as readFileSync26, readdirSync as readdirSync13, realpathSync as realpathSync13 } from "fs";
|
|
8676
8912
|
import { basename as basename15, dirname as dirname26, isAbsolute as isAbsolute28, join as join38, relative as relative10, resolve as resolve27, sep as sep15 } from "path";
|
|
8677
8913
|
import { isDeepStrictEqual as isDeepStrictEqual9 } from "util";
|
|
8678
|
-
import { dirname as
|
|
8914
|
+
import { dirname as dirname62, isAbsolute as isAbsolute6, join as join82, resolve as resolve6 } from "path";
|
|
8679
8915
|
import { lstatSync as lstatSync6, readFileSync as readFileSync62, opendirSync } from "fs";
|
|
8680
|
-
import { createHash as
|
|
8916
|
+
import { createHash as createHash6 } from "crypto";
|
|
8681
8917
|
import { lstatSync as lstatSync7, opendirSync as opendirSync2 } from "fs";
|
|
8682
8918
|
import { dirname as dirname7, isAbsolute as isAbsolute7, join as join92, resolve as resolve7 } from "path";
|
|
8683
8919
|
import { createHash as createHash7 } from "crypto";
|
|
@@ -8752,7 +8988,6 @@ import { closeSync as closeSync19, constants as constants20, fstatSync as fstatS
|
|
|
8752
8988
|
import { basename as basename14, dirname as dirname25, isAbsolute as isAbsolute27, resolve as resolve26 } from "path";
|
|
8753
8989
|
import { createHash as createHash29 } from "crypto";
|
|
8754
8990
|
import { isAbsolute as isAbsolute30 } from "path";
|
|
8755
|
-
import { createHash as createHash34 } from "crypto";
|
|
8756
8991
|
var __defProp2 = Object.defineProperty;
|
|
8757
8992
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
8758
8993
|
var __returnValue2 = (v) => v;
|
|
@@ -15604,10 +15839,10 @@ var SKILLS_HOME_ENV = "SKILLS_HOME";
|
|
|
15604
15839
|
var DEFAULT_SQLITE_FILENAME = "server.db";
|
|
15605
15840
|
var GLOBAL_CONFIG_FILENAME = "config.json";
|
|
15606
15841
|
function effectiveHome() {
|
|
15607
|
-
return process.env["HOME"] || process.env["USERPROFILE"] ||
|
|
15842
|
+
return process.env["HOME"] || process.env["USERPROFILE"] || homedir6() || "/tmp";
|
|
15608
15843
|
}
|
|
15609
15844
|
function legacyDataRoot() {
|
|
15610
|
-
return
|
|
15845
|
+
return join11(effectiveHome(), ".hasna", "skills");
|
|
15611
15846
|
}
|
|
15612
15847
|
function resolverDataRoot(home = effectiveHome(), env) {
|
|
15613
15848
|
return dataDir2({ app: "skills", home, env });
|
|
@@ -15616,13 +15851,13 @@ function adoptResolverDataRoot2(resolved, env = process.env) {
|
|
|
15616
15851
|
const dataOverride = env.HASNA_DATA_HOME;
|
|
15617
15852
|
if (typeof dataOverride === "string" && dataOverride.trim().length > 0)
|
|
15618
15853
|
return true;
|
|
15619
|
-
return existsSync10(
|
|
15854
|
+
return existsSync10(join11(resolved, DEFAULT_SQLITE_FILENAME)) || existsSync10(join11(resolved, GLOBAL_CONFIG_FILENAME));
|
|
15620
15855
|
}
|
|
15621
15856
|
function exactDataRoot() {
|
|
15622
15857
|
for (const key of [DATA_DIR_ENV, HASNA_SKILLS_HOME_ENV, SKILLS_HOME_ENV]) {
|
|
15623
15858
|
const dir = process.env[key]?.trim();
|
|
15624
15859
|
if (dir)
|
|
15625
|
-
return
|
|
15860
|
+
return resolve4(dir);
|
|
15626
15861
|
}
|
|
15627
15862
|
return;
|
|
15628
15863
|
}
|
|
@@ -15631,7 +15866,7 @@ function getDataRoot() {
|
|
|
15631
15866
|
if (exact)
|
|
15632
15867
|
return exact;
|
|
15633
15868
|
const resolved = resolverDataRoot();
|
|
15634
|
-
return adoptResolverDataRoot2(resolved) ?
|
|
15869
|
+
return adoptResolverDataRoot2(resolved) ? resolve4(resolved) : resolve4(legacyDataRoot());
|
|
15635
15870
|
}
|
|
15636
15871
|
function getDataDirReadOnly() {
|
|
15637
15872
|
return getDataRoot();
|
|
@@ -15729,132 +15964,7 @@ class SkillEntryPaths {
|
|
|
15729
15964
|
this.files.add(key);
|
|
15730
15965
|
}
|
|
15731
15966
|
}
|
|
15732
|
-
var CONTENT_HASH_ALGORITHM = "sha256";
|
|
15733
15967
|
var HASH_EXCLUDE_DIRS = new Set([".git", "node_modules", "dist", "build", ".turbo"]);
|
|
15734
|
-
function excludedHashEntry(name, directory) {
|
|
15735
|
-
return name.startsWith(".") || directory && HASH_EXCLUDE_DIRS.has(name);
|
|
15736
|
-
}
|
|
15737
|
-
var HASH_COVERAGE = [
|
|
15738
|
-
"SKILL.md",
|
|
15739
|
-
"skill.json",
|
|
15740
|
-
"AGENTS.md",
|
|
15741
|
-
"package.json",
|
|
15742
|
-
"tsconfig.json",
|
|
15743
|
-
"src",
|
|
15744
|
-
"scripts",
|
|
15745
|
-
"assets",
|
|
15746
|
-
"references"
|
|
15747
|
-
];
|
|
15748
|
-
function normalizeLineEndings(content) {
|
|
15749
|
-
return content.replace(/\r\n/g, `
|
|
15750
|
-
`).replace(/\r/g, `
|
|
15751
|
-
`);
|
|
15752
|
-
}
|
|
15753
|
-
function canonicalizeManifest(raw) {
|
|
15754
|
-
let parsed;
|
|
15755
|
-
try {
|
|
15756
|
-
parsed = JSON.parse(raw);
|
|
15757
|
-
} catch {
|
|
15758
|
-
return normalizeLineEndings(raw);
|
|
15759
|
-
}
|
|
15760
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
15761
|
-
return normalizeLineEndings(raw);
|
|
15762
|
-
}
|
|
15763
|
-
const record = parsed;
|
|
15764
|
-
delete record.content_hash;
|
|
15765
|
-
if (record.provenance && typeof record.provenance === "object" && !Array.isArray(record.provenance)) {
|
|
15766
|
-
delete record.provenance.content_hash;
|
|
15767
|
-
}
|
|
15768
|
-
return `${JSON.stringify(sortObjectKeys(record), null, 2)}
|
|
15769
|
-
`;
|
|
15770
|
-
}
|
|
15771
|
-
function sortObjectKeys(value) {
|
|
15772
|
-
if (Array.isArray(value))
|
|
15773
|
-
return value.map((item) => sortObjectKeys(item));
|
|
15774
|
-
if (typeof value === "object" && value !== null) {
|
|
15775
|
-
const record = value;
|
|
15776
|
-
const sorted = Object.create(null);
|
|
15777
|
-
for (const key of Object.keys(record).sort())
|
|
15778
|
-
sorted[key] = sortObjectKeys(record[key]);
|
|
15779
|
-
return sorted;
|
|
15780
|
-
}
|
|
15781
|
-
return value;
|
|
15782
|
-
}
|
|
15783
|
-
function looksLikeText(buffer) {
|
|
15784
|
-
return !buffer.includes(0);
|
|
15785
|
-
}
|
|
15786
|
-
function collectBundleFiles(skillPath) {
|
|
15787
|
-
const files = [];
|
|
15788
|
-
const seen = new Set;
|
|
15789
|
-
for (const entry of HASH_COVERAGE) {
|
|
15790
|
-
if (seen.has(entry))
|
|
15791
|
-
continue;
|
|
15792
|
-
seen.add(entry);
|
|
15793
|
-
const absolute = join52(skillPath, entry);
|
|
15794
|
-
if (!existsSync52(absolute))
|
|
15795
|
-
continue;
|
|
15796
|
-
if (statSync4(absolute).isDirectory())
|
|
15797
|
-
collectDirectory(files, absolute, entry);
|
|
15798
|
-
else
|
|
15799
|
-
collectFile(files, absolute, entry);
|
|
15800
|
-
}
|
|
15801
|
-
return files.sort((a, b) => a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0);
|
|
15802
|
-
}
|
|
15803
|
-
function collectDirectory(files, dir, rel) {
|
|
15804
|
-
for (const entry of readdirSync3(dir).sort()) {
|
|
15805
|
-
if (entry.startsWith("."))
|
|
15806
|
-
continue;
|
|
15807
|
-
const absolute = join52(dir, entry);
|
|
15808
|
-
const childRel = `${rel}/${entry}`;
|
|
15809
|
-
let stats;
|
|
15810
|
-
try {
|
|
15811
|
-
stats = statSync4(absolute);
|
|
15812
|
-
} catch {
|
|
15813
|
-
continue;
|
|
15814
|
-
}
|
|
15815
|
-
if (stats.isSymbolicLink())
|
|
15816
|
-
continue;
|
|
15817
|
-
if (stats.isDirectory()) {
|
|
15818
|
-
if (excludedHashEntry(entry, true))
|
|
15819
|
-
continue;
|
|
15820
|
-
collectDirectory(files, absolute, childRel);
|
|
15821
|
-
} else if (stats.isFile()) {
|
|
15822
|
-
collectFile(files, absolute, childRel);
|
|
15823
|
-
}
|
|
15824
|
-
}
|
|
15825
|
-
}
|
|
15826
|
-
function collectFile(files, absolute, rel) {
|
|
15827
|
-
const buffer = readFileSync42(absolute);
|
|
15828
|
-
files.push(normalizeBundleFile(rel.split(sep2).join("/"), buffer));
|
|
15829
|
-
}
|
|
15830
|
-
function normalizeBundleFile(rel, buffer) {
|
|
15831
|
-
if (rel === "skill.json") {
|
|
15832
|
-
return { rel, content: new TextEncoder().encode(canonicalizeManifest(new TextDecoder().decode(buffer))) };
|
|
15833
|
-
}
|
|
15834
|
-
if (looksLikeText(buffer)) {
|
|
15835
|
-
const normalized = normalizeLineEndings(new TextDecoder().decode(buffer));
|
|
15836
|
-
return { rel, content: new TextEncoder().encode(normalized) };
|
|
15837
|
-
}
|
|
15838
|
-
return { rel, content: buffer };
|
|
15839
|
-
}
|
|
15840
|
-
function computeContentHash(skillPath) {
|
|
15841
|
-
return hashBundleFiles(collectBundleFiles(skillPath));
|
|
15842
|
-
}
|
|
15843
|
-
function* bundleHashParts(files) {
|
|
15844
|
-
for (const file of files) {
|
|
15845
|
-
yield new TextEncoder().encode(file.rel);
|
|
15846
|
-
yield new TextEncoder().encode(`\x00${file.content.length}\x00`);
|
|
15847
|
-
yield file.content;
|
|
15848
|
-
yield new TextEncoder().encode("\x00");
|
|
15849
|
-
}
|
|
15850
|
-
yield new TextEncoder().encode("\x00");
|
|
15851
|
-
}
|
|
15852
|
-
function hashBundleFiles(files) {
|
|
15853
|
-
const hash = createHash6(CONTENT_HASH_ALGORITHM);
|
|
15854
|
-
for (const part of bundleHashParts(files))
|
|
15855
|
-
hash.update(part);
|
|
15856
|
-
return hash.digest("hex");
|
|
15857
|
-
}
|
|
15858
15968
|
var CONTENT_HASH_LIMITS = Object.freeze({
|
|
15859
15969
|
entries: 1024,
|
|
15860
15970
|
rawBytes: 64 * 1024 * 1024,
|
|
@@ -15869,173 +15979,6 @@ var CONTENT_HASH_LIMITS = Object.freeze({
|
|
|
15869
15979
|
var typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
15870
15980
|
var byteLengthOf = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteLength").get;
|
|
15871
15981
|
var bufferOf = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
|
|
15872
|
-
function verifyContentHash(skillPath, manifest) {
|
|
15873
|
-
const declaredHash = manifest?.provenance?.content_hash?.trim() || undefined;
|
|
15874
|
-
if (!declaredHash)
|
|
15875
|
-
return { declared: false, valid: false };
|
|
15876
|
-
if (!/^[a-f0-9]{64}$/.test(declaredHash)) {
|
|
15877
|
-
return { declared: true, valid: false, declaredHash };
|
|
15878
|
-
}
|
|
15879
|
-
const computedHash = computeContentHash(skillPath);
|
|
15880
|
-
return {
|
|
15881
|
-
declared: true,
|
|
15882
|
-
valid: computedHash === declaredHash,
|
|
15883
|
-
declaredHash,
|
|
15884
|
-
computedHash
|
|
15885
|
-
};
|
|
15886
|
-
}
|
|
15887
|
-
var PORTABLE_SKILL_STANDARD = "hasna.skill.v1";
|
|
15888
|
-
var SKILL_RUNTIMES = ["bun", "node", "python3"];
|
|
15889
|
-
var SKILL_SANDBOX_MODES = ["readonly-fs", "workspace-write", "full"];
|
|
15890
|
-
var SKILL_SYSTEM_DEPS_ALLOWLIST = [
|
|
15891
|
-
"ffmpeg",
|
|
15892
|
-
"ffprobe",
|
|
15893
|
-
"imagemagick",
|
|
15894
|
-
"convert",
|
|
15895
|
-
"curl",
|
|
15896
|
-
"wget",
|
|
15897
|
-
"git",
|
|
15898
|
-
"gh",
|
|
15899
|
-
"jq",
|
|
15900
|
-
"python3",
|
|
15901
|
-
"pip3",
|
|
15902
|
-
"node",
|
|
15903
|
-
"bun",
|
|
15904
|
-
"npm",
|
|
15905
|
-
"rsync",
|
|
15906
|
-
"pdftotext",
|
|
15907
|
-
"tesseract",
|
|
15908
|
-
"7z",
|
|
15909
|
-
"unzip",
|
|
15910
|
-
"zip"
|
|
15911
|
-
];
|
|
15912
|
-
var SEMVER_PATTERN2 = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
|
|
15913
|
-
var CONTENT_HASH_PATTERN = "^[a-f0-9]{64}$";
|
|
15914
|
-
var ENV_REFERENCE_PATTERN = "^[A-Z0-9_]+$";
|
|
15915
|
-
var MAX_RUNTIME_TIMEOUT_SECONDS = 900;
|
|
15916
|
-
function add2(target, code, message) {
|
|
15917
|
-
target.push({ code, message });
|
|
15918
|
-
}
|
|
15919
|
-
function isRecord(value) {
|
|
15920
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15921
|
-
}
|
|
15922
|
-
function isNonEmptyString(value) {
|
|
15923
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
15924
|
-
}
|
|
15925
|
-
function validatePortableManifestContract(manifest, options = {}) {
|
|
15926
|
-
const issues = [];
|
|
15927
|
-
if (!manifest) {
|
|
15928
|
-
add2(issues, "contract.manifest_missing", "No portable manifest to validate");
|
|
15929
|
-
return issues;
|
|
15930
|
-
}
|
|
15931
|
-
if (manifest.standard !== PORTABLE_SKILL_STANDARD) {
|
|
15932
|
-
add2(issues, "contract.standard_invalid", `standard must be '${PORTABLE_SKILL_STANDARD}'`);
|
|
15933
|
-
}
|
|
15934
|
-
if (!/^[a-z0-9][a-z0-9._-]*$/.test(manifest.name)) {
|
|
15935
|
-
add2(issues, "contract.name_invalid", `name '${manifest.name}' must be a lowercase slug (letters, numbers, dots, underscores, hyphens)`);
|
|
15936
|
-
}
|
|
15937
|
-
if (!isNonEmptyString(manifest.description)) {
|
|
15938
|
-
add2(issues, "contract.description_missing", "description is required");
|
|
15939
|
-
}
|
|
15940
|
-
if (!isNonEmptyString(manifest.version)) {
|
|
15941
|
-
add2(issues, "contract.version_missing", "version is required");
|
|
15942
|
-
} else if (!new RegExp(SEMVER_PATTERN2).test(manifest.version)) {
|
|
15943
|
-
add2(issues, "contract.version_invalid", `version '${manifest.version}' is not valid semver`);
|
|
15944
|
-
}
|
|
15945
|
-
validateRuntimeContract(manifest, issues, options.strict === true);
|
|
15946
|
-
const provenance = manifest.provenance;
|
|
15947
|
-
if (provenance && !isRecord(provenance)) {
|
|
15948
|
-
add2(issues, "contract.provenance_invalid", "provenance must be an object");
|
|
15949
|
-
} else {
|
|
15950
|
-
const sourceCommit = provenance?.source_commit;
|
|
15951
|
-
if (sourceCommit !== undefined && sourceCommit !== null && !isNonEmptyString(sourceCommit)) {
|
|
15952
|
-
add2(issues, "contract.source_commit_invalid", "provenance.source_commit must be a string");
|
|
15953
|
-
}
|
|
15954
|
-
const changelog = provenance?.changelog;
|
|
15955
|
-
if (changelog !== undefined && changelog !== null && !isNonEmptyString(changelog)) {
|
|
15956
|
-
add2(issues, "contract.changelog_invalid", "provenance.changelog must be a string");
|
|
15957
|
-
}
|
|
15958
|
-
const declaredHash = provenance?.content_hash;
|
|
15959
|
-
if (options.strict && !isNonEmptyString(declaredHash)) {
|
|
15960
|
-
add2(issues, "contract.content_hash_missing", "provenance.content_hash is required: a portable manifest must carry its canonical content hash");
|
|
15961
|
-
} else if (isNonEmptyString(declaredHash) && !new RegExp(CONTENT_HASH_PATTERN).test(declaredHash)) {
|
|
15962
|
-
add2(issues, "contract.content_hash_invalid", "provenance.content_hash must be a 64-character lowercase hex SHA-256");
|
|
15963
|
-
} else if (options.skillPath && isNonEmptyString(declaredHash)) {
|
|
15964
|
-
const verification = verifyContentHash(options.skillPath, manifest);
|
|
15965
|
-
if (!verification.valid) {
|
|
15966
|
-
add2(issues, "contract.content_hash_mismatch", `provenance.content_hash does not match the bundle: declared ${verification.declaredHash}, computed ${verification.computedHash}. Content changed without re-hashing (a content change requires a version bump too).`);
|
|
15967
|
-
}
|
|
15968
|
-
}
|
|
15969
|
-
}
|
|
15970
|
-
return issues;
|
|
15971
|
-
}
|
|
15972
|
-
function validateRuntimeContract(manifest, issues, strict) {
|
|
15973
|
-
const runtime = manifest.runtime;
|
|
15974
|
-
if (runtime === undefined) {
|
|
15975
|
-
if (strict && manifest.kind !== "instruction") {
|
|
15976
|
-
add2(issues, "contract.runtime_missing", "runtime contract is required: { runtime, entrypoint?, timeout?, needs_network?, env?, sandbox?, system_deps?, artifacts? }");
|
|
15977
|
-
}
|
|
15978
|
-
return;
|
|
15979
|
-
}
|
|
15980
|
-
if (!isRecord(runtime)) {
|
|
15981
|
-
add2(issues, "contract.runtime_invalid", "runtime must be an object");
|
|
15982
|
-
return;
|
|
15983
|
-
}
|
|
15984
|
-
const runtimeName = runtime.runtime;
|
|
15985
|
-
if (!SKILL_RUNTIMES.includes(runtimeName)) {
|
|
15986
|
-
add2(issues, "contract.runtime_invalid", `runtime.runtime must be one of: ${SKILL_RUNTIMES.join(", ")}`);
|
|
15987
|
-
}
|
|
15988
|
-
if (runtime.version !== undefined && runtime.version !== null && !isNonEmptyString(runtime.version)) {
|
|
15989
|
-
add2(issues, "contract.runtime_version_invalid", "runtime.version must be a string");
|
|
15990
|
-
}
|
|
15991
|
-
if (runtime.entrypoint !== undefined && runtime.entrypoint !== null && !isNonEmptyString(runtime.entrypoint)) {
|
|
15992
|
-
add2(issues, "contract.entrypoint_invalid", "runtime.entrypoint must be a relative path string");
|
|
15993
|
-
}
|
|
15994
|
-
if (runtime.timeout !== undefined && runtime.timeout !== null) {
|
|
15995
|
-
if (typeof runtime.timeout !== "number" || !Number.isInteger(runtime.timeout) || runtime.timeout < 1 || runtime.timeout > MAX_RUNTIME_TIMEOUT_SECONDS) {
|
|
15996
|
-
add2(issues, "contract.timeout_invalid", `runtime.timeout must be an integer between 1 and ${MAX_RUNTIME_TIMEOUT_SECONDS} seconds`);
|
|
15997
|
-
}
|
|
15998
|
-
}
|
|
15999
|
-
if (runtime.needs_network !== undefined && runtime.needs_network !== null && typeof runtime.needs_network !== "boolean") {
|
|
16000
|
-
add2(issues, "contract.needs_network_invalid", "runtime.needs_network must be a boolean");
|
|
16001
|
-
}
|
|
16002
|
-
if (runtime.env !== undefined && runtime.env !== null) {
|
|
16003
|
-
if (!Array.isArray(runtime.env)) {
|
|
16004
|
-
add2(issues, "contract.env_invalid", "runtime.env must be an array of secret REFERENCE names");
|
|
16005
|
-
} else {
|
|
16006
|
-
for (const reference of runtime.env) {
|
|
16007
|
-
if (typeof reference !== "string" || !new RegExp(ENV_REFERENCE_PATTERN).test(reference)) {
|
|
16008
|
-
add2(issues, "contract.env_invalid", `runtime.env entry '${String(reference)}' must be an uppercase identifier (e.g. OPENAI_API_KEY) \u2014 names only, never values`);
|
|
16009
|
-
}
|
|
16010
|
-
}
|
|
16011
|
-
}
|
|
16012
|
-
}
|
|
16013
|
-
if (runtime.sandbox !== undefined && runtime.sandbox !== null && !SKILL_SANDBOX_MODES.includes(runtime.sandbox)) {
|
|
16014
|
-
add2(issues, "contract.sandbox_invalid", `runtime.sandbox must be one of: ${SKILL_SANDBOX_MODES.join(", ")}`);
|
|
16015
|
-
}
|
|
16016
|
-
if (runtime.system_deps !== undefined && runtime.system_deps !== null) {
|
|
16017
|
-
if (!Array.isArray(runtime.system_deps)) {
|
|
16018
|
-
add2(issues, "contract.system_deps_invalid", "runtime.system_deps must be an array");
|
|
16019
|
-
} else {
|
|
16020
|
-
for (const dep of runtime.system_deps) {
|
|
16021
|
-
if (!SKILL_SYSTEM_DEPS_ALLOWLIST.includes(dep)) {
|
|
16022
|
-
add2(issues, "contract.system_dep_not_allowed", `runtime.system_deps entry '${dep}' is not on the allowlist: ${SKILL_SYSTEM_DEPS_ALLOWLIST.join(", ")}`);
|
|
16023
|
-
}
|
|
16024
|
-
}
|
|
16025
|
-
}
|
|
16026
|
-
}
|
|
16027
|
-
if (runtime.artifacts !== undefined && runtime.artifacts !== null) {
|
|
16028
|
-
if (!Array.isArray(runtime.artifacts)) {
|
|
16029
|
-
add2(issues, "contract.artifacts_invalid", "runtime.artifacts must be an array of glob patterns");
|
|
16030
|
-
} else {
|
|
16031
|
-
for (const glob of runtime.artifacts) {
|
|
16032
|
-
if (!isNonEmptyString(glob)) {
|
|
16033
|
-
add2(issues, "contract.artifacts_invalid", "runtime.artifacts entries must be non-empty glob strings");
|
|
16034
|
-
}
|
|
16035
|
-
}
|
|
16036
|
-
}
|
|
16037
|
-
}
|
|
16038
|
-
}
|
|
16039
15982
|
var ANY_SEGMENT_COPY_EXCLUDES = new Set([
|
|
16040
15983
|
".git",
|
|
16041
15984
|
".DS_Store",
|
|
@@ -16725,14 +16668,14 @@ function captureClaudeMarketplaceEntry(path, marketplace, plugin, budget2 = { re
|
|
|
16725
16668
|
return { path, hashMode: CLAUDE_MARKETPLACE_ENTRY_HASH_MODE, marketplace, plugin, sha256: hashClaudeMarketplaceEntry(text, { marketplace, plugin }) };
|
|
16726
16669
|
}
|
|
16727
16670
|
var CLAUDE_ORPHAN_MARKER_MODE = "claude-plugin-orphaned-at-v1";
|
|
16728
|
-
var CACHE = `${
|
|
16671
|
+
var CACHE = `${sep2}.claude${sep2}plugins${sep2}cache${sep2}`;
|
|
16729
16672
|
function isClaudePluginCacheOrphanMarker(path) {
|
|
16730
|
-
if (typeof path !== "string" || basename4(path) !== ".orphaned_at" || !isAbsolute4(path) ||
|
|
16673
|
+
if (typeof path !== "string" || basename4(path) !== ".orphaned_at" || !isAbsolute4(path) || resolve42(path) !== path || path.includes("\x00"))
|
|
16731
16674
|
return false;
|
|
16732
16675
|
const at = path.indexOf(CACHE);
|
|
16733
16676
|
if (at < 0 || path.indexOf(CACHE, at + 1) >= 0)
|
|
16734
16677
|
return false;
|
|
16735
|
-
const parts = path.slice(at + CACHE.length).split(
|
|
16678
|
+
const parts = path.slice(at + CACHE.length).split(sep2);
|
|
16736
16679
|
return parts.length === 4 && parts.every((part) => part && part !== "." && part !== "..");
|
|
16737
16680
|
}
|
|
16738
16681
|
function same(left, right) {
|
|
@@ -17181,10 +17124,10 @@ function assertHermesEnvironment(home) {
|
|
|
17181
17124
|
throw new Error("NATIVE_SKILL_DRIFT: Hermes project plugins require a dedicated discovery review");
|
|
17182
17125
|
}
|
|
17183
17126
|
function read(path) {
|
|
17184
|
-
for (let current2 = path;; current2 =
|
|
17127
|
+
for (let current2 = path;; current2 = dirname62(current2)) {
|
|
17185
17128
|
if (lstatSync6(current2, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
17186
17129
|
throw new Error("NATIVE_SKILL_DRIFT: symlink Hermes protection input");
|
|
17187
|
-
if (
|
|
17130
|
+
if (dirname62(current2) === current2)
|
|
17188
17131
|
break;
|
|
17189
17132
|
}
|
|
17190
17133
|
const stat = lstatSync6(path, { throwIfNoEntry: false });
|
|
@@ -17224,10 +17167,10 @@ function assertHermesProtection(home, config, command, profile, supervisor2) {
|
|
|
17224
17167
|
}
|
|
17225
17168
|
function assertNoHermesLegacyShadow(root) {
|
|
17226
17169
|
let entries = 0;
|
|
17227
|
-
for (let cursor = resolve6(root);; cursor =
|
|
17170
|
+
for (let cursor = resolve6(root);; cursor = dirname62(cursor)) {
|
|
17228
17171
|
if (lstatSync6(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
17229
17172
|
throw new Error("NATIVE_SKILL_DRIFT: symlink Hermes legacy discovery root");
|
|
17230
|
-
if (
|
|
17173
|
+
if (dirname62(cursor) === cursor)
|
|
17231
17174
|
break;
|
|
17232
17175
|
}
|
|
17233
17176
|
function scan(path, depth) {
|
|
@@ -17344,7 +17287,7 @@ function capture(path, budget2, excludedRoots, omittedRoots = [], rows) {
|
|
|
17344
17287
|
if (!root)
|
|
17345
17288
|
return { path, sha256: null };
|
|
17346
17289
|
need3(root.isDirectory(), "Unsupported native discovery directory input");
|
|
17347
|
-
const hash =
|
|
17290
|
+
const hash = createHash6("sha256");
|
|
17348
17291
|
function walk(current2, relative2, before, depth) {
|
|
17349
17292
|
need3(depth <= 64, "Native discovery directory depth limit exceeded");
|
|
17350
17293
|
const names = [], directory = opendirSync2(current2);
|
|
@@ -17396,7 +17339,7 @@ function verifyDiscoveryDirectoryProjection(directories, omittedRoots, tolerance
|
|
|
17396
17339
|
const expected = directories.map((directory) => {
|
|
17397
17340
|
safe2(directory.path);
|
|
17398
17341
|
need3(Array.isArray(directory.entries), "Missing reviewed directory membership inventory");
|
|
17399
|
-
const hash =
|
|
17342
|
+
const hash = createHash6("sha256");
|
|
17400
17343
|
const kept = [];
|
|
17401
17344
|
for (const row of directory.entries) {
|
|
17402
17345
|
need3(typeof row === "string" && ++count <= AGENT_POLICY_LIMITS.discoveryDirectoryEntries, "Invalid reviewed directory membership rows");
|
|
@@ -17412,7 +17355,7 @@ function verifyDiscoveryDirectoryProjection(directories, omittedRoots, tolerance
|
|
|
17412
17355
|
}
|
|
17413
17356
|
need3(directory.sha256 === null ? directory.entries.length === 0 : hash.digest("hex") === directory.sha256, "Reviewed directory inventory does not match its fingerprint");
|
|
17414
17357
|
const absent = omittedRoots.some((root) => directory.path === root || directory.path.startsWith(root + "/"));
|
|
17415
|
-
return { path: directory.path, sha256: absent || directory.sha256 === null ? null :
|
|
17358
|
+
return { path: directory.path, sha256: absent || directory.sha256 === null ? null : createHash6("sha256").update(kept.join("")).digest("hex") };
|
|
17416
17359
|
});
|
|
17417
17360
|
const current2 = captureDiscoveryDirectoryProjection(directories.map((item) => item.path), omittedRoots);
|
|
17418
17361
|
for (let i = 0;i < current2.length; i++)
|
|
@@ -17500,7 +17443,6 @@ function hashRawDiscoveryFile(path, budget2, changes) {
|
|
|
17500
17443
|
closeSync4(fd);
|
|
17501
17444
|
}
|
|
17502
17445
|
}
|
|
17503
|
-
var BLOCK = 512;
|
|
17504
17446
|
var ANY_SEGMENT_EXCLUDES = new Set([
|
|
17505
17447
|
".git",
|
|
17506
17448
|
".ds_store",
|
|
@@ -17630,136 +17572,6 @@ var SKILL_BUNDLE_INSPECTION_LIMITS = Object.freeze({
|
|
|
17630
17572
|
pathBytes: 100,
|
|
17631
17573
|
timeoutMs: 5000
|
|
17632
17574
|
});
|
|
17633
|
-
|
|
17634
|
-
class SkillBundleInspectionError extends Error {
|
|
17635
|
-
code;
|
|
17636
|
-
constructor(code, message) {
|
|
17637
|
-
super(message);
|
|
17638
|
-
this.code = code;
|
|
17639
|
-
this.name = "SkillBundleInspectionError";
|
|
17640
|
-
}
|
|
17641
|
-
}
|
|
17642
|
-
function invalidBundle(message) {
|
|
17643
|
-
throw new SkillBundleInspectionError("BUNDLE_INVALID", message);
|
|
17644
|
-
}
|
|
17645
|
-
class BoundedTarReader {
|
|
17646
|
-
limits;
|
|
17647
|
-
check;
|
|
17648
|
-
header = new Uint8Array(BLOCK);
|
|
17649
|
-
headerOffset = 0;
|
|
17650
|
-
pending;
|
|
17651
|
-
bodyOffset = 0;
|
|
17652
|
-
padding = 0;
|
|
17653
|
-
zeroBlocks = 0;
|
|
17654
|
-
entries = [];
|
|
17655
|
-
paths = new SkillEntryPaths;
|
|
17656
|
-
fileBytes = 0;
|
|
17657
|
-
constructor(limits, check) {
|
|
17658
|
-
this.limits = limits;
|
|
17659
|
-
this.check = check;
|
|
17660
|
-
}
|
|
17661
|
-
push(chunk) {
|
|
17662
|
-
let offset = 0;
|
|
17663
|
-
while (offset < chunk.byteLength) {
|
|
17664
|
-
this.check();
|
|
17665
|
-
if (this.pending) {
|
|
17666
|
-
const count = Math.min(this.pending.bytes.byteLength - this.bodyOffset, chunk.byteLength - offset);
|
|
17667
|
-
this.pending.bytes.set(chunk.subarray(offset, offset + count), this.bodyOffset);
|
|
17668
|
-
offset += count;
|
|
17669
|
-
this.bodyOffset += count;
|
|
17670
|
-
if (this.bodyOffset === this.pending.bytes.byteLength) {
|
|
17671
|
-
this.entries.push(this.pending);
|
|
17672
|
-
this.pending = undefined;
|
|
17673
|
-
}
|
|
17674
|
-
} else if (this.padding) {
|
|
17675
|
-
const count = Math.min(this.padding, chunk.byteLength - offset);
|
|
17676
|
-
if (chunk.subarray(offset, offset + count).some((byte) => byte !== 0))
|
|
17677
|
-
invalidBundle("Nonzero tar body padding");
|
|
17678
|
-
offset += count;
|
|
17679
|
-
this.padding -= count;
|
|
17680
|
-
} else {
|
|
17681
|
-
const count = Math.min(BLOCK - this.headerOffset, chunk.byteLength - offset);
|
|
17682
|
-
this.header.set(chunk.subarray(offset, offset + count), this.headerOffset);
|
|
17683
|
-
offset += count;
|
|
17684
|
-
this.headerOffset += count;
|
|
17685
|
-
if (this.headerOffset === BLOCK) {
|
|
17686
|
-
this.readHeader();
|
|
17687
|
-
this.headerOffset = 0;
|
|
17688
|
-
}
|
|
17689
|
-
}
|
|
17690
|
-
}
|
|
17691
|
-
}
|
|
17692
|
-
finish() {
|
|
17693
|
-
this.check();
|
|
17694
|
-
if (this.pending || this.padding || this.headerOffset || this.zeroBlocks < 2)
|
|
17695
|
-
invalidBundle("Truncated tar bundle");
|
|
17696
|
-
return this.entries;
|
|
17697
|
-
}
|
|
17698
|
-
readHeader() {
|
|
17699
|
-
this.check();
|
|
17700
|
-
const h = this.header;
|
|
17701
|
-
if (h.every((byte) => byte === 0)) {
|
|
17702
|
-
this.zeroBlocks++;
|
|
17703
|
-
return;
|
|
17704
|
-
}
|
|
17705
|
-
if (this.zeroBlocks)
|
|
17706
|
-
invalidBundle("Nonzero tar data after terminator");
|
|
17707
|
-
if (this.entries.length >= this.limits.entries)
|
|
17708
|
-
throw new SkillBundleInspectionError("BUNDLE_LIMIT", "Bundle entry limit exceeded");
|
|
17709
|
-
let checksum = 0;
|
|
17710
|
-
for (let i = 0;i < BLOCK; i++)
|
|
17711
|
-
checksum += i >= 148 && i < 156 ? 32 : h[i];
|
|
17712
|
-
if (tarOctal(h.subarray(148, 156)) !== checksum)
|
|
17713
|
-
invalidBundle("Invalid tar header checksum");
|
|
17714
|
-
if (new TextDecoder().decode(h.subarray(257, 265)) !== "ustar\x00" + "00")
|
|
17715
|
-
invalidBundle("Unsupported tar format");
|
|
17716
|
-
if (h[156] !== 48 && h[156] !== 0 || h.subarray(157, 257).some((b) => b !== 0) || h.subarray(345).some((b) => b !== 0))
|
|
17717
|
-
invalidBundle("Unsupported tar entry or path prefix");
|
|
17718
|
-
const mode = tarOctal(h.subarray(100, 108));
|
|
17719
|
-
if (mode > 511)
|
|
17720
|
-
invalidBundle("Unsupported tar permission bits");
|
|
17721
|
-
tarOctal(h.subarray(108, 116));
|
|
17722
|
-
tarOctal(h.subarray(116, 124));
|
|
17723
|
-
tarOctal(h.subarray(136, 148));
|
|
17724
|
-
const size = tarOctal(h.subarray(124, 136));
|
|
17725
|
-
if (size > this.limits.fileBytes || this.fileBytes + size > this.limits.decompressedBytes) {
|
|
17726
|
-
throw new SkillBundleInspectionError("BUNDLE_LIMIT", "Bundle file byte limit exceeded");
|
|
17727
|
-
}
|
|
17728
|
-
const name = h.subarray(0, 100);
|
|
17729
|
-
const end = name.indexOf(0);
|
|
17730
|
-
if (end !== -1 && name.subarray(end).some((b) => b !== 0))
|
|
17731
|
-
invalidBundle("Invalid tar path padding");
|
|
17732
|
-
const raw = end === -1 ? name : name.subarray(0, end);
|
|
17733
|
-
if (raw.byteLength > this.limits.pathBytes)
|
|
17734
|
-
throw new SkillBundleInspectionError("BUNDLE_LIMIT", "Bundle path byte limit exceeded");
|
|
17735
|
-
let path;
|
|
17736
|
-
try {
|
|
17737
|
-
path = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(raw);
|
|
17738
|
-
} catch {
|
|
17739
|
-
return invalidBundle("Invalid UTF-8 bundle path");
|
|
17740
|
-
}
|
|
17741
|
-
this.paths.add(path, this.limits.pathBytes, invalidBundle, () => {
|
|
17742
|
-
throw new SkillBundleInspectionError("BUNDLE_LIMIT", "Bundle path byte limit exceeded");
|
|
17743
|
-
});
|
|
17744
|
-
this.fileBytes += size;
|
|
17745
|
-
this.pending = { path, mode, bytes: new Uint8Array(new ArrayBuffer(size)) };
|
|
17746
|
-
this.bodyOffset = 0;
|
|
17747
|
-
this.padding = (BLOCK - size % BLOCK) % BLOCK;
|
|
17748
|
-
if (!size) {
|
|
17749
|
-
this.entries.push(this.pending);
|
|
17750
|
-
this.pending = undefined;
|
|
17751
|
-
}
|
|
17752
|
-
}
|
|
17753
|
-
}
|
|
17754
|
-
function tarOctal(field2) {
|
|
17755
|
-
const text2 = new TextDecoder().decode(field2);
|
|
17756
|
-
if (!/^[0-7]+[\0 ]*$/.test(text2))
|
|
17757
|
-
invalidBundle("Invalid tar octal field");
|
|
17758
|
-
const value = Number.parseInt(text2, 8);
|
|
17759
|
-
if (!Number.isSafeInteger(value))
|
|
17760
|
-
invalidBundle("Tar integer is out of range");
|
|
17761
|
-
return value;
|
|
17762
|
-
}
|
|
17763
17575
|
var SKILL_VERSION_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/;
|
|
17764
17576
|
function isValidSkillVersion(value) {
|
|
17765
17577
|
return typeof value === "string" && SKILL_VERSION_PATTERN.test(value) && !/^\.+$/.test(value) && !value.includes("..");
|
|
@@ -20986,50 +20798,6 @@ var SKILLS_API_URL_ENV_KEYS = ENV_KEYS.apiUrlKeys;
|
|
|
20986
20798
|
var SKILLS_API_KEY_ENV_KEYS = ENV_KEYS.apiKeyKeys;
|
|
20987
20799
|
var SKILLS_API_URL_ENV = SKILLS_API_URL_ENV_KEYS[0];
|
|
20988
20800
|
var SKILLS_API_KEY_ENV = SKILLS_API_KEY_ENV_KEYS[0];
|
|
20989
|
-
|
|
20990
|
-
class SkillsFleetCredentialError extends Error {
|
|
20991
|
-
code;
|
|
20992
|
-
next;
|
|
20993
|
-
constructor(message, code = "MISSING_API_CREDENTIAL", next) {
|
|
20994
|
-
super(message);
|
|
20995
|
-
this.name = "SkillsFleetCredentialError";
|
|
20996
|
-
this.code = code;
|
|
20997
|
-
if (next)
|
|
20998
|
-
this.next = next;
|
|
20999
|
-
}
|
|
21000
|
-
}
|
|
21001
|
-
function normalizeSkillsApiOrigin(apiUrl) {
|
|
21002
|
-
const url = new URL(apiUrl);
|
|
21003
|
-
if (url.username || url.password || url.search || url.hash || url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))) {
|
|
21004
|
-
throw new SkillsFleetCredentialError("A Skills API URL must use HTTPS (or loopback HTTP), without credentials, query or fragment", "INVALID_API_URL");
|
|
21005
|
-
}
|
|
21006
|
-
const pathname = url.pathname.replace(/\/+$/, "");
|
|
21007
|
-
if (url.origin === "https://api.hasna.com" && pathname === "/skills/v1") {
|
|
21008
|
-
url.pathname = "/skills";
|
|
21009
|
-
} else if (pathname === "/api" || pathname === "/api/v1") {
|
|
21010
|
-
url.pathname = "/";
|
|
21011
|
-
} else if (pathname.endsWith("/api/v1")) {
|
|
21012
|
-
url.pathname = pathname.slice(0, -"/api/v1".length) || "/";
|
|
21013
|
-
} else if (pathname.endsWith("/api")) {
|
|
21014
|
-
url.pathname = pathname.slice(0, -"/api".length) || "/";
|
|
21015
|
-
}
|
|
21016
|
-
return url.toString().replace(/\/+$/, "");
|
|
21017
|
-
}
|
|
21018
|
-
function skillsApiRequestUrl(apiUrl, route) {
|
|
21019
|
-
const origin = normalizeSkillsApiOrigin(apiUrl);
|
|
21020
|
-
if (!route.startsWith("/api/") || route.includes("#") || route.includes("\\")) {
|
|
21021
|
-
throw new SkillsFleetCredentialError("Invalid Skills API route", "INVALID_API_URL");
|
|
21022
|
-
}
|
|
21023
|
-
if (origin === "https://api.hasna.com/skills") {
|
|
21024
|
-
if (route === "/api/auth/whoami")
|
|
21025
|
-
return `${origin}/v1/auth/whoami`;
|
|
21026
|
-
if (!route.startsWith("/api/v1/")) {
|
|
21027
|
-
throw new SkillsFleetCredentialError("The internal Skills gateway has no established login contract yet. Select an explicitly configured instance with supported authentication.", "GATEWAY_AUTH_UNAVAILABLE");
|
|
21028
|
-
}
|
|
21029
|
-
return `${origin}${route.slice("/api".length)}`;
|
|
21030
|
-
}
|
|
21031
|
-
return `${origin}${route}`;
|
|
21032
|
-
}
|
|
21033
20801
|
var MAX_REMOTE_FILE_BYTES = 64 * 1024 * 1024;
|
|
21034
20802
|
var CODEX_NATIVE_POLICY_CAPABILITY = "host-path-allowlist-v1";
|
|
21035
20803
|
var CODEX_NATIVE_POLICY_RECEIPT_SCHEMA = "skills.codex-native-policy-acceptance/v1";
|
|
@@ -44949,46 +44717,6 @@ var revocation = exports_external2.object({
|
|
|
44949
44717
|
});
|
|
44950
44718
|
var page = (item) => exports_external2.object({ contractVersion: exports_external2.literal(1), items: exports_external2.array(item).max(100), nextCursor: exports_external2.string().min(1).max(2048).nullable() });
|
|
44951
44719
|
var results = { preview, draft: preview.nullable(), activate: exports_external2.object({ replayed: exports_external2.boolean(), consent }), list: page(consent), get: consent.nullable(), occurrences: page(occurrence), revoke: revocation };
|
|
44952
|
-
var record7 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
44953
|
-
var uuid8 = (v) => typeof v === "string" && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(v);
|
|
44954
|
-
var text2 = (v, max = 1024) => typeof v === "string" && !!v.trim() && v.length <= max && !/[\p{Cc}\p{Cs}\u2028\u2029]/u.test(v);
|
|
44955
|
-
var role2 = (v) => typeof v === "string" && ["owner", "admin", "member", "viewer"].includes(v);
|
|
44956
|
-
var invalidWorkspaceResult = "The server returned an invalid workspace selection result.";
|
|
44957
|
-
class WorkspaceIdentityMismatchError extends Error {
|
|
44958
|
-
constructor() {
|
|
44959
|
-
super("The verified account does not match the requested workspace context.");
|
|
44960
|
-
this.name = "WorkspaceIdentityMismatchError";
|
|
44961
|
-
}
|
|
44962
|
-
}
|
|
44963
|
-
function invalid3() {
|
|
44964
|
-
throw new Error(invalidWorkspaceResult);
|
|
44965
|
-
}
|
|
44966
|
-
function organization(v) {
|
|
44967
|
-
if (!record7(v) || !uuid8(v.id) || !text2(v.slug) || !text2(v.name))
|
|
44968
|
-
return invalid3();
|
|
44969
|
-
return { id: v.id, slug: v.slug, name: v.name };
|
|
44970
|
-
}
|
|
44971
|
-
function parseWorkspaceIdentity(value, expectedUserId) {
|
|
44972
|
-
if (!record7(value))
|
|
44973
|
-
return invalid3();
|
|
44974
|
-
const user = value.user;
|
|
44975
|
-
if (!record7(user) || !uuid8(user.id) || !uuid8(user.membershipId) || !text2(user.email, 320) || !(user.displayName === null || text2(user.displayName)) || !role2(user.role))
|
|
44976
|
-
return invalid3();
|
|
44977
|
-
if (user.id !== expectedUserId)
|
|
44978
|
-
throw new WorkspaceIdentityMismatchError;
|
|
44979
|
-
return { user: { id: user.id, membershipId: user.membershipId, email: user.email, displayName: user.displayName, role: user.role }, organization: organization(value.organization) };
|
|
44980
|
-
}
|
|
44981
|
-
function sessionToken(value) {
|
|
44982
|
-
if (typeof value !== "string" || !value || value.length > 8192 || /[^\x21-\x7e]/.test(value) || value.startsWith("sk_"))
|
|
44983
|
-
return invalid3();
|
|
44984
|
-
return value;
|
|
44985
|
-
}
|
|
44986
|
-
function parseWorkspaceSession(value, expected) {
|
|
44987
|
-
const identity5 = parseWorkspaceIdentity(value, expected.userId);
|
|
44988
|
-
if (identity5.user.membershipId !== expected.membershipId)
|
|
44989
|
-
throw new WorkspaceIdentityMismatchError;
|
|
44990
|
-
return { token: sessionToken(value.token), ...identity5 };
|
|
44991
|
-
}
|
|
44992
44720
|
var SKILLS_API_KEY_REF = credentialPointerEnvKey("skills");
|
|
44993
44721
|
var quoteUnavailableMessages = Object.freeze({
|
|
44994
44722
|
HOSTED_PROVIDER_UNAVAILABLE: "Hosted execution is temporarily unavailable on this Skills instance.",
|
|
@@ -45000,353 +44728,6 @@ var quoteUnavailableMessages = Object.freeze({
|
|
|
45000
44728
|
});
|
|
45001
44729
|
var KNOWN_SKILL_LIFECYCLE_CODES = new Set(["SKILL_ARCHIVE_PROFILE_CONFLICT", "LIFECYCLE_ROLE_REQUIRED"]);
|
|
45002
44730
|
var PRIVATE_PUBLICATION_MAX_BYTES = 16 * 1024 * 1024;
|
|
45003
|
-
var skillCreateFailures = {
|
|
45004
|
-
INVALID_SLUG: [400, "Provide a lowercase kebab-case skill slug."],
|
|
45005
|
-
INVALID_DISPLAY_NAME: [400, "Provide a nonempty skill display name."],
|
|
45006
|
-
INVALID_VISIBILITY: [400, "Use private or team visibility for source publication."],
|
|
45007
|
-
SESSION_EXPIRED: [401, "Sign in again before creating a private skill."],
|
|
45008
|
-
INTERACTIVE_SESSION_REQUIRED: [403, "An interactive account session is required to create a private skill."],
|
|
45009
|
-
ACCOUNT_UNAVAILABLE: [403, "The current account membership cannot create a private skill."],
|
|
45010
|
-
PLAN_REQUIRED: [403, "Private and team skills require the Pro plan."],
|
|
45011
|
-
SLUG_CONFLICT: [409, "This skill slug already exists. Inspect the existing skill before publishing."]
|
|
45012
|
-
};
|
|
45013
|
-
var failures2 = {
|
|
45014
|
-
INVALID_REQUEST: [400, "The publication request is invalid."],
|
|
45015
|
-
SESSION_EXPIRED: [401, "Sign in again to manage this publication."],
|
|
45016
|
-
ACCOUNT_UNAVAILABLE: [403, "The account is unavailable."],
|
|
45017
|
-
INTERACTIVE_SESSION_REQUIRED: [403, "An interactive account session is required."],
|
|
45018
|
-
PUBLICATION_FORBIDDEN: [403, "This session cannot manage the publication."],
|
|
45019
|
-
PUBLICATION_ENTITLEMENT_REQUIRED: [403, "The workspace is not entitled to publish private skills."],
|
|
45020
|
-
PUBLICATION_UNAVAILABLE: [404, "The publication is unavailable to this session."],
|
|
45021
|
-
MANIFEST_NAME_MISMATCH: [409, "The manifest name does not match the selected skill."],
|
|
45022
|
-
IDEMPOTENCY_CONFLICT: [409, "This request key already identifies different publication bytes. Use the saved recovery directory."],
|
|
45023
|
-
CURRENT_VERSION_CHANGED: [409, "The current version changed. Inspect it before explicitly starting another publication."],
|
|
45024
|
-
VERSION_EXISTS: [409, "This version already exists."],
|
|
45025
|
-
VERSION_RESERVED: [409, "This version is reserved by another publication."],
|
|
45026
|
-
PUBLICATION_COMMITTED: [409, "The publication is already committed."],
|
|
45027
|
-
PUBLICATION_UPLOAD_UNAVAILABLE: [409, "This publication cannot receive another upload."],
|
|
45028
|
-
PUBLICATION_LIMIT: [429, "The workspace publication limit has been reached."],
|
|
45029
|
-
PUBLICATION_BUSY: [503, "The publication is busy. Reconcile the saved intent before retrying."],
|
|
45030
|
-
PUBLICATION_UNCERTAIN: [503, "The publication outcome is uncertain. Reconcile the saved intent."],
|
|
45031
|
-
PUBLICATION_CAPABILITY_UNAVAILABLE: [503, "Private publishing is not enabled on this server."],
|
|
45032
|
-
PUBLICATION_SIGNING_UNAVAILABLE: [503, "Upload authorization is temporarily unavailable. Keep the same intent."]
|
|
45033
|
-
};
|
|
45034
|
-
|
|
45035
|
-
class PrivatePublicationError extends Error {
|
|
45036
|
-
code;
|
|
45037
|
-
uncertain;
|
|
45038
|
-
status;
|
|
45039
|
-
constructor(code, message, uncertain = false, status) {
|
|
45040
|
-
super(message);
|
|
45041
|
-
this.code = code;
|
|
45042
|
-
this.uncertain = uncertain;
|
|
45043
|
-
this.status = status;
|
|
45044
|
-
this.name = "PrivatePublicationError";
|
|
45045
|
-
}
|
|
45046
|
-
}
|
|
45047
|
-
var bad = () => {
|
|
45048
|
-
throw new PrivatePublicationError("INVALID_PUBLICATION_INPUT", "Invalid publication input or recovery data.");
|
|
45049
|
-
};
|
|
45050
|
-
var invalid4 = () => {
|
|
45051
|
-
throw new PrivatePublicationError("INVALID_PUBLICATION_RESPONSE", "The server returned an invalid publication result.");
|
|
45052
|
-
};
|
|
45053
|
-
var publicationUuid = (v) => typeof v === "string" && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(v);
|
|
45054
|
-
var hash4 = (v) => typeof v === "string" && /^[a-f0-9]{64}$/.test(v);
|
|
45055
|
-
var record11 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
45056
|
-
var exact = (v, keys2) => record11(v) && Object.keys(v).sort().join(",") === keys2.sort().join(",");
|
|
45057
|
-
var date5 = (v) => typeof v === "string" && /^\d{4}-\d\d-\d\dT[0-9:.]+(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.test(v) && Number.isFinite(Date.parse(v));
|
|
45058
|
-
var publicationSha256 = (bytes) => createHash34("sha256").update(bytes).digest("hex");
|
|
45059
|
-
function checkedPrivateSkillCreate(value) {
|
|
45060
|
-
const refuse6 = (field3, accepted) => {
|
|
45061
|
-
throw new PrivatePublicationError("INVALID_SKILL_CREATE_INPUT", `Invalid ${field3}. ${accepted}`);
|
|
45062
|
-
};
|
|
45063
|
-
if (!record11(value) || !Object.keys(value).every((key2) => ["slug", "displayName", "description", "visibility", "confirm"].includes(key2)))
|
|
45064
|
-
return refuse6("create input", "Provide only slug, displayName, description, visibility and confirm.");
|
|
45065
|
-
if (value.confirm !== true)
|
|
45066
|
-
throw new PrivatePublicationError("SKILL_CREATE_CONFIRM_REQUIRED", "Explicit confirmation is required to create this skill.");
|
|
45067
|
-
if (typeof value.slug !== "string" || value.slug.length > 128 || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value.slug))
|
|
45068
|
-
return refuse6("slug", "Use lowercase kebab-case, at most 128 characters.");
|
|
45069
|
-
if (typeof value.displayName !== "string" || !value.displayName.trim() || value.displayName.length > 256 || /[\p{Cc}\p{Cs}\u2028\u2029]/u.test(value.displayName))
|
|
45070
|
-
return refuse6("displayName", "Use nonempty text, at most 256 characters, without control characters.");
|
|
45071
|
-
if (value.description !== undefined && (typeof value.description !== "string" || Buffer.byteLength(value.description) > 8192 || /[\p{Cc}\p{Cs}]/u.test(value.description.replace(/[\r\n\t]/g, ""))))
|
|
45072
|
-
return refuse6("description", "Use text of at most 8192 UTF-8 bytes, without control characters other than tabs and newlines.");
|
|
45073
|
-
if (value.visibility !== undefined && value.visibility !== "private" && value.visibility !== "team")
|
|
45074
|
-
return refuse6("visibility", "Use private or team.");
|
|
45075
|
-
return Object.freeze({ slug: value.slug, displayName: value.displayName.trim(), description: value.description ?? "", visibility: value.visibility ?? "private" });
|
|
45076
|
-
}
|
|
45077
|
-
function checkedPublicationDeclaration(value) {
|
|
45078
|
-
if (!exact(value, ["idempotencyKey", "version", "expectedCurrentVersionId", "manifestText", "archiveSha256", "archiveByteSize"]) || !publicationUuid(value.idempotencyKey) || !(value.expectedCurrentVersionId === null || publicationUuid(value.expectedCurrentVersionId)) || typeof value.version !== "string" || !value.version || value.version.length > 128 || /[\p{Cc}\p{Cs}]/u.test(value.version) || typeof value.manifestText !== "string" || Buffer.byteLength(value.manifestText) > 16384 || !hash4(value.archiveSha256) || !Number.isSafeInteger(value.archiveByteSize) || Number(value.archiveByteSize) < 1 || Number(value.archiveByteSize) > PRIVATE_PUBLICATION_MAX_BYTES)
|
|
45079
|
-
return bad();
|
|
45080
|
-
try {
|
|
45081
|
-
const manifest = JSON.parse(value.manifestText);
|
|
45082
|
-
if (!record11(manifest) || manifest.version !== value.version || validatePortableManifestContract(manifest, { strict: true }).length || !hash4(manifest.provenance?.content_hash))
|
|
45083
|
-
return bad();
|
|
45084
|
-
} catch {
|
|
45085
|
-
return bad();
|
|
45086
|
-
}
|
|
45087
|
-
return Object.freeze({ ...value });
|
|
45088
|
-
}
|
|
45089
|
-
function checkedPublicationView(value, skillId, intentId, declaration) {
|
|
45090
|
-
if (!exact(value, ["id", "skillId", "version", "expectedCurrentVersionId", "archiveSha256", "archiveByteSize", "state", "expiresAt", "createdAt", "versionId"]) || !publicationUuid(value.id) || value.skillId !== skillId || intentId !== undefined && value.id !== intentId || typeof value.version !== "string" || !value.version || value.version.length > 128 || /[\p{Cc}\p{Cs}]/u.test(value.version) || !(value.expectedCurrentVersionId === null || publicationUuid(value.expectedCurrentVersionId)) || !hash4(value.archiveSha256) || !Number.isSafeInteger(value.archiveByteSize) || Number(value.archiveByteSize) < 1 || Number(value.archiveByteSize) > PRIVATE_PUBLICATION_MAX_BYTES || typeof value.state !== "string" || !["awaiting_upload", "queued", "verifying", "needs_attention", "committed", "rejected", "cancelled", "expired"].includes(value.state) || !date5(value.expiresAt) || !date5(value.createdAt) || !(value.versionId === null || publicationUuid(value.versionId)) || value.state === "committed" && value.versionId === null)
|
|
45091
|
-
return invalid4();
|
|
45092
|
-
if (declaration && ["version", "expectedCurrentVersionId", "archiveSha256", "archiveByteSize"].some((k) => value[k] !== declaration[k]))
|
|
45093
|
-
return invalid4();
|
|
45094
|
-
return Object.freeze({ ...value });
|
|
45095
|
-
}
|
|
45096
|
-
async function boundedJson(url2, init, token, mutation, budget3 = 15000, signal, create = false) {
|
|
45097
|
-
const controller = new AbortController;
|
|
45098
|
-
let reader;
|
|
45099
|
-
let response;
|
|
45100
|
-
const timeout2 = new PrivatePublicationError(create ? "SKILL_CREATE_UNCONFIRMED" : "PUBLICATION_UNCONFIRMED", create ? "Skill creation could not be confirmed. Inspect the workspace for this slug before another create; do not retry automatically." : "No confirmed publication result. Inspect the saved intent before retrying.", mutation);
|
|
45101
|
-
let timer;
|
|
45102
|
-
let abort;
|
|
45103
|
-
try {
|
|
45104
|
-
return await Promise.race([(async () => {
|
|
45105
|
-
if (signal?.aborted)
|
|
45106
|
-
throw timeout2;
|
|
45107
|
-
response = await fetch(url2, {
|
|
45108
|
-
...init,
|
|
45109
|
-
redirect: "error",
|
|
45110
|
-
credentials: "omit",
|
|
45111
|
-
signal: controller.signal,
|
|
45112
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` }
|
|
45113
|
-
});
|
|
45114
|
-
const length = response.headers.get("content-length");
|
|
45115
|
-
if (length !== null && (!/^\d+$/.test(length) || Number(length) > 65536))
|
|
45116
|
-
return invalid4();
|
|
45117
|
-
reader = response.body?.getReader();
|
|
45118
|
-
const chunks = [];
|
|
45119
|
-
let size = 0;
|
|
45120
|
-
if (reader)
|
|
45121
|
-
while (true) {
|
|
45122
|
-
const part = await reader.read();
|
|
45123
|
-
if (part.done)
|
|
45124
|
-
break;
|
|
45125
|
-
size += part.value.byteLength;
|
|
45126
|
-
if (size > 65536)
|
|
45127
|
-
return invalid4();
|
|
45128
|
-
chunks.push(part.value);
|
|
45129
|
-
}
|
|
45130
|
-
if (controller.signal.aborted)
|
|
45131
|
-
throw timeout2;
|
|
45132
|
-
const bytes = Buffer.concat(chunks);
|
|
45133
|
-
let body;
|
|
45134
|
-
try {
|
|
45135
|
-
body = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
45136
|
-
} catch {
|
|
45137
|
-
return invalid4();
|
|
45138
|
-
}
|
|
45139
|
-
if (!response.ok) {
|
|
45140
|
-
const known = create ? skillCreateFailures : failures2;
|
|
45141
|
-
const code = record11(body) && typeof body.code === "string" && Object.hasOwn(known, body.code) ? body.code : null;
|
|
45142
|
-
if (code && known[code][0] === response.status)
|
|
45143
|
-
throw new PrivatePublicationError(code, known[code][1], mutation && code === "PUBLICATION_UNCERTAIN", response.status);
|
|
45144
|
-
if (create) {
|
|
45145
|
-
if (response.status >= 500)
|
|
45146
|
-
throw timeout2;
|
|
45147
|
-
throw new PrivatePublicationError("SKILL_CREATE_REQUEST_FAILED", "The server refused skill creation.", false, response.status);
|
|
45148
|
-
}
|
|
45149
|
-
throw new PrivatePublicationError("PUBLICATION_REQUEST_FAILED", "The publication request was refused. Inspect its status before retrying.", mutation && response.status >= 500, response.status);
|
|
45150
|
-
}
|
|
45151
|
-
if (create && response.status !== 201)
|
|
45152
|
-
return invalid4();
|
|
45153
|
-
return body;
|
|
45154
|
-
})(), new Promise((_, reject) => {
|
|
45155
|
-
abort = () => {
|
|
45156
|
-
controller.abort();
|
|
45157
|
-
reject(timeout2);
|
|
45158
|
-
};
|
|
45159
|
-
timer = setTimeout(abort, Math.max(1, Math.min(15000, budget3)));
|
|
45160
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
45161
|
-
})]);
|
|
45162
|
-
} catch (error61) {
|
|
45163
|
-
if (error61 instanceof PrivatePublicationError) {
|
|
45164
|
-
if (mutation && error61.code === "INVALID_PUBLICATION_RESPONSE")
|
|
45165
|
-
throw timeout2;
|
|
45166
|
-
throw error61;
|
|
45167
|
-
}
|
|
45168
|
-
throw timeout2;
|
|
45169
|
-
} finally {
|
|
45170
|
-
if (timer)
|
|
45171
|
-
clearTimeout(timer);
|
|
45172
|
-
if (abort)
|
|
45173
|
-
signal?.removeEventListener("abort", abort);
|
|
45174
|
-
controller.abort();
|
|
45175
|
-
if (reader)
|
|
45176
|
-
reader.cancel().catch(() => {});
|
|
45177
|
-
else
|
|
45178
|
-
response?.body?.cancel().catch(() => {});
|
|
45179
|
-
}
|
|
45180
|
-
}
|
|
45181
|
-
|
|
45182
|
-
class RemotePrivatePublicationsClient {
|
|
45183
|
-
apiOrigin;
|
|
45184
|
-
organizationId;
|
|
45185
|
-
userId;
|
|
45186
|
-
membershipId;
|
|
45187
|
-
#token;
|
|
45188
|
-
constructor(apiUrl, session) {
|
|
45189
|
-
const checked = parseWorkspaceSession(session, { userId: session?.user?.id, membershipId: session?.user?.membershipId });
|
|
45190
|
-
if (checked.user.role === "viewer")
|
|
45191
|
-
throw new PrivatePublicationError("PUBLICATION_FORBIDDEN", failures2.PUBLICATION_FORBIDDEN[1]);
|
|
45192
|
-
this.apiOrigin = normalizeSkillsApiOrigin(apiUrl);
|
|
45193
|
-
this.#token = checked.token;
|
|
45194
|
-
this.organizationId = checked.organization.id;
|
|
45195
|
-
this.userId = checked.user.id;
|
|
45196
|
-
this.membershipId = checked.user.membershipId;
|
|
45197
|
-
Object.freeze(this);
|
|
45198
|
-
}
|
|
45199
|
-
async createSkill(input2, options = {}) {
|
|
45200
|
-
const body = checkedPrivateSkillCreate(input2);
|
|
45201
|
-
if (options.timeoutMs !== undefined && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 1 || options.timeoutMs > 15000))
|
|
45202
|
-
throw new PrivatePublicationError("INVALID_SKILL_CREATE_INPUT", "Invalid timeoutMs. Use an integer from 1 to 15000.");
|
|
45203
|
-
const value = await boundedJson(skillsApiRequestUrl(this.apiOrigin, "/api/v1/skills"), { method: "POST", body: JSON.stringify(body) }, this.#token, true, options.timeoutMs, options.signal, true);
|
|
45204
|
-
if (!record11(value) || !publicationUuid(value.id) || value.slug !== body.slug || value.displayName !== body.displayName || value.description !== body.description || value.visibility !== body.visibility || value.sourceType !== "private_hosted" || !record11(value.metadata) || value.metadata.ownerOrganizationId !== this.organizationId)
|
|
45205
|
-
throw new PrivatePublicationError("SKILL_CREATE_UNCONFIRMED", "Skill creation returned an unbound result. Inspect the workspace for this slug before another create; do not retry automatically.", true);
|
|
45206
|
-
return Object.freeze({ id: value.id, slug: body.slug, visibility: body.visibility, sourceType: "private_hosted", ownerOrganizationId: this.organizationId });
|
|
45207
|
-
}
|
|
45208
|
-
async getCapability(options = {}) {
|
|
45209
|
-
if (options.timeoutMs !== undefined && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 1 || options.timeoutMs > 15000))
|
|
45210
|
-
return bad();
|
|
45211
|
-
const response = await boundedJson(skillsApiRequestUrl(this.apiOrigin, "/api/v1/capabilities"), {}, this.#token, false, options.timeoutMs, options.signal);
|
|
45212
|
-
const p = record11(response) && response.privatePublishing;
|
|
45213
|
-
if (!record11(response) || response.contractVersion !== 1 || response.apiVersion !== 1 || !exact(p, ["contractVersion", "enabled", "authentication", "maxArchiveBytes", "uploadMaxTtlSeconds", "executionEnabled"]) || p.contractVersion !== 1 || typeof p.enabled !== "boolean" || p.authentication !== "interactive-session" || p.maxArchiveBytes !== PRIVATE_PUBLICATION_MAX_BYTES || p.uploadMaxTtlSeconds !== 300 || typeof p.executionEnabled !== "boolean")
|
|
45214
|
-
throw new PrivatePublicationError("PUBLICATION_CONTRACT_UNAVAILABLE", "This server does not support the hosted private publication contract.");
|
|
45215
|
-
return Object.freeze({ ...p });
|
|
45216
|
-
}
|
|
45217
|
-
async#gate(enabled, options = {}) {
|
|
45218
|
-
if (!(await this.getCapability(options)).enabled && enabled)
|
|
45219
|
-
throw new PrivatePublicationError("PUBLICATION_CAPABILITY_UNAVAILABLE", failures2.PUBLICATION_CAPABILITY_UNAVAILABLE[1]);
|
|
45220
|
-
}
|
|
45221
|
-
#path(skillId, intentId) {
|
|
45222
|
-
if (!publicationUuid(skillId) || intentId !== undefined && !publicationUuid(intentId))
|
|
45223
|
-
return bad();
|
|
45224
|
-
return skillsApiRequestUrl(this.apiOrigin, `/api/v1/skills/${skillId}/publication-uploads${intentId ? `/${intentId}` : ""}`);
|
|
45225
|
-
}
|
|
45226
|
-
async#view(path, method, skillId, intentId, declaration, options = {}) {
|
|
45227
|
-
const value = await boundedJson(path, { method, ...method === "GET" ? {} : { body: JSON.stringify(declaration ?? {}) } }, this.#token, method !== "GET", options.timeoutMs, options.signal);
|
|
45228
|
-
try {
|
|
45229
|
-
if (!record11(value) || !Object.keys(value).every((k) => k === "upload" || k === "changed") || value.changed !== undefined && typeof value.changed !== "boolean")
|
|
45230
|
-
return invalid4();
|
|
45231
|
-
return checkedPublicationView(value.upload, skillId, intentId, declaration);
|
|
45232
|
-
} catch (error61) {
|
|
45233
|
-
if (method !== "GET")
|
|
45234
|
-
throw new PrivatePublicationError("PUBLICATION_UNCONFIRMED", "The publication result could not be confirmed. Reconcile the saved intent before another action.", true);
|
|
45235
|
-
throw error61;
|
|
45236
|
-
}
|
|
45237
|
-
}
|
|
45238
|
-
async begin(skillId, input2) {
|
|
45239
|
-
const path = this.#path(skillId), declaration = checkedPublicationDeclaration(input2);
|
|
45240
|
-
await this.#gate(true);
|
|
45241
|
-
return this.#view(path, "POST", skillId, undefined, declaration);
|
|
45242
|
-
}
|
|
45243
|
-
async get(skillId, intentId, options = {}) {
|
|
45244
|
-
const path = this.#path(skillId, intentId), until = Date.now() + (options.timeoutMs ?? 15000);
|
|
45245
|
-
await this.#gate(false, options);
|
|
45246
|
-
return this.#view(path, "GET", skillId, intentId, undefined, { ...options, timeoutMs: Math.max(1, until - Date.now()) });
|
|
45247
|
-
}
|
|
45248
|
-
async finalize(skillId, intentId) {
|
|
45249
|
-
const path = this.#path(skillId, intentId);
|
|
45250
|
-
await this.#gate(true);
|
|
45251
|
-
return this.#view(`${path}/finalize`, "POST", skillId, intentId);
|
|
45252
|
-
}
|
|
45253
|
-
async cancel(skillId, intentId) {
|
|
45254
|
-
const path = this.#path(skillId, intentId);
|
|
45255
|
-
await this.#gate(false);
|
|
45256
|
-
return this.#view(path, "DELETE", skillId, intentId);
|
|
45257
|
-
}
|
|
45258
|
-
async upload(skillId, intent, bytes) {
|
|
45259
|
-
const captured = checkedPublicationView(intent, skillId), path = this.#path(skillId, captured.id);
|
|
45260
|
-
if (!(bytes instanceof Uint8Array) || bytes.byteLength !== captured.archiveByteSize)
|
|
45261
|
-
return bad();
|
|
45262
|
-
const owned = Buffer.from(bytes);
|
|
45263
|
-
if (captured.state !== "awaiting_upload" || owned.byteLength !== captured.archiveByteSize || publicationSha256(owned) !== captured.archiveSha256)
|
|
45264
|
-
return bad();
|
|
45265
|
-
await this.#gate(true);
|
|
45266
|
-
const value = await boundedJson(`${path}/upload-url`, { method: "POST", body: "{}" }, this.#token, false);
|
|
45267
|
-
const upload = this.#upload(value, captured);
|
|
45268
|
-
const controller = new AbortController;
|
|
45269
|
-
let timer;
|
|
45270
|
-
const uncertain = () => new PrivatePublicationError("PUBLICATION_UPLOAD_UNCONFIRMED", "Upload acceptance is uncertain. Resume this saved intent to finalize and inspect it; do not upload again.", true);
|
|
45271
|
-
try {
|
|
45272
|
-
await Promise.race([(async () => {
|
|
45273
|
-
const response = await fetch(upload.uploadUrl, { method: "PUT", headers: upload.headers, body: owned, redirect: "error", credentials: "omit", signal: controller.signal });
|
|
45274
|
-
response.body?.cancel().catch(() => {});
|
|
45275
|
-
if (response.status !== 200 || controller.signal.aborted)
|
|
45276
|
-
throw uncertain();
|
|
45277
|
-
})(), new Promise((_, reject) => {
|
|
45278
|
-
timer = setTimeout(() => {
|
|
45279
|
-
controller.abort();
|
|
45280
|
-
reject(uncertain());
|
|
45281
|
-
}, 30000);
|
|
45282
|
-
})]);
|
|
45283
|
-
} catch {
|
|
45284
|
-
throw uncertain();
|
|
45285
|
-
} finally {
|
|
45286
|
-
if (timer)
|
|
45287
|
-
clearTimeout(timer);
|
|
45288
|
-
controller.abort();
|
|
45289
|
-
}
|
|
45290
|
-
}
|
|
45291
|
-
#upload(value, intent) {
|
|
45292
|
-
if (!exact(value, ["upload"]) || !exact(value.upload, ["method", "uploadUrl", "headers", "expiresAt"]))
|
|
45293
|
-
return invalid4();
|
|
45294
|
-
const p = value.upload;
|
|
45295
|
-
if (p.method !== "PUT" || typeof p.uploadUrl !== "string" || p.uploadUrl.length > 8192 || /[\x00-\x20\x7f]/.test(p.uploadUrl) || !date5(p.expiresAt) || Date.parse(p.expiresAt) - Date.now() < 1000 || Date.parse(p.expiresAt) - Date.now() > 300000 || Date.parse(p.expiresAt) > Date.parse(intent.expiresAt) || !exact(p.headers, ["content-type", "content-length", "x-amz-checksum-sha256", "x-amz-expected-bucket-owner"]) || p.headers["content-type"] !== "application/gzip" || p.headers["content-length"] !== String(intent.archiveByteSize) || p.headers["x-amz-checksum-sha256"] !== Buffer.from(intent.archiveSha256, "hex").toString("base64") || typeof p.headers["x-amz-expected-bucket-owner"] !== "string" || !/^\d{12}$/.test(p.headers["x-amz-expected-bucket-owner"]))
|
|
45296
|
-
return invalid4();
|
|
45297
|
-
let url2;
|
|
45298
|
-
try {
|
|
45299
|
-
url2 = new URL(p.uploadUrl);
|
|
45300
|
-
} catch {
|
|
45301
|
-
return invalid4();
|
|
45302
|
-
}
|
|
45303
|
-
if (url2.protocol !== "https:" || url2.port || url2.username || url2.password || url2.hash || !/^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]\.s3\.[a-z]{2}(?:-[a-z]+)+-[1-9]\.amazonaws\.com$/.test(url2.hostname) || url2.pathname !== `/private-publication-staging/${this.organizationId}/${intent.id}/bundle.tgz` || !url2.search || url2.searchParams.get("X-Amz-Algorithm") !== "AWS4-HMAC-SHA256" || url2.searchParams.get("X-Amz-SignedHeaders") !== "content-length;content-type;host;x-amz-checksum-sha256;x-amz-expected-bucket-owner" || !/^[a-f0-9]{64}$/.test(url2.searchParams.get("X-Amz-Signature") ?? ""))
|
|
45304
|
-
return invalid4();
|
|
45305
|
-
const queryKeys = ["X-Amz-Algorithm", "X-Amz-Credential", "X-Amz-Date", "X-Amz-Expires", "X-Amz-Security-Token", "X-Amz-Signature", "X-Amz-SignedHeaders"];
|
|
45306
|
-
if ([...url2.searchParams.keys()].sort().join(",") !== queryKeys.sort().join(","))
|
|
45307
|
-
return invalid4();
|
|
45308
|
-
const issued = url2.searchParams.get("X-Amz-Date"), ttl = url2.searchParams.get("X-Amz-Expires"), credential = url2.searchParams.get("X-Amz-Credential");
|
|
45309
|
-
const timestamp3 = /^(\d{4})(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)Z$/.exec(issued);
|
|
45310
|
-
const region = url2.hostname.split(".s3.")[1].split(".amazonaws.com")[0];
|
|
45311
|
-
if (!timestamp3 || !/^[1-9]\d{0,2}$/.test(ttl) || Number(ttl) > 300 || !/^[A-Z0-9]{16,128}\//.test(credential) || credential.split("/").slice(1).join("/") !== `${issued.slice(0, 8)}/${region}/s3/aws4_request` || !/^[\x21-\x7e]{1,4096}$/.test(url2.searchParams.get("X-Amz-Security-Token")))
|
|
45312
|
-
return invalid4();
|
|
45313
|
-
const issuedAt = Date.parse(`${timestamp3[1]}-${timestamp3[2]}-${timestamp3[3]}T${timestamp3[4]}:${timestamp3[5]}:${timestamp3[6]}Z`);
|
|
45314
|
-
if (!Number.isFinite(issuedAt) || issuedAt > Date.now() + 1000 || issuedAt + Number(ttl) * 1000 !== Date.parse(p.expiresAt))
|
|
45315
|
-
return invalid4();
|
|
45316
|
-
return { method: "PUT", uploadUrl: url2.href, expiresAt: p.expiresAt, headers: Object.freeze({ ...p.headers }) };
|
|
45317
|
-
}
|
|
45318
|
-
async wait(skillId, intentId, options = {}) {
|
|
45319
|
-
const timeout2 = options.timeoutMs ?? 60000;
|
|
45320
|
-
if (!Number.isSafeInteger(timeout2) || timeout2 < 0 || timeout2 > 300000)
|
|
45321
|
-
return bad();
|
|
45322
|
-
const until = Date.now() + timeout2;
|
|
45323
|
-
let previous;
|
|
45324
|
-
while (true) {
|
|
45325
|
-
if (options.signal?.aborted)
|
|
45326
|
-
throw new PrivatePublicationError("PUBLICATION_WAIT_ABORTED", "Stopped waiting. The server publication continues; inspect the saved intent.");
|
|
45327
|
-
let view;
|
|
45328
|
-
try {
|
|
45329
|
-
view = await this.get(skillId, intentId, { timeoutMs: timeout2 === 0 ? 15000 : Math.max(1, Math.min(15000, until - Date.now())), signal: options.signal });
|
|
45330
|
-
} catch (error61) {
|
|
45331
|
-
if (previous && Date.now() >= until && !options.signal?.aborted)
|
|
45332
|
-
return previous;
|
|
45333
|
-
throw error61;
|
|
45334
|
-
}
|
|
45335
|
-
previous = view;
|
|
45336
|
-
if (!["queued", "verifying"].includes(view.state) || Date.now() >= until)
|
|
45337
|
-
return view;
|
|
45338
|
-
await new Promise((resolve30) => {
|
|
45339
|
-
const timer = setTimeout(done, Math.min(1000, until - Date.now()));
|
|
45340
|
-
function done() {
|
|
45341
|
-
clearTimeout(timer);
|
|
45342
|
-
options.signal?.removeEventListener("abort", done);
|
|
45343
|
-
resolve30();
|
|
45344
|
-
}
|
|
45345
|
-
options.signal?.addEventListener("abort", done, { once: true });
|
|
45346
|
-
});
|
|
45347
|
-
}
|
|
45348
|
-
}
|
|
45349
|
-
}
|
|
45350
44731
|
var uuid12 = exports_external2.string().regex(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/);
|
|
45351
44732
|
var sha6 = exports_external2.string().regex(/^[a-f0-9]{64}$/);
|
|
45352
44733
|
var common = exports_external2.object({
|
|
@@ -46554,7 +45935,7 @@ function claudeSkillsUsage(before, home) {
|
|
|
46554
45935
|
}
|
|
46555
45936
|
if (events3.length)
|
|
46556
45937
|
evidence.push(`Skills-managed hook entries in ${events3.join(", ")}`);
|
|
46557
|
-
const bridge =
|
|
45938
|
+
const bridge = join17(home, ".claude", "skills", "skills-cli", "SKILL.md");
|
|
46558
45939
|
let bridgePresent;
|
|
46559
45940
|
try {
|
|
46560
45941
|
bridgePresent = lstatSync9(bridge, { throwIfNoEntry: false }) !== undefined;
|
|
@@ -46568,8 +45949,8 @@ function claudeSkillsUsage(before, home) {
|
|
|
46568
45949
|
function skillsPolicyLocations(dataDir3) {
|
|
46569
45950
|
const state = (path) => existsSync11(path) ? "present" : "absent";
|
|
46570
45951
|
if (dataDir3 !== undefined)
|
|
46571
|
-
return [`${
|
|
46572
|
-
const env = process.env, home = env.HOME || env.USERPROFILE ||
|
|
45952
|
+
return [`${join17(resolve9(dataDir3), "agent-policy.json")} (explicit data directory, absent)`];
|
|
45953
|
+
const env = process.env, home = env.HOME || env.USERPROFILE || homedir7() || "/tmp", searched = [];
|
|
46573
45954
|
let selected = false;
|
|
46574
45955
|
for (const key2 of ["HASNA_SKILLS_DIR", "HASNA_SKILLS_HOME", "SKILLS_HOME"]) {
|
|
46575
45956
|
const value = env[key2]?.trim();
|
|
@@ -46579,13 +45960,13 @@ function skillsPolicyLocations(dataDir3) {
|
|
|
46579
45960
|
searched.push(`$${key2} (unset)`);
|
|
46580
45961
|
else {
|
|
46581
45962
|
selected = true;
|
|
46582
|
-
searched.push(`$${key2} -> ${
|
|
45963
|
+
searched.push(`$${key2} -> ${join17(resolve9(value), "agent-policy.json")} (selected, absent)`);
|
|
46583
45964
|
}
|
|
46584
45965
|
}
|
|
46585
45966
|
const override = env.HASNA_DATA_HOME;
|
|
46586
|
-
const base = typeof override === "string" && override.length > 0 ? override : process.platform === "darwin" ?
|
|
46587
|
-
const xdg =
|
|
46588
|
-
const adopted = typeof override === "string" && override.trim().length > 0 || existsSync11(
|
|
45967
|
+
const base = typeof override === "string" && override.length > 0 ? override : process.platform === "darwin" ? join17(home, "Library", "Application Support", "Hasna") : join17(home, ".local", "share", "hasna");
|
|
45968
|
+
const xdg = join17(base, "skills"), xdgPolicy = join17(xdg, "agent-policy.json");
|
|
45969
|
+
const adopted = typeof override === "string" && override.trim().length > 0 || existsSync11(join17(xdg, "server.db")) || existsSync11(join17(xdg, "config.json"));
|
|
46589
45970
|
if (selected)
|
|
46590
45971
|
searched.push(`${xdgPolicy} (not consulted, ${state(xdgPolicy)})`);
|
|
46591
45972
|
else if (adopted) {
|
|
@@ -46593,7 +45974,7 @@ function skillsPolicyLocations(dataDir3) {
|
|
|
46593
45974
|
searched.push(`${xdgPolicy} (selected, absent)`);
|
|
46594
45975
|
} else
|
|
46595
45976
|
searched.push(`${xdgPolicy} (not selected: the directory holds no server.db or config.json and HASNA_DATA_HOME is unset; ${state(xdgPolicy)})`);
|
|
46596
|
-
const legacy =
|
|
45977
|
+
const legacy = join17(home, ".hasna", "skills", "agent-policy.json");
|
|
46597
45978
|
searched.push(selected ? `${legacy} (not consulted, ${state(legacy)})` : `${legacy} (selected, absent)`);
|
|
46598
45979
|
return searched;
|
|
46599
45980
|
}
|
|
@@ -46611,7 +45992,7 @@ function planCoordinatedClaudeSettings(before, replacement, options) {
|
|
|
46611
45992
|
if (!plan) {
|
|
46612
45993
|
const usage = claudeSkillsUsage(before, options.home);
|
|
46613
45994
|
if (usage.length)
|
|
46614
|
-
throw new ClaudeSettingsRefusal("skills_policy_unresolved", `Skills manages ${
|
|
45995
|
+
throw new ClaudeSettingsRefusal("skills_policy_unresolved", `Skills manages ${join17(options.home, ".claude", "settings.json")} (${usage.join("; ")}), but no Skills agent policy resolved, ` + "so Hooks cannot coordinate this change and wrote nothing. Locations searched, in Skills resolution order: " + skillsPolicyLocations(options.dataDir).map((location, index) => `${index + 1}) ${location}`).join("; ") + ". Run hooks with the environment that selects the Skills data directory (for example HASNA_SKILLS_DIR), " + "or repair the integration with `skills hook install`.");
|
|
46615
45996
|
}
|
|
46616
45997
|
return plan;
|
|
46617
45998
|
}
|
|
@@ -46624,33 +46005,689 @@ function coordinateClaudeSettings(before, replacement, options, beforeWrite) {
|
|
|
46624
46005
|
return true;
|
|
46625
46006
|
}
|
|
46626
46007
|
|
|
46627
|
-
// src/lib/
|
|
46628
|
-
|
|
46629
|
-
|
|
46630
|
-
|
|
46008
|
+
// src/lib/target-adapters.ts
|
|
46009
|
+
init_profiles();
|
|
46010
|
+
import { spawnSync } from "child_process";
|
|
46011
|
+
import { chmodSync as chmodSync2, existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync8, readdirSync as readdirSync4, rmdirSync as rmdirSync2, statSync, unlinkSync as unlinkSync3, writeFileSync as writeFileSync9, renameSync as renameSync5 } from "fs";
|
|
46012
|
+
import { tmpdir } from "os";
|
|
46013
|
+
import { basename as basename9, dirname as dirname9, join as join22 } from "path";
|
|
46014
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
46015
|
+
var ADAPTER_TARGETS = ["muse", "kimi", "pi", "cursor"];
|
|
46016
|
+
function isAdapterTarget(value) {
|
|
46017
|
+
return typeof value === "string" && ADAPTER_TARGETS.includes(value);
|
|
46018
|
+
}
|
|
46019
|
+
var defaultRunner = (command, args) => {
|
|
46020
|
+
const result = spawnSync(command, args, { encoding: "utf8", maxBuffer: 4 * 1024 * 1024 });
|
|
46021
|
+
return {
|
|
46022
|
+
status: result.status ?? 1,
|
|
46023
|
+
stdout: result.stdout ?? "",
|
|
46024
|
+
stderr: result.stderr ?? "",
|
|
46025
|
+
notFound: result.error?.code === "ENOENT"
|
|
46026
|
+
};
|
|
46027
|
+
};
|
|
46028
|
+
var HOOK_COMMAND_RE = /^hooks run ([\w-]+)(?:\s|$)/;
|
|
46029
|
+
function hookFromCommand(command) {
|
|
46030
|
+
return command.trim().match(HOOK_COMMAND_RE)?.[1];
|
|
46631
46031
|
}
|
|
46632
|
-
function
|
|
46633
|
-
|
|
46634
|
-
throw new Error("Invalid --target; expected claude, codex, gemini, codewith, sumi, or opencode");
|
|
46635
|
-
if (!dispatch)
|
|
46636
|
-
return [...args];
|
|
46637
|
-
if (!isHookRunTarget(target))
|
|
46638
|
-
throw new Error("This hook requires --target from its native registration");
|
|
46639
|
-
if (args.some((arg) => arg === "--harness" || arg.startsWith("--harness=")))
|
|
46640
|
-
throw new Error("nativeTargetDispatch owns the --harness argument; remove it from manifest args");
|
|
46641
|
-
return [...args, "--harness", target];
|
|
46032
|
+
function homeOf(options) {
|
|
46033
|
+
return options.home ?? process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
46642
46034
|
}
|
|
46643
|
-
function
|
|
46644
|
-
|
|
46645
|
-
|
|
46646
|
-
|
|
46647
|
-
|
|
46648
|
-
|
|
46035
|
+
function adapterStorePath(target, options, hook) {
|
|
46036
|
+
return adapterPath(target, options, hook);
|
|
46037
|
+
}
|
|
46038
|
+
function adapterPath(target, options, hook) {
|
|
46039
|
+
const capabilities = getTargetCapabilities(target, {
|
|
46040
|
+
scope: options.scope,
|
|
46041
|
+
home: homeOf(options),
|
|
46042
|
+
cwd: options.cwd ?? process.cwd(),
|
|
46043
|
+
env: options.env ?? process.env,
|
|
46044
|
+
...hook ? { hook } : {}
|
|
46045
|
+
});
|
|
46046
|
+
if (!capabilities)
|
|
46047
|
+
throw new Error(`No capability record for target '${target}'`);
|
|
46048
|
+
return capabilities.configPath;
|
|
46049
|
+
}
|
|
46050
|
+
function redactedDiagnostic(text2) {
|
|
46051
|
+
const line = (text2.split(`
|
|
46052
|
+
`).find((entry) => entry.trim()) ?? "").trim();
|
|
46053
|
+
return line.slice(0, 300).replace(/[A-Za-z0-9_\-]{24,}/g, "<redacted>");
|
|
46054
|
+
}
|
|
46055
|
+
function redactedCode(value) {
|
|
46056
|
+
return typeof value === "string" && value.length <= 64 && /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/.test(value) ? value : "<redacted>";
|
|
46057
|
+
}
|
|
46058
|
+
function messageOf(error61) {
|
|
46059
|
+
return error61 instanceof Error ? error61.message : String(error61);
|
|
46060
|
+
}
|
|
46061
|
+
function readJsonObject(path) {
|
|
46062
|
+
let text2;
|
|
46063
|
+
try {
|
|
46064
|
+
text2 = readFileSync8(path, "utf-8");
|
|
46065
|
+
} catch (error61) {
|
|
46066
|
+
if (error61?.code === "ENOENT")
|
|
46067
|
+
return { status: "absent" };
|
|
46068
|
+
return { status: "unreadable", kind: "file", reason: `cannot read ${path} (${redactedDiagnostic(messageOf(error61))})` };
|
|
46069
|
+
}
|
|
46070
|
+
try {
|
|
46071
|
+
const value = JSON.parse(text2);
|
|
46072
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
46073
|
+
return { status: "unreadable", kind: "content", reason: `${path} is not a JSON object` };
|
|
46074
|
+
}
|
|
46075
|
+
return { status: "verified", value };
|
|
46076
|
+
} catch (error61) {
|
|
46077
|
+
return { status: "unreadable", kind: "content", reason: `${path} is not valid JSON (${redactedDiagnostic(messageOf(error61))})` };
|
|
46078
|
+
}
|
|
46079
|
+
}
|
|
46080
|
+
function writeText(path, content) {
|
|
46081
|
+
const dir = dirname9(path);
|
|
46082
|
+
mkdirSync10(dir, { recursive: true });
|
|
46083
|
+
const temp = join22(dir, `.${basename9(path)}.${randomUUID5()}.tmp`);
|
|
46084
|
+
try {
|
|
46085
|
+
writeFileSync9(temp, content);
|
|
46086
|
+
if (existsSync13(path))
|
|
46087
|
+
chmodSync2(temp, statSync(path).mode & 4095);
|
|
46088
|
+
renameSync5(temp, path);
|
|
46089
|
+
} catch (error61) {
|
|
46090
|
+
try {
|
|
46091
|
+
if (existsSync13(temp))
|
|
46092
|
+
unlinkSync3(temp);
|
|
46093
|
+
} catch {}
|
|
46094
|
+
throw error61;
|
|
46095
|
+
}
|
|
46096
|
+
}
|
|
46097
|
+
function tomlString(value) {
|
|
46098
|
+
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
46099
|
+
}
|
|
46100
|
+
function tomlStringValue(raw) {
|
|
46101
|
+
return raw.replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
46102
|
+
}
|
|
46103
|
+
var TOML_HEADER_RE = /^\s*\[\[?[^\]]/;
|
|
46104
|
+
var KIMI_HOOK_HEADER_RE = /^\s*\[\[hooks\]\]\s*$/;
|
|
46105
|
+
function splitToml(text2) {
|
|
46106
|
+
const preamble = [];
|
|
46107
|
+
const chunks = [];
|
|
46108
|
+
let current2 = null;
|
|
46109
|
+
for (const line of text2.split(`
|
|
46110
|
+
`)) {
|
|
46111
|
+
if (TOML_HEADER_RE.test(line)) {
|
|
46112
|
+
if (current2)
|
|
46113
|
+
chunks.push(current2);
|
|
46114
|
+
current2 = { header: line.trim(), lines: [line] };
|
|
46115
|
+
} else if (current2) {
|
|
46116
|
+
current2.lines.push(line);
|
|
46117
|
+
} else {
|
|
46118
|
+
preamble.push(line);
|
|
46119
|
+
}
|
|
46120
|
+
}
|
|
46121
|
+
if (current2)
|
|
46122
|
+
chunks.push(current2);
|
|
46123
|
+
return { preamble, chunks };
|
|
46124
|
+
}
|
|
46125
|
+
function chunkCommand(chunk) {
|
|
46126
|
+
const text2 = chunk.lines.join(`
|
|
46127
|
+
`);
|
|
46128
|
+
const basic = text2.match(/^\s*command\s*=\s*"((?:[^"\\]|\\.)*)"/m);
|
|
46129
|
+
if (basic)
|
|
46130
|
+
return tomlStringValue(basic[1]);
|
|
46131
|
+
const literal2 = text2.match(/^\s*command\s*=\s*'([^']*)'/m);
|
|
46132
|
+
return literal2 ? literal2[1] : undefined;
|
|
46133
|
+
}
|
|
46134
|
+
function isKimiHookChunk(chunk) {
|
|
46135
|
+
return KIMI_HOOK_HEADER_RE.test(chunk.header);
|
|
46136
|
+
}
|
|
46137
|
+
function kimiRegistrations(text2) {
|
|
46138
|
+
const out = [];
|
|
46139
|
+
for (const chunk of splitToml(text2).chunks) {
|
|
46140
|
+
if (!isKimiHookChunk(chunk))
|
|
46141
|
+
continue;
|
|
46142
|
+
const command = chunkCommand(chunk);
|
|
46143
|
+
const hook = command ? hookFromCommand(command) : undefined;
|
|
46144
|
+
if (command && hook)
|
|
46145
|
+
out.push({ hook, command });
|
|
46146
|
+
}
|
|
46147
|
+
return out;
|
|
46148
|
+
}
|
|
46149
|
+
function kimiBlock(command, timeoutSeconds) {
|
|
46150
|
+
return [
|
|
46151
|
+
"[[hooks]]",
|
|
46152
|
+
'event = "Stop"',
|
|
46153
|
+
`command = ${tomlString(command)}`,
|
|
46154
|
+
`timeout = ${Math.max(1, Math.min(600, timeoutSeconds))}`
|
|
46155
|
+
].join(`
|
|
46156
|
+
`);
|
|
46157
|
+
}
|
|
46158
|
+
function removeKimiChunk(text2, hook) {
|
|
46159
|
+
const { preamble, chunks } = splitToml(text2);
|
|
46160
|
+
const kept = [...preamble];
|
|
46161
|
+
let removed = false;
|
|
46162
|
+
for (const chunk of chunks) {
|
|
46163
|
+
const command = isKimiHookChunk(chunk) ? chunkCommand(chunk) : undefined;
|
|
46164
|
+
if (command && hookFromCommand(command) === hook) {
|
|
46165
|
+
removed = true;
|
|
46166
|
+
while (kept.length > 0 && kept[kept.length - 1].trim() === "")
|
|
46167
|
+
kept.pop();
|
|
46168
|
+
continue;
|
|
46169
|
+
}
|
|
46170
|
+
if (TOML_HEADER_RE.test(chunk.header) && kept.length > 0 && kept[kept.length - 1].trim() !== "") {
|
|
46171
|
+
kept.push("");
|
|
46172
|
+
}
|
|
46173
|
+
kept.push(...chunk.lines);
|
|
46174
|
+
}
|
|
46175
|
+
return { text: kept.join(`
|
|
46176
|
+
`), removed };
|
|
46177
|
+
}
|
|
46178
|
+
function installKimi(hook, command, options, timeoutSeconds) {
|
|
46179
|
+
const path = adapterPath("kimi", options);
|
|
46180
|
+
const read3 = readTextState(path);
|
|
46181
|
+
if (read3.status === "unreadable") {
|
|
46182
|
+
return { ok: false, configPath: path, error: `Refused: ${read3.reason}, so Hooks wrote nothing. Repair the file or move it aside, then retry.` };
|
|
46183
|
+
}
|
|
46184
|
+
const existing = read3.status === "verified" ? read3.text : "";
|
|
46185
|
+
if (kimiRegistrations(existing).some((entry) => entry.hook === hook)) {
|
|
46186
|
+
return { ok: true, configPath: path, note: "already registered; nothing was written" };
|
|
46187
|
+
}
|
|
46188
|
+
const next = existing.trim() === "" ? `${kimiBlock(command, timeoutSeconds)}
|
|
46189
|
+
` : `${existing.trimEnd()}
|
|
46190
|
+
|
|
46191
|
+
${kimiBlock(command, timeoutSeconds)}
|
|
46192
|
+
`;
|
|
46193
|
+
const candidate = join22(tmpdir(), `hooks-kimi-config-${randomUUID5()}.toml`);
|
|
46194
|
+
writeFileSync9(candidate, next);
|
|
46195
|
+
let validationNote;
|
|
46196
|
+
try {
|
|
46197
|
+
const result = (options.run ?? defaultRunner)("kimi", ["doctor", "config", candidate]);
|
|
46198
|
+
if (result.notFound) {
|
|
46199
|
+
validationNote = "kimi is not installed here, so `kimi doctor config` did not validate the entry";
|
|
46200
|
+
} else if (result.status !== 0) {
|
|
46201
|
+
const detail = redactedDiagnostic(result.stderr) || redactedDiagnostic(result.stdout) || `exit ${result.status}`;
|
|
46202
|
+
return { ok: false, configPath: path, error: `Refused: \`kimi doctor config\` rejected the candidate config (${detail}). Nothing was written to ${path}.` };
|
|
46203
|
+
} else {
|
|
46204
|
+
validationNote = "validated with `kimi doctor config`";
|
|
46205
|
+
}
|
|
46206
|
+
} finally {
|
|
46207
|
+
try {
|
|
46208
|
+
if (existsSync13(candidate))
|
|
46209
|
+
unlinkSync3(candidate);
|
|
46210
|
+
} catch {}
|
|
46211
|
+
}
|
|
46212
|
+
writeText(path, next);
|
|
46213
|
+
return {
|
|
46214
|
+
ok: true,
|
|
46215
|
+
configPath: path,
|
|
46216
|
+
note: `Kimi blocks with exit 2 + stderr once per turn; ${validationNote}.`
|
|
46217
|
+
};
|
|
46218
|
+
}
|
|
46219
|
+
var PI_PREFERENCE_KEY = "hasna-pi-hooks";
|
|
46220
|
+
function piPointerPath(options) {
|
|
46221
|
+
return adapterPath("pi", options);
|
|
46222
|
+
}
|
|
46223
|
+
function readPiPointer(options) {
|
|
46224
|
+
return readJsonObject(piPointerPath(options));
|
|
46225
|
+
}
|
|
46226
|
+
function piProfile(options, pointer) {
|
|
46227
|
+
const state = pointer === undefined ? readPiPointer(options) : undefined;
|
|
46228
|
+
const config2 = pointer ?? (state?.status === "verified" ? state.value : undefined);
|
|
46229
|
+
if (typeof config2?.profile === "string") {
|
|
46230
|
+
const pointed = getProfile(config2.profile);
|
|
46231
|
+
if (pointed)
|
|
46232
|
+
return pointed;
|
|
46233
|
+
}
|
|
46234
|
+
return listProfiles().find((profile) => profile.agent_type === "custom" && profile.name === "pi");
|
|
46235
|
+
}
|
|
46236
|
+
function piCommands(profile) {
|
|
46237
|
+
const stored = profile?.preferences?.[PI_PREFERENCE_KEY];
|
|
46238
|
+
const hooks = stored?.hooks;
|
|
46239
|
+
return Array.isArray(hooks) ? hooks.filter((entry) => typeof entry === "string") : [];
|
|
46240
|
+
}
|
|
46241
|
+
function writePiCommands(profileId, commands) {
|
|
46242
|
+
const profile = getProfile(profileId);
|
|
46243
|
+
if (!profile)
|
|
46244
|
+
return;
|
|
46245
|
+
updateProfile(profileId, {
|
|
46246
|
+
preferences: {
|
|
46247
|
+
...profile.preferences,
|
|
46248
|
+
[PI_PREFERENCE_KEY]: { hooks: commands, updated_at: new Date().toISOString() }
|
|
46249
|
+
}
|
|
46250
|
+
});
|
|
46251
|
+
}
|
|
46252
|
+
function installPi(hook, command, options) {
|
|
46253
|
+
const path = piPointerPath(options);
|
|
46254
|
+
const pointerRead = readPiPointer(options);
|
|
46255
|
+
if (pointerRead.status === "unreadable") {
|
|
46256
|
+
return { ok: false, configPath: path, error: `Refused: ${pointerRead.reason}, so Hooks wrote nothing. Repair the file or move it aside, then retry.` };
|
|
46257
|
+
}
|
|
46258
|
+
const profile = piProfile(options) ?? createProfile({ agent_type: "custom", name: "pi" });
|
|
46259
|
+
const commands = piCommands(profile);
|
|
46260
|
+
if (commands.some((entry) => hookFromCommand(entry) === hook)) {
|
|
46261
|
+
return { ok: true, configPath: path, note: "already registered; nothing was written" };
|
|
46262
|
+
}
|
|
46263
|
+
const pointer = pointerRead.status === "verified" ? pointerRead.value : {};
|
|
46264
|
+
writeText(path, `${JSON.stringify({ ...pointer, profile: profile.agent_id }, null, 2)}
|
|
46265
|
+
`);
|
|
46266
|
+
writePiCommands(profile.agent_id, [...commands, command]);
|
|
46267
|
+
return {
|
|
46268
|
+
ok: true,
|
|
46269
|
+
configPath: path,
|
|
46270
|
+
note: `registered through Hooks profile ${profile.agent_id}, which the hasna-pi-hooks bridge reads`
|
|
46271
|
+
};
|
|
46272
|
+
}
|
|
46273
|
+
function readCursorFile(path) {
|
|
46274
|
+
return readJsonObject(path);
|
|
46275
|
+
}
|
|
46276
|
+
function cursorRegistrations(config2) {
|
|
46277
|
+
const out = [];
|
|
46278
|
+
const hooks = config2?.hooks;
|
|
46279
|
+
if (!hooks || typeof hooks !== "object")
|
|
46280
|
+
return out;
|
|
46281
|
+
for (const key2 of Object.keys(hooks)) {
|
|
46282
|
+
const entries = hooks[key2];
|
|
46283
|
+
if (!Array.isArray(entries))
|
|
46284
|
+
continue;
|
|
46285
|
+
for (const entry of entries) {
|
|
46286
|
+
const command = typeof entry?.command === "string" ? entry.command : undefined;
|
|
46287
|
+
const hook = command ? hookFromCommand(command) : undefined;
|
|
46288
|
+
if (command && hook)
|
|
46289
|
+
out.push({ hook, command });
|
|
46290
|
+
}
|
|
46291
|
+
}
|
|
46292
|
+
return out;
|
|
46293
|
+
}
|
|
46294
|
+
function installCursor(hook, command, options, timeoutSeconds) {
|
|
46295
|
+
const path = adapterPath("cursor", options);
|
|
46296
|
+
const read3 = readCursorFile(path);
|
|
46297
|
+
if (read3.status === "unreadable") {
|
|
46298
|
+
return {
|
|
46299
|
+
ok: false,
|
|
46300
|
+
configPath: path,
|
|
46301
|
+
error: read3.kind === "file" ? `Refused: ${read3.reason}, so Hooks wrote nothing. Repair the file or move it aside, then retry.` : `Refused: ${path} is not a JSON object, so Hooks wrote nothing. Repair the file or move it aside, then retry.`
|
|
46302
|
+
};
|
|
46303
|
+
}
|
|
46304
|
+
const config2 = read3.status === "verified" ? read3.value : undefined;
|
|
46305
|
+
if (cursorRegistrations(config2).some((entry) => entry.hook === hook)) {
|
|
46306
|
+
return { ok: true, configPath: path, note: "already registered; nothing was written" };
|
|
46307
|
+
}
|
|
46308
|
+
const next = config2 ?? {};
|
|
46309
|
+
const hooks = next.hooks && typeof next.hooks === "object" ? { ...next.hooks } : {};
|
|
46310
|
+
const stop = Array.isArray(hooks.stop) ? [...hooks.stop] : [];
|
|
46311
|
+
stop.push({ command, timeout: Math.max(1, Math.min(600, timeoutSeconds)) });
|
|
46312
|
+
hooks.stop = stop;
|
|
46313
|
+
writeText(path, `${JSON.stringify({ version: 1, ...next, hooks }, null, 2)}
|
|
46314
|
+
`);
|
|
46315
|
+
return { ok: true, configPath: path };
|
|
46316
|
+
}
|
|
46317
|
+
function splitArgv(command) {
|
|
46318
|
+
return command.trim().split(/\s+/).filter(Boolean);
|
|
46319
|
+
}
|
|
46320
|
+
function hookFromMuseCommand(command) {
|
|
46321
|
+
if (!Array.isArray(command))
|
|
46322
|
+
return;
|
|
46323
|
+
const joined = command.filter((part) => typeof part === "string").join(" ");
|
|
46324
|
+
const match = joined.match(/(?:^|\s)\S*hooks run ([\w-]+)(?:\s|$)/);
|
|
46325
|
+
return match?.[1];
|
|
46326
|
+
}
|
|
46327
|
+
function museManifest(hook, command, options, timeoutSeconds) {
|
|
46328
|
+
return {
|
|
46329
|
+
name: `hasna-hook-${hook}`,
|
|
46330
|
+
version: options.version ?? "0.0.0",
|
|
46331
|
+
description: options.description ?? `Hasna hook ${hook}`,
|
|
46332
|
+
schemaVersion: 1,
|
|
46333
|
+
compat: { source: "native", manifestDir: ".muse-plugin" },
|
|
46334
|
+
capabilities: {
|
|
46335
|
+
hooks: [{
|
|
46336
|
+
id: `hasna-${hook}-stop`,
|
|
46337
|
+
event: "Stop",
|
|
46338
|
+
command: splitArgv(command),
|
|
46339
|
+
timeoutMs: timeoutSeconds * 1000,
|
|
46340
|
+
statusMessage: `Running Hasna hook ${hook}`
|
|
46341
|
+
}]
|
|
46342
|
+
}
|
|
46343
|
+
};
|
|
46344
|
+
}
|
|
46345
|
+
function museDiagnostic(outcome) {
|
|
46346
|
+
try {
|
|
46347
|
+
const parsed = JSON.parse(outcome.stdout);
|
|
46348
|
+
const message = parsed?.error?.message;
|
|
46349
|
+
if (typeof message === "string" && message.trim()) {
|
|
46350
|
+
const code2 = parsed.error?.code === undefined ? "" : `${redactedCode(parsed.error.code)}: `;
|
|
46351
|
+
return `${code2}${redactedDiagnostic(message)}`;
|
|
46352
|
+
}
|
|
46353
|
+
} catch {}
|
|
46354
|
+
return redactedDiagnostic(outcome.stderr) || redactedDiagnostic(outcome.stdout) || `exit ${outcome.status}`;
|
|
46355
|
+
}
|
|
46356
|
+
function removeMuseBundle(bundle) {
|
|
46357
|
+
const manifestPath = join22(bundle, ".muse-plugin", "plugin.json");
|
|
46358
|
+
try {
|
|
46359
|
+
if (existsSync13(manifestPath))
|
|
46360
|
+
unlinkSync3(manifestPath);
|
|
46361
|
+
} catch {}
|
|
46362
|
+
for (const dir of [join22(bundle, ".muse-plugin"), bundle]) {
|
|
46363
|
+
try {
|
|
46364
|
+
if (existsSync13(dir))
|
|
46365
|
+
rmdirSync2(dir);
|
|
46366
|
+
} catch {}
|
|
46367
|
+
}
|
|
46368
|
+
}
|
|
46369
|
+
function museBundles(options) {
|
|
46370
|
+
const root = musePluginRoot({ home: homeOf(options), env: options.env ?? process.env });
|
|
46371
|
+
if (!existsSync13(root))
|
|
46372
|
+
return [];
|
|
46373
|
+
const out = [];
|
|
46374
|
+
for (const entry of readdirSync4(root)) {
|
|
46375
|
+
const manifestPath = join22(root, entry, ".muse-plugin", "plugin.json");
|
|
46376
|
+
if (!existsSync13(manifestPath))
|
|
46377
|
+
continue;
|
|
46378
|
+
try {
|
|
46379
|
+
const manifest = JSON.parse(readFileSync8(manifestPath, "utf-8"));
|
|
46380
|
+
for (const capability of manifest.capabilities?.hooks ?? []) {
|
|
46381
|
+
const command = Array.isArray(capability.command) ? capability.command.join(" ") : "";
|
|
46382
|
+
const hook = hookFromCommand(command) ?? hookFromMuseCommand(capability.command);
|
|
46383
|
+
if (hook)
|
|
46384
|
+
out.push({ hook, command });
|
|
46385
|
+
}
|
|
46386
|
+
} catch {}
|
|
46387
|
+
}
|
|
46388
|
+
return out;
|
|
46389
|
+
}
|
|
46390
|
+
function museOwnFiles(options) {
|
|
46391
|
+
const home = homeOf(options);
|
|
46392
|
+
const env = options.env ?? process.env;
|
|
46393
|
+
const configBase = env.XDG_CONFIG_HOME?.startsWith("/") ? env.XDG_CONFIG_HOME : join22(home, ".config");
|
|
46394
|
+
const dataBase = env.XDG_DATA_HOME?.startsWith("/") ? env.XDG_DATA_HOME : join22(home, ".local", "share");
|
|
46395
|
+
const searched = [join22(configBase, "muse", "settings.json"), join22(dataBase, "muse")];
|
|
46396
|
+
const found = searched.filter((path) => existsSync13(path));
|
|
46397
|
+
return { present: found.length > 0, found, searched };
|
|
46398
|
+
}
|
|
46399
|
+
function readMuseState(options, runner = options.run ?? defaultRunner) {
|
|
46400
|
+
const source = "`muse plugins list --json`";
|
|
46401
|
+
const bundleRoot = musePluginRoot({ home: homeOf(options), env: options.env ?? process.env });
|
|
46402
|
+
const unverified = (reason2) => ({ status: "unverified", registrations: [], inactive: [], source, reason: reason2 });
|
|
46403
|
+
const result = runner("muse", ["plugins", "list", "--json"]);
|
|
46404
|
+
if (result.notFound) {
|
|
46405
|
+
const muse = museOwnFiles(options);
|
|
46406
|
+
if (muse.present) {
|
|
46407
|
+
return unverified(`Muse's own store is here (${muse.found.join(", ")}), but the \`muse\` command is not on PATH, so ${source} cannot say what Muse carries \u2014 ` + `a plugin Muse registered may still run, and a bundle under ${bundleRoot} is a file Hooks wrote, not proof either way`);
|
|
46408
|
+
}
|
|
46409
|
+
return {
|
|
46410
|
+
...unverified(`Muse is not installed here: neither its store (${muse.searched.join(" or ")}) nor the \`muse\` command exists, so it carries no registration`),
|
|
46411
|
+
absent: true
|
|
46412
|
+
};
|
|
46413
|
+
}
|
|
46414
|
+
if (result.status !== 0) {
|
|
46415
|
+
return unverified(`${source} failed (${museDiagnostic(result)})`);
|
|
46416
|
+
}
|
|
46417
|
+
let parsed;
|
|
46418
|
+
try {
|
|
46419
|
+
parsed = JSON.parse(result.stdout);
|
|
46420
|
+
} catch {
|
|
46421
|
+
return unverified(`${source} did not return JSON`);
|
|
46422
|
+
}
|
|
46423
|
+
const entries = parsed?.plugins;
|
|
46424
|
+
if (!Array.isArray(entries))
|
|
46425
|
+
return unverified(`${source} returned no plugin list`);
|
|
46426
|
+
const registrations = [];
|
|
46427
|
+
const inactive = [];
|
|
46428
|
+
for (const entry of entries) {
|
|
46429
|
+
const hooks = entry?.plugin?.capabilities?.hooks;
|
|
46430
|
+
if (!Array.isArray(hooks))
|
|
46431
|
+
continue;
|
|
46432
|
+
const enabled = entry?.record?.enabled === true;
|
|
46433
|
+
for (const capability of hooks) {
|
|
46434
|
+
const command = Array.isArray(capability?.command) ? capability.command.filter((part) => typeof part === "string").join(" ") : "";
|
|
46435
|
+
const hook = hookFromMuseCommand(capability?.command);
|
|
46436
|
+
if (!hook)
|
|
46437
|
+
continue;
|
|
46438
|
+
if (enabled) {
|
|
46439
|
+
registrations.push({ hook, command });
|
|
46440
|
+
} else if (!inactive.includes(hook)) {
|
|
46441
|
+
inactive.push(hook);
|
|
46442
|
+
}
|
|
46443
|
+
}
|
|
46444
|
+
}
|
|
46445
|
+
return { status: "verified", registrations, inactive, source };
|
|
46446
|
+
}
|
|
46447
|
+
function installMuse(hook, command, options, timeoutSeconds) {
|
|
46448
|
+
const runner = options.run ?? defaultRunner;
|
|
46449
|
+
const bundle = adapterPath("muse", options, hook);
|
|
46450
|
+
const manifestPath = join22(bundle, ".muse-plugin", "plugin.json");
|
|
46451
|
+
const existedBefore = existsSync13(manifestPath);
|
|
46452
|
+
const manifest = museManifest(hook, command, options, timeoutSeconds);
|
|
46453
|
+
writeText(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
46454
|
+
`);
|
|
46455
|
+
const installCommand = `muse plugins install ${bundle} --scope user`;
|
|
46456
|
+
const approveCommand = `muse plugins approve ${manifest.name}`;
|
|
46457
|
+
const cleanup = () => {
|
|
46458
|
+
if (!existedBefore)
|
|
46459
|
+
removeMuseBundle(bundle);
|
|
46460
|
+
};
|
|
46461
|
+
const left = existedBefore ? ` The existing bundle at ${bundle} was left as it was.` : " The bundle was removed again, so nothing is left half-written.";
|
|
46462
|
+
const validated = runner("muse", ["plugins", "validate", bundle, "--json"]);
|
|
46463
|
+
if (validated.notFound) {
|
|
46464
|
+
cleanup();
|
|
46465
|
+
const muse = museOwnFiles(options);
|
|
46466
|
+
return {
|
|
46467
|
+
ok: false,
|
|
46468
|
+
configPath: bundle,
|
|
46469
|
+
error: muse.present ? `Refused: Muse's own store is here (${muse.found.join(", ")}), but the \`muse\` command is not on PATH, so \`muse plugins validate\` could not check the bundle.${left} Run it where the Muse command is available: \`${installCommand}\` then \`${approveCommand}\`.` : `Refused: Muse is not installed here, so \`muse plugins validate\` could not check the bundle.${left} On a station with Muse run \`${installCommand}\` then \`${approveCommand}\`.`
|
|
46470
|
+
};
|
|
46471
|
+
}
|
|
46472
|
+
if (validated.status !== 0) {
|
|
46473
|
+
cleanup();
|
|
46474
|
+
return {
|
|
46475
|
+
ok: false,
|
|
46476
|
+
configPath: bundle,
|
|
46477
|
+
error: `Refused: Muse rejected the plugin manifest (${museDiagnostic(validated)}).${left} Nothing was registered.`
|
|
46478
|
+
};
|
|
46479
|
+
}
|
|
46480
|
+
const installed = runner("muse", ["plugins", "install", bundle, "--scope", "user"]);
|
|
46481
|
+
if (installed.notFound) {
|
|
46482
|
+
cleanup();
|
|
46483
|
+
return {
|
|
46484
|
+
ok: false,
|
|
46485
|
+
configPath: bundle,
|
|
46486
|
+
error: `Refused: Muse disappeared between validation and install, so the plugin was not registered.${left} On a station with Muse run \`${installCommand}\` then \`${approveCommand}\`.`
|
|
46487
|
+
};
|
|
46488
|
+
}
|
|
46489
|
+
if (installed.status !== 0) {
|
|
46490
|
+
cleanup();
|
|
46491
|
+
return {
|
|
46492
|
+
ok: false,
|
|
46493
|
+
configPath: bundle,
|
|
46494
|
+
error: `Refused: \`${installCommand}\` failed (${museDiagnostic(installed)}).${left}`
|
|
46495
|
+
};
|
|
46496
|
+
}
|
|
46497
|
+
const approved = runner("muse", ["plugins", "approve", manifest.name]);
|
|
46498
|
+
if (approved.status !== 0) {
|
|
46499
|
+
const detail = museDiagnostic(approved);
|
|
46500
|
+
return {
|
|
46501
|
+
ok: false,
|
|
46502
|
+
configPath: bundle,
|
|
46503
|
+
error: `Refused: the plugin installed but Muse did not approve it (${detail}); an unapproved plugin does not run. Run \`${approveCommand}\` and retry.`
|
|
46504
|
+
};
|
|
46505
|
+
}
|
|
46506
|
+
return { ok: true, configPath: bundle, note: `installed at user scope and approved as ${manifest.name}` };
|
|
46507
|
+
}
|
|
46508
|
+
function readTextState(path) {
|
|
46509
|
+
try {
|
|
46510
|
+
return { status: "verified", text: readFileSync8(path, "utf-8") };
|
|
46511
|
+
} catch (error61) {
|
|
46512
|
+
if (error61?.code === "ENOENT")
|
|
46513
|
+
return { status: "absent" };
|
|
46514
|
+
return { status: "unreadable", reason: `cannot read ${path} (${redactedDiagnostic(messageOf(error61))})` };
|
|
46515
|
+
}
|
|
46516
|
+
}
|
|
46517
|
+
function readKimiState(options) {
|
|
46518
|
+
const read3 = readTextState(adapterPath("kimi", options));
|
|
46519
|
+
if (read3.status === "unreadable")
|
|
46520
|
+
return { status: "unverified", registrations: [], reason: read3.reason };
|
|
46521
|
+
if (read3.status === "absent")
|
|
46522
|
+
return { status: "verified", registrations: [] };
|
|
46523
|
+
return { status: "verified", registrations: kimiRegistrations(read3.text) };
|
|
46524
|
+
}
|
|
46525
|
+
function readPiState(options) {
|
|
46526
|
+
const read3 = readPiPointer(options);
|
|
46527
|
+
if (read3.status === "unreadable")
|
|
46528
|
+
return { status: "unverified", registrations: [], reason: read3.reason };
|
|
46529
|
+
const profile = piProfile(options, read3.status === "verified" ? read3.value : {});
|
|
46530
|
+
const registrations = piCommands(profile).flatMap((command) => {
|
|
46531
|
+
const hook = hookFromCommand(command);
|
|
46532
|
+
return hook ? [{ hook, command }] : [];
|
|
46533
|
+
});
|
|
46534
|
+
return { status: "verified", registrations };
|
|
46535
|
+
}
|
|
46536
|
+
function readCursorState(options) {
|
|
46537
|
+
const read3 = readCursorFile(adapterPath("cursor", options));
|
|
46538
|
+
if (read3.status === "unreadable")
|
|
46539
|
+
return { status: "unverified", registrations: [], reason: read3.reason };
|
|
46540
|
+
if (read3.status === "absent")
|
|
46541
|
+
return { status: "verified", registrations: [] };
|
|
46542
|
+
return { status: "verified", registrations: cursorRegistrations(read3.value) };
|
|
46543
|
+
}
|
|
46544
|
+
function readAdapterState(target, options, runner) {
|
|
46545
|
+
try {
|
|
46546
|
+
if (target === "kimi")
|
|
46547
|
+
return readKimiState(options);
|
|
46548
|
+
if (target === "pi")
|
|
46549
|
+
return readPiState(options);
|
|
46550
|
+
if (target === "cursor")
|
|
46551
|
+
return readCursorState(options);
|
|
46552
|
+
return readMuseState(options, runner ?? options.run ?? defaultRunner);
|
|
46553
|
+
} catch (error61) {
|
|
46554
|
+
return {
|
|
46555
|
+
status: "unverified",
|
|
46556
|
+
registrations: [],
|
|
46557
|
+
reason: `${target}: cannot read its registration state (${redactedDiagnostic(messageOf(error61))})`
|
|
46558
|
+
};
|
|
46559
|
+
}
|
|
46560
|
+
}
|
|
46561
|
+
function readAdapterRegistrations(target, options) {
|
|
46562
|
+
if (target === "muse") {
|
|
46563
|
+
try {
|
|
46564
|
+
return museBundles(options);
|
|
46565
|
+
} catch {
|
|
46566
|
+
return [];
|
|
46567
|
+
}
|
|
46568
|
+
}
|
|
46569
|
+
return readAdapterState(target, options).registrations;
|
|
46570
|
+
}
|
|
46571
|
+
function adapterStateCarries(state, hook) {
|
|
46572
|
+
if (state.registrations.some((entry) => entry.hook === hook))
|
|
46573
|
+
return true;
|
|
46574
|
+
const inactive = state.inactive;
|
|
46575
|
+
return Array.isArray(inactive) && inactive.includes(hook);
|
|
46576
|
+
}
|
|
46577
|
+
function installInAdapter(target, hook, command, options, timeoutSeconds = 10) {
|
|
46578
|
+
try {
|
|
46579
|
+
if (target === "kimi")
|
|
46580
|
+
return installKimi(hook, command, options, timeoutSeconds);
|
|
46581
|
+
if (target === "pi")
|
|
46582
|
+
return installPi(hook, command, options);
|
|
46583
|
+
if (target === "cursor")
|
|
46584
|
+
return installCursor(hook, command, options, timeoutSeconds);
|
|
46585
|
+
return installMuse(hook, command, options, timeoutSeconds);
|
|
46586
|
+
} catch (error61) {
|
|
46587
|
+
return { ok: false, configPath: "", error: `Refused: ${target}: the install did not complete (${redactedDiagnostic(messageOf(error61))})` };
|
|
46588
|
+
}
|
|
46589
|
+
}
|
|
46590
|
+
function removeFromAdapter(target, hook, options) {
|
|
46591
|
+
try {
|
|
46592
|
+
if (target === "kimi") {
|
|
46593
|
+
const path = adapterPath("kimi", options);
|
|
46594
|
+
const existing = readTextState(path);
|
|
46595
|
+
if (existing.status === "unreadable") {
|
|
46596
|
+
return { removed: false, reason: `${existing.reason}, so Hooks cannot tell whether '${hook}' is registered; nothing was removed` };
|
|
46597
|
+
}
|
|
46598
|
+
const { text: text2, removed } = removeKimiChunk(existing.status === "verified" ? existing.text : "", hook);
|
|
46599
|
+
if (!removed)
|
|
46600
|
+
return { removed: false, reason: `no '${hook}' entry in ${path}` };
|
|
46601
|
+
writeText(path, text2.endsWith(`
|
|
46602
|
+
`) ? text2 : `${text2}
|
|
46603
|
+
`);
|
|
46604
|
+
return { removed: true };
|
|
46605
|
+
}
|
|
46606
|
+
if (target === "pi") {
|
|
46607
|
+
const pointer = readPiPointer(options);
|
|
46608
|
+
if (pointer.status === "unreadable") {
|
|
46609
|
+
return { removed: false, reason: `${pointer.reason}, so Hooks cannot tell whether '${hook}' is registered; nothing was removed` };
|
|
46610
|
+
}
|
|
46611
|
+
const profile = piProfile(options);
|
|
46612
|
+
if (!profile)
|
|
46613
|
+
return { removed: false, reason: `no Hooks profile is registered for Pi; nothing to remove` };
|
|
46614
|
+
const commands = piCommands(profile);
|
|
46615
|
+
const kept = commands.filter((command) => hookFromCommand(command) !== hook);
|
|
46616
|
+
if (kept.length === commands.length)
|
|
46617
|
+
return { removed: false, reason: `no '${hook}' entry in profile ${profile.agent_id}` };
|
|
46618
|
+
writePiCommands(profile.agent_id, kept);
|
|
46619
|
+
return { removed: true };
|
|
46620
|
+
}
|
|
46621
|
+
if (target === "cursor") {
|
|
46622
|
+
const path = adapterPath("cursor", options);
|
|
46623
|
+
const read3 = readCursorFile(path);
|
|
46624
|
+
if (read3.status === "unreadable") {
|
|
46625
|
+
return { removed: false, reason: `${read3.reason}, so Hooks cannot tell whether '${hook}' is registered; nothing was removed` };
|
|
46626
|
+
}
|
|
46627
|
+
const config2 = read3.status === "verified" ? read3.value : undefined;
|
|
46628
|
+
if (!config2?.hooks)
|
|
46629
|
+
return { removed: false, reason: `no '${hook}' entry in ${path}` };
|
|
46630
|
+
let removed = false;
|
|
46631
|
+
const hooks = {};
|
|
46632
|
+
for (const key2 of Object.keys(config2.hooks)) {
|
|
46633
|
+
const entries = config2.hooks[key2];
|
|
46634
|
+
if (!Array.isArray(entries)) {
|
|
46635
|
+
hooks[key2] = entries;
|
|
46636
|
+
continue;
|
|
46637
|
+
}
|
|
46638
|
+
const kept = entries.filter((entry) => {
|
|
46639
|
+
if (typeof entry?.command !== "string" || hookFromCommand(entry.command) !== hook)
|
|
46640
|
+
return true;
|
|
46641
|
+
removed = true;
|
|
46642
|
+
return false;
|
|
46643
|
+
});
|
|
46644
|
+
if (kept.length > 0)
|
|
46645
|
+
hooks[key2] = kept;
|
|
46646
|
+
}
|
|
46647
|
+
if (!removed)
|
|
46648
|
+
return { removed: false, reason: `no '${hook}' entry in ${path}` };
|
|
46649
|
+
const next = { ...config2, hooks };
|
|
46650
|
+
if (Object.keys(hooks).length === 0)
|
|
46651
|
+
delete next.hooks;
|
|
46652
|
+
writeText(path, `${JSON.stringify(next, null, 2)}
|
|
46653
|
+
`);
|
|
46654
|
+
return { removed: true };
|
|
46655
|
+
}
|
|
46656
|
+
const bundle = adapterPath("muse", options, hook);
|
|
46657
|
+
const manifestPath = join22(bundle, ".muse-plugin", "plugin.json");
|
|
46658
|
+
const hadBundle = existsSync13(manifestPath);
|
|
46659
|
+
const bundleNote = hadBundle ? `the bundle at ${bundle} was left in place` : `no bundle was present at ${bundle}`;
|
|
46660
|
+
const pluginId2 = `hasna-hook-${hook}`;
|
|
46661
|
+
const result = (options.run ?? defaultRunner)("muse", ["plugins", "remove", pluginId2, "--json"]);
|
|
46662
|
+
if (result.notFound) {
|
|
46663
|
+
const muse = museOwnFiles(options);
|
|
46664
|
+
return {
|
|
46665
|
+
removed: false,
|
|
46666
|
+
reason: muse.present ? `Refused: Muse's own store is here (${muse.found.join(", ")}), but the \`muse\` command is not on PATH, so '${hook}' cannot be unregistered from it and may still run; ${bundleNote}. Run \`muse plugins remove ${pluginId2}\` where the Muse command is available.` : `Refused: Muse is not installed here, so '${hook}' cannot be unregistered from Muse's own store; ${bundleNote}. Run \`muse plugins remove ${pluginId2}\` on a station with Muse.`
|
|
46667
|
+
};
|
|
46668
|
+
}
|
|
46669
|
+
const refusal3 = result.status === 0 ? undefined : museDiagnostic(result);
|
|
46670
|
+
const alreadyGone = refusal3 !== undefined && /unknown-plugin|not installed/i.test(refusal3);
|
|
46671
|
+
if (refusal3 !== undefined && !alreadyGone) {
|
|
46672
|
+
return {
|
|
46673
|
+
removed: false,
|
|
46674
|
+
reason: `Refused: \`muse plugins remove ${pluginId2}\` failed (${refusal3}); ${bundleNote}.`
|
|
46675
|
+
};
|
|
46676
|
+
}
|
|
46677
|
+
removeMuseBundle(bundle);
|
|
46678
|
+
return {
|
|
46679
|
+
removed: true,
|
|
46680
|
+
bundleRemoved: hadBundle,
|
|
46681
|
+
reason: alreadyGone ? `Muse did not carry ${pluginId2}; ${hadBundle ? `the bundle at ${bundle} was removed` : `no bundle was present at ${bundle}`}` : hadBundle ? `unregistered ${pluginId2} from Muse and removed ${bundle}` : `unregistered ${pluginId2} from Muse; no bundle was present at ${bundle}`
|
|
46682
|
+
};
|
|
46683
|
+
} catch (error61) {
|
|
46684
|
+
return { removed: false, reason: `${target}: the removal failed (${redactedDiagnostic(messageOf(error61))}); nothing was removed` };
|
|
46685
|
+
}
|
|
46649
46686
|
}
|
|
46650
46687
|
|
|
46651
46688
|
// src/lib/installer.ts
|
|
46652
|
-
var __dirname2 =
|
|
46653
|
-
var HOOKS_DIR =
|
|
46689
|
+
var __dirname2 = dirname16(fileURLToPath3(import.meta.url));
|
|
46690
|
+
var HOOKS_DIR = existsSync14(join24(__dirname2, "..", "..", "hooks", "hook-gitguard")) ? join24(__dirname2, "..", "..", "hooks") : join24(__dirname2, "..", "hooks");
|
|
46654
46691
|
function normalizeHookName(name) {
|
|
46655
46692
|
return name.startsWith("hook-") ? name : `hook-${name}`;
|
|
46656
46693
|
}
|
|
@@ -46667,17 +46704,19 @@ function removeHookEntriesByName(entries, hookName) {
|
|
|
46667
46704
|
return kept.length === entry.hooks.length ? [entry] : kept.length ? [{ ...entry, hooks: kept }] : [];
|
|
46668
46705
|
});
|
|
46669
46706
|
}
|
|
46707
|
+
var CLAUDE_EVENT_MAP = {
|
|
46708
|
+
PreToolUse: "PreToolUse",
|
|
46709
|
+
PostToolUse: "PostToolUse",
|
|
46710
|
+
Stop: "Stop",
|
|
46711
|
+
Notification: "Notification",
|
|
46712
|
+
SessionStart: "SessionStart",
|
|
46713
|
+
SessionEnd: "SessionEnd",
|
|
46714
|
+
UserPromptSubmit: "UserPromptSubmit",
|
|
46715
|
+
SubagentStart: null
|
|
46716
|
+
};
|
|
46670
46717
|
var EVENT_MAP = {
|
|
46671
|
-
claude:
|
|
46672
|
-
|
|
46673
|
-
PostToolUse: "PostToolUse",
|
|
46674
|
-
Stop: "Stop",
|
|
46675
|
-
Notification: "Notification",
|
|
46676
|
-
SessionStart: "SessionStart",
|
|
46677
|
-
SessionEnd: "SessionEnd",
|
|
46678
|
-
UserPromptSubmit: "UserPromptSubmit",
|
|
46679
|
-
SubagentStart: null
|
|
46680
|
-
},
|
|
46718
|
+
claude: CLAUDE_EVENT_MAP,
|
|
46719
|
+
qwen: CLAUDE_EVENT_MAP,
|
|
46681
46720
|
gemini: {
|
|
46682
46721
|
PreToolUse: "BeforeTool",
|
|
46683
46722
|
PostToolUse: "AfterTool",
|
|
@@ -46709,15 +46748,6 @@ var EVENT_MAP = {
|
|
|
46709
46748
|
SubagentStart: "SubagentStart"
|
|
46710
46749
|
}
|
|
46711
46750
|
};
|
|
46712
|
-
function getTargetSettingsDir(target) {
|
|
46713
|
-
if (target === "codex")
|
|
46714
|
-
return ".codex";
|
|
46715
|
-
if (target === "codewith")
|
|
46716
|
-
return ".codewith";
|
|
46717
|
-
if (target === "gemini")
|
|
46718
|
-
return ".gemini";
|
|
46719
|
-
return ".claude";
|
|
46720
|
-
}
|
|
46721
46751
|
function getGlobalSettingsPathOverride(target) {
|
|
46722
46752
|
if (target === "codex")
|
|
46723
46753
|
return process.env.HASNA_HOOKS_CODEX_SETTINGS_PATH ?? (process.env.CODEX_HOME ? resolve28(process.env.CODEX_HOME, "hooks.json") : undefined);
|
|
@@ -46725,34 +46755,38 @@ function getGlobalSettingsPathOverride(target) {
|
|
|
46725
46755
|
return process.env.HASNA_HOOKS_CLAUDE_SETTINGS_PATH ?? (process.env.CLAUDE_CONFIG_DIR ? resolve28(process.env.CLAUDE_CONFIG_DIR, "settings.json") : undefined);
|
|
46726
46756
|
if (target === "gemini")
|
|
46727
46757
|
return process.env.HASNA_HOOKS_GEMINI_SETTINGS_PATH;
|
|
46758
|
+
if (target === "qwen")
|
|
46759
|
+
return process.env.HASNA_HOOKS_QWEN_SETTINGS_PATH;
|
|
46760
|
+
if (target === "codewith")
|
|
46761
|
+
return process.env.HASNA_HOOKS_CODEWITH_CONFIG_PATH;
|
|
46728
46762
|
return;
|
|
46729
46763
|
}
|
|
46764
|
+
function capabilityOptions(scope, hook) {
|
|
46765
|
+
return { scope, home: homedir8(), cwd: process.cwd(), env: process.env, ...hook ? { hook } : {} };
|
|
46766
|
+
}
|
|
46767
|
+
function adapterOptions(scope, home, run) {
|
|
46768
|
+
return { scope, home: home ?? process.env.HOME ?? homedir8(), cwd: process.cwd(), env: process.env, ...run ? { run } : {} };
|
|
46769
|
+
}
|
|
46730
46770
|
function getSettingsPath(scope = "global", target = "claude", codewithConfigPath) {
|
|
46731
46771
|
if (target === "codewith" && codewithConfigPath)
|
|
46732
46772
|
return codewithConfigPath;
|
|
46733
|
-
if (target === "codewith" && scope === "global" && process.env.HASNA_HOOKS_CODEWITH_CONFIG_PATH) {
|
|
46734
|
-
return process.env.HASNA_HOOKS_CODEWITH_CONFIG_PATH;
|
|
46735
|
-
}
|
|
46736
46773
|
const globalOverride = scope === "global" ? getGlobalSettingsPathOverride(target) : undefined;
|
|
46737
46774
|
if (globalOverride)
|
|
46738
46775
|
return globalOverride;
|
|
46739
|
-
const
|
|
46740
|
-
if (
|
|
46741
|
-
return
|
|
46742
|
-
|
|
46743
|
-
return target === "codewith" ? join17(process.cwd(), dir, "config.toml") : join17(process.cwd(), dir, "settings.json");
|
|
46744
|
-
}
|
|
46745
|
-
return target === "codewith" ? join17(homedir7(), dir, "config.toml") : join17(homedir7(), dir, "settings.json");
|
|
46776
|
+
const capabilities = getTargetCapabilities(target, capabilityOptions(scope));
|
|
46777
|
+
if (capabilities)
|
|
46778
|
+
return capabilities.configPath;
|
|
46779
|
+
return join24(homedir8(), ".claude", "settings.json");
|
|
46746
46780
|
}
|
|
46747
46781
|
function getHookPath(name) {
|
|
46748
46782
|
const shortName = shortHookName(name);
|
|
46749
46783
|
const resolved = resolveHookDir(shortName);
|
|
46750
46784
|
if (resolved)
|
|
46751
46785
|
return resolved;
|
|
46752
|
-
return
|
|
46786
|
+
return join24(HOOKS_DIR, normalizeHookName(shortName));
|
|
46753
46787
|
}
|
|
46754
46788
|
function hookExists(name) {
|
|
46755
|
-
return
|
|
46789
|
+
return existsSync14(getHookPath(name));
|
|
46756
46790
|
}
|
|
46757
46791
|
var settingsPreimages = new WeakMap;
|
|
46758
46792
|
var unreadableSettings = new WeakMap;
|
|
@@ -46762,14 +46796,14 @@ function readSettings(scope = "global", target = "claude") {
|
|
|
46762
46796
|
return readCodexSettings(path);
|
|
46763
46797
|
let reason2 = "cannot be read";
|
|
46764
46798
|
try {
|
|
46765
|
-
if (
|
|
46766
|
-
const
|
|
46799
|
+
if (existsSync14(path)) {
|
|
46800
|
+
const text2 = readFileSync13(path, "utf-8");
|
|
46767
46801
|
reason2 = "is not valid JSON";
|
|
46768
|
-
const value = JSON.parse(
|
|
46802
|
+
const value = JSON.parse(text2);
|
|
46769
46803
|
reason2 = "does not hold a JSON object";
|
|
46770
46804
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
46771
46805
|
throw new TypeError(reason2);
|
|
46772
|
-
settingsPreimages.set(value, { path, text:
|
|
46806
|
+
settingsPreimages.set(value, { path, text: text2 });
|
|
46773
46807
|
return value;
|
|
46774
46808
|
}
|
|
46775
46809
|
} catch (error61) {
|
|
@@ -46779,7 +46813,7 @@ function readSettings(scope = "global", target = "claude") {
|
|
|
46779
46813
|
console.warn("[hooks] Cannot read hook settings; repair the selected file before installation.");
|
|
46780
46814
|
}
|
|
46781
46815
|
const empty = {};
|
|
46782
|
-
if (!
|
|
46816
|
+
if (!existsSync14(path))
|
|
46783
46817
|
settingsPreimages.set(empty, { path, text: null });
|
|
46784
46818
|
else
|
|
46785
46819
|
unreadableSettings.set(empty, { path, reason: reason2 });
|
|
@@ -46787,23 +46821,23 @@ function readSettings(scope = "global", target = "claude") {
|
|
|
46787
46821
|
}
|
|
46788
46822
|
function unreadableSettingsRefusal(settings, path) {
|
|
46789
46823
|
const captured = settingsPreimages.get(settings);
|
|
46790
|
-
if (captured?.path === path && captured.text !== null || !
|
|
46824
|
+
if (captured?.path === path && captured.text !== null || !existsSync14(path))
|
|
46791
46825
|
return;
|
|
46792
46826
|
const failed = unreadableSettings.get(settings);
|
|
46793
46827
|
const reason2 = captured?.path === path ? "was created after Hooks read the settings" : failed?.path === path ? failed.reason : "was not read as a settings object";
|
|
46794
46828
|
return new ClaudeSettingsRefusal("settings_unreadable", `${path} ${reason2}, so Hooks wrote nothing. Repair the file or move it aside, then retry.`);
|
|
46795
46829
|
}
|
|
46796
46830
|
function settingsIdentity(path) {
|
|
46797
|
-
if (
|
|
46831
|
+
if (existsSync14(path))
|
|
46798
46832
|
return realpathSync4(path);
|
|
46799
|
-
return
|
|
46833
|
+
return existsSync14(dirname16(path)) ? join24(realpathSync4(dirname16(path)), basename12(path)) : resolve28(path);
|
|
46800
46834
|
}
|
|
46801
46835
|
function coordinatesWithSkills(path, target) {
|
|
46802
|
-
return target === "claude" && settingsIdentity(path) === settingsIdentity(
|
|
46836
|
+
return target === "claude" && settingsIdentity(path) === settingsIdentity(join24(homedir8(), ".claude/settings.json"));
|
|
46803
46837
|
}
|
|
46804
46838
|
function planClaudeSettingsWrite(before, after, scope = "global") {
|
|
46805
46839
|
if (coordinatesWithSkills(getSettingsPath(scope, "claude"), "claude"))
|
|
46806
|
-
planCoordinatedClaudeSettings(before, after, { home:
|
|
46840
|
+
planCoordinatedClaudeSettings(before, after, { home: homedir8() });
|
|
46807
46841
|
}
|
|
46808
46842
|
function writerRefusal(error61) {
|
|
46809
46843
|
return { error: error61 instanceof Error ? error61.message : "Unknown error", ...error61 instanceof ClaudeSettingsRefusal ? { code: error61.code } : {} };
|
|
@@ -46825,21 +46859,21 @@ function writeSettings(settings, scope = "global", target = "claude", expectedSe
|
|
|
46825
46859
|
const before = settingsPreimages.get(settings);
|
|
46826
46860
|
if (!before || before.path !== path)
|
|
46827
46861
|
throw new Error("Claude settings require a valid captured preimage before installation.");
|
|
46828
|
-
const current2 =
|
|
46862
|
+
const current2 = existsSync14(path) ? readFileSync13(path, "utf8") : null;
|
|
46829
46863
|
if (current2 !== before.text)
|
|
46830
46864
|
throw new Error("Claude settings changed during installation; no settings were written.");
|
|
46831
46865
|
if (coordinateClaudeSettings(before.text, JSON.stringify(settings, null, 2) + `
|
|
46832
|
-
`, { home:
|
|
46866
|
+
`, { home: homedir8() }, beforeWrite))
|
|
46833
46867
|
return;
|
|
46834
46868
|
}
|
|
46835
46869
|
if (expectedSettingsSha256 !== undefined)
|
|
46836
46870
|
return writeHookSettingsPreimage(path, settings, captured.text, beforeWrite);
|
|
46837
46871
|
beforeWrite?.();
|
|
46838
|
-
const dir =
|
|
46839
|
-
if (!
|
|
46840
|
-
|
|
46872
|
+
const dir = dirname16(path);
|
|
46873
|
+
if (!existsSync14(dir)) {
|
|
46874
|
+
mkdirSync12(dir, { recursive: true });
|
|
46841
46875
|
}
|
|
46842
|
-
|
|
46876
|
+
writeFileSync10(path, JSON.stringify(settings, null, 2) + `
|
|
46843
46877
|
`);
|
|
46844
46878
|
}
|
|
46845
46879
|
function getTargetEventName(internalEvent, target) {
|
|
@@ -46848,7 +46882,7 @@ function getTargetEventName(internalEvent, target) {
|
|
|
46848
46882
|
function isEventSupported(internalEvent, target) {
|
|
46849
46883
|
return getTargetEventName(internalEvent, target) !== null;
|
|
46850
46884
|
}
|
|
46851
|
-
function
|
|
46885
|
+
function tomlString2(value) {
|
|
46852
46886
|
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
46853
46887
|
}
|
|
46854
46888
|
function codewithMatcher(matcher) {
|
|
@@ -46922,8 +46956,8 @@ function buildCodewithTomlFragment(name, profile, mementos) {
|
|
|
46922
46956
|
`[[hooks.${eventKey}]]`
|
|
46923
46957
|
];
|
|
46924
46958
|
if (matcher)
|
|
46925
|
-
lines.push(`matcher = ${
|
|
46926
|
-
lines.push("", `[[hooks.${eventKey}.hooks]]`, `type = "command"`, `command = ${
|
|
46959
|
+
lines.push(`matcher = ${tomlString2(matcher)}`);
|
|
46960
|
+
lines.push("", `[[hooks.${eventKey}.hooks]]`, `type = "command"`, `command = ${tomlString2(command)}`, `timeout = ${codewithTimeout(shortName)}`, `statusMessage = ${tomlString2(codewithStatusMessage(shortName))}`);
|
|
46927
46961
|
fragments.push(lines.join(`
|
|
46928
46962
|
`));
|
|
46929
46963
|
}
|
|
@@ -46935,21 +46969,21 @@ function buildCodewithTomlFragment(name, profile, mementos) {
|
|
|
46935
46969
|
function readCodewithConfig(scope, configPath) {
|
|
46936
46970
|
const path = getSettingsPath(scope, "codewith", configPath);
|
|
46937
46971
|
try {
|
|
46938
|
-
return
|
|
46972
|
+
return existsSync14(path) ? readFileSync13(path, "utf-8") : "";
|
|
46939
46973
|
} catch {
|
|
46940
46974
|
return "";
|
|
46941
46975
|
}
|
|
46942
46976
|
}
|
|
46943
46977
|
function appendCodewithFragment(fragment, scope, configPath) {
|
|
46944
46978
|
const path = getSettingsPath(scope, "codewith", configPath);
|
|
46945
|
-
const dir =
|
|
46946
|
-
if (!
|
|
46947
|
-
|
|
46948
|
-
const existing =
|
|
46979
|
+
const dir = dirname16(path);
|
|
46980
|
+
if (!existsSync14(dir))
|
|
46981
|
+
mkdirSync12(dir, { recursive: true });
|
|
46982
|
+
const existing = existsSync14(path) ? readFileSync13(path, "utf-8") : "";
|
|
46949
46983
|
const sep10 = existing.trim() ? `
|
|
46950
46984
|
|
|
46951
46985
|
` : "";
|
|
46952
|
-
|
|
46986
|
+
writeFileSync10(path, `${existing.replace(/\s*$/, "")}${sep10}${fragment}`);
|
|
46953
46987
|
return path;
|
|
46954
46988
|
}
|
|
46955
46989
|
function detectConflict(name, scope, target) {
|
|
@@ -46992,14 +47026,59 @@ function detectRewriteConflict(name, scope, target, lookup = getHook) {
|
|
|
46992
47026
|
}
|
|
46993
47027
|
return;
|
|
46994
47028
|
}
|
|
47029
|
+
function installForAdapter(shortName, scope, overwrite, target, events3, timeoutSeconds, profile, mementos) {
|
|
47030
|
+
const stopEvent = getTargetCapabilities(target, capabilityOptions(scope, shortName))?.stopEvent ?? "turn-end";
|
|
47031
|
+
const unsupported = events3.filter((event) => event !== "Stop");
|
|
47032
|
+
if (events3.length === 0 || unsupported.length > 0) {
|
|
47033
|
+
return {
|
|
47034
|
+
hook: shortName,
|
|
47035
|
+
success: false,
|
|
47036
|
+
scope,
|
|
47037
|
+
target,
|
|
47038
|
+
error: `Refused: '${shortName}' runs on ${events3.length > 0 ? events3.join(", ") : "no event"}, and target '${target}' only has the ${stopEvent} turn-end event. Install it on claude, codex, gemini, codewith or qwen; a harness config is never given an event it does not carry.`
|
|
47039
|
+
};
|
|
47040
|
+
}
|
|
47041
|
+
const options = adapterOptions(scope);
|
|
47042
|
+
const registered = readAdapterRegistrations(target, options).some((entry) => entry.hook === shortName);
|
|
47043
|
+
if (registered && !overwrite) {
|
|
47044
|
+
return { hook: shortName, success: false, error: "Already installed. Use --overwrite to replace.", scope, target };
|
|
47045
|
+
}
|
|
47046
|
+
if (registered)
|
|
47047
|
+
removeFromAdapter(target, shortName, options);
|
|
47048
|
+
const conflict = detectConflict(shortName, scope, target);
|
|
47049
|
+
const command = (profile ? `hooks run ${shortName} --profile ${profile}` : `hooks run ${shortName}`) + ` --target ${target}` + mementosCommandSuffix(mementos);
|
|
47050
|
+
const outcome = installInAdapter(target, shortName, command, options, timeoutSeconds);
|
|
47051
|
+
if (!outcome.ok) {
|
|
47052
|
+
return { hook: shortName, success: false, error: outcome.error, scope, target, ...outcome.configPath ? { configPath: outcome.configPath } : {} };
|
|
47053
|
+
}
|
|
47054
|
+
const note = [outcome.note, targetInstallNote(target)].filter(Boolean).join(" ");
|
|
47055
|
+
return {
|
|
47056
|
+
hook: shortName,
|
|
47057
|
+
success: true,
|
|
47058
|
+
scope,
|
|
47059
|
+
target,
|
|
47060
|
+
applied: true,
|
|
47061
|
+
conflict,
|
|
47062
|
+
configPath: outcome.configPath,
|
|
47063
|
+
...note ? { note } : {}
|
|
47064
|
+
};
|
|
47065
|
+
}
|
|
46995
47066
|
function installForTarget(name, scope, overwrite, target, profile, codewithMode = "fragment", codewithConfigPath, mementos, expectedSettingsSha256, beforeWrite) {
|
|
46996
47067
|
const shortName = shortHookName(name);
|
|
46997
|
-
if (isNativeSafetyName(shortName) && (profile || target === "gemini" || target === "codewith" && codewithMode === "write")) {
|
|
47068
|
+
if (isNativeSafetyName(shortName) && (profile || target === "gemini" || isAdapterTarget(target) || target === "codewith" && codewithMode === "write")) {
|
|
46998
47069
|
return { hook: shortName, success: false, error: "Bundled native safety guards support Claude/Codex and managed Codewith fragments, without registry profiles.", target };
|
|
46999
47070
|
}
|
|
47000
47071
|
if (!isNativeSafetyName(shortName) && !hookExists(shortName)) {
|
|
47001
47072
|
return { hook: shortName, success: false, error: `Hook '${shortName}' not found`, target };
|
|
47002
47073
|
}
|
|
47074
|
+
const meta3 = isNativeSafetyName(shortName) ? getHook(shortName) : resolveHookMeta(shortName);
|
|
47075
|
+
const events3 = meta3 ? getHookEvents(meta3) : [];
|
|
47076
|
+
const capabilityRefusal = installCapabilityRefusal(shortName, target, { events: events3, requiresFinalMessage: meta3?.requiresFinalMessage === true, requiresBlock: meta3?.requiresBlock === true }, capabilityOptions(scope, shortName));
|
|
47077
|
+
if (capabilityRefusal)
|
|
47078
|
+
return { hook: shortName, success: false, error: capabilityRefusal, scope, target };
|
|
47079
|
+
if (isAdapterTarget(target)) {
|
|
47080
|
+
return installForAdapter(shortName, scope, overwrite, target, events3, meta3?.timeoutSeconds ?? 10, profile, mementos);
|
|
47081
|
+
}
|
|
47003
47082
|
if (target === "codewith") {
|
|
47004
47083
|
try {
|
|
47005
47084
|
const fragment = buildCodewithTomlFragment(shortName, profile, mementos);
|
|
@@ -47050,7 +47129,8 @@ function installForTarget(name, scope, overwrite, target, profile, codewithMode
|
|
|
47050
47129
|
}
|
|
47051
47130
|
}
|
|
47052
47131
|
try {
|
|
47053
|
-
const
|
|
47132
|
+
const settingsTarget = target;
|
|
47133
|
+
const registered = getRegisteredHooksForTarget(scope, settingsTarget);
|
|
47054
47134
|
if (registered.includes(shortName) && !overwrite) {
|
|
47055
47135
|
return { hook: shortName, success: false, error: "Already installed. Use --overwrite to replace.", scope, target };
|
|
47056
47136
|
}
|
|
@@ -47059,7 +47139,7 @@ function installForTarget(name, scope, overwrite, target, profile, codewithMode
|
|
|
47059
47139
|
if (rewriteConflict) {
|
|
47060
47140
|
return { hook: shortName, success: false, error: `Refused: ${rewriteConflict}`, scope, target };
|
|
47061
47141
|
}
|
|
47062
|
-
registerHook(shortName, scope,
|
|
47142
|
+
registerHook(shortName, scope, settingsTarget, profile, mementos, (settings, selectedScope, selectedTarget) => writeSettings(settings, selectedScope, selectedTarget, expectedSettingsSha256, beforeWrite));
|
|
47063
47143
|
return {
|
|
47064
47144
|
hook: shortName,
|
|
47065
47145
|
success: true,
|
|
@@ -47283,6 +47363,9 @@ function installHooks(names, options = {}) {
|
|
|
47283
47363
|
return names.map((name) => installHook(name, options));
|
|
47284
47364
|
}
|
|
47285
47365
|
function getRegisteredHooksForTarget(scope = "global", target = "claude") {
|
|
47366
|
+
if (isAdapterTarget(target)) {
|
|
47367
|
+
return [...new Set(readAdapterRegistrations(target, adapterOptions(scope)).map((entry) => entry.hook))];
|
|
47368
|
+
}
|
|
47286
47369
|
if (target === "codewith") {
|
|
47287
47370
|
const config2 = readCodewithConfig(scope);
|
|
47288
47371
|
const registered2 = [];
|
|
@@ -47322,20 +47405,37 @@ function getRegisteredHooks(scope = "global") {
|
|
|
47322
47405
|
return getRegisteredHooksForTarget(scope, "claude");
|
|
47323
47406
|
}
|
|
47324
47407
|
var getInstalledHooks = getRegisteredHooks;
|
|
47325
|
-
function removeHook(name, scope = "global", target = "claude") {
|
|
47408
|
+
function removeHook(name, scope = "global", target = "claude", options = {}) {
|
|
47326
47409
|
const shortName = shortHookName(name);
|
|
47327
47410
|
if (target === "all") {
|
|
47328
|
-
|
|
47329
|
-
const
|
|
47330
|
-
|
|
47331
|
-
|
|
47411
|
+
let removedAny = false;
|
|
47412
|
+
for (const candidate of ALL_REMOVABLE_TARGETS) {
|
|
47413
|
+
if (removeHookForTarget(shortName, scope, candidate, options.run))
|
|
47414
|
+
removedAny = true;
|
|
47415
|
+
}
|
|
47416
|
+
return removedAny;
|
|
47332
47417
|
}
|
|
47333
47418
|
if (target === "codewith") {
|
|
47334
47419
|
return false;
|
|
47335
47420
|
}
|
|
47336
|
-
|
|
47421
|
+
if (isAdapterTarget(target)) {
|
|
47422
|
+
return removeFromAdapter(target, shortName, adapterOptions(scope, undefined, options.run)).removed;
|
|
47423
|
+
}
|
|
47424
|
+
if (target === "opencode" || target === "sumi") {
|
|
47425
|
+
return false;
|
|
47426
|
+
}
|
|
47427
|
+
return removeHookForTarget(shortName, scope, target, options.run);
|
|
47337
47428
|
}
|
|
47338
|
-
function removeHookForTarget(name, scope, target) {
|
|
47429
|
+
function removeHookForTarget(name, scope, target, run) {
|
|
47430
|
+
if (isAdapterTarget(target)) {
|
|
47431
|
+
const options = adapterOptions(scope, undefined, run);
|
|
47432
|
+
const state = readAdapterState(target, options);
|
|
47433
|
+
if (state.status !== "verified")
|
|
47434
|
+
return false;
|
|
47435
|
+
if (!adapterStateCarries(state, name))
|
|
47436
|
+
return false;
|
|
47437
|
+
return removeFromAdapter(target, name, options).removed;
|
|
47438
|
+
}
|
|
47339
47439
|
const registered = getRegisteredHooksForTarget(scope, target);
|
|
47340
47440
|
if (!registered.includes(name)) {
|
|
47341
47441
|
return false;
|
|
@@ -47343,7 +47443,8 @@ function removeHookForTarget(name, scope, target) {
|
|
|
47343
47443
|
unregisterHook(name, scope, target);
|
|
47344
47444
|
return true;
|
|
47345
47445
|
}
|
|
47346
|
-
var JSON_SETTINGS_TARGETS = ["claude", "gemini", "codex"];
|
|
47446
|
+
var JSON_SETTINGS_TARGETS = ["claude", "gemini", "codex", "qwen"];
|
|
47447
|
+
var ALL_REMOVABLE_TARGETS = [...JSON_SETTINGS_TARGETS, ...ADAPTER_TARGETS];
|
|
47347
47448
|
function removeCodewithHookEntry(configText, name) {
|
|
47348
47449
|
const sections = configText.split(/\n\s*\n/);
|
|
47349
47450
|
const commandRe = /^command\s*=\s*"([^"\n]+)"$/;
|
|
@@ -47400,70 +47501,149 @@ function codewithHasHookEntryInText(configText, name) {
|
|
|
47400
47501
|
}
|
|
47401
47502
|
function codewithHasHookEntry(name, scope = "global") {
|
|
47402
47503
|
const path = getSettingsPath(scope, "codewith");
|
|
47403
|
-
if (!
|
|
47504
|
+
if (!existsSync14(path))
|
|
47404
47505
|
return false;
|
|
47405
47506
|
try {
|
|
47406
|
-
return codewithHasHookEntryInText(
|
|
47507
|
+
return codewithHasHookEntryInText(readFileSync13(path, "utf-8"), name);
|
|
47407
47508
|
} catch {
|
|
47408
47509
|
return false;
|
|
47409
47510
|
}
|
|
47410
47511
|
}
|
|
47411
47512
|
function removeStoreDirFailClosed(dir) {
|
|
47412
|
-
const entries =
|
|
47513
|
+
const entries = readdirSync8(dir, { withFileTypes: true });
|
|
47413
47514
|
for (const entry of entries) {
|
|
47414
47515
|
if (entry.isDirectory()) {
|
|
47415
|
-
removeStoreDirFailClosed(
|
|
47516
|
+
removeStoreDirFailClosed(join24(dir, entry.name));
|
|
47416
47517
|
}
|
|
47417
47518
|
}
|
|
47418
47519
|
for (const entry of entries) {
|
|
47419
47520
|
if (!entry.isDirectory()) {
|
|
47420
|
-
|
|
47521
|
+
unlinkSync6(join24(dir, entry.name));
|
|
47421
47522
|
}
|
|
47422
47523
|
}
|
|
47423
|
-
|
|
47524
|
+
rmdirSync4(dir);
|
|
47424
47525
|
}
|
|
47425
|
-
function uninstallHook(name, scope = "global", target = "claude") {
|
|
47526
|
+
function uninstallHook(name, scope = "global", target = "claude", options = {}) {
|
|
47426
47527
|
const shortName = shortHookName(name);
|
|
47528
|
+
const adapterOptionsFor = (s) => adapterOptions(s, undefined, options.run);
|
|
47427
47529
|
const custom3 = readCustomManifest(shortName);
|
|
47428
47530
|
const bundledMeta = custom3 ? undefined : getHook(shortName);
|
|
47429
|
-
const
|
|
47430
|
-
const
|
|
47431
|
-
const
|
|
47432
|
-
const
|
|
47531
|
+
const configuredTargets = target === "all" ? ALL_REMOVABLE_TARGETS : [target];
|
|
47532
|
+
const adapterStates = new Map;
|
|
47533
|
+
const unreadable = [];
|
|
47534
|
+
const notes = [];
|
|
47535
|
+
const withNotes = (result) => notes.length > 0 ? { ...result, notes } : result;
|
|
47536
|
+
const adapterStateFor = (t, s) => {
|
|
47537
|
+
const key2 = `${s}:${t}`;
|
|
47538
|
+
const cached2 = adapterStates.get(key2);
|
|
47539
|
+
if (cached2)
|
|
47540
|
+
return cached2;
|
|
47541
|
+
const state = isAdapterTarget(t) ? readAdapterState(t, adapterOptionsFor(s)) : { status: "verified", registrations: [] };
|
|
47542
|
+
adapterStates.set(key2, state);
|
|
47543
|
+
return state;
|
|
47544
|
+
};
|
|
47545
|
+
const forgetAdapterState = (t, s) => {
|
|
47546
|
+
adapterStates.delete(`${s}:${t}`);
|
|
47547
|
+
};
|
|
47548
|
+
const isRegistered = (s, t) => {
|
|
47549
|
+
if (!isAdapterTarget(t))
|
|
47550
|
+
return getRegisteredHooksForTarget(s, t).includes(shortName);
|
|
47551
|
+
const state = adapterStateFor(t, s);
|
|
47552
|
+
if (state.status === "unverified") {
|
|
47553
|
+
if (state.absent && target === "all") {
|
|
47554
|
+
const note = `${t}: skipped, ${state.reason}`;
|
|
47555
|
+
if (!notes.includes(note))
|
|
47556
|
+
notes.push(note);
|
|
47557
|
+
return false;
|
|
47558
|
+
}
|
|
47559
|
+
const reason2 = `${t} (${s} scope): its config could not be read \u2014 ${state.reason}`;
|
|
47560
|
+
if (!unreadable.includes(reason2))
|
|
47561
|
+
unreadable.push(reason2);
|
|
47562
|
+
return false;
|
|
47563
|
+
}
|
|
47564
|
+
return adapterStateCarries(state, shortName);
|
|
47565
|
+
};
|
|
47566
|
+
const registeredGlobal = configuredTargets.some((t) => isRegistered("global", t));
|
|
47567
|
+
const registeredProject = configuredTargets.some((t) => isRegistered("project", t));
|
|
47433
47568
|
const codewithOnly = (target === "codewith" || target === "all") && codewithHasHookEntry(shortName, scope);
|
|
47434
|
-
if (!custom3 && !bundledMeta && !registeredGlobal && !registeredProject && !codewithOnly) {
|
|
47435
|
-
return { name: shortName, removed: false, source: null, settingsScopes: [], storeDirRemoved: false, pinRemoved: false, dbRecordRemoved: false, registrationsRemaining: [], error: `Hook '${shortName}' not found` };
|
|
47569
|
+
if (!custom3 && !bundledMeta && !registeredGlobal && !registeredProject && !codewithOnly && unreadable.length === 0) {
|
|
47570
|
+
return withNotes({ name: shortName, removed: false, source: null, settingsScopes: [], storeDirRemoved: false, pinRemoved: false, dbRecordRemoved: false, registrationsRemaining: [], error: `Hook '${shortName}' not found` });
|
|
47436
47571
|
}
|
|
47437
|
-
const writableTargets = target === "all" ?
|
|
47572
|
+
const writableTargets = target === "all" ? ALL_REMOVABLE_TARGETS : target === "codewith" ? [] : [target];
|
|
47438
47573
|
const scopes = [];
|
|
47574
|
+
const registrationsRemaining = [];
|
|
47575
|
+
const notRemoved = [];
|
|
47576
|
+
const attemptedStores = new Set;
|
|
47439
47577
|
for (const s of ["global", "project"]) {
|
|
47440
47578
|
for (const t of writableTargets) {
|
|
47441
|
-
if (
|
|
47579
|
+
if (!isRegistered(s, t))
|
|
47580
|
+
continue;
|
|
47581
|
+
if (isAdapterTarget(t)) {
|
|
47582
|
+
const storePath = adapterStorePath(t, adapterOptionsFor(s), shortName);
|
|
47583
|
+
if (attemptedStores.has(storePath))
|
|
47584
|
+
continue;
|
|
47585
|
+
attemptedStores.add(storePath);
|
|
47586
|
+
const before = adapterStateFor(t, s);
|
|
47587
|
+
const disabledInStore = t === "muse" && adapterStateCarries(before, shortName) && !before.registrations.some((entry) => entry.hook === shortName);
|
|
47588
|
+
const outcome = removeFromAdapter(t, shortName, adapterOptionsFor(s));
|
|
47589
|
+
forgetAdapterState(t, s);
|
|
47590
|
+
if (!outcome.removed) {
|
|
47591
|
+
if (!registrationsRemaining.includes(t))
|
|
47592
|
+
registrationsRemaining.push(t);
|
|
47593
|
+
const reason2 = `${t} (${s} scope): ${outcome.reason ?? "the adapter refused the removal"}`;
|
|
47594
|
+
if (!notRemoved.includes(reason2))
|
|
47595
|
+
notRemoved.push(reason2);
|
|
47596
|
+
continue;
|
|
47597
|
+
}
|
|
47598
|
+
if (disabledInStore) {
|
|
47599
|
+
const bundleClause = outcome.bundleRemoved === undefined ? "the plugin was removed from Muse" : outcome.bundleRemoved ? `the plugin and its bundle at ${storePath} were removed` : `the plugin was removed from Muse; no bundle was present at ${storePath}`;
|
|
47600
|
+
const note = `${t} (${s} scope): '${shortName}' is in Muse's store but is not enabled now, and Hooks cannot tell whether it ran; ${bundleClause}.`;
|
|
47601
|
+
if (!notes.includes(note))
|
|
47602
|
+
notes.push(note);
|
|
47603
|
+
} else if (outcome.reason) {
|
|
47604
|
+
const note = `${t} (${s} scope): ${outcome.reason}`;
|
|
47605
|
+
if (!notes.includes(note))
|
|
47606
|
+
notes.push(note);
|
|
47607
|
+
}
|
|
47608
|
+
} else {
|
|
47442
47609
|
unregisterHook(shortName, s, t);
|
|
47443
|
-
if (!scopes.includes(s))
|
|
47444
|
-
scopes.push(s);
|
|
47445
47610
|
}
|
|
47611
|
+
if (!scopes.includes(s))
|
|
47612
|
+
scopes.push(s);
|
|
47446
47613
|
}
|
|
47447
47614
|
}
|
|
47448
|
-
const registrationsRemaining = [];
|
|
47449
47615
|
if (target === "codewith" || target === "all") {
|
|
47450
47616
|
const codewithPath = getSettingsPath(scope, "codewith");
|
|
47451
|
-
if (
|
|
47452
|
-
const before =
|
|
47617
|
+
if (existsSync14(codewithPath)) {
|
|
47618
|
+
const before = readFileSync13(codewithPath, "utf-8");
|
|
47453
47619
|
const after = removeCodewithHookEntry(before, shortName);
|
|
47454
47620
|
if (after.removed) {
|
|
47455
|
-
|
|
47621
|
+
writeFileSync10(codewithPath, after.text, "utf-8");
|
|
47456
47622
|
}
|
|
47457
47623
|
if (codewithHasHookEntryInText(after.removed ? after.text : before, shortName)) {
|
|
47458
47624
|
registrationsRemaining.push("codewith");
|
|
47459
47625
|
}
|
|
47460
47626
|
}
|
|
47461
47627
|
}
|
|
47628
|
+
const blockers = [...unreadable, ...notRemoved];
|
|
47629
|
+
if (blockers.length > 0) {
|
|
47630
|
+
return withNotes({
|
|
47631
|
+
name: shortName,
|
|
47632
|
+
removed: false,
|
|
47633
|
+
source: custom3 ? "custom" : bundledMeta ? "bundled" : "registered-only",
|
|
47634
|
+
settingsScopes: scopes,
|
|
47635
|
+
storeDirRemoved: false,
|
|
47636
|
+
pinRemoved: false,
|
|
47637
|
+
dbRecordRemoved: false,
|
|
47638
|
+
registrationsRemaining,
|
|
47639
|
+
error: `Hook '${shortName}' was not fully uninstalled: ${blockers.join("; ")}. Its store, pin and DB record were preserved because that registration could still run; fix the named cause and retry.`
|
|
47640
|
+
});
|
|
47641
|
+
}
|
|
47462
47642
|
if (custom3) {
|
|
47463
47643
|
try {
|
|
47464
47644
|
removeStoreDirFailClosed(customHookDir(shortName));
|
|
47465
47645
|
} catch {
|
|
47466
|
-
return {
|
|
47646
|
+
return withNotes({
|
|
47467
47647
|
name: shortName,
|
|
47468
47648
|
removed: false,
|
|
47469
47649
|
source: "custom",
|
|
@@ -47473,11 +47653,11 @@ function uninstallHook(name, scope = "global", target = "claude") {
|
|
|
47473
47653
|
dbRecordRemoved: false,
|
|
47474
47654
|
registrationsRemaining,
|
|
47475
47655
|
error: `Hook '${shortName}' store directory could not be removed; trust records preserved (no fail-open)`
|
|
47476
|
-
};
|
|
47656
|
+
});
|
|
47477
47657
|
}
|
|
47478
47658
|
}
|
|
47479
47659
|
const { removedPin, removedRecord } = removeHookFromStore(shortName);
|
|
47480
|
-
return {
|
|
47660
|
+
return withNotes({
|
|
47481
47661
|
name: shortName,
|
|
47482
47662
|
removed: true,
|
|
47483
47663
|
source: custom3 ? "custom" : bundledMeta ? "bundled" : "registered-only",
|
|
@@ -47486,10 +47666,10 @@ function uninstallHook(name, scope = "global", target = "claude") {
|
|
|
47486
47666
|
pinRemoved: removedPin,
|
|
47487
47667
|
dbRecordRemoved: removedRecord,
|
|
47488
47668
|
registrationsRemaining
|
|
47489
|
-
};
|
|
47669
|
+
});
|
|
47490
47670
|
}
|
|
47491
47671
|
// src/index.ts
|
|
47492
|
-
import { readFileSync as
|
|
47672
|
+
import { readFileSync as readFileSync32 } from "fs";
|
|
47493
47673
|
init_profiles();
|
|
47494
47674
|
init_config();
|
|
47495
47675
|
|
|
@@ -47631,15 +47811,15 @@ init_manifest();
|
|
|
47631
47811
|
// src/lib/custom-install.ts
|
|
47632
47812
|
init_config();
|
|
47633
47813
|
init_manifest();
|
|
47634
|
-
import { existsSync as
|
|
47635
|
-
import { join as
|
|
47636
|
-
import { tmpdir } from "os";
|
|
47814
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync13, mkdtempSync as mkdtempSync2, readFileSync as readFileSync20, rmSync as rmSync5 } from "fs";
|
|
47815
|
+
import { join as join34 } from "path";
|
|
47816
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
47637
47817
|
function manifestAt(dir) {
|
|
47638
|
-
const path =
|
|
47639
|
-
if (!
|
|
47818
|
+
const path = join34(dir, "manifest.json");
|
|
47819
|
+
if (!existsSync15(path))
|
|
47640
47820
|
return;
|
|
47641
47821
|
try {
|
|
47642
|
-
return parseManifest(
|
|
47822
|
+
return parseManifest(readFileSync20(path, "utf-8"));
|
|
47643
47823
|
} catch {
|
|
47644
47824
|
return;
|
|
47645
47825
|
}
|
|
@@ -47658,8 +47838,8 @@ function writeFromManifest(manifest, srcDir, source, kind) {
|
|
|
47658
47838
|
return { name, version: manifest.version, kind, source, dir, scriptPath };
|
|
47659
47839
|
}
|
|
47660
47840
|
async function cloneToTemp(gitUrl) {
|
|
47661
|
-
const tmp = mkdtempSync2(
|
|
47662
|
-
const proc = Bun.spawn(["git", "clone", "--depth", "1", "--quiet", gitUrl,
|
|
47841
|
+
const tmp = mkdtempSync2(join34(tmpdir2(), "hooks-install-"));
|
|
47842
|
+
const proc = Bun.spawn(["git", "clone", "--depth", "1", "--quiet", gitUrl, join34(tmp, "repo")], {
|
|
47663
47843
|
stdout: "pipe",
|
|
47664
47844
|
stderr: "pipe"
|
|
47665
47845
|
});
|
|
@@ -47672,7 +47852,7 @@ async function cloneToTemp(gitUrl) {
|
|
|
47672
47852
|
rmSync5(tmp, { recursive: true, force: true });
|
|
47673
47853
|
throw new Error(`git clone failed (${exitCode}): ${stderr.trim()}`);
|
|
47674
47854
|
}
|
|
47675
|
-
return
|
|
47855
|
+
return join34(tmp, "repo");
|
|
47676
47856
|
}
|
|
47677
47857
|
function isGitUrl(value) {
|
|
47678
47858
|
return value.startsWith("git@") || value.startsWith("ssh://") || value.startsWith("file://") || value.endsWith(".git");
|
|
@@ -47682,7 +47862,7 @@ function isCustomSource(value) {
|
|
|
47682
47862
|
return true;
|
|
47683
47863
|
if (value.startsWith("http://") || value.startsWith("https://"))
|
|
47684
47864
|
return true;
|
|
47685
|
-
return
|
|
47865
|
+
return existsSync15(value);
|
|
47686
47866
|
}
|
|
47687
47867
|
async function installCustomSource(source) {
|
|
47688
47868
|
if (isGitUrl(source)) {
|
|
@@ -47696,11 +47876,11 @@ async function installCustomSource(source) {
|
|
|
47696
47876
|
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
47697
47877
|
return installManifestUrl(source);
|
|
47698
47878
|
}
|
|
47699
|
-
if (!
|
|
47879
|
+
if (!existsSync15(source)) {
|
|
47700
47880
|
throw new Error(`No such local path: ${source}`);
|
|
47701
47881
|
}
|
|
47702
47882
|
if (source.endsWith("manifest.json")) {
|
|
47703
|
-
const manifest = parseManifest(
|
|
47883
|
+
const manifest = parseManifest(readFileSync20(source, "utf-8"));
|
|
47704
47884
|
return writeFromManifest(manifest, source.substring(0, source.lastIndexOf("/")), source, "local");
|
|
47705
47885
|
}
|
|
47706
47886
|
return copyManifestDir(source, source, "local");
|
|
@@ -47731,18 +47911,18 @@ async function installManifestUrl(url2) {
|
|
|
47731
47911
|
}
|
|
47732
47912
|
// src/lib/sync.ts
|
|
47733
47913
|
init_config();
|
|
47734
|
-
import { createHash as createHash18, randomUUID as
|
|
47735
|
-
import { readFileSync as
|
|
47736
|
-
import { dirname as
|
|
47914
|
+
import { createHash as createHash18, randomUUID as randomUUID7 } from "crypto";
|
|
47915
|
+
import { readFileSync as readFileSync21, lstatSync as lstatSync18, mkdirSync as mkdirSync14, writeFileSync as writeFileSync11, accessSync as accessSync3, constants as constants5, existsSync as existsSync16 } from "fs";
|
|
47916
|
+
import { dirname as dirname27, join as join35, resolve as resolve30, sep as sep16 } from "path";
|
|
47737
47917
|
init_db();
|
|
47738
47918
|
init_store();
|
|
47739
47919
|
init_manifest();
|
|
47740
47920
|
init_registry_artifact();
|
|
47741
|
-
function sha256OfText(
|
|
47742
|
-
return createHash18("sha256").update(
|
|
47921
|
+
function sha256OfText(text2) {
|
|
47922
|
+
return createHash18("sha256").update(text2).digest("hex");
|
|
47743
47923
|
}
|
|
47744
47924
|
function sha256OfPath(path) {
|
|
47745
|
-
return createHash18("sha256").update(
|
|
47925
|
+
return createHash18("sha256").update(readFileSync21(path)).digest("hex");
|
|
47746
47926
|
}
|
|
47747
47927
|
function collectBundledCatalog() {
|
|
47748
47928
|
const out = [];
|
|
@@ -47902,7 +48082,7 @@ function prepareRegistryCommit(staged) {
|
|
|
47902
48082
|
if (!lstatSync18(path).isFile())
|
|
47903
48083
|
throw new Error("REGISTRY_SYNC_DESTINATION_INVALID");
|
|
47904
48084
|
accessSync3(path, constants5.W_OK);
|
|
47905
|
-
originals.set(path,
|
|
48085
|
+
originals.set(path, readFileSync21(path));
|
|
47906
48086
|
} catch (error61) {
|
|
47907
48087
|
if (error61.code !== "ENOENT")
|
|
47908
48088
|
throw error61;
|
|
@@ -47913,10 +48093,10 @@ function prepareRegistryCommit(staged) {
|
|
|
47913
48093
|
const script = resolve30(root, item.scriptRel);
|
|
47914
48094
|
if (script !== root && !script.startsWith(root + sep16))
|
|
47915
48095
|
throw new ScriptContainmentError(script, root, item.scriptRel);
|
|
47916
|
-
const manifest =
|
|
48096
|
+
const manifest = join35(root, "manifest.json");
|
|
47917
48097
|
if (script === manifest || script === root)
|
|
47918
48098
|
throw new Error("REGISTRY_SYNC_DESTINATION_INVALID");
|
|
47919
|
-
for (let path =
|
|
48099
|
+
for (let path = dirname27(script);; path = dirname27(path)) {
|
|
47920
48100
|
try {
|
|
47921
48101
|
if (!lstatSync18(path).isDirectory())
|
|
47922
48102
|
throw new Error("REGISTRY_SYNC_DESTINATION_INVALID");
|
|
@@ -47928,24 +48108,24 @@ function prepareRegistryCommit(staged) {
|
|
|
47928
48108
|
if (path === root)
|
|
47929
48109
|
break;
|
|
47930
48110
|
}
|
|
47931
|
-
if (
|
|
48111
|
+
if (existsSync16(root))
|
|
47932
48112
|
assertContained(script, root, item.scriptRel);
|
|
47933
48113
|
inspectFile(script);
|
|
47934
48114
|
inspectFile(manifest);
|
|
47935
48115
|
}
|
|
47936
48116
|
inspectFile(getLockPath());
|
|
47937
48117
|
if (originals.size) {
|
|
47938
|
-
const recovery =
|
|
47939
|
-
|
|
48118
|
+
const recovery = join35(getHooksDataDir(), "registry-preservation", randomUUID7());
|
|
48119
|
+
mkdirSync14(recovery, { recursive: true, mode: 448 });
|
|
47940
48120
|
const receipt = [];
|
|
47941
48121
|
for (const [target, bytes] of originals) {
|
|
47942
|
-
const path =
|
|
47943
|
-
|
|
47944
|
-
if (!
|
|
48122
|
+
const path = join35(recovery, `${receipt.length}.original`);
|
|
48123
|
+
writeFileSync11(path, bytes, { flag: "wx", mode: 384 });
|
|
48124
|
+
if (!readFileSync21(path).equals(bytes))
|
|
47945
48125
|
throw new Error("REGISTRY_PRESERVATION_READBACK_FAILED");
|
|
47946
48126
|
receipt.push({ target, preserved: path, sha256: createHash18("sha256").update(bytes).digest("hex"), readback: true });
|
|
47947
48127
|
}
|
|
47948
|
-
|
|
48128
|
+
writeFileSync11(join35(recovery, "receipt.json"), JSON.stringify(receipt, null, 2) + `
|
|
47949
48129
|
`, { flag: "wx", mode: 384 });
|
|
47950
48130
|
}
|
|
47951
48131
|
for (const item of staged)
|
|
@@ -48140,8 +48320,8 @@ async function installPinnedFromBundled(name, version3) {
|
|
|
48140
48320
|
// src/serve.ts
|
|
48141
48321
|
init_manifest();
|
|
48142
48322
|
init_store();
|
|
48143
|
-
import { readFileSync as
|
|
48144
|
-
import { dirname as
|
|
48323
|
+
import { readFileSync as readFileSync23 } from "fs";
|
|
48324
|
+
import { dirname as dirname29, join as join39 } from "path";
|
|
48145
48325
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
48146
48326
|
|
|
48147
48327
|
// src/lib/secure-compare.ts
|
|
@@ -49413,7 +49593,7 @@ async function registryReady() {
|
|
|
49413
49593
|
function json2(body, status = 200, headers = {}) {
|
|
49414
49594
|
return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json", "cache-control": "no-store", ...headers } });
|
|
49415
49595
|
}
|
|
49416
|
-
async function
|
|
49596
|
+
async function boundedJson(request) {
|
|
49417
49597
|
if (!request.body)
|
|
49418
49598
|
throw new RegistryError(400, "REGISTRY_BODY_REQUIRED");
|
|
49419
49599
|
const reader = request.body.getReader(), chunks = [];
|
|
@@ -49456,7 +49636,7 @@ async function handleRegistryRequest(request, key2, registry2) {
|
|
|
49456
49636
|
if (path === "/v1/lock" && request.method === "GET")
|
|
49457
49637
|
return json2(await owner2.selection(url2.searchParams.get("profile") ?? "fleet"));
|
|
49458
49638
|
if (path === "/v1/hooks" && request.method === "PUT")
|
|
49459
|
-
return json2(await owner2.publish(await
|
|
49639
|
+
return json2(await owner2.publish(await boundedJson(request)));
|
|
49460
49640
|
const artifact = /^\/v1\/hooks\/([^/]+)\/([^/]+)$/.exec(path);
|
|
49461
49641
|
if (artifact && request.method === "GET") {
|
|
49462
49642
|
const { body, row, format, portable } = await owner2.artifactWire(decodeURIComponent(artifact[1]), decodeURIComponent(artifact[2]));
|
|
@@ -49468,7 +49648,7 @@ async function handleRegistryRequest(request, key2, registry2) {
|
|
|
49468
49648
|
if (request.method === "GET")
|
|
49469
49649
|
return json2(await owner2.selection(profile));
|
|
49470
49650
|
if (request.method === "PUT")
|
|
49471
|
-
return json2(await owner2.select(profile, await
|
|
49651
|
+
return json2(await owner2.select(profile, await boundedJson(request)));
|
|
49472
49652
|
}
|
|
49473
49653
|
return json2({ error: "REGISTRY_ROUTE_NOT_FOUND" }, 404);
|
|
49474
49654
|
} catch (error61) {
|
|
@@ -49487,8 +49667,8 @@ var SERVE_HOST = "127.0.0.1";
|
|
|
49487
49667
|
var SERVE_SERVICE_NAME = "hooks-registry";
|
|
49488
49668
|
function packageVersion() {
|
|
49489
49669
|
try {
|
|
49490
|
-
const pkgPath =
|
|
49491
|
-
return JSON.parse(
|
|
49670
|
+
const pkgPath = join39(dirname29(fileURLToPath5(import.meta.url)), "..", "package.json");
|
|
49671
|
+
return JSON.parse(readFileSync23(pkgPath, "utf-8")).version || "0.0.0";
|
|
49492
49672
|
} catch {
|
|
49493
49673
|
return "0.0.0";
|
|
49494
49674
|
}
|
|
@@ -49747,16 +49927,16 @@ async function provisionCloudflareResources(options) {
|
|
|
49747
49927
|
return result;
|
|
49748
49928
|
}
|
|
49749
49929
|
// src/lib/codex-safety-trust.ts
|
|
49750
|
-
import { createHash as createHash31, randomUUID as
|
|
49751
|
-
import { constants as constants21, closeSync as closeSync15, fsyncSync as fsyncSync5, fstatSync as fstatSync15, lstatSync as lstatSync33, mkdirSync as
|
|
49752
|
-
import { dirname as
|
|
49753
|
-
import { homedir as
|
|
49930
|
+
import { createHash as createHash31, randomUUID as randomUUID8 } from "crypto";
|
|
49931
|
+
import { constants as constants21, closeSync as closeSync15, fsyncSync as fsyncSync5, fstatSync as fstatSync15, lstatSync as lstatSync33, mkdirSync as mkdirSync16, openSync as openSync15, readFileSync as readFileSync29, realpathSync as realpathSync16, writeFileSync as writeFileSync13 } from "fs";
|
|
49932
|
+
import { dirname as dirname33, isAbsolute as isAbsolute29, join as join42, relative as relative2 } from "path";
|
|
49933
|
+
import { homedir as homedir10 } from "os";
|
|
49754
49934
|
|
|
49755
49935
|
// src/lib/codex-safety-check.ts
|
|
49756
49936
|
import { spawn as spawn2, execFile as execFile2 } from "child_process";
|
|
49757
49937
|
import { createHash as createHash25 } from "crypto";
|
|
49758
|
-
import { constants as constants16, openSync as openSync10, closeSync as closeSync10, fstatSync as fstatSync10, lstatSync as lstatSync29, readFileSync as
|
|
49759
|
-
import { dirname as
|
|
49938
|
+
import { constants as constants16, openSync as openSync10, closeSync as closeSync10, fstatSync as fstatSync10, lstatSync as lstatSync29, readFileSync as readFileSync27, realpathSync as realpathSync14 } from "fs";
|
|
49939
|
+
import { dirname as dirname31, isAbsolute as isAbsolute17, resolve as resolve33 } from "path";
|
|
49760
49940
|
import { promisify } from "util";
|
|
49761
49941
|
|
|
49762
49942
|
// src/lib/native-child-env.ts
|
|
@@ -49803,9 +49983,9 @@ function nativeChildEnv(source, explicit = {}, inherit = () => false) {
|
|
|
49803
49983
|
|
|
49804
49984
|
// src/native-safety.ts
|
|
49805
49985
|
import { execFile } from "child_process";
|
|
49806
|
-
import { closeSync as closeSync8, constants as constants9, existsSync as
|
|
49807
|
-
import { homedir as
|
|
49808
|
-
import { dirname as
|
|
49986
|
+
import { closeSync as closeSync8, constants as constants9, existsSync as existsSync17, fstatSync as fstatSync8, fsyncSync, linkSync, lstatSync as lstatSync26, mkdirSync as mkdirSync15, openSync as openSync8, readFileSync as readFileSync25, realpathSync as realpathSync11, renameSync as renameSync7, unlinkSync as unlinkSync8, writeFileSync as writeFileSync12 } from "fs";
|
|
49987
|
+
import { homedir as homedir9 } from "os";
|
|
49988
|
+
import { dirname as dirname30, isAbsolute as isAbsolute14, join as join41, resolve as resolve31 } from "path";
|
|
49809
49989
|
class NativeSafetyError extends Error {
|
|
49810
49990
|
code;
|
|
49811
49991
|
reason;
|
|
@@ -49819,11 +49999,11 @@ class NativeSafetyError extends Error {
|
|
|
49819
49999
|
var executionSchema = "hasna.hooks.execution.v1";
|
|
49820
50000
|
var owner2 = (uid2) => uid2 === 0 || uid2 === process.getuid?.();
|
|
49821
50001
|
function safeDirectory(path) {
|
|
49822
|
-
for (let cursor = path;; cursor =
|
|
50002
|
+
for (let cursor = path;; cursor = dirname30(cursor)) {
|
|
49823
50003
|
const stat2 = lstatSync26(cursor);
|
|
49824
50004
|
if (!stat2.isDirectory() || !owner2(stat2.uid) || stat2.mode & 18)
|
|
49825
50005
|
throw new NativeSafetyError("binding_invalid");
|
|
49826
|
-
if (
|
|
50006
|
+
if (dirname30(cursor) === cursor)
|
|
49827
50007
|
return;
|
|
49828
50008
|
}
|
|
49829
50009
|
}
|
|
@@ -49833,8 +50013,8 @@ function canonicalHome(home) {
|
|
|
49833
50013
|
safeDirectory(home);
|
|
49834
50014
|
return resolve31(home);
|
|
49835
50015
|
}
|
|
49836
|
-
function parseRecord(
|
|
49837
|
-
const record6 = JSON.parse(
|
|
50016
|
+
function parseRecord(text2, home) {
|
|
50017
|
+
const record6 = JSON.parse(text2);
|
|
49838
50018
|
if (!record6 || Array.isArray(record6) || Object.keys(record6).sort().join() !== "command,harness,schema" || record6.schema !== "hasna.hooks.native-safety.v1" || record6.harness !== "sumi" || typeof record6.command !== "string")
|
|
49839
50019
|
throw new NativeSafetyError("binding_invalid");
|
|
49840
50020
|
const binding = nativeSafetyCommandBinding(record6.command);
|
|
@@ -49875,7 +50055,7 @@ async function evaluateRecord(event, record6, signal, executionAgent) {
|
|
|
49875
50055
|
} catch {}
|
|
49876
50056
|
throw new NativeSafetyError("guard_failed");
|
|
49877
50057
|
}
|
|
49878
|
-
async function verifyNativeSafetyCommand(command, home =
|
|
50058
|
+
async function verifyNativeSafetyCommand(command, home = homedir9(), guard = "trash-guard") {
|
|
49879
50059
|
if (guard !== "trash-guard" && guard !== "workspace-repos-guard")
|
|
49880
50060
|
throw new NativeSafetyError("input_invalid");
|
|
49881
50061
|
home = canonicalHome(home);
|
|
@@ -49883,7 +50063,7 @@ async function verifyNativeSafetyCommand(command, home = homedir8(), guard = "tr
|
|
|
49883
50063
|
const binding = nativeSafetyCommandBinding(command);
|
|
49884
50064
|
if (binding?.name !== guard || binding.home !== home)
|
|
49885
50065
|
throw new NativeSafetyError("binding_invalid");
|
|
49886
|
-
const root =
|
|
50066
|
+
const root = join41(home, ".hasna", "repos", "clones"), probe2 = join41(root, ".hasna-workspace-repos-verification-only");
|
|
49887
50067
|
const verdict2 = await evaluateRecord({
|
|
49888
50068
|
hook_event_name: "PreToolUse",
|
|
49889
50069
|
tool_name: "Bash",
|
|
@@ -49936,17 +50116,17 @@ function executable2(command) {
|
|
|
49936
50116
|
need11(found, "native_unavailable");
|
|
49937
50117
|
try {
|
|
49938
50118
|
const path = realpathSync14(found);
|
|
49939
|
-
for (let parent =
|
|
50119
|
+
for (let parent = dirname31(path);; parent = dirname31(parent)) {
|
|
49940
50120
|
const stat2 = lstatSync29(parent);
|
|
49941
50121
|
need11(stat2.isDirectory() && [0, process.getuid?.()].includes(stat2.uid) && !(stat2.mode & 18), "native_unsafe_executable");
|
|
49942
|
-
if (parent ===
|
|
50122
|
+
if (parent === dirname31(parent))
|
|
49943
50123
|
break;
|
|
49944
50124
|
}
|
|
49945
50125
|
const fd = openSync10(path, constants16.O_RDONLY | constants16.O_NOFOLLOW | constants16.O_NONBLOCK);
|
|
49946
50126
|
try {
|
|
49947
50127
|
const stat2 = fstatSync10(fd);
|
|
49948
50128
|
need11(stat2.isFile() && [0, process.getuid?.()].includes(stat2.uid) && !(stat2.mode & 18) && !!(stat2.mode & 64) && stat2.size <= CODEX_EXECUTABLE_MAX_BYTES, "native_unsafe_executable");
|
|
49949
|
-
const bytes =
|
|
50129
|
+
const bytes = readFileSync27(fd);
|
|
49950
50130
|
need11(bytes.length <= CODEX_EXECUTABLE_MAX_BYTES, "native_unavailable");
|
|
49951
50131
|
need11(nativeHeader(bytes), "native_executable_required");
|
|
49952
50132
|
return { path, sha256: digest4(bytes) };
|
|
@@ -50081,9 +50261,9 @@ function supportedDiscoveryWarnings(hooks, warnings) {
|
|
|
50081
50261
|
const sources = new Set(hooks.map((hook) => JSON.stringify([hook?.source, hook?.sourcePath])));
|
|
50082
50262
|
for (const hook of hooks) {
|
|
50083
50263
|
const path = hook?.sourcePath;
|
|
50084
|
-
if (typeof path !== "string" || path.length > 4096 || !isAbsolute17(path) || path !== resolve33(
|
|
50264
|
+
if (typeof path !== "string" || path.length > 4096 || !isAbsolute17(path) || path !== resolve33(dirname31(path), "hooks.json") || !["user", "project"].includes(hook.source))
|
|
50085
50265
|
continue;
|
|
50086
|
-
const toml = resolve33(
|
|
50266
|
+
const toml = resolve33(dirname31(path), "config.toml");
|
|
50087
50267
|
if (sources.has(JSON.stringify([hook.source, toml]))) {
|
|
50088
50268
|
allowed.add(`loading hooks from both ${path} and ${toml}; prefer a single representation for this layer`);
|
|
50089
50269
|
}
|
|
@@ -50199,20 +50379,20 @@ function mergedConfiguration(value) {
|
|
|
50199
50379
|
return canonical9(copy);
|
|
50200
50380
|
}
|
|
50201
50381
|
function safeDirectory2(path) {
|
|
50202
|
-
for (let p = path;; p =
|
|
50382
|
+
for (let p = path;; p = dirname33(p)) {
|
|
50203
50383
|
const s = lstatSync33(p);
|
|
50204
50384
|
need13(s.isDirectory() && [0, process.getuid?.()].includes(s.uid) && !(s.mode & 18), "preimage_unsafe");
|
|
50205
|
-
if (
|
|
50385
|
+
if (dirname33(p) === p)
|
|
50206
50386
|
return;
|
|
50207
50387
|
}
|
|
50208
50388
|
}
|
|
50209
50389
|
function readPrivate(path) {
|
|
50210
|
-
safeDirectory2(
|
|
50390
|
+
safeDirectory2(dirname33(path));
|
|
50211
50391
|
const fd = openSync15(path, constants21.O_RDONLY | constants21.O_NOFOLLOW | constants21.O_NONBLOCK);
|
|
50212
50392
|
try {
|
|
50213
50393
|
const s = fstatSync15(fd);
|
|
50214
50394
|
need13(s.isFile() && s.uid === process.getuid?.() && !(s.mode & 63) && s.size <= 4194304, "preimage_unsafe");
|
|
50215
|
-
const bytes =
|
|
50395
|
+
const bytes = readFileSync29(fd);
|
|
50216
50396
|
need13(bytes.length <= 4194304, "preimage_unsafe");
|
|
50217
50397
|
return bytes;
|
|
50218
50398
|
} finally {
|
|
@@ -50230,12 +50410,12 @@ function syncDirectory(path) {
|
|
|
50230
50410
|
function exclusive(path, bytes) {
|
|
50231
50411
|
const fd = openSync15(path, constants21.O_CREAT | constants21.O_EXCL | constants21.O_WRONLY | constants21.O_NOFOLLOW, 384);
|
|
50232
50412
|
try {
|
|
50233
|
-
|
|
50413
|
+
writeFileSync13(fd, bytes);
|
|
50234
50414
|
fsyncSync5(fd);
|
|
50235
50415
|
} finally {
|
|
50236
50416
|
closeSync15(fd);
|
|
50237
50417
|
}
|
|
50238
|
-
syncDirectory(
|
|
50418
|
+
syncDirectory(dirname33(path));
|
|
50239
50419
|
}
|
|
50240
50420
|
async function inspect(rpc, home, cwd, readiness = false, selected = "trash-guard") {
|
|
50241
50421
|
const observed = await readCodexSafety(rpc, home, cwd, { includeLayers: true, requireReady: false, readiness, guard: selected });
|
|
@@ -50273,7 +50453,7 @@ async function inspect(rpc, home, cwd, readiness = false, selected = "trash-guar
|
|
|
50273
50453
|
}
|
|
50274
50454
|
async function context2(options, dependencies) {
|
|
50275
50455
|
need13(options.readiness ? options.guard === undefined : options.guard === undefined || isNativeSafetyName(options.guard), "input_invalid");
|
|
50276
|
-
const home = realpathSync16(options.home ??
|
|
50456
|
+
const home = realpathSync16(options.home ?? homedir10()), cwd = realpathSync16(options.cwd ?? process.cwd());
|
|
50277
50457
|
need13(isAbsolute29(home) && isAbsolute29(cwd), "input_invalid");
|
|
50278
50458
|
return { home, cwd, rpc: await (dependencies.connect ?? connectCodexSafety)({ ...options, home }) };
|
|
50279
50459
|
}
|
|
@@ -50316,21 +50496,21 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
50316
50496
|
const expectedGuard = expectedDiscovery.data[0].hooks.find((h) => h.key === before.guard.key);
|
|
50317
50497
|
expectedGuard.enabled = true;
|
|
50318
50498
|
expectedGuard.trustStatus = "trusted";
|
|
50319
|
-
operationId =
|
|
50499
|
+
operationId = randomUUID8();
|
|
50320
50500
|
let directory3 = home;
|
|
50321
50501
|
for (const part of [".hasna", "hooks", "native", selected.readiness ? "codex-readiness-trust" : (selected.guard ?? "trash-guard") === "trash-guard" ? "codex-trash-trust" : "codex-" + selected.guard + "-trust", operationId]) {
|
|
50322
|
-
directory3 =
|
|
50502
|
+
directory3 = join42(directory3, part);
|
|
50323
50503
|
try {
|
|
50324
|
-
|
|
50325
|
-
syncDirectory(
|
|
50504
|
+
mkdirSync16(directory3, { mode: 448 });
|
|
50505
|
+
syncDirectory(dirname33(directory3));
|
|
50326
50506
|
} catch (error61) {
|
|
50327
50507
|
if (error61.code !== "EEXIST")
|
|
50328
50508
|
throw error61;
|
|
50329
50509
|
}
|
|
50330
50510
|
safeDirectory2(directory3);
|
|
50331
50511
|
}
|
|
50332
|
-
exclusive(
|
|
50333
|
-
exclusive(
|
|
50512
|
+
exclusive(join42(directory3, "config.before"), before.before);
|
|
50513
|
+
exclusive(join42(directory3, "intent.json"), JSON.stringify({ operationId, plan: before.plan, configSHA256: sha7(before.before) }) + `
|
|
50334
50514
|
`);
|
|
50335
50515
|
journal = directory3;
|
|
50336
50516
|
need13(sha7(readPrivate(before.canonicalPath)) === sha7(before.before));
|
|
@@ -50358,7 +50538,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
50358
50538
|
nativeAdoptionVerified: false,
|
|
50359
50539
|
unrelatedConfigurationPreserved: true
|
|
50360
50540
|
};
|
|
50361
|
-
exclusive(
|
|
50541
|
+
exclusive(join42(directory3, "receipt.json"), JSON.stringify(receipt) + `
|
|
50362
50542
|
`);
|
|
50363
50543
|
return receipt;
|
|
50364
50544
|
} catch (error61) {
|
|
@@ -50371,7 +50551,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
50371
50551
|
if (!journal)
|
|
50372
50552
|
throw new CodexTrustError("trust_refused", undefined, refusal3);
|
|
50373
50553
|
try {
|
|
50374
|
-
exclusive(
|
|
50554
|
+
exclusive(join42(journal, "refused.json"), JSON.stringify({ ok: false, outcome: "refused", operationId, planDigest: selected.expectedPlanDigest, refusal: refusal3 }) + `
|
|
50375
50555
|
`);
|
|
50376
50556
|
} catch {
|
|
50377
50557
|
throw new CodexTrustError("trust_outcome_uncertain", operationId);
|
|
@@ -50384,10 +50564,10 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
50384
50564
|
var planCodexSafetyTrust = (options = {}, dependencies = {}) => planTrust({ ...options, readiness: false }, dependencies);
|
|
50385
50565
|
var applyCodexSafetyTrust = (options, dependencies = {}) => applyTrust({ ...options, readiness: false }, dependencies);
|
|
50386
50566
|
// src/lib/claude-safety-check.ts
|
|
50387
|
-
import { constants as constants23, closeSync as closeSync20, fstatSync as fstatSync20, lstatSync as lstatSync35, openSync as openSync20, readFileSync as
|
|
50567
|
+
import { constants as constants23, closeSync as closeSync20, fstatSync as fstatSync20, lstatSync as lstatSync35, openSync as openSync20, readFileSync as readFileSync30, realpathSync as realpathSync17 } from "fs";
|
|
50388
50568
|
import { createHash as createHash33 } from "crypto";
|
|
50389
|
-
import { dirname as
|
|
50390
|
-
import { homedir as
|
|
50569
|
+
import { dirname as dirname35, isAbsolute as isAbsolute31, join as join43, resolve as resolve35 } from "path";
|
|
50570
|
+
import { homedir as homedir11 } from "os";
|
|
50391
50571
|
class ClaudeSafetyError extends Error {
|
|
50392
50572
|
code;
|
|
50393
50573
|
constructor(code2) {
|
|
@@ -50404,17 +50584,17 @@ var sha9 = (value) => createHash33("sha256").update(value).digest("hex");
|
|
|
50404
50584
|
function read3(path) {
|
|
50405
50585
|
try {
|
|
50406
50586
|
const resolved = realpathSync17(path);
|
|
50407
|
-
for (let parent =
|
|
50587
|
+
for (let parent = dirname35(resolved);; parent = dirname35(parent)) {
|
|
50408
50588
|
const s = lstatSync35(parent);
|
|
50409
50589
|
need14(s.isDirectory() && [0, process.getuid?.()].includes(s.uid) && !(s.mode & 18), "settings_unsafe");
|
|
50410
|
-
if (
|
|
50590
|
+
if (dirname35(parent) === parent)
|
|
50411
50591
|
break;
|
|
50412
50592
|
}
|
|
50413
50593
|
const fd = openSync20(resolved, constants23.O_RDONLY | constants23.O_NOFOLLOW | constants23.O_NONBLOCK);
|
|
50414
50594
|
try {
|
|
50415
50595
|
const s = fstatSync20(fd);
|
|
50416
50596
|
need14(s.isFile() && [0, process.getuid?.()].includes(s.uid) && !(s.mode & 18) && s.size <= 1048576, "settings_unsafe");
|
|
50417
|
-
const raw =
|
|
50597
|
+
const raw = readFileSync30(fd, "utf8");
|
|
50418
50598
|
need14(Buffer.byteLength(raw) <= 1048576, "settings_unsafe");
|
|
50419
50599
|
return { path, resolved, sha256: sha9(raw), raw };
|
|
50420
50600
|
} finally {
|
|
@@ -50429,11 +50609,11 @@ function read3(path) {
|
|
|
50429
50609
|
}
|
|
50430
50610
|
}
|
|
50431
50611
|
async function verifyClaudeSafetyConfiguration(options = {}, dependencies = {}) {
|
|
50432
|
-
const home = realpathSync17(options.home ??
|
|
50612
|
+
const home = realpathSync17(options.home ?? homedir11()), cwd = realpathSync17(options.cwd ?? process.cwd());
|
|
50433
50613
|
const paths = [
|
|
50434
|
-
options.userSettingsPath ??
|
|
50435
|
-
|
|
50436
|
-
options.localSettingsPath ??
|
|
50614
|
+
options.userSettingsPath ?? join43(home, ".claude/settings.json"),
|
|
50615
|
+
join43(cwd, ".claude/settings.json"),
|
|
50616
|
+
options.localSettingsPath ?? join43(cwd, ".claude/settings.local.json")
|
|
50437
50617
|
];
|
|
50438
50618
|
need14(paths.every((path) => isAbsolute31(path) && resolve35(path) === path), "settings_unsafe");
|
|
50439
50619
|
const inspect2 = () => [...new Set(paths)].map(read3);
|
|
@@ -50494,10 +50674,10 @@ async function verifyClaudeSafetyConfiguration(options = {}, dependencies = {})
|
|
|
50494
50674
|
};
|
|
50495
50675
|
}
|
|
50496
50676
|
// src/lib/native-safety-registration.ts
|
|
50497
|
-
import { createHash as
|
|
50498
|
-
import { constants as constants24, closeSync as closeSync24, fstatSync as fstatSync24, fsyncSync as fsyncSync8, lstatSync as lstatSync36, mkdirSync as
|
|
50499
|
-
import { basename as
|
|
50500
|
-
import { homedir as
|
|
50677
|
+
import { createHash as createHash34, randomUUID as randomUUID9 } from "crypto";
|
|
50678
|
+
import { constants as constants24, closeSync as closeSync24, fstatSync as fstatSync24, fsyncSync as fsyncSync8, lstatSync as lstatSync36, mkdirSync as mkdirSync17, openSync as openSync24, readFileSync as readFileSync31, realpathSync as realpathSync18, writeFileSync as writeFileSync14 } from "fs";
|
|
50679
|
+
import { basename as basename18, dirname as dirname36, isAbsolute as isAbsolute33, join as join44, relative as relative7, resolve as resolve36 } from "path";
|
|
50680
|
+
import { homedir as homedir12 } from "os";
|
|
50501
50681
|
class NativeRegistrationError extends Error {
|
|
50502
50682
|
code;
|
|
50503
50683
|
operationId;
|
|
@@ -50514,7 +50694,7 @@ var need15 = (value, code2) => {
|
|
|
50514
50694
|
if (!value)
|
|
50515
50695
|
throw new NativeRegistrationError(code2);
|
|
50516
50696
|
};
|
|
50517
|
-
var sha10 = (value) =>
|
|
50697
|
+
var sha10 = (value) => createHash34("sha256").update(value).digest("hex");
|
|
50518
50698
|
function canonical11(value) {
|
|
50519
50699
|
if (Array.isArray(value))
|
|
50520
50700
|
return "[" + value.map(canonical11).join(",") + "]";
|
|
@@ -50523,10 +50703,10 @@ function canonical11(value) {
|
|
|
50523
50703
|
return JSON.stringify(value);
|
|
50524
50704
|
}
|
|
50525
50705
|
function safeDirectory3(path) {
|
|
50526
|
-
for (let p = path;; p =
|
|
50706
|
+
for (let p = path;; p = dirname36(p)) {
|
|
50527
50707
|
const s = lstatSync36(p);
|
|
50528
50708
|
need15(s.isDirectory() && [0, process.getuid?.()].includes(s.uid) && !(s.mode & 18), "settings_unsafe");
|
|
50529
|
-
if (
|
|
50709
|
+
if (dirname36(p) === p)
|
|
50530
50710
|
return;
|
|
50531
50711
|
}
|
|
50532
50712
|
}
|
|
@@ -50544,14 +50724,14 @@ function read5(path) {
|
|
|
50544
50724
|
if (missing2.code !== "ENOENT")
|
|
50545
50725
|
throw missing2;
|
|
50546
50726
|
}
|
|
50547
|
-
let ancestor =
|
|
50548
|
-
const suffix = [
|
|
50727
|
+
let ancestor = dirname36(path);
|
|
50728
|
+
const suffix = [basename18(path)];
|
|
50549
50729
|
for (;; ) {
|
|
50550
50730
|
try {
|
|
50551
|
-
resolved =
|
|
50731
|
+
resolved = join44(realpathSync18(ancestor), ...suffix);
|
|
50552
50732
|
break;
|
|
50553
50733
|
} catch (missing2) {
|
|
50554
|
-
if (missing2.code !== "ENOENT" ||
|
|
50734
|
+
if (missing2.code !== "ENOENT" || dirname36(ancestor) === ancestor || suffix.length >= 64)
|
|
50555
50735
|
throw new NativeRegistrationError("settings_unsafe");
|
|
50556
50736
|
try {
|
|
50557
50737
|
lstatSync36(ancestor);
|
|
@@ -50560,14 +50740,14 @@ function read5(path) {
|
|
|
50560
50740
|
if (absent.code !== "ENOENT")
|
|
50561
50741
|
throw absent;
|
|
50562
50742
|
}
|
|
50563
|
-
suffix.unshift(
|
|
50564
|
-
ancestor =
|
|
50743
|
+
suffix.unshift(basename18(ancestor));
|
|
50744
|
+
ancestor = dirname36(ancestor);
|
|
50565
50745
|
}
|
|
50566
50746
|
}
|
|
50567
50747
|
safeDirectory3(realpathSync18(ancestor));
|
|
50568
50748
|
return { resolved, raw: null, sha256: "absent" };
|
|
50569
50749
|
}
|
|
50570
|
-
safeDirectory3(
|
|
50750
|
+
safeDirectory3(dirname36(resolved));
|
|
50571
50751
|
let fd;
|
|
50572
50752
|
try {
|
|
50573
50753
|
fd = openSync24(resolved, constants24.O_RDONLY | constants24.O_NOFOLLOW | constants24.O_NONBLOCK);
|
|
@@ -50579,7 +50759,7 @@ function read5(path) {
|
|
|
50579
50759
|
try {
|
|
50580
50760
|
const s = fstatSync24(fd);
|
|
50581
50761
|
need15(s.isFile() && s.uid === process.getuid?.() && !(s.mode & 18) && s.nlink === 1 && s.size <= 1048576, "settings_unsafe");
|
|
50582
|
-
const bytes =
|
|
50762
|
+
const bytes = readFileSync31(fd);
|
|
50583
50763
|
need15(bytes.length <= 1048576, "settings_unsafe");
|
|
50584
50764
|
const raw = bytes.toString("utf8");
|
|
50585
50765
|
need15(Buffer.from(raw).equals(bytes), "settings_invalid");
|
|
@@ -50591,8 +50771,8 @@ function read5(path) {
|
|
|
50591
50771
|
function assertLosslessJson(raw) {
|
|
50592
50772
|
const tokens = /"(?:\\[\s\S]|[^"\\])*"|-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?|true|false|null|[{}\[\],:]/g;
|
|
50593
50773
|
const stack = [];
|
|
50594
|
-
function decimal(
|
|
50595
|
-
const match = /^(-?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/.exec(
|
|
50774
|
+
function decimal(text2) {
|
|
50775
|
+
const match = /^(-?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/.exec(text2);
|
|
50596
50776
|
need15((match[4]?.replace(/^[+-]/, "").length ?? 0) <= 6, "settings_invalid");
|
|
50597
50777
|
let digits = (match[2] + (match[3] ?? "")).replace(/^0+/, "");
|
|
50598
50778
|
if (!digits)
|
|
@@ -50655,7 +50835,7 @@ function validateSettings(raw) {
|
|
|
50655
50835
|
function inspect2(options) {
|
|
50656
50836
|
need15(options?.target === "codex" || options?.target === "claude", "input_invalid");
|
|
50657
50837
|
need15(options.readiness ? options.guard === "trash-guard" : isNativeSafetyName(options.guard), "input_invalid");
|
|
50658
|
-
const home = realpathSync18(
|
|
50838
|
+
const home = realpathSync18(homedir12()), path = getSettingsPath("global", options.target);
|
|
50659
50839
|
need15(isAbsolute33(path) && resolve36(path) === path, "input_invalid");
|
|
50660
50840
|
const nativeHome = options.target === "codex" ? process.env.CODEX_HOME : process.env.CLAUDE_CONFIG_DIR;
|
|
50661
50841
|
if (nativeHome !== undefined) {
|
|
@@ -50704,12 +50884,12 @@ function syncDirectory2(path) {
|
|
|
50704
50884
|
function exclusive2(path, bytes) {
|
|
50705
50885
|
const fd = openSync24(path, constants24.O_CREAT | constants24.O_EXCL | constants24.O_WRONLY | constants24.O_NOFOLLOW, 384);
|
|
50706
50886
|
try {
|
|
50707
|
-
|
|
50887
|
+
writeFileSync14(fd, bytes);
|
|
50708
50888
|
fsyncSync8(fd);
|
|
50709
50889
|
} finally {
|
|
50710
50890
|
closeSync24(fd);
|
|
50711
50891
|
}
|
|
50712
|
-
syncDirectory2(
|
|
50892
|
+
syncDirectory2(dirname36(path));
|
|
50713
50893
|
}
|
|
50714
50894
|
function refusalOf(error61) {
|
|
50715
50895
|
const code2 = error61?.code;
|
|
@@ -50717,7 +50897,7 @@ function refusalOf(error61) {
|
|
|
50717
50897
|
}
|
|
50718
50898
|
function refuseApply(directory3, operationId, planDigest, refusal3) {
|
|
50719
50899
|
try {
|
|
50720
|
-
exclusive2(
|
|
50900
|
+
exclusive2(join44(directory3, "refused.json"), JSON.stringify({ ok: false, outcome: "refused", operationId, planDigest, refusal: refusal3 }) + `
|
|
50721
50901
|
`);
|
|
50722
50902
|
} catch {
|
|
50723
50903
|
throw new NativeRegistrationError("apply_outcome_uncertain", operationId);
|
|
@@ -50758,13 +50938,13 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
50758
50938
|
need15(before.plan.planDigest === plan.planDigest, "settings_changed");
|
|
50759
50939
|
if (plan.action === "unchanged")
|
|
50760
50940
|
return { ok: true, changed: false, ...plan };
|
|
50761
|
-
const operationId =
|
|
50941
|
+
const operationId = randomUUID9();
|
|
50762
50942
|
let directory3 = before.home;
|
|
50763
50943
|
for (const part of [".hasna", "hooks", "native", selected.readiness ? "trash-readiness-registration" : selected.guard === "trash-guard" ? "trash-registration" : selected.guard + "-registration", operationId]) {
|
|
50764
|
-
directory3 =
|
|
50944
|
+
directory3 = join44(directory3, part);
|
|
50765
50945
|
try {
|
|
50766
|
-
|
|
50767
|
-
syncDirectory2(
|
|
50946
|
+
mkdirSync17(directory3, { mode: 448 });
|
|
50947
|
+
syncDirectory2(dirname36(directory3));
|
|
50768
50948
|
} catch (error61) {
|
|
50769
50949
|
if (error61.code !== "EEXIST")
|
|
50770
50950
|
throw new NativeRegistrationError("settings_unsafe");
|
|
@@ -50772,8 +50952,8 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
50772
50952
|
safeDirectory3(directory3);
|
|
50773
50953
|
}
|
|
50774
50954
|
if (before.before.raw !== null)
|
|
50775
|
-
exclusive2(
|
|
50776
|
-
exclusive2(
|
|
50955
|
+
exclusive2(join44(directory3, "settings.before"), before.before.raw);
|
|
50956
|
+
exclusive2(join44(directory3, "intent.json"), JSON.stringify({ operationId, plan }) + `
|
|
50777
50957
|
`);
|
|
50778
50958
|
let writeMayHaveStarted = false;
|
|
50779
50959
|
const beforeWrite = () => {
|
|
@@ -50802,7 +50982,7 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
50802
50982
|
...selected.readiness ? { readinessRunnerVerified: true } : {},
|
|
50803
50983
|
nativeAdoptionVerified: false
|
|
50804
50984
|
};
|
|
50805
|
-
exclusive2(
|
|
50985
|
+
exclusive2(join44(directory3, "receipt.json"), JSON.stringify(receipt) + `
|
|
50806
50986
|
`);
|
|
50807
50987
|
return receipt;
|
|
50808
50988
|
} catch (error61) {
|
|
@@ -50838,7 +51018,7 @@ async function runHook(name, input2, options = {}) {
|
|
|
50838
51018
|
if (!script)
|
|
50839
51019
|
throw new Error(`Hook script not found: ${name}`);
|
|
50840
51020
|
const { sha256Of: sha256Of2, checkScriptHash: checkScriptHash2 } = await Promise.resolve().then(() => (init_store(), exports_store));
|
|
50841
|
-
const content =
|
|
51021
|
+
const content = readFileSync32(script);
|
|
50842
51022
|
const check2 = checkScriptHash2(name, sha256Of2(content));
|
|
50843
51023
|
if (!check2.ok) {
|
|
50844
51024
|
throw new Error(`Hook '${name}' script changed since it was trusted (sha256 ${check2.expected} != ${check2.actual}). Run 'hooks trust ${name}' to trust the new content.`);
|
|
@@ -50927,122 +51107,122 @@ async function runHook(name, input2, options = {}) {
|
|
|
50927
51107
|
return { output: output2, stderr: stderrText, exitCode };
|
|
50928
51108
|
}
|
|
50929
51109
|
export {
|
|
50930
|
-
|
|
50931
|
-
writeCustomHook,
|
|
50932
|
-
verifyScriptHash,
|
|
50933
|
-
verifyClaudeSafetyConfiguration,
|
|
50934
|
-
upsertHookRecord,
|
|
50935
|
-
updateProfile,
|
|
50936
|
-
uninstallHook,
|
|
50937
|
-
touchProfile,
|
|
50938
|
-
syncHooks,
|
|
50939
|
-
storageSync,
|
|
50940
|
-
storagePush,
|
|
50941
|
-
storagePull,
|
|
50942
|
-
startServeServer,
|
|
50943
|
-
sha256Of,
|
|
50944
|
-
sha256File,
|
|
50945
|
-
setPinnedHook,
|
|
50946
|
-
selectsHooksLocalStore,
|
|
50947
|
-
searchHooks,
|
|
50948
|
-
runStorageMigrations,
|
|
50949
|
-
runHook,
|
|
50950
|
-
retrustHook,
|
|
50951
|
-
resolveTables,
|
|
50952
|
-
resolveScriptPath,
|
|
50953
|
-
resolveScript,
|
|
50954
|
-
resolveHooksTransport,
|
|
50955
|
-
resolveHooksServePublishKeyAsync,
|
|
50956
|
-
resolveHooksServePublishKey,
|
|
50957
|
-
resolveHooksRequestAuthority,
|
|
50958
|
-
resolveHookMeta,
|
|
50959
|
-
resolveHookEventSink,
|
|
50960
|
-
resolveHookDir,
|
|
50961
|
-
resolveHook,
|
|
50962
|
-
removeProjectHook,
|
|
50963
|
-
removePinnedHook,
|
|
50964
|
-
removeHookRecord,
|
|
50965
|
-
removeHookFromStore,
|
|
50966
|
-
removeHook,
|
|
50967
|
-
refuseLocalStore,
|
|
50968
|
-
readLock,
|
|
50969
|
-
readCustomManifest,
|
|
50970
|
-
provisionCloudflareResources,
|
|
50971
|
-
planSync,
|
|
50972
|
-
planNativeSafetyRegistration,
|
|
50973
|
-
planCodexSafetyTrust,
|
|
50974
|
-
pinInstalledHook,
|
|
50975
|
-
parseStorageTables,
|
|
50976
|
-
parseManifest,
|
|
50977
|
-
listProjectHooks,
|
|
50978
|
-
listProfiles,
|
|
50979
|
-
listHookRecords,
|
|
50980
|
-
listCustomHooks,
|
|
50981
|
-
isLocalStoreRefused,
|
|
50982
|
-
isHooksLocalOptIn,
|
|
50983
|
-
isEventSupported,
|
|
50984
|
-
isCustomSource,
|
|
50985
|
-
installPinnedFromBundled,
|
|
50986
|
-
installHooksForProject,
|
|
50987
|
-
installHooks,
|
|
50988
|
-
installHookForProject,
|
|
50989
|
-
installHook,
|
|
50990
|
-
installCustomSource,
|
|
50991
|
-
importProfiles,
|
|
50992
|
-
hooksRegistryOrigin,
|
|
50993
|
-
hooksHostedRouteLocalStoreRefusal,
|
|
50994
|
-
hooksFailClosedLine,
|
|
50995
|
-
hooksEventSinkRefusal,
|
|
50996
|
-
hookExists,
|
|
50997
|
-
hasHooksEnvAuthorityIntent,
|
|
50998
|
-
handleServeRequest,
|
|
50999
|
-
getSyncMetaAll,
|
|
51000
|
-
getStorageStatus,
|
|
51001
|
-
getStoragePg,
|
|
51002
|
-
getStorageDatabaseUrl,
|
|
51003
|
-
getStorageDatabaseEnvName,
|
|
51004
|
-
getStorageDatabaseEnv,
|
|
51005
|
-
getStorageBackend,
|
|
51006
|
-
getSettingsPath,
|
|
51007
|
-
getRegisteredHooksForTarget,
|
|
51008
|
-
getRegisteredHooks,
|
|
51009
|
-
getProfilesDir,
|
|
51010
|
-
getProfile,
|
|
51011
|
-
getPinnedHook,
|
|
51012
|
-
getLockPath,
|
|
51013
|
-
getInstalledHooks,
|
|
51014
|
-
getHooksDataDir,
|
|
51015
|
-
getHooksByCategory,
|
|
51016
|
-
getHookRecord,
|
|
51017
|
-
getHookPath,
|
|
51018
|
-
getHookEvents,
|
|
51019
|
-
getHook,
|
|
51020
|
-
getCustomHooksDir,
|
|
51021
|
-
fetchPinnedHook,
|
|
51022
|
-
exportProfiles,
|
|
51023
|
-
deleteProfile,
|
|
51024
|
-
createProfile,
|
|
51025
|
-
checkScriptHash,
|
|
51026
|
-
buildCodewithTomlFragment,
|
|
51027
|
-
applyNativeSafetyRegistration,
|
|
51028
|
-
applyCodexSafetyTrust,
|
|
51029
|
-
allowLocalStore,
|
|
51030
|
-
STORAGE_TABLES,
|
|
51031
|
-
STORAGE_DATABASE_ENV,
|
|
51032
|
-
STORAGE_BACKEND_ENV,
|
|
51033
|
-
STORAGE_BACKENDS,
|
|
51034
|
-
RETIRED_STORAGE_MODE_ENV,
|
|
51035
|
-
NativeRegistrationError,
|
|
51036
|
-
HOOK_EVENTS,
|
|
51037
|
-
HOOKS_STORAGE_TABLES,
|
|
51038
|
-
HOOKS_STORAGE_FALLBACK_ENV,
|
|
51039
|
-
HOOKS_STORAGE_ENV,
|
|
51040
|
-
HOOKS_STORAGE_BACKEND_FALLBACK_ENV,
|
|
51041
|
-
HOOKS_STORAGE_BACKEND_ENV,
|
|
51042
|
-
HOOKS_LOCAL_OPT_IN_ENV_KEYS,
|
|
51043
|
-
HOOKS,
|
|
51044
|
-
DEFAULT_SERVE_PORT,
|
|
51045
|
-
CodexTrustError,
|
|
51110
|
+
CATEGORIES,
|
|
51046
51111
|
ClaudeSafetyError,
|
|
51047
|
-
|
|
51112
|
+
CodexTrustError,
|
|
51113
|
+
DEFAULT_SERVE_PORT,
|
|
51114
|
+
HOOKS,
|
|
51115
|
+
HOOKS_LOCAL_OPT_IN_ENV_KEYS,
|
|
51116
|
+
HOOKS_STORAGE_BACKEND_ENV,
|
|
51117
|
+
HOOKS_STORAGE_BACKEND_FALLBACK_ENV,
|
|
51118
|
+
HOOKS_STORAGE_ENV,
|
|
51119
|
+
HOOKS_STORAGE_FALLBACK_ENV,
|
|
51120
|
+
HOOKS_STORAGE_TABLES,
|
|
51121
|
+
HOOK_EVENTS,
|
|
51122
|
+
NativeRegistrationError,
|
|
51123
|
+
RETIRED_STORAGE_MODE_ENV,
|
|
51124
|
+
STORAGE_BACKENDS,
|
|
51125
|
+
STORAGE_BACKEND_ENV,
|
|
51126
|
+
STORAGE_DATABASE_ENV,
|
|
51127
|
+
STORAGE_TABLES,
|
|
51128
|
+
allowLocalStore,
|
|
51129
|
+
applyCodexSafetyTrust,
|
|
51130
|
+
applyNativeSafetyRegistration,
|
|
51131
|
+
buildCodewithTomlFragment,
|
|
51132
|
+
checkScriptHash,
|
|
51133
|
+
createProfile,
|
|
51134
|
+
deleteProfile,
|
|
51135
|
+
exportProfiles,
|
|
51136
|
+
fetchPinnedHook,
|
|
51137
|
+
getCustomHooksDir,
|
|
51138
|
+
getHook,
|
|
51139
|
+
getHookEvents,
|
|
51140
|
+
getHookPath,
|
|
51141
|
+
getHookRecord,
|
|
51142
|
+
getHooksByCategory,
|
|
51143
|
+
getHooksDataDir,
|
|
51144
|
+
getInstalledHooks,
|
|
51145
|
+
getLockPath,
|
|
51146
|
+
getPinnedHook,
|
|
51147
|
+
getProfile,
|
|
51148
|
+
getProfilesDir,
|
|
51149
|
+
getRegisteredHooks,
|
|
51150
|
+
getRegisteredHooksForTarget,
|
|
51151
|
+
getSettingsPath,
|
|
51152
|
+
getStorageBackend,
|
|
51153
|
+
getStorageDatabaseEnv,
|
|
51154
|
+
getStorageDatabaseEnvName,
|
|
51155
|
+
getStorageDatabaseUrl,
|
|
51156
|
+
getStoragePg,
|
|
51157
|
+
getStorageStatus,
|
|
51158
|
+
getSyncMetaAll,
|
|
51159
|
+
handleServeRequest,
|
|
51160
|
+
hasHooksEnvAuthorityIntent,
|
|
51161
|
+
hookExists,
|
|
51162
|
+
hooksEventSinkRefusal,
|
|
51163
|
+
hooksFailClosedLine,
|
|
51164
|
+
hooksHostedRouteLocalStoreRefusal,
|
|
51165
|
+
hooksRegistryOrigin,
|
|
51166
|
+
importProfiles,
|
|
51167
|
+
installCustomSource,
|
|
51168
|
+
installHook,
|
|
51169
|
+
installHookForProject,
|
|
51170
|
+
installHooks,
|
|
51171
|
+
installHooksForProject,
|
|
51172
|
+
installPinnedFromBundled,
|
|
51173
|
+
isCustomSource,
|
|
51174
|
+
isEventSupported,
|
|
51175
|
+
isHooksLocalOptIn,
|
|
51176
|
+
isLocalStoreRefused,
|
|
51177
|
+
listCustomHooks,
|
|
51178
|
+
listHookRecords,
|
|
51179
|
+
listProfiles,
|
|
51180
|
+
listProjectHooks,
|
|
51181
|
+
parseManifest,
|
|
51182
|
+
parseStorageTables,
|
|
51183
|
+
pinInstalledHook,
|
|
51184
|
+
planCodexSafetyTrust,
|
|
51185
|
+
planNativeSafetyRegistration,
|
|
51186
|
+
planSync,
|
|
51187
|
+
provisionCloudflareResources,
|
|
51188
|
+
readCustomManifest,
|
|
51189
|
+
readLock,
|
|
51190
|
+
refuseLocalStore,
|
|
51191
|
+
removeHook,
|
|
51192
|
+
removeHookFromStore,
|
|
51193
|
+
removeHookRecord,
|
|
51194
|
+
removePinnedHook,
|
|
51195
|
+
removeProjectHook,
|
|
51196
|
+
resolveHook,
|
|
51197
|
+
resolveHookDir,
|
|
51198
|
+
resolveHookEventSink,
|
|
51199
|
+
resolveHookMeta,
|
|
51200
|
+
resolveHooksRequestAuthority,
|
|
51201
|
+
resolveHooksServePublishKey,
|
|
51202
|
+
resolveHooksServePublishKeyAsync,
|
|
51203
|
+
resolveHooksTransport,
|
|
51204
|
+
resolveScript,
|
|
51205
|
+
resolveScriptPath,
|
|
51206
|
+
resolveTables,
|
|
51207
|
+
retrustHook,
|
|
51208
|
+
runHook,
|
|
51209
|
+
runStorageMigrations,
|
|
51210
|
+
searchHooks,
|
|
51211
|
+
selectsHooksLocalStore,
|
|
51212
|
+
setPinnedHook,
|
|
51213
|
+
sha256File,
|
|
51214
|
+
sha256Of,
|
|
51215
|
+
startServeServer,
|
|
51216
|
+
storagePull,
|
|
51217
|
+
storagePush,
|
|
51218
|
+
storageSync,
|
|
51219
|
+
syncHooks,
|
|
51220
|
+
touchProfile,
|
|
51221
|
+
uninstallHook,
|
|
51222
|
+
updateProfile,
|
|
51223
|
+
upsertHookRecord,
|
|
51224
|
+
verifyClaudeSafetyConfiguration,
|
|
51225
|
+
verifyScriptHash,
|
|
51226
|
+
writeCustomHook,
|
|
51227
|
+
writeLock
|
|
51048
51228
|
};
|