@joshuafolkken/kit 1.872.0 → 1.879.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/.github/workflows/publish.yml +39 -2
- package/README.md +3 -3
- package/package.json +6 -2
- package/scripts/init/distributed-paths.ts +14 -11
- package/scripts/init/hook-command-bootstrap.ts +51 -0
- package/scripts/init/hook-command-rewrite.ts +9 -1
- package/scripts/init/init-logic.ts +2 -8
- package/templates/workflows/ci.yml +6 -2
- package/dist/hooks/chunk-25JL6FMS.js +0 -4970
- package/dist/hooks/chunk-2ANGT3XM.js +0 -375
- package/dist/hooks/chunk-2EI5GBSW.js +0 -42
- package/dist/hooks/chunk-2OT5XE2N.js +0 -5014
- package/dist/hooks/chunk-33ELOKEV.js +0 -910
- package/dist/hooks/chunk-33YRTKM7.js +0 -230
- package/dist/hooks/chunk-36JQU5NN.js +0 -77
- package/dist/hooks/chunk-3EJBTWVS.js +0 -1769
- package/dist/hooks/chunk-3FK5SFAC.js +0 -432
- package/dist/hooks/chunk-3PWPYDD2.js +0 -240
- package/dist/hooks/chunk-3TQU7TDH.js +0 -375
- package/dist/hooks/chunk-3TVLSFZ6.js +0 -432
- package/dist/hooks/chunk-3VXYCB4E.js +0 -77
- package/dist/hooks/chunk-44M6JXGV.js +0 -3398
- package/dist/hooks/chunk-46EEEHC3.js +0 -240
- package/dist/hooks/chunk-4A7UVP2P.js +0 -364
- package/dist/hooks/chunk-4LFQEZS4.js +0 -137
- package/dist/hooks/chunk-4OCX3V2T.js +0 -469
- package/dist/hooks/chunk-4OHA5DE7.js +0 -49
- package/dist/hooks/chunk-4PMDW3YD.js +0 -68
- package/dist/hooks/chunk-4QHBNAI4.js +0 -68
- package/dist/hooks/chunk-4SSB3FEE.js +0 -3273
- package/dist/hooks/chunk-5A2WQ2CQ.js +0 -5390
- package/dist/hooks/chunk-5EVA2JQB.js +0 -5390
- package/dist/hooks/chunk-5P7VF5VE.js +0 -3230
- package/dist/hooks/chunk-5QWJGGZP.js +0 -49
- package/dist/hooks/chunk-5U5EZYG6.js +0 -77
- package/dist/hooks/chunk-5VUUF3ZV.js +0 -240
- package/dist/hooks/chunk-5WA7UBT3.js +0 -374
- package/dist/hooks/chunk-6EBGRQ3Q.js +0 -301
- package/dist/hooks/chunk-6TVHWMD3.js +0 -432
- package/dist/hooks/chunk-6VAGLEMB.js +0 -68
- package/dist/hooks/chunk-75BTXKFJ.js +0 -3424
- package/dist/hooks/chunk-75RHN67S.js +0 -137
- package/dist/hooks/chunk-76KC3BDD.js +0 -3414
- package/dist/hooks/chunk-76SLS7CZ.js +0 -898
- package/dist/hooks/chunk-7DHZ4DWT.js +0 -5015
- package/dist/hooks/chunk-7INSJDGE.js +0 -458
- package/dist/hooks/chunk-7VJ4FTDX.js +0 -268
- package/dist/hooks/chunk-7XCYNHQK.js +0 -77
- package/dist/hooks/chunk-A5YJ3H7E.js +0 -375
- package/dist/hooks/chunk-AAEXXUUL.js +0 -268
- package/dist/hooks/chunk-ABVEVV2M.js +0 -432
- package/dist/hooks/chunk-ACN3YXFL.js +0 -68
- package/dist/hooks/chunk-AD3XE3QZ.js +0 -397
- package/dist/hooks/chunk-AENFZPZH.js +0 -230
- package/dist/hooks/chunk-AFKRFQ6W.js +0 -68
- package/dist/hooks/chunk-AHD5IPWI.js +0 -375
- package/dist/hooks/chunk-AMK5JGV7.js +0 -77
- package/dist/hooks/chunk-ARN7NCQI.js +0 -425
- package/dist/hooks/chunk-AUFY653N.js +0 -3425
- package/dist/hooks/chunk-AXQBNFEF.js +0 -375
- package/dist/hooks/chunk-AYC7R6U4.js +0 -3316
- package/dist/hooks/chunk-AYEA2FJ7.js +0 -5015
- package/dist/hooks/chunk-B4HPNY2I.js +0 -375
- package/dist/hooks/chunk-B57S3VWT.js +0 -922
- package/dist/hooks/chunk-BINZ3PLI.js +0 -364
- package/dist/hooks/chunk-BODUSXKK.js +0 -410
- package/dist/hooks/chunk-BQBAT2YK.js +0 -375
- package/dist/hooks/chunk-BUJEBW75.js +0 -391
- package/dist/hooks/chunk-BVNWORKA.js +0 -72
- package/dist/hooks/chunk-BWI47LQS.js +0 -5205
- package/dist/hooks/chunk-C25HRMJX.js +0 -137
- package/dist/hooks/chunk-CBFZNC74.js +0 -375
- package/dist/hooks/chunk-CECYXS4Y.js +0 -3424
- package/dist/hooks/chunk-CELGUP5F.js +0 -49
- package/dist/hooks/chunk-CMHANU3F.js +0 -3442
- package/dist/hooks/chunk-CMN372LI.js +0 -68
- package/dist/hooks/chunk-CPGZLMMK.js +0 -3299
- package/dist/hooks/chunk-CTQKXDC7.js +0 -268
- package/dist/hooks/chunk-CYAT4RIT.js +0 -68
- package/dist/hooks/chunk-CYTWYCH2.js +0 -5014
- package/dist/hooks/chunk-CZSOLRBA.js +0 -77
- package/dist/hooks/chunk-D2PIDYJR.js +0 -3438
- package/dist/hooks/chunk-DE57HI6T.js +0 -137
- package/dist/hooks/chunk-DGXDGAPG.js +0 -5306
- package/dist/hooks/chunk-DNYRSYQG.js +0 -5014
- package/dist/hooks/chunk-DTAXH2A2.js +0 -240
- package/dist/hooks/chunk-E2IZUWI5.js +0 -375
- package/dist/hooks/chunk-E4L2K2BL.js +0 -397
- package/dist/hooks/chunk-ECXVCCVD.js +0 -3079
- package/dist/hooks/chunk-EPHO443D.js +0 -68
- package/dist/hooks/chunk-EUFK2BI2.js +0 -375
- package/dist/hooks/chunk-EYCD5ZAV.js +0 -137
- package/dist/hooks/chunk-F2SDYJU4.js +0 -240
- package/dist/hooks/chunk-F4B5D5TF.js +0 -68
- package/dist/hooks/chunk-FGEO3NDX.js +0 -432
- package/dist/hooks/chunk-FJYI52RE.js +0 -137
- package/dist/hooks/chunk-FYTZHIY4.js +0 -3085
- package/dist/hooks/chunk-G7JL2A5K.js +0 -375
- package/dist/hooks/chunk-GA3ITDBW.js +0 -42
- package/dist/hooks/chunk-GDR4H4SV.js +0 -469
- package/dist/hooks/chunk-GFKDXPSM.js +0 -2855
- package/dist/hooks/chunk-GIMRTKFU.js +0 -566
- package/dist/hooks/chunk-GOPHRLGO.js +0 -240
- package/dist/hooks/chunk-GX4HO7SJ.js +0 -230
- package/dist/hooks/chunk-GZ6FUVIK.js +0 -566
- package/dist/hooks/chunk-H5HPY5M5.js +0 -2869
- package/dist/hooks/chunk-HCF3OGEE.js +0 -1829
- package/dist/hooks/chunk-HDEXAOUM.js +0 -469
- package/dist/hooks/chunk-HM2TY3TN.js +0 -469
- package/dist/hooks/chunk-HOA7NXA2.js +0 -55
- package/dist/hooks/chunk-HOFEWH6H.js +0 -240
- package/dist/hooks/chunk-HUUI6S5J.js +0 -2669
- package/dist/hooks/chunk-I4D3NVUD.js +0 -469
- package/dist/hooks/chunk-I4Q6WAJE.js +0 -68
- package/dist/hooks/chunk-IB6N4CR2.js +0 -432
- package/dist/hooks/chunk-IFLDYJMD.js +0 -469
- package/dist/hooks/chunk-IGU466YD.js +0 -77
- package/dist/hooks/chunk-IJCQUHKY.js +0 -375
- package/dist/hooks/chunk-IKUMBDJB.js +0 -230
- package/dist/hooks/chunk-IM3BDIBJ.js +0 -5005
- package/dist/hooks/chunk-IMYMAODK.js +0 -3431
- package/dist/hooks/chunk-IN2ZVGXA.js +0 -5005
- package/dist/hooks/chunk-ITVJ2MKQ.js +0 -18
- package/dist/hooks/chunk-J5RIJYTM.js +0 -2669
- package/dist/hooks/chunk-JFLMH4K5.js +0 -3460
- package/dist/hooks/chunk-JR25IFML.js +0 -77
- package/dist/hooks/chunk-JT5AUXFI.js +0 -432
- package/dist/hooks/chunk-JY5YVN6N.js +0 -3234
- package/dist/hooks/chunk-K5Q4ETVI.js +0 -391
- package/dist/hooks/chunk-K67V2F24.js +0 -137
- package/dist/hooks/chunk-KATZESEC.js +0 -3273
- package/dist/hooks/chunk-KFH4H7W7.js +0 -469
- package/dist/hooks/chunk-KMUEI6RX.js +0 -910
- package/dist/hooks/chunk-KMV4OY77.js +0 -3438
- package/dist/hooks/chunk-KQAZNWEY.js +0 -137
- package/dist/hooks/chunk-KZZR6JER.js +0 -5015
- package/dist/hooks/chunk-LAR6DREP.js +0 -77
- package/dist/hooks/chunk-LNCJWEZD.js +0 -5015
- package/dist/hooks/chunk-LRYD2GLM.js +0 -6
- package/dist/hooks/chunk-LXBKYHDV.js +0 -77
- package/dist/hooks/chunk-LYLKIUNE.js +0 -5024
- package/dist/hooks/chunk-LZKCFOVC.js +0 -432
- package/dist/hooks/chunk-M4FCIYRI.js +0 -77
- package/dist/hooks/chunk-M5M7327Q.js +0 -3425
- package/dist/hooks/chunk-MF72MHSX.js +0 -3455
- package/dist/hooks/chunk-MK56LKDO.js +0 -397
- package/dist/hooks/chunk-N3MJADY7.js +0 -240
- package/dist/hooks/chunk-NFQSUDBN.js +0 -458
- package/dist/hooks/chunk-NHREKY45.js +0 -137
- package/dist/hooks/chunk-NP5TTAAW.js +0 -375
- package/dist/hooks/chunk-NQTLTKTJ.js +0 -2993
- package/dist/hooks/chunk-NVRCZPBZ.js +0 -391
- package/dist/hooks/chunk-O46HMMLJ.js +0 -469
- package/dist/hooks/chunk-OFJGH2L4.js +0 -240
- package/dist/hooks/chunk-OLFMCZH5.js +0 -240
- package/dist/hooks/chunk-OMCZS46I.js +0 -49
- package/dist/hooks/chunk-OQZEZW5G.js +0 -469
- package/dist/hooks/chunk-P2MDAT2Y.js +0 -1897
- package/dist/hooks/chunk-P3M2JJIF.js +0 -68
- package/dist/hooks/chunk-PDVHQITQ.js +0 -3453
- package/dist/hooks/chunk-PNT2AMDH.js +0 -391
- package/dist/hooks/chunk-PR2LVSY6.js +0 -3445
- package/dist/hooks/chunk-PRR5R4JK.js +0 -137
- package/dist/hooks/chunk-PXT44QVN.js +0 -566
- package/dist/hooks/chunk-PZLWJLAP.js +0 -469
- package/dist/hooks/chunk-Q2FEAZJ2.js +0 -77
- package/dist/hooks/chunk-Q32WETDO.js +0 -3265
- package/dist/hooks/chunk-Q45DUBLE.js +0 -3600
- package/dist/hooks/chunk-Q7NZSWQ5.js +0 -240
- package/dist/hooks/chunk-QH2JNAMK.js +0 -3085
- package/dist/hooks/chunk-QPU5H2OS.js +0 -68
- package/dist/hooks/chunk-QRAHZ5TO.js +0 -1829
- package/dist/hooks/chunk-QUZ5HPIE.js +0 -469
- package/dist/hooks/chunk-QVCRG34O.js +0 -2893
- package/dist/hooks/chunk-R3MY4E3S.js +0 -1675
- package/dist/hooks/chunk-R6TXJJXP.js +0 -77
- package/dist/hooks/chunk-REJU6VT7.js +0 -1829
- package/dist/hooks/chunk-REQAQLRC.js +0 -2993
- package/dist/hooks/chunk-RFCXPAHH.js +0 -391
- package/dist/hooks/chunk-RHI6Y22X.js +0 -137
- package/dist/hooks/chunk-RKZVOBBS.js +0 -469
- package/dist/hooks/chunk-RL57TT2Y.js +0 -566
- package/dist/hooks/chunk-RORDOD4S.js +0 -3321
- package/dist/hooks/chunk-RZKYW5P2.js +0 -77
- package/dist/hooks/chunk-SJPJ6VSI.js +0 -391
- package/dist/hooks/chunk-SKSIJQQQ.js +0 -432
- package/dist/hooks/chunk-SSQDZKXG.js +0 -268
- package/dist/hooks/chunk-SYHFKE4C.js +0 -77
- package/dist/hooks/chunk-TCGNI2ZY.js +0 -42
- package/dist/hooks/chunk-TG3WXJF5.js +0 -137
- package/dist/hooks/chunk-TH7IJAY5.js +0 -77
- package/dist/hooks/chunk-TLZ27PCY.js +0 -240
- package/dist/hooks/chunk-U652FXTN.js +0 -566
- package/dist/hooks/chunk-UEK47YUF.js +0 -268
- package/dist/hooks/chunk-UIO45H3O.js +0 -432
- package/dist/hooks/chunk-UNLZEEVH.js +0 -5005
- package/dist/hooks/chunk-UNRVF3SZ.js +0 -432
- package/dist/hooks/chunk-USLFAFOI.js +0 -3453
- package/dist/hooks/chunk-VAEELMLL.js +0 -442
- package/dist/hooks/chunk-VALSWLDQ.js +0 -3453
- package/dist/hooks/chunk-VC5JEPNY.js +0 -3398
- package/dist/hooks/chunk-VEZVK6C7.js +0 -230
- package/dist/hooks/chunk-VK5JKFAR.js +0 -49
- package/dist/hooks/chunk-VNF2KP7Z.js +0 -469
- package/dist/hooks/chunk-VWWCUMW6.js +0 -2669
- package/dist/hooks/chunk-W4JARUQV.js +0 -137
- package/dist/hooks/chunk-WEOBMNJG.js +0 -2993
- package/dist/hooks/chunk-WKJU3J5Y.js +0 -5390
- package/dist/hooks/chunk-WMN4TSVF.js +0 -3299
- package/dist/hooks/chunk-WNON54PT.js +0 -3469
- package/dist/hooks/chunk-WOVKBPPX.js +0 -137
- package/dist/hooks/chunk-WRVFORYJ.js +0 -432
- package/dist/hooks/chunk-WUBVYGQZ.js +0 -240
- package/dist/hooks/chunk-WWULTUOM.js +0 -68
- package/dist/hooks/chunk-WXHKKB45.js +0 -4962
- package/dist/hooks/chunk-XAI3YTHJ.js +0 -469
- package/dist/hooks/chunk-XFZH6JZJ.js +0 -77
- package/dist/hooks/chunk-XGPWX6IA.js +0 -137
- package/dist/hooks/chunk-XIXXIVGY.js +0 -566
- package/dist/hooks/chunk-XKDOYJGA.js +0 -922
- package/dist/hooks/chunk-YALTVBHM.js +0 -432
- package/dist/hooks/chunk-YEBEPBFK.js +0 -5014
- package/dist/hooks/chunk-YI2BQ3DK.js +0 -3441
- package/dist/hooks/chunk-YVNBCFGG.js +0 -1829
- package/dist/hooks/chunk-YXBN3RGG.js +0 -432
- package/dist/hooks/chunk-Z2OOJSW3.js +0 -3163
- package/dist/hooks/chunk-ZA3HVBOY.js +0 -2644
- package/dist/hooks/chunk-ZKID46U3.js +0 -137
- package/dist/hooks/chunk-ZPMU2JV6.js +0 -49
- package/dist/hooks/chunk-ZRKY4W7O.js +0 -432
- package/dist/hooks/chunk-ZTMRB7LJ.js +0 -268
- package/dist/hooks/chunk-ZVPPBQ3L.js +0 -3413
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
investigation_reads
|
|
3
|
-
} from "./chunk-3TQU7TDH.js";
|
|
4
|
-
import {
|
|
5
|
-
lane_guard_policy
|
|
6
|
-
} from "./chunk-RKZVOBBS.js";
|
|
7
|
-
import {
|
|
8
|
-
hook_decision
|
|
9
|
-
} from "./chunk-WUBVYGQZ.js";
|
|
10
|
-
import {
|
|
11
|
-
json_value,
|
|
12
|
-
time_spans
|
|
13
|
-
} from "./chunk-CECYXS4Y.js";
|
|
14
|
-
|
|
15
|
-
// scripts/delegation/duplicate-read-guard.ts
|
|
16
|
-
import { statSync } from "node:fs";
|
|
17
|
-
import { text } from "node:stream/consumers";
|
|
18
|
-
import { fileURLToPath } from "node:url";
|
|
19
|
-
var SWITCH_ENV_KEY = "JOSH_DUPLICATE_READ_GUARD";
|
|
20
|
-
var LANE_GUARD_ID = "duplicate-read";
|
|
21
|
-
var STAMP_PREFIX = "josh-duplicate-read-guard-";
|
|
22
|
-
var NOTICE_STAMP_PREFIX = "josh-duplicate-read-notice-";
|
|
23
|
-
var READ_TOOL = "Read";
|
|
24
|
-
var GLOB_CHARACTERS = /[*?]/u;
|
|
25
|
-
var REASON = `\u26D4 duplicate read: this file was already read in this session and has not changed since (its mtime predates that read), so reading it again returns nothing new. Scroll up to the earlier result instead of re-reading it. A read with a new offset/limit, or of a file that has since changed, is allowed; set \`JOSH_DUPLICATE_READ_GUARD=off\` to disable this guard.`;
|
|
26
|
-
var NOTICE = `\u26A0 duplicate read: this file was already read in this session and has not changed since, so re-reading it returns nothing new \u2014 scroll up to the earlier result instead of re-reading it. Set \`JOSH_DUPLICATE_READ_GUARD=off\` to silence this.`;
|
|
27
|
-
function is_paginated(input) {
|
|
28
|
-
return input["offset"] !== void 0 || input["limit"] !== void 0;
|
|
29
|
-
}
|
|
30
|
-
function names_one_file(file_path) {
|
|
31
|
-
return typeof file_path === "string" && file_path !== "" && !GLOB_CHARACTERS.test(file_path);
|
|
32
|
-
}
|
|
33
|
-
function read_target(call) {
|
|
34
|
-
if (call.name !== READ_TOOL || !json_value.is_record(call.input)) return void 0;
|
|
35
|
-
const { input } = call;
|
|
36
|
-
if (is_paginated(input) || !names_one_file(input["file_path"])) return void 0;
|
|
37
|
-
return investigation_reads.resolved(input["file_path"]);
|
|
38
|
-
}
|
|
39
|
-
function is_refusable_call(call) {
|
|
40
|
-
return read_target(call) !== void 0;
|
|
41
|
-
}
|
|
42
|
-
function is_successful_read(span) {
|
|
43
|
-
const is_read = investigation_reads.READ_TOOLS.has(span.label);
|
|
44
|
-
return is_read && span.outcome !== time_spans.FAILED_OUTCOME;
|
|
45
|
-
}
|
|
46
|
-
function reads_target(span, target) {
|
|
47
|
-
return span.targets.some((one) => investigation_reads.resolved(one) === target);
|
|
48
|
-
}
|
|
49
|
-
function last_read_ms(spans, target) {
|
|
50
|
-
const times = spans.filter((span) => is_successful_read(span) && reads_target(span, target)).map((span) => span.ended_ms);
|
|
51
|
-
return times.length === 0 ? hook_decision.NEVER_MS : Math.max(...times);
|
|
52
|
-
}
|
|
53
|
-
function file_mtime_ms(target) {
|
|
54
|
-
try {
|
|
55
|
-
return statSync(target).mtimeMs;
|
|
56
|
-
} catch {
|
|
57
|
-
return void 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function read_window(tail, target) {
|
|
61
|
-
const { spans, started_ms } = time_spans.parse_timeline(tail);
|
|
62
|
-
return { last_ms: last_read_ms(spans, target), window_start_ms: started_ms };
|
|
63
|
-
}
|
|
64
|
-
function is_unchanged_reread(last_ms, mtime) {
|
|
65
|
-
if (mtime === void 0 || last_ms === hook_decision.NEVER_MS) return false;
|
|
66
|
-
return mtime < last_ms;
|
|
67
|
-
}
|
|
68
|
-
function is_rearmed(window, fired_at_ms) {
|
|
69
|
-
if (fired_at_ms === hook_decision.NEVER_MS || fired_at_ms < window.window_start_ms) return true;
|
|
70
|
-
return window.last_ms > fired_at_ms;
|
|
71
|
-
}
|
|
72
|
-
function is_redundant_reread(tail, call, fired_at_ms) {
|
|
73
|
-
const target = read_target(call);
|
|
74
|
-
if (target === void 0) return false;
|
|
75
|
-
const window = read_window(tail, target);
|
|
76
|
-
if (!is_unchanged_reread(window.last_ms, file_mtime_ms(target))) return false;
|
|
77
|
-
return is_rearmed(window, fired_at_ms);
|
|
78
|
-
}
|
|
79
|
-
function duplicate_mode() {
|
|
80
|
-
return lane_guard_policy.mode_here(LANE_GUARD_ID);
|
|
81
|
-
}
|
|
82
|
-
function is_candidate(call) {
|
|
83
|
-
return is_refusable_call(call) && duplicate_mode() !== "off";
|
|
84
|
-
}
|
|
85
|
-
function should_block_here(tail, call, refused_at_ms) {
|
|
86
|
-
if (duplicate_mode() !== "refuse") return false;
|
|
87
|
-
return is_redundant_reread(tail, call, refused_at_ms);
|
|
88
|
-
}
|
|
89
|
-
function should_notify_here(tail, call, notified_at_ms) {
|
|
90
|
-
if (duplicate_mode() !== "notice") return false;
|
|
91
|
-
return is_redundant_reread(tail, call, notified_at_ms);
|
|
92
|
-
}
|
|
93
|
-
var GUARD = hook_decision.create_transcript_guard({
|
|
94
|
-
prefix: STAMP_PREFIX,
|
|
95
|
-
switch_key: SWITCH_ENV_KEY,
|
|
96
|
-
is_candidate,
|
|
97
|
-
should_block: should_block_here,
|
|
98
|
-
reason: REASON,
|
|
99
|
-
notify: {
|
|
100
|
-
prefix: NOTICE_STAMP_PREFIX,
|
|
101
|
-
should_notify: should_notify_here,
|
|
102
|
-
text: () => NOTICE
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
var duplicate_read_refusal = GUARD.refusal;
|
|
106
|
-
var duplicate_read_outcome = GUARD.outcome;
|
|
107
|
-
var { is_enabled, refusal_path } = GUARD;
|
|
108
|
-
var notice_refusal_path = hook_decision.create_refusal_stamp(NOTICE_STAMP_PREFIX).path;
|
|
109
|
-
var { deny_envelope, DISABLED_VALUES } = hook_decision;
|
|
110
|
-
var duplicate_reads = {
|
|
111
|
-
REASON,
|
|
112
|
-
NOTICE,
|
|
113
|
-
SWITCH_ENV_KEY,
|
|
114
|
-
is_candidate,
|
|
115
|
-
is_rearmed,
|
|
116
|
-
is_redundant_reread,
|
|
117
|
-
is_refusable_call,
|
|
118
|
-
is_unchanged_reread,
|
|
119
|
-
last_read_ms,
|
|
120
|
-
read_target
|
|
121
|
-
};
|
|
122
|
-
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
123
|
-
if (process.stdin.isTTY) hook_decision.report_no_payload("duplicate-read:guard");
|
|
124
|
-
else hook_decision.write_outcome(await text(process.stdin), duplicate_read_outcome);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
SWITCH_ENV_KEY,
|
|
129
|
-
duplicate_read_refusal,
|
|
130
|
-
duplicate_read_outcome,
|
|
131
|
-
is_enabled,
|
|
132
|
-
refusal_path,
|
|
133
|
-
notice_refusal_path,
|
|
134
|
-
deny_envelope,
|
|
135
|
-
DISABLED_VALUES,
|
|
136
|
-
duplicate_reads
|
|
137
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hook_decision,
|
|
3
|
-
time_batch_guard
|
|
4
|
-
} from "./chunk-XIXXIVGY.js";
|
|
5
|
-
|
|
6
|
-
// scripts/hooks/batch-guard.ts
|
|
7
|
-
import { text } from "node:stream/consumers";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
var SWITCH_ENV_KEY = "JOSH_BATCH_GUARD";
|
|
10
|
-
function is_batch_candidate(call) {
|
|
11
|
-
return time_batch_guard.is_guarded_call(call) || time_batch_guard.is_notice_call(call);
|
|
12
|
-
}
|
|
13
|
-
var GUARD = hook_decision.create_transcript_guard({
|
|
14
|
-
prefix: time_batch_guard.STAMP_PREFIX,
|
|
15
|
-
switch_key: SWITCH_ENV_KEY,
|
|
16
|
-
is_candidate: is_batch_candidate,
|
|
17
|
-
should_block: time_batch_guard.should_block,
|
|
18
|
-
reason: time_batch_guard.REASON,
|
|
19
|
-
// The whole-file write is notified rather than refused, on a record of its own so it never spends
|
|
20
|
-
// the refusal's stamp (joshuafolkken/kit#1848).
|
|
21
|
-
notify: {
|
|
22
|
-
prefix: time_batch_guard.NOTICE_STAMP_PREFIX,
|
|
23
|
-
should_notify: time_batch_guard.should_notify,
|
|
24
|
-
text: time_batch_guard.NOTICE
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
var batch_refusal = GUARD.refusal;
|
|
28
|
-
var batch_outcome = GUARD.outcome;
|
|
29
|
-
var { is_enabled, refusal_path } = GUARD;
|
|
30
|
-
var notice_refusal_path = hook_decision.create_refusal_stamp(
|
|
31
|
-
time_batch_guard.NOTICE_STAMP_PREFIX
|
|
32
|
-
).path;
|
|
33
|
-
var { deny_envelope, load_environment_file, DISABLED_VALUES } = hook_decision;
|
|
34
|
-
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
35
|
-
if (process.stdin.isTTY) hook_decision.report_no_payload("batch:guard");
|
|
36
|
-
else hook_decision.write_outcome(await text(process.stdin), batch_outcome);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
SWITCH_ENV_KEY,
|
|
41
|
-
batch_refusal,
|
|
42
|
-
batch_outcome,
|
|
43
|
-
is_enabled,
|
|
44
|
-
refusal_path,
|
|
45
|
-
notice_refusal_path,
|
|
46
|
-
deny_envelope,
|
|
47
|
-
load_environment_file,
|
|
48
|
-
DISABLED_VALUES
|
|
49
|
-
};
|
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ESLINT_EDIT_CACHE_FLAGS,
|
|
3
|
-
time_density_hook
|
|
4
|
-
} from "./chunk-USLFAFOI.js";
|
|
5
|
-
|
|
6
|
-
// scripts/hooks/format-edited-file.ts
|
|
7
|
-
import { existsSync as existsSync3 } from "node:fs";
|
|
8
|
-
import path3 from "node:path";
|
|
9
|
-
import { text } from "node:stream/consumers";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
11
|
-
|
|
12
|
-
// scripts/build/local-bin.ts
|
|
13
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
-
import { createRequire } from "node:module";
|
|
15
|
-
import path from "node:path";
|
|
16
|
-
|
|
17
|
-
// scripts/lib/schemas.ts
|
|
18
|
-
import { z } from "zod";
|
|
19
|
-
var overrides_snapshot_schema = z.record(z.string(), z.string());
|
|
20
|
-
var package_version_schema = z.object({ version: z.string() });
|
|
21
|
-
var package_named_version_schema = z.looseObject({ name: z.string(), version: z.string() });
|
|
22
|
-
var package_with_version_schema = z.looseObject({ version: z.string() });
|
|
23
|
-
var ls_global_dependency_schema = z.looseObject({ version: z.string() });
|
|
24
|
-
var ls_global_dependencies_schema = z.record(z.string(), ls_global_dependency_schema).optional();
|
|
25
|
-
var pnpm_ls_global_schema = z.array(
|
|
26
|
-
z.looseObject({
|
|
27
|
-
dependencies: ls_global_dependencies_schema
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
var vscode_settings_schema = z.record(z.string(), z.unknown());
|
|
31
|
-
var with_scripts_schema = z.looseObject({
|
|
32
|
-
scripts: z.record(z.string(), z.string()).optional()
|
|
33
|
-
});
|
|
34
|
-
var with_development_deps_schema = z.looseObject({
|
|
35
|
-
devDependencies: z.record(z.string(), z.string()).optional()
|
|
36
|
-
});
|
|
37
|
-
var with_package_manager_schema = z.looseObject({
|
|
38
|
-
packageManager: z.string().optional()
|
|
39
|
-
});
|
|
40
|
-
var with_development_engine_schema = z.looseObject({
|
|
41
|
-
devEngines: z.record(z.string(), z.unknown()).optional()
|
|
42
|
-
});
|
|
43
|
-
var bin_entry_schema = z.union([z.string(), z.record(z.string(), z.string())]).optional();
|
|
44
|
-
var package_bin_schema = z.looseObject({ bin: bin_entry_schema });
|
|
45
|
-
var json_object_schema = z.record(z.string(), z.unknown());
|
|
46
|
-
var string_array_schema = z.array(z.string());
|
|
47
|
-
var string_record_schema = z.record(z.string(), z.string());
|
|
48
|
-
|
|
49
|
-
// scripts/build/local-bin.ts
|
|
50
|
-
var NODE_MODULES = "node_modules";
|
|
51
|
-
var BIN_DIR = ".bin";
|
|
52
|
-
var WINDOWS_PLATFORM = "win32";
|
|
53
|
-
var WINDOWS_SHIM_SUFFIX = ".cmd";
|
|
54
|
-
var PACKAGE_JSON = "package.json";
|
|
55
|
-
function resolve_local_bin(project_root, bin_name) {
|
|
56
|
-
const shim = process.platform === WINDOWS_PLATFORM ? `${bin_name}${WINDOWS_SHIM_SUFFIX}` : bin_name;
|
|
57
|
-
return path.join(project_root, NODE_MODULES, BIN_DIR, shim);
|
|
58
|
-
}
|
|
59
|
-
function read_bin_entry(manifest_path, package_name, bin_name) {
|
|
60
|
-
const { bin } = package_bin_schema.parse(JSON.parse(readFileSync(manifest_path, "utf8")));
|
|
61
|
-
if (typeof bin === "string") return bin_name === path.basename(package_name) ? bin : void 0;
|
|
62
|
-
return bin?.[bin_name];
|
|
63
|
-
}
|
|
64
|
-
function resolve_package_bin(base_directory, package_name, bin_name) {
|
|
65
|
-
try {
|
|
66
|
-
const resolve_from = createRequire(path.join(base_directory, PACKAGE_JSON));
|
|
67
|
-
const manifest_path = resolve_from.resolve(`${package_name}/${PACKAGE_JSON}`);
|
|
68
|
-
const bin_entry = read_bin_entry(manifest_path, package_name, bin_name);
|
|
69
|
-
if (bin_entry === void 0) return void 0;
|
|
70
|
-
const cli_entry = path.join(path.dirname(manifest_path), bin_entry);
|
|
71
|
-
return existsSync(cli_entry) ? cli_entry : void 0;
|
|
72
|
-
} catch {
|
|
73
|
-
return void 0;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// scripts/hooks/format-edited-file.ts
|
|
78
|
-
import { execa as execa2 } from "execa";
|
|
79
|
-
import { z as z2 } from "zod";
|
|
80
|
-
|
|
81
|
-
// scripts/hooks/edited-cspell.ts
|
|
82
|
-
import { existsSync as existsSync2 } from "node:fs";
|
|
83
|
-
import path2 from "node:path";
|
|
84
|
-
import { execa } from "execa";
|
|
85
|
-
var CSPELL_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
86
|
-
".ts",
|
|
87
|
-
".tsx",
|
|
88
|
-
".js",
|
|
89
|
-
".jsx",
|
|
90
|
-
".mjs",
|
|
91
|
-
".cjs",
|
|
92
|
-
".svelte",
|
|
93
|
-
".md",
|
|
94
|
-
".mdx",
|
|
95
|
-
".txt",
|
|
96
|
-
".json",
|
|
97
|
-
".jsonc",
|
|
98
|
-
".yml",
|
|
99
|
-
".yaml",
|
|
100
|
-
".html",
|
|
101
|
-
".css"
|
|
102
|
-
]);
|
|
103
|
-
var CSPELL_ARGS = [
|
|
104
|
-
"exec",
|
|
105
|
-
"cspell",
|
|
106
|
-
"lint",
|
|
107
|
-
"--words-only",
|
|
108
|
-
"--unique",
|
|
109
|
-
"--no-progress",
|
|
110
|
-
"--no-summary"
|
|
111
|
-
];
|
|
112
|
-
var PNPM = "pnpm";
|
|
113
|
-
var PROCESS_TIMEOUT_MS = 15e3;
|
|
114
|
-
var HEADER = "The edit hook found words cspell does not know; fix them or add them to `cspell.config.yaml` now rather than at the gate:";
|
|
115
|
-
var MAX_DIAGNOSTIC_CHARS = 4e3;
|
|
116
|
-
var TRUNCATION_NOTICE = "\n\u2026(unknown words truncated)";
|
|
117
|
-
function is_checkable(file_path, project_root) {
|
|
118
|
-
if (!existsSync2(file_path) || !CSPELL_EXTENSIONS.has(path2.extname(file_path).toLowerCase())) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
const relative = path2.relative(path2.resolve(project_root), path2.resolve(file_path));
|
|
122
|
-
return relative !== "" && !relative.startsWith("..") && !path2.isAbsolute(relative);
|
|
123
|
-
}
|
|
124
|
-
async function run_cspell(file_path, project_root) {
|
|
125
|
-
const result = await execa(PNPM, [...CSPELL_ARGS, file_path], {
|
|
126
|
-
reject: false,
|
|
127
|
-
cwd: project_root,
|
|
128
|
-
stdout: "pipe",
|
|
129
|
-
stderr: "ignore",
|
|
130
|
-
timeout: PROCESS_TIMEOUT_MS
|
|
131
|
-
});
|
|
132
|
-
return result.stdout;
|
|
133
|
-
}
|
|
134
|
-
function format_unknown_words(stdout) {
|
|
135
|
-
const words = stdout.split("\n").map((word) => word.trim()).filter((word) => word.length > 0);
|
|
136
|
-
if (words.length === 0) return void 0;
|
|
137
|
-
const joined = words.join("\n");
|
|
138
|
-
const body = joined.length > MAX_DIAGNOSTIC_CHARS ? `${joined.slice(0, MAX_DIAGNOSTIC_CHARS)}${TRUNCATION_NOTICE}` : joined;
|
|
139
|
-
return `${HEADER}
|
|
140
|
-
${body}`;
|
|
141
|
-
}
|
|
142
|
-
async function spelling_diagnostics(file_path, project_root, runner = run_cspell) {
|
|
143
|
-
if (file_path === void 0 || !is_checkable(file_path, project_root)) return void 0;
|
|
144
|
-
try {
|
|
145
|
-
return format_unknown_words(await runner(file_path, project_root));
|
|
146
|
-
} catch {
|
|
147
|
-
return void 0;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
var edited_cspell = { format_unknown_words, is_checkable, spelling_diagnostics };
|
|
151
|
-
|
|
152
|
-
// scripts/hooks/format-rewrite-notice.ts
|
|
153
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
154
|
-
var MAX_REWRITE_CHARS = 1200;
|
|
155
|
-
var REWRITE_TRUNCATION_NOTICE = "\n\u2026(rewrite preview truncated)";
|
|
156
|
-
var REWRITE_HEADER = "The format hook rewrote this file after your edit, so your in-memory copy is now stale \u2014 re-read it before the next Edit or the match will miss.";
|
|
157
|
-
var REWRITE_RANGE_PREFIX = "Changed around lines ";
|
|
158
|
-
var LINE_SEPARATOR = "\n";
|
|
159
|
-
var FIRST_LINE = 1;
|
|
160
|
-
function common_prefix_length(before, after) {
|
|
161
|
-
const limit = Math.min(before.length, after.length);
|
|
162
|
-
let index = 0;
|
|
163
|
-
while (index < limit && before[index] === after[index]) index += 1;
|
|
164
|
-
return index;
|
|
165
|
-
}
|
|
166
|
-
function common_suffix_length(before, after, prefix) {
|
|
167
|
-
const limit = Math.min(before.length, after.length) - prefix;
|
|
168
|
-
let index = 0;
|
|
169
|
-
while (index < limit && before.at(-1 - index) === after.at(-1 - index)) index += 1;
|
|
170
|
-
return index;
|
|
171
|
-
}
|
|
172
|
-
function changed_range(before, after) {
|
|
173
|
-
const before_lines = before.split(LINE_SEPARATOR);
|
|
174
|
-
const after_lines = after.split(LINE_SEPARATOR);
|
|
175
|
-
const prefix = common_prefix_length(before_lines, after_lines);
|
|
176
|
-
const last = after_lines.length - common_suffix_length(before_lines, after_lines, prefix);
|
|
177
|
-
return {
|
|
178
|
-
start_line: prefix + FIRST_LINE,
|
|
179
|
-
end_line: Math.max(prefix + FIRST_LINE, last),
|
|
180
|
-
body: after_lines.slice(prefix, last).join(LINE_SEPARATOR)
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function cap_body(body) {
|
|
184
|
-
if (body.length <= MAX_REWRITE_CHARS) return body;
|
|
185
|
-
return `${body.slice(0, MAX_REWRITE_CHARS)}${REWRITE_TRUNCATION_NOTICE}`;
|
|
186
|
-
}
|
|
187
|
-
function build(before, after) {
|
|
188
|
-
if (before === after) return void 0;
|
|
189
|
-
const range = changed_range(before, after);
|
|
190
|
-
const location = `${REWRITE_RANGE_PREFIX}${String(range.start_line)}-${String(range.end_line)}:`;
|
|
191
|
-
return `${REWRITE_HEADER}
|
|
192
|
-
${location}
|
|
193
|
-
${cap_body(range.body)}`;
|
|
194
|
-
}
|
|
195
|
-
function read_text(file_path) {
|
|
196
|
-
if (file_path === void 0) return "";
|
|
197
|
-
try {
|
|
198
|
-
return readFileSync2(file_path, "utf8");
|
|
199
|
-
} catch {
|
|
200
|
-
return "";
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
var rewrite_notice = { build, read_text };
|
|
204
|
-
|
|
205
|
-
// scripts/hooks/format-edited-file.ts
|
|
206
|
-
var hook_payload_schema = z2.object({
|
|
207
|
-
tool_input: z2.object({ file_path: z2.string().min(1) }).optional()
|
|
208
|
-
});
|
|
209
|
-
var PRETTIER_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
210
|
-
".ts",
|
|
211
|
-
".tsx",
|
|
212
|
-
".js",
|
|
213
|
-
".jsx",
|
|
214
|
-
".mjs",
|
|
215
|
-
".cjs",
|
|
216
|
-
".svelte",
|
|
217
|
-
".json",
|
|
218
|
-
".jsonc",
|
|
219
|
-
".md",
|
|
220
|
-
".yml",
|
|
221
|
-
".yaml",
|
|
222
|
-
".css",
|
|
223
|
-
".html"
|
|
224
|
-
]);
|
|
225
|
-
var ESLINT_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".svelte"]);
|
|
226
|
-
var EXCLUDED_ANYWHERE = /* @__PURE__ */ new Set(["node_modules", ".git"]);
|
|
227
|
-
var EXCLUDED_AT_ROOT = /* @__PURE__ */ new Set(["dist", "build"]);
|
|
228
|
-
var PARENT_SEGMENT = "..";
|
|
229
|
-
var PNPM2 = "pnpm";
|
|
230
|
-
var PRETTIER_BIN = "prettier";
|
|
231
|
-
var PRETTIER_ARGUMENTS = ["--write", "--ignore-unknown"];
|
|
232
|
-
var ESLINT_BIN = "eslint";
|
|
233
|
-
var ESLINT_ARGUMENTS = [
|
|
234
|
-
"--fix",
|
|
235
|
-
"--no-error-on-unmatched-pattern",
|
|
236
|
-
...ESLINT_EDIT_CACHE_FLAGS
|
|
237
|
-
];
|
|
238
|
-
var ESLINT_DAEMON = "eslint_d";
|
|
239
|
-
var DAEMON_RESTART = "restart";
|
|
240
|
-
var ESLINT_CONFIG_DIR = "eslint";
|
|
241
|
-
var ESLINT_CONFIG_ENTRY = /^eslint\.config\.[cm]?[jt]s$/u;
|
|
242
|
-
var PROCESS_TIMEOUT_MS2 = 15e3;
|
|
243
|
-
var DIAGNOSTIC_HEADER = "The edit hook could not auto-fix these lint problems; address them now rather than at the gate:";
|
|
244
|
-
var MAX_DIAGNOSTIC_CHARS2 = 4e3;
|
|
245
|
-
var DIAGNOSTIC_TRUNCATION_NOTICE = "\n\u2026(diagnostics truncated)";
|
|
246
|
-
var SECTION_SEPARATOR = "\n\n";
|
|
247
|
-
var MODULE_DIRECTORY = path3.dirname(fileURLToPath(import.meta.url));
|
|
248
|
-
function parse_edited_path(raw_payload) {
|
|
249
|
-
try {
|
|
250
|
-
const result = hook_payload_schema.safeParse(JSON.parse(raw_payload));
|
|
251
|
-
return result.success ? result.data.tool_input?.file_path : void 0;
|
|
252
|
-
} catch {
|
|
253
|
-
return void 0;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
function is_excluded(relative_path) {
|
|
257
|
-
const segments = relative_path.split(path3.sep);
|
|
258
|
-
return segments.some((segment) => EXCLUDED_ANYWHERE.has(segment)) || EXCLUDED_AT_ROOT.has(segments[0] ?? "");
|
|
259
|
-
}
|
|
260
|
-
function relative_to_root(project_root, file_path) {
|
|
261
|
-
const relative = path3.relative(path3.resolve(project_root), path3.resolve(file_path));
|
|
262
|
-
const is_inside_root = relative !== "" && relative.split(path3.sep)[0] !== PARENT_SEGMENT && !path3.isAbsolute(relative);
|
|
263
|
-
return is_inside_root ? relative : void 0;
|
|
264
|
-
}
|
|
265
|
-
function is_formattable(file_path, project_root) {
|
|
266
|
-
const relative = relative_to_root(project_root, file_path);
|
|
267
|
-
return relative !== void 0 && !is_excluded(relative) && existsSync3(file_path);
|
|
268
|
-
}
|
|
269
|
-
function plan_commands(file_path, project_root) {
|
|
270
|
-
if (!is_formattable(file_path, project_root)) return [];
|
|
271
|
-
const extension = path3.extname(file_path).toLowerCase();
|
|
272
|
-
const commands = [];
|
|
273
|
-
if (ESLINT_EXTENSIONS.has(extension)) {
|
|
274
|
-
commands.push({ bin: ESLINT_BIN, command_arguments: [...ESLINT_ARGUMENTS, file_path] });
|
|
275
|
-
}
|
|
276
|
-
if (PRETTIER_EXTENSIONS.has(extension)) {
|
|
277
|
-
commands.push({ bin: PRETTIER_BIN, command_arguments: [...PRETTIER_ARGUMENTS, file_path] });
|
|
278
|
-
}
|
|
279
|
-
return commands;
|
|
280
|
-
}
|
|
281
|
-
function select_invocation(command, routes) {
|
|
282
|
-
if (routes.daemon_cli !== void 0) {
|
|
283
|
-
return {
|
|
284
|
-
bin: process.execPath,
|
|
285
|
-
command_arguments: [routes.daemon_cli, ...command.command_arguments]
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
if (routes.shim !== void 0) {
|
|
289
|
-
return { bin: routes.shim, command_arguments: command.command_arguments };
|
|
290
|
-
}
|
|
291
|
-
return { bin: PNPM2, command_arguments: ["exec", command.bin, ...command.command_arguments] };
|
|
292
|
-
}
|
|
293
|
-
var DAEMON_BINS = /* @__PURE__ */ new Set([ESLINT_BIN, ESLINT_DAEMON]);
|
|
294
|
-
function resolve_daemon_cli(bin, project_root) {
|
|
295
|
-
if (!DAEMON_BINS.has(bin)) return void 0;
|
|
296
|
-
return resolve_package_bin(MODULE_DIRECTORY, ESLINT_DAEMON, ESLINT_DAEMON) ?? resolve_package_bin(project_root, ESLINT_DAEMON, ESLINT_DAEMON);
|
|
297
|
-
}
|
|
298
|
-
function is_eslint_config_input(relative_path) {
|
|
299
|
-
return relative_path.split(path3.sep)[0] === ESLINT_CONFIG_DIR || ESLINT_CONFIG_ENTRY.test(relative_path);
|
|
300
|
-
}
|
|
301
|
-
function plan_daemon_restart(file_path, project_root) {
|
|
302
|
-
const relative = relative_to_root(project_root, file_path);
|
|
303
|
-
if (relative === void 0 || !is_eslint_config_input(relative)) return [];
|
|
304
|
-
if (resolve_daemon_cli(ESLINT_DAEMON, project_root) === void 0) return [];
|
|
305
|
-
return [{ bin: ESLINT_DAEMON, command_arguments: [DAEMON_RESTART] }];
|
|
306
|
-
}
|
|
307
|
-
function resolve_invocations(command, project_root) {
|
|
308
|
-
const shim = resolve_local_bin(project_root, command.bin);
|
|
309
|
-
const routes = {
|
|
310
|
-
daemon_cli: resolve_daemon_cli(command.bin, project_root),
|
|
311
|
-
shim: existsSync3(shim) ? shim : void 0
|
|
312
|
-
};
|
|
313
|
-
const without_daemon = select_invocation(command, { ...routes, daemon_cli: void 0 });
|
|
314
|
-
if (routes.daemon_cli === void 0) return [without_daemon];
|
|
315
|
-
return [select_invocation(command, routes), without_daemon];
|
|
316
|
-
}
|
|
317
|
-
function is_start_failure(outcome) {
|
|
318
|
-
return outcome.exit_code !== 0 && outcome.stdout.length === 0;
|
|
319
|
-
}
|
|
320
|
-
async function spawn_invocation(invocation, project_root) {
|
|
321
|
-
const result = await execa2(invocation.bin, [...invocation.command_arguments], {
|
|
322
|
-
reject: false,
|
|
323
|
-
cwd: project_root,
|
|
324
|
-
env: { ESLINT_D_MISS: "fail" },
|
|
325
|
-
stdout: "pipe",
|
|
326
|
-
stderr: "ignore",
|
|
327
|
-
timeout: PROCESS_TIMEOUT_MS2
|
|
328
|
-
});
|
|
329
|
-
return { exit_code: result.exitCode ?? 1, stdout: result.stdout };
|
|
330
|
-
}
|
|
331
|
-
async function run_command(command, project_root) {
|
|
332
|
-
let outcome = { exit_code: 0, stdout: "" };
|
|
333
|
-
for (const invocation of resolve_invocations(command, project_root)) {
|
|
334
|
-
outcome = await spawn_invocation(invocation, project_root);
|
|
335
|
-
if (!is_start_failure(outcome)) return outcome;
|
|
336
|
-
}
|
|
337
|
-
return outcome;
|
|
338
|
-
}
|
|
339
|
-
function eslint_unfixed(command, outcome) {
|
|
340
|
-
if (command.bin !== ESLINT_BIN) return void 0;
|
|
341
|
-
if (outcome.exit_code === 0 || outcome.stdout.length === 0) return void 0;
|
|
342
|
-
return outcome.stdout;
|
|
343
|
-
}
|
|
344
|
-
function format_diagnostics(unfixed) {
|
|
345
|
-
if (unfixed === void 0) return void 0;
|
|
346
|
-
const is_over = unfixed.length > MAX_DIAGNOSTIC_CHARS2;
|
|
347
|
-
const body = is_over ? `${unfixed.slice(0, MAX_DIAGNOSTIC_CHARS2)}${DIAGNOSTIC_TRUNCATION_NOTICE}` : unfixed;
|
|
348
|
-
return `${DIAGNOSTIC_HEADER}
|
|
349
|
-
${body}`;
|
|
350
|
-
}
|
|
351
|
-
async function collect_unfixed(plan, runner, project_root) {
|
|
352
|
-
let unfixed = "";
|
|
353
|
-
for (const command of plan) {
|
|
354
|
-
try {
|
|
355
|
-
unfixed = eslint_unfixed(command, await runner(command, project_root)) ?? unfixed;
|
|
356
|
-
} catch {
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return unfixed;
|
|
361
|
-
}
|
|
362
|
-
async function format_edited_file(raw_payload, runner, project_root) {
|
|
363
|
-
const file_path = parse_edited_path(raw_payload);
|
|
364
|
-
if (file_path === void 0) return void 0;
|
|
365
|
-
const plan = [
|
|
366
|
-
...plan_commands(file_path, project_root),
|
|
367
|
-
...plan_daemon_restart(file_path, project_root)
|
|
368
|
-
];
|
|
369
|
-
const unfixed = await collect_unfixed(plan, runner, project_root);
|
|
370
|
-
return format_diagnostics(unfixed === "" ? void 0 : unfixed);
|
|
371
|
-
}
|
|
372
|
-
async function format_edited_payload(raw_payload, project_root) {
|
|
373
|
-
return await format_edited_file(raw_payload, run_command, project_root);
|
|
374
|
-
}
|
|
375
|
-
var HOOK_EVENT_NAME = "PostToolUse";
|
|
376
|
-
function build_envelope(additional_context) {
|
|
377
|
-
return JSON.stringify({
|
|
378
|
-
hookSpecificOutput: { hookEventName: HOOK_EVENT_NAME, additionalContext: additional_context }
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
function density_envelope(raw_payload) {
|
|
382
|
-
const notice = time_density_hook.density_notice(raw_payload);
|
|
383
|
-
return notice === void 0 ? void 0 : build_envelope(notice);
|
|
384
|
-
}
|
|
385
|
-
function compose_context(notice, diagnostics) {
|
|
386
|
-
const sections = [notice, diagnostics].filter(
|
|
387
|
-
(section) => section !== void 0
|
|
388
|
-
);
|
|
389
|
-
return sections.length === 0 ? void 0 : sections.join(SECTION_SEPARATOR);
|
|
390
|
-
}
|
|
391
|
-
function report_no_payload() {
|
|
392
|
-
process.stderr.write(
|
|
393
|
-
"format:edited reads a Claude Code PostToolUse payload on stdin; it is not run by hand.\n"
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
async function run_hook(payload) {
|
|
397
|
-
const notice = time_density_hook.density_notice(payload);
|
|
398
|
-
const file_path = parse_edited_path(payload);
|
|
399
|
-
const before = rewrite_notice.read_text(file_path);
|
|
400
|
-
const lint = await format_edited_payload(payload, process.cwd());
|
|
401
|
-
const rewrite = rewrite_notice.build(before, rewrite_notice.read_text(file_path));
|
|
402
|
-
const spelling = await edited_cspell.spelling_diagnostics(file_path, process.cwd());
|
|
403
|
-
const parts = compose_context(rewrite, compose_context(lint, spelling));
|
|
404
|
-
const context = compose_context(notice, parts);
|
|
405
|
-
if (context !== void 0) process.stdout.write(`${build_envelope(context)}
|
|
406
|
-
`);
|
|
407
|
-
}
|
|
408
|
-
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
409
|
-
if (process.stdin.isTTY) {
|
|
410
|
-
report_no_payload();
|
|
411
|
-
} else {
|
|
412
|
-
await run_hook(await text(process.stdin));
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
export {
|
|
417
|
-
ESLINT_DAEMON,
|
|
418
|
-
PROCESS_TIMEOUT_MS2 as PROCESS_TIMEOUT_MS,
|
|
419
|
-
MAX_DIAGNOSTIC_CHARS2 as MAX_DIAGNOSTIC_CHARS,
|
|
420
|
-
parse_edited_path,
|
|
421
|
-
relative_to_root,
|
|
422
|
-
plan_commands,
|
|
423
|
-
select_invocation,
|
|
424
|
-
plan_daemon_restart,
|
|
425
|
-
resolve_invocations,
|
|
426
|
-
is_start_failure,
|
|
427
|
-
format_edited_file,
|
|
428
|
-
format_edited_payload,
|
|
429
|
-
build_envelope,
|
|
430
|
-
density_envelope,
|
|
431
|
-
compose_context
|
|
432
|
-
};
|