clikcode 1.0.3 → 1.0.5
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 +25 -14
- package/dist/chunk-23TDEBGZ.js +71 -0
- package/dist/chunk-25T3GVS7.js +425 -0
- package/dist/chunk-2BBELGHY.js +11 -0
- package/dist/chunk-2EOL5PZL.js +208 -0
- package/dist/chunk-2GAB36IE.js +26 -0
- package/dist/chunk-2OLS7V66.js +2440 -0
- package/dist/chunk-2QFO2URB.js +179 -0
- package/dist/chunk-2QWPQRSU.js +254 -0
- package/dist/chunk-2YPAPAR3.js +184 -0
- package/dist/chunk-2ZAG5372.js +33 -0
- package/dist/chunk-32IKAIZC.js +12507 -0
- package/dist/chunk-34AZEGYW.js +95 -0
- package/dist/chunk-34JQYQCA.js +175 -0
- package/dist/chunk-34ZISPAO.js +67 -0
- package/dist/chunk-3AAAARE6.js +46 -0
- package/dist/chunk-3AJ6Q3OY.js +510 -0
- package/dist/chunk-3B2CHX7M.js +884 -0
- package/dist/chunk-3BUFORRX.js +59 -0
- package/dist/chunk-3QLHYYFK.js +30 -0
- package/dist/chunk-3RXBMYKZ.js +140 -0
- package/dist/chunk-3TFNIJWS.js +52 -0
- package/dist/chunk-3W3IPDFP.js +119 -0
- package/dist/chunk-3WMS7SEE.js +417 -0
- package/dist/chunk-435ZNSZ3.js +23 -0
- package/dist/chunk-4AQ5NINV.js +39 -0
- package/dist/chunk-4GVEJ5FK.js +168 -0
- package/dist/chunk-4GXAO3UY.js +262 -0
- package/dist/chunk-4L2ZZM4Q.js +332 -0
- package/dist/chunk-4LPDG57B.js +17 -0
- package/dist/chunk-4NN3XQQT.js +223 -0
- package/dist/chunk-4QZEZME7.js +54 -0
- package/dist/chunk-4R6CSC3S.js +38 -0
- package/dist/chunk-4RHXTL3W.js +514 -0
- package/dist/chunk-4SJMPTVQ.js +18 -0
- package/dist/chunk-4VY7G6TX.js +114 -0
- package/dist/chunk-5642PBF7.js +124 -0
- package/dist/chunk-5B6TVO4A.js +33 -0
- package/dist/chunk-5BJLDUPL.js +62 -0
- package/dist/chunk-5HMFFJWU.js +19 -0
- package/dist/chunk-5IKLK33T.js +69 -0
- package/dist/chunk-5NQ5FFMX.js +44 -0
- package/dist/chunk-5QNNW5L6.js +176 -0
- package/dist/chunk-5SM5UAWN.js +239 -0
- package/dist/chunk-5WYJTA6O.js +74 -0
- package/dist/chunk-5ZSR2Y5T.js +227 -0
- package/dist/chunk-5ZWUM5GH.js +39 -0
- package/dist/chunk-64E7D4HY.js +364 -0
- package/dist/chunk-6CK466BC.js +99 -0
- package/dist/chunk-6ES45HHO.js +138 -0
- package/dist/chunk-6HYEZFGL.js +277 -0
- package/dist/chunk-6Y7HLXGW.js +29 -0
- package/dist/chunk-6YKK4FYR.js +258 -0
- package/dist/chunk-74WNMLMS.js +117 -0
- package/dist/chunk-7AULZ7OD.js +55 -0
- package/dist/chunk-7DOKGSUN.js +101 -0
- package/dist/chunk-7IH5LTIZ.js +195 -0
- package/dist/chunk-7ISTS5NS.js +21 -0
- package/dist/chunk-7NMUTGOW.js +527 -0
- package/dist/chunk-7PNHUZEL.js +153 -0
- package/dist/chunk-7TSQLONI.js +88 -0
- package/dist/chunk-AE7TOLD5.js +30 -0
- package/dist/chunk-AEMHSXKA.js +130 -0
- package/dist/chunk-AKRYTS2D.js +211 -0
- package/dist/chunk-AMNSE36L.js +59 -0
- package/dist/chunk-AZVD74ZV.js +23 -0
- package/dist/chunk-B35DVOTK.js +1981 -0
- package/dist/chunk-B4HNJRAH.js +626 -0
- package/dist/chunk-B5WYPPHS.js +13 -0
- package/dist/chunk-BBOVDXQM.js +59 -0
- package/dist/chunk-BD3ECZLK.js +62 -0
- package/dist/chunk-BDGSOT74.js +4578 -0
- package/dist/chunk-BF5VEOPK.js +31 -0
- package/dist/chunk-BFFRW4XH.js +47 -0
- package/dist/chunk-BFPC6PEW.js +208 -0
- package/dist/chunk-BGEMY2JJ.js +376 -0
- package/dist/chunk-BISGNHKD.js +35 -0
- package/dist/chunk-BMRAEBRY.js +21 -0
- package/dist/chunk-BNTXAZXW.js +127 -0
- package/dist/chunk-BOQBXGSN.js +75 -0
- package/dist/chunk-BTJDSTQP.js +213 -0
- package/dist/chunk-BUOPJQP5.js +218 -0
- package/dist/chunk-BXFJS65Q.js +52 -0
- package/dist/chunk-BXPQFSX5.js +59 -0
- package/dist/chunk-C57LIWNY.js +1269 -0
- package/dist/chunk-C6YVCCWR.js +74 -0
- package/dist/chunk-CAADDF6M.js +167 -0
- package/dist/chunk-CBANJFBO.js +69 -0
- package/dist/chunk-CERF3RIB.js +597 -0
- package/dist/chunk-COAS5ETR.js +46 -0
- package/dist/chunk-CQ7J6UQ7.js +78 -0
- package/dist/chunk-CRUVYGO2.js +26 -0
- package/dist/chunk-CVFVFRGN.js +58 -0
- package/dist/chunk-D2UK66HM.js +37 -0
- package/dist/chunk-D2W7SA4R.js +18 -0
- package/dist/chunk-DA44ZENT.js +501 -0
- package/dist/chunk-DAJ76TOC.js +99 -0
- package/dist/chunk-DCZ6CIUM.js +147 -0
- package/dist/chunk-DF35KMXM.js +1314 -0
- package/dist/chunk-DGASQT26.js +151 -0
- package/dist/chunk-DJT57C5P.js +55 -0
- package/dist/chunk-DKDPZTD3.js +44 -0
- package/dist/chunk-DQYVQ2N7.js +77 -0
- package/dist/chunk-DRTP2RTY.js +266 -0
- package/dist/chunk-DW2BMUKY.js +61 -0
- package/dist/chunk-DW5T5ZVU.js +307 -0
- package/dist/chunk-DXKNDNFC.js +164 -0
- package/dist/chunk-DZEQ7UYR.js +291 -0
- package/dist/chunk-E4F4OUAC.js +463 -0
- package/dist/chunk-EE4B6A7W.js +69 -0
- package/dist/chunk-EISKIYWG.js +23 -0
- package/dist/chunk-EKAQK7UQ.js +235 -0
- package/dist/chunk-EOBTJV32.js +123 -0
- package/dist/chunk-ESF3DIZY.js +325 -0
- package/dist/chunk-EVOHOZ4U.js +45 -0
- package/dist/chunk-EXN4KHLB.js +110 -0
- package/dist/chunk-F252T6Y3.js +78 -0
- package/dist/chunk-F3DP4ZA2.js +40 -0
- package/dist/chunk-F6F47QAY.js +58 -0
- package/dist/chunk-FA3Y23ZW.js +57 -0
- package/dist/chunk-FBKXE4EJ.js +640 -0
- package/dist/chunk-FCGEB3H6.js +23 -0
- package/dist/chunk-FF7ZVYJF.js +3732 -0
- package/dist/chunk-FFGKN6L3.js +39 -0
- package/dist/chunk-FFGU4GCC.js +94 -0
- package/dist/chunk-FSFDAOVP.js +74 -0
- package/dist/chunk-FT5TX7OX.js +1573 -0
- package/dist/chunk-G3QP67Z7.js +232 -0
- package/dist/chunk-G5ORJKV2.js +179 -0
- package/dist/chunk-GFNC62PE.js +111 -0
- package/dist/chunk-GGK43Q3N.js +67 -0
- package/dist/chunk-GGYKY4GF.js +11537 -0
- package/dist/chunk-GGYNHGNJ.js +55 -0
- package/dist/chunk-GLY7RM3C.js +354 -0
- package/dist/chunk-GQBZU6EO.js +20 -0
- package/dist/chunk-GSXENUZL.js +9 -0
- package/dist/chunk-GTOAT5D3.js +40 -0
- package/dist/chunk-GWCMDPQU.js +1007 -0
- package/dist/chunk-GXYSMYHJ.js +152 -0
- package/dist/chunk-GYMAI5NY.js +14 -0
- package/dist/chunk-H2VZMKPE.js +30 -0
- package/dist/chunk-H4THUNBM.js +2091 -0
- package/dist/chunk-HGRVSNUZ.js +361 -0
- package/dist/chunk-HI4VY473.js +27 -0
- package/dist/chunk-HOJRSD3Q.js +447 -0
- package/dist/chunk-HRX25W35.js +82 -0
- package/dist/chunk-HSE4AQYV.js +55 -0
- package/dist/chunk-HU5SSUFX.js +383 -0
- package/dist/chunk-I3GDBJLH.js +196 -0
- package/dist/chunk-I75EDU75.js +684 -0
- package/dist/chunk-IBA7DMIO.js +20 -0
- package/dist/chunk-IC6N4NZA.js +231 -0
- package/dist/chunk-IF43HIGV.js +284 -0
- package/dist/chunk-IGZ6C2MC.js +439 -0
- package/dist/chunk-IMLTL2MY.js +192 -0
- package/dist/chunk-IMZL6SGR.js +33 -0
- package/dist/chunk-IS4USJPY.js +516 -0
- package/dist/chunk-ISFSPN2F.js +82 -0
- package/dist/chunk-IXE7GTFI.js +55 -0
- package/dist/chunk-IZ77QJQG.js +36 -0
- package/dist/chunk-J2PACWRQ.js +34 -0
- package/dist/chunk-J6EGFVQX.js +180 -0
- package/dist/chunk-JEKOD43D.js +22 -0
- package/dist/chunk-JGIWATSG.js +30 -0
- package/dist/chunk-JYBONKD4.js +43 -0
- package/dist/chunk-K2NLG2HK.js +454 -0
- package/dist/chunk-KCQ4TBLS.js +164 -0
- package/dist/chunk-KD5KIVMS.js +176 -0
- package/dist/chunk-KHW6TX6I.js +63 -0
- package/dist/chunk-KI5GZFCE.js +520 -0
- package/dist/chunk-KN34B7NO.js +105 -0
- package/dist/chunk-KYUHIFP3.js +136 -0
- package/dist/chunk-KZL5VS4B.js +300 -0
- package/dist/chunk-L3VW3QIH.js +48 -0
- package/dist/chunk-LA6MG4ET.js +2110 -0
- package/dist/chunk-LAVFOA3S.js +66 -0
- package/dist/chunk-LB4OA77N.js +13 -0
- package/dist/chunk-LBFRF2K4.js +196 -0
- package/dist/chunk-LM6EIA4B.js +93 -0
- package/dist/chunk-LPCNRGJ7.js +692 -0
- package/dist/chunk-LSLNL5T3.js +168 -0
- package/dist/chunk-LVRRWP4W.js +568 -0
- package/dist/chunk-LWCFBRHL.js +33 -0
- package/dist/chunk-LXFTMGZZ.js +166 -0
- package/dist/chunk-M33LVA4M.js +151 -0
- package/dist/chunk-M3FO5UMK.js +4944 -0
- package/dist/chunk-M5QNDBAY.js +66 -0
- package/dist/chunk-M6ND6KBE.js +1291 -0
- package/dist/chunk-M7H3WQTE.js +76 -0
- package/dist/chunk-MCBRVPA7.js +191 -0
- package/dist/chunk-MCSDWZET.js +91 -0
- package/dist/chunk-MDT5XDXL.js +289 -0
- package/dist/chunk-MJG3IQY4.js +91 -0
- package/dist/chunk-MOU3N2UL.js +44 -0
- package/dist/chunk-MP4KZOQC.js +3451 -0
- package/dist/chunk-MPAJ446F.js +66 -0
- package/dist/chunk-MVJZZ6AL.js +16 -0
- package/dist/chunk-MXS6S2PY.js +253 -0
- package/dist/chunk-N3SFDYM7.js +291 -0
- package/dist/chunk-NAOX3JUB.js +13 -0
- package/dist/chunk-NEKKIBCX.js +283 -0
- package/dist/chunk-NKDATMEM.js +133 -0
- package/dist/chunk-NR4FMC4K.js +395 -0
- package/dist/chunk-NSOHOJBR.js +221 -0
- package/dist/chunk-NTDB6QKF.js +29 -0
- package/dist/chunk-NWEYRBWK.js +25 -0
- package/dist/chunk-O2YSNYWD.js +23 -0
- package/dist/chunk-O3EW7LAY.js +54 -0
- package/dist/chunk-O7BNJIXU.js +366 -0
- package/dist/chunk-OARL2NXZ.js +116 -0
- package/dist/chunk-OHKZUEJW.js +351 -0
- package/dist/chunk-OKU45BXA.js +647 -0
- package/dist/chunk-OL4JBD3J.js +59 -0
- package/dist/chunk-OLUO5DDR.js +192 -0
- package/dist/chunk-OQ245JLA.js +196 -0
- package/dist/chunk-P72UZAQI.js +289 -0
- package/dist/chunk-PAL2ENB6.js +20 -0
- package/dist/chunk-PAXYQZH7.js +53 -0
- package/dist/chunk-PDPEM5VW.js +51 -0
- package/dist/chunk-PEWCDI2C.js +668 -0
- package/dist/chunk-PGZ54EDX.js +27 -0
- package/dist/chunk-PRWVLDZF.js +73 -0
- package/dist/chunk-PSQQ75VJ.js +52 -0
- package/dist/chunk-PUOVIFHW.js +118 -0
- package/dist/chunk-PWBF2X3V.js +107 -0
- package/dist/chunk-PWXII6HF.js +43 -0
- package/dist/chunk-Q35VLJRT.js +80 -0
- package/dist/chunk-QJP7EYGL.js +128 -0
- package/dist/chunk-QPQKX2MK.js +8836 -0
- package/dist/chunk-QQRLPY25.js +1053 -0
- package/dist/chunk-QUS4ER2W.js +407 -0
- package/dist/chunk-QYHI3YET.js +29 -0
- package/dist/chunk-QYRU2UQI.js +32 -0
- package/dist/chunk-R6XVVQGC.js +13 -0
- package/dist/chunk-R7QN6ONS.js +483 -0
- package/dist/chunk-RD23MPGC.js +221 -0
- package/dist/chunk-RDDWQBEM.js +185 -0
- package/dist/chunk-RDLLDYFO.js +104 -0
- package/dist/chunk-RE4TGORR.js +84 -0
- package/dist/chunk-RJLHVYQY.js +217 -0
- package/dist/chunk-RJLPTWHW.js +905 -0
- package/dist/chunk-RKUVLRZI.js +295 -0
- package/dist/chunk-ROGXPGYR.js +37 -0
- package/dist/chunk-RSZGEL5U.js +163 -0
- package/dist/chunk-RVUOIJXN.js +909 -0
- package/dist/chunk-RW7F4JRP.js +11 -0
- package/dist/chunk-S4UO3AO3.js +53 -0
- package/dist/chunk-S5JAAF6S.js +585 -0
- package/dist/chunk-SNU37TQI.js +56 -0
- package/dist/chunk-SQVUDO2O.js +31 -0
- package/dist/chunk-SYVHIYQT.js +66 -0
- package/dist/chunk-SZBQMTG2.js +85 -0
- package/dist/chunk-T5VCXA3J.js +25 -0
- package/dist/chunk-TK6NSP56.js +30 -0
- package/dist/chunk-TKWVMA6L.js +22 -0
- package/dist/chunk-TQDKJHWX.js +59 -0
- package/dist/chunk-TQDM7S5N.js +127 -0
- package/dist/chunk-TULAXS77.js +23 -0
- package/dist/chunk-TVT45XNH.js +4625 -0
- package/dist/chunk-TWCVV2JO.js +467 -0
- package/dist/chunk-U4DKAD6S.js +47 -0
- package/dist/chunk-UA5K2BTI.js +564 -0
- package/dist/chunk-UAMKCMOK.js +40 -0
- package/dist/chunk-UBMVADBF.js +51 -0
- package/dist/chunk-UFQ5A5PW.js +645 -0
- package/dist/chunk-UOD2SOLL.js +1301 -0
- package/dist/chunk-UTSB4LOW.js +156 -0
- package/dist/chunk-UVXNIUTN.js +412 -0
- package/dist/chunk-UXVPXYPE.js +90 -0
- package/dist/chunk-UYEEMIWR.js +374 -0
- package/dist/chunk-VBGM5ZBW.js +54 -0
- package/dist/chunk-VEWPCZPG.js +762 -0
- package/dist/chunk-VIRDLZ5E.js +108 -0
- package/dist/chunk-VMPO7WKN.js +52 -0
- package/dist/chunk-W2NVSDO5.js +5122 -0
- package/dist/chunk-W3YYPBEA.js +176 -0
- package/dist/chunk-W5AYOICN.js +280 -0
- package/dist/chunk-W5GZOIUF.js +27 -0
- package/dist/chunk-WHKNLZ3C.js +76 -0
- package/dist/chunk-WKBEPPQ5.js +1409 -0
- package/dist/chunk-WM3Z6QKQ.js +151 -0
- package/dist/chunk-WMI2TPMA.js +31 -0
- package/dist/chunk-WNX5VD7S.js +150 -0
- package/dist/chunk-WOVTYST3.js +60 -0
- package/dist/chunk-WPB5WEZJ.js +546 -0
- package/dist/chunk-WUO5EOAT.js +44 -0
- package/dist/chunk-WWLJMP6D.js +133 -0
- package/dist/chunk-WZMLH3XP.js +58 -0
- package/dist/chunk-WZYVLUVQ.js +79 -0
- package/dist/chunk-X2OCPVU5.js +135 -0
- package/dist/chunk-X3CL6DTR.js +95 -0
- package/dist/chunk-X6WF7JEV.js +354 -0
- package/dist/chunk-XAHGBPWT.js +44 -0
- package/dist/chunk-XCKQ5BM2.js +228 -0
- package/dist/chunk-XIBYREEY.js +106 -0
- package/dist/chunk-XKW5NDMR.js +378 -0
- package/dist/chunk-XRDALAO3.js +100 -0
- package/dist/chunk-XUP22EAS.js +41 -0
- package/dist/chunk-XWAC3MKW.js +243 -0
- package/dist/chunk-Y3R7JMXB.js +59 -0
- package/dist/chunk-Y54LTP4W.js +82 -0
- package/dist/chunk-Y7UECI4M.js +99 -0
- package/dist/chunk-YACGDFHC.js +47 -0
- package/dist/chunk-YHNIQPKY.js +71 -0
- package/dist/chunk-YMBR6HYP.js +111 -0
- package/dist/chunk-YMCH3L2S.js +26 -0
- package/dist/chunk-Z4ZU6T7V.js +99 -0
- package/dist/chunk-ZDPF67ZZ.js +173 -0
- package/dist/chunk-ZFC2Q67K.js +101 -0
- package/dist/chunk-ZGHNNSCT.js +114 -0
- package/dist/chunk-ZGX3ERAT.js +173 -0
- package/dist/chunk-ZI3YHEBY.js +37 -0
- package/dist/chunk-ZN7G6JLS.js +639 -0
- package/dist/chunk-ZNPFQMXT.js +47 -0
- package/dist/chunk-ZOU3LV4U.js +63 -0
- package/dist/chunk-ZT7B4H2V.js +117 -0
- package/dist/chunk-ZZCBDNZI.js +58 -0
- package/dist/cli.js +498 -112593
- package/dist/computer-tools.js +36642 -21258
- package/dist/harness-catalog.cjs +88 -43
- package/dist/index.js +1 -1
- package/dist/local-model-supervisor.cjs +555 -0
- package/package.json +3 -4
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/local-models/supervisor.ts
|
|
26
|
+
var import_node_child_process = __toESM(require("node:child_process"), 1);
|
|
27
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
28
|
+
var import_node_http = __toESM(require("node:http"), 1);
|
|
29
|
+
var import_node_os = __toESM(require("node:os"), 1);
|
|
30
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
31
|
+
|
|
32
|
+
// src/local-models/memwatch.ts
|
|
33
|
+
function memoryStep(input) {
|
|
34
|
+
const SUSTAIN_MS = 6e3;
|
|
35
|
+
const CRITICAL_MS = 2e3;
|
|
36
|
+
const SETTLE_MS = 1e4;
|
|
37
|
+
const BUSY_GRACE_MS = 12e3;
|
|
38
|
+
const SWAP_OUT_PAGES_PER_SECOND = 256;
|
|
39
|
+
const PRESSURE_PERCENT = 1;
|
|
40
|
+
const gb2 = (bytes) => `${(bytes / 1e9).toFixed(1)} GB`;
|
|
41
|
+
const sample = input.sample;
|
|
42
|
+
const previous = input.state;
|
|
43
|
+
const spareBytes = sample.availableBytes - sample.ourFileBytes;
|
|
44
|
+
const othersBytes = Math.max(0, sample.totalBytes - sample.availableBytes - sample.ourAnonBytes);
|
|
45
|
+
let swapOutPerSecond = 0;
|
|
46
|
+
if (typeof sample.swapOutPages === "number" && typeof previous.lastSwapOut === "number" && typeof previous.lastAt === "number" && sample.at > previous.lastAt) {
|
|
47
|
+
swapOutPerSecond = Math.max(0, sample.swapOutPages - previous.lastSwapOut) / ((sample.at - previous.lastAt) / 1e3);
|
|
48
|
+
}
|
|
49
|
+
const state = { lastAt: sample.at };
|
|
50
|
+
if (typeof sample.swapOutPages === "number") state.lastSwapOut = sample.swapOutPages;
|
|
51
|
+
if (previous.lastActionAt !== void 0) state.lastActionAt = previous.lastActionAt;
|
|
52
|
+
const base = { state, spareBytes, othersBytes, swapOutPerSecond };
|
|
53
|
+
const deficit = input.bufferBytes - spareBytes;
|
|
54
|
+
const swapping = swapOutPerSecond >= SWAP_OUT_PAGES_PER_SECOND;
|
|
55
|
+
const pressureGuard = input.bufferBytes + Math.min(1024 ** 3, input.bufferBytes * 0.25);
|
|
56
|
+
const pressure = ((sample.pressureSomeAvg10 ?? 0) >= PRESSURE_PERCENT || swapping) && spareBytes < pressureGuard;
|
|
57
|
+
if (deficit <= 0 && !pressure) return { ...base, level: "ok", action: "none" };
|
|
58
|
+
const critical = spareBytes < input.bufferBytes / 2 || swapping || pressure;
|
|
59
|
+
const level = critical ? "critical" : "low";
|
|
60
|
+
state.lowSince = previous.lowSince ?? sample.at;
|
|
61
|
+
const lowFor = sample.at - state.lowSince;
|
|
62
|
+
const settling = previous.lastActionAt !== void 0 && sample.at - previous.lastActionAt < SETTLE_MS;
|
|
63
|
+
if (settling && !critical) return { ...base, level, action: "none" };
|
|
64
|
+
if (!swapping && lowFor < (critical ? CRITICAL_MS : SUSTAIN_MS)) return { ...base, level, action: "none" };
|
|
65
|
+
if (!critical && input.busy && lowFor < BUSY_GRACE_MS) {
|
|
66
|
+
return { ...base, level, action: "wait", reason: "a request is running" };
|
|
67
|
+
}
|
|
68
|
+
const why = (pressure ? `${swapping ? `swapping out ${Math.round(swapOutPerSecond)} pages/s` : `memory stalls ${sample.pressureSomeAvg10?.toFixed(1)}%`} with ${gb2(Math.max(0, spareBytes))} left for other programs, approaching the ${gb2(input.bufferBytes)} buffer` : `only ${gb2(Math.max(0, spareBytes))} was left for other programs, under the ${gb2(input.bufferBytes)} buffer`) + ` (they hold ${gb2(othersBytes)}${swapping ? ", and the machine is swapping" : ""})`;
|
|
69
|
+
const wanted = (pressure ? pressureGuard - spareBytes : deficit) + input.bufferBytes / 4;
|
|
70
|
+
state.lastActionAt = sample.at;
|
|
71
|
+
delete state.lowSince;
|
|
72
|
+
for (let index = 0; index < input.shrinks.length; index++) {
|
|
73
|
+
const option = input.shrinks[index];
|
|
74
|
+
if (option.freesBytes >= wanted) {
|
|
75
|
+
return {
|
|
76
|
+
...base,
|
|
77
|
+
level,
|
|
78
|
+
action: "shrink",
|
|
79
|
+
shrinkIndex: index,
|
|
80
|
+
reason: `${why}; restarting at ${Math.round(option.context / 1024)}K context without the prompt cache frees about ${gb2(option.freesBytes)}`
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { ...base, level, action: "stop", reason: `${why}; no smaller setting of this model frees the ${gb2(wanted)} needed` };
|
|
85
|
+
}
|
|
86
|
+
function parseMeminfo(text) {
|
|
87
|
+
const field = (name) => {
|
|
88
|
+
const match = new RegExp(`^${name}:\\s+(\\d+)\\s*kB`, "m").exec(text);
|
|
89
|
+
return match ? Number(match[1]) * 1024 : void 0;
|
|
90
|
+
};
|
|
91
|
+
const free = field("MemFree");
|
|
92
|
+
const cached = field("Cached");
|
|
93
|
+
const available = field("MemAvailable") ?? (free !== void 0 && cached !== void 0 ? free + cached + (field("Buffers") ?? 0) : void 0);
|
|
94
|
+
const total = field("MemTotal");
|
|
95
|
+
return { ...total !== void 0 ? { totalBytes: total } : {}, ...available !== void 0 ? { availableBytes: available } : {} };
|
|
96
|
+
}
|
|
97
|
+
function parseVmstatSwapOut(text) {
|
|
98
|
+
const match = /^pswpout\s+(\d+)/m.exec(text);
|
|
99
|
+
return match ? Number(match[1]) : void 0;
|
|
100
|
+
}
|
|
101
|
+
function parseMemoryPressure(text) {
|
|
102
|
+
const match = /^some\s+avg10=([\d.]+)/m.exec(text);
|
|
103
|
+
return match ? Number(match[1]) : void 0;
|
|
104
|
+
}
|
|
105
|
+
function parseProcStatus(text) {
|
|
106
|
+
const field = (name) => {
|
|
107
|
+
const match = new RegExp(`^${name}:\\s+(\\d+)\\s*kB`, "m").exec(text);
|
|
108
|
+
return match ? Number(match[1]) * 1024 : 0;
|
|
109
|
+
};
|
|
110
|
+
return { anonBytes: field("RssAnon"), fileBytes: field("RssFile") };
|
|
111
|
+
}
|
|
112
|
+
function parseVmStatMac(text) {
|
|
113
|
+
const pageSize = Number(/page size of (\d+) bytes/.exec(text)?.[1] ?? 4096);
|
|
114
|
+
const pages = (label) => Number(new RegExp(`^Pages ${label}:\\s+(\\d+)`, "m").exec(text)?.[1] ?? 0);
|
|
115
|
+
const total = pages("free") + pages("inactive") + pages("speculative") + pages("purgeable");
|
|
116
|
+
const swapouts = /^Swapouts:\s+(\d+)/m.exec(text);
|
|
117
|
+
return { ...total > 0 ? { availableBytes: total * pageSize } : {}, ...swapouts ? { swapOutPages: Number(swapouts[1]) } : {} };
|
|
118
|
+
}
|
|
119
|
+
function mergeFootprint(previous, next) {
|
|
120
|
+
if (!previous || previous.mmap !== next.mmap) return next;
|
|
121
|
+
return { ...next, anonBytes: Math.max(previous.anonBytes, next.anonBytes), fileBytes: Math.max(previous.fileBytes, next.fileBytes) };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/agent/computer/shared-state.ts
|
|
125
|
+
function sharedState(key, make) {
|
|
126
|
+
const holder = globalThis;
|
|
127
|
+
const name = `__clikcode_${key}`;
|
|
128
|
+
return holder[name] ??= make();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/agent/computer/secret-scrubber.ts
|
|
132
|
+
var live = sharedState("secrets-live", () => /* @__PURE__ */ new Map());
|
|
133
|
+
var refs = sharedState("secret-refs", () => ({ byValue: /* @__PURE__ */ new Map(), byNumber: /* @__PURE__ */ new Map() }));
|
|
134
|
+
|
|
135
|
+
// src/runtime/secret-shapes.ts
|
|
136
|
+
var SECRET_SHAPES = [
|
|
137
|
+
/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY-----|$)/g,
|
|
138
|
+
// OpenAI, Anthropic, OpenRouter and most `sk-` style keys.
|
|
139
|
+
/\b(?:sk|pk|rk)-(?:ant-|proj-|or-)?[A-Za-z0-9_-]{16,}/g,
|
|
140
|
+
// GitHub tokens.
|
|
141
|
+
/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})/g,
|
|
142
|
+
// Slack, Stripe, Google, AWS, Hugging Face, npm, GitLab.
|
|
143
|
+
/\bxox[abprs]-[A-Za-z0-9-]{10,}/g,
|
|
144
|
+
/\b(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{16,}/g,
|
|
145
|
+
/\bAIza[0-9A-Za-z_-]{30,}/g,
|
|
146
|
+
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
147
|
+
/\bhf_[A-Za-z0-9]{20,}/g,
|
|
148
|
+
/\bnpm_[A-Za-z0-9]{30,}/g,
|
|
149
|
+
/\bglpat-[A-Za-z0-9_-]{16,}/g,
|
|
150
|
+
// A JWT: three base64url parts, the first an encoded `{"`.
|
|
151
|
+
/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
// src/runtime/redact.ts
|
|
155
|
+
var LOG_SHAPES = [
|
|
156
|
+
...SECRET_SHAPES,
|
|
157
|
+
/\b(?:Bearer|Basic)\s+[\w.=+/-]{12,}/gi,
|
|
158
|
+
/\b((?:api[_-]?key|token|secret|password|passwd|authorization)["']?\s*[=:]\s*["']?)[^\s"']{8,}/gi,
|
|
159
|
+
/(:\/\/[^\s/:@]+:)[^\s/@]+@/g
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
// src/runtime/lifecycle-log.ts
|
|
163
|
+
var ROTATE_BYTES = 10 * 1024 * 1024;
|
|
164
|
+
|
|
165
|
+
// src/session/store/locks.ts
|
|
166
|
+
function pidIsAlive(pid) {
|
|
167
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
168
|
+
try {
|
|
169
|
+
process.kill(pid, 0);
|
|
170
|
+
return true;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return error.code === "EPERM";
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
var LOCK_TUNING = {
|
|
176
|
+
/** A lock whose file has not been refreshed for this long is stale. */
|
|
177
|
+
staleMs: 3e4,
|
|
178
|
+
/** A lock file with no readable owner is stale this soon. A lock is
|
|
179
|
+
* created with its owner already in it (createLock), so only an older
|
|
180
|
+
* build -- open, then write -- shows one empty, for the moment between
|
|
181
|
+
* the two steps; one that stays empty was left by a process killed
|
|
182
|
+
* there, and waiting staleMs on it stood a VS Code send 30 s. */
|
|
183
|
+
ownerlessStaleMs: 1e3,
|
|
184
|
+
/** A holder refreshes its lock file's mtime this often... */
|
|
185
|
+
heartbeatMs: 1e4,
|
|
186
|
+
/** ...for at most this long. A holder stuck past it stops refreshing, and
|
|
187
|
+
* is broken staleMs later rather than stalling every ClikCode forever. */
|
|
188
|
+
maxHoldMs: 5 * 6e4,
|
|
189
|
+
/** A waiter behind a live holder never gives up (a holder that is alive and
|
|
190
|
+
* heartbeating is only slow, and a stuck one is broken by maxHoldMs +
|
|
191
|
+
* staleMs); it records a 'lock.wait' event this often so the wait is
|
|
192
|
+
* visible. It never proceeds unlocked. */
|
|
193
|
+
waitNoticeMs: 1e4
|
|
194
|
+
};
|
|
195
|
+
var STATE_LOCK_HELD = Object.freeze({});
|
|
196
|
+
|
|
197
|
+
// src/local-models/supervisor.ts
|
|
198
|
+
var config = JSON.parse(import_node_fs.default.readFileSync(process.argv[2], "utf8"));
|
|
199
|
+
var memory = config.memory;
|
|
200
|
+
var leases = import_node_path.default.join(config.dir, "leases");
|
|
201
|
+
var recordFile = import_node_path.default.join(config.dir, "supervisor.json");
|
|
202
|
+
var WINDOWS = process.platform === "win32";
|
|
203
|
+
var note = (text) => {
|
|
204
|
+
try {
|
|
205
|
+
import_node_fs.default.appendFileSync(import_node_path.default.join(config.dir, "supervisor.log"), `${(/* @__PURE__ */ new Date()).toISOString()} ${text}
|
|
206
|
+
`);
|
|
207
|
+
} catch {
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var gb = (bytes) => `${(bytes / 1e9).toFixed(1)} GB`;
|
|
211
|
+
function liveLeases() {
|
|
212
|
+
let names;
|
|
213
|
+
try {
|
|
214
|
+
names = import_node_fs.default.readdirSync(leases);
|
|
215
|
+
} catch {
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
let count = 0;
|
|
219
|
+
for (const name of names) {
|
|
220
|
+
if (!name.endsWith(".json")) continue;
|
|
221
|
+
if (pidIsAlive(Number(name.split("-")[0]))) count++;
|
|
222
|
+
else {
|
|
223
|
+
try {
|
|
224
|
+
import_node_fs.default.rmSync(import_node_path.default.join(leases, name), { force: true });
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return count;
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
import_node_os.default.setPriority(0, import_node_os.default.constants.priority.PRIORITY_BELOW_NORMAL);
|
|
233
|
+
} catch {
|
|
234
|
+
}
|
|
235
|
+
var LOG_LIMIT = 5 * 1024 * 1024;
|
|
236
|
+
var serverLog = import_node_path.default.join(config.dir, "server.log");
|
|
237
|
+
var supervisorLog = import_node_path.default.join(config.dir, "supervisor.log");
|
|
238
|
+
function rotateLogs(fd) {
|
|
239
|
+
try {
|
|
240
|
+
if (fd === void 0) {
|
|
241
|
+
if (import_node_fs.default.statSync(serverLog).size > LOG_LIMIT) import_node_fs.default.renameSync(serverLog, `${serverLog}.1`);
|
|
242
|
+
} else if (import_node_fs.default.fstatSync(fd).size > LOG_LIMIT) {
|
|
243
|
+
import_node_fs.default.copyFileSync(serverLog, `${serverLog}.1`);
|
|
244
|
+
import_node_fs.default.ftruncateSync(fd, 0);
|
|
245
|
+
}
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
if (import_node_fs.default.statSync(supervisorLog).size > LOG_LIMIT) import_node_fs.default.renameSync(supervisorLog, `${supervisorLog}.1`);
|
|
250
|
+
} catch {
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
rotateLogs();
|
|
254
|
+
var log = import_node_fs.default.openSync(serverLog, "a");
|
|
255
|
+
setInterval(() => rotateLogs(log), config.logCheckMs || 6e4).unref();
|
|
256
|
+
var record = {
|
|
257
|
+
supervisorPid: process.pid,
|
|
258
|
+
serverPid: 0,
|
|
259
|
+
port: config.port,
|
|
260
|
+
modelId: config.modelId,
|
|
261
|
+
alias: config.alias,
|
|
262
|
+
context: config.context,
|
|
263
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
264
|
+
};
|
|
265
|
+
var writeRecord = () => import_node_fs.default.writeFileSync(recordFile, JSON.stringify(record));
|
|
266
|
+
var child;
|
|
267
|
+
var stopping = false;
|
|
268
|
+
var restartArgs = null;
|
|
269
|
+
function launch(args) {
|
|
270
|
+
const self = import_node_child_process.default.spawn(config.command, args, {
|
|
271
|
+
cwd: config.dir,
|
|
272
|
+
env: { ...process.env, ...config.env },
|
|
273
|
+
stdio: ["ignore", log, log],
|
|
274
|
+
windowsHide: true
|
|
275
|
+
});
|
|
276
|
+
child = self;
|
|
277
|
+
try {
|
|
278
|
+
if (self.pid !== void 0) import_node_os.default.setPriority(self.pid, import_node_os.default.constants.priority.PRIORITY_BELOW_NORMAL);
|
|
279
|
+
} catch {
|
|
280
|
+
}
|
|
281
|
+
record.serverPid = self.pid ?? 0;
|
|
282
|
+
delete record.restarting;
|
|
283
|
+
writeRecord();
|
|
284
|
+
note(`started llama-server pid ${self.pid} on port ${config.port} at ${Math.round(record.context / 1024)}K context`);
|
|
285
|
+
self.on("exit", (code, signal) => {
|
|
286
|
+
if (self !== child || stopping) return;
|
|
287
|
+
if (restartArgs) {
|
|
288
|
+
const next = restartArgs;
|
|
289
|
+
restartArgs = null;
|
|
290
|
+
launch(next);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
stopping = true;
|
|
294
|
+
finish(`llama-server exited (${code !== null ? code : signal})`);
|
|
295
|
+
});
|
|
296
|
+
self.on("error", (error) => {
|
|
297
|
+
if (self !== child || stopping) return;
|
|
298
|
+
stopping = true;
|
|
299
|
+
finish(`llama-server could not start: ${error.message}`);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
function killChild(target) {
|
|
303
|
+
if (WINDOWS) import_node_child_process.default.spawnSync("taskkill", ["/PID", String(target.pid), "/T", "/F"], { windowsHide: true });
|
|
304
|
+
else {
|
|
305
|
+
try {
|
|
306
|
+
target.kill("SIGTERM");
|
|
307
|
+
} catch {
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function finish(reason) {
|
|
312
|
+
writeFootprint();
|
|
313
|
+
note(`stopped: ${reason}`);
|
|
314
|
+
try {
|
|
315
|
+
const current2 = JSON.parse(import_node_fs.default.readFileSync(recordFile, "utf8"));
|
|
316
|
+
if (current2.supervisorPid === process.pid) import_node_fs.default.rmSync(recordFile, { force: true });
|
|
317
|
+
} catch {
|
|
318
|
+
}
|
|
319
|
+
process.exit(0);
|
|
320
|
+
}
|
|
321
|
+
function stop(reason) {
|
|
322
|
+
if (stopping) return;
|
|
323
|
+
stopping = true;
|
|
324
|
+
const running = child;
|
|
325
|
+
if (running.exitCode !== null || running.signalCode !== null) finish(reason);
|
|
326
|
+
killChild(running);
|
|
327
|
+
const deadline = Date.now() + 1e4;
|
|
328
|
+
const wait = setInterval(() => {
|
|
329
|
+
if (running.exitCode !== null || running.signalCode !== null || !pidIsAlive(running.pid ?? 0)) {
|
|
330
|
+
clearInterval(wait);
|
|
331
|
+
finish(reason);
|
|
332
|
+
} else if (Date.now() > deadline) {
|
|
333
|
+
try {
|
|
334
|
+
running.kill("SIGKILL");
|
|
335
|
+
} catch {
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}, 200);
|
|
339
|
+
}
|
|
340
|
+
for (const signal of ["SIGTERM", "SIGINT", "SIGHUP"]) {
|
|
341
|
+
try {
|
|
342
|
+
process.on(signal, () => stop(`signal ${signal}`));
|
|
343
|
+
} catch {
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function slots() {
|
|
347
|
+
return new Promise((resolve) => {
|
|
348
|
+
const request = import_node_http.default.get({ host: "127.0.0.1", port: config.port, path: "/slots", timeout: 5e3 }, (response) => {
|
|
349
|
+
let text = "";
|
|
350
|
+
response.on("data", (chunk) => {
|
|
351
|
+
text += chunk;
|
|
352
|
+
});
|
|
353
|
+
response.on("end", () => {
|
|
354
|
+
try {
|
|
355
|
+
resolve(JSON.parse(text));
|
|
356
|
+
} catch {
|
|
357
|
+
resolve(void 0);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
request.on("timeout", () => request.destroy());
|
|
362
|
+
request.on("error", () => resolve(void 0));
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
var current = memory ? memory.current : null;
|
|
366
|
+
var shrinks = memory ? memory.shrinks : [];
|
|
367
|
+
var watch = {};
|
|
368
|
+
var healthy = false;
|
|
369
|
+
var busy = false;
|
|
370
|
+
var baseline = null;
|
|
371
|
+
var lastLog = "";
|
|
372
|
+
var lastStatusAt = 0;
|
|
373
|
+
var peak = { anon: 0, file: 0 };
|
|
374
|
+
var written = 0;
|
|
375
|
+
var read = (file) => {
|
|
376
|
+
try {
|
|
377
|
+
return import_node_fs.default.readFileSync(file, "utf8");
|
|
378
|
+
} catch {
|
|
379
|
+
return "";
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
function sampleMemory(pid) {
|
|
383
|
+
const at = Date.now();
|
|
384
|
+
if (process.platform === "linux") {
|
|
385
|
+
const mem = parseMeminfo(read("/proc/meminfo"));
|
|
386
|
+
if (!mem.totalBytes || mem.availableBytes === void 0) return void 0;
|
|
387
|
+
const own = parseProcStatus(read(`/proc/${pid}/status`));
|
|
388
|
+
const swapOutPages = parseVmstatSwapOut(read("/proc/vmstat"));
|
|
389
|
+
const pressureSomeAvg10 = parseMemoryPressure(read("/proc/pressure/memory"));
|
|
390
|
+
return {
|
|
391
|
+
at,
|
|
392
|
+
totalBytes: mem.totalBytes,
|
|
393
|
+
availableBytes: mem.availableBytes,
|
|
394
|
+
ourAnonBytes: own.anonBytes,
|
|
395
|
+
ourFileBytes: memory.mmap ? own.fileBytes : 0,
|
|
396
|
+
...swapOutPages === void 0 ? {} : { swapOutPages },
|
|
397
|
+
...pressureSomeAvg10 === void 0 ? {} : { pressureSomeAvg10 }
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
if (process.platform === "darwin") {
|
|
401
|
+
let vm = {};
|
|
402
|
+
let rss = 0;
|
|
403
|
+
try {
|
|
404
|
+
vm = parseVmStatMac(import_node_child_process.default.execFileSync("vm_stat", { encoding: "utf8", timeout: 3e3 }));
|
|
405
|
+
} catch {
|
|
406
|
+
}
|
|
407
|
+
try {
|
|
408
|
+
rss = Number(import_node_child_process.default.execFileSync("ps", ["-o", "rss=", "-p", String(pid)], { encoding: "utf8", timeout: 3e3 }).trim()) * 1024 || 0;
|
|
409
|
+
} catch {
|
|
410
|
+
}
|
|
411
|
+
if (vm.availableBytes === void 0) return void 0;
|
|
412
|
+
return {
|
|
413
|
+
at,
|
|
414
|
+
totalBytes: import_node_os.default.totalmem(),
|
|
415
|
+
availableBytes: vm.availableBytes,
|
|
416
|
+
ourAnonBytes: rss,
|
|
417
|
+
ourFileBytes: 0,
|
|
418
|
+
...vm.swapOutPages === void 0 ? {} : { swapOutPages: vm.swapOutPages }
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
return { at, totalBytes: import_node_os.default.totalmem(), availableBytes: import_node_os.default.freemem(), ourAnonBytes: 0, ourFileBytes: 0 };
|
|
422
|
+
}
|
|
423
|
+
function writeFootprint() {
|
|
424
|
+
if (!memory || !current || !(peak.anon > 0)) return;
|
|
425
|
+
if (peak.anon + peak.file <= written) return;
|
|
426
|
+
try {
|
|
427
|
+
let store = {};
|
|
428
|
+
try {
|
|
429
|
+
store = JSON.parse(import_node_fs.default.readFileSync(memory.footprintsFile, "utf8"));
|
|
430
|
+
} catch {
|
|
431
|
+
}
|
|
432
|
+
const machine = store[memory.machine] ?? (store[memory.machine] = {});
|
|
433
|
+
machine[current.footprintKey] = mergeFootprint(machine[current.footprintKey], {
|
|
434
|
+
context: current.context,
|
|
435
|
+
cacheType: memory.cacheType,
|
|
436
|
+
parallel: memory.parallel,
|
|
437
|
+
vision: memory.vision,
|
|
438
|
+
anonBytes: peak.anon,
|
|
439
|
+
fileBytes: peak.file,
|
|
440
|
+
mmap: Boolean(memory.mmap),
|
|
441
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
442
|
+
});
|
|
443
|
+
const temporary = `${memory.footprintsFile}.${process.pid}.tmp`;
|
|
444
|
+
import_node_fs.default.writeFileSync(temporary, JSON.stringify(store, null, 2));
|
|
445
|
+
import_node_fs.default.renameSync(temporary, memory.footprintsFile);
|
|
446
|
+
written = peak.anon + peak.file;
|
|
447
|
+
} catch (error) {
|
|
448
|
+
note(`footprint not recorded: ${error.message}`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function shrinkTo(option, reason) {
|
|
452
|
+
writeFootprint();
|
|
453
|
+
const event = { at: (/* @__PURE__ */ new Date()).toISOString(), action: "shrink", modelId: config.modelId, fromContext: record.context, toContext: option.context, reason };
|
|
454
|
+
current = option;
|
|
455
|
+
healthy = false;
|
|
456
|
+
baseline = null;
|
|
457
|
+
peak = { anon: 0, file: 0 };
|
|
458
|
+
written = 0;
|
|
459
|
+
restartArgs = option.args;
|
|
460
|
+
record.context = option.context;
|
|
461
|
+
record.restarting = true;
|
|
462
|
+
record.memoryEvent = event;
|
|
463
|
+
writeRecord();
|
|
464
|
+
note(`restarting llama-server at ${Math.round(option.context / 1024)}K context, prompt cache ${option.cacheRamMib} MiB`);
|
|
465
|
+
const target = child;
|
|
466
|
+
killChild(target);
|
|
467
|
+
setTimeout(() => {
|
|
468
|
+
if (target === child && pidIsAlive(target.pid ?? 0)) {
|
|
469
|
+
try {
|
|
470
|
+
target.kill("SIGKILL");
|
|
471
|
+
} catch {
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}, 1e4);
|
|
475
|
+
}
|
|
476
|
+
function memoryTick() {
|
|
477
|
+
if (stopping || restartArgs || !memory || !child || !current) return;
|
|
478
|
+
const sample = sampleMemory(child.pid ?? 0);
|
|
479
|
+
if (!sample) return;
|
|
480
|
+
if (!healthy) return;
|
|
481
|
+
if (baseline === null) baseline = sample.ourAnonBytes;
|
|
482
|
+
peak = { anon: Math.max(peak.anon, sample.ourAnonBytes), file: Math.max(peak.file, sample.ourFileBytes) };
|
|
483
|
+
if (peak.anon + peak.file > written + 64 * 1024 * 1024) writeFootprint();
|
|
484
|
+
const growth = Math.max(0, sample.ourAnonBytes - baseline);
|
|
485
|
+
const now = current;
|
|
486
|
+
const options = shrinks.map((option) => ({
|
|
487
|
+
context: option.context,
|
|
488
|
+
freesBytes: Math.max(0, now.kvBytes - option.kvBytes) + (now.cacheRamMib > option.cacheRamMib ? growth : 0)
|
|
489
|
+
}));
|
|
490
|
+
const decision = memoryStep({ sample, state: watch, bufferBytes: memory.bufferBytes, busy, shrinks: options });
|
|
491
|
+
watch = decision.state;
|
|
492
|
+
const summary = `memory ${decision.level}: ${gb(decision.spareBytes)} spare (buffer ${gb(memory.bufferBytes)}), others hold ${gb(decision.othersBytes)}, model ${gb(sample.ourAnonBytes)}${memory.mmap ? ` own + ${gb(sample.ourFileBytes)} mapped weights` : ""}` + (sample.pressureSomeAvg10 ? `, memory stalls ${sample.pressureSomeAvg10.toFixed(1)}%` : "") + (decision.swapOutPerSecond ? `, swapping out ${Math.round(decision.swapOutPerSecond)} pages/s` : "");
|
|
493
|
+
const key = `${decision.level} ${decision.action}`;
|
|
494
|
+
if (key !== lastLog || decision.action === "shrink" || decision.action === "stop" || sample.at - lastStatusAt > 3e5) {
|
|
495
|
+
note(summary + (decision.action !== "none" ? ` -> ${decision.action}${decision.reason ? `: ${decision.reason}` : ""}` : ""));
|
|
496
|
+
lastLog = key;
|
|
497
|
+
lastStatusAt = sample.at;
|
|
498
|
+
}
|
|
499
|
+
if (decision.action === "shrink") {
|
|
500
|
+
const option = shrinks[decision.shrinkIndex];
|
|
501
|
+
shrinks = shrinks.slice(decision.shrinkIndex + 1);
|
|
502
|
+
shrinkTo(option, decision.reason);
|
|
503
|
+
} else if (decision.action === "stop") {
|
|
504
|
+
const event = { at: (/* @__PURE__ */ new Date()).toISOString(), action: "stop", modelId: config.modelId, fromContext: record.context, reason: decision.reason };
|
|
505
|
+
try {
|
|
506
|
+
import_node_fs.default.writeFileSync(import_node_path.default.join(config.dir, "memory-stop.json"), JSON.stringify(event));
|
|
507
|
+
} catch (error) {
|
|
508
|
+
note(`memory stop not recorded: ${error.message}`);
|
|
509
|
+
}
|
|
510
|
+
stop(`to leave memory for other programs: ${decision.reason}`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
var LEASE_GRACE_MS = config.leaseGraceMs || 1e4;
|
|
514
|
+
var lastActive = Date.now();
|
|
515
|
+
var lastSignature = "";
|
|
516
|
+
var leaselessSince;
|
|
517
|
+
async function tick() {
|
|
518
|
+
if (stopping) return;
|
|
519
|
+
if (liveLeases() === 0) {
|
|
520
|
+
leaselessSince ??= Date.now();
|
|
521
|
+
if (Date.now() - leaselessSince >= LEASE_GRACE_MS) {
|
|
522
|
+
stop("no live ClikCode process holds a lease");
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
} else leaselessSince = void 0;
|
|
526
|
+
if (restartArgs) {
|
|
527
|
+
lastActive = Date.now();
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const list = await slots();
|
|
531
|
+
if (Array.isArray(list)) {
|
|
532
|
+
if (!healthy) {
|
|
533
|
+
healthy = true;
|
|
534
|
+
if (watch.lastActionAt !== void 0) watch.lastActionAt = Date.now();
|
|
535
|
+
}
|
|
536
|
+
busy = list.some((slot) => slot.is_processing);
|
|
537
|
+
const signature = JSON.stringify(list.map((slot) => [slot.id, slot.id_task, slot.is_processing]));
|
|
538
|
+
if (signature !== lastSignature || busy) lastActive = Date.now();
|
|
539
|
+
lastSignature = signature;
|
|
540
|
+
} else {
|
|
541
|
+
lastActive = Date.now();
|
|
542
|
+
}
|
|
543
|
+
if (config.idleMs > 0 && Date.now() - lastActive > config.idleMs) stop(`idle for ${Math.round(config.idleMs / 1e3)} s`);
|
|
544
|
+
}
|
|
545
|
+
launch(config.args);
|
|
546
|
+
setInterval(() => {
|
|
547
|
+
tick().catch((error) => note(`tick failed: ${error.message}`));
|
|
548
|
+
}, config.pollMs);
|
|
549
|
+
if (memory) setInterval(() => {
|
|
550
|
+
try {
|
|
551
|
+
memoryTick();
|
|
552
|
+
} catch (error) {
|
|
553
|
+
note(`memory check failed: ${error.message}`);
|
|
554
|
+
}
|
|
555
|
+
}, memory.sampleMs);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clikcode",
|
|
3
3
|
"//version": "MAJOR.MINOR only: ClikDeploy computes the patch and stamps the full version into its own build copy before `npm publish`, so the patch digit here is ignored. Bump the minor (or major) here for a release line; never the patch.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"description": "The harness that logs in all your favorite AI coding providers, in the terminal and in VS Code. Chats you can resume in any of them, and automatic account switching when you hit a usage limit.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
"build": "node scripts/build.mjs",
|
|
17
17
|
"install-local": "node scripts/install-local.mjs",
|
|
18
18
|
"build:analyze": "node scripts/build.mjs --analyze",
|
|
19
|
-
"build:
|
|
20
|
-
"
|
|
21
|
-
"type-check": "tsc --noEmit -p tsconfig.json && pnpm --filter @clikcode/router type-check",
|
|
19
|
+
"build:chat-client": "node scripts/build-chat-client.mjs",
|
|
20
|
+
"type-check": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.browser-tests.json && pnpm --filter @clikcode/router type-check",
|
|
22
21
|
"test": "vitest run",
|
|
23
22
|
"test:router": "pnpm --filter @clikcode/router test",
|
|
24
23
|
"test:all": "pnpm run test && pnpm run test:router",
|