@inventec/dsh-copilot-auth 1.2.24 → 1.2.25
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/README.md +3 -2
- package/lib/client.js +47 -17
- package/package.json +1 -1
- package/src/auth-host.mjs +9 -1
- package/src/host.mjs +20 -1
- package/src/refresh-flow.mjs +30 -12
- package/src/refresh-service.mjs +19 -1
- package/src/refresh-transaction.mjs +8 -3
package/README.md
CHANGED
|
@@ -64,8 +64,9 @@ pi-ai 的模型目录是打包时硬编码的 JSON:上游新增模型在本机
|
|
|
64
64
|
- **勾选即终态**:一张分组全表——**可新增**(账号可用 ∩ 目录可解析,默认不勾)、**在列**(默认勾选)、**待删除候选**(在列但账号未报告 / 目录无法解析,默认不勾=删除提案,重新勾选即**挽留**)。应用时被保留模型的对象、顺序与定制逐字保留,被移除模型的定制随模型消失。
|
|
65
65
|
- **快捷动作**:「全选 / 取消全选」作用于全表;「**对齐账号与目录**」仅在漂移时出现,一键把勾选态设为账号 ∩ 可解析;「**同时清除全部模型定制**」复选框仅在存在可清除定制时出现;摘要行常驻显示「应用后共 N 个:保留 · 新增 · 移除」。
|
|
66
66
|
- **证据门控按实际 diff**:纯新增可用 24 小时内同授权的缓存;**移除类变更强制实时账号证据 + 最新目录并二次确认**(缓存下勾选删除会自动升级为实时预览);空目标需单独确认,落显式空列表且不会被登录自动回填。移除所需的实时证据会在本地会话令牌过期时**自动续期**(仅内存、不落库);续期仍失败时,来源行会给出原因与出路(先用一次模型 / 重新授权 / 稍后重试)。
|
|
67
|
-
- **生效时机**:web /
|
|
68
|
-
- **并发与恢复**:每个操作带服务端签发的 operationId(幂等可查、绝不重复执行);配置并发编辑永远优先(漂移返回 409 要求重新预览);崩溃 / 重启后可恢复,出现冲突时提供「结束旧配置意图」显式闭环。apply
|
|
67
|
+
- **生效时机**:web / 服务形态先做原子只增补丁、**重启后**生效(页面明确提示「待重启生效」并附「**放弃待重启的更改**」按钮,期间新的应用会被拒绝并给出同提示);desktop(只读 `app.asar`)走进程内注册表注入,**当次生效、无需重启**、不碰官方产物(ADR 0003)。
|
|
68
|
+
- **并发与恢复**:每个操作带服务端签发的 operationId(幂等可查、绝不重复执行);配置并发编辑永远优先(漂移返回 409 要求重新预览);崩溃 / 重启后可恢复,出现冲突时提供「结束旧配置意图」显式闭环。apply 撞上进行中的旧操作(423)且该操作已 `recovery-needed` 或 `pending-restart` 时提供对应出口(前者「结束旧配置意图」,后者「放弃待重启的更改」),出口在弹窗与页面主视图(含刷新后)均可达——know-how 032 缺口闭环 + ADR-0006 扩展;作废 / 放弃后页面如实显示结果与原因,不再残留「待重启生效」提示(评审 Q4)。
|
|
69
|
+
- **授权动作即时作废**(ADR-0006):**登录 / 退出登录会立即作废进行中的模型配置更改**(历史结果中标注原因「授权状态已变化」),已落盘的目录数据保留,重新预览应用即可——无需重启也不会再出现「重启后才失效」的困惑。
|
|
69
70
|
|
|
70
71
|
## 工作原理
|
|
71
72
|
|
package/lib/client.js
CHANGED
|
@@ -192,9 +192,12 @@ function reduce(state, event) {
|
|
|
192
192
|
if (event.type === "retire-request" && state.name === "result") {
|
|
193
193
|
return [{ name: "retireConfirm", result: state.result }, null];
|
|
194
194
|
}
|
|
195
|
-
if (event.type === "retire-request" && state.name === "busy" && state.active?.phaseResult?.status
|
|
195
|
+
if (event.type === "retire-request" && state.name === "busy" && ["recovery-needed", "pending-restart"].includes(state.active?.phaseResult?.status ?? "")) {
|
|
196
196
|
return [{ name: "retireConfirm", active: state.active }, null];
|
|
197
197
|
}
|
|
198
|
+
if (event.type === "retire-request" && state.name === "pendingRestart" && (state.active?.operationId || state.result?.status === "pending-restart" && state.result?.operationId)) {
|
|
199
|
+
return [{ name: "retireConfirm", result: state.result, active: state.active ?? null }, null];
|
|
200
|
+
}
|
|
198
201
|
if (event.type === "dismiss" && state.name === "failed") {
|
|
199
202
|
return [{ ...initial, flags: state.flags }, null];
|
|
200
203
|
}
|
|
@@ -207,7 +210,7 @@ function reduce(state, event) {
|
|
|
207
210
|
return [{ ...base, name: "busy", active: refresh.activeOperation }, null];
|
|
208
211
|
}
|
|
209
212
|
if (restartStates.has(refresh?.lastResult?.status ?? "") || refresh?.pendingRestart === true) {
|
|
210
|
-
return [{ ...base, name: "pendingRestart", result: refresh.lastResult }, null];
|
|
213
|
+
return [{ ...base, name: "pendingRestart", result: refresh.lastResult, active: refresh.activeOperation ?? null }, null];
|
|
211
214
|
}
|
|
212
215
|
const st = refresh?.lastResult?.status;
|
|
213
216
|
if (st && ["recovery-needed", "rollback-conflict", "conflict", "partial", "rolled-back", "intent-retired", "applied"].includes(st)) {
|
|
@@ -347,15 +350,22 @@ function reduce(state, event) {
|
|
|
347
350
|
}
|
|
348
351
|
case "retireConfirm": {
|
|
349
352
|
if (event.type === "retire-confirm") {
|
|
350
|
-
|
|
353
|
+
const retireId = state.active?.operationId ?? state.result?.operationId;
|
|
354
|
+
return [{ name: "retiring", operationId: retireId, result: state.result, active: state.active }, { type: "retire", operationId: retireId }];
|
|
355
|
+
}
|
|
356
|
+
if (event.type === "cancel") {
|
|
357
|
+
if (state.active) return [{ name: "busy", active: state.active }, null];
|
|
358
|
+
if (state.result?.status === "pending-restart") return [{ name: "pendingRestart", result: state.result }, null];
|
|
359
|
+
return [{ name: "result", result: state.result }, null];
|
|
351
360
|
}
|
|
352
|
-
if (event.type === "cancel") return state.active ? [{ name: "busy", active: state.active }, null] : [{ name: "result", result: state.result }, null];
|
|
353
361
|
return [state, null];
|
|
354
362
|
}
|
|
355
363
|
case "retiring": {
|
|
356
364
|
if (event.type === "retire-ok") return [{ ...state, name: "checking" }, { type: "status" }];
|
|
357
365
|
if (event.type === "retire-fail") {
|
|
358
|
-
|
|
366
|
+
if (state.active) return [{ name: "busy", active: state.active, retireError: event.error }, null];
|
|
367
|
+
if (state.result?.status === "pending-restart") return [{ name: "pendingRestart", result: state.result, retireError: event.error }, null];
|
|
368
|
+
return [{ name: "result", result: state.result, retireError: event.error }, null];
|
|
359
369
|
}
|
|
360
370
|
return [state, null];
|
|
361
371
|
}
|
|
@@ -714,6 +724,11 @@ var DICTS = {
|
|
|
714
724
|
retireBtn: "End previous configuration intent",
|
|
715
725
|
retireTitle: "End previous configuration intent",
|
|
716
726
|
retireConfirmText: "End the intent only; existing changes are not rolled back or undone.",
|
|
727
|
+
busyPendingRestart: "The previous change is saved and takes effect after restart. New changes cannot be applied until then \u2014 wait for the restart, or discard that change.",
|
|
728
|
+
retireBtnPending: "Discard the pending change",
|
|
729
|
+
retireConfirmPending: "Discarding drops this pending change; catalog data already written is kept. Preview and apply again afterwards.",
|
|
730
|
+
retiredByAuth: "Authorization changed (sign-in or sign-out) and the in-flight model configuration change was discarded. Preview and apply again.",
|
|
731
|
+
discarded: "The pending change was discarded; catalog data already written is kept. Preview and apply again afterwards.",
|
|
717
732
|
legacy: "Legacy shared recovery state was found. It will not be applied automatically; preview and confirm in this profile.",
|
|
718
733
|
techDetails: "Technical details",
|
|
719
734
|
stateCorrupt: "State file was corrupted and quarantined. Preview and confirm again.",
|
|
@@ -805,6 +820,11 @@ var DICTS = {
|
|
|
805
820
|
retireBtn: "\u7ED3\u675F\u65E7\u914D\u7F6E\u610F\u56FE",
|
|
806
821
|
retireTitle: "\u7ED3\u675F\u65E7\u914D\u7F6E\u610F\u56FE",
|
|
807
822
|
retireConfirmText: "\u53EA\u7ED3\u675F\u65E7\u610F\u56FE\uFF0C\u4E0D\u56DE\u6EDA\u6216\u64A4\u9500\u5DF2\u53D1\u751F\u7684\u66F4\u6539\u3002",
|
|
823
|
+
busyPendingRestart: "\u4E0A\u4E00\u6B21\u66F4\u6539\u5DF2\u4FDD\u5B58\u3001\u5F85\u91CD\u542F\u751F\u6548\uFF1B\u91CD\u542F\u524D\u65E0\u6CD5\u5E94\u7528\u65B0\u7684\u66F4\u6539\u3002\u53EF\u7B49\u5F85\u91CD\u542F\uFF0C\u6216\u653E\u5F03\u8BE5\u6B21\u66F4\u6539\u3002",
|
|
824
|
+
retireBtnPending: "\u653E\u5F03\u5F85\u91CD\u542F\u7684\u66F4\u6539",
|
|
825
|
+
retireConfirmPending: "\u653E\u5F03\u540E\uFF0C\u672C\u6B21\u5F85\u91CD\u542F\u7684\u66F4\u6539\u5C06\u88AB\u4E22\u5F03\uFF1B\u5DF2\u843D\u76D8\u7684\u76EE\u5F55\u6570\u636E\u4FDD\u7559\uFF0C\u4E4B\u540E\u53EF\u91CD\u65B0\u9884\u89C8\u5E76\u5E94\u7528\u3002",
|
|
826
|
+
retiredByAuth: "\u6388\u6743\u72B6\u6001\u5DF2\u53D8\u5316\uFF08\u767B\u5F55\u6216\u9000\u51FA\u767B\u5F55\uFF09\uFF0C\u8FDB\u884C\u4E2D\u7684\u6A21\u578B\u914D\u7F6E\u66F4\u6539\u5DF2\u4F5C\u5E9F\uFF1B\u8BF7\u91CD\u65B0\u9884\u89C8\u5E76\u5E94\u7528\u3002",
|
|
827
|
+
discarded: "\u5DF2\u653E\u5F03\u8BE5\u6B21\u5F85\u91CD\u542F\u7684\u66F4\u6539\uFF1B\u5DF2\u843D\u76D8\u7684\u76EE\u5F55\u6570\u636E\u4FDD\u7559\uFF0C\u53EF\u91CD\u65B0\u9884\u89C8\u5E76\u5E94\u7528\u3002",
|
|
808
828
|
legacy: "\u68C0\u6D4B\u5230\u65E7\u7684\u5171\u4EAB\u6062\u590D\u72B6\u6001\u3002\u4E0D\u4F1A\u81EA\u52A8\u5E94\u7528\uFF0C\u8BF7\u5728\u5F53\u524D profile \u91CD\u65B0\u9884\u89C8\u786E\u8BA4\u3002",
|
|
809
829
|
techDetails: "\u6280\u672F\u8BE6\u60C5",
|
|
810
830
|
stateCorrupt: "\u6062\u590D\u72B6\u6001\u65E0\u6CD5\u8BFB\u53D6\uFF0C\u539F\u4EF6\u5DF2\u4FDD\u7559\u3002\u8BF7\u91CD\u65B0\u9884\u89C8\u786E\u8BA4\u3002",
|
|
@@ -1149,21 +1169,24 @@ function RefreshModal({ t, flow, onSelect, onConfirm, onCancel, onOverlay }) {
|
|
|
1149
1169
|
] })
|
|
1150
1170
|
] }) });
|
|
1151
1171
|
}
|
|
1152
|
-
function RetireDialog({ t, onConfirm, onCancel }) {
|
|
1172
|
+
function RetireDialog({ t, onConfirm, onCancel, pending = false }) {
|
|
1153
1173
|
const cancelRef = (0, import_react.useRef)(null);
|
|
1154
1174
|
const surface = (0, import_react.useRef)(null);
|
|
1155
1175
|
if (!surface.current) surface.current = sampleThemeSurface();
|
|
1156
1176
|
(0, import_react.useEffect)(() => {
|
|
1157
1177
|
cancelRef.current?.focus();
|
|
1158
1178
|
}, []);
|
|
1179
|
+
const titleKey = pending ? "retireBtnPending" : "retireTitle";
|
|
1180
|
+
const bodyKey = pending ? "retireConfirmPending" : "retireConfirmText";
|
|
1181
|
+
const btnKey = pending ? "retireBtnPending" : "retireBtn";
|
|
1159
1182
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles.modalMask, role: "dialog", "aria-modal": "true", onKeyDown: (e) => {
|
|
1160
1183
|
if (e.key === "Escape") onCancel();
|
|
1161
1184
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { ...styles.modal, background: surface.current.bg, color: surface.current.fg, maxWidth: 420 }, children: [
|
|
1162
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { style: styles.modalTitle, children: t(
|
|
1163
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: styles.modalText, children: t(
|
|
1185
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { style: styles.modalTitle, children: t(titleKey) }),
|
|
1186
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: styles.modalText, children: t(bodyKey) }),
|
|
1164
1187
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: styles.modalActions, children: [
|
|
1165
1188
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { ref: cancelRef, type: "button", style: { ...styles.button, ...styles.secondary }, onClick: onCancel, children: t("cancel") }),
|
|
1166
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", style: { ...styles.button, ...styles.primary }, onClick: onConfirm, children: t(
|
|
1189
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", style: { ...styles.button, ...styles.primary }, onClick: onConfirm, children: t(btnKey) })
|
|
1167
1190
|
] })
|
|
1168
1191
|
] }) });
|
|
1169
1192
|
}
|
|
@@ -1337,16 +1360,20 @@ function CopilotSection({ t = (key) => DICTS.en[key] ?? key }) {
|
|
|
1337
1360
|
"\u24D8 ",
|
|
1338
1361
|
t("legacy")
|
|
1339
1362
|
] }),
|
|
1340
|
-
flow.name === "pendingRestart" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1341
|
-
|
|
1342
|
-
|
|
1363
|
+
flow.name === "pendingRestart" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1364
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { style: styles.banner, children: [
|
|
1365
|
+
"\u26A0 ",
|
|
1366
|
+
t("pendingRestart"),
|
|
1367
|
+
flow.retireError ? `\uFF08${flow.retireError}\uFF09` : ""
|
|
1368
|
+
] }),
|
|
1369
|
+
(flow.active?.operationId || flow.result?.status === "pending-restart" && flow.result?.operationId) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", style: { ...styles.button, ...styles.secondary }, onClick: () => drive({ type: "retire-request" }), children: t("retireBtnPending") }) })
|
|
1343
1370
|
] }),
|
|
1344
1371
|
flow.name === "busy" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { style: styles.banner, children: [
|
|
1345
1372
|
"\u24D8 ",
|
|
1346
|
-
t("busy"),
|
|
1373
|
+
flow.active?.phaseResult?.status === "pending-restart" ? t("busyPendingRestart") : t("busy"),
|
|
1347
1374
|
flow.retireError ? `\uFF08${flow.retireError}\uFF09` : ""
|
|
1348
1375
|
] }),
|
|
1349
|
-
flow.name === "busy" && flow.active?.phaseResult?.status
|
|
1376
|
+
flow.name === "busy" && ["recovery-needed", "pending-restart"].includes(flow.active?.phaseResult?.status ?? "") && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", style: { ...styles.button, ...styles.secondary }, onClick: () => drive({ type: "retire-request" }), children: flow.active?.phaseResult?.status === "pending-restart" ? t("retireBtnPending") : t("retireBtn") }) }),
|
|
1350
1377
|
flow.name === "resultUnknown" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1351
1378
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { style: styles.error, children: [
|
|
1352
1379
|
"\u26A0 ",
|
|
@@ -1357,7 +1384,9 @@ function CopilotSection({ t = (key) => DICTS.en[key] ?? key }) {
|
|
|
1357
1384
|
flow.name === "result" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
1358
1385
|
(() => {
|
|
1359
1386
|
const st = flow.result?.status;
|
|
1360
|
-
const
|
|
1387
|
+
const retiredByAuth = st === "intent-retired" && typeof flow.result?.error === "string" && flow.result.error.startsWith("superseded-by-auth-action:");
|
|
1388
|
+
const selfDiscarded = st === "intent-retired" && !retiredByAuth && flow.result?.error == null;
|
|
1389
|
+
const key = retiredByAuth ? "retiredByAuth" : selfDiscarded ? "discarded" : {
|
|
1361
1390
|
applied: "applied",
|
|
1362
1391
|
conflict: "conflict",
|
|
1363
1392
|
partial: "partial",
|
|
@@ -1366,8 +1395,8 @@ function CopilotSection({ t = (key) => DICTS.en[key] ?? key }) {
|
|
|
1366
1395
|
"recovery-needed": "recoveryNeeded",
|
|
1367
1396
|
"intent-retired": "recoveryNeeded"
|
|
1368
1397
|
}[st];
|
|
1369
|
-
return key ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { style: st === "applied" ? styles.banner : styles.error, children: [
|
|
1370
|
-
st === "applied" ? "\u2713" : "\u26A0",
|
|
1398
|
+
return key ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { style: st === "applied" || key === "discarded" ? styles.banner : styles.error, children: [
|
|
1399
|
+
st === "applied" ? "\u2713" : key === "discarded" ? "\u24D8" : "\u26A0",
|
|
1371
1400
|
" ",
|
|
1372
1401
|
t(key)
|
|
1373
1402
|
] }) : null;
|
|
@@ -1395,6 +1424,7 @@ function CopilotSection({ t = (key) => DICTS.en[key] ?? key }) {
|
|
|
1395
1424
|
RetireDialog,
|
|
1396
1425
|
{
|
|
1397
1426
|
t,
|
|
1427
|
+
pending: flow.active?.phaseResult?.status === "pending-restart",
|
|
1398
1428
|
onConfirm: () => drive({ type: "retire-confirm" }),
|
|
1399
1429
|
onCancel: () => drive({ type: "cancel" })
|
|
1400
1430
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inventec/dsh-copilot-auth",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.25",
|
|
4
4
|
"description": "为内置 Copilot 提供方补设备码登录设置页,预置开箱路由;凭据入内置凭据库,模型目录兜底不覆盖定制。v1.2.19:管理模型列表 v3 目标状态编辑(分组全表/挽留/对齐/清空语义告知)+单次确认+移除请求撤回+退出残影修复。v1.2.18:授权失败附网络失败码+人性化提示。适配 DSH 0.1.7+(≤0.1.5 请用 1.1.x)。v1.2.21:移除前实时证据自动续期(ephemeral 不落库+负缓存 5min)+缓存证据原因分型文案+busy 卡死 retire 出口与水合判序修正(032)。",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|
package/src/auth-host.mjs
CHANGED
|
@@ -39,7 +39,7 @@ function authError(code, message, extra = {}) {
|
|
|
39
39
|
return err;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function createAuthorizationController(ctx, { scope, intentIO, clock = { now: () => Date.now() }, onAuthorized } = {}) {
|
|
42
|
+
export function createAuthorizationController(ctx, { scope, intentIO, clock = { now: () => Date.now() }, onAuthorized, onIntentBump } = {}) {
|
|
43
43
|
let attempt = null;
|
|
44
44
|
let riskLatch = null; // { reason, at } — 进程级风险锁存,本进程生命周期内不解除
|
|
45
45
|
|
|
@@ -69,6 +69,10 @@ export function createAuthorizationController(ctx, { scope, intentIO, clock = {
|
|
|
69
69
|
}
|
|
70
70
|
// 先持久意图版本,失败不发 begin(安全门拒绝动作不产生副作用)
|
|
71
71
|
const originIntentVersion = intentIO.bump();
|
|
72
|
+
// ADR-0006:栅栏抬升的同一时刻即时作废进行中的模型配置操作(fire-and-forget,不阻断授权主路径)
|
|
73
|
+
if (typeof onIntentBump === "function") {
|
|
74
|
+
try { onIntentBump("auth-start"); } catch { /* 回调异常不阻断授权 */ }
|
|
75
|
+
}
|
|
72
76
|
const a = {
|
|
73
77
|
attemptId: randomUUID(),
|
|
74
78
|
status: "starting",
|
|
@@ -143,6 +147,10 @@ export function createAuthorizationController(ctx, { scope, intentIO, clock = {
|
|
|
143
147
|
if (riskLatch) throw authError("LOGOUT_UNSAFE", "logout-unsafe");
|
|
144
148
|
// 本 profile 显式操作:旧预览/模型配置意图先行失效(失败则不动凭据)
|
|
145
149
|
intentIO.bump();
|
|
150
|
+
// ADR-0006:作废即时化——不等到 boot 漂移检查才暴露(fire-and-forget,不阻断退出主路径)
|
|
151
|
+
if (typeof onIntentBump === "function") {
|
|
152
|
+
try { onIntentBump("logout"); } catch { /* 回调异常不阻断退出 */ }
|
|
153
|
+
}
|
|
146
154
|
try {
|
|
147
155
|
const deleted = await ctx.credentials.deleteRecord(CREDENTIAL_KEY);
|
|
148
156
|
if (deleted === false) throw authError("LOGOUT_FAILED", "logout-failed");
|
package/src/host.mjs
CHANGED
|
@@ -389,11 +389,24 @@ export function apply(ctx, opts = {}) {
|
|
|
389
389
|
ctx.logger?.warn?.("copilot-auth: model sync failed: %s", lastSyncError);
|
|
390
390
|
});
|
|
391
391
|
|
|
392
|
+
// ADR-0006:授权动作即时作废进行中的模型配置操作。service 晚于 controller 创建(L479),
|
|
393
|
+
// 用晚绑定 ref;fire-and-forget,失败只记日志,绝不影响授权动作本身。
|
|
394
|
+
let refreshServiceRef = null;
|
|
395
|
+
const onIntentBump = (source) => {
|
|
396
|
+
const svc = refreshServiceRef;
|
|
397
|
+
const invalidate = svc?.invalidateForAuthAction;
|
|
398
|
+
if (typeof invalidate !== "function") return;
|
|
399
|
+
Promise.resolve(invalidate.call(svc, source)).catch((err) => {
|
|
400
|
+
ctx.logger?.warn?.("copilot-auth: invalidate for %s failed: %s", source, String(err?.message ?? err));
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
|
|
392
404
|
// 授权控制器(T3):软撤回+风险锁存;退出/重新授权在当前宿主下统一禁用。
|
|
393
405
|
const controller = createAuthorizationController(ctx, {
|
|
394
406
|
scope,
|
|
395
407
|
intentIO,
|
|
396
408
|
onAuthorized: (handoff) => { void runSync(handoff); },
|
|
409
|
+
onIntentBump,
|
|
397
410
|
});
|
|
398
411
|
|
|
399
412
|
// ---- 初始化期能力探测(Q23:GET status 不执行写探针,通道分类来自此处缓存) ----
|
|
@@ -488,6 +501,7 @@ export function apply(ctx, opts = {}) {
|
|
|
488
501
|
transaction,
|
|
489
502
|
fetchImpl,
|
|
490
503
|
});
|
|
504
|
+
refreshServiceRef = refreshService; // ADR-0006:晚绑定回填(见 onIntentBump)
|
|
491
505
|
|
|
492
506
|
// 启动序列(boot 恢复+保守激活/自愈,T9 bootRecover);绝不阻断挂载。
|
|
493
507
|
void refreshService.bootReady()
|
|
@@ -588,7 +602,12 @@ export function apply(ctx, opts = {}) {
|
|
|
588
602
|
activated: st?.activated === true,
|
|
589
603
|
activeOperation: st?.activeOperation ?? null,
|
|
590
604
|
lastResult: st?.lastResult ?? null,
|
|
591
|
-
|
|
605
|
+
// 评审 Q4(ADR-0006):作废(intent-retired)后内核 restartState 残留不得再宣称
|
|
606
|
+
// 「待重启生效」——activeOperation 已清、无任何待提交配置,重启不再完成任何更改;
|
|
607
|
+
// 正常 pending-restart(lastResult 非 intent-retired)行为不变,水合判序零改动
|
|
608
|
+
pendingRestart: (st?.activeOperation == null && st?.lastResult?.status === "intent-retired")
|
|
609
|
+
? false
|
|
610
|
+
: (!!st?.restartState || st?.activeOperation?.phaseResult?.status === "pending-restart"),
|
|
592
611
|
legacyStateDetected: loaded.flags.legacyStateDetected === true,
|
|
593
612
|
stateUnknownVersion: loaded.flags.unknownVersion === true,
|
|
594
613
|
piAiVersion: installInfo?.version ?? null,
|
package/src/refresh-flow.mjs
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// 状态:idle → previewing → confirming(勾选→materialize 循环;缓存证据+删除提案时
|
|
4
4
|
// 自动 live 升级:闩锁、硬失败回退 materialize、软降级置 staleNotice)→ applying →
|
|
5
5
|
// result / pendingRestart / checking / busy / resultUnknown;recovery-needed 经
|
|
6
|
-
// retireConfirm → retiring → 重新预览闭环;busy 态在 active.phaseResult.status
|
|
7
|
-
// "recovery-needed"
|
|
6
|
+
// retireConfirm → retiring → 重新预览闭环;busy 态在 active.phaseResult.status 为
|
|
7
|
+
// "recovery-needed"(032)或 "pending-restart"(ADR-0006/v1.2.25:放弃等待重启)时
|
|
8
|
+
// 同样提供 retire 出口,水合时 recovery-needed 判据优先于旧 lastResult
|
|
8
9
|
// (防旧 "applied" 遮蔽卡死操作),retire 失败回 busy 可重试。
|
|
9
10
|
// 关键规则:
|
|
10
11
|
// - 勾选集合即终态;选择变化经 basePreviewId 从原快照 materialize(不重新取数)
|
|
@@ -110,10 +111,18 @@ export function reduce(state, event) {
|
|
|
110
111
|
if (event.type === "retire-request" && state.name === "result") {
|
|
111
112
|
return [{ name: "retireConfirm", result: state.result }, null];
|
|
112
113
|
}
|
|
113
|
-
// 032:busy 态的 retire
|
|
114
|
-
|
|
114
|
+
// 032 + ADR-0006:busy 态的 retire 出口——卡死操作(recovery-needed)与挂起重启的
|
|
115
|
+
// 操作(pending-restart)都可放弃(静止核实后清,绝不写配置);文案由渲染层按态区分
|
|
116
|
+
if (event.type === "retire-request" && state.name === "busy" && ["recovery-needed", "pending-restart"].includes(state.active?.phaseResult?.status ?? "")) {
|
|
115
117
|
return [{ name: "retireConfirm", active: state.active }, null];
|
|
116
118
|
}
|
|
119
|
+
// ADR-0006/v1.2.25(Q5 + Q6):pendingRestart 态主视图的放弃出口——优先取 active
|
|
120
|
+
// (真实占用操作,跨会话水合落点),result 兜底仅认 pending-restart 终态(排除旧
|
|
121
|
+
// lastResult 残影与终态残留的误导出口)
|
|
122
|
+
if (event.type === "retire-request" && state.name === "pendingRestart"
|
|
123
|
+
&& (state.active?.operationId || (state.result?.status === "pending-restart" && state.result?.operationId))) {
|
|
124
|
+
return [{ name: "retireConfirm", result: state.result, active: state.active ?? null }, null];
|
|
125
|
+
}
|
|
117
126
|
if (event.type === "dismiss" && state.name === "failed") {
|
|
118
127
|
return [{ ...initial, flags: state.flags }, null];
|
|
119
128
|
}
|
|
@@ -127,7 +136,9 @@ export function reduce(state, event) {
|
|
|
127
136
|
return [{ ...base, name: "busy", active: refresh.activeOperation }, null];
|
|
128
137
|
}
|
|
129
138
|
if (restartStates.has(refresh?.lastResult?.status ?? "") || refresh?.pendingRestart === true) {
|
|
130
|
-
|
|
139
|
+
// 评审 Q6:水合落点必须携带 active(真实占用操作的 operationId)——lastResult 可能是
|
|
140
|
+
// 旧操作残影(如旧 applied),放弃出口若取旧 id 会 operation-mismatch 永远失败
|
|
141
|
+
return [{ ...base, name: "pendingRestart", result: refresh.lastResult, active: refresh.activeOperation ?? null }, null];
|
|
131
142
|
}
|
|
132
143
|
const st = refresh?.lastResult?.status;
|
|
133
144
|
if (st && ["recovery-needed", "rollback-conflict", "conflict", "partial", "rolled-back", "intent-retired", "applied"].includes(st)) {
|
|
@@ -281,19 +292,26 @@ export function reduce(state, event) {
|
|
|
281
292
|
}
|
|
282
293
|
case "retireConfirm": {
|
|
283
294
|
if (event.type === "retire-confirm") {
|
|
284
|
-
// 双入口:
|
|
285
|
-
|
|
295
|
+
// 双入口:busy/pendingRestart 入口携 active(真实占用操作——Q6 起 active 优先,
|
|
296
|
+
// 防 lastResult 残影 id 造成 operation-mismatch);result 入口携 result
|
|
297
|
+
const retireId = state.active?.operationId ?? state.result?.operationId;
|
|
298
|
+
return [{ name: "retiring", operationId: retireId, result: state.result, active: state.active }, { type: "retire", operationId: retireId }];
|
|
299
|
+
}
|
|
300
|
+
if (event.type === "cancel") {
|
|
301
|
+
// Q5:pendingRestart 入口取消回 pendingRestart(携待重启横幅),不落进无提示的 result 空态
|
|
302
|
+
if (state.active) return [{ name: "busy", active: state.active }, null];
|
|
303
|
+
if (state.result?.status === "pending-restart") return [{ name: "pendingRestart", result: state.result }, null];
|
|
304
|
+
return [{ name: "result", result: state.result }, null];
|
|
286
305
|
}
|
|
287
|
-
if (event.type === "cancel") return state.active ? [{ name: "busy", active: state.active }, null] : [{ name: "result", result: state.result }, null];
|
|
288
306
|
return [state, null];
|
|
289
307
|
}
|
|
290
308
|
case "retiring": {
|
|
291
309
|
if (event.type === "retire-ok") return [{ ...state, name: "checking" }, { type: "status" }];
|
|
292
310
|
if (event.type === "retire-fail") {
|
|
293
|
-
// 032:busy 入口失败回 busy 可重试;result 入口维持既有落点
|
|
294
|
-
return state.active
|
|
295
|
-
|
|
296
|
-
|
|
311
|
+
// 032:busy 入口失败回 busy 可重试;Q5:pendingRestart 入口失败回 pendingRestart 可重试;result 入口维持既有落点
|
|
312
|
+
if (state.active) return [{ name: "busy", active: state.active, retireError: event.error }, null];
|
|
313
|
+
if (state.result?.status === "pending-restart") return [{ name: "pendingRestart", result: state.result, retireError: event.error }, null];
|
|
314
|
+
return [{ name: "result", result: state.result, retireError: event.error }, null];
|
|
297
315
|
}
|
|
298
316
|
return [state, null];
|
|
299
317
|
}
|
package/src/refresh-service.mjs
CHANGED
|
@@ -314,6 +314,24 @@ export function createRefreshService(ctx, {
|
|
|
314
314
|
return queue(() => transaction.retire({ operationId: body?.operationId }));
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
+
// ADR-0006:授权动作(start/logout)bump 意图栅栏的同一时刻,即时终结进行中的 refresh 操作。
|
|
318
|
+
// 幂等:无 activeOperation 时 {ok:true, invalidated:false};operationId 恒 undefined
|
|
319
|
+
// (transaction.retire 语义=终结当前 active,无需 service 层读状态或校验归属)。
|
|
320
|
+
async function invalidateForAuthAction(source) {
|
|
321
|
+
requireScope();
|
|
322
|
+
if (source !== "auth-start" && source !== "logout") {
|
|
323
|
+
throw flowError("INVALID_SOURCE", "invalid invalidate source");
|
|
324
|
+
}
|
|
325
|
+
if (!transaction) throw flowError("DEPS_MISSING", "transaction kernel not wired");
|
|
326
|
+
const res = await queue(() => transaction.retire({ operationId: undefined, reason: `superseded-by-auth-action:${source}` }));
|
|
327
|
+
// 评审 Q3:真内核在无 active 且 lastResult 为空时会误入 idempotent 分支
|
|
328
|
+
// (lastResult.operationId 与 undefined 严格相等误命中),该情形下没有任何操作被
|
|
329
|
+
// 终结 → 映射 invalidated:false,不虚报契约语义;内核 retire 语义零改动(全局约束 1)。
|
|
330
|
+
return res?.ok && res?.idempotent !== true
|
|
331
|
+
? { ok: true, invalidated: true, result: res.result }
|
|
332
|
+
: { ok: true, invalidated: false };
|
|
333
|
+
}
|
|
334
|
+
|
|
317
335
|
async function bootReady() {
|
|
318
336
|
requireScope();
|
|
319
337
|
if (!transaction) return { ok: true, skipped: true };
|
|
@@ -332,5 +350,5 @@ export function createRefreshService(ctx, {
|
|
|
332
350
|
return snapshots.size;
|
|
333
351
|
}
|
|
334
352
|
|
|
335
|
-
return { preview, apply, status, retire, bootReady, dispose, snapshotCount };
|
|
353
|
+
return { preview, apply, status, retire, invalidateForAuthAction, bootReady, dispose, snapshotCount };
|
|
336
354
|
}
|
|
@@ -390,7 +390,9 @@ export function createTransaction(ctx, {
|
|
|
390
390
|
const active = st?.activeOperation;
|
|
391
391
|
if (!active) return { ok: true, active: false };
|
|
392
392
|
|
|
393
|
-
// intentVersion 漂移:不消费旧 target,标记 recovery-needed(用户经 retire
|
|
393
|
+
// intentVersion 漂移:不消费旧 target,标记 recovery-needed(用户经 retire 显式结束后重新预览)。
|
|
394
|
+
// 兜底定位(ADR-0006,v1.2.25 起):正常路径的授权失效已由 auth 动作即时作废
|
|
395
|
+
// (invalidateForAuthAction),此处只应被崩溃窗口/外部改写触达。
|
|
394
396
|
if (active.intentVersion !== readIntentVersion()) {
|
|
395
397
|
const next = stateIO.load();
|
|
396
398
|
next.activeOperation = { ...active, phaseResult: { status: "recovery-needed", error: "intent-version-drift" } };
|
|
@@ -544,7 +546,9 @@ export function createTransaction(ctx, {
|
|
|
544
546
|
}
|
|
545
547
|
|
|
546
548
|
// ---- retire:静止核实后清 activeOperation(服务队列内串行即静止;绝不写配置) ----
|
|
547
|
-
|
|
549
|
+
// reason(ADR-0006):授权动作即时作废时携带受控原因串(superseded-by-auth-action:<source>),
|
|
550
|
+
// 透传为 lastResult.error;未携带时维持既有 drift 语义。
|
|
551
|
+
async function retire({ operationId, reason } = {}) {
|
|
548
552
|
const state = stateIO.load();
|
|
549
553
|
const active = state?.activeOperation;
|
|
550
554
|
if (!active) {
|
|
@@ -555,13 +559,14 @@ export function createTransaction(ctx, {
|
|
|
555
559
|
return { ok: false, error: "operation-mismatch" };
|
|
556
560
|
}
|
|
557
561
|
const drift = active.intentVersion !== readIntentVersion();
|
|
562
|
+
const reasonText = typeof reason === "string" && reason.length > 0 && reason.length <= 120 ? reason : null;
|
|
558
563
|
const result = {
|
|
559
564
|
operationId: active.operationId,
|
|
560
565
|
status: "intent-retired",
|
|
561
566
|
phase: active.phase,
|
|
562
567
|
drift,
|
|
563
568
|
changes: null,
|
|
564
|
-
error: drift ? "intent-version-drift: old target not consumed" : null,
|
|
569
|
+
error: reasonText ?? (drift ? "intent-version-drift: old target not consumed" : null),
|
|
565
570
|
};
|
|
566
571
|
const next = { ...state, activeOperation: null, lastResult: result };
|
|
567
572
|
next.intentVersion = readIntentVersion();
|