@moonshot-ai/kimi-code 2.0.0 → 2.0.1
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/dist/main.mjs +9990 -7856
- package/dist/search-worker.mjs +103 -3
- package/package.json +7 -7
package/dist/search-worker.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import fs from "node:fs";
|
|
|
3
3
|
import path, { join, relative } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
6
|
-
import fs$1, { open, readFile, readdir, stat } from "node:fs/promises";
|
|
6
|
+
import fs$1, { open, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
7
7
|
import os from "node:os";
|
|
8
8
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
9
|
|
|
@@ -12401,6 +12401,7 @@ function analyzeWireLine(line) {
|
|
|
12401
12401
|
const TEXT_INDEX_NAME = "body";
|
|
12402
12402
|
const TRI_INDEX_NAME = "tri";
|
|
12403
12403
|
const WIRE_FILENAME = "wire.jsonl";
|
|
12404
|
+
const TEXT_BUILD_TMP_SUFFIX = ".tmpbuild";
|
|
12404
12405
|
const FILE_META_PREFIX = "\0meta\\file\\";
|
|
12405
12406
|
const SESSION_META_PREFIX = "\0meta\\session\\";
|
|
12406
12407
|
const STATS_KEY = "\0meta\\stats";
|
|
@@ -12423,6 +12424,7 @@ const SYNC_ROUND_TIME_BUDGET_MS = 3e4;
|
|
|
12423
12424
|
const SYNC_FAILURE_ESCALATION_LIMIT = 5;
|
|
12424
12425
|
const SESSION_SYNC_FAILURE_SKIP_LIMIT = 5;
|
|
12425
12426
|
const SESSION_SYNC_SKIP_COOLDOWN_MS = 3e5;
|
|
12427
|
+
const SYNC_SESSION_CAP_DEFAULT = 500;
|
|
12426
12428
|
const EMPTY_BUFFER = Buffer.alloc(0);
|
|
12427
12429
|
function syncBudgetExhausted(budget) {
|
|
12428
12430
|
return budget.bytesLeft <= 0 || Date.now() >= budget.deadline;
|
|
@@ -12441,6 +12443,44 @@ async function sessionDirectoryIdentity(dir) {
|
|
|
12441
12443
|
throw error;
|
|
12442
12444
|
}
|
|
12443
12445
|
}
|
|
12446
|
+
async function statMtimeMs(path) {
|
|
12447
|
+
try {
|
|
12448
|
+
return (await stat(path)).mtimeMs;
|
|
12449
|
+
} catch {
|
|
12450
|
+
return;
|
|
12451
|
+
}
|
|
12452
|
+
}
|
|
12453
|
+
async function probeSessionSource(dir) {
|
|
12454
|
+
let dirStat;
|
|
12455
|
+
try {
|
|
12456
|
+
dirStat = await stat(dir);
|
|
12457
|
+
} catch {
|
|
12458
|
+
return;
|
|
12459
|
+
}
|
|
12460
|
+
if (!dirStat.isDirectory()) return void 0;
|
|
12461
|
+
const agentsMtimeMs = await statMtimeMs(join(dir, "agents"));
|
|
12462
|
+
const stateMtimeMs = await statMtimeMs(join(dir, "state.json")) ?? await statMtimeMs(join(dir, "session-meta", "state.json"));
|
|
12463
|
+
return {
|
|
12464
|
+
dirMtimeMs: dirStat.mtimeMs,
|
|
12465
|
+
agentsMtimeMs,
|
|
12466
|
+
stateMtimeMs
|
|
12467
|
+
};
|
|
12468
|
+
}
|
|
12469
|
+
function formatSessionSourceProbe(probe) {
|
|
12470
|
+
return `${probe.dirMtimeMs}|${probe.agentsMtimeMs ?? "x"}|${probe.stateMtimeMs ?? "x"}`;
|
|
12471
|
+
}
|
|
12472
|
+
async function wireFileUnchanged(meta) {
|
|
12473
|
+
if (meta.mtimeMs === void 0) return false;
|
|
12474
|
+
let st;
|
|
12475
|
+
try {
|
|
12476
|
+
st = await stat(meta.path);
|
|
12477
|
+
} catch {
|
|
12478
|
+
return false;
|
|
12479
|
+
}
|
|
12480
|
+
if (st.size !== meta.size || st.mtimeMs !== meta.mtimeMs) return false;
|
|
12481
|
+
if (meta.ino !== void 0 && st.ino !== meta.ino) return false;
|
|
12482
|
+
return true;
|
|
12483
|
+
}
|
|
12444
12484
|
const querySourceChecks = {
|
|
12445
12485
|
running: false,
|
|
12446
12486
|
waiters: /* @__PURE__ */ new Set()
|
|
@@ -12581,6 +12621,7 @@ var SearchIndexCore = class {
|
|
|
12581
12621
|
syncRoundBytes = SYNC_ROUND_BYTE_BUDGET;
|
|
12582
12622
|
syncRoundMs = SYNC_ROUND_TIME_BUDGET_MS;
|
|
12583
12623
|
syncSkipCooldownMs = SESSION_SYNC_SKIP_COOLDOWN_MS;
|
|
12624
|
+
syncSessionCap = SYNC_SESSION_CAP_DEFAULT;
|
|
12584
12625
|
constructor(options) {
|
|
12585
12626
|
this.options = options;
|
|
12586
12627
|
}
|
|
@@ -12610,6 +12651,27 @@ var SearchIndexCore = class {
|
|
|
12610
12651
|
throw new GlobalSearchError("index_unavailable", "search service is disposed");
|
|
12611
12652
|
}
|
|
12612
12653
|
await this.publishDb(db, null);
|
|
12654
|
+
if (!db.readOnly) await this.cleanInterruptedTextBuilds();
|
|
12655
|
+
}
|
|
12656
|
+
async cleanInterruptedTextBuilds() {
|
|
12657
|
+
const entries = await readdir(this.indexDir, { withFileTypes: true }).catch(() => void 0);
|
|
12658
|
+
if (entries === void 0) return;
|
|
12659
|
+
for (const entry of entries) {
|
|
12660
|
+
if (!entry.isDirectory() || !entry.name.endsWith(TEXT_BUILD_TMP_SUFFIX)) continue;
|
|
12661
|
+
const path = join(this.indexDir, entry.name);
|
|
12662
|
+
try {
|
|
12663
|
+
await rm(path, {
|
|
12664
|
+
recursive: true,
|
|
12665
|
+
force: true
|
|
12666
|
+
});
|
|
12667
|
+
this.log.info("global search: removed an interrupted text-build leftover", { dir: path });
|
|
12668
|
+
} catch (error) {
|
|
12669
|
+
this.log.warn("global search: cannot remove an interrupted text-build leftover", {
|
|
12670
|
+
dir: path,
|
|
12671
|
+
error: errorMessage(error)
|
|
12672
|
+
});
|
|
12673
|
+
}
|
|
12674
|
+
}
|
|
12613
12675
|
}
|
|
12614
12676
|
tokenGeneration() {
|
|
12615
12677
|
return `${this.options.bootSalt}:${this.generation}`;
|
|
@@ -12822,6 +12884,7 @@ var SearchIndexCore = class {
|
|
|
12822
12884
|
deadline: Date.now() + this.syncRoundMs
|
|
12823
12885
|
};
|
|
12824
12886
|
let indexed = 0;
|
|
12887
|
+
let syncedFresh = 0;
|
|
12825
12888
|
let truncated = false;
|
|
12826
12889
|
let failures = 0;
|
|
12827
12890
|
for (const summary of sessions) {
|
|
@@ -12833,8 +12896,13 @@ var SearchIndexCore = class {
|
|
|
12833
12896
|
truncated = true;
|
|
12834
12897
|
break;
|
|
12835
12898
|
}
|
|
12899
|
+
if (syncedFresh >= this.syncSessionCap) {
|
|
12900
|
+
truncated = true;
|
|
12901
|
+
break;
|
|
12902
|
+
}
|
|
12836
12903
|
const result = await this.syncSession(db, summary, budget);
|
|
12837
12904
|
if (result === void 0) continue;
|
|
12905
|
+
if (result.skipped !== true) syncedFresh++;
|
|
12838
12906
|
if (result.truncated) truncated = true;
|
|
12839
12907
|
if (result.failed) {
|
|
12840
12908
|
const count = (this.sessionSyncFailures.get(summary.id) ?? 0) + 1;
|
|
@@ -12917,6 +12985,13 @@ var SearchIndexCore = class {
|
|
|
12917
12985
|
await db.del(SESSION_META_PREFIX + sessionId);
|
|
12918
12986
|
}
|
|
12919
12987
|
async syncSession(db, summary, budget) {
|
|
12988
|
+
const metaKey = SESSION_META_PREFIX + summary.id;
|
|
12989
|
+
const previous = db.get(metaKey);
|
|
12990
|
+
if (await this.sessionSourceUnchanged(db, summary, previous)) return {
|
|
12991
|
+
truncated: false,
|
|
12992
|
+
failed: false,
|
|
12993
|
+
skipped: true
|
|
12994
|
+
};
|
|
12920
12995
|
let identity;
|
|
12921
12996
|
try {
|
|
12922
12997
|
identity = await sessionDirectoryIdentity(summary.dir);
|
|
@@ -12932,8 +13007,6 @@ var SearchIndexCore = class {
|
|
|
12932
13007
|
return;
|
|
12933
13008
|
}
|
|
12934
13009
|
const title = await sessionDirectoryTitle(summary.dir, this.log);
|
|
12935
|
-
const metaKey = SESSION_META_PREFIX + summary.id;
|
|
12936
|
-
const previous = db.get(metaKey);
|
|
12937
13010
|
if (previous?.kind !== "sessionMeta" || previous.identity !== identity || previous.dir !== summary.dir) {
|
|
12938
13011
|
await this.deleteSessionDocs(db, summary.id);
|
|
12939
13012
|
if (previous !== void 0) this.syncReplaced = true;
|
|
@@ -12988,12 +13061,38 @@ var SearchIndexCore = class {
|
|
|
12988
13061
|
if (existing !== void 0) this.syncReplaced = true;
|
|
12989
13062
|
}
|
|
12990
13063
|
} else if (existing !== void 0) await db.del(titleKey);
|
|
13064
|
+
if (!truncated && !failed) await this.stampSessionSource(db, metaKey, meta, summary);
|
|
12991
13065
|
return {
|
|
12992
13066
|
truncated,
|
|
12993
13067
|
failed,
|
|
12994
13068
|
error
|
|
12995
13069
|
};
|
|
12996
13070
|
}
|
|
13071
|
+
async sessionSourceUnchanged(db, summary, previous) {
|
|
13072
|
+
if (previous?.kind !== "sessionMeta") return false;
|
|
13073
|
+
if (previous.dir !== summary.dir) return false;
|
|
13074
|
+
if (previous.sourceUpdatedAt !== summary.updatedAt) return false;
|
|
13075
|
+
if ((previous.title ?? "") !== (summary.title ?? "")) return false;
|
|
13076
|
+
const syncSource = previous.syncSource;
|
|
13077
|
+
if (syncSource === void 0) return false;
|
|
13078
|
+
const probe = await probeSessionSource(summary.dir);
|
|
13079
|
+
if (probe === void 0 || formatSessionSourceProbe(probe) !== syncSource) return false;
|
|
13080
|
+
for (const row of db.query({ key: { prefix: fileMetaPrefixFor(summary.id) } })) {
|
|
13081
|
+
const meta = row.value;
|
|
13082
|
+
if (meta.kind !== "fileMeta") continue;
|
|
13083
|
+
if (!await wireFileUnchanged(meta)) return false;
|
|
13084
|
+
}
|
|
13085
|
+
return true;
|
|
13086
|
+
}
|
|
13087
|
+
async stampSessionSource(db, metaKey, meta, summary) {
|
|
13088
|
+
const probe = await probeSessionSource(summary.dir);
|
|
13089
|
+
if (probe === void 0) return;
|
|
13090
|
+
await db.set(metaKey, {
|
|
13091
|
+
...meta,
|
|
13092
|
+
sourceUpdatedAt: summary.updatedAt,
|
|
13093
|
+
syncSource: formatSessionSourceProbe(probe)
|
|
13094
|
+
});
|
|
13095
|
+
}
|
|
12997
13096
|
async deleteFileDocs(db, meta) {
|
|
12998
13097
|
const prefix = `${meta.sessionId}/${meta.agentId}/${meta.source}:`;
|
|
12999
13098
|
for (const row of db.query({
|
|
@@ -13520,6 +13619,7 @@ const core = new SearchIndexCore({
|
|
|
13520
13619
|
});
|
|
13521
13620
|
}
|
|
13522
13621
|
});
|
|
13622
|
+
if (typeof data.syncSessionCap === "number") core.syncSessionCap = data.syncSessionCap;
|
|
13523
13623
|
function toErrorPayload(error) {
|
|
13524
13624
|
if (error instanceof GlobalSearchError) return {
|
|
13525
13625
|
message: error.message,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonshot-ai/kimi-code",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "The Starting Point for Next-Gen Agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Moonshot AI",
|
|
@@ -72,16 +72,16 @@
|
|
|
72
72
|
"zod": "^4.3.6",
|
|
73
73
|
"@moonshot-ai/acp-server": "^0.0.1",
|
|
74
74
|
"@moonshot-ai/agent-core-v2": "^0.4.3",
|
|
75
|
+
"@moonshot-ai/kap-server": "^0.2.3",
|
|
75
76
|
"@moonshot-ai/kimi-code-sdk": "^0.20.0",
|
|
76
77
|
"@moonshot-ai/kimi-code-oauth": "^0.4.0",
|
|
77
|
-
"@moonshot-ai/
|
|
78
|
-
"@moonshot-ai/kimi-telemetry": "^0.1.1",
|
|
79
|
-
"@moonshot-ai/migration-legacy": "^0.1.16",
|
|
78
|
+
"@moonshot-ai/kimi-telemetry": "^0.2.0",
|
|
80
79
|
"@moonshot-ai/minidb": "^0.2.0",
|
|
81
|
-
"@moonshot-ai/
|
|
80
|
+
"@moonshot-ai/migration-legacy": "^0.1.16",
|
|
81
|
+
"@moonshot-ai/pi-tui": "^0.84.5",
|
|
82
82
|
"@moonshot-ai/remote-control": "^0.0.0",
|
|
83
|
-
"@moonshot-ai/vis-
|
|
84
|
-
"@moonshot-ai/
|
|
83
|
+
"@moonshot-ai/vis-server": "^0.1.1",
|
|
84
|
+
"@moonshot-ai/vis-web": "0.1.1"
|
|
85
85
|
},
|
|
86
86
|
"engines": {
|
|
87
87
|
"node": ">=22.19.0"
|