dsh-mcviseron-plugin 0.6.8 → 0.7.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/CHANGELOG.md +14 -1
- package/README.en.md +10 -4
- package/README.md +12 -5
- package/docs/automation-task.md +1 -1
- package/docs/automation-tasks.md +48 -0
- package/docs/release.md +2 -2
- package/lib/index.js +451 -166
- package/package.json +24 -22
- package/src/automation-tasks/index.ts +337 -0
- package/src/index.ts +2 -0
package/lib/index.js
CHANGED
|
@@ -3194,7 +3194,7 @@ var require_punycode = __commonJS({
|
|
|
3194
3194
|
return result + encoded;
|
|
3195
3195
|
}
|
|
3196
3196
|
function ucs2decode(string) {
|
|
3197
|
-
const
|
|
3197
|
+
const output2 = [];
|
|
3198
3198
|
let counter = 0;
|
|
3199
3199
|
const length = string.length;
|
|
3200
3200
|
while (counter < length) {
|
|
@@ -3202,16 +3202,16 @@ var require_punycode = __commonJS({
|
|
|
3202
3202
|
if (value >= 55296 && value <= 56319 && counter < length) {
|
|
3203
3203
|
const extra = string.charCodeAt(counter++);
|
|
3204
3204
|
if ((extra & 64512) == 56320) {
|
|
3205
|
-
|
|
3205
|
+
output2.push(((value & 1023) << 10) + (extra & 1023) + 65536);
|
|
3206
3206
|
} else {
|
|
3207
|
-
|
|
3207
|
+
output2.push(value);
|
|
3208
3208
|
counter--;
|
|
3209
3209
|
}
|
|
3210
3210
|
} else {
|
|
3211
|
-
|
|
3211
|
+
output2.push(value);
|
|
3212
3212
|
}
|
|
3213
3213
|
}
|
|
3214
|
-
return
|
|
3214
|
+
return output2;
|
|
3215
3215
|
}
|
|
3216
3216
|
var ucs2encode = (codePoints) => String.fromCodePoint(...codePoints);
|
|
3217
3217
|
var basicToDigit = function(codePoint) {
|
|
@@ -3244,7 +3244,7 @@ var require_punycode = __commonJS({
|
|
|
3244
3244
|
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
|
3245
3245
|
};
|
|
3246
3246
|
var decode = function(input) {
|
|
3247
|
-
const
|
|
3247
|
+
const output2 = [];
|
|
3248
3248
|
const inputLength = input.length;
|
|
3249
3249
|
let i = 0;
|
|
3250
3250
|
let n = initialN;
|
|
@@ -3257,7 +3257,7 @@ var require_punycode = __commonJS({
|
|
|
3257
3257
|
if (input.charCodeAt(j) >= 128) {
|
|
3258
3258
|
error("not-basic");
|
|
3259
3259
|
}
|
|
3260
|
-
|
|
3260
|
+
output2.push(input.charCodeAt(j));
|
|
3261
3261
|
}
|
|
3262
3262
|
for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; ) {
|
|
3263
3263
|
const oldi = i;
|
|
@@ -3283,19 +3283,19 @@ var require_punycode = __commonJS({
|
|
|
3283
3283
|
}
|
|
3284
3284
|
w *= baseMinusT;
|
|
3285
3285
|
}
|
|
3286
|
-
const out =
|
|
3286
|
+
const out = output2.length + 1;
|
|
3287
3287
|
bias = adapt(i - oldi, out, oldi == 0);
|
|
3288
3288
|
if (floor(i / out) > maxInt - n) {
|
|
3289
3289
|
error("overflow");
|
|
3290
3290
|
}
|
|
3291
3291
|
n += floor(i / out);
|
|
3292
3292
|
i %= out;
|
|
3293
|
-
|
|
3293
|
+
output2.splice(i++, 0, n);
|
|
3294
3294
|
}
|
|
3295
|
-
return String.fromCodePoint(...
|
|
3295
|
+
return String.fromCodePoint(...output2);
|
|
3296
3296
|
};
|
|
3297
3297
|
var encode = function(input) {
|
|
3298
|
-
const
|
|
3298
|
+
const output2 = [];
|
|
3299
3299
|
input = ucs2decode(input);
|
|
3300
3300
|
const inputLength = input.length;
|
|
3301
3301
|
let n = initialN;
|
|
@@ -3303,13 +3303,13 @@ var require_punycode = __commonJS({
|
|
|
3303
3303
|
let bias = initialBias;
|
|
3304
3304
|
for (const currentValue of input) {
|
|
3305
3305
|
if (currentValue < 128) {
|
|
3306
|
-
|
|
3306
|
+
output2.push(stringFromCharCode(currentValue));
|
|
3307
3307
|
}
|
|
3308
3308
|
}
|
|
3309
|
-
const basicLength =
|
|
3309
|
+
const basicLength = output2.length;
|
|
3310
3310
|
let handledCPCount = basicLength;
|
|
3311
3311
|
if (basicLength) {
|
|
3312
|
-
|
|
3312
|
+
output2.push(delimiter);
|
|
3313
3313
|
}
|
|
3314
3314
|
while (handledCPCount < inputLength) {
|
|
3315
3315
|
let m = maxInt;
|
|
@@ -3337,10 +3337,10 @@ var require_punycode = __commonJS({
|
|
|
3337
3337
|
}
|
|
3338
3338
|
const qMinusT = q - t;
|
|
3339
3339
|
const baseMinusT = base - t;
|
|
3340
|
-
|
|
3340
|
+
output2.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
|
|
3341
3341
|
q = floor(qMinusT / baseMinusT);
|
|
3342
3342
|
}
|
|
3343
|
-
|
|
3343
|
+
output2.push(stringFromCharCode(digitToBasic(q, 0)));
|
|
3344
3344
|
bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
|
|
3345
3345
|
delta = 0;
|
|
3346
3346
|
++handledCPCount;
|
|
@@ -3349,7 +3349,7 @@ var require_punycode = __commonJS({
|
|
|
3349
3349
|
++delta;
|
|
3350
3350
|
++n;
|
|
3351
3351
|
}
|
|
3352
|
-
return
|
|
3352
|
+
return output2.join("");
|
|
3353
3353
|
};
|
|
3354
3354
|
var toUnicode = function(input) {
|
|
3355
3355
|
return mapDomain(input, function(string) {
|
|
@@ -5632,16 +5632,16 @@ var require_mail_composer = __commonJS({
|
|
|
5632
5632
|
* @returns {Array} An array of alternative elements. Includes the `text` and `html` values as well
|
|
5633
5633
|
*/
|
|
5634
5634
|
getAlternatives() {
|
|
5635
|
-
let alternatives = [],
|
|
5635
|
+
let alternatives = [], text3, html, watchHtml, amp, icalEvent, eventObject;
|
|
5636
5636
|
if (this.mail.text) {
|
|
5637
5637
|
if (typeof this.mail.text === "object" && (this.mail.text.content || this.mail.text.path || this.mail.text.href || this.mail.text.raw)) {
|
|
5638
|
-
|
|
5638
|
+
text3 = this.mail.text;
|
|
5639
5639
|
} else {
|
|
5640
|
-
|
|
5640
|
+
text3 = {
|
|
5641
5641
|
content: this.mail.text
|
|
5642
5642
|
};
|
|
5643
5643
|
}
|
|
5644
|
-
|
|
5644
|
+
text3.contentType = "text/plain; charset=utf-8";
|
|
5645
5645
|
}
|
|
5646
5646
|
if (this.mail.watchHtml) {
|
|
5647
5647
|
if (typeof this.mail.watchHtml === "object" && (this.mail.watchHtml.content || this.mail.watchHtml.path || this.mail.watchHtml.href || this.mail.watchHtml.raw)) {
|
|
@@ -5694,7 +5694,7 @@ var require_mail_composer = __commonJS({
|
|
|
5694
5694
|
}
|
|
5695
5695
|
html.contentType = "text/html; charset=utf-8";
|
|
5696
5696
|
}
|
|
5697
|
-
[].concat(
|
|
5697
|
+
[].concat(text3 || []).concat(watchHtml || []).concat(amp || []).concat(html || []).concat(eventObject || []).concat(this.mail.alternatives || []).forEach((alternative) => {
|
|
5698
5698
|
let data;
|
|
5699
5699
|
if (/^data:/i.test(alternative.path || alternative.href)) {
|
|
5700
5700
|
alternative = this._processDataUrl(alternative);
|
|
@@ -6254,7 +6254,7 @@ var require_dkim = __commonJS({
|
|
|
6254
6254
|
var DKIM_ALGO = "sha256";
|
|
6255
6255
|
var MAX_MESSAGE_SIZE = 128 * 1024;
|
|
6256
6256
|
var DKIMSigner = class {
|
|
6257
|
-
constructor(options, keys, input,
|
|
6257
|
+
constructor(options, keys, input, output2) {
|
|
6258
6258
|
this.options = options || {};
|
|
6259
6259
|
this.keys = keys;
|
|
6260
6260
|
this.cacheTreshold = Number(this.options.cacheTreshold) || MAX_MESSAGE_SIZE;
|
|
@@ -6270,13 +6270,13 @@ var require_dkim = __commonJS({
|
|
|
6270
6270
|
this.parser = false;
|
|
6271
6271
|
this.relaxedBody = false;
|
|
6272
6272
|
this.input = input;
|
|
6273
|
-
this.output =
|
|
6273
|
+
this.output = output2;
|
|
6274
6274
|
this.output.usingCache = false;
|
|
6275
6275
|
this.hasErrored = false;
|
|
6276
6276
|
this.input.on("error", (err) => {
|
|
6277
6277
|
this.hasErrored = true;
|
|
6278
6278
|
this.cleanup();
|
|
6279
|
-
|
|
6279
|
+
output2.emit("error", err);
|
|
6280
6280
|
});
|
|
6281
6281
|
}
|
|
6282
6282
|
cleanup() {
|
|
@@ -6405,7 +6405,7 @@ var require_dkim = __commonJS({
|
|
|
6405
6405
|
);
|
|
6406
6406
|
}
|
|
6407
6407
|
sign(input, extraOptions) {
|
|
6408
|
-
let
|
|
6408
|
+
let output2 = new PassThrough();
|
|
6409
6409
|
let inputStream = input;
|
|
6410
6410
|
let writeValue = false;
|
|
6411
6411
|
if (Buffer.isBuffer(input)) {
|
|
@@ -6427,7 +6427,7 @@ var require_dkim = __commonJS({
|
|
|
6427
6427
|
}
|
|
6428
6428
|
});
|
|
6429
6429
|
}
|
|
6430
|
-
let signer = new DKIMSigner(options, this.keys, inputStream,
|
|
6430
|
+
let signer = new DKIMSigner(options, this.keys, inputStream, output2);
|
|
6431
6431
|
setImmediate(() => {
|
|
6432
6432
|
signer.signStream();
|
|
6433
6433
|
if (writeValue) {
|
|
@@ -6436,7 +6436,7 @@ var require_dkim = __commonJS({
|
|
|
6436
6436
|
});
|
|
6437
6437
|
}
|
|
6438
6438
|
});
|
|
6439
|
-
return
|
|
6439
|
+
return output2;
|
|
6440
6440
|
}
|
|
6441
6441
|
};
|
|
6442
6442
|
module.exports = DKIM;
|
|
@@ -6848,14 +6848,14 @@ var require_mailer = __commonJS({
|
|
|
6848
6848
|
this.getVersionString()
|
|
6849
6849
|
);
|
|
6850
6850
|
if (typeof this.transporter.on === "function") {
|
|
6851
|
-
this.transporter.on("log", (
|
|
6851
|
+
this.transporter.on("log", (log2) => {
|
|
6852
6852
|
this.logger.debug(
|
|
6853
6853
|
{
|
|
6854
6854
|
tnx: "transport"
|
|
6855
6855
|
},
|
|
6856
6856
|
"%s: %s",
|
|
6857
|
-
|
|
6858
|
-
|
|
6857
|
+
log2.type,
|
|
6858
|
+
log2.message
|
|
6859
6859
|
);
|
|
6860
6860
|
});
|
|
6861
6861
|
this.transporter.on("error", (err) => {
|
|
@@ -11715,12 +11715,296 @@ function apply2(ctx) {
|
|
|
11715
11715
|
installIndexInjection(ctx);
|
|
11716
11716
|
}
|
|
11717
11717
|
|
|
11718
|
+
// src/automation-tasks/index.ts
|
|
11719
|
+
var automation_tasks_exports = {};
|
|
11720
|
+
__export(automation_tasks_exports, {
|
|
11721
|
+
apply: () => apply3,
|
|
11722
|
+
makeAutomationTaskTools: () => makeAutomationTaskTools
|
|
11723
|
+
});
|
|
11724
|
+
import { appendFileSync as appendFileSync2 } from "node:fs";
|
|
11725
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
11726
|
+
import { join as join2 } from "node:path";
|
|
11727
|
+
var OUTPUT_SCHEMA = { type: "object", additionalProperties: true };
|
|
11728
|
+
var SELECTOR_KEYS = ["after_seconds", "at", "every_seconds", "daily", "weekly", "cron"];
|
|
11729
|
+
function output() {
|
|
11730
|
+
return {
|
|
11731
|
+
schema: OUTPUT_SCHEMA,
|
|
11732
|
+
render: (_args, value) => [{ type: "text", text: JSON.stringify(value) }]
|
|
11733
|
+
};
|
|
11734
|
+
}
|
|
11735
|
+
function log(message) {
|
|
11736
|
+
try {
|
|
11737
|
+
appendFileSync2(join2(tmpdir2(), "dsh-mcviseron-automation-tasks.log"), (/* @__PURE__ */ new Date()).toISOString() + " " + message + "\n", "utf8");
|
|
11738
|
+
} catch {
|
|
11739
|
+
}
|
|
11740
|
+
}
|
|
11741
|
+
function sessionIdOf(exec) {
|
|
11742
|
+
const id = exec.agent?.session?.id;
|
|
11743
|
+
return typeof id === "string" ? id : "";
|
|
11744
|
+
}
|
|
11745
|
+
function text(value) {
|
|
11746
|
+
return typeof value === "string" && value.trim() !== "";
|
|
11747
|
+
}
|
|
11748
|
+
function selectorCount(args, keys) {
|
|
11749
|
+
return keys.filter((key) => args[key] !== void 0).length;
|
|
11750
|
+
}
|
|
11751
|
+
function timingChange(args) {
|
|
11752
|
+
if (args.at !== void 0) return { kind: "at", at: args.at };
|
|
11753
|
+
if (args.every_seconds !== void 0) return { kind: "every", every_seconds: args.every_seconds };
|
|
11754
|
+
if (args.daily !== void 0) return { kind: "daily", daily: args.daily };
|
|
11755
|
+
if (args.weekly !== void 0) return { kind: "weekly", weekly: args.weekly };
|
|
11756
|
+
if (args.cron !== void 0) return { kind: "cron", cron: args.cron };
|
|
11757
|
+
return void 0;
|
|
11758
|
+
}
|
|
11759
|
+
function invalid(message) {
|
|
11760
|
+
return { ok: false, code: "invalid", error: message };
|
|
11761
|
+
}
|
|
11762
|
+
function serviceFailure(error) {
|
|
11763
|
+
return { ok: false, code: "service_error", error: error instanceof Error ? error.message : String(error) };
|
|
11764
|
+
}
|
|
11765
|
+
function validateCreate(args) {
|
|
11766
|
+
if (!text(args.title)) return "title must be a non-empty string";
|
|
11767
|
+
if (!text(args.prompt)) return "prompt must be a non-empty string";
|
|
11768
|
+
const count = selectorCount(args, SELECTOR_KEYS);
|
|
11769
|
+
if (count !== 1) return "supply exactly one of after_seconds, at, every_seconds, daily, weekly, or cron";
|
|
11770
|
+
if (args.after_seconds !== void 0 && (!Number.isSafeInteger(args.after_seconds) || Number(args.after_seconds) <= 0)) {
|
|
11771
|
+
return "after_seconds must be a positive integer";
|
|
11772
|
+
}
|
|
11773
|
+
if (args.every_seconds !== void 0 && (!Number.isSafeInteger(args.every_seconds) || Number(args.every_seconds) < 60)) {
|
|
11774
|
+
return "every_seconds must be an integer of at least 60";
|
|
11775
|
+
}
|
|
11776
|
+
if (args.at !== void 0 && !text(args.at)) return "at must be a non-empty ISO date-time string";
|
|
11777
|
+
return void 0;
|
|
11778
|
+
}
|
|
11779
|
+
function validateUpdate(args) {
|
|
11780
|
+
if (!text(args.id)) return "id must be a non-empty string";
|
|
11781
|
+
const keys = ["at", "every_seconds", "daily", "weekly", "cron"];
|
|
11782
|
+
if (selectorCount(args, keys) > 1) return "update accepts at most one timing selector";
|
|
11783
|
+
if (args.every_seconds !== void 0 && (!Number.isSafeInteger(args.every_seconds) || Number(args.every_seconds) < 60)) {
|
|
11784
|
+
return "every_seconds must be an integer of at least 60";
|
|
11785
|
+
}
|
|
11786
|
+
if (args.title === void 0 && args.prompt === void 0 && timingChange(args) === void 0) {
|
|
11787
|
+
return "update needs a new title, prompt, or one timing selector";
|
|
11788
|
+
}
|
|
11789
|
+
if (args.title !== void 0 && !text(args.title)) return "title must be a non-empty string";
|
|
11790
|
+
if (args.prompt !== void 0 && !text(args.prompt)) return "prompt must be a non-empty string";
|
|
11791
|
+
return void 0;
|
|
11792
|
+
}
|
|
11793
|
+
var SELECTOR_SCHEMA = {
|
|
11794
|
+
after_seconds: { type: "number", description: "Delay in whole seconds; create only." },
|
|
11795
|
+
at: { type: "string", description: "Absolute RFC 3339 date-time with offset." },
|
|
11796
|
+
every_seconds: { type: "number", description: "Fixed interval in whole seconds, at least 60." },
|
|
11797
|
+
daily: {
|
|
11798
|
+
type: "object",
|
|
11799
|
+
additionalProperties: false,
|
|
11800
|
+
required: ["time", "time_zone"],
|
|
11801
|
+
properties: { time: { type: "string" }, time_zone: { type: "string" } }
|
|
11802
|
+
},
|
|
11803
|
+
weekly: {
|
|
11804
|
+
type: "object",
|
|
11805
|
+
additionalProperties: false,
|
|
11806
|
+
required: ["time", "time_zone", "weekdays"],
|
|
11807
|
+
properties: {
|
|
11808
|
+
time: { type: "string" },
|
|
11809
|
+
time_zone: { type: "string" },
|
|
11810
|
+
weekdays: { type: "array", items: { type: "integer", minimum: 1, maximum: 7 } }
|
|
11811
|
+
}
|
|
11812
|
+
},
|
|
11813
|
+
cron: {
|
|
11814
|
+
type: "object",
|
|
11815
|
+
additionalProperties: false,
|
|
11816
|
+
required: ["expression", "time_zone"],
|
|
11817
|
+
properties: { expression: { type: "string" }, time_zone: { type: "string" } }
|
|
11818
|
+
}
|
|
11819
|
+
};
|
|
11820
|
+
var { after_seconds: _createOnlyAfterSeconds, ...UPDATE_SELECTOR_SCHEMA } = SELECTOR_SCHEMA;
|
|
11821
|
+
var CREATE_PARAMETERS = {
|
|
11822
|
+
type: "object",
|
|
11823
|
+
additionalProperties: false,
|
|
11824
|
+
required: ["title", "prompt"],
|
|
11825
|
+
properties: {
|
|
11826
|
+
title: { type: "string", description: "Short task name; no schedule in the title." },
|
|
11827
|
+
prompt: { type: "string", description: "Complete instruction delivered when due." },
|
|
11828
|
+
...SELECTOR_SCHEMA
|
|
11829
|
+
}
|
|
11830
|
+
};
|
|
11831
|
+
var UPDATE_PARAMETERS = {
|
|
11832
|
+
type: "object",
|
|
11833
|
+
additionalProperties: false,
|
|
11834
|
+
required: ["id"],
|
|
11835
|
+
properties: {
|
|
11836
|
+
id: { type: "string", description: "Exact schedule id from automation_task_list." },
|
|
11837
|
+
title: { type: "string" },
|
|
11838
|
+
prompt: { type: "string" },
|
|
11839
|
+
...UPDATE_SELECTOR_SCHEMA
|
|
11840
|
+
}
|
|
11841
|
+
};
|
|
11842
|
+
var DELETE_PARAMETERS = {
|
|
11843
|
+
type: "object",
|
|
11844
|
+
additionalProperties: false,
|
|
11845
|
+
required: ["id"],
|
|
11846
|
+
properties: { id: { type: "string", description: "Exact schedule id." } }
|
|
11847
|
+
};
|
|
11848
|
+
var LIST_PARAMETERS = { type: "object", additionalProperties: false, properties: {} };
|
|
11849
|
+
function makeAutomationTaskTools(schedule) {
|
|
11850
|
+
return [
|
|
11851
|
+
{
|
|
11852
|
+
name: "automation_task_list",
|
|
11853
|
+
description: "List the official automation tasks bound to the current session. Use this before changing a task so you have its exact id and current prompt.",
|
|
11854
|
+
parameters: LIST_PARAMETERS,
|
|
11855
|
+
output: output(),
|
|
11856
|
+
async execute(_args, exec) {
|
|
11857
|
+
const sessionId = sessionIdOf(exec);
|
|
11858
|
+
if (sessionId === "") return { ok: false, code: "no_session", error: "no current session" };
|
|
11859
|
+
try {
|
|
11860
|
+
return { ok: true, tasks: await schedule.list({ sessionId }) };
|
|
11861
|
+
} catch (error) {
|
|
11862
|
+
return serviceFailure(error);
|
|
11863
|
+
}
|
|
11864
|
+
}
|
|
11865
|
+
},
|
|
11866
|
+
{
|
|
11867
|
+
name: "automation_task_create",
|
|
11868
|
+
description: "Create an official automation task (DSH schedule) bound to the current session. Supply title, prompt, and exactly one timing selector. The Host schedule service persists it immediately; never edit schedule.json by hand.",
|
|
11869
|
+
parameters: CREATE_PARAMETERS,
|
|
11870
|
+
output: output(),
|
|
11871
|
+
async execute(args, exec) {
|
|
11872
|
+
const sessionId = sessionIdOf(exec);
|
|
11873
|
+
if (sessionId === "") return { ok: false, code: "no_session", error: "no current session" };
|
|
11874
|
+
const invalidInput = validateCreate(args);
|
|
11875
|
+
if (invalidInput !== void 0) return invalid(invalidInput);
|
|
11876
|
+
try {
|
|
11877
|
+
const record2 = await schedule.create(sessionId, {
|
|
11878
|
+
...args,
|
|
11879
|
+
title: String(args.title).trim(),
|
|
11880
|
+
prompt: String(args.prompt).trim()
|
|
11881
|
+
}, exec.signal);
|
|
11882
|
+
return { ok: true, task: record2 };
|
|
11883
|
+
} catch (error) {
|
|
11884
|
+
return serviceFailure(error);
|
|
11885
|
+
}
|
|
11886
|
+
}
|
|
11887
|
+
},
|
|
11888
|
+
{
|
|
11889
|
+
name: "automation_task_update",
|
|
11890
|
+
description: "Update an existing official automation task in place, keeping its id. Supply id plus a new title, prompt, or at most one timing selector. The Host schedule service persists it immediately; this is the supported way to edit an automation task from the conversation.",
|
|
11891
|
+
parameters: UPDATE_PARAMETERS,
|
|
11892
|
+
output: output(),
|
|
11893
|
+
async execute(args, exec) {
|
|
11894
|
+
const sessionId = sessionIdOf(exec);
|
|
11895
|
+
if (sessionId === "") return { ok: false, code: "no_session", error: "no current session" };
|
|
11896
|
+
const invalidInput = validateUpdate(args);
|
|
11897
|
+
if (invalidInput !== void 0) return invalid(invalidInput);
|
|
11898
|
+
try {
|
|
11899
|
+
const id = String(args.id);
|
|
11900
|
+
const expected = (await schedule.list({ sessionId })).find((record2) => record2.id === id);
|
|
11901
|
+
if (expected === void 0) return { ok: false, code: "schedule_not_found", error: "automation task not found in this session: " + id };
|
|
11902
|
+
const change = timingChange(args);
|
|
11903
|
+
const result = await schedule.update({
|
|
11904
|
+
sessionId,
|
|
11905
|
+
id,
|
|
11906
|
+
expected,
|
|
11907
|
+
...change === void 0 ? {} : { change },
|
|
11908
|
+
...args.title === void 0 ? {} : { title: String(args.title).trim() },
|
|
11909
|
+
...args.prompt === void 0 ? {} : { prompt: String(args.prompt).trim() }
|
|
11910
|
+
}, exec.signal);
|
|
11911
|
+
if (result.record !== void 0) return { ok: true, task: result.record };
|
|
11912
|
+
return { ok: false, ...result };
|
|
11913
|
+
} catch (error) {
|
|
11914
|
+
return serviceFailure(error);
|
|
11915
|
+
}
|
|
11916
|
+
}
|
|
11917
|
+
},
|
|
11918
|
+
{
|
|
11919
|
+
name: "automation_task_delete",
|
|
11920
|
+
description: "Delete an official automation task in the current session. The Host schedule service removes and persists it immediately.",
|
|
11921
|
+
parameters: DELETE_PARAMETERS,
|
|
11922
|
+
output: output(),
|
|
11923
|
+
async execute(args, exec) {
|
|
11924
|
+
const sessionId = sessionIdOf(exec);
|
|
11925
|
+
if (sessionId === "") return { ok: false, code: "no_session", error: "no current session" };
|
|
11926
|
+
if (!text(args.id) || String(args.id).trim() !== String(args.id)) {
|
|
11927
|
+
return invalid("id must be a non-empty string without surrounding whitespace");
|
|
11928
|
+
}
|
|
11929
|
+
try {
|
|
11930
|
+
const result = await schedule.delete({ sessionId, id: String(args.id) }, exec.signal);
|
|
11931
|
+
return { ok: true, ...result };
|
|
11932
|
+
} catch (error) {
|
|
11933
|
+
return serviceFailure(error);
|
|
11934
|
+
}
|
|
11935
|
+
}
|
|
11936
|
+
}
|
|
11937
|
+
];
|
|
11938
|
+
}
|
|
11939
|
+
function serviceOf(scope, name) {
|
|
11940
|
+
try {
|
|
11941
|
+
if (scope[name] !== void 0) return scope[name];
|
|
11942
|
+
const get = scope.get;
|
|
11943
|
+
return typeof get === "function" ? get.call(scope, name) : void 0;
|
|
11944
|
+
} catch {
|
|
11945
|
+
return void 0;
|
|
11946
|
+
}
|
|
11947
|
+
}
|
|
11948
|
+
function apply3(ctx) {
|
|
11949
|
+
const inject5 = ctx.inject;
|
|
11950
|
+
if (typeof inject5 !== "function") return;
|
|
11951
|
+
try {
|
|
11952
|
+
inject5.call(ctx, ["tools", "schedule"], (scope) => {
|
|
11953
|
+
const tools = serviceOf(scope, "tools");
|
|
11954
|
+
const schedule = serviceOf(scope, "schedule");
|
|
11955
|
+
if (tools === void 0 || typeof tools.register !== "function" || schedule === void 0) {
|
|
11956
|
+
log("schedule tools unavailable");
|
|
11957
|
+
return;
|
|
11958
|
+
}
|
|
11959
|
+
const dispose = makeAutomationTaskTools(schedule).map((definition) => {
|
|
11960
|
+
try {
|
|
11961
|
+
return tools.register?.(definition);
|
|
11962
|
+
} catch (error) {
|
|
11963
|
+
log("tool registration failed: " + (error instanceof Error ? error.message : String(error)));
|
|
11964
|
+
return void 0;
|
|
11965
|
+
}
|
|
11966
|
+
}).filter((item) => typeof item === "function");
|
|
11967
|
+
const effect = scope.effect;
|
|
11968
|
+
if (typeof effect === "function") {
|
|
11969
|
+
effect.call(scope, () => () => {
|
|
11970
|
+
for (const disposeTool of dispose) {
|
|
11971
|
+
try {
|
|
11972
|
+
disposeTool();
|
|
11973
|
+
} catch {
|
|
11974
|
+
}
|
|
11975
|
+
}
|
|
11976
|
+
}, "mcviseron-automation-tasks: tools");
|
|
11977
|
+
}
|
|
11978
|
+
});
|
|
11979
|
+
} catch (error) {
|
|
11980
|
+
log("tool injection failed: " + (error instanceof Error ? error.message : String(error)));
|
|
11981
|
+
}
|
|
11982
|
+
try {
|
|
11983
|
+
inject5.call(ctx, ["systemPrompt"], (scope) => {
|
|
11984
|
+
const systemPrompt = serviceOf(scope, "systemPrompt");
|
|
11985
|
+
if (typeof systemPrompt?.section === "function") {
|
|
11986
|
+
systemPrompt.section({
|
|
11987
|
+
name: "plugin:mcviseron-automation-tasks",
|
|
11988
|
+
order: 232,
|
|
11989
|
+
text: [
|
|
11990
|
+
"Official DSH automation tasks are writable from this conversation.",
|
|
11991
|
+
"Use automation_task_list / automation_task_create / automation_task_update / automation_task_delete; they call the Host schedule service and persist automatically.",
|
|
11992
|
+
"Never edit ~/.dsh/storages/schedule.json by hand, and never tell the user to use a command to change a task when these tools are available."
|
|
11993
|
+
].join(" ")
|
|
11994
|
+
});
|
|
11995
|
+
}
|
|
11996
|
+
});
|
|
11997
|
+
} catch (error) {
|
|
11998
|
+
log("system prompt section unavailable: " + (error instanceof Error ? error.message : String(error)));
|
|
11999
|
+
}
|
|
12000
|
+
}
|
|
12001
|
+
|
|
11718
12002
|
// src/auto-review-fix/index.ts
|
|
11719
12003
|
var auto_review_fix_exports = {};
|
|
11720
12004
|
__export(auto_review_fix_exports, {
|
|
11721
12005
|
Config: () => Config2,
|
|
11722
12006
|
DEFAULT_AUTO_REVIEW_CONFIG: () => DEFAULT_AUTO_REVIEW_CONFIG,
|
|
11723
|
-
apply: () =>
|
|
12007
|
+
apply: () => apply4
|
|
11724
12008
|
});
|
|
11725
12009
|
import z2 from "@deepseek-ai/schemastery";
|
|
11726
12010
|
|
|
@@ -11728,9 +12012,9 @@ import z2 from "@deepseek-ai/schemastery";
|
|
|
11728
12012
|
import { randomUUID } from "node:crypto";
|
|
11729
12013
|
|
|
11730
12014
|
// src/components/auto-review-fix/review-context.ts
|
|
11731
|
-
import { appendFileSync as
|
|
11732
|
-
import { tmpdir as
|
|
11733
|
-
import { join as
|
|
12015
|
+
import { appendFileSync as appendFileSync3 } from "node:fs";
|
|
12016
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
12017
|
+
import { join as join3 } from "node:path";
|
|
11734
12018
|
var REVIEW_MARKER = "REVIEW_POLICY";
|
|
11735
12019
|
var REVIEW_MARKER_2 = "final authorization reviewer";
|
|
11736
12020
|
var HISTORY_HEADER = "FILTERED_HISTORY\n\n";
|
|
@@ -11756,12 +12040,12 @@ function isAutoReviewRequest(options) {
|
|
|
11756
12040
|
const system = options.system;
|
|
11757
12041
|
if (typeof system !== "string" || !system.includes(REVIEW_MARKER) || !system.includes(REVIEW_MARKER_2)) return false;
|
|
11758
12042
|
if (!Array.isArray(options.messages) || options.messages.length === 0) return false;
|
|
11759
|
-
const
|
|
11760
|
-
return
|
|
12043
|
+
const text3 = textOf(options.messages[0]);
|
|
12044
|
+
return text3 !== void 0 && text3.includes(HISTORY_HEADER) && text3.includes(ACTION_HEADER);
|
|
11761
12045
|
}
|
|
11762
|
-
function truncateText(
|
|
11763
|
-
if (
|
|
11764
|
-
return
|
|
12046
|
+
function truncateText(text3, limit) {
|
|
12047
|
+
if (text3.length <= limit) return text3;
|
|
12048
|
+
return text3.slice(0, limit) + "\n\u2026[" + String(text3.length - limit) + " characters omitted]";
|
|
11765
12049
|
}
|
|
11766
12050
|
function compactBlock(block) {
|
|
11767
12051
|
if (!record(block)) return { type: "text", text: "[non-text history block omitted from reviewer context]" };
|
|
@@ -11831,9 +12115,9 @@ function boundEntries(entries, maxChars, keepRecent) {
|
|
|
11831
12115
|
if (omitted > 0) selected.unshift(summaryEntry(omitted, originalChars));
|
|
11832
12116
|
return selected;
|
|
11833
12117
|
}
|
|
11834
|
-
function parseArray(
|
|
12118
|
+
function parseArray(text3) {
|
|
11835
12119
|
try {
|
|
11836
|
-
const value = JSON.parse(
|
|
12120
|
+
const value = JSON.parse(text3);
|
|
11837
12121
|
return Array.isArray(value) ? value : void 0;
|
|
11838
12122
|
} catch {
|
|
11839
12123
|
return void 0;
|
|
@@ -11841,8 +12125,8 @@ function parseArray(text2) {
|
|
|
11841
12125
|
}
|
|
11842
12126
|
function logTrim(originalChars, nextChars, originalEntries, nextEntries) {
|
|
11843
12127
|
try {
|
|
11844
|
-
|
|
11845
|
-
|
|
12128
|
+
appendFileSync3(
|
|
12129
|
+
join3(tmpdir3(), "dsh-mcviseron-auto-review.log"),
|
|
11846
12130
|
(/* @__PURE__ */ new Date()).toISOString() + " review context trimmed: " + String(originalChars) + " -> " + String(nextChars) + " chars, history " + String(originalEntries) + " -> " + String(nextEntries) + "\n",
|
|
11847
12131
|
"utf8"
|
|
11848
12132
|
);
|
|
@@ -11853,22 +12137,22 @@ function trimReviewRequest(options, settings) {
|
|
|
11853
12137
|
if (!settings.enabled || !isAutoReviewRequest(options)) return options;
|
|
11854
12138
|
const messages = options.messages;
|
|
11855
12139
|
const message = messages[0];
|
|
11856
|
-
const
|
|
11857
|
-
if (
|
|
11858
|
-
const projectAt =
|
|
11859
|
-
const historyAt =
|
|
11860
|
-
const actionAt =
|
|
12140
|
+
const text3 = textOf(message);
|
|
12141
|
+
if (text3 === void 0) return options;
|
|
12142
|
+
const projectAt = text3.indexOf(PROJECT_HEADER);
|
|
12143
|
+
const historyAt = text3.indexOf(HISTORY_HEADER, projectAt + 1);
|
|
12144
|
+
const actionAt = text3.indexOf(ACTION_HEADER, historyAt + 1);
|
|
11861
12145
|
if (projectAt < 0 || historyAt < 0 || actionAt < 0) return options;
|
|
11862
|
-
const projectJson =
|
|
11863
|
-
const historyJson =
|
|
12146
|
+
const projectJson = text3.slice(projectAt + PROJECT_HEADER.length, historyAt - 2);
|
|
12147
|
+
const historyJson = text3.slice(historyAt + HISTORY_HEADER.length, actionAt);
|
|
11864
12148
|
const project = parseArray(projectJson);
|
|
11865
12149
|
const history = parseArray(historyJson);
|
|
11866
12150
|
if (project === void 0 || history === void 0) return options;
|
|
11867
12151
|
const nextProject = boundEntries(project, PROJECT_MAX_CHARS, 4);
|
|
11868
12152
|
const nextHistory = boundEntries(history, settings.maxHistoryChars, settings.keepRecentEntries);
|
|
11869
|
-
const nextText =
|
|
11870
|
-
if (nextText ===
|
|
11871
|
-
logTrim(
|
|
12153
|
+
const nextText = text3.slice(0, projectAt) + PROJECT_HEADER + JSON.stringify(nextProject) + HISTORY_HEADER + JSON.stringify(nextHistory) + text3.slice(actionAt);
|
|
12154
|
+
if (nextText === text3) return options;
|
|
12155
|
+
logTrim(text3.length, nextText.length, history.length, nextHistory.length);
|
|
11872
12156
|
const content = [{ type: "text", text: nextText }];
|
|
11873
12157
|
return {
|
|
11874
12158
|
...options,
|
|
@@ -11891,7 +12175,7 @@ function whenService(ctx, name, run) {
|
|
|
11891
12175
|
} catch {
|
|
11892
12176
|
}
|
|
11893
12177
|
}
|
|
11894
|
-
function
|
|
12178
|
+
function serviceOf2(scope, name) {
|
|
11895
12179
|
try {
|
|
11896
12180
|
const direct = scope[name];
|
|
11897
12181
|
if (direct !== void 0) return direct;
|
|
@@ -11914,7 +12198,7 @@ function effectOf(scope, setup, label) {
|
|
|
11914
12198
|
function installReviewContextGuard(ctx, settings) {
|
|
11915
12199
|
if (!settings.enabled) return;
|
|
11916
12200
|
whenService(ctx, "llm", (scope) => {
|
|
11917
|
-
const llm =
|
|
12201
|
+
const llm = serviceOf2(scope, "llm");
|
|
11918
12202
|
if (llm === null || typeof llm !== "object" || typeof llm.stream !== "function") return;
|
|
11919
12203
|
const existing = guardedLlms.get(llm);
|
|
11920
12204
|
if (existing !== void 0) {
|
|
@@ -11971,14 +12255,14 @@ function englishText(display) {
|
|
|
11971
12255
|
for (const value of Object.values(display)) if (typeof value === "string") return value;
|
|
11972
12256
|
return void 0;
|
|
11973
12257
|
}
|
|
11974
|
-
function isAutoReviewText(
|
|
11975
|
-
return /auto[\s\-_]*review/i.test(
|
|
12258
|
+
function isAutoReviewText(text3) {
|
|
12259
|
+
return /auto[\s\-_]*review/i.test(text3);
|
|
11976
12260
|
}
|
|
11977
|
-
function reviewerExcerpt(
|
|
11978
|
-
const match = /^\s*auto[\s\-_]*review\s+(?:denied\s+this\s+call|拒绝了此调用)\s*[::.]?\s*/i.exec(
|
|
11979
|
-
if (match === null) return
|
|
11980
|
-
const rest =
|
|
11981
|
-
return rest.length === 0 ?
|
|
12261
|
+
function reviewerExcerpt(text3) {
|
|
12262
|
+
const match = /^\s*auto[\s\-_]*review\s+(?:denied\s+this\s+call|拒绝了此调用)\s*[::.]?\s*/i.exec(text3);
|
|
12263
|
+
if (match === null) return text3.trim();
|
|
12264
|
+
const rest = text3.slice(match[0].length).trim();
|
|
12265
|
+
return rest.length === 0 ? text3.trim() : rest;
|
|
11982
12266
|
}
|
|
11983
12267
|
function withTranslation(original, translation) {
|
|
11984
12268
|
return original.length === 0 ? `${TRANSLATION_LABEL}
|
|
@@ -11990,25 +12274,25 @@ ${translation}`;
|
|
|
11990
12274
|
function hasTranslation(value) {
|
|
11991
12275
|
return value.includes(TRANSLATION_LABEL);
|
|
11992
12276
|
}
|
|
11993
|
-
function isPredominantlyChinese(
|
|
11994
|
-
const han = (
|
|
12277
|
+
function isPredominantlyChinese(text3) {
|
|
12278
|
+
const han = (text3.match(/[\u3400-\u9fff\uf900-\ufaff]/g) ?? []).length;
|
|
11995
12279
|
if (han === 0) return false;
|
|
11996
|
-
const englishWords = (
|
|
12280
|
+
const englishWords = (text3.match(/[A-Za-z][A-Za-z0-9_.-]*/g) ?? []).length;
|
|
11997
12281
|
return englishWords <= Math.max(2, Math.ceil(han / 2));
|
|
11998
12282
|
}
|
|
11999
12283
|
function cleanTranslation(raw) {
|
|
12000
|
-
let
|
|
12001
|
-
const fenced = /^\s*```[a-zA-Z]*\n([\s\S]*?)\n```\s*$/.exec(
|
|
12284
|
+
let text3 = raw.trim();
|
|
12285
|
+
const fenced = /^\s*```[a-zA-Z]*\n([\s\S]*?)\n```\s*$/.exec(text3);
|
|
12002
12286
|
const fencedBody = fenced?.[1];
|
|
12003
|
-
if (fencedBody !== void 0)
|
|
12004
|
-
if (
|
|
12005
|
-
const first =
|
|
12006
|
-
const last =
|
|
12287
|
+
if (fencedBody !== void 0) text3 = fencedBody.trim();
|
|
12288
|
+
if (text3.length >= 2) {
|
|
12289
|
+
const first = text3[0];
|
|
12290
|
+
const last = text3[text3.length - 1];
|
|
12007
12291
|
if (first === '"' && last === '"' || first === "'" && last === "'" || first === "\u300C" && last === "\u300D") {
|
|
12008
|
-
|
|
12292
|
+
text3 = text3.slice(1, -1).trim();
|
|
12009
12293
|
}
|
|
12010
12294
|
}
|
|
12011
|
-
return
|
|
12295
|
+
return text3;
|
|
12012
12296
|
}
|
|
12013
12297
|
function sessionRoute(request) {
|
|
12014
12298
|
try {
|
|
@@ -12031,14 +12315,14 @@ function translationRoute(settings, request) {
|
|
|
12031
12315
|
return sessionRoute(request);
|
|
12032
12316
|
}
|
|
12033
12317
|
async function readStream(stream, controller) {
|
|
12034
|
-
let
|
|
12318
|
+
let text3 = "";
|
|
12035
12319
|
for await (const chunk of stream) {
|
|
12036
12320
|
if (controller.signal.aborted) return void 0;
|
|
12037
12321
|
const value = chunk;
|
|
12038
12322
|
if (value === null || typeof value !== "object") continue;
|
|
12039
12323
|
if (value.type === "text-delta" && typeof value.text === "string") {
|
|
12040
|
-
|
|
12041
|
-
if (
|
|
12324
|
+
text3 += value.text;
|
|
12325
|
+
if (text3.length > 16e3) break;
|
|
12042
12326
|
continue;
|
|
12043
12327
|
}
|
|
12044
12328
|
if (value.type === "finish") {
|
|
@@ -12046,10 +12330,10 @@ async function readStream(stream, controller) {
|
|
|
12046
12330
|
if (typeof kind === "string" && kind !== "stop") return void 0;
|
|
12047
12331
|
}
|
|
12048
12332
|
}
|
|
12049
|
-
return
|
|
12333
|
+
return text3;
|
|
12050
12334
|
}
|
|
12051
|
-
async function translateForDisplay(llm, settings, request,
|
|
12052
|
-
const source =
|
|
12335
|
+
async function translateForDisplay(llm, settings, request, text3) {
|
|
12336
|
+
const source = text3.trim();
|
|
12053
12337
|
if (source.length === 0 || source.length > settings.maxChars) return void 0;
|
|
12054
12338
|
const cached = cache.get(source);
|
|
12055
12339
|
if (cached !== void 0) return cached;
|
|
@@ -12132,7 +12416,7 @@ function whenService2(ctx, name, run) {
|
|
|
12132
12416
|
} catch {
|
|
12133
12417
|
}
|
|
12134
12418
|
}
|
|
12135
|
-
function
|
|
12419
|
+
function serviceOf3(scope, name) {
|
|
12136
12420
|
try {
|
|
12137
12421
|
const direct = scope[name];
|
|
12138
12422
|
if (direct !== void 0) return direct;
|
|
@@ -12164,7 +12448,7 @@ function rootIsActive(root) {
|
|
|
12164
12448
|
}
|
|
12165
12449
|
function installPresetGuard(ctx) {
|
|
12166
12450
|
whenService2(ctx, "permissionPresets", (scope) => {
|
|
12167
|
-
const presets =
|
|
12451
|
+
const presets = serviceOf3(scope, "permissionPresets");
|
|
12168
12452
|
if (presets === null || typeof presets !== "object") return;
|
|
12169
12453
|
if (typeof presets.set !== "function") return;
|
|
12170
12454
|
if (guardedPresets.has(presets)) return;
|
|
@@ -12196,7 +12480,7 @@ async function decorateApprovalRequest(scope, settings, request, translate = tra
|
|
|
12196
12480
|
if (excerpt.length === 0 || excerpt.length > settings.maxChars) return request;
|
|
12197
12481
|
if (isPredominantlyChinese(excerpt)) return request;
|
|
12198
12482
|
if (translationRoute(settings, request) === void 0) return request;
|
|
12199
|
-
const llm =
|
|
12483
|
+
const llm = serviceOf3(scope, "llm");
|
|
12200
12484
|
const translated = await translate(llm, settings, request, excerpt);
|
|
12201
12485
|
if (translated === void 0) return request;
|
|
12202
12486
|
const cleaned = cleanTranslation(translated);
|
|
@@ -12210,7 +12494,7 @@ async function decorateApprovalRequest(scope, settings, request, translate = tra
|
|
|
12210
12494
|
displayReason: { ...record2, [key]: withTranslation(localized, cleaned) }
|
|
12211
12495
|
};
|
|
12212
12496
|
}
|
|
12213
|
-
function
|
|
12497
|
+
function sessionIdOf2(agent) {
|
|
12214
12498
|
const session = agent?.session;
|
|
12215
12499
|
return typeof session?.id === "string" ? session.id : "";
|
|
12216
12500
|
}
|
|
@@ -12220,7 +12504,7 @@ function sessionVersion(agent) {
|
|
|
12220
12504
|
}
|
|
12221
12505
|
function rejectionKey(agent, callId) {
|
|
12222
12506
|
if (typeof callId !== "string" || callId === "") return "";
|
|
12223
|
-
const sessionId =
|
|
12507
|
+
const sessionId = sessionIdOf2(agent);
|
|
12224
12508
|
return sessionId === "" ? "" : sessionId + ":" + callId;
|
|
12225
12509
|
}
|
|
12226
12510
|
function approvalReasonText(request) {
|
|
@@ -12254,7 +12538,7 @@ function buildRejectionNotice(agent, request) {
|
|
|
12254
12538
|
const reason = approvalReasonText(request);
|
|
12255
12539
|
if (reason === "") return void 0;
|
|
12256
12540
|
const toolName = typeof request.toolName === "string" && request.toolName !== "" ? request.toolName : "\u672A\u77E5\u5DE5\u5177";
|
|
12257
|
-
const
|
|
12541
|
+
const text3 = [
|
|
12258
12542
|
'\u3010\u5BA1\u6279\u88AB\u62D2\u3011\u5DE5\u5177 "' + toolName + '" \u7684\u4EBA\u5DE5\u5BA1\u6279\u88AB\u62D2\u7EDD\u3002',
|
|
12259
12543
|
"\u81EA\u52A8\u5BA1\u67E5\u7406\u7531\uFF1A",
|
|
12260
12544
|
reason,
|
|
@@ -12264,7 +12548,7 @@ function buildRejectionNotice(agent, request) {
|
|
|
12264
12548
|
return {
|
|
12265
12549
|
id: randomUUID(),
|
|
12266
12550
|
role: "user",
|
|
12267
|
-
content: [{ type: "text", text:
|
|
12551
|
+
content: [{ type: "text", text: text3 }],
|
|
12268
12552
|
source: rejectionSource(agent, "\u5BA1\u6279\u88AB\u62D2 \xB7 " + toolName)
|
|
12269
12553
|
};
|
|
12270
12554
|
}
|
|
@@ -12312,7 +12596,7 @@ function installRejectionRelay(ctx, relay) {
|
|
|
12312
12596
|
}
|
|
12313
12597
|
function installApprovalTranslation(ctx, settings, relay) {
|
|
12314
12598
|
whenService2(ctx, "approval", (scope) => {
|
|
12315
|
-
const approval =
|
|
12599
|
+
const approval = serviceOf3(scope, "approval");
|
|
12316
12600
|
if (approval === null || typeof approval !== "object") return;
|
|
12317
12601
|
const original = approval.request;
|
|
12318
12602
|
if (typeof original !== "function") return;
|
|
@@ -12379,7 +12663,7 @@ var Config2 = z2.object({
|
|
|
12379
12663
|
reviewMaxHistoryChars: z2.number().min(2e4).max(6e5).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewMaxHistoryChars).volatile(),
|
|
12380
12664
|
reviewKeepRecentEntries: z2.number().min(4).max(64).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewKeepRecentEntries).volatile()
|
|
12381
12665
|
}).default(DEFAULT_AUTO_REVIEW_CONFIG);
|
|
12382
|
-
function
|
|
12666
|
+
function apply4(ctx, config) {
|
|
12383
12667
|
installAutoReview(ctx, toPlain(config));
|
|
12384
12668
|
}
|
|
12385
12669
|
|
|
@@ -12389,7 +12673,7 @@ __export(restart_exports, {
|
|
|
12389
12673
|
Config: () => Config3,
|
|
12390
12674
|
DEFAULT_RESTART_CONFIG: () => DEFAULT_RESTART_CONFIG,
|
|
12391
12675
|
RESTART_API: () => RESTART_API,
|
|
12392
|
-
apply: () =>
|
|
12676
|
+
apply: () => apply5,
|
|
12393
12677
|
closeDesktop: () => closeDesktop,
|
|
12394
12678
|
deriveDesktopAppPath: () => deriveDesktopAppPath,
|
|
12395
12679
|
inject: () => inject3,
|
|
@@ -12399,9 +12683,9 @@ __export(restart_exports, {
|
|
|
12399
12683
|
resolveRestartTarget: () => resolveRestartTarget
|
|
12400
12684
|
});
|
|
12401
12685
|
import { execFileSync } from "node:child_process";
|
|
12402
|
-
import { appendFileSync as
|
|
12403
|
-
import { tmpdir as
|
|
12404
|
-
import { basename, dirname, join as
|
|
12686
|
+
import { appendFileSync as appendFileSync4, existsSync } from "node:fs";
|
|
12687
|
+
import { tmpdir as tmpdir4 } from "node:os";
|
|
12688
|
+
import { basename, dirname, join as join4, resolve } from "node:path";
|
|
12405
12689
|
import z3 from "@deepseek-ai/schemastery";
|
|
12406
12690
|
var DEFAULT_RESTART_CONFIG = { enabled: true, appPath: "" };
|
|
12407
12691
|
var Config3 = z3.object({
|
|
@@ -12430,13 +12714,13 @@ function deriveDesktopAppPath(execPath, argv, exists) {
|
|
|
12430
12714
|
if (argv0 !== "" && argv0 !== execPath && !isNode(argv0) && exists(argv0)) return argv0;
|
|
12431
12715
|
const runtimeDir = argv[2] ?? "";
|
|
12432
12716
|
if (runtimeDir === "") return execPath;
|
|
12433
|
-
const candidate =
|
|
12717
|
+
const candidate = join4(resolve(runtimeDir, "../../.."), "DeepSeek Harness.exe");
|
|
12434
12718
|
return exists(candidate) ? candidate : execPath;
|
|
12435
12719
|
}
|
|
12436
12720
|
var RESTART_TASK_NAME = "DSH-MCviseron-Restart";
|
|
12437
12721
|
var RESTART_DELAY_SECONDS = 6;
|
|
12438
12722
|
function restartLogPath() {
|
|
12439
|
-
return
|
|
12723
|
+
return join4(tmpdir4(), "dsh-mcviseron-restart.log");
|
|
12440
12724
|
}
|
|
12441
12725
|
function makeTaskScript(target, taskName, delaySeconds) {
|
|
12442
12726
|
const quote = (value) => "'" + value.replace(/'/g, "''") + "'";
|
|
@@ -12477,21 +12761,21 @@ function launchHelper(target) {
|
|
|
12477
12761
|
"-Command",
|
|
12478
12762
|
makeTaskScript(target, RESTART_TASK_NAME, RESTART_DELAY_SECONDS)
|
|
12479
12763
|
], { windowsHide: true, timeout: 2e4, encoding: "utf8" });
|
|
12480
|
-
|
|
12764
|
+
appendFileSync4(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: scheduled ${target.exePath} in ${RESTART_DELAY_SECONDS}s
|
|
12481
12765
|
`, "utf8");
|
|
12482
12766
|
} catch (error) {
|
|
12483
12767
|
const message = error instanceof Error ? error.message : String(error);
|
|
12484
|
-
|
|
12768
|
+
appendFileSync4(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: task registration failed: ${message}
|
|
12485
12769
|
`, "utf8");
|
|
12486
12770
|
throw new Error("cannot schedule the restart task: " + message, { cause: error });
|
|
12487
12771
|
}
|
|
12488
12772
|
setTimeout(() => {
|
|
12489
12773
|
try {
|
|
12490
12774
|
process.kill(target.mainPid);
|
|
12491
|
-
|
|
12775
|
+
appendFileSync4(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill sent to ${target.mainPid}
|
|
12492
12776
|
`, "utf8");
|
|
12493
12777
|
} catch (error) {
|
|
12494
|
-
|
|
12778
|
+
appendFileSync4(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill failed: ${error instanceof Error ? error.message : String(error)}
|
|
12495
12779
|
`, "utf8");
|
|
12496
12780
|
}
|
|
12497
12781
|
}, 700);
|
|
@@ -12558,7 +12842,7 @@ function makeRestartRoutes(deps) {
|
|
|
12558
12842
|
return [status, execute];
|
|
12559
12843
|
}
|
|
12560
12844
|
var inject3 = ["webServer"];
|
|
12561
|
-
function
|
|
12845
|
+
function apply5(ctx, config) {
|
|
12562
12846
|
const plain = toPlain(config) ?? {};
|
|
12563
12847
|
if (plain.enabled === false) return;
|
|
12564
12848
|
const appPath = typeof plain.appPath === "string" ? plain.appPath : "";
|
|
@@ -12579,7 +12863,7 @@ var session_end_exports = {};
|
|
|
12579
12863
|
__export(session_end_exports, {
|
|
12580
12864
|
Config: () => Config4,
|
|
12581
12865
|
DEFAULT_SESSION_END_CONFIG: () => DEFAULT_SESSION_END_CONFIG,
|
|
12582
|
-
apply: () =>
|
|
12866
|
+
apply: () => apply6,
|
|
12583
12867
|
createSessionEndController: () => createSessionEndController,
|
|
12584
12868
|
inject: () => inject4,
|
|
12585
12869
|
inspectRunningTasks: () => inspectRunningTasks,
|
|
@@ -12589,14 +12873,14 @@ __export(session_end_exports, {
|
|
|
12589
12873
|
shutdownComputer: () => shutdownComputer
|
|
12590
12874
|
});
|
|
12591
12875
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
12592
|
-
import { appendFileSync as
|
|
12593
|
-
import { tmpdir as
|
|
12594
|
-
import { join as
|
|
12876
|
+
import { appendFileSync as appendFileSync5, existsSync as existsSync2 } from "node:fs";
|
|
12877
|
+
import { tmpdir as tmpdir5 } from "node:os";
|
|
12878
|
+
import { join as join5 } from "node:path";
|
|
12595
12879
|
import z4 from "@deepseek-ai/schemastery";
|
|
12596
12880
|
|
|
12597
12881
|
// src/session-end/email.ts
|
|
12598
12882
|
var import_nodemailer = __toESM(require_nodemailer(), 1);
|
|
12599
|
-
function
|
|
12883
|
+
function text2(value) {
|
|
12600
12884
|
return typeof value === "string" ? value.trim() : "";
|
|
12601
12885
|
}
|
|
12602
12886
|
function readNumber(value, fallback) {
|
|
@@ -12608,11 +12892,11 @@ function emailNotifyConfigFromView(view) {
|
|
|
12608
12892
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
12609
12893
|
const source = value;
|
|
12610
12894
|
if (source.enabled === false) return void 0;
|
|
12611
|
-
const smtpHost =
|
|
12612
|
-
const smtpUser =
|
|
12613
|
-
const smtpPassword =
|
|
12614
|
-
const mailTo =
|
|
12615
|
-
const mailFrom =
|
|
12895
|
+
const smtpHost = text2(source.smtpHost);
|
|
12896
|
+
const smtpUser = text2(source.smtpUser);
|
|
12897
|
+
const smtpPassword = text2(source.smtpPassword);
|
|
12898
|
+
const mailTo = text2(source.mailTo);
|
|
12899
|
+
const mailFrom = text2(source.mailFrom) || smtpUser;
|
|
12616
12900
|
if (smtpHost === "" || smtpUser === "" || smtpPassword === "" || mailTo === "" || mailFrom === "") return void 0;
|
|
12617
12901
|
return {
|
|
12618
12902
|
smtpHost,
|
|
@@ -12723,11 +13007,11 @@ function isSessionEndMode(value) {
|
|
|
12723
13007
|
return value === "off" || value === "restart" || value === "close" || value === "shutdown";
|
|
12724
13008
|
}
|
|
12725
13009
|
function sessionLogPath() {
|
|
12726
|
-
return
|
|
13010
|
+
return join5(tmpdir5(), "dsh-mcviseron-session-end.log");
|
|
12727
13011
|
}
|
|
12728
13012
|
function defaultLog(message) {
|
|
12729
13013
|
try {
|
|
12730
|
-
|
|
13014
|
+
appendFileSync5(sessionLogPath(), (/* @__PURE__ */ new Date()).toISOString() + " " + message + "\n", "utf8");
|
|
12731
13015
|
} catch {
|
|
12732
13016
|
}
|
|
12733
13017
|
}
|
|
@@ -12787,7 +13071,7 @@ function createSessionEndController(deps = {}) {
|
|
|
12787
13071
|
const enabled = deps.enabled ?? true;
|
|
12788
13072
|
const graceMs = deps.graceMs ?? GRACE_MS;
|
|
12789
13073
|
const pollMs = deps.pollMs ?? POLL_MS;
|
|
12790
|
-
const
|
|
13074
|
+
const log2 = deps.log ?? defaultLog;
|
|
12791
13075
|
const entries = /* @__PURE__ */ new Map();
|
|
12792
13076
|
const timers = /* @__PURE__ */ new Map();
|
|
12793
13077
|
let dispatching = false;
|
|
@@ -12856,7 +13140,7 @@ function createSessionEndController(deps = {}) {
|
|
|
12856
13140
|
if (mode === "restart") {
|
|
12857
13141
|
const target = resolveTarget();
|
|
12858
13142
|
if (target === void 0) {
|
|
12859
|
-
|
|
13143
|
+
log2("restart skipped: desktop app unavailable (session " + sessionId + ")");
|
|
12860
13144
|
return;
|
|
12861
13145
|
}
|
|
12862
13146
|
restart(target);
|
|
@@ -12866,7 +13150,7 @@ function createSessionEndController(deps = {}) {
|
|
|
12866
13150
|
shutdown();
|
|
12867
13151
|
}
|
|
12868
13152
|
} catch (error) {
|
|
12869
|
-
|
|
13153
|
+
log2(mode + " failed (session " + sessionId + "): " + (error instanceof Error ? error.message : String(error)));
|
|
12870
13154
|
}
|
|
12871
13155
|
};
|
|
12872
13156
|
const pump = (sessionId) => {
|
|
@@ -12877,7 +13161,7 @@ function createSessionEndController(deps = {}) {
|
|
|
12877
13161
|
try {
|
|
12878
13162
|
tasks = hasRunningTasks();
|
|
12879
13163
|
} catch (error) {
|
|
12880
|
-
|
|
13164
|
+
log2("task inspection failed (session " + sessionId + "): " + (error instanceof Error ? error.message : String(error)));
|
|
12881
13165
|
tasks = { running: false, agents: 0, jobs: 0 };
|
|
12882
13166
|
}
|
|
12883
13167
|
if (tasks.running) {
|
|
@@ -13031,7 +13315,7 @@ function makeSessionEndRoutes(controller) {
|
|
|
13031
13315
|
};
|
|
13032
13316
|
return [state, set, global];
|
|
13033
13317
|
}
|
|
13034
|
-
function
|
|
13318
|
+
function serviceOf4(ctx, name) {
|
|
13035
13319
|
try {
|
|
13036
13320
|
const direct = ctx[name];
|
|
13037
13321
|
if (direct !== void 0) return direct;
|
|
@@ -13049,7 +13333,7 @@ function installGuidance(ctx) {
|
|
|
13049
13333
|
if (typeof inject5 !== "function") return;
|
|
13050
13334
|
try {
|
|
13051
13335
|
inject5.call(ctx, ["systemPrompt"], (scope) => {
|
|
13052
|
-
const systemPrompt =
|
|
13336
|
+
const systemPrompt = serviceOf4(scope, "systemPrompt");
|
|
13053
13337
|
if (systemPrompt === void 0 || typeof systemPrompt.section !== "function") return;
|
|
13054
13338
|
try {
|
|
13055
13339
|
systemPrompt.section({
|
|
@@ -13066,12 +13350,12 @@ function installGuidance(ctx) {
|
|
|
13066
13350
|
}
|
|
13067
13351
|
}
|
|
13068
13352
|
var emailed = /* @__PURE__ */ new Map();
|
|
13069
|
-
function installAgentTool(ctx, controller, options,
|
|
13353
|
+
function installAgentTool(ctx, controller, options, log2) {
|
|
13070
13354
|
const inject5 = ctx.inject;
|
|
13071
13355
|
if (typeof inject5 !== "function") return;
|
|
13072
13356
|
try {
|
|
13073
13357
|
inject5.call(ctx, ["tools"], (scope) => {
|
|
13074
|
-
const tools =
|
|
13358
|
+
const tools = serviceOf4(scope, "tools");
|
|
13075
13359
|
if (tools === void 0 || typeof tools.register !== "function") return;
|
|
13076
13360
|
const definition = {
|
|
13077
13361
|
name: "set_session_end_action",
|
|
@@ -13136,7 +13420,7 @@ function installAgentTool(ctx, controller, options, log) {
|
|
|
13136
13420
|
let label = typeof title === "string" && title !== "" ? title : "";
|
|
13137
13421
|
if (label === "") {
|
|
13138
13422
|
try {
|
|
13139
|
-
const titles =
|
|
13423
|
+
const titles = serviceOf4(ctx, "sessionTitle");
|
|
13140
13424
|
const snapshot = titles?.get?.(session);
|
|
13141
13425
|
const folded = snapshot !== null && typeof snapshot === "object" ? snapshot.title : void 0;
|
|
13142
13426
|
if (typeof folded === "string" && folded !== "") label = folded;
|
|
@@ -13152,16 +13436,16 @@ function installAgentTool(ctx, controller, options, log) {
|
|
|
13152
13436
|
emailed.set(key, now);
|
|
13153
13437
|
const sessionName = label === "" ? sessionId : label;
|
|
13154
13438
|
void sendSessionEndEmail({
|
|
13155
|
-
settings:
|
|
13439
|
+
settings: serviceOf4(ctx, "settings"),
|
|
13156
13440
|
template: options,
|
|
13157
13441
|
sessionId,
|
|
13158
13442
|
sessionName,
|
|
13159
13443
|
action,
|
|
13160
13444
|
reason: typeof args.reason === "string" ? args.reason : ""
|
|
13161
13445
|
}).then((result) => {
|
|
13162
|
-
if (!result.sent)
|
|
13446
|
+
if (!result.sent) log2("email reminder skipped: " + (result.reason ?? "unknown"));
|
|
13163
13447
|
}).catch((error) => {
|
|
13164
|
-
|
|
13448
|
+
log2("email reminder failed: " + (error instanceof Error ? error.message : String(error)));
|
|
13165
13449
|
});
|
|
13166
13450
|
}
|
|
13167
13451
|
}
|
|
@@ -13188,7 +13472,7 @@ function installAgentTool(ctx, controller, options, log) {
|
|
|
13188
13472
|
defaultLog("tool injection failed: " + (error instanceof Error ? error.message : String(error)));
|
|
13189
13473
|
}
|
|
13190
13474
|
}
|
|
13191
|
-
function
|
|
13475
|
+
function sessionIdOf3(session) {
|
|
13192
13476
|
const id = session?.id;
|
|
13193
13477
|
return typeof id === "string" ? id : "";
|
|
13194
13478
|
}
|
|
@@ -13211,14 +13495,14 @@ function normalizeSessionEndOptions(input) {
|
|
|
13211
13495
|
};
|
|
13212
13496
|
}
|
|
13213
13497
|
var inject4 = ["webServer"];
|
|
13214
|
-
function
|
|
13498
|
+
function apply6(ctx, config) {
|
|
13215
13499
|
const options = normalizeSessionEndOptions(config);
|
|
13216
|
-
const
|
|
13500
|
+
const log2 = defaultLog;
|
|
13217
13501
|
const controller = createSessionEndController({
|
|
13218
13502
|
enabled: options.enabled,
|
|
13219
13503
|
graceMs: options.graceMs,
|
|
13220
13504
|
appPath: options.appPath,
|
|
13221
|
-
hasRunningTasks: () => inspectRunningTasks(
|
|
13505
|
+
hasRunningTasks: () => inspectRunningTasks(serviceOf4(ctx, "agents"), serviceOf4(ctx, "jobs"))
|
|
13222
13506
|
});
|
|
13223
13507
|
const routes = makeSessionEndRoutes(controller);
|
|
13224
13508
|
ctx.effect(() => {
|
|
@@ -13233,7 +13517,7 @@ function apply5(ctx, config) {
|
|
|
13233
13517
|
if (typeof eventBus.on === "function") {
|
|
13234
13518
|
ctx.effect(() => {
|
|
13235
13519
|
const dispose = eventBus.on?.("session/event", (session, event) => {
|
|
13236
|
-
const sessionId =
|
|
13520
|
+
const sessionId = sessionIdOf3(session);
|
|
13237
13521
|
if (sessionId === "") return;
|
|
13238
13522
|
if (event?.type === "turn/start") controller.onTurnStart(sessionId);
|
|
13239
13523
|
else if (event?.type === "turn/end") controller.onTurnEnd(sessionId);
|
|
@@ -13244,7 +13528,7 @@ function apply5(ctx, config) {
|
|
|
13244
13528
|
}, "mcviseron-session-end: session events");
|
|
13245
13529
|
}
|
|
13246
13530
|
installGuidance(ctx);
|
|
13247
|
-
installAgentTool(ctx, controller, options,
|
|
13531
|
+
installAgentTool(ctx, controller, options, log2);
|
|
13248
13532
|
}
|
|
13249
13533
|
try {
|
|
13250
13534
|
ctx.effect(() => () => controller.dispose(), "mcviseron-session-end: timers");
|
|
@@ -13257,7 +13541,7 @@ var task_guard_exports = {};
|
|
|
13257
13541
|
__export(task_guard_exports, {
|
|
13258
13542
|
Config: () => Config5,
|
|
13259
13543
|
DEFAULT_TASK_GUARD_CONFIG: () => DEFAULT_TASK_GUARD_CONFIG,
|
|
13260
|
-
apply: () =>
|
|
13544
|
+
apply: () => apply7
|
|
13261
13545
|
});
|
|
13262
13546
|
import z5 from "@deepseek-ai/schemastery";
|
|
13263
13547
|
|
|
@@ -13281,8 +13565,8 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
13281
13565
|
"translateTodoContent",
|
|
13282
13566
|
"todoTranslationTimeoutMs"
|
|
13283
13567
|
]);
|
|
13284
|
-
function containsCjk(
|
|
13285
|
-
return /[\u3400-\u9fff\uf900-\ufaff]/.test(
|
|
13568
|
+
function containsCjk(text3) {
|
|
13569
|
+
return /[\u3400-\u9fff\uf900-\ufaff]/.test(text3);
|
|
13286
13570
|
}
|
|
13287
13571
|
function normalizeText(value) {
|
|
13288
13572
|
return value.toLowerCase().replace(/[\`*_#>\[\](){}]+/g, " ").replace(/\s+/g, " ").trim();
|
|
@@ -13306,16 +13590,16 @@ var INTENT_MARKERS = [
|
|
|
13306
13590
|
/(?:接下来|下一步|现在|然后|下面)(?:我会|我将|我要|我来|就开始|开始|准备)([^\n。;;]{2,120})/g,
|
|
13307
13591
|
/(?:接下来|下一步|现在|然后|下面)(?:开始|进行|做|处理|继续|检查|运行|绘制|布局|布线|导出|放置|连接)([^\n。;;]{2,120})/g
|
|
13308
13592
|
];
|
|
13309
|
-
function intentPhrases(
|
|
13593
|
+
function intentPhrases(text3) {
|
|
13310
13594
|
const found = [];
|
|
13311
13595
|
for (const marker of INTENT_MARKERS) {
|
|
13312
13596
|
marker.lastIndex = 0;
|
|
13313
|
-
let match = marker.exec(
|
|
13597
|
+
let match = marker.exec(text3);
|
|
13314
13598
|
while (match !== null) {
|
|
13315
13599
|
const raw = (match[1] ?? "").trim();
|
|
13316
13600
|
const phrase = raw.replace(/^[::,\-\s]+/, "").split(/[.。!!??;;\n]/)[0].trim();
|
|
13317
13601
|
if (phrase.length >= 2) found.push({ index: match.index, phrase });
|
|
13318
|
-
match = marker.exec(
|
|
13602
|
+
match = marker.exec(text3);
|
|
13319
13603
|
}
|
|
13320
13604
|
}
|
|
13321
13605
|
found.sort((left, right) => left.index - right.index);
|
|
@@ -13339,9 +13623,9 @@ function phasesOf(value) {
|
|
|
13339
13623
|
for (const { id, pattern } of PHASE_PATTERNS) if (pattern.test(value)) phases.add(id);
|
|
13340
13624
|
return phases;
|
|
13341
13625
|
}
|
|
13342
|
-
function detectStepIntent(
|
|
13343
|
-
if (
|
|
13344
|
-
const phrases = intentPhrases(
|
|
13626
|
+
function detectStepIntent(text3, todos) {
|
|
13627
|
+
if (text3.length === 0 || todos.length === 0) return void 0;
|
|
13628
|
+
const phrases = intentPhrases(text3).slice(-3);
|
|
13345
13629
|
if (phrases.length === 0) return void 0;
|
|
13346
13630
|
let best;
|
|
13347
13631
|
for (const phrase of phrases) {
|
|
@@ -13379,13 +13663,13 @@ var COMPLETION_PATTERNS = [
|
|
|
13379
13663
|
function isCompletionSentence(sentence) {
|
|
13380
13664
|
return COMPLETION_PATTERNS.some((pattern) => pattern.test(sentence));
|
|
13381
13665
|
}
|
|
13382
|
-
function detectCompletion(
|
|
13383
|
-
if (
|
|
13666
|
+
function detectCompletion(text3, todos) {
|
|
13667
|
+
if (text3.length === 0 || todos.length === 0) return void 0;
|
|
13384
13668
|
const active = todos.filter((todo) => todo.status === "in_progress");
|
|
13385
13669
|
if (active.length > 1) return void 0;
|
|
13386
13670
|
const pool = active.length === 1 ? active : todos.filter((todo) => todo.status === "pending");
|
|
13387
13671
|
if (pool.length === 0) return void 0;
|
|
13388
|
-
const sentences =
|
|
13672
|
+
const sentences = text3.split(/(?<=[.!?。!?])\s+|\n+/).map((sentence) => sentence.trim()).filter((sentence) => sentence.length > 0);
|
|
13389
13673
|
for (const sentence of sentences) {
|
|
13390
13674
|
if (!isCompletionSentence(sentence)) continue;
|
|
13391
13675
|
const sentencePhases = phasesOf(sentence);
|
|
@@ -13420,7 +13704,7 @@ function completionPayload(todos, matched) {
|
|
|
13420
13704
|
}));
|
|
13421
13705
|
return JSON.stringify({ todos: updated });
|
|
13422
13706
|
}
|
|
13423
|
-
function
|
|
13707
|
+
function serviceOf5(scope, name) {
|
|
13424
13708
|
try {
|
|
13425
13709
|
const direct = scope[name];
|
|
13426
13710
|
if (direct !== void 0) return direct;
|
|
@@ -13449,7 +13733,7 @@ function sessionRoute2(agent) {
|
|
|
13449
13733
|
}
|
|
13450
13734
|
function noticeContext(agent, config, ctx) {
|
|
13451
13735
|
const route = sessionRoute2(agent);
|
|
13452
|
-
const llm =
|
|
13736
|
+
const llm = serviceOf5(ctx, "llm");
|
|
13453
13737
|
return {
|
|
13454
13738
|
llm,
|
|
13455
13739
|
route,
|
|
@@ -13484,16 +13768,16 @@ async function translateBatch(contents, context) {
|
|
|
13484
13768
|
signal: controller.signal
|
|
13485
13769
|
});
|
|
13486
13770
|
if (stream === null || typeof stream !== "object") return void 0;
|
|
13487
|
-
let
|
|
13771
|
+
let text3 = "";
|
|
13488
13772
|
for await (const chunk of stream) {
|
|
13489
13773
|
if (controller.signal.aborted) return void 0;
|
|
13490
|
-
if (chunk?.type === "text-delta" && typeof chunk.text === "string")
|
|
13774
|
+
if (chunk?.type === "text-delta" && typeof chunk.text === "string") text3 += chunk.text;
|
|
13491
13775
|
if (chunk?.type === "finish") {
|
|
13492
13776
|
const kind = chunk.reason?.kind;
|
|
13493
13777
|
if (typeof kind === "string" && kind !== "stop") return void 0;
|
|
13494
13778
|
}
|
|
13495
13779
|
}
|
|
13496
|
-
const parsed = parseStringArray(
|
|
13780
|
+
const parsed = parseStringArray(text3);
|
|
13497
13781
|
if (parsed === void 0 || parsed.length !== contents.length) return void 0;
|
|
13498
13782
|
return parsed;
|
|
13499
13783
|
} catch {
|
|
@@ -13567,7 +13851,7 @@ function installTaskGuard(ctx, input) {
|
|
|
13567
13851
|
return next();
|
|
13568
13852
|
}
|
|
13569
13853
|
if (config.blockAfterCalls > 0 && exec.parent === void 0 && isTracked(exec.name, config)) {
|
|
13570
|
-
const state = sessions.get(
|
|
13854
|
+
const state = sessions.get(sessionIdOf4(exec.agent));
|
|
13571
13855
|
if (state?.todos != null && hasUnfinished(state.todos) && state.callsSinceWrite >= config.blockAfterCalls) {
|
|
13572
13856
|
return { kind: "deny", reason: denyStale(state, config) };
|
|
13573
13857
|
}
|
|
@@ -13581,7 +13865,7 @@ function installTaskGuard(ctx, input) {
|
|
|
13581
13865
|
if (result.isError) return downstream;
|
|
13582
13866
|
const todos = readTodos(exec.arguments);
|
|
13583
13867
|
if (todos === null) return downstream;
|
|
13584
|
-
const sessionId2 =
|
|
13868
|
+
const sessionId2 = sessionIdOf4(exec.agent);
|
|
13585
13869
|
if (sessionId2 !== "") {
|
|
13586
13870
|
resetState(sessions, sessionId2, todos);
|
|
13587
13871
|
intentBuffers.delete(sessionId2);
|
|
@@ -13598,7 +13882,7 @@ function installTaskGuard(ctx, input) {
|
|
|
13598
13882
|
return downstream;
|
|
13599
13883
|
}
|
|
13600
13884
|
if (exec.parent !== void 0 || result.isError || !isTracked(exec.name, config)) return downstream;
|
|
13601
|
-
const sessionId =
|
|
13885
|
+
const sessionId = sessionIdOf4(exec.agent);
|
|
13602
13886
|
if (sessionId === "") return downstream;
|
|
13603
13887
|
const state = sessions.get(sessionId);
|
|
13604
13888
|
if (state?.todos == null || !hasUnfinished(state.todos)) return downstream;
|
|
@@ -13646,7 +13930,7 @@ function installTaskGuard(ctx, input) {
|
|
|
13646
13930
|
return attachContext(downstream, reminder);
|
|
13647
13931
|
});
|
|
13648
13932
|
bus.on("agent/pre-step", async (payload, next) => {
|
|
13649
|
-
const sessionId =
|
|
13933
|
+
const sessionId = sessionIdOf4(payload.agent);
|
|
13650
13934
|
if (sessionId !== "") intentBuffers.delete(sessionId);
|
|
13651
13935
|
const state = sessions.get(sessionId);
|
|
13652
13936
|
if (state !== void 0) {
|
|
@@ -13671,7 +13955,7 @@ function installTaskGuard(ctx, input) {
|
|
|
13671
13955
|
intentBuffers.set(sessionId, next);
|
|
13672
13956
|
});
|
|
13673
13957
|
bus.on("session/event", (session, event) => {
|
|
13674
|
-
const sessionId =
|
|
13958
|
+
const sessionId = sessionIdOf4({ session });
|
|
13675
13959
|
if (sessionId === "") return;
|
|
13676
13960
|
if (event.type === "turn/start" || event.type === "turn/end") {
|
|
13677
13961
|
sessions.delete(sessionId);
|
|
@@ -13796,7 +14080,7 @@ function resetState(sessions, sessionId, todos) {
|
|
|
13796
14080
|
intentNotifiedThisStep: false
|
|
13797
14081
|
});
|
|
13798
14082
|
}
|
|
13799
|
-
function
|
|
14083
|
+
function sessionIdOf4(agent) {
|
|
13800
14084
|
const id = agent?.session?.id;
|
|
13801
14085
|
return typeof id === "string" && id !== "" ? id : "";
|
|
13802
14086
|
}
|
|
@@ -13828,8 +14112,8 @@ async function noticeMissingActive(todos, config, sourceKind, context) {
|
|
|
13828
14112
|
const quoted = remaining.slice(0, config.maxListItems).map((todo, index) => (todo.status === "in_progress" ? "[~] " : "[ ] ") + truncate(display[index], 60)).join("\n");
|
|
13829
14113
|
const omitted = remaining.length - config.maxListItems;
|
|
13830
14114
|
const items = omitted > 0 ? quoted + "\n\u2026 +" + omitted : quoted;
|
|
13831
|
-
const
|
|
13832
|
-
return createNotice(
|
|
14115
|
+
const text3 = config.locale === "en" ? (completed ? "[Todo sync] A task was marked completed, but " + pending + " task(s) remain pending and no task is in_progress. Mark the next task in_progress before continuing, or clear the list / mark everything completed if this work is finished." : "[Todo sync] No task is in_progress while " + pending + " task(s) are pending. Mark the task you are about to start as in_progress.") + "\n\nRemaining:\n" + items + "\n\n(Tip: todo titles can be written in Chinese.)" : (completed ? "\u3010todo \u540C\u6B65\u3011\u5DF2\u6709\u4EFB\u52A1\u88AB\u6807\u4E3A completed\uFF0C\u4F46\u6E05\u5355\u91CC\u8FD8\u6709 " + pending + " \u4E2A\u5F85\u529E\uFF0C\u4E14\u6CA1\u6709\u4EFB\u4F55 in_progress \u4EFB\u52A1\u3002\u7EE7\u7EED\u4E4B\u524D\u8BF7\u628A\u4E0B\u4E00\u9636\u6BB5\u6807\u4E3A in_progress\uFF1B\u5982\u679C\u672C\u6B21\u5DE5\u4F5C\u5DF2\u7ECF\u7ED3\u675F\uFF0C\u8BF7\u6E05\u7A7A\u6E05\u5355\u6216\u628A\u4EFB\u52A1\u5168\u90E8\u6807\u4E3A completed\u3002" : "\u3010todo \u540C\u6B65\u3011\u6E05\u5355\u91CC\u8FD8\u6709 " + pending + " \u4E2A\u5F85\u529E\uFF0C\u4F46\u8FD8\u6CA1\u6709\u4EFB\u4F55 in_progress \u4EFB\u52A1\u3002\u8BF7\u628A\u5373\u5C06\u5F00\u59CB\u7684\u9636\u6BB5\u6807\u4E3A in_progress\u3002") + "\n\n\u5269\u4F59\uFF1A\n" + items + "\n\n\uFF08\u63D0\u793A\uFF1Atodo \u5185\u5BB9\u53EF\u4EE5\u76F4\u63A5\u7528\u4E2D\u6587\u4E66\u5199\u3002\uFF09";
|
|
14116
|
+
return createNotice(text3, config.locale === "en" ? "todo has no active task" : "todo \u6CA1\u6709\u8FDB\u884C\u4E2D\u4EFB\u52A1", sourceKind);
|
|
13833
14117
|
}
|
|
13834
14118
|
function denyStale(state, config) {
|
|
13835
14119
|
if (config.locale === "en") {
|
|
@@ -13851,7 +14135,7 @@ async function buildReminder(state, config, sourceKind, context) {
|
|
|
13851
14135
|
const items = omitted > 0 ? quoted + "\n\u2026 +" + omitted : quoted;
|
|
13852
14136
|
const activeOne = active.length === 1 ? active[0] : void 0;
|
|
13853
14137
|
const suggested = activeOne === void 0 ? void 0 : completionPayload(todos, activeOne);
|
|
13854
|
-
const
|
|
14138
|
+
const text3 = config.locale === "en" ? [
|
|
13855
14139
|
"[Todo sync] " + state.callsSinceWrite + " tool calls have run since the last todo_write.",
|
|
13856
14140
|
"In progress: " + activeText,
|
|
13857
14141
|
"Remaining:\n" + items,
|
|
@@ -13867,14 +14151,14 @@ async function buildReminder(state, config, sourceKind, context) {
|
|
|
13867
14151
|
"\uFF08\u63D0\u793A\uFF1Atodo \u5185\u5BB9\u53EF\u4EE5\u76F4\u63A5\u7528\u4E2D\u6587\u4E66\u5199\u3002\uFF09"
|
|
13868
14152
|
].filter((line) => line !== "").join("\n");
|
|
13869
14153
|
const summary = config.locale === "en" ? "todo stale \xB7 " + state.callsSinceWrite + " calls" : "todo \u672A\u66F4\u65B0 \xB7 " + state.callsSinceWrite + " \u6B21\u8C03\u7528";
|
|
13870
|
-
return createNotice(
|
|
14154
|
+
return createNotice(text3, summary, sourceKind);
|
|
13871
14155
|
}
|
|
13872
14156
|
async function buildCompletionNotice(state, match, config, sourceKind, context) {
|
|
13873
14157
|
const todos = state.todos ?? [];
|
|
13874
14158
|
const [display] = await displayTodoContents([match.todo.content], context);
|
|
13875
14159
|
const suggested = completionPayload(todos, match.todo);
|
|
13876
14160
|
const phrase = truncate(match.phrase, 80);
|
|
13877
|
-
const
|
|
14161
|
+
const text3 = config.locale === "en" ? [
|
|
13878
14162
|
'[Todo sync] The assistant text looks like a completed phase: "' + display + '".',
|
|
13879
14163
|
"Source: " + phrase,
|
|
13880
14164
|
suggested === void 0 ? "If that phase is finished, call todo_write: mark it completed and the next task in_progress." : "If that phase is finished, send this todo_write now:",
|
|
@@ -13890,14 +14174,14 @@ async function buildCompletionNotice(state, match, config, sourceKind, context)
|
|
|
13890
14174
|
"\uFF08\u63D0\u793A\uFF1Atodo \u5185\u5BB9\u53EF\u4EE5\u76F4\u63A5\u7528\u4E2D\u6587\u4E66\u5199\u3002\uFF09"
|
|
13891
14175
|
].filter((line) => line !== "").join("\n");
|
|
13892
14176
|
const summary = config.locale === "en" ? "todo complete \xB7 " + truncate(display, 40) : "todo \u5B8C\u6210 \xB7 " + truncate(display, 40);
|
|
13893
|
-
return createNotice(
|
|
14177
|
+
return createNotice(text3, summary, sourceKind);
|
|
13894
14178
|
}
|
|
13895
14179
|
async function buildIntentNotice(state, match, config, sourceKind, context) {
|
|
13896
14180
|
const todos = state.todos ?? [];
|
|
13897
14181
|
const [display] = await displayTodoContents([match.todo.content], context);
|
|
13898
14182
|
const suggested = suggestedTodoPayload(todos, match.todo);
|
|
13899
14183
|
const phrase = truncate(match.phrase, 60);
|
|
13900
|
-
const
|
|
14184
|
+
const text3 = config.locale === "en" ? [
|
|
13901
14185
|
'[Todo sync] Your reasoning says "' + phrase + '", which matches the pending todo "' + display + '", but that task is not in_progress.',
|
|
13902
14186
|
suggested === void 0 ? "Mark it in_progress before continuing and keep the finished phase completed." : "If the previous phase is done, send this todo_write now:",
|
|
13903
14187
|
suggested ?? "",
|
|
@@ -13909,18 +14193,18 @@ async function buildIntentNotice(state, match, config, sourceKind, context) {
|
|
|
13909
14193
|
"\uFF08\u63D0\u793A\uFF1Atodo \u5185\u5BB9\u53EF\u4EE5\u76F4\u63A5\u7528\u4E2D\u6587\u4E66\u5199\u3002\uFF09"
|
|
13910
14194
|
].filter((line) => line !== "").join("\n");
|
|
13911
14195
|
const summary = config.locale === "en" ? "todo intent \xB7 " + truncate(phrase, 40) : "todo \u610F\u56FE \xB7 " + truncate(phrase, 40);
|
|
13912
|
-
return createNotice(
|
|
14196
|
+
return createNotice(text3, summary, sourceKind);
|
|
13913
14197
|
}
|
|
13914
14198
|
function truncate(value, max) {
|
|
13915
14199
|
return value.length <= max ? value : `${value.slice(0, max - 1)}\u2026`;
|
|
13916
14200
|
}
|
|
13917
|
-
function createNotice(
|
|
14201
|
+
function createNotice(text3, summary, sourceKind) {
|
|
13918
14202
|
const boundedSummary = summary.length <= SUMMARY_MAX_CHARS ? summary : `${summary.slice(0, SUMMARY_MAX_CHARS - 1)}\u2026`;
|
|
13919
14203
|
const source = sourceKind === "v3" ? { kind: "plugin", plugin: "task-guard", form: "notice", summary: boundedSummary } : { kind: "plugin:task-guard", form: "notice", summary: boundedSummary };
|
|
13920
14204
|
return deepFreeze({
|
|
13921
14205
|
id: randomUUID2(),
|
|
13922
14206
|
role: "user",
|
|
13923
|
-
content: [{ type: "text", text:
|
|
14207
|
+
content: [{ type: "text", text: text3 }],
|
|
13924
14208
|
source
|
|
13925
14209
|
});
|
|
13926
14210
|
}
|
|
@@ -13969,7 +14253,7 @@ var Config5 = z5.object({
|
|
|
13969
14253
|
include: z5.array(z5.string()).default(DEFAULT_TASK_GUARD_CONFIG.include).volatile(),
|
|
13970
14254
|
exclude: z5.array(z5.string()).default(DEFAULT_TASK_GUARD_CONFIG.exclude).volatile()
|
|
13971
14255
|
}).default(DEFAULT_TASK_GUARD_CONFIG);
|
|
13972
|
-
function
|
|
14256
|
+
function apply7(ctx, config) {
|
|
13973
14257
|
installTaskGuard(ctx, toPlain(config));
|
|
13974
14258
|
}
|
|
13975
14259
|
|
|
@@ -13999,8 +14283,9 @@ function mount(ctx, component, config) {
|
|
|
13999
14283
|
logger?.warn?.(new Error("mcviseron: cannot mount a component", { cause: error }));
|
|
14000
14284
|
}
|
|
14001
14285
|
}
|
|
14002
|
-
function
|
|
14286
|
+
function apply8(ctx, rawConfig) {
|
|
14003
14287
|
const config = toPlain(rawConfig) ?? {};
|
|
14288
|
+
mount(ctx, automation_tasks_exports, {});
|
|
14004
14289
|
mount(ctx, auth_cookie_exports, {});
|
|
14005
14290
|
mount(ctx, appearance_exports, {
|
|
14006
14291
|
enabled: config.enabled ?? DEFAULT_SCHEDULE_CONFIG.enabled,
|
|
@@ -14019,5 +14304,5 @@ function apply7(ctx, rawConfig) {
|
|
|
14019
14304
|
}
|
|
14020
14305
|
export {
|
|
14021
14306
|
Config6 as Config,
|
|
14022
|
-
|
|
14307
|
+
apply8 as apply
|
|
14023
14308
|
};
|