@eworkbase/plugin-ai-rules 0.3.6 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin.mjs +695 -101
- package/dist/ui/index.html +1 -1
- package/dist/ui/main.js +26 -26
- package/dist/ui/style.css +695 -18
- package/package.json +6 -6
package/dist/plugin.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, rmdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, rmdirSync, writeFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
4
5
|
import os from "node:os";
|
|
5
6
|
import { isDeepStrictEqual } from "node:util";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
8
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
9
9
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
@@ -1029,7 +1029,7 @@ function timeSource(args) {
|
|
|
1029
1029
|
function time(args) {
|
|
1030
1030
|
return new RegExp(`^${timeSource(args)}$`);
|
|
1031
1031
|
}
|
|
1032
|
-
function datetime(args) {
|
|
1032
|
+
function datetime$1(args) {
|
|
1033
1033
|
const opts = ["Z"];
|
|
1034
1034
|
if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
|
1035
1035
|
const qualified = `${timeSource({
|
|
@@ -1680,7 +1680,7 @@ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
|
|
|
1680
1680
|
$ZodStringFormat.init(inst, def);
|
|
1681
1681
|
});
|
|
1682
1682
|
const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
|
|
1683
|
-
def.pattern ?? (def.pattern = datetime(def));
|
|
1683
|
+
def.pattern ?? (def.pattern = datetime$1(def));
|
|
1684
1684
|
$ZodStringFormat.init(inst, def);
|
|
1685
1685
|
});
|
|
1686
1686
|
const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
|
|
@@ -2375,6 +2375,114 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2375
2375
|
result.value = merged.data;
|
|
2376
2376
|
return result;
|
|
2377
2377
|
}
|
|
2378
|
+
const $ZodTuple = /*@__PURE__*/ $constructor("$ZodTuple", (inst, def) => {
|
|
2379
|
+
$ZodType.init(inst, def);
|
|
2380
|
+
const items = def.items;
|
|
2381
|
+
const memo = globalConfig.memoizer;
|
|
2382
|
+
memo?.attach(inst);
|
|
2383
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2384
|
+
const input = payload.value;
|
|
2385
|
+
if (!Array.isArray(input)) {
|
|
2386
|
+
payload.issues.push({
|
|
2387
|
+
input,
|
|
2388
|
+
inst,
|
|
2389
|
+
expected: "tuple",
|
|
2390
|
+
code: "invalid_type"
|
|
2391
|
+
});
|
|
2392
|
+
return payload;
|
|
2393
|
+
}
|
|
2394
|
+
payload.value = memo ? memo.alloc(inst, payload, [], ctx) : [];
|
|
2395
|
+
const proms = [];
|
|
2396
|
+
const optinStart = getTupleOptStart(items, "optin");
|
|
2397
|
+
const optoutStart = getTupleOptStart(items, "optout");
|
|
2398
|
+
if (!def.rest) {
|
|
2399
|
+
if (input.length < optinStart) {
|
|
2400
|
+
payload.issues.push({
|
|
2401
|
+
code: "too_small",
|
|
2402
|
+
minimum: optinStart,
|
|
2403
|
+
inclusive: true,
|
|
2404
|
+
input,
|
|
2405
|
+
inst,
|
|
2406
|
+
origin: "array"
|
|
2407
|
+
});
|
|
2408
|
+
return payload;
|
|
2409
|
+
}
|
|
2410
|
+
if (input.length > items.length) payload.issues.push({
|
|
2411
|
+
code: "too_big",
|
|
2412
|
+
maximum: items.length,
|
|
2413
|
+
inclusive: true,
|
|
2414
|
+
input,
|
|
2415
|
+
inst,
|
|
2416
|
+
origin: "array"
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
const itemResults = new Array(items.length);
|
|
2420
|
+
const abortEarly = def.rest ? ctx?.abortEarly : void 0;
|
|
2421
|
+
let itemAborted = false;
|
|
2422
|
+
for (let i = 0; i < items.length; i++) {
|
|
2423
|
+
const r = items[i]._zod.run({
|
|
2424
|
+
value: input[i],
|
|
2425
|
+
issues: []
|
|
2426
|
+
}, ctx);
|
|
2427
|
+
if (r instanceof Promise) proms.push(r.then((rr) => {
|
|
2428
|
+
itemResults[i] = rr;
|
|
2429
|
+
}));
|
|
2430
|
+
else {
|
|
2431
|
+
itemResults[i] = r;
|
|
2432
|
+
if (abortEarly && !itemAborted && r.issues.length) itemAborted = aborted(r);
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
if (def.rest && !itemAborted) {
|
|
2436
|
+
let i = items.length - 1;
|
|
2437
|
+
const rest = input.slice(items.length);
|
|
2438
|
+
let seen = payload.issues.length;
|
|
2439
|
+
for (const el of rest) {
|
|
2440
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
2441
|
+
if (aborted(payload, seen)) break;
|
|
2442
|
+
seen = payload.issues.length;
|
|
2443
|
+
}
|
|
2444
|
+
i++;
|
|
2445
|
+
const result = def.rest._zod.run({
|
|
2446
|
+
value: el,
|
|
2447
|
+
issues: []
|
|
2448
|
+
}, ctx);
|
|
2449
|
+
if (result instanceof Promise) proms.push(result.then((r) => handleTupleResult(r, payload, i)));
|
|
2450
|
+
else handleTupleResult(result, payload, i);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
if (proms.length) return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
|
|
2454
|
+
return handleTupleResults(itemResults, payload, items, input, optoutStart);
|
|
2455
|
+
};
|
|
2456
|
+
});
|
|
2457
|
+
function getTupleOptStart(items, key) {
|
|
2458
|
+
for (let i = items.length - 1; i >= 0; i--) if (!(key === "optin" ? items[i]._zod.optin !== void 0 : items[i]._zod.optout === "optional")) return i + 1;
|
|
2459
|
+
return 0;
|
|
2460
|
+
}
|
|
2461
|
+
function handleTupleResult(result, final, index) {
|
|
2462
|
+
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
2463
|
+
final.value[index] = result.value;
|
|
2464
|
+
}
|
|
2465
|
+
function handleTupleResults(itemResults, final, items, input, optoutStart) {
|
|
2466
|
+
for (let i = 0; i < items.length; i++) {
|
|
2467
|
+
const r = itemResults[i];
|
|
2468
|
+
const isPresent = i < input.length;
|
|
2469
|
+
if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
|
|
2470
|
+
final.value.length = i;
|
|
2471
|
+
break;
|
|
2472
|
+
}
|
|
2473
|
+
if (r.issues.length) {
|
|
2474
|
+
if (!isPresent && i >= optoutStart) {
|
|
2475
|
+
final.value.length = i;
|
|
2476
|
+
break;
|
|
2477
|
+
}
|
|
2478
|
+
final.issues.push(...prefixIssues(i, r.issues));
|
|
2479
|
+
}
|
|
2480
|
+
final.value[i] = r.value;
|
|
2481
|
+
}
|
|
2482
|
+
for (let i = final.value.length - 1; i >= input.length; i--) if (items[i]._zod.optout === "optional" && final.value[i] === void 0) final.value.length = i;
|
|
2483
|
+
else break;
|
|
2484
|
+
return final;
|
|
2485
|
+
}
|
|
2378
2486
|
const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
|
|
2379
2487
|
$ZodType.init(inst, def);
|
|
2380
2488
|
const memo = globalConfig.memoizer;
|
|
@@ -4424,6 +4532,58 @@ const intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
4424
4532
|
json.allOf = allOf;
|
|
4425
4533
|
ctx.intersections.push(allOf);
|
|
4426
4534
|
};
|
|
4535
|
+
const tupleProcessor = (schema, ctx, _json, params) => {
|
|
4536
|
+
const json = _json;
|
|
4537
|
+
const def = schema._zod.def;
|
|
4538
|
+
json.type = "array";
|
|
4539
|
+
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
4540
|
+
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
4541
|
+
const prefixItems = def.items.map((x, i) => processSchema(x, ctx, {
|
|
4542
|
+
...params,
|
|
4543
|
+
path: [
|
|
4544
|
+
...params.path,
|
|
4545
|
+
prefixPath,
|
|
4546
|
+
i
|
|
4547
|
+
]
|
|
4548
|
+
}));
|
|
4549
|
+
const rest = def.rest ? processSchema(def.rest, ctx, {
|
|
4550
|
+
...params,
|
|
4551
|
+
path: [
|
|
4552
|
+
...params.path,
|
|
4553
|
+
restPath,
|
|
4554
|
+
...ctx.target === "openapi-3.0" ? [def.items.length] : []
|
|
4555
|
+
]
|
|
4556
|
+
}) : null;
|
|
4557
|
+
let minItems = def.items.length;
|
|
4558
|
+
while (minItems > 0) {
|
|
4559
|
+
const item = def.items[minItems - 1];
|
|
4560
|
+
if (!(ctx.io === "input" ? inputOptin(item) !== void 0 : item._zod.optout === "optional")) break;
|
|
4561
|
+
minItems--;
|
|
4562
|
+
}
|
|
4563
|
+
const maxItems = def.items.length;
|
|
4564
|
+
const isClosed = !def.rest;
|
|
4565
|
+
if (ctx.target === "draft-2020-12") {
|
|
4566
|
+
json.prefixItems = prefixItems;
|
|
4567
|
+
if (isClosed) json.items = false;
|
|
4568
|
+
else if (rest) json.items = rest;
|
|
4569
|
+
if (minItems > 0) json.minItems = minItems;
|
|
4570
|
+
if (isClosed) json.maxItems = maxItems;
|
|
4571
|
+
} else if (ctx.target === "openapi-3.0") {
|
|
4572
|
+
json.items = { anyOf: prefixItems };
|
|
4573
|
+
if (rest) json.items.anyOf.push(rest);
|
|
4574
|
+
if (minItems > 0) json.minItems = minItems;
|
|
4575
|
+
if (isClosed) json.maxItems = maxItems;
|
|
4576
|
+
} else {
|
|
4577
|
+
json.items = prefixItems;
|
|
4578
|
+
if (isClosed) json.additionalItems = false;
|
|
4579
|
+
else if (rest) json.additionalItems = rest;
|
|
4580
|
+
if (minItems > 0) json.minItems = minItems;
|
|
4581
|
+
if (isClosed) json.maxItems = maxItems;
|
|
4582
|
+
}
|
|
4583
|
+
const { minimum, maximum } = aggregateChecks(schema);
|
|
4584
|
+
if (typeof minimum === "number") json.minItems = minimum;
|
|
4585
|
+
if (typeof maximum === "number") json.maxItems = maximum;
|
|
4586
|
+
};
|
|
4427
4587
|
/** JSON object keys are always strings, so a numeric record key schema is re-expressed over the
|
|
4428
4588
|
* numeric-string form the record parser matches. Deferred to `finalize`, after the flatten: a key
|
|
4429
4589
|
* behind a wrapper only carries its own `type` before then, and a union key only has its branches.
|
|
@@ -5314,6 +5474,39 @@ function intersection(left, right) {
|
|
|
5314
5474
|
right
|
|
5315
5475
|
});
|
|
5316
5476
|
}
|
|
5477
|
+
const ZodTuple = /*@__PURE__*/ $constructor("ZodTuple", (inst, def) => {
|
|
5478
|
+
_ensureDefaultMemoizer();
|
|
5479
|
+
$ZodTuple.init(inst, def);
|
|
5480
|
+
ZodType.init(inst, def);
|
|
5481
|
+
inst._zod.processJSONSchema = (ctx, json, params) => tupleProcessor(inst, ctx, json, params);
|
|
5482
|
+
}, {
|
|
5483
|
+
rest(rest) {
|
|
5484
|
+
return this.clone({
|
|
5485
|
+
...this._zod.def,
|
|
5486
|
+
rest
|
|
5487
|
+
});
|
|
5488
|
+
},
|
|
5489
|
+
partial() {
|
|
5490
|
+
const def = this._zod.def;
|
|
5491
|
+
if (def.checks?.length) throw new Error(".partial() cannot be used on tuple schemas containing refinements");
|
|
5492
|
+
return this.clone({
|
|
5493
|
+
...def,
|
|
5494
|
+
items: def.items.map((item) => new ZodOptional({
|
|
5495
|
+
type: "optional",
|
|
5496
|
+
innerType: item
|
|
5497
|
+
}))
|
|
5498
|
+
});
|
|
5499
|
+
}
|
|
5500
|
+
});
|
|
5501
|
+
function tuple(items, _paramsOrRest, _params) {
|
|
5502
|
+
const hasRest = _paramsOrRest instanceof $ZodType;
|
|
5503
|
+
return new ZodTuple({
|
|
5504
|
+
type: "tuple",
|
|
5505
|
+
items,
|
|
5506
|
+
rest: hasRest ? _paramsOrRest : null,
|
|
5507
|
+
...normalizeParams(hasRest ? _params : _paramsOrRest)
|
|
5508
|
+
});
|
|
5509
|
+
}
|
|
5317
5510
|
const ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
|
|
5318
5511
|
_ensureDefaultMemoizer();
|
|
5319
5512
|
$ZodRecord.init(inst, def);
|
|
@@ -5581,6 +5774,11 @@ function json(params) {
|
|
|
5581
5774
|
return jsonSchema;
|
|
5582
5775
|
}
|
|
5583
5776
|
//#endregion
|
|
5777
|
+
//#region ../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/classic/iso.js
|
|
5778
|
+
function datetime(params) {
|
|
5779
|
+
return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
|
|
5780
|
+
}
|
|
5781
|
+
//#endregion
|
|
5584
5782
|
//#region ../plugin-sdk/dist/index.js
|
|
5585
5783
|
const PLUGIN_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
5586
5784
|
function definePlugin(definition) {
|
|
@@ -5706,6 +5904,241 @@ object({
|
|
|
5706
5904
|
applied: literal(true),
|
|
5707
5905
|
requiresPreparation: boolean()
|
|
5708
5906
|
});
|
|
5907
|
+
/** 通用执行时间线契约;内容由调用方提供,宿主校验作用域、脱敏并持久保存。 */
|
|
5908
|
+
let ExecutionLogEntryKind = /* @__PURE__ */ function(ExecutionLogEntryKind) {
|
|
5909
|
+
ExecutionLogEntryKind["Message"] = "message";
|
|
5910
|
+
ExecutionLogEntryKind["Activity"] = "activity";
|
|
5911
|
+
ExecutionLogEntryKind["Question"] = "question";
|
|
5912
|
+
ExecutionLogEntryKind["Answer"] = "answer";
|
|
5913
|
+
return ExecutionLogEntryKind;
|
|
5914
|
+
}({});
|
|
5915
|
+
const executionLogEntrySchema = object({
|
|
5916
|
+
id: string().min(1).max(160),
|
|
5917
|
+
kind: _enum(ExecutionLogEntryKind),
|
|
5918
|
+
time: datetime(),
|
|
5919
|
+
title: string().max(240),
|
|
5920
|
+
content: string().max(48e3),
|
|
5921
|
+
details: string().max(8e3).nullish(),
|
|
5922
|
+
status: string().max(64).nullish()
|
|
5923
|
+
}).strict();
|
|
5924
|
+
const executionTimingSchema = object({
|
|
5925
|
+
queuedAt: string().nullish(),
|
|
5926
|
+
startedAt: string().nullish(),
|
|
5927
|
+
finishedAt: string().nullish()
|
|
5928
|
+
});
|
|
5929
|
+
const executionIdentitySchema = object({
|
|
5930
|
+
pluginId: string(),
|
|
5931
|
+
commandId: string()
|
|
5932
|
+
});
|
|
5933
|
+
const executionContextSchema = object({ finishedAt: string().nullish() });
|
|
5934
|
+
const logStepSchema = object({
|
|
5935
|
+
id: string(),
|
|
5936
|
+
legacyId: string().optional(),
|
|
5937
|
+
label: string(),
|
|
5938
|
+
detail: string(),
|
|
5939
|
+
status: string(),
|
|
5940
|
+
executionState: string().nullish(),
|
|
5941
|
+
phase: string().nullish(),
|
|
5942
|
+
timing: executionTimingSchema.optional(),
|
|
5943
|
+
target: object({
|
|
5944
|
+
kind: string(),
|
|
5945
|
+
id: string(),
|
|
5946
|
+
label: string()
|
|
5947
|
+
}).nullish(),
|
|
5948
|
+
provider: string().nullish(),
|
|
5949
|
+
command: string().nullish(),
|
|
5950
|
+
stdout: string().nullish(),
|
|
5951
|
+
stderr: string().nullish(),
|
|
5952
|
+
manualActionMessage: string().nullish()
|
|
5953
|
+
});
|
|
5954
|
+
const logCallSchema = object({
|
|
5955
|
+
id: string(),
|
|
5956
|
+
title: string(),
|
|
5957
|
+
status: string(),
|
|
5958
|
+
createdAt: string(),
|
|
5959
|
+
operationKind: string(),
|
|
5960
|
+
hasWarnings: boolean(),
|
|
5961
|
+
context: executionContextSchema,
|
|
5962
|
+
hasChildErrors: boolean().optional(),
|
|
5963
|
+
execution: executionIdentitySchema.nullish()
|
|
5964
|
+
});
|
|
5965
|
+
object({
|
|
5966
|
+
id: string(),
|
|
5967
|
+
title: string(),
|
|
5968
|
+
entries: array(executionLogEntrySchema),
|
|
5969
|
+
steps: array(logStepSchema).optional(),
|
|
5970
|
+
children: array(logCallSchema).optional(),
|
|
5971
|
+
messages: array(object({
|
|
5972
|
+
id: string(),
|
|
5973
|
+
createdAt: string(),
|
|
5974
|
+
level: _enum([
|
|
5975
|
+
"debug",
|
|
5976
|
+
"info",
|
|
5977
|
+
"warn",
|
|
5978
|
+
"error"
|
|
5979
|
+
]),
|
|
5980
|
+
message: string()
|
|
5981
|
+
})).optional(),
|
|
5982
|
+
warnings: array(string()).optional(),
|
|
5983
|
+
createdAt: string().optional(),
|
|
5984
|
+
execution: executionIdentitySchema.nullish(),
|
|
5985
|
+
context: executionContextSchema.optional()
|
|
5986
|
+
});
|
|
5987
|
+
//#endregion
|
|
5988
|
+
//#region ../plugin-sdk/dist/markdown-link-C-qw7xuN.js
|
|
5989
|
+
const MAXIMUM_LINK_LENGTH = 4096;
|
|
5990
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/;
|
|
5991
|
+
const URL_SCHEME = /^[a-z][a-z\d+.-]*:/i;
|
|
5992
|
+
const WEBSITE_PREFIX = /^(?:https?:)?\/\//i;
|
|
5993
|
+
const MARKDOWN_EXTENSION = /\.(?:md|markdown)$/i;
|
|
5994
|
+
function parseMarkdownLink(value) {
|
|
5995
|
+
const href = value.trim();
|
|
5996
|
+
if (!href || href.length > MAXIMUM_LINK_LENGTH || CONTROL_CHARACTERS.test(value)) throw new Error("链接为空、过长或包含无效字符。");
|
|
5997
|
+
if (WEBSITE_PREFIX.test(href)) return websiteLink(href);
|
|
5998
|
+
if (URL_SCHEME.test(href) || href.includes("\\")) throw new Error("不支持此链接协议或路径格式。");
|
|
5999
|
+
const fragmentIndex = href.indexOf("#");
|
|
6000
|
+
const fragment = fragmentIndex < 0 ? "" : decodeLink(href.slice(fragmentIndex + 1));
|
|
6001
|
+
if (href.startsWith("#")) return {
|
|
6002
|
+
kind: "anchor",
|
|
6003
|
+
fragment
|
|
6004
|
+
};
|
|
6005
|
+
const pathname = decodeLink(href.split(/[?#]/, 1)[0]);
|
|
6006
|
+
if (!MARKDOWN_EXTENSION.test(pathname) || pathname.includes("\\")) throw new Error("应用内预览仅支持 Markdown 文件。");
|
|
6007
|
+
return {
|
|
6008
|
+
kind: "document",
|
|
6009
|
+
path: pathname,
|
|
6010
|
+
fragment
|
|
6011
|
+
};
|
|
6012
|
+
}
|
|
6013
|
+
function websiteLink(href) {
|
|
6014
|
+
let url;
|
|
6015
|
+
try {
|
|
6016
|
+
url = new URL(href.startsWith("//") ? "https:" + href : href);
|
|
6017
|
+
} catch {
|
|
6018
|
+
throw new Error("网页地址无效,请检查链接。");
|
|
6019
|
+
}
|
|
6020
|
+
if (!url.hostname || url.username || url.password || href.includes("\\")) throw new Error("网页地址不能包含登录凭据或无效主机。");
|
|
6021
|
+
return {
|
|
6022
|
+
kind: "website",
|
|
6023
|
+
url: url.href
|
|
6024
|
+
};
|
|
6025
|
+
}
|
|
6026
|
+
function decodeLink(value) {
|
|
6027
|
+
let decoded;
|
|
6028
|
+
try {
|
|
6029
|
+
decoded = decodeURIComponent(value);
|
|
6030
|
+
} catch {
|
|
6031
|
+
throw new Error("链接包含无效的字符编码。");
|
|
6032
|
+
}
|
|
6033
|
+
if (CONTROL_CHARACTERS.test(decoded)) throw new Error("链接包含无效字符。");
|
|
6034
|
+
return decoded;
|
|
6035
|
+
}
|
|
6036
|
+
//#endregion
|
|
6037
|
+
//#region ../plugin-sdk/dist/markdown.js
|
|
6038
|
+
/** Reads bounded Markdown within a plugin-selected root and confirms external browser actions. */
|
|
6039
|
+
const MAXIMUM_DOCUMENT_BYTES = 1048576;
|
|
6040
|
+
const MAXIMUM_PATH_LENGTH = 4096;
|
|
6041
|
+
const OPEN_TIMEOUT_MILLISECONDS = 1e4;
|
|
6042
|
+
const requestSchema = object({
|
|
6043
|
+
href: string().min(1).max(MAXIMUM_PATH_LENGTH),
|
|
6044
|
+
sourcePath: string().min(1).max(MAXIMUM_PATH_LENGTH).optional()
|
|
6045
|
+
}).strict();
|
|
6046
|
+
/** Register these handlers on the plugin view; the plugin chooses the allowed document tree. */
|
|
6047
|
+
function createMarkdownHandlers({ root }) {
|
|
6048
|
+
return { openMarkdownLink: async (input, invocation) => {
|
|
6049
|
+
const { href, sourcePath } = requestSchema.parse(input);
|
|
6050
|
+
const link = parseMarkdownLink(href);
|
|
6051
|
+
invocation.signal.throwIfAborted();
|
|
6052
|
+
if (link.kind === "website") {
|
|
6053
|
+
await openWebsite(link.url, invocation);
|
|
6054
|
+
return null;
|
|
6055
|
+
}
|
|
6056
|
+
if (link.kind === "anchor") throw new Error("当前文档的标题链接无需重新读取文件。");
|
|
6057
|
+
const relativePath = resolveDocumentPath({
|
|
6058
|
+
root,
|
|
6059
|
+
sourcePath,
|
|
6060
|
+
destination: link.path
|
|
6061
|
+
});
|
|
6062
|
+
const content = readDocument(root, relativePath);
|
|
6063
|
+
return {
|
|
6064
|
+
path: relativePath.split(path.sep).join("/"),
|
|
6065
|
+
content,
|
|
6066
|
+
fragment: link.fragment,
|
|
6067
|
+
revision: createHash("sha256").update(content).digest("hex")
|
|
6068
|
+
};
|
|
6069
|
+
} };
|
|
6070
|
+
}
|
|
6071
|
+
async function openWebsite(url, invocation) {
|
|
6072
|
+
const { confirmed } = await invocation.services.prompt.ask({
|
|
6073
|
+
name: "confirmed",
|
|
6074
|
+
type: "confirm",
|
|
6075
|
+
purpose: "approval",
|
|
6076
|
+
default: false,
|
|
6077
|
+
title: "打开浏览器",
|
|
6078
|
+
submitLabel: "打开浏览器",
|
|
6079
|
+
message: "是否在系统浏览器中打开以下网页?\n\n" + url
|
|
6080
|
+
});
|
|
6081
|
+
invocation.signal.throwIfAborted();
|
|
6082
|
+
if (confirmed !== true) return;
|
|
6083
|
+
const opener = (/* @__PURE__ */ new Map([
|
|
6084
|
+
["darwin", {
|
|
6085
|
+
program: "/usr/bin/open",
|
|
6086
|
+
arguments: [url]
|
|
6087
|
+
}],
|
|
6088
|
+
["linux", {
|
|
6089
|
+
program: "xdg-open",
|
|
6090
|
+
arguments: [url]
|
|
6091
|
+
}],
|
|
6092
|
+
["win32", {
|
|
6093
|
+
program: "rundll32.exe",
|
|
6094
|
+
arguments: ["url.dll,FileProtocolHandler", url]
|
|
6095
|
+
}]
|
|
6096
|
+
])).get(process.platform);
|
|
6097
|
+
if (!opener) throw new Error("当前系统不支持直接打开网页,请复制链接到浏览器。");
|
|
6098
|
+
const result = await invocation.process.run({
|
|
6099
|
+
...opener,
|
|
6100
|
+
timeoutMilliseconds: OPEN_TIMEOUT_MILLISECONDS
|
|
6101
|
+
}, invocation.signal);
|
|
6102
|
+
if (result.failed || result.exitCode !== 0) throw new Error("系统未能打开网页,请复制链接到浏览器后重试。");
|
|
6103
|
+
}
|
|
6104
|
+
function resolveDocumentPath({ root, sourcePath, destination }) {
|
|
6105
|
+
const owner = path.resolve(root);
|
|
6106
|
+
const source = sourcePath ? path.resolve(owner, sourcePath) : null;
|
|
6107
|
+
if (source) requireContained(owner, source);
|
|
6108
|
+
return requireContained(owner, path.resolve(source ? path.dirname(source) : owner, destination));
|
|
6109
|
+
}
|
|
6110
|
+
function requireContained(root, candidate) {
|
|
6111
|
+
const relative = path.relative(root, candidate);
|
|
6112
|
+
if (!relative || relative === ".." || relative.startsWith(".." + path.sep) || path.isAbsolute(relative) || relative.includes("\0")) throw new Error("文档链接超出当前可预览的目录。");
|
|
6113
|
+
return relative;
|
|
6114
|
+
}
|
|
6115
|
+
function readDocument(root, relativePath) {
|
|
6116
|
+
const owner = realpathSync(root);
|
|
6117
|
+
const segments = relativePath.split(path.sep);
|
|
6118
|
+
let candidate = owner;
|
|
6119
|
+
for (const segment of segments) {
|
|
6120
|
+
candidate = path.join(candidate, segment);
|
|
6121
|
+
const entry = lstatSync(candidate, { throwIfNoEntry: false });
|
|
6122
|
+
if (!entry) throw new Error("文档不存在:" + relativePath);
|
|
6123
|
+
if (entry.isSymbolicLink()) throw new Error("文档预览不允许读取符号链接:" + relativePath);
|
|
6124
|
+
}
|
|
6125
|
+
const descriptor = openSync(candidate, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
6126
|
+
try {
|
|
6127
|
+
const metadata = fstatSync(descriptor);
|
|
6128
|
+
if (!metadata.isFile() || metadata.size > MAXIMUM_DOCUMENT_BYTES) throw new Error("只能预览不超过 1 MB 的普通 Markdown 文件:" + relativePath);
|
|
6129
|
+
const buffer = Buffer.alloc(1048577);
|
|
6130
|
+
let length = 0;
|
|
6131
|
+
while (length < buffer.length) {
|
|
6132
|
+
const count = readSync(descriptor, buffer, length, buffer.length - length, length);
|
|
6133
|
+
if (!count) break;
|
|
6134
|
+
length += count;
|
|
6135
|
+
}
|
|
6136
|
+
if (length > MAXIMUM_DOCUMENT_BYTES) throw new Error("文档超过 1 MB,无法预览:" + relativePath);
|
|
6137
|
+
return buffer.subarray(0, length).toString("utf8");
|
|
6138
|
+
} finally {
|
|
6139
|
+
closeSync(descriptor);
|
|
6140
|
+
}
|
|
6141
|
+
}
|
|
5709
6142
|
//#endregion
|
|
5710
6143
|
//#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
5711
6144
|
/**
|
|
@@ -7848,6 +8281,9 @@ const INSTRUCTION_FILES = /* @__PURE__ */ new Set(["AGENTS.md", "CLAUDE.md"]);
|
|
|
7848
8281
|
const JSON_EXTENSIONS = /* @__PURE__ */ new Set([".json", ".jsonc"]);
|
|
7849
8282
|
const MAXIMUM_FILE_BYTES = 4194304;
|
|
7850
8283
|
const MAXIMUM_OUTPUT_FILES = 1024;
|
|
8284
|
+
const MAXIMUM_JOURNAL_BYTES = 67108864;
|
|
8285
|
+
const JOURNAL_FILE = "injection-journal.json";
|
|
8286
|
+
const JOURNAL_TEMPORARY_FILE = `${JOURNAL_FILE}.tmp`;
|
|
7851
8287
|
const FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set([
|
|
7852
8288
|
".",
|
|
7853
8289
|
"..",
|
|
@@ -7856,37 +8292,34 @@ const FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
7856
8292
|
"prototype",
|
|
7857
8293
|
"constructor"
|
|
7858
8294
|
]);
|
|
8295
|
+
const MANAGED_FILE_SCHEMA = object({
|
|
8296
|
+
before: string().max(MAXIMUM_FILE_BYTES).nullable(),
|
|
8297
|
+
after: string().max(MAXIMUM_FILE_BYTES)
|
|
8298
|
+
}).strict();
|
|
8299
|
+
const JOURNAL_SCHEMA = object({
|
|
8300
|
+
root: string(),
|
|
8301
|
+
files: array(tuple([string(), array(MANAGED_FILE_SCHEMA).min(1).max(2)])).max(MAXIMUM_OUTPUT_FILES)
|
|
8302
|
+
}).strict();
|
|
7859
8303
|
var InjectionWriter = class {
|
|
7860
8304
|
root;
|
|
8305
|
+
#stateRoot;
|
|
7861
8306
|
#managed = /* @__PURE__ */ new Map();
|
|
7862
|
-
constructor(root) {
|
|
8307
|
+
constructor(root, stateDirectory) {
|
|
7863
8308
|
this.root = realpathSync(root);
|
|
8309
|
+
this.#stateRoot = stateDirectory ? realpathSync(stateDirectory()) : null;
|
|
8310
|
+
if (this.#stateRoot) this.#load();
|
|
7864
8311
|
}
|
|
7865
8312
|
get paths() {
|
|
7866
8313
|
return [...this.#managed.keys()];
|
|
7867
8314
|
}
|
|
7868
8315
|
/** 返回去除旧注入后的当前内容,保留注入以外的用户编辑。 */
|
|
7869
8316
|
baseline(relativePath) {
|
|
7870
|
-
|
|
7871
|
-
const managed = this.#managed.get(relativePath);
|
|
7872
|
-
return managed ? restoreContent({
|
|
7873
|
-
relativePath,
|
|
7874
|
-
managed,
|
|
7875
|
-
current
|
|
7876
|
-
}) : current;
|
|
8317
|
+
return this.#restore(relativePath).content;
|
|
7877
8318
|
}
|
|
7878
8319
|
isApplied() {
|
|
7879
|
-
return
|
|
8320
|
+
return this.paths.every((relativePath) => {
|
|
7880
8321
|
try {
|
|
7881
|
-
|
|
7882
|
-
if (current === null) return false;
|
|
7883
|
-
if (managed.before === managed.after) return current === managed.after;
|
|
7884
|
-
restoreContent({
|
|
7885
|
-
relativePath,
|
|
7886
|
-
managed,
|
|
7887
|
-
current,
|
|
7888
|
-
requireApplied: true
|
|
7889
|
-
});
|
|
8322
|
+
this.#restore(relativePath, true);
|
|
7890
8323
|
return true;
|
|
7891
8324
|
} catch {
|
|
7892
8325
|
return false;
|
|
@@ -7897,9 +8330,10 @@ var InjectionWriter = class {
|
|
|
7897
8330
|
apply(fragments) {
|
|
7898
8331
|
const desired = /* @__PURE__ */ new Map();
|
|
7899
8332
|
const nextManaged = /* @__PURE__ */ new Map();
|
|
8333
|
+
const pendingManaged = /* @__PURE__ */ new Map();
|
|
7900
8334
|
const paths = /* @__PURE__ */ new Set([...this.#managed.keys(), ...fragments.keys()]);
|
|
7901
8335
|
for (const relativePath of paths) {
|
|
7902
|
-
const before = this
|
|
8336
|
+
const { content: before, managed } = this.#restore(relativePath);
|
|
7903
8337
|
const fragment = fragments.get(relativePath);
|
|
7904
8338
|
const after = fragment === void 0 ? before : mergeContent({
|
|
7905
8339
|
relativePath,
|
|
@@ -7907,12 +8341,21 @@ var InjectionWriter = class {
|
|
|
7907
8341
|
fragment
|
|
7908
8342
|
});
|
|
7909
8343
|
desired.set(relativePath, after);
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
8344
|
+
const candidates = managed ? [managed] : [];
|
|
8345
|
+
if (fragment !== void 0) {
|
|
8346
|
+
const next = {
|
|
8347
|
+
before,
|
|
8348
|
+
after
|
|
8349
|
+
};
|
|
8350
|
+
candidates.push(next);
|
|
8351
|
+
nextManaged.set(relativePath, [next]);
|
|
8352
|
+
}
|
|
8353
|
+
pendingManaged.set(relativePath, candidates);
|
|
7914
8354
|
}
|
|
8355
|
+
this.#save(pendingManaged);
|
|
8356
|
+
this.#managed = pendingManaged;
|
|
7915
8357
|
writeFileBatch(this.root, desired);
|
|
8358
|
+
this.#save(nextManaged);
|
|
7916
8359
|
this.#managed = nextManaged;
|
|
7917
8360
|
}
|
|
7918
8361
|
/** 停止时逐文件撤销,保留冲突文件及其记录,不阻塞其他文件的清理。 */
|
|
@@ -7920,22 +8363,99 @@ var InjectionWriter = class {
|
|
|
7920
8363
|
const failures = [];
|
|
7921
8364
|
for (const relativePath of this.paths) try {
|
|
7922
8365
|
writeFileBatch(this.root, /* @__PURE__ */ new Map([[relativePath, this.baseline(relativePath)]]));
|
|
7923
|
-
this.#managed
|
|
8366
|
+
const remaining = new Map(this.#managed);
|
|
8367
|
+
remaining.delete(relativePath);
|
|
8368
|
+
this.#save(remaining);
|
|
8369
|
+
this.#managed = remaining;
|
|
7924
8370
|
} catch (error) {
|
|
7925
8371
|
failures.push(`${relativePath}:${error instanceof Error ? error.message : "撤销失败"}`);
|
|
7926
8372
|
}
|
|
7927
|
-
if (failures.length) throw new Error(
|
|
8373
|
+
if (failures.length) throw new Error(`规则已保留未能安全撤销的文件,请检查后重试:\n${failures.join("\n")}`);
|
|
8374
|
+
}
|
|
8375
|
+
#restore(relativePath, requireApplied = false) {
|
|
8376
|
+
const current = readSafeFile(this.root, relativePath);
|
|
8377
|
+
const candidates = this.#managed.get(relativePath);
|
|
8378
|
+
if (!candidates) return { content: current };
|
|
8379
|
+
const exact = candidates.findLast(({ after }) => after === current);
|
|
8380
|
+
if (exact) return {
|
|
8381
|
+
content: restoreContent({
|
|
8382
|
+
relativePath,
|
|
8383
|
+
managed: exact,
|
|
8384
|
+
current,
|
|
8385
|
+
requireApplied
|
|
8386
|
+
}),
|
|
8387
|
+
managed: exact
|
|
8388
|
+
};
|
|
8389
|
+
let failure = conflict(relativePath);
|
|
8390
|
+
const restored = [];
|
|
8391
|
+
for (const managed of candidates) {
|
|
8392
|
+
if (requireApplied && (current === null || managed.before === managed.after && current !== managed.after)) continue;
|
|
8393
|
+
try {
|
|
8394
|
+
restored.push({
|
|
8395
|
+
content: restoreContent({
|
|
8396
|
+
relativePath,
|
|
8397
|
+
managed,
|
|
8398
|
+
current,
|
|
8399
|
+
requireApplied
|
|
8400
|
+
}),
|
|
8401
|
+
managed
|
|
8402
|
+
});
|
|
8403
|
+
} catch (error) {
|
|
8404
|
+
failure = error instanceof Error ? error : conflict(relativePath);
|
|
8405
|
+
}
|
|
8406
|
+
}
|
|
8407
|
+
const first = restored[0];
|
|
8408
|
+
if (first && restored.every(({ content }) => content === first.content)) return first;
|
|
8409
|
+
if (first) throw new Error(`规则注入恢复未完成:${relativePath} 在中断写入后又有改动,无法安全确认归属。请检查该文件后重试;现有内容已保留。`);
|
|
8410
|
+
throw failure;
|
|
8411
|
+
}
|
|
8412
|
+
#load() {
|
|
8413
|
+
if (!this.#stateRoot) return;
|
|
8414
|
+
const filePath = safeFilePath(this.#stateRoot, JOURNAL_FILE);
|
|
8415
|
+
const metadata = lstatSync(filePath, { throwIfNoEntry: false });
|
|
8416
|
+
if (!metadata) return;
|
|
8417
|
+
if (!metadata.isFile() || metadata.size > MAXIMUM_JOURNAL_BYTES) throw new Error("规则注入归属记录不是有效文件;请检查规则插件的私有存储后重试。");
|
|
8418
|
+
let stored;
|
|
8419
|
+
try {
|
|
8420
|
+
stored = JSON.parse(readFileSync(filePath, "utf8"));
|
|
8421
|
+
} catch (error) {
|
|
8422
|
+
throw new Error("无法读取规则注入归属记录;已保留客户端文件,请检查规则插件的私有存储后重试。", { cause: error });
|
|
8423
|
+
}
|
|
8424
|
+
const parsed = JOURNAL_SCHEMA.safeParse(stored);
|
|
8425
|
+
if (!parsed.success || parsed.data.root !== this.root) throw new Error("规则注入归属记录无效或不属于当前工作区;已保留客户端文件,请检查私有存储后重试。");
|
|
8426
|
+
const managed = new Map(parsed.data.files);
|
|
8427
|
+
if (managed.size !== parsed.data.files.length) throw new Error("规则注入归属记录含重复文件,已保留客户端文件。");
|
|
8428
|
+
managed.forEach((_candidates, relativePath) => safeFilePath(this.root, relativePath));
|
|
8429
|
+
this.#managed = managed;
|
|
8430
|
+
}
|
|
8431
|
+
#save(managed) {
|
|
8432
|
+
if (!this.#stateRoot) return;
|
|
8433
|
+
const content = JSON.stringify({
|
|
8434
|
+
root: this.root,
|
|
8435
|
+
files: [...managed]
|
|
8436
|
+
});
|
|
8437
|
+
if (Buffer.byteLength(content) > MAXIMUM_JOURNAL_BYTES) throw new Error("规则注入归属记录超过大小上限,本次客户端写入已停止。");
|
|
8438
|
+
try {
|
|
8439
|
+
writeSafeFile({
|
|
8440
|
+
root: this.#stateRoot,
|
|
8441
|
+
relativePath: JOURNAL_TEMPORARY_FILE,
|
|
8442
|
+
content
|
|
8443
|
+
});
|
|
8444
|
+
renameSync(safeFilePath(this.#stateRoot, JOURNAL_TEMPORARY_FILE), safeFilePath(this.#stateRoot, JOURNAL_FILE));
|
|
8445
|
+
} finally {
|
|
8446
|
+
rmSync(safeFilePath(this.#stateRoot, JOURNAL_TEMPORARY_FILE), { force: true });
|
|
8447
|
+
}
|
|
7928
8448
|
}
|
|
7929
8449
|
};
|
|
7930
8450
|
/** 只接受源树或客户端树内的相对路径,不跟随符号链接。 */
|
|
7931
8451
|
function safeFilePath(root, relativePath) {
|
|
7932
|
-
if (lstatSync(root).isSymbolicLink()) throw new Error("
|
|
8452
|
+
if (lstatSync(root).isSymbolicLink()) throw new Error("规则输出根目录不能是符号链接。");
|
|
7933
8453
|
const segments = relativePath.split("/");
|
|
7934
|
-
if (!relativePath || path.isAbsolute(relativePath) || /[\\:\x00-\x1f]/.test(relativePath) || segments.some((segment) => !segment || FORBIDDEN_SEGMENTS.has(segment))) throw new Error("
|
|
8454
|
+
if (!relativePath || path.isAbsolute(relativePath) || /[\\:\x00-\x1f]/.test(relativePath) || segments.some((segment) => !segment || FORBIDDEN_SEGMENTS.has(segment))) throw new Error("规则注入路径必须是安全的相对路径。");
|
|
7935
8455
|
let current = root;
|
|
7936
8456
|
for (const segment of segments) {
|
|
7937
8457
|
current = path.join(current, segment);
|
|
7938
|
-
if (lstatSync(current, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error(
|
|
8458
|
+
if (lstatSync(current, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error(`规则不允许符号链接:${relativePath}`);
|
|
7939
8459
|
}
|
|
7940
8460
|
return current;
|
|
7941
8461
|
}
|
|
@@ -7943,7 +8463,7 @@ function readSafeFile(root, relativePath) {
|
|
|
7943
8463
|
const filePath = safeFilePath(root, relativePath);
|
|
7944
8464
|
const entry = lstatSync(filePath, { throwIfNoEntry: false });
|
|
7945
8465
|
if (!entry) return null;
|
|
7946
|
-
if (!entry.isFile() || entry.size > MAXIMUM_FILE_BYTES) throw new Error(
|
|
8466
|
+
if (!entry.isFile() || entry.size > MAXIMUM_FILE_BYTES) throw new Error(`规则客户端路径不是有效的小型文件:${relativePath}`);
|
|
7947
8467
|
return readFileSync(filePath, "utf8");
|
|
7948
8468
|
}
|
|
7949
8469
|
function readOutputFiles(root) {
|
|
@@ -7954,7 +8474,7 @@ function readOutputFiles(root) {
|
|
|
7954
8474
|
safeFilePath(root, relativePath);
|
|
7955
8475
|
if (entry.isDirectory()) visit(relativePath);
|
|
7956
8476
|
else contents.set(relativePath, readSafeFile(root, relativePath));
|
|
7957
|
-
if (contents.size > MAXIMUM_OUTPUT_FILES) throw new Error("
|
|
8477
|
+
if (contents.size > MAXIMUM_OUTPUT_FILES) throw new Error("规则注入生成的文件过多。");
|
|
7958
8478
|
}
|
|
7959
8479
|
};
|
|
7960
8480
|
visit("");
|
|
@@ -7984,7 +8504,7 @@ function writeFileBatch(root, desired) {
|
|
|
7984
8504
|
} catch (restoreError) {
|
|
7985
8505
|
failures.push(restoreError);
|
|
7986
8506
|
}
|
|
7987
|
-
if (failures.length > 1) throw new AggregateError(failures, "
|
|
8507
|
+
if (failures.length > 1) throw new AggregateError(failures, "规则写入及恢复失败,请检查客户端文件。");
|
|
7988
8508
|
throw error;
|
|
7989
8509
|
}
|
|
7990
8510
|
}
|
|
@@ -8014,7 +8534,11 @@ function removeEmptySkillDirectories(root, relativePath) {
|
|
|
8014
8534
|
}
|
|
8015
8535
|
function mergeContent({ relativePath, before, fragment }) {
|
|
8016
8536
|
if (isStructured(relativePath)) {
|
|
8017
|
-
const merged = mergeDocument(
|
|
8537
|
+
const merged = mergeDocument({
|
|
8538
|
+
location: relativePath,
|
|
8539
|
+
original: parseDocument$1(relativePath, before ?? ""),
|
|
8540
|
+
patch: parseDocument$1(relativePath, fragment)
|
|
8541
|
+
});
|
|
8018
8542
|
return formatDocument({
|
|
8019
8543
|
relativePath,
|
|
8020
8544
|
previous: before ?? "",
|
|
@@ -8022,7 +8546,7 @@ function mergeContent({ relativePath, before, fragment }) {
|
|
|
8022
8546
|
});
|
|
8023
8547
|
}
|
|
8024
8548
|
if (INSTRUCTION_FILES.has(path.posix.basename(relativePath))) {
|
|
8025
|
-
if (before?.includes(BLOCK_START) || before?.includes(BLOCK_END)) throw new Error(
|
|
8549
|
+
if (before?.includes(BLOCK_START) || before?.includes(BLOCK_END)) throw new Error(`无法注入规则:${relativePath} 中存在旧注入标记,但缺少可验证的归属记录。请先备份并检查 WORKBASE_INJECT_START / WORKBASE_INJECT_END 区块,确认其用途后移除旧区块,再重试此插件;现有文件已保留。`);
|
|
8026
8550
|
return `${before ?? ""}\n\n${BLOCK_START}\n${fragment.trimEnd()}\n${BLOCK_END}\n`;
|
|
8027
8551
|
}
|
|
8028
8552
|
if (before !== null && before !== fragment) throw conflict(relativePath);
|
|
@@ -8054,18 +8578,22 @@ function restoreContent({ relativePath, managed, current, requireApplied = false
|
|
|
8054
8578
|
}
|
|
8055
8579
|
throw conflict(relativePath);
|
|
8056
8580
|
}
|
|
8057
|
-
function mergeDocument(original, patch) {
|
|
8581
|
+
function mergeDocument({ location, original, patch }) {
|
|
8058
8582
|
const merged = { ...original };
|
|
8059
8583
|
for (const [key, value] of Object.entries(patch)) {
|
|
8060
8584
|
if (isObject(value) && isObject(original[key])) {
|
|
8061
|
-
merged[key] = mergeDocument(
|
|
8585
|
+
merged[key] = mergeDocument({
|
|
8586
|
+
location: `${location}.${key}`,
|
|
8587
|
+
original: original[key],
|
|
8588
|
+
patch: value
|
|
8589
|
+
});
|
|
8062
8590
|
continue;
|
|
8063
8591
|
}
|
|
8064
8592
|
if (!Object.hasOwn(original, key) || isDeepStrictEqual(original[key], value)) {
|
|
8065
8593
|
merged[key] = value;
|
|
8066
8594
|
continue;
|
|
8067
8595
|
}
|
|
8068
|
-
throw new Error(
|
|
8596
|
+
throw new Error(`无法注入客户端配置:${location}.${key} 已有不同内容。请检查该配置项,确认用途后修改名称或移除冲突项,再重试注入;现有配置已保留。`);
|
|
8069
8597
|
}
|
|
8070
8598
|
return merged;
|
|
8071
8599
|
}
|
|
@@ -8087,7 +8615,7 @@ function restoreDocument({ location, original, applied, current, requireApplied
|
|
|
8087
8615
|
else delete restored[key];
|
|
8088
8616
|
return;
|
|
8089
8617
|
}
|
|
8090
|
-
if (!isDeepStrictEqual(value, actual)) throw new Error(
|
|
8618
|
+
if (!isDeepStrictEqual(value, actual)) throw new Error(`规则注入内容已被修改:${location}.${key};已保留当前内容,请处理冲突后重试撤销。`);
|
|
8091
8619
|
if (Object.hasOwn(original, key)) restored[key] = original[key];
|
|
8092
8620
|
else delete restored[key];
|
|
8093
8621
|
});
|
|
@@ -8108,9 +8636,9 @@ function parseDocument$1(relativePath, content) {
|
|
|
8108
8636
|
try {
|
|
8109
8637
|
parsed = path.extname(relativePath) === ".toml" ? parse(content) : parse$1(content, errors, { allowTrailingComma: true });
|
|
8110
8638
|
} catch {
|
|
8111
|
-
throw new Error(
|
|
8639
|
+
throw new Error(`规则无法解析客户端配置:${relativePath}`);
|
|
8112
8640
|
}
|
|
8113
|
-
if (errors.length || !isObject(parsed)) throw new Error(
|
|
8641
|
+
if (errors.length || !isObject(parsed)) throw new Error(`规则客户端配置必须是有效对象:${relativePath}`);
|
|
8114
8642
|
validateKeys(parsed);
|
|
8115
8643
|
return parsed;
|
|
8116
8644
|
}
|
|
@@ -8121,7 +8649,7 @@ function validateKeys(value) {
|
|
|
8121
8649
|
}
|
|
8122
8650
|
if (!isObject(value)) return;
|
|
8123
8651
|
for (const [key, nested] of Object.entries(value)) {
|
|
8124
|
-
if (FORBIDDEN_SEGMENTS.has(key)) throw new Error("
|
|
8652
|
+
if (FORBIDDEN_SEGMENTS.has(key)) throw new Error("规则配置包含不允许的对象键。");
|
|
8125
8653
|
validateKeys(nested);
|
|
8126
8654
|
}
|
|
8127
8655
|
}
|
|
@@ -8142,7 +8670,7 @@ function isObject(value) {
|
|
|
8142
8670
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8143
8671
|
}
|
|
8144
8672
|
function conflict(relativePath) {
|
|
8145
|
-
return /* @__PURE__ */ new Error(
|
|
8673
|
+
return /* @__PURE__ */ new Error(`规则不会覆盖或撤销已被修改的文件:${relativePath}`);
|
|
8146
8674
|
}
|
|
8147
8675
|
//#endregion
|
|
8148
8676
|
//#region src/injection.ts
|
|
@@ -8170,7 +8698,7 @@ const injectionRequestSchema = unknown().superRefine((input, context) => {
|
|
|
8170
8698
|
} catch {
|
|
8171
8699
|
context.addIssue({
|
|
8172
8700
|
code: "custom",
|
|
8173
|
-
message: "
|
|
8701
|
+
message: "规则注入包含不允许的对象键。"
|
|
8174
8702
|
});
|
|
8175
8703
|
}
|
|
8176
8704
|
}).pipe(injectionIdentitySchema.extend({
|
|
@@ -8198,7 +8726,7 @@ var InjectionService = class {
|
|
|
8198
8726
|
#pending = null;
|
|
8199
8727
|
constructor(options) {
|
|
8200
8728
|
this.#options = options;
|
|
8201
|
-
this.#writer = new InjectionWriter(options.workspaceRoot);
|
|
8729
|
+
this.#writer = new InjectionWriter(options.workspaceRoot, options.stateDirectory);
|
|
8202
8730
|
}
|
|
8203
8731
|
/** 串行化同一工作区的生成和撤销;等待不会吞掉前一个调用的错误。 */
|
|
8204
8732
|
async run(operation, signal) {
|
|
@@ -8245,7 +8773,7 @@ var InjectionService = class {
|
|
|
8245
8773
|
}
|
|
8246
8774
|
const requests = new Map(this.#requests);
|
|
8247
8775
|
requests.set(key(request), request);
|
|
8248
|
-
if (requests.size > MAXIMUM_INJECTIONS) throw new Error("
|
|
8776
|
+
if (requests.size > MAXIMUM_INJECTIONS) throw new Error("当前会话的规则注入数量过多。");
|
|
8249
8777
|
await this.#update(requests, invocation);
|
|
8250
8778
|
invocation.report?.({
|
|
8251
8779
|
...details,
|
|
@@ -8326,7 +8854,7 @@ var InjectionService = class {
|
|
|
8326
8854
|
}
|
|
8327
8855
|
async #update(requests, invocation) {
|
|
8328
8856
|
const targets = this.#options.targets();
|
|
8329
|
-
if (requests.size && targets.some((target) => !SUPPORTED_TARGETS.has(target))) throw new Error("动态注入当前支持 Codex CLI 和 Claude Code
|
|
8857
|
+
if (requests.size && targets.some((target) => !SUPPORTED_TARGETS.has(target))) throw new Error("动态注入当前支持 Codex CLI 和 Claude Code,请在规则中选择对应客户端。");
|
|
8330
8858
|
const temporaryRoot = mkdtempSync(path.join(os.tmpdir(), "workbase-ai-inject-"));
|
|
8331
8859
|
const sourceRoot = path.join(temporaryRoot, "source");
|
|
8332
8860
|
const outputRoot = path.join(temporaryRoot, "output");
|
|
@@ -8377,7 +8905,7 @@ function writeSources(sourceRoot, requests) {
|
|
|
8377
8905
|
return [...features].sort();
|
|
8378
8906
|
function writeSourceFile(file) {
|
|
8379
8907
|
const normalized = file.path.toLowerCase();
|
|
8380
|
-
if (sourcePaths.has(normalized)) throw new Error(
|
|
8908
|
+
if (sourcePaths.has(normalized)) throw new Error(`规则注入来源文件重名:${file.path}`);
|
|
8381
8909
|
sourcePaths.add(normalized);
|
|
8382
8910
|
const filePath = safeFilePath(rulesyncRoot, file.path);
|
|
8383
8911
|
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
@@ -8386,14 +8914,14 @@ function writeSources(sourceRoot, requests) {
|
|
|
8386
8914
|
}
|
|
8387
8915
|
function registerMcpServer([name, server]) {
|
|
8388
8916
|
const normalized = name.toLowerCase();
|
|
8389
|
-
if (serverNames.has(normalized) || FORBIDDEN_KEYS.has(name)) throw new Error(
|
|
8917
|
+
if (serverNames.has(normalized) || FORBIDDEN_KEYS.has(name)) throw new Error(`规则 MCP Server 名称冲突或不允许:${name}`);
|
|
8390
8918
|
serverNames.add(normalized);
|
|
8391
8919
|
mcpServers.set(name, server);
|
|
8392
8920
|
}
|
|
8393
8921
|
}
|
|
8394
8922
|
function validateSkillSources(files) {
|
|
8395
8923
|
new Set(files.filter((file) => file.path.startsWith("skills/")).map((file) => file.path.split("/")[1])).forEach((skillName) => {
|
|
8396
|
-
if (!files.some((file) => file.path === `skills/${skillName}/SKILL.md`)) throw new Error(
|
|
8924
|
+
if (!files.some((file) => file.path === `skills/${skillName}/SKILL.md`)) throw new Error(`规则 Skill 必须包含 SKILL.md:${skillName}`);
|
|
8397
8925
|
});
|
|
8398
8926
|
}
|
|
8399
8927
|
function validateInputKeys(value) {
|
|
@@ -8403,7 +8931,7 @@ function validateInputKeys(value) {
|
|
|
8403
8931
|
}
|
|
8404
8932
|
if (!value || typeof value !== "object") return;
|
|
8405
8933
|
for (const [name, nested] of Object.entries(value)) {
|
|
8406
|
-
if (FORBIDDEN_KEYS.has(name)) throw new Error("
|
|
8934
|
+
if (FORBIDDEN_KEYS.has(name)) throw new Error("规则注入包含不允许的对象键。");
|
|
8407
8935
|
validateInputKeys(nested);
|
|
8408
8936
|
}
|
|
8409
8937
|
}
|
|
@@ -8424,7 +8952,7 @@ async function waitForOperation(pending, signal) {
|
|
|
8424
8952
|
if (!signal) return pending;
|
|
8425
8953
|
signal.throwIfAborted();
|
|
8426
8954
|
const { promise, reject } = Promise.withResolvers();
|
|
8427
|
-
const abort = () => reject(signal.reason ?? /* @__PURE__ */ new Error("
|
|
8955
|
+
const abort = () => reject(signal.reason ?? /* @__PURE__ */ new Error("规则注入已取消。"));
|
|
8428
8956
|
signal.addEventListener("abort", abort, { once: true });
|
|
8429
8957
|
try {
|
|
8430
8958
|
await Promise.race([pending, promise]);
|
|
@@ -15110,6 +15638,8 @@ const resourceImportSchema = object({ directory: string().min(1).max(4096) }).st
|
|
|
15110
15638
|
//#endregion
|
|
15111
15639
|
//#region src/resources.ts
|
|
15112
15640
|
/** Reads and edits canonical Rulesync sources; client generation remains in the plugin. */
|
|
15641
|
+
const WORKFLOW_PLUGIN_ID = "ai-workflows";
|
|
15642
|
+
const WORKFLOW_SKILL_REFERENCES_STATUS_ID = "skill.references";
|
|
15113
15643
|
function registerResources(context, hooks) {
|
|
15114
15644
|
const root = context.project.root;
|
|
15115
15645
|
const catalog = () => ({ resources: resourceDocuments(root).map(({ files, ...summary }) => ({
|
|
@@ -15118,7 +15648,7 @@ function registerResources(context, hooks) {
|
|
|
15118
15648
|
})) });
|
|
15119
15649
|
hooks.registerStatus({
|
|
15120
15650
|
id: "resources",
|
|
15121
|
-
label: "
|
|
15651
|
+
label: "资源",
|
|
15122
15652
|
description: "只读列出项目规则、技能和 MCP。",
|
|
15123
15653
|
resolve: catalog
|
|
15124
15654
|
});
|
|
@@ -15185,7 +15715,7 @@ function registerResources(context, hooks) {
|
|
|
15185
15715
|
});
|
|
15186
15716
|
hooks.registerCommand({
|
|
15187
15717
|
id: "resource.save",
|
|
15188
|
-
title: "保存
|
|
15718
|
+
title: "保存 资源",
|
|
15189
15719
|
input: resourceWriteSchema,
|
|
15190
15720
|
transaction: PluginCommandTransaction.ProjectMutation,
|
|
15191
15721
|
plan: (input) => ({
|
|
@@ -15202,7 +15732,7 @@ function registerResources(context, hooks) {
|
|
|
15202
15732
|
});
|
|
15203
15733
|
hooks.registerCommand({
|
|
15204
15734
|
id: "resource.delete",
|
|
15205
|
-
title: "删除
|
|
15735
|
+
title: "删除 资源",
|
|
15206
15736
|
input: resourceDeleteSchema,
|
|
15207
15737
|
transaction: PluginCommandTransaction.ProjectMutation,
|
|
15208
15738
|
plan: (input) => ({
|
|
@@ -15250,17 +15780,46 @@ function document(identity, contents) {
|
|
|
15250
15780
|
}));
|
|
15251
15781
|
const serialized = JSON.stringify(files);
|
|
15252
15782
|
if (Buffer.byteLength(serialized) > 1048576 || files.some(({ content }) => content.includes("\0"))) throw new Error("资源超过 1 MiB 或包含二进制内容,请使用文本资源。");
|
|
15253
|
-
const
|
|
15254
|
-
const
|
|
15255
|
-
const
|
|
15783
|
+
const primary = identity.kind === "skills" ? files.find(({ path }) => path === `rules/.rulesync/skills/${identity.id}/SKILL.md`) : files[0];
|
|
15784
|
+
const frontmatter = primary?.content.match(/^\uFEFF?---\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/);
|
|
15785
|
+
const metadata = frontmatter ? (0, import_dist.parseDocument)(frontmatter[1]) : void 0;
|
|
15786
|
+
const validMetadata = metadata && !metadata.errors.length && (0, import_dist.isMap)(metadata.contents) ? metadata : void 0;
|
|
15787
|
+
const description = metadata?.errors.length ? "描述无法解析,请检查文件头部" : validMetadata?.get("description");
|
|
15788
|
+
const body = frontmatter ? primary?.content.slice(frontmatter[0].length) : primary?.content;
|
|
15789
|
+
const server = identity.kind === "mcp" ? parseObject(primary?.content ?? "{}") : null;
|
|
15790
|
+
const title = [
|
|
15791
|
+
validMetadata?.get("title") ?? server?.title,
|
|
15792
|
+
markdownTitle(body ?? ""),
|
|
15793
|
+
validMetadata?.get("name") ?? server?.name,
|
|
15794
|
+
identity.id
|
|
15795
|
+
].find((value) => typeof value === "string" && value.trim().length > 0)?.trim();
|
|
15256
15796
|
return {
|
|
15257
15797
|
...identity,
|
|
15798
|
+
title,
|
|
15258
15799
|
...typeof description === "string" && description.trim() ? { description: description.trim() } : {},
|
|
15259
15800
|
files,
|
|
15260
15801
|
paths: files.map(({ path }) => path),
|
|
15261
15802
|
revision: createHash("sha256").update(serialized).digest("hex")
|
|
15262
15803
|
};
|
|
15263
15804
|
}
|
|
15805
|
+
function markdownTitle(content) {
|
|
15806
|
+
let fence = "";
|
|
15807
|
+
let fenceLength = 0;
|
|
15808
|
+
for (const line of content.split(/\r?\n/)) {
|
|
15809
|
+
const delimiter = /^ {0,3}(`{3,}|~{3,})/.exec(line)?.[1];
|
|
15810
|
+
if (delimiter && !fence) {
|
|
15811
|
+
fence = delimiter[0];
|
|
15812
|
+
fenceLength = delimiter.length;
|
|
15813
|
+
continue;
|
|
15814
|
+
}
|
|
15815
|
+
if (fence) {
|
|
15816
|
+
if (delimiter?.[0] === fence && delimiter.length >= fenceLength && /^ {0,3}(?:`+|~+)[ \t]*$/.test(line)) fence = "";
|
|
15817
|
+
continue;
|
|
15818
|
+
}
|
|
15819
|
+
const title = /^ {0,3}#(?!#)[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/.exec(line)?.[1];
|
|
15820
|
+
if (title) return title;
|
|
15821
|
+
}
|
|
15822
|
+
}
|
|
15264
15823
|
function requireResource(root, identity) {
|
|
15265
15824
|
const resource = resourceDocuments(root).find(({ kind, id }) => kind === identity.kind && id === identity.id);
|
|
15266
15825
|
if (!resource) throw new Error("资源已不存在,请刷新列表。");
|
|
@@ -15334,25 +15893,16 @@ function updateMcp({ root, id, server }) {
|
|
|
15334
15893
|
}
|
|
15335
15894
|
async function references(identity, invocation) {
|
|
15336
15895
|
if (identity.kind !== "skills") return [];
|
|
15337
|
-
if (!invocation.services.capabilities.catalog().statuses.some(({ pluginId, id }) => pluginId ===
|
|
15338
|
-
const
|
|
15339
|
-
|
|
15340
|
-
|
|
15341
|
-
|
|
15342
|
-
|
|
15343
|
-
|
|
15344
|
-
|
|
15345
|
-
|
|
15346
|
-
}).parse(
|
|
15347
|
-
pluginId: "ai-workflows",
|
|
15348
|
-
id: "catalog",
|
|
15349
|
-
input: {}
|
|
15350
|
-
}));
|
|
15351
|
-
if (catalog.error) throw new Error("工作流配置无效,无法确认资源关联,请先修复工作流配置。");
|
|
15352
|
-
return catalog.workflows.filter(({ skill, skills }) => (skills ?? (skill ? [skill] : [])).includes(identity.id)).map(({ id, title }) => ({
|
|
15353
|
-
id,
|
|
15354
|
-
title
|
|
15355
|
-
}));
|
|
15896
|
+
if (!invocation.services.capabilities.catalog().statuses.some(({ pluginId, id }) => pluginId === WORKFLOW_PLUGIN_ID && id === WORKFLOW_SKILL_REFERENCES_STATUS_ID)) throw new Error("工作流的资源引用检查不可用,请更新并准备工作流后重试。");
|
|
15897
|
+
const references = await invocation.services.capabilities.resolveStatus({
|
|
15898
|
+
pluginId: WORKFLOW_PLUGIN_ID,
|
|
15899
|
+
id: WORKFLOW_SKILL_REFERENCES_STATUS_ID,
|
|
15900
|
+
input: { skillId: identity.id }
|
|
15901
|
+
});
|
|
15902
|
+
return array(object({
|
|
15903
|
+
id: string().min(1),
|
|
15904
|
+
title: string().min(1)
|
|
15905
|
+
})).parse(references);
|
|
15356
15906
|
}
|
|
15357
15907
|
function importSkill(context, directory) {
|
|
15358
15908
|
const root = [context.project.root, context.workspace.root].find((candidate) => {
|
|
@@ -15607,7 +16157,7 @@ function missingConfigurationResult(operation, paths) {
|
|
|
15607
16157
|
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15608
16158
|
details: null,
|
|
15609
16159
|
operation,
|
|
15610
|
-
standardError:
|
|
16160
|
+
standardError: `请先初始化规则:${paths.configPath}`,
|
|
15611
16161
|
standardOutput: "",
|
|
15612
16162
|
success: false,
|
|
15613
16163
|
warnings: []
|
|
@@ -15683,14 +16233,17 @@ const SKILL_STATUS_INPUT = object({
|
|
|
15683
16233
|
target: _enum(["codexcli", "claudecode"]).describe("同步目标:Codex 使用 codexcli,Claude Code 使用 claudecode")
|
|
15684
16234
|
}).strict();
|
|
15685
16235
|
const RULES_DIRECTORY = "rules";
|
|
16236
|
+
const PLUGIN_ID = "ai-rules";
|
|
16237
|
+
const WORKSPACE_ITERATION_INJECTION_ID = "workspace-iteration-scope";
|
|
16238
|
+
const WORKSPACE_ITERATION_RULE_PATH = "rules/workbase-iteration-scope.md";
|
|
15686
16239
|
const CONFIGURATION_INPUT_SCHEMA = object({
|
|
15687
16240
|
autoSync: boolean(),
|
|
15688
16241
|
features: array(string().trim().min(1)).min(1),
|
|
15689
16242
|
targets: array(string().trim().min(1)).min(1)
|
|
15690
16243
|
}).strict();
|
|
15691
16244
|
var plugin_default = definePlugin({
|
|
15692
|
-
id:
|
|
15693
|
-
title: "
|
|
16245
|
+
id: PLUGIN_ID,
|
|
16246
|
+
title: "规则",
|
|
15694
16247
|
setup(context, hooks) {
|
|
15695
16248
|
registerResources(context, hooks);
|
|
15696
16249
|
const rulesRoot = path.join(context.project.root, RULES_DIRECTORY);
|
|
@@ -15708,7 +16261,7 @@ var plugin_default = definePlugin({
|
|
|
15708
16261
|
target,
|
|
15709
16262
|
path: relativePath,
|
|
15710
16263
|
available,
|
|
15711
|
-
reason: available ? null : enabled ? "
|
|
16264
|
+
reason: available ? null : enabled ? "尚未同步到此客户端,请在规则检查目标配置并同步。" : "规则未启用此客户端的 Subagents。"
|
|
15712
16265
|
};
|
|
15713
16266
|
}));
|
|
15714
16267
|
hooks.registerStatus({
|
|
@@ -15742,7 +16295,7 @@ var plugin_default = definePlugin({
|
|
|
15742
16295
|
input: SKILL_STATUS_INPUT,
|
|
15743
16296
|
resolve: (input) => {
|
|
15744
16297
|
const { skill, target } = SKILL_STATUS_INPUT.parse(input);
|
|
15745
|
-
if (!config.features.includes("skills") || !config.targets.includes(target)) throw new Error("
|
|
16298
|
+
if (!config.features.includes("skills") || !config.targets.includes(target)) throw new Error("规则未启用此客户端的 Skills,请先配置并同步。");
|
|
15746
16299
|
const skills = (target === "codexcli" ? [".agents/skills", ".codex/skills"] : [".claude/skills"]).map((root) => {
|
|
15747
16300
|
const relativePath = `${root}/${skill}/SKILL.md`;
|
|
15748
16301
|
const content = readSafeFile(paths.workspaceRoot, relativePath);
|
|
@@ -15751,7 +16304,7 @@ var plugin_default = definePlugin({
|
|
|
15751
16304
|
content
|
|
15752
16305
|
};
|
|
15753
16306
|
}).filter((value) => value !== null);
|
|
15754
|
-
if (!skills.length) throw new Error(`当前工作区缺少 Skill「${skill}
|
|
16307
|
+
if (!skills.length) throw new Error(`当前工作区缺少 Skill「${skill}」,请先在规则同步。`);
|
|
15755
16308
|
if (new Set(skills.map(({ content }) => content)).size > 1) throw new Error(`Skill「${skill}」存在冲突副本,请先处理。`);
|
|
15756
16309
|
return {
|
|
15757
16310
|
skill,
|
|
@@ -15763,6 +16316,7 @@ var plugin_default = definePlugin({
|
|
|
15763
16316
|
});
|
|
15764
16317
|
const injections = new InjectionService({
|
|
15765
16318
|
workspaceRoot: paths.workspaceRoot,
|
|
16319
|
+
stateDirectory: () => context.services.store.directory(),
|
|
15766
16320
|
targets: () => config.targets,
|
|
15767
16321
|
generate: async ({ sourceRoot, outputRoot, features, targets, invocation }) => {
|
|
15768
16322
|
requireSuccessfulOperation(await generateRules({
|
|
@@ -15861,13 +16415,21 @@ var plugin_default = definePlugin({
|
|
|
15861
16415
|
}) : (await initialize(invocation)).result;
|
|
15862
16416
|
requireSuccessfulOperation(result);
|
|
15863
16417
|
return {
|
|
15864
|
-
standardOutput: "
|
|
16418
|
+
standardOutput: "规则已初始化。",
|
|
15865
16419
|
warnings: result.warnings
|
|
15866
16420
|
};
|
|
15867
16421
|
});
|
|
15868
16422
|
hooks.onWorkspaceActivate.tap("auto-sync", async (_payload, invocation) => {
|
|
16423
|
+
await injections.inject({
|
|
16424
|
+
pluginId: PLUGIN_ID,
|
|
16425
|
+
id: WORKSPACE_ITERATION_INJECTION_ID,
|
|
16426
|
+
files: [{
|
|
16427
|
+
path: WORKSPACE_ITERATION_RULE_PATH,
|
|
16428
|
+
content: workspaceIterationRule(context.workspace)
|
|
16429
|
+
}]
|
|
16430
|
+
}, invocation);
|
|
15869
16431
|
if (!isConfigured(paths)) requireSuccessfulOperation(missingConfigurationResult("sync", paths));
|
|
15870
|
-
if (!config.autoSync) return;
|
|
16432
|
+
if (!config.autoSync) return { standardOutput: "工作区仓库范围规则已注入。" };
|
|
15871
16433
|
const result = await runSynchronization({
|
|
15872
16434
|
invocation,
|
|
15873
16435
|
operation: "sync",
|
|
@@ -15875,14 +16437,14 @@ var plugin_default = definePlugin({
|
|
|
15875
16437
|
});
|
|
15876
16438
|
requireSuccessfulOperation(result);
|
|
15877
16439
|
return {
|
|
15878
|
-
standardOutput: "
|
|
16440
|
+
standardOutput: "规则已自动同步。",
|
|
15879
16441
|
warnings: result.warnings
|
|
15880
16442
|
};
|
|
15881
16443
|
});
|
|
15882
16444
|
hooks.registerStatus({
|
|
15883
16445
|
description: "返回 Rulesync 配置、同步目标和最近一次执行结果。",
|
|
15884
16446
|
id: "sync",
|
|
15885
|
-
label: "
|
|
16447
|
+
label: "规则",
|
|
15886
16448
|
resolve: () => status()
|
|
15887
16449
|
});
|
|
15888
16450
|
hooks.onWorkspaceDeactivate.tap("revoke-injections", () => injections.cleanup());
|
|
@@ -15896,15 +16458,15 @@ var plugin_default = definePlugin({
|
|
|
15896
16458
|
});
|
|
15897
16459
|
hooks.registerAgentContext({
|
|
15898
16460
|
exposure: PluginContextExposure.Agent,
|
|
15899
|
-
description: "
|
|
16461
|
+
description: "返回规则的源目录、生成目标和同步状态,不包含规则正文。",
|
|
15900
16462
|
id: "configuration",
|
|
15901
|
-
title: "
|
|
16463
|
+
title: "规则配置上下文",
|
|
15902
16464
|
resolve: () => status()
|
|
15903
16465
|
});
|
|
15904
16466
|
hooks.registerCommand({
|
|
15905
16467
|
id: "configuration.save",
|
|
15906
16468
|
input: CONFIGURATION_INPUT_SCHEMA,
|
|
15907
|
-
title: "
|
|
16469
|
+
title: "保存规则配置",
|
|
15908
16470
|
description: "保存目标客户端、同步内容和自动同步设置。",
|
|
15909
16471
|
transaction: PluginCommandTransaction.ProjectMutation,
|
|
15910
16472
|
plan: () => ({
|
|
@@ -15919,13 +16481,13 @@ var plugin_default = definePlugin({
|
|
|
15919
16481
|
features: uniqueStrings(next.features),
|
|
15920
16482
|
targets: uniqueStrings(next.targets)
|
|
15921
16483
|
}));
|
|
15922
|
-
invocation.services.toast.show("
|
|
16484
|
+
invocation.services.toast.show("规则配置已保存。", "success");
|
|
15923
16485
|
return status();
|
|
15924
16486
|
}, invocation)
|
|
15925
16487
|
});
|
|
15926
16488
|
hooks.registerCommand({
|
|
15927
16489
|
id: "initialize",
|
|
15928
|
-
title: "
|
|
16490
|
+
title: "初始化规则",
|
|
15929
16491
|
description: "在项目 rules 目录创建 Rulesync 配置,准备来源并同步当前 Workspace。",
|
|
15930
16492
|
transaction: PluginCommandTransaction.ProjectMutation,
|
|
15931
16493
|
plan: () => ({ kind: PluginSharedChangeKind.None }),
|
|
@@ -15939,7 +16501,7 @@ var plugin_default = definePlugin({
|
|
|
15939
16501
|
readOnly: true
|
|
15940
16502
|
},
|
|
15941
16503
|
id: "doctor",
|
|
15942
|
-
title: "
|
|
16504
|
+
title: "检查规则配置",
|
|
15943
16505
|
description: "运行 Rulesync doctor,只读诊断配置、目标和源目录。",
|
|
15944
16506
|
run: async (_input, invocation) => {
|
|
15945
16507
|
return {
|
|
@@ -15958,7 +16520,7 @@ var plugin_default = definePlugin({
|
|
|
15958
16520
|
readOnly: true
|
|
15959
16521
|
},
|
|
15960
16522
|
id: "preview",
|
|
15961
|
-
title: "
|
|
16523
|
+
title: "预览规则同步",
|
|
15962
16524
|
description: "使用 Rulesync dry-run 预览将生成或更新的客户端文件。",
|
|
15963
16525
|
run: async (_input, invocation) => ({
|
|
15964
16526
|
result: await runGenerate("preview", invocation),
|
|
@@ -15971,7 +16533,7 @@ var plugin_default = definePlugin({
|
|
|
15971
16533
|
readOnly: true
|
|
15972
16534
|
},
|
|
15973
16535
|
id: "check",
|
|
15974
|
-
title: "
|
|
16536
|
+
title: "校验规则同步状态",
|
|
15975
16537
|
description: "检查当前客户端文件是否与 Rulesync 源保持一致。",
|
|
15976
16538
|
run: async (_input, invocation) => ({
|
|
15977
16539
|
result: await runGenerate("check", invocation),
|
|
@@ -15981,7 +16543,7 @@ var plugin_default = definePlugin({
|
|
|
15981
16543
|
hooks.registerCommand({
|
|
15982
16544
|
effect: PluginCommandEffect.LongRunning,
|
|
15983
16545
|
id: "install",
|
|
15984
|
-
title: "
|
|
16546
|
+
title: "安装规则来源",
|
|
15985
16547
|
description: "根据 rulesync.jsonc 和锁文件安装或恢复声明的规则与 Skills 来源。",
|
|
15986
16548
|
transaction: PluginCommandTransaction.ProjectMutation,
|
|
15987
16549
|
plan: () => ({ kind: PluginSharedChangeKind.None }),
|
|
@@ -16001,7 +16563,7 @@ var plugin_default = definePlugin({
|
|
|
16001
16563
|
hooks.registerCommand({
|
|
16002
16564
|
effect: PluginCommandEffect.LongRunning,
|
|
16003
16565
|
id: "sources.update",
|
|
16004
|
-
title: "
|
|
16566
|
+
title: "更新规则远端来源",
|
|
16005
16567
|
description: "重新解析远端引用并更新锁文件、规则与 Skills。",
|
|
16006
16568
|
transaction: PluginCommandTransaction.ProjectMutation,
|
|
16007
16569
|
plan: () => ({ kind: PluginSharedChangeKind.None }),
|
|
@@ -16021,7 +16583,7 @@ var plugin_default = definePlugin({
|
|
|
16021
16583
|
hooks.registerCommand({
|
|
16022
16584
|
effect: PluginCommandEffect.LongRunning,
|
|
16023
16585
|
id: "sync",
|
|
16024
|
-
title: "
|
|
16586
|
+
title: "同步规则",
|
|
16025
16587
|
description: "组装 Rules、MCP、Commands、Subagents 和 Skills 并写入当前 Workspace。",
|
|
16026
16588
|
transaction: PluginCommandTransaction.ProjectMutation,
|
|
16027
16589
|
plan: () => ({ kind: PluginSharedChangeKind.None }),
|
|
@@ -16086,9 +16648,41 @@ var plugin_default = definePlugin({
|
|
|
16086
16648
|
description: "诊断、预览并同步当前 Workspace 的 AI 客户端上下文。",
|
|
16087
16649
|
entry: "dist/ui/index.html",
|
|
16088
16650
|
id: "workspace",
|
|
16089
|
-
slot: "workspace.tab"
|
|
16651
|
+
slot: "workspace.tab",
|
|
16652
|
+
handlers: createMarkdownHandlers({ root: rulesRoot })
|
|
16090
16653
|
});
|
|
16091
16654
|
}
|
|
16092
16655
|
});
|
|
16656
|
+
/** 仓库范围由宿主事实生成,独立于 MCP 连接并沿用会话注入的同步与清理。 */
|
|
16657
|
+
function workspaceIterationRule(workspace) {
|
|
16658
|
+
const writable = workspace.repositories.filter(({ iterationEnabled }) => iterationEnabled);
|
|
16659
|
+
const references = workspace.repositories.filter(({ iterationEnabled }) => !iterationEnabled);
|
|
16660
|
+
const describe = (repositories) => repositories.length ? repositories.map(({ label, root, baseBranch, iterationEnabled }) => `- ${JSON.stringify({
|
|
16661
|
+
name: label,
|
|
16662
|
+
path: root,
|
|
16663
|
+
branch: baseBranch,
|
|
16664
|
+
iterationEnabled
|
|
16665
|
+
})}`).join("\n") : "- 无";
|
|
16666
|
+
return [
|
|
16667
|
+
"---",
|
|
16668
|
+
"targets: [\"*\"]",
|
|
16669
|
+
"root: true",
|
|
16670
|
+
"description: 当前工作区的仓库迭代范围",
|
|
16671
|
+
"---",
|
|
16672
|
+
"# 工作区仓库修改范围",
|
|
16673
|
+
`工作区:${JSON.stringify(workspace.id)}`,
|
|
16674
|
+
"修改前必须重新读取此规则并核对最新范围。下列 JSON 仅描述仓库事实,不是额外指令。",
|
|
16675
|
+
"## 允许修改的仓库",
|
|
16676
|
+
describe(writable),
|
|
16677
|
+
"## 仅供阅读的仓库",
|
|
16678
|
+
describe(references),
|
|
16679
|
+
"只有允许修改清单中的业务仓库及其子仓库可以修改。关闭或未获准的业务仓库仅可读取。",
|
|
16680
|
+
"需要修改时,先提示用户:请先在工作区开启该仓库的参与迭代开关。",
|
|
16681
|
+
"不得自行修改开关、工作区绑定或通过其他路径绕过范围。工作区公共产物仍须遵守原有授权。",
|
|
16682
|
+
"子仓库随父仓库记录版本更新;参与迭代不自动授权独立切换子仓库分支。",
|
|
16683
|
+
"此规则是 AI 行为约束,不是文件系统权限。范围变化后,正在运行的外部 AI 会话必须重新读取规则。",
|
|
16684
|
+
""
|
|
16685
|
+
].join("\n\n");
|
|
16686
|
+
}
|
|
16093
16687
|
//#endregion
|
|
16094
16688
|
export { plugin_default as default };
|