dsh-mcviseron-plugin 0.7.3 → 0.7.8

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/lib/index.js CHANGED
@@ -11295,6 +11295,9 @@ var SESSION_END_API = {
11295
11295
  var AUTH_COOKIE_API = {
11296
11296
  prune: "/api/dsh-mcviseron/auth-cookies/prune"
11297
11297
  };
11298
+ var ARCHIVE_API = {
11299
+ status: "/api/dsh-mcviseron/archive-integration/status"
11300
+ };
11298
11301
 
11299
11302
  // src/namespace.ts
11300
11303
  var MCVISERON_SETTINGS_NAMESPACE = "mcviseron";
@@ -11569,15 +11572,103 @@ function apply(ctx, _config) {
11569
11572
  });
11570
11573
  }
11571
11574
 
11575
+ // src/archive-integration/index.ts
11576
+ var archive_integration_exports = {};
11577
+ __export(archive_integration_exports, {
11578
+ apply: () => apply2,
11579
+ inject: () => inject2,
11580
+ makeArchiveStatus: () => makeArchiveStatus
11581
+ });
11582
+ import { existsSync, readFileSync } from "node:fs";
11583
+ import { homedir } from "node:os";
11584
+ import { join } from "node:path";
11585
+ function dshHome() {
11586
+ const raw = process.env.DSH_HOME;
11587
+ if (raw !== void 0 && raw.trim() !== "") return raw.trim().startsWith("~") ? join(homedir(), raw.trim().slice(1).replace(/^[\\/]/, "")) : raw.trim();
11588
+ return join(homedir(), ".dsh");
11589
+ }
11590
+ function archiveAvailable(ctx) {
11591
+ try {
11592
+ const loader = ctx.loader;
11593
+ for (const entry of loader?.entries?.() ?? []) {
11594
+ const name = String(entry.options?.name ?? "");
11595
+ if (name.includes("session-archive") && entry.disabled !== true && entry.fiber !== void 0 && entry.fiber !== null) return true;
11596
+ }
11597
+ } catch {
11598
+ }
11599
+ return false;
11600
+ }
11601
+ function archivedIds(ctx) {
11602
+ try {
11603
+ const registry = ctx.get?.("workspaceRegistry");
11604
+ const value = registry?.archivedSessionIds;
11605
+ return Array.isArray(value) ? value.filter((id) => typeof id === "string" && id.length > 0) : [];
11606
+ } catch {
11607
+ return [];
11608
+ }
11609
+ }
11610
+ function makeArchiveStatus(ctx) {
11611
+ const available = archiveAvailable(ctx);
11612
+ const ledgerPath = join(dshHome(), "dsh-session-archive", "archive-ledger.json");
11613
+ let ledger;
11614
+ try {
11615
+ ledger = JSON.parse(readFileSync(ledgerPath, "utf8"));
11616
+ } catch {
11617
+ ledger = void 0;
11618
+ }
11619
+ const entries = ledger?.entries !== null && typeof ledger?.entries === "object" ? ledger.entries : {};
11620
+ const ids = archivedIds(ctx);
11621
+ let observed = 0;
11622
+ let manual = 0;
11623
+ for (const entry of Object.values(entries)) {
11624
+ if (entry.source === "observed") observed++;
11625
+ else if (entry.source === "manual") manual++;
11626
+ }
11627
+ let unknown = 0;
11628
+ for (const id of ids) if (entries[id] === void 0) unknown++;
11629
+ return {
11630
+ ok: true,
11631
+ available,
11632
+ ledgerPath,
11633
+ ledgerExists: existsSync(ledgerPath),
11634
+ entries: Object.keys(entries).length,
11635
+ observed,
11636
+ manual,
11637
+ archivedCount: ids.length,
11638
+ unknownCount: unknown
11639
+ };
11640
+ }
11641
+ var inject2 = ["webServer"];
11642
+ function apply2(ctx) {
11643
+ ctx.effect(() => ctx.webServer.register({
11644
+ kind: "exact",
11645
+ path: ARCHIVE_API.status,
11646
+ handler: async (req, res) => {
11647
+ const send = (status, value) => {
11648
+ res.statusCode = status;
11649
+ res.setHeader("content-type", "application/json; charset=utf-8");
11650
+ res.end(JSON.stringify(value));
11651
+ };
11652
+ if (req.method !== "GET" && req.method !== "POST") return send(405, { ok: false, error: "method-not-allowed" });
11653
+ if (!isLoopbackRequest(req)) return send(403, { ok: false, error: "forbidden" });
11654
+ try {
11655
+ send(200, makeArchiveStatus(ctx));
11656
+ } catch (error) {
11657
+ send(500, { ok: false, error: error instanceof Error ? error.message : String(error) });
11658
+ }
11659
+ }
11660
+ }), "mcviseron: archive integration status");
11661
+ }
11662
+
11572
11663
  // src/auth-cookie/index.ts
11573
11664
  var auth_cookie_exports = {};
11574
11665
  __export(auth_cookie_exports, {
11575
11666
  AUTH_COOKIE_PREFIX: () => AUTH_COOKIE_PREFIX,
11576
- apply: () => apply2,
11667
+ apply: () => apply3,
11577
11668
  authCookieName: () => authCookieName,
11578
11669
  authCookieNames: () => authCookieNames,
11579
11670
  expiredAuthCookie: () => expiredAuthCookie,
11580
- inject: () => inject2,
11671
+ inject: () => inject3,
11581
11672
  makeAuthCookieRoutes: () => makeAuthCookieRoutes,
11582
11673
  pruneCookieHeaders: () => pruneCookieHeaders,
11583
11674
  pruneScript: () => pruneScript,
@@ -11587,13 +11678,13 @@ __export(auth_cookie_exports, {
11587
11678
  import { createHash } from "node:crypto";
11588
11679
  import { appendFileSync } from "node:fs";
11589
11680
  import { tmpdir } from "node:os";
11590
- import { join } from "node:path";
11681
+ import { join as join2 } from "node:path";
11591
11682
  var AUTH_COOKIE_PREFIX = "dsh-auth-";
11592
11683
  var EXPIRED_AT = "Thu, 01 Jan 1970 00:00:00 GMT";
11593
11684
  function logPrune(authority, pruned) {
11594
11685
  try {
11595
11686
  appendFileSync(
11596
- join(tmpdir(), "dsh-mcviseron-auth-cookie.log"),
11687
+ join2(tmpdir(), "dsh-mcviseron-auth-cookie.log"),
11597
11688
  (/* @__PURE__ */ new Date()).toISOString() + " pruned=" + pruned + " authority=" + authority + "\n",
11598
11689
  "utf8"
11599
11690
  );
@@ -11696,8 +11787,8 @@ function installIndexInjection(ctx) {
11696
11787
  } catch {
11697
11788
  }
11698
11789
  }
11699
- var inject2 = ["webServer"];
11700
- function apply2(ctx) {
11790
+ var inject3 = ["webServer"];
11791
+ function apply3(ctx) {
11701
11792
  const secure = () => {
11702
11793
  try {
11703
11794
  return ctx.webServer.protocol === "https:";
@@ -11718,12 +11809,12 @@ function apply2(ctx) {
11718
11809
  // src/automation-tasks/index.ts
11719
11810
  var automation_tasks_exports = {};
11720
11811
  __export(automation_tasks_exports, {
11721
- apply: () => apply3,
11812
+ apply: () => apply4,
11722
11813
  makeAutomationTaskTools: () => makeAutomationTaskTools
11723
11814
  });
11724
11815
  import { appendFileSync as appendFileSync2 } from "node:fs";
11725
11816
  import { tmpdir as tmpdir2 } from "node:os";
11726
- import { join as join2 } from "node:path";
11817
+ import { join as join3 } from "node:path";
11727
11818
  var OUTPUT_SCHEMA = { type: "object", additionalProperties: true };
11728
11819
  var SELECTOR_KEYS = ["after_seconds", "at", "every_seconds", "daily", "weekly", "cron"];
11729
11820
  function output() {
@@ -11734,10 +11825,23 @@ function output() {
11734
11825
  }
11735
11826
  function log(message) {
11736
11827
  try {
11737
- appendFileSync2(join2(tmpdir2(), "dsh-mcviseron-automation-tasks.log"), (/* @__PURE__ */ new Date()).toISOString() + " " + message + "\n", "utf8");
11828
+ appendFileSync2(join3(tmpdir2(), "dsh-mcviseron-automation-tasks.log"), (/* @__PURE__ */ new Date()).toISOString() + " " + message + "\n", "utf8");
11738
11829
  } catch {
11739
11830
  }
11740
11831
  }
11832
+ function isModernSchedule(schedule) {
11833
+ return typeof schedule.edit === "function";
11834
+ }
11835
+ function modernTiming(args) {
11836
+ if (args.after_seconds !== void 0) return { kind: "after", after_seconds: args.after_seconds };
11837
+ if (args.at !== void 0) return { kind: "at", at: args.at };
11838
+ if (args.every_seconds !== void 0) return { kind: "every", every_seconds: args.every_seconds };
11839
+ if (args.daily !== void 0) return { kind: "daily", daily: args.daily };
11840
+ if (args.weekly !== void 0) return { kind: "weekly", weekly: args.weekly };
11841
+ if (args.cron !== void 0) return { kind: "cron", cron: args.cron };
11842
+ if (args.rrule !== void 0) return { kind: "rrule", rrule: args.rrule };
11843
+ return void 0;
11844
+ }
11741
11845
  function listRecords(result) {
11742
11846
  return Array.isArray(result) ? result : result.items;
11743
11847
  }
@@ -11860,7 +11964,7 @@ function makeAutomationTaskTools(schedule) {
11860
11964
  const sessionId = sessionIdOf(exec);
11861
11965
  if (sessionId === "") return { ok: false, code: "no_session", error: "no current session" };
11862
11966
  try {
11863
- return { ok: true, tasks: listRecords(await schedule.list({ sessionId })) };
11967
+ return { ok: true, tasks: listRecords(await schedule.list(isModernSchedule(schedule) ? {} : { sessionId })) };
11864
11968
  } catch (error) {
11865
11969
  return serviceFailure(error);
11866
11970
  }
@@ -11877,11 +11981,23 @@ function makeAutomationTaskTools(schedule) {
11877
11981
  const invalidInput = validateCreate(args);
11878
11982
  if (invalidInput !== void 0) return invalid(invalidInput);
11879
11983
  try {
11880
- const record2 = await schedule.create(sessionId, {
11881
- ...args,
11882
- title: String(args.title).trim(),
11883
- prompt: String(args.prompt).trim()
11884
- }, exec.signal);
11984
+ let record2;
11985
+ if (isModernSchedule(schedule)) {
11986
+ const timing = modernTiming(args);
11987
+ if (timing === void 0) return invalid("timing is required");
11988
+ record2 = await schedule.create({
11989
+ title: String(args.title).trim(),
11990
+ prompt: String(args.prompt).trim(),
11991
+ timing,
11992
+ target: { kind: "session", sessionId }
11993
+ }, sessionId, exec.signal);
11994
+ } else {
11995
+ record2 = await schedule.create(sessionId, {
11996
+ ...args,
11997
+ title: String(args.title).trim(),
11998
+ prompt: String(args.prompt).trim()
11999
+ }, exec.signal);
12000
+ }
11885
12001
  return { ok: true, task: record2 };
11886
12002
  } catch (error) {
11887
12003
  return serviceFailure(error);
@@ -11900,9 +12016,18 @@ function makeAutomationTaskTools(schedule) {
11900
12016
  if (invalidInput !== void 0) return invalid(invalidInput);
11901
12017
  try {
11902
12018
  const id = String(args.id);
11903
- const expected = listRecords(await schedule.list({ sessionId })).find((record2) => record2.id === id);
11904
- if (expected === void 0) return { ok: false, code: "schedule_not_found", error: "automation task not found in this session: " + id };
12019
+ const expected = listRecords(await schedule.list(isModernSchedule(schedule) ? {} : { sessionId })).find((record2) => record2.id === id);
12020
+ if (expected === void 0) return { ok: false, code: "schedule_not_found", error: "automation task not found: " + id };
11905
12021
  const change = timingChange(args);
12022
+ if (isModernSchedule(schedule)) {
12023
+ const patch = {};
12024
+ if (args.title !== void 0) patch.title = String(args.title).trim();
12025
+ if (args.prompt !== void 0) patch.prompt = String(args.prompt).trim();
12026
+ const timing = modernTiming(args);
12027
+ if (timing !== void 0) patch.timing = timing;
12028
+ const result2 = await schedule.edit({ id, action: "update", patch }, sessionId, exec.signal);
12029
+ return { ok: true, task: result2 };
12030
+ }
11906
12031
  const result = await schedule.update({
11907
12032
  sessionId,
11908
12033
  id,
@@ -11930,6 +12055,10 @@ function makeAutomationTaskTools(schedule) {
11930
12055
  return invalid("id must be a non-empty string without surrounding whitespace");
11931
12056
  }
11932
12057
  try {
12058
+ if (isModernSchedule(schedule)) {
12059
+ const result2 = await schedule.edit({ id: String(args.id), action: "delete" }, sessionId, exec.signal);
12060
+ return { ok: true, ...result2 };
12061
+ }
11933
12062
  const result = await schedule.delete({ sessionId, id: String(args.id) }, exec.signal);
11934
12063
  return { ok: true, ...result };
11935
12064
  } catch (error) {
@@ -11948,11 +12077,11 @@ function serviceOf(scope, name) {
11948
12077
  return void 0;
11949
12078
  }
11950
12079
  }
11951
- function apply3(ctx) {
11952
- const inject5 = ctx.inject;
11953
- if (typeof inject5 !== "function") return;
12080
+ function apply4(ctx) {
12081
+ const inject6 = ctx.inject;
12082
+ if (typeof inject6 !== "function") return;
11954
12083
  try {
11955
- inject5.call(ctx, ["tools", "schedule"], (scope) => {
12084
+ inject6.call(ctx, ["tools", "schedule"], (scope) => {
11956
12085
  const tools = serviceOf(scope, "tools");
11957
12086
  const schedule = serviceOf(scope, "schedule");
11958
12087
  if (tools === void 0 || typeof tools.register !== "function" || schedule === void 0) {
@@ -11983,7 +12112,7 @@ function apply3(ctx) {
11983
12112
  log("tool injection failed: " + (error instanceof Error ? error.message : String(error)));
11984
12113
  }
11985
12114
  try {
11986
- inject5.call(ctx, ["systemPrompt"], (scope) => {
12115
+ inject6.call(ctx, ["systemPrompt"], (scope) => {
11987
12116
  const systemPrompt = serviceOf(scope, "systemPrompt");
11988
12117
  if (typeof systemPrompt?.section === "function") {
11989
12118
  systemPrompt.section({
@@ -12007,7 +12136,7 @@ var auto_review_fix_exports = {};
12007
12136
  __export(auto_review_fix_exports, {
12008
12137
  Config: () => Config2,
12009
12138
  DEFAULT_AUTO_REVIEW_CONFIG: () => DEFAULT_AUTO_REVIEW_CONFIG,
12010
- apply: () => apply4
12139
+ apply: () => apply5
12011
12140
  });
12012
12141
  import z2 from "@deepseek-ai/schemastery";
12013
12142
 
@@ -12017,7 +12146,7 @@ import { randomUUID } from "node:crypto";
12017
12146
  // src/components/auto-review-fix/review-context.ts
12018
12147
  import { appendFileSync as appendFileSync3 } from "node:fs";
12019
12148
  import { tmpdir as tmpdir3 } from "node:os";
12020
- import { join as join3 } from "node:path";
12149
+ import { join as join4 } from "node:path";
12021
12150
  var REVIEW_MARKER = "REVIEW_POLICY";
12022
12151
  var REVIEW_MARKER_2 = "final authorization reviewer";
12023
12152
  var HISTORY_HEADER = "FILTERED_HISTORY\n\n";
@@ -12038,7 +12167,7 @@ function textOf(message) {
12038
12167
  }
12039
12168
  return texts.join("");
12040
12169
  }
12041
- function isAutoReviewRequest(options) {
12170
+ function isLegacyAutoReviewRequest(options) {
12042
12171
  if (!record(options)) return false;
12043
12172
  const system = options.system;
12044
12173
  if (typeof system !== "string" || !system.includes(REVIEW_MARKER) || !system.includes(REVIEW_MARKER_2)) return false;
@@ -12129,7 +12258,7 @@ function parseArray(text3) {
12129
12258
  function logTrim(originalChars, nextChars, originalEntries, nextEntries) {
12130
12259
  try {
12131
12260
  appendFileSync3(
12132
- join3(tmpdir3(), "dsh-mcviseron-auto-review.log"),
12261
+ join4(tmpdir3(), "dsh-mcviseron-auto-review.log"),
12133
12262
  (/* @__PURE__ */ new Date()).toISOString() + " review context trimmed: " + String(originalChars) + " -> " + String(nextChars) + " chars, history " + String(originalEntries) + " -> " + String(nextEntries) + "\n",
12134
12263
  "utf8"
12135
12264
  );
@@ -12137,7 +12266,9 @@ function logTrim(originalChars, nextChars, originalEntries, nextEntries) {
12137
12266
  }
12138
12267
  }
12139
12268
  function trimReviewRequest(options, settings) {
12140
- if (!settings.enabled || !isAutoReviewRequest(options)) return options;
12269
+ if (!settings.enabled) return options;
12270
+ if (isModernAutoReviewRequest(options)) return trimModernReviewRequest(options, settings);
12271
+ if (!isLegacyAutoReviewRequest(options)) return options;
12141
12272
  const messages = options.messages;
12142
12273
  const message = messages[0];
12143
12274
  const text3 = textOf(message);
@@ -12165,12 +12296,139 @@ function trimReviewRequest(options, settings) {
12165
12296
  ]
12166
12297
  };
12167
12298
  }
12299
+ var MODERN_PURPOSE = "auto-review";
12300
+ var ENVIRONMENT_HEADER = "ENVIRONMENT\n";
12301
+ var MODERN_USER_ROLES = /* @__PURE__ */ new Set(["user-instruction", "direct-parent-instruction", "constraint", "checkpoint", "human-instruction"]);
12302
+ var MODERN_USER_TEXT_CHARS = 8e3;
12303
+ var MODERN_TOOL_ARGUMENT_CHARS = 4e3;
12304
+ var MODERN_SCHEMA_DESCRIPTION_CHARS = 4e3;
12305
+ var MODERN_SCHEMA_PARAMETER_CHARS = 12e3;
12306
+ function isModernAutoReviewRequest(options) {
12307
+ if (!record(options) || options.purpose !== MODERN_PURPOSE) return false;
12308
+ if (typeof options.system !== "string" || !options.system.includes(REVIEW_MARKER) || !options.system.includes(REVIEW_MARKER_2)) return false;
12309
+ if (!Array.isArray(options.messages) || options.messages.length < 2) return false;
12310
+ const first = textOf(options.messages[0]);
12311
+ return first !== void 0 && first.startsWith(ENVIRONMENT_HEADER);
12312
+ }
12313
+ function modernRole(entry) {
12314
+ return record(entry) && typeof entry.role === "string" ? entry.role : void 0;
12315
+ }
12316
+ function modernProtected(entry, index, lastIndex, schemaIndexes) {
12317
+ if (index === lastIndex) return true;
12318
+ const role = modernRole(entry);
12319
+ if (role !== void 0 && MODERN_USER_ROLES.has(role)) return true;
12320
+ return schemaIndexes.has(index);
12321
+ }
12322
+ function compactModernContent(content, textLimit) {
12323
+ if (!Array.isArray(content)) return [];
12324
+ return content.map((block) => {
12325
+ if (!record(block)) return { type: "text", text: "[non-text history block omitted from reviewer context]" };
12326
+ if (block.type === "text" && typeof block.text === "string") {
12327
+ return { ...block, text: truncateText(block.text, textLimit) };
12328
+ }
12329
+ return { type: "text", text: "[" + String(block.type ?? "attachment") + " omitted from reviewer context]" };
12330
+ });
12331
+ }
12332
+ function compactModernEntry(entry, pending) {
12333
+ if (!record(entry)) return { kind: "summary", role: "fact", content: [{ type: "text", text: "[invalid history entry omitted]" }] };
12334
+ if (pending) return entry;
12335
+ if (entry.kind === "user-message") {
12336
+ return { ...entry, content: compactModernContent(entry.content, MODERN_USER_TEXT_CHARS) };
12337
+ }
12338
+ if (entry.kind === "tool-call") {
12339
+ if (typeof entry.arguments === "string") {
12340
+ return { ...entry, arguments: truncateText(entry.arguments, MODERN_TOOL_ARGUMENT_CHARS) };
12341
+ }
12342
+ if (entry.arguments !== void 0) {
12343
+ let rendered = "";
12344
+ try {
12345
+ rendered = JSON.stringify(entry.arguments) ?? "";
12346
+ } catch {
12347
+ rendered = "";
12348
+ }
12349
+ return { ...entry, arguments: truncateText(rendered, MODERN_TOOL_ARGUMENT_CHARS) };
12350
+ }
12351
+ }
12352
+ if (entry.kind === "tool-schema") {
12353
+ const description = typeof entry.description === "string" ? truncateText(entry.description, MODERN_SCHEMA_DESCRIPTION_CHARS) : entry.description;
12354
+ let parameters = entry.parameters;
12355
+ if (parameters !== void 0) {
12356
+ try {
12357
+ const rendered = JSON.stringify(parameters) ?? "";
12358
+ if (rendered.length > MODERN_SCHEMA_PARAMETER_CHARS) parameters = truncateText(rendered, MODERN_SCHEMA_PARAMETER_CHARS);
12359
+ } catch {
12360
+ parameters = "[unserializable schema parameters omitted]";
12361
+ }
12362
+ }
12363
+ return { ...entry, description, parameters };
12364
+ }
12365
+ return entry;
12366
+ }
12367
+ function modernSchemaIndexes(entries) {
12368
+ const indexes = /* @__PURE__ */ new Map();
12369
+ entries.forEach((entry, index) => {
12370
+ if (!record(entry) || entry.kind !== "tool-schema") return;
12371
+ indexes.set(String(entry.mode) + "\0" + String(entry.name), index);
12372
+ });
12373
+ return new Set(indexes.values());
12374
+ }
12375
+ function trimModernReviewRequest(options, settings) {
12376
+ const messages = options.messages;
12377
+ const first = textOf(messages[0]);
12378
+ if (first === void 0 || !first.startsWith(ENVIRONMENT_HEADER)) return options;
12379
+ const entries = [];
12380
+ for (const message of messages.slice(1)) {
12381
+ const text3 = textOf(message);
12382
+ if (text3 === void 0) return options;
12383
+ try {
12384
+ entries.push(JSON.parse(text3));
12385
+ } catch {
12386
+ return options;
12387
+ }
12388
+ }
12389
+ if (entries.length === 0) return options;
12390
+ const lastIndex = entries.length - 1;
12391
+ const schemaIndexes = modernSchemaIndexes(entries);
12392
+ const recentStart = Math.max(0, entries.length - Math.max(1, settings.keepRecentEntries));
12393
+ const selected = [];
12394
+ for (let index = 0; index < entries.length; index += 1) {
12395
+ if (index >= recentStart || modernProtected(entries[index], index, lastIndex, schemaIndexes)) selected.push(index);
12396
+ }
12397
+ let omitted = entries.length - selected.length;
12398
+ const compacted = selected.map((index) => compactModernEntry(entries[index], index === lastIndex));
12399
+ while (selected.length > 2 && jsonLength(compacted) > settings.maxHistoryChars) {
12400
+ let at = selected.findIndex((index, position) => index !== lastIndex && position < selected.length - 1 && !modernProtected(entries[index], index, lastIndex, schemaIndexes));
12401
+ if (at < 0) at = selected.findIndex((index, position) => index !== lastIndex && position < selected.length - 1);
12402
+ if (at < 0) break;
12403
+ selected.splice(at, 1);
12404
+ compacted.splice(at, 1);
12405
+ omitted += 1;
12406
+ }
12407
+ const summary = {
12408
+ kind: "summary",
12409
+ role: "fact",
12410
+ content: [{
12411
+ type: "text",
12412
+ text: "[auto-review-fix] " + String(omitted) + " earlier history entries omitted from the reviewer context (original history " + String(jsonLength(entries)) + " chars). Current action, instructions and recent context are retained."
12413
+ }]
12414
+ };
12415
+ const nextMessages = [messages[0]];
12416
+ if (omitted > 0) nextMessages.push({ role: "user", content: [{ type: "text", text: JSON.stringify(summary) }] });
12417
+ selected.forEach((originalIndex, position) => {
12418
+ const original = messages[originalIndex + 1];
12419
+ if (originalIndex === lastIndex) nextMessages.push(original);
12420
+ else nextMessages.push({ ...original, content: [{ type: "text", text: JSON.stringify(compacted[position]) }] });
12421
+ });
12422
+ if (jsonLength(nextMessages) >= jsonLength(messages)) return options;
12423
+ logTrim(jsonLength(messages), jsonLength(nextMessages), entries.length, selected.length);
12424
+ return { ...options, messages: nextMessages };
12425
+ }
12168
12426
  var guardedLlms = /* @__PURE__ */ new WeakMap();
12169
12427
  function whenService(ctx, name, run) {
12170
12428
  try {
12171
- const inject5 = ctx.inject;
12172
- if (typeof inject5 === "function") {
12173
- inject5.call(ctx, [name], run);
12429
+ const inject6 = ctx.inject;
12430
+ if (typeof inject6 === "function") {
12431
+ inject6.call(ctx, [name], run);
12174
12432
  return;
12175
12433
  }
12176
12434
  const get = ctx.get;
@@ -12401,16 +12659,16 @@ function normalizeConfig(config) {
12401
12659
  model: stringSetting(source, "translateModel", ""),
12402
12660
  reviewContext: {
12403
12661
  enabled: boolSetting(source, "reviewContextGuard", true),
12404
- maxHistoryChars: numberSetting(source, "reviewMaxHistoryChars", 12e4, 2e4, 6e5),
12405
- keepRecentEntries: numberSetting(source, "reviewKeepRecentEntries", 16, 4, 64)
12662
+ maxHistoryChars: numberSetting(source, "reviewMaxHistoryChars", 2e5, 2e4, 6e5),
12663
+ keepRecentEntries: numberSetting(source, "reviewKeepRecentEntries", 32, 4, 64)
12406
12664
  }
12407
12665
  };
12408
12666
  }
12409
12667
  function whenService2(ctx, name, run) {
12410
12668
  try {
12411
- const inject5 = ctx.inject;
12412
- if (typeof inject5 === "function") {
12413
- inject5.call(ctx, [name], run);
12669
+ const inject6 = ctx.inject;
12670
+ if (typeof inject6 === "function") {
12671
+ inject6.call(ctx, [name], run);
12414
12672
  return;
12415
12673
  }
12416
12674
  const get = ctx.get;
@@ -12652,8 +12910,8 @@ var DEFAULT_AUTO_REVIEW_CONFIG = {
12652
12910
  translateProvider: "",
12653
12911
  translateModel: "",
12654
12912
  reviewContextGuard: true,
12655
- reviewMaxHistoryChars: 12e4,
12656
- reviewKeepRecentEntries: 16
12913
+ reviewMaxHistoryChars: 2e5,
12914
+ reviewKeepRecentEntries: 32
12657
12915
  };
12658
12916
  var Config2 = z2.object({
12659
12917
  keepPresetGuard: z2.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.keepPresetGuard).volatile(),
@@ -12666,7 +12924,7 @@ var Config2 = z2.object({
12666
12924
  reviewMaxHistoryChars: z2.number().min(2e4).max(6e5).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewMaxHistoryChars).volatile(),
12667
12925
  reviewKeepRecentEntries: z2.number().min(4).max(64).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewKeepRecentEntries).volatile()
12668
12926
  }).default(DEFAULT_AUTO_REVIEW_CONFIG);
12669
- function apply4(ctx, config) {
12927
+ function apply5(ctx, config) {
12670
12928
  installAutoReview(ctx, toPlain(config));
12671
12929
  }
12672
12930
 
@@ -12676,19 +12934,19 @@ __export(restart_exports, {
12676
12934
  Config: () => Config3,
12677
12935
  DEFAULT_RESTART_CONFIG: () => DEFAULT_RESTART_CONFIG,
12678
12936
  RESTART_API: () => RESTART_API,
12679
- apply: () => apply5,
12937
+ apply: () => apply6,
12680
12938
  closeDesktop: () => closeDesktop,
12681
12939
  deriveDesktopAppPath: () => deriveDesktopAppPath,
12682
- inject: () => inject3,
12940
+ inject: () => inject4,
12683
12941
  launchRestart: () => launchRestart,
12684
12942
  makeRestartRoutes: () => makeRestartRoutes,
12685
12943
  makeTaskScript: () => makeTaskScript,
12686
12944
  resolveRestartTarget: () => resolveRestartTarget
12687
12945
  });
12688
12946
  import { execFileSync } from "node:child_process";
12689
- import { appendFileSync as appendFileSync4, existsSync } from "node:fs";
12947
+ import { appendFileSync as appendFileSync4, existsSync as existsSync2 } from "node:fs";
12690
12948
  import { tmpdir as tmpdir4 } from "node:os";
12691
- import { basename, dirname, join as join4, resolve } from "node:path";
12949
+ import { basename, dirname, join as join5, resolve } from "node:path";
12692
12950
  import z3 from "@deepseek-ai/schemastery";
12693
12951
  var DEFAULT_RESTART_CONFIG = { enabled: true, appPath: "" };
12694
12952
  var Config3 = z3.object({
@@ -12717,13 +12975,13 @@ function deriveDesktopAppPath(execPath, argv, exists) {
12717
12975
  if (argv0 !== "" && argv0 !== execPath && !isNode(argv0) && exists(argv0)) return argv0;
12718
12976
  const runtimeDir = argv[2] ?? "";
12719
12977
  if (runtimeDir === "") return execPath;
12720
- const candidate = join4(resolve(runtimeDir, "../../.."), "DeepSeek Harness.exe");
12978
+ const candidate = join5(resolve(runtimeDir, "../../.."), "DeepSeek Harness.exe");
12721
12979
  return exists(candidate) ? candidate : execPath;
12722
12980
  }
12723
12981
  var RESTART_TASK_NAME = "DSH-MCviseron-Restart";
12724
12982
  var RESTART_DELAY_SECONDS = 6;
12725
12983
  function restartLogPath() {
12726
- return join4(tmpdir4(), "dsh-mcviseron-restart.log");
12984
+ return join5(tmpdir4(), "dsh-mcviseron-restart.log");
12727
12985
  }
12728
12986
  function makeTaskScript(target, taskName, delaySeconds) {
12729
12987
  const quote = (value) => "'" + value.replace(/'/g, "''") + "'";
@@ -12844,13 +13102,13 @@ function makeRestartRoutes(deps) {
12844
13102
  };
12845
13103
  return [status, execute];
12846
13104
  }
12847
- var inject3 = ["webServer"];
12848
- function apply5(ctx, config) {
13105
+ var inject4 = ["webServer"];
13106
+ function apply6(ctx, config) {
12849
13107
  const plain = toPlain(config) ?? {};
12850
13108
  if (plain.enabled === false) return;
12851
13109
  const appPath = typeof plain.appPath === "string" ? plain.appPath : "";
12852
13110
  const routes = makeRestartRoutes({
12853
- target: () => resolveRestartTarget(process.execPath, process.ppid, existsSync, appPath, process.argv),
13111
+ target: () => resolveRestartTarget(process.execPath, process.ppid, existsSync2, appPath, process.argv),
12854
13112
  launch: launchHelper
12855
13113
  });
12856
13114
  ctx.effect(() => {
@@ -12866,9 +13124,9 @@ var session_end_exports = {};
12866
13124
  __export(session_end_exports, {
12867
13125
  Config: () => Config4,
12868
13126
  DEFAULT_SESSION_END_CONFIG: () => DEFAULT_SESSION_END_CONFIG,
12869
- apply: () => apply6,
13127
+ apply: () => apply7,
12870
13128
  createSessionEndController: () => createSessionEndController,
12871
- inject: () => inject4,
13129
+ inject: () => inject5,
12872
13130
  inspectRunningTasks: () => inspectRunningTasks,
12873
13131
  isSessionEndMode: () => isSessionEndMode,
12874
13132
  makeSessionEndRoutes: () => makeSessionEndRoutes,
@@ -12876,9 +13134,9 @@ __export(session_end_exports, {
12876
13134
  shutdownComputer: () => shutdownComputer
12877
13135
  });
12878
13136
  import { execFileSync as execFileSync2 } from "node:child_process";
12879
- import { appendFileSync as appendFileSync5, existsSync as existsSync2 } from "node:fs";
13137
+ import { appendFileSync as appendFileSync5, existsSync as existsSync3 } from "node:fs";
12880
13138
  import { tmpdir as tmpdir5 } from "node:os";
12881
- import { join as join5 } from "node:path";
13139
+ import { join as join6 } from "node:path";
12882
13140
  import z4 from "@deepseek-ai/schemastery";
12883
13141
 
12884
13142
  // src/session-end/email.ts
@@ -13010,7 +13268,7 @@ function isSessionEndMode(value) {
13010
13268
  return value === "off" || value === "restart" || value === "close" || value === "shutdown";
13011
13269
  }
13012
13270
  function sessionLogPath() {
13013
- return join5(tmpdir5(), "dsh-mcviseron-session-end.log");
13271
+ return join6(tmpdir5(), "dsh-mcviseron-session-end.log");
13014
13272
  }
13015
13273
  function defaultLog(message) {
13016
13274
  try {
@@ -13081,7 +13339,7 @@ function createSessionEndController(deps = {}) {
13081
13339
  const resolveTarget = deps.resolveTarget ?? (() => resolveRestartTarget(
13082
13340
  process.execPath,
13083
13341
  process.ppid,
13084
- existsSync2,
13342
+ existsSync3,
13085
13343
  typeof deps.appPath === "string" ? deps.appPath : "",
13086
13344
  process.argv
13087
13345
  ));
@@ -13332,10 +13590,10 @@ function serviceOf4(ctx, name) {
13332
13590
  }
13333
13591
  }
13334
13592
  function installGuidance(ctx) {
13335
- const inject5 = ctx.inject;
13336
- if (typeof inject5 !== "function") return;
13593
+ const inject6 = ctx.inject;
13594
+ if (typeof inject6 !== "function") return;
13337
13595
  try {
13338
- inject5.call(ctx, ["systemPrompt"], (scope) => {
13596
+ inject6.call(ctx, ["systemPrompt"], (scope) => {
13339
13597
  const systemPrompt = serviceOf4(scope, "systemPrompt");
13340
13598
  if (systemPrompt === void 0 || typeof systemPrompt.section !== "function") return;
13341
13599
  try {
@@ -13354,10 +13612,10 @@ function installGuidance(ctx) {
13354
13612
  }
13355
13613
  var emailed = /* @__PURE__ */ new Map();
13356
13614
  function installAgentTool(ctx, controller, options, log2) {
13357
- const inject5 = ctx.inject;
13358
- if (typeof inject5 !== "function") return;
13615
+ const inject6 = ctx.inject;
13616
+ if (typeof inject6 !== "function") return;
13359
13617
  try {
13360
- inject5.call(ctx, ["tools"], (scope) => {
13618
+ inject6.call(ctx, ["tools"], (scope) => {
13361
13619
  const tools = serviceOf4(scope, "tools");
13362
13620
  if (tools === void 0 || typeof tools.register !== "function") return;
13363
13621
  const definition = {
@@ -13497,8 +13755,8 @@ function normalizeSessionEndOptions(input) {
13497
13755
  appPath: string("appPath", "")
13498
13756
  };
13499
13757
  }
13500
- var inject4 = ["webServer"];
13501
- function apply6(ctx, config) {
13758
+ var inject5 = ["webServer"];
13759
+ function apply7(ctx, config) {
13502
13760
  const options = normalizeSessionEndOptions(config);
13503
13761
  const log2 = defaultLog;
13504
13762
  const controller = createSessionEndController({
@@ -13544,7 +13802,7 @@ var task_guard_exports = {};
13544
13802
  __export(task_guard_exports, {
13545
13803
  Config: () => Config5,
13546
13804
  DEFAULT_TASK_GUARD_CONFIG: () => DEFAULT_TASK_GUARD_CONFIG,
13547
- apply: () => apply7
13805
+ apply: () => apply8
13548
13806
  });
13549
13807
  import z5 from "@deepseek-ai/schemastery";
13550
13808
 
@@ -14256,7 +14514,7 @@ var Config5 = z5.object({
14256
14514
  include: z5.array(z5.string()).default(DEFAULT_TASK_GUARD_CONFIG.include).volatile(),
14257
14515
  exclude: z5.array(z5.string()).default(DEFAULT_TASK_GUARD_CONFIG.exclude).volatile()
14258
14516
  }).default(DEFAULT_TASK_GUARD_CONFIG);
14259
- function apply7(ctx, config) {
14517
+ function apply8(ctx, config) {
14260
14518
  installTaskGuard(ctx, toPlain(config));
14261
14519
  }
14262
14520
 
@@ -14286,9 +14544,10 @@ function mount(ctx, component, config) {
14286
14544
  logger?.warn?.(new Error("mcviseron: cannot mount a component", { cause: error }));
14287
14545
  }
14288
14546
  }
14289
- function apply8(ctx, rawConfig) {
14547
+ function apply9(ctx, rawConfig) {
14290
14548
  const config = toPlain(rawConfig) ?? {};
14291
14549
  mount(ctx, automation_tasks_exports, {});
14550
+ mount(ctx, archive_integration_exports, {});
14292
14551
  mount(ctx, auth_cookie_exports, {});
14293
14552
  mount(ctx, appearance_exports, {
14294
14553
  enabled: config.enabled ?? DEFAULT_SCHEDULE_CONFIG.enabled,
@@ -14307,5 +14566,5 @@ function apply8(ctx, rawConfig) {
14307
14566
  }
14308
14567
  export {
14309
14568
  Config6 as Config,
14310
- apply8 as apply
14569
+ apply9 as apply
14311
14570
  };