@dsh-plus/agent-preset-rea 0.1.0 → 0.1.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/lib/client.js CHANGED
@@ -19,6 +19,41 @@ window.__ModuleLoader__.load({
19
19
  children: props.label
20
20
  });
21
21
  }
22
+ function TextField(props) {
23
+ const p = props.prefix ?? "dshp";
24
+ const invalid = props.invalid === true;
25
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
26
+ className: `${p}-field`,
27
+ children: [
28
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
29
+ className: `${p}-head`,
30
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
31
+ className: `${p}-label`,
32
+ htmlFor: props.id,
33
+ children: props.label
34
+ }), props.badge !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
35
+ className: `${p}-badge ${props.badge.set ? `${p}-badgeSet` : `${p}-badgeUnset`}`,
36
+ children: props.badge.text
37
+ }) : null]
38
+ }),
39
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
40
+ id: props.id,
41
+ className: `${p}-input${invalid ? ` ${p}-inputInvalid` : ""}`,
42
+ type: props.password === true ? "password" : "text",
43
+ inputMode: props.numeric === true ? "numeric" : void 0,
44
+ autoComplete: props.password === true ? "off" : void 0,
45
+ "aria-invalid": invalid || void 0,
46
+ value: props.value,
47
+ disabled: props.disabled === true,
48
+ onChange: (event) => props.onEdit(event.target.value)
49
+ }),
50
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
51
+ className: invalid ? `${p}-invalid` : `${p}-hint`,
52
+ children: invalid ? props.invalidLabel ?? "" : props.hint ?? ""
53
+ })
54
+ ]
55
+ });
56
+ }
22
57
  //#endregion
23
58
  //#region ../shared/src/client/card.tsx
24
59
  const IDLE_STATUS = {
@@ -194,6 +229,27 @@ window.__ModuleLoader__.load({
194
229
  };
195
230
  }
196
231
  //#endregion
232
+ //#region ../shared/src/client/fetch.ts
233
+ async function parse(res, guard) {
234
+ const body = await res.json();
235
+ if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`);
236
+ if (guard !== void 0 && !guard(body)) throw new Error(`响应结构不符合预期(${res.url})`);
237
+ return body;
238
+ }
239
+ /** GET 同源 JSON 端点。 */
240
+ async function getJson(route, guard) {
241
+ return parse(await fetch(route, { credentials: "same-origin" }), guard);
242
+ }
243
+ /** POST 同源 JSON 端点(body 可省略)。 */
244
+ async function postJson(route, body, guard) {
245
+ return parse(await fetch(route, {
246
+ method: "POST",
247
+ credentials: "same-origin",
248
+ headers: { "content-type": "application/json" },
249
+ ...body === void 0 ? {} : { body: JSON.stringify(body) }
250
+ }), guard);
251
+ }
252
+ //#endregion
197
253
  //#region ../shared/src/client/i18n.ts
198
254
  /** 卡片通用文案(save/discard/unsaved/loading 等四插件共有键)。 */
199
255
  const commonZh = {
@@ -434,34 +490,413 @@ ${extra}
434
490
  * @module @dsh-plus/agent-preset-rea/ns
435
491
  */
436
492
  const SETTINGS_NS = "dsh-plus-agent-preset-rea";
437
- //#endregion
438
- //#region src/client/draft.ts
439
- /** 解析值 → 草稿(非字符串一律视为空串)。 */
493
+ /** 解析值 → 草稿(类型不符一律回落默认)。 */
440
494
  function draftFromValue(value) {
441
- return { personaPrefix: typeof value.personaPrefix === "string" ? value.personaPrefix : "" };
495
+ return {
496
+ personaPrefix: typeof value.personaPrefix === "string" ? value.personaPrefix : "",
497
+ proxyPort: typeof value.proxyPort === "number" ? String(value.proxyPort) : ""
498
+ };
499
+ }
500
+ /**
501
+ * 代理端口文本 → 端口号。
502
+ * @returns 空串按 0(不用代理);非纯数字或越界返回 null(调用方据此判非法)。
503
+ */
504
+ function parseProxyPort(text) {
505
+ const trimmed = text.trim();
506
+ if (trimmed === "") return 0;
507
+ if (!/^\d+$/.test(trimmed)) return null;
508
+ const port = Number(trimmed);
509
+ return Number.isInteger(port) && port >= 0 && port <= 65535 ? port : null;
442
510
  }
443
511
  /** 草稿 → 提交形状(只回写本卡片负责的字段)。 */
444
512
  function toPatch(draft) {
445
- return { personaPrefix: draft.personaPrefix };
513
+ return {
514
+ personaPrefix: draft.personaPrefix,
515
+ proxyPort: parseProxyPort(draft.proxyPort) ?? 0
516
+ };
517
+ }
518
+ //#endregion
519
+ //#region src/client/api.ts
520
+ /**
521
+ * 受管安装/更新的端点通道(状态查询 + 三类动作)。
522
+ * 配置读写仍走 `ctx.remote.settings` 直连(见 card.tsx),这里只补官方传输没有的动作。
523
+ *
524
+ * 响应都经类型谓词在边界收窄:宿主契约漂移时立即报错,而不是渲染期白屏。
525
+ * @module agent-preset-rea/client/api
526
+ */
527
+ const ROUTE_BASE = "/dsh-plus/agent-preset-rea";
528
+ /** JobDto 守卫。 */
529
+ function isJob(value) {
530
+ if (typeof value !== "object" || value === null) return false;
531
+ const job = value;
532
+ return typeof job["id"] === "number" && typeof job["kind"] === "string" && typeof job["state"] === "string" && Array.isArray(job["log"]) && typeof job["progress"] === "object" && job["progress"] !== null;
533
+ }
534
+ /** StatusDto 守卫(结构性字段缺席即判不符)。 */
535
+ function isStatus(value) {
536
+ if (typeof value !== "object" || value === null) return false;
537
+ const body = value;
538
+ const install = body["install"];
539
+ const skill = body["skill"];
540
+ const mcp = body["mcp"];
541
+ return typeof install === "object" && install !== null && typeof skill === "object" && skill !== null && typeof mcp === "object" && mcp !== null && typeof body["config"] === "object" && body["config"] !== null;
542
+ }
543
+ /** JobActionDto 守卫。 */
544
+ const isJobAction = (value) => {
545
+ if (typeof value !== "object" || value === null) return false;
546
+ const job = value["job"];
547
+ return job === null || job === void 0 || isJob(job);
548
+ };
549
+ /** 查询安装/skill/MCP 行状态与当前作业。 */
550
+ async function fetchStatus() {
551
+ return getJson(`${ROUTE_BASE}/status`, isStatus);
552
+ }
553
+ /**
554
+ * 启动作业。
555
+ * @param kind - `install` = 安装/更新 REA 包;`skill` = 拉取并替换 skill 副本。
556
+ * @param proxyPort - 草稿里当前填的代理端口(未保存也即时生效)。
557
+ */
558
+ async function startJob(kind, proxyPort) {
559
+ return postJson(`${ROUTE_BASE}/${kind}`, { proxyPort }, isJobAction);
560
+ }
561
+ /** 取消当前作业。 */
562
+ async function cancelJob() {
563
+ return postJson(`${ROUTE_BASE}/cancel`, void 0, isJobAction);
564
+ }
565
+ //#endregion
566
+ //#region src/client/install.tsx
567
+ /**
568
+ * 卡片的「REA 安装与更新」区:只读状态表 + 三个动作(安装/更新 REA、更新 skill、
569
+ * 取消作业)+ 运行中作业的阶段进度条、已用时与日志尾部。
570
+ *
571
+ * 状态与作业都来自宿主半的同源端点(见 client/api.ts 与宿主 routes.ts):这里只管
572
+ * 轮询与呈现。作业在跑时按 {@link PROGRESS_POLL_MS} 轮询——进度是宿主侧的真事实,
573
+ * 浏览器不自己造百分比。
574
+ * @module agent-preset-rea/client/install
575
+ */
576
+ /** 作业运行中的状态轮询间隔(毫秒)。 */
577
+ const PROGRESS_POLL_MS = 1e3;
578
+ /** 错误对象 → 人话。 */
579
+ function messageOf(error) {
580
+ return error instanceof Error ? error.message : String(error);
581
+ }
582
+ /** 起止时间 → 已用时文本。 */
583
+ function elapsedOf(job) {
584
+ const start = Date.parse(job.startedAt);
585
+ if (Number.isNaN(start)) return "—";
586
+ const end = job.finishedAt === null ? Date.now() : Date.parse(job.finishedAt);
587
+ const seconds = Math.max(0, Math.round((end - start) / 1e3));
588
+ if (seconds < 60) return `${seconds}s`;
589
+ return `${Math.floor(seconds / 60)}m${String(seconds % 60).padStart(2, "0")}s`;
590
+ }
591
+ /** 作业状态 → 徽标类名后缀(视觉区分运行中/成功/失败)。 */
592
+ const STATE_CLASS = {
593
+ running: "Running",
594
+ ok: "Ok",
595
+ error: "Error",
596
+ cancelled: "Cancelled"
597
+ };
598
+ /** 作业进度块:状态徽标 + 阶段 + 进度条 + 日志尾部。 */
599
+ function JobPanel(props) {
600
+ const { t, job } = props;
601
+ const stateKey = job.state === "running" ? "jobRunning" : job.state === "ok" ? "jobOk" : job.state === "error" ? "jobError" : "jobCancelled";
602
+ const lines = job.log.slice(-12);
603
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
604
+ className: "apr-job",
605
+ children: [
606
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
607
+ className: "apr-jobHead",
608
+ children: [
609
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
610
+ className: `apr-pill apr-pill${STATE_CLASS[job.state]}`,
611
+ children: t(stateKey)
612
+ }),
613
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
614
+ className: "apr-jobTitle",
615
+ children: t(job.kind === "install" ? "jobInstall" : "jobSkill")
616
+ }),
617
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
618
+ className: "apr-hint",
619
+ children: [
620
+ t("jobPhase"),
621
+ " ",
622
+ job.progress.step,
623
+ "/",
624
+ job.progress.steps,
625
+ "·",
626
+ job.progress.phase
627
+ ]
628
+ }),
629
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
630
+ className: "apr-hint",
631
+ children: [
632
+ t("jobElapsed"),
633
+ " ",
634
+ elapsedOf(job)
635
+ ]
636
+ })
637
+ ]
638
+ }),
639
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
640
+ className: "apr-bar",
641
+ role: "progressbar",
642
+ "aria-valuemin": 0,
643
+ "aria-valuemax": 100,
644
+ "aria-valuenow": job.progress.percent,
645
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
646
+ className: "apr-barFill",
647
+ style: { width: `${job.progress.percent}%` }
648
+ })
649
+ }),
650
+ job.error === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
651
+ className: "apr-error",
652
+ children: job.error
653
+ }),
654
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
655
+ className: "apr-logBox",
656
+ open: job.state !== "ok",
657
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", {
658
+ className: "apr-logSummary",
659
+ children: t("jobLog")
660
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
661
+ className: "apr-log",
662
+ children: lines.length === 0 ? t("jobLogEmpty") : lines.join("\n")
663
+ })]
664
+ })
665
+ ]
666
+ });
667
+ }
668
+ /** 一行状态(键 + 值)。 */
669
+ function StatusRow(props) {
670
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
671
+ className: "apr-installRow",
672
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", {
673
+ className: "apr-installKey",
674
+ children: props.label
675
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
676
+ className: "apr-installVal",
677
+ children: props.children
678
+ })]
679
+ });
680
+ }
681
+ /** 只读状态表:REA 包 / 受管目录 / skill 来源 / MCP 行形态。 */
682
+ function StatusTable(props) {
683
+ const { t, status } = props;
684
+ const skillLabel = status.skill.source === "updated" ? t("skillUpdated") : t("skillBundled");
685
+ const mcpLabel = !status.mcp.enabled ? status.config.mcpEnabled ? t("mcpMissing") : t("mcpOff") : status.mcp.mode === "custom" ? t("mcpCustom") : t("mcpInstalled");
686
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dl", {
687
+ className: "apr-install",
688
+ children: [
689
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(StatusRow, {
690
+ label: t("installPackage"),
691
+ children: [
692
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
693
+ className: `apr-pill ${status.install.installed ? "apr-pillOk" : "apr-pillMiss"}`,
694
+ children: t(status.install.installed ? "installed" : "notInstalled")
695
+ }),
696
+ status.install.version === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
697
+ className: "apr-mono",
698
+ children: status.install.version
699
+ }),
700
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
701
+ className: "apr-hint",
702
+ children: [
703
+ t("installTarget"),
704
+ " ",
705
+ status.config.reaVersion
706
+ ]
707
+ })
708
+ ]
709
+ }),
710
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusRow, {
711
+ label: t("installPath"),
712
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
713
+ className: "apr-mono",
714
+ children: status.install.root
715
+ })
716
+ }),
717
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(StatusRow, {
718
+ label: t("skillSource"),
719
+ children: [
720
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
721
+ className: "apr-mono",
722
+ children: skillLabel
723
+ }),
724
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
725
+ className: "apr-hint",
726
+ children: [
727
+ t("skillFiles"),
728
+ " ",
729
+ status.skill.files,
730
+ status.skill.version === null ? "" : ` · ${status.skill.version}`
731
+ ]
732
+ }),
733
+ status.skill.updatedAt === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
734
+ className: "apr-hint",
735
+ children: [
736
+ t("updatedAt"),
737
+ " ",
738
+ status.skill.updatedAt
739
+ ]
740
+ })
741
+ ]
742
+ }),
743
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(StatusRow, {
744
+ label: t("mcpRow"),
745
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
746
+ className: "apr-mono",
747
+ children: mcpLabel
748
+ }), status.mcp.command === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("code", {
749
+ className: "apr-mono",
750
+ children: [
751
+ status.mcp.command,
752
+ " ",
753
+ status.mcp.args.join(" ")
754
+ ]
755
+ })]
756
+ })
757
+ ]
758
+ });
759
+ }
760
+ function InstallSection(props) {
761
+ const { t, disabled, proxyPort } = props;
762
+ const [status, setStatus] = (0, react.useState)(null);
763
+ const [error, setError] = (0, react.useState)(null);
764
+ const [busy, setBusy] = (0, react.useState)(false);
765
+ const alive = (0, react.useRef)(true);
766
+ (0, react.useEffect)(() => () => {
767
+ alive.current = false;
768
+ }, []);
769
+ const load = (0, react.useCallback)(async () => {
770
+ try {
771
+ const next = await fetchStatus();
772
+ if (!alive.current) return;
773
+ setStatus(next);
774
+ setError(null);
775
+ } catch (failure) {
776
+ if (alive.current) setError(`${t("statusFailed")}${messageOf(failure)}`);
777
+ }
778
+ }, [t]);
779
+ (0, react.useEffect)(() => {
780
+ load();
781
+ }, [load]);
782
+ const running = status?.job?.state === "running";
783
+ (0, react.useEffect)(() => {
784
+ if (running !== true) return;
785
+ const timer = window.setInterval(() => {
786
+ load();
787
+ }, PROGRESS_POLL_MS);
788
+ return () => {
789
+ window.clearInterval(timer);
790
+ };
791
+ }, [running, load]);
792
+ const runAction = (0, react.useCallback)((action) => {
793
+ setBusy(true);
794
+ setError(null);
795
+ action().then((result) => {
796
+ if (!alive.current) return;
797
+ setStatus((prev) => prev === null ? prev : {
798
+ ...prev,
799
+ job: result.job
800
+ });
801
+ load();
802
+ }).catch((failure) => {
803
+ if (alive.current) setError(`${t("actionFailed")}${messageOf(failure)}`);
804
+ }).finally(() => {
805
+ if (alive.current) setBusy(false);
806
+ });
807
+ }, [load, t]);
808
+ const blocked = disabled || busy || running === true;
809
+ const job = status?.job ?? null;
810
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
811
+ className: "apr-field",
812
+ children: [
813
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
814
+ className: "apr-head",
815
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
816
+ className: "apr-label",
817
+ children: t("installSection")
818
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
819
+ prefix: "apr",
820
+ label: t("refreshStatus"),
821
+ disabled: busy || running === true,
822
+ onClick: () => {
823
+ load();
824
+ }
825
+ })]
826
+ }),
827
+ status === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
828
+ className: "apr-hint",
829
+ children: t("statusLoading")
830
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusTable, {
831
+ t,
832
+ status
833
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
834
+ className: "apr-btnRow",
835
+ children: [
836
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
837
+ prefix: "apr",
838
+ variant: "primary",
839
+ label: t("installAction"),
840
+ disabled: blocked || proxyPort === null,
841
+ onClick: () => {
842
+ runAction(() => startJob("install", proxyPort ?? 0));
843
+ }
844
+ }),
845
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
846
+ prefix: "apr",
847
+ label: t("skillAction"),
848
+ disabled: blocked || proxyPort === null,
849
+ onClick: () => {
850
+ runAction(() => startJob("skill", proxyPort ?? 0));
851
+ }
852
+ }),
853
+ running === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
854
+ prefix: "apr",
855
+ label: t("cancelAction"),
856
+ disabled: busy,
857
+ onClick: () => {
858
+ runAction(() => cancelJob());
859
+ }
860
+ }) : null
861
+ ]
862
+ })] }),
863
+ job === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(JobPanel, {
864
+ t,
865
+ job
866
+ }),
867
+ error === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
868
+ className: "apr-error",
869
+ children: error
870
+ }),
871
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
872
+ className: "apr-hint",
873
+ children: t("installHint")
874
+ })
875
+ ]
876
+ });
446
877
  }
447
878
  //#endregion
448
879
  //#region src/client/card.tsx
449
880
  /**
450
- * 「逆向工程」预设配置卡片:唯一字段是 persona 提示词。
881
+ * 「逆向工程」预设配置卡片:提示词(活动字段)+ 代理端口(活动字段)+ 安装维护区。
451
882
  *
452
883
  * 经 injectPluginConfigCard 注册(插件页 plugins.row.config / plugins.bundle.config,
453
884
  * view 分发 summary/page);外壳与草稿语义走 @dsh-plus/shared/client 套件
454
885
  * (CardChrome + useNamespaceDraft:staged 草稿、脏判定、revision fencing、
455
- * Host 更新不覆盖在途编辑)。
886
+ * Host 更新不覆盖在途编辑),安装维护区见 client/install.tsx。
887
+ *
888
+ * 两个活动字段(`Config` 里标 `.volatile()` 的)都在这里给出编辑器:
889
+ * - `personaPrefix`:system-prompt 的 persona 前缀段;
890
+ * - `proxyPort`:安装/更新时的本机代理端口。
891
+ * 其余字段(安装位置、MCP 参数、超时、附加 skill 根)属部署方平面,由 profile 的
892
+ * cordis.patch.yml 行级配置覆盖,卡片只读展示关键事实。
456
893
  *
457
- * 为什么只有这一个字段:`Config` 里只有 `personaPrefix` 标了 `.volatile()`
458
- * (对用户的承诺=必须给编辑器);MCP 参数、超时、附加 skill 根等属部署方平面,
459
- * 由 profile 的 cordis.patch.yml 行级配置覆盖,因此卡片底部只作说明。
460
- * 保存后 loader 原位提交活动引用并广播 `loader/volatile-update`,宿主半据此换代
461
- * 注册预设声明——新建会话即用新提示词,已存在会话保持原装配。
894
+ * 安装维护为什么不放在注册期自动做:启动期 `npx`/npm 安装会跑依赖安装脚本
895
+ * (原生 prebuild 下载),卡住即吊死预设激活与整个名册;因此改成显式动作
896
+ * ——后台作业 + 轮询实时进度,作业完成后宿主半换代注册,新建会话即用新事实。
462
897
  * @module agent-preset-rea/client/card
463
898
  */
464
- /** 卡片动作:放弃 / 保存(仅脏且可写时可用)。 */
899
+ /** 卡片动作:放弃 / 保存(脏且可写且输入合法时才可用)。 */
465
900
  function cardActions(options) {
466
901
  return [{
467
902
  key: "discard",
@@ -472,7 +907,7 @@ ${extra}
472
907
  key: "save",
473
908
  label: options.t(options.saving ? "saving" : "save"),
474
909
  variant: "primary",
475
- disabled: !options.dirty || options.saving || options.disabled,
910
+ disabled: !options.dirty || options.saving || options.disabled || options.invalid,
476
911
  onClick: options.onSave
477
912
  }];
478
913
  }
@@ -492,7 +927,8 @@ ${extra}
492
927
  text: t("loading")
493
928
  });
494
929
  const disabled = state.disabled;
495
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CardChrome, {
930
+ const port = parseProxyPort(draft.proxyPort);
931
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CardChrome, {
496
932
  prefix: "apr",
497
933
  title: t("title"),
498
934
  description: t("description"),
@@ -505,40 +941,60 @@ ${extra}
505
941
  dirty: state.dirty,
506
942
  saving: state.saving,
507
943
  disabled,
944
+ invalid: port === null,
508
945
  onDiscard: state.reset,
509
946
  onSave: state.save
510
947
  }),
511
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
512
- className: "apr-field",
513
- children: [
514
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
515
- className: "apr-head",
516
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
517
- className: "apr-label",
518
- htmlFor: "apr-prompt",
519
- children: t("prompt")
520
- })
521
- }),
522
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
523
- id: "apr-prompt",
524
- className: "apr-textarea",
525
- rows: 10,
526
- spellCheck: false,
527
- placeholder: t("promptPlaceholder"),
528
- value: draft.personaPrefix,
529
- disabled,
530
- onChange: (event) => state.edit({ personaPrefix: event.target.value })
531
- }),
532
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
533
- className: "apr-hint",
534
- children: t("promptHint")
535
- }),
536
- draft.personaPrefix.trim() === "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
537
- className: "apr-hint",
538
- children: t("promptEmpty")
539
- }) : null
540
- ]
541
- })
948
+ children: [
949
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
950
+ className: "apr-field",
951
+ children: [
952
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
953
+ className: "apr-head",
954
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
955
+ className: "apr-label",
956
+ htmlFor: "apr-prompt",
957
+ children: t("prompt")
958
+ })
959
+ }),
960
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
961
+ id: "apr-prompt",
962
+ className: "apr-textarea",
963
+ rows: 10,
964
+ spellCheck: false,
965
+ placeholder: t("promptPlaceholder"),
966
+ value: draft.personaPrefix,
967
+ disabled,
968
+ onChange: (event) => state.edit({ personaPrefix: event.target.value })
969
+ }),
970
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
971
+ className: "apr-hint",
972
+ children: t("promptHint")
973
+ }),
974
+ draft.personaPrefix.trim() === "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
975
+ className: "apr-hint",
976
+ children: t("promptEmpty")
977
+ }) : null
978
+ ]
979
+ }),
980
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
981
+ prefix: "apr",
982
+ id: "apr-proxy",
983
+ label: t("proxyPort"),
984
+ hint: t("proxyPortHint"),
985
+ invalid: port === null,
986
+ invalidLabel: t("proxyPortInvalid"),
987
+ numeric: true,
988
+ value: draft.proxyPort,
989
+ disabled,
990
+ onEdit: (text) => state.edit({ proxyPort: text })
991
+ }),
992
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InstallSection, {
993
+ t,
994
+ disabled,
995
+ proxyPort: port
996
+ })
997
+ ]
542
998
  });
543
999
  }
544
1000
  //#endregion
@@ -551,32 +1007,116 @@ ${extra}
551
1007
  const NS = "dsh-plus-agent-preset-rea";
552
1008
  const ownZh = {
553
1009
  title: "逆向工程预设",
554
- description: "REA 提示词:留空即空 persona,工具指引与运行时上下文照常由官方装配注入。",
555
- summaryLine: "编辑「逆向工程」预设的 persona 提示词",
1010
+ description: "REA 提示词与安装维护:提示词留空即空 persona,工具指引与运行时上下文照常注入。",
1011
+ summaryLine: "编辑「逆向工程」预设的提示词,并安装/更新 REA 与 skill",
556
1012
  prompt: "系统提示词(persona 前缀)",
557
1013
  promptHint: "写入 system-prompt 的 persona 前缀段,仅对「逆向工程」预设的新会话生效;留空 = 不注入 persona 段(官方工具指引、项目指令与运行时上下文不受影响)。保存后新建会话即用新值。",
558
1014
  promptPlaceholder: "例如:先做证据分级,再动手改二进制;每一步给出可复核的证据链……",
559
1015
  promptEmpty: "当前为空:该预设不注入 persona 段。",
560
- saveFailed: "保存失败:"
1016
+ saveFailed: "保存失败:",
1017
+ installSection: "REA 安装与更新",
1018
+ installHint: "安装/更新在后台执行:把 rea-agents 装进下面的受管目录(先装 staging 再换目录,失败不留半截安装树),作业完成后本预设自动换代——新建会话即带 mcp__rea__* 工具。安装位置与 MCP 命令属部署方平面(profile 的 cordis.patch.yml),此处只读展示。",
1019
+ installPackage: "REA 包",
1020
+ installPath: "受管安装目录",
1021
+ installVersion: "版本",
1022
+ installTarget: "目标版本",
1023
+ installed: "已安装",
1024
+ notInstalled: "未安装",
1025
+ skillSource: "REA skill",
1026
+ skillBundled: "随包副本",
1027
+ skillUpdated: "手动更新副本",
1028
+ skillFiles: "文件",
1029
+ updatedAt: "更新时间",
1030
+ mcpRow: "MCP 行",
1031
+ mcpInstalled: "已挂载(受管安装入口)",
1032
+ mcpCustom: "已挂载(显式 mcpCommand)",
1033
+ mcpMissing: "未挂载:未安装 REA,该行已禁用(不会在启动期拉取)",
1034
+ mcpOff: "已按配置关闭",
1035
+ commandLabel: "命令",
1036
+ refreshStatus: "刷新状态",
1037
+ installAction: "安装 / 更新 REA",
1038
+ skillAction: "更新 skill",
1039
+ cancelAction: "取消作业",
1040
+ statusLoading: "正在读取安装状态…",
1041
+ statusFailed: "状态查询失败:",
1042
+ actionFailed: "操作失败:",
1043
+ jobRunning: "作业进行中",
1044
+ jobOk: "作业完成",
1045
+ jobError: "作业失败",
1046
+ jobCancelled: "作业已取消",
1047
+ jobInstall: "安装 REA",
1048
+ jobSkill: "更新 skill",
1049
+ jobPhase: "阶段",
1050
+ jobLog: "日志",
1051
+ jobStartedAt: "开始于",
1052
+ jobFinishedAt: "结束于",
1053
+ jobElapsed: "已用时",
1054
+ jobLogEmpty: "(暂无输出)",
1055
+ proxyPort: "安装代理端口",
1056
+ proxyPortHint: "安装/更新时供 npm 与原生依赖(node-pty)prebuild 下载使用的本机代理端口;0 或留空 = 直连。未保存也用于本次安装,保存后长期生效。",
1057
+ proxyPortInvalid: "代理端口必须是 0..65535 的整数。"
561
1058
  };
562
1059
  const ownEn = {
563
1060
  title: "Reverse-engineering preset",
564
- description: "REA prompt: leave it empty for a blank persona; official tool guidance and runtime context stay in place.",
565
- summaryLine: "Edit the persona prompt of the “逆向工程” preset",
1061
+ description: "REA prompt and installation: an empty prompt means a blank persona; tool guidance and runtime context stay in place.",
1062
+ summaryLine: "Edit the “逆向工程” prompt and install/update REA and its skill",
566
1063
  prompt: "System prompt (persona prefix)",
567
1064
  promptHint: "Written to the persona-prefix section of the system prompt for new sessions of this preset only. Empty means no persona section (official tool guidance, project instructions and runtime context are unaffected). New sessions pick up the saved value.",
568
1065
  promptPlaceholder: "e.g. Grade the evidence first, then patch the binary; every step needs a checkable chain of evidence…",
569
1066
  promptEmpty: "Currently empty: this preset injects no persona section.",
570
- saveFailed: "Save failed: "
1067
+ saveFailed: "Save failed: ",
1068
+ installSection: "REA installation",
1069
+ installHint: "Install/update runs in the background: rea-agents goes into the managed directory below (staged install, then directory swap, so a failure leaves no half tree). When the job finishes the preset re-registers — new sessions get the mcp__rea__* tools. The install location and MCP command belong to the deployment plane (profile cordis.patch.yml) and are shown read-only.",
1070
+ installPackage: "REA package",
1071
+ installPath: "Managed install dir",
1072
+ installVersion: "Version",
1073
+ installTarget: "Target version",
1074
+ installed: "Installed",
1075
+ notInstalled: "Not installed",
1076
+ skillSource: "REA skill",
1077
+ skillBundled: "Bundled copy",
1078
+ skillUpdated: "Manually updated copy",
1079
+ skillFiles: "Files",
1080
+ updatedAt: "Updated at",
1081
+ mcpRow: "MCP row",
1082
+ mcpInstalled: "Mounted (managed install entry)",
1083
+ mcpCustom: "Mounted (explicit mcpCommand)",
1084
+ mcpMissing: "Not mounted: REA is not installed, the row stays disabled (nothing is fetched at boot)",
1085
+ mcpOff: "Disabled by config",
1086
+ commandLabel: "Command",
1087
+ refreshStatus: "Refresh status",
1088
+ installAction: "Install / update REA",
1089
+ skillAction: "Update skill",
1090
+ cancelAction: "Cancel job",
1091
+ statusLoading: "Reading install status…",
1092
+ statusFailed: "Status query failed: ",
1093
+ actionFailed: "Action failed: ",
1094
+ jobRunning: "Job running",
1095
+ jobOk: "Job finished",
1096
+ jobError: "Job failed",
1097
+ jobCancelled: "Job cancelled",
1098
+ jobInstall: "Install REA",
1099
+ jobSkill: "Update skill",
1100
+ jobPhase: "Phase",
1101
+ jobLog: "Log",
1102
+ jobStartedAt: "Started",
1103
+ jobFinishedAt: "Finished",
1104
+ jobElapsed: "Elapsed",
1105
+ jobLogEmpty: "(no output yet)",
1106
+ proxyPort: "Install proxy port",
1107
+ proxyPortHint: "Local proxy port used by npm and by the native node-pty prebuild download during install/update; 0 or empty means direct. The unsaved value is used for the next install and applies permanently once saved.",
1108
+ proxyPortInvalid: "Proxy port must be an integer in 0..65535."
571
1109
  };
572
1110
  const zh = mergeDict(commonZh, ownZh);
573
1111
  const en = mergeDict(commonEn, ownEn);
574
1112
  //#endregion
575
1113
  //#region src/client/styles.ts
576
1114
  /**
577
- * 配置卡片样式:基础规则走 @dsh-plus/shared/client 的 cardCss('apr'),
578
- * 本文件只补插件特有规则(提示词多行输入框)。
1115
+ * 配置卡片样式:基础规则走 @dsh-plus/shared/client 的 cardCss('apr')
1116
+ * (按钮/字段/徽标等类名由共享控件生成,本文件**不**重复定义),这里只补
1117
+ * 插件特有规则:提示词多行框、安装状态表、作业进度条与日志。
579
1118
  * 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载)。
1119
+ * 颜色与度量全部走官方主题变量(--dsw-alias-*),不写死色值。
580
1120
  * @module agent-preset-rea/client/styles
581
1121
  */
582
1122
  const PLUGIN_ID = "@dsh-plus/agent-preset-rea";
@@ -586,8 +1126,28 @@ ${extra}
586
1126
  .apr-textarea:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
587
1127
  .apr-textarea:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
588
1128
  .apr-textarea::placeholder{color:var(--dsw-alias-label-tertiary)}
1129
+ .apr-btnRow{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}
1130
+ .apr-install{margin:6px 0 0;padding:0;display:flex;flex-direction:column;gap:6px}
1131
+ .apr-installRow{display:flex;gap:10px;align-items:baseline;flex-wrap:wrap}
1132
+ .apr-installKey{flex:none;width:118px;margin:0;font-size:12px;color:var(--dsw-alias-label-tertiary)}
1133
+ .apr-installVal{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin:0;font-size:13px;color:var(--dsw-alias-label-primary)}
1134
+ .apr-mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;word-break:break-all}
1135
+ .apr-pill{flex:none;padding:2px 8px;border-radius:999px;font-size:11px;line-height:16px}
1136
+ .apr-pillOk{background:var(--dsw-alias-state-success-secondary);color:var(--dsw-alias-state-success-primary)}
1137
+ .apr-pillMiss,.apr-pillError,.apr-pillCancelled{background:var(--dsw-alias-state-error-secondary);color:var(--dsw-alias-state-error-primary)}
1138
+ .apr-pillRunning{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
1139
+ .apr-job{margin-top:12px;padding:10px 12px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-3)}
1140
+ .apr-jobHead{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
1141
+ .apr-jobTitle{font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary)}
1142
+ .apr-bar{margin-top:8px;height:6px;border-radius:999px;background:var(--dsw-alias-interactive-bg-hover);overflow:hidden}
1143
+ .apr-barFill{height:100%;background:var(--dsw-alias-brand-primary);transition:width .3s}
1144
+ .apr-logBox{margin-top:8px}
1145
+ .apr-logSummary{font-size:12px;color:var(--dsw-alias-label-tertiary);cursor:pointer}
1146
+ .apr-log{margin:6px 0 0;max-height:200px;overflow:auto;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;line-height:1.5;white-space:pre-wrap;word-break:break-all;color:var(--dsw-alias-label-tertiary)}
1147
+ .apr-error{margin:4px 0 0;font-size:12px;color:var(--dsw-alias-state-error-primary)}
589
1148
  @media (max-width:767px){
590
1149
  .apr-textarea{font-size:16px;min-height:140px}
1150
+ .apr-installKey{width:100%}
591
1151
  }
592
1152
  `);
593
1153
  /** 幂等注入样式标签;返回标签(已存在或环境无 document 时为 null)。 */