weir-harness 1.1.4 → 1.1.6

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.
Files changed (57) hide show
  1. package/cordis.patch.yml +48 -87
  2. package/icon.svg +1 -0
  3. package/lib/client.capability-badge.js +16 -16
  4. package/lib/client.capability-manager.js +87 -36
  5. package/lib/client.capability-model.js +151 -31
  6. package/lib/client.capability-presets.js +187 -39
  7. package/lib/client.edit-lock-maintenance.js +27 -12
  8. package/lib/client.edit-lock-panel.js +52 -19
  9. package/lib/client.js +270 -12
  10. package/lib/client.settings-page.js +13 -8
  11. package/lib/client.worktree-model.js +20 -1
  12. package/lib/client.worktree-view.js +32 -9
  13. package/package.json +4 -2
  14. package/skills/deep-work/SKILL.md +7 -3
  15. package/src/blackboard/durable.js +199 -0
  16. package/src/blackboard/index.js +62 -42
  17. package/src/blackboard/kernel.js +20 -1
  18. package/src/blackboard/remote.js +36 -28
  19. package/src/blackboard/storage.js +238 -0
  20. package/src/capabilities/capability-remote.js +122 -69
  21. package/src/capabilities/preset-library.js +113 -87
  22. package/src/capabilities/read-payloads.js +21 -4
  23. package/src/capabilities/skill-selection-plugin.js +188 -168
  24. package/src/capabilities/skill-selection-provider.js +13 -0
  25. package/src/capabilities/store/enumerate.js +46 -0
  26. package/src/capabilities/store/store.js +86 -1
  27. package/src/context-guard/index.js +222 -117
  28. package/src/context-guard/pressure.js +12 -3
  29. package/src/context-guard/recovery.js +25 -0
  30. package/src/core/doctrine.js +3 -3
  31. package/src/delegate/group-coordinator.js +2 -1
  32. package/src/delegate/supervision-mount.js +41 -2
  33. package/src/delegate/tool.js +11 -3
  34. package/src/edit-lock/admin-ledger.js +42 -6
  35. package/src/edit-lock/admin-recovery.js +4 -2
  36. package/src/edit-lock/binding-attestation.js +29 -0
  37. package/src/edit-lock/binding-guidance.js +43 -0
  38. package/src/edit-lock/domain.js +20 -5
  39. package/src/edit-lock/host.js +3 -3
  40. package/src/edit-lock/index.js +268 -57
  41. package/src/edit-lock/lifecycle.js +106 -47
  42. package/src/edit-lock/maintenance.js +12 -3
  43. package/src/edit-lock/manager.js +8 -3
  44. package/src/edit-lock/peer.js +2 -0
  45. package/src/edit-lock/publisher.js +57 -1
  46. package/src/edit-lock/remote.js +120 -52
  47. package/src/edit-lock/runtime.js +8 -0
  48. package/src/edit-lock/view.js +27 -12
  49. package/src/settings/sections.js +30 -6
  50. package/src/shared/audit.js +6 -0
  51. package/src/shared/delegate-edit-lifecycle.js +36 -0
  52. package/src/todo-driver/index.js +16 -1
  53. package/src/worktree/cards.js +47 -3
  54. package/src/worktree/command.js +29 -5
  55. package/src/worktree/git.js +39 -5
  56. package/src/worktree/lanes.js +83 -25
  57. package/src/worktree/prompts.js +2 -1
@@ -253,6 +253,7 @@ window.__ModuleLoader__.load({
253
253
  const [rowAction, setRowAction] = react.useState(null);
254
254
  const [defaultBox, setDefaultBox] = react.useState({ confirm: null, from: "draft", busy: false, error: null });
255
255
  const [notice, setNotice] = react.useState(null);
256
+ const [editAlert, setEditAlert] = react.useState(null);
256
257
  const presetListOf = (payload) => (payload && !payload.error && Array.isArray(payload.presets) ? model.groupPresets(payload) : { error: true });
257
258
  const refreshPresets = () => {
258
259
  if (typeof props.fetchPresets !== "function") { setList({ error: true }); return; }
@@ -292,12 +293,23 @@ window.__ModuleLoader__.load({
292
293
  return;
293
294
  }
294
295
  const spec = { scope: saveForm.scope, name, from: saveForm.from };
296
+ if (saveForm.from === "applied") {
297
+ const issue = appliedSourceIssue();
298
+ if (issue) { setSaveForm({ ...saveForm, error: issue }); return; }
299
+ spec.expectedSelectionRevision = props.draft.revision;
300
+ spec.expectedSelectionDigest = props.draft.appliedDigest;
301
+ }
295
302
  if (saveForm.from === "draft") {
296
303
  spec.skills = Array.isArray(props.draft?.skills) ? props.draft.skills : [];
297
304
  spec.mcpServers = Array.isArray(props.draft?.mcpServers) ? props.draft.mcpServers : [];
298
305
  spec.unresolvedRefs = Array.isArray(props.draft?.unresolvedRefs) ? props.draft.unresolvedRefs : [];
299
306
  }
300
- if (onNameConflict) spec.onNameConflict = onNameConflict;
307
+ if (onNameConflict === "replace") {
308
+ const target = saveForm.conflict;
309
+ if (!target || typeof target.with !== "string" || !Number.isSafeInteger(target.withRevision) || target.name !== name || target.scope !== saveForm.scope) return;
310
+ spec.onNameConflict = "replace";
311
+ spec.replaceTarget = { presetId: target.with, expectedRevision: target.withRevision, name };
312
+ }
301
313
  setSaveForm({ ...saveForm, busy: true, error: null });
302
314
  props.presetSave(props.sessionId, spec).then((response) => {
303
315
  const outcome = model.presetWriteOutcomeOf(response);
@@ -306,23 +318,99 @@ window.__ModuleLoader__.load({
306
318
  setNotice(t("capability.presets.saved", "Preset saved."));
307
319
  refreshPresets();
308
320
  } else if (outcome.kind === "name-conflict") {
309
- setSaveForm({ ...saveForm, busy: false, error: null, conflict: { with: outcome.with } });
321
+ setSaveForm({ ...saveForm, busy: false, error: null, conflict: { with: outcome.with, withRevision: outcome.withRevision, name, scope: saveForm.scope } });
310
322
  } else if (outcome.kind === "revision-conflict") {
311
323
  setSaveForm({ ...saveForm, busy: false, error: t("capability.presets.revisionConflict", "Changed elsewhere — the list was refreshed."), conflict: null });
312
324
  refreshPresets();
313
325
  } else if (outcome.kind === "no-workspace") {
314
326
  setSaveForm({ ...saveForm, busy: false, error: t("capability.presets.noWorkspace", "This session has no workspace."), conflict: null });
315
327
  } else {
316
- setSaveForm({ ...saveForm, busy: false, error: t("capability.presets.saveFailed", "The preset could not be saved."), conflict: null });
328
+ setSaveForm({ ...saveForm, busy: false, error: editMessage(outcome), conflict: null });
329
+ refreshPresets();
317
330
  }
318
- }).catch(() => setSaveForm({ ...saveForm, busy: false, error: t("capability.presets.saveFailed", "The preset could not be saved.") }));
331
+ }).catch(() => { setSaveForm({ ...saveForm, busy: false, error: editMessage({ kind: "error" }), conflict: null }); refreshPresets(); });
332
+ };
333
+ // Row edits use the listed revision as a one-shot CAS. A failed or
334
+ // indeterminate edit requires a fresh user decision, never auto-retry.
335
+ const editMessage = (outcome) => {
336
+ switch (outcome.kind) {
337
+ case "name-conflict": return t("capability.presets.renameCollision", "That name belongs to another preset. Choose another name.");
338
+ case "revision-conflict": return t("capability.presets.editConflict", "The preset changed. Review the refreshed row and confirm again.");
339
+ case "source-changed": return t("capability.presets.sourceChanged", "The applied selection changed. Review it and confirm again.");
340
+ case "source-unavailable": return t("capability.presets.sourceUnavailable", "Applied source unavailable{missing}. Restore the missing Skills, refresh the receipt, and confirm again.")
341
+ .replace("{missing}", outcome.missing?.length ? ": " + outcome.missing.join(", ") : "");
342
+ case "locked": return t("capability.presets.locked", "Preset storage is busy. Wait, then refresh and decide again.");
343
+ case "unreadable": return t("capability.presets.unreadable", "Preset storage cannot be read safely. Check the storage before retrying.");
344
+ case "unsupported": return t("capability.presets.unsupported", "This preset version is unsupported. Update the client or host before editing.");
345
+ case "absent": case "deleted": return t("capability.presets.gone", "This preset was deleted or is missing. Refresh the list; it was not recreated.");
346
+ case "confirmation-required": return t("capability.presets.confirmAgain", "The replacement target changed. Refresh and confirm its identity again.");
347
+ default: return t("capability.presets.uncertain", "Result unknown. Refresh and inspect the preset before deciding whether to retry.");
348
+ }
349
+ };
350
+ const rowIdentity = (row) => ({ scope: row.scope, presetId: row.presetId, expectedRevision: row.revision });
351
+ const appliedSourceIssue = () => props.draft?.appliedSourceIssue === "unavailable" ? t("capability.presets.appliedUnavailable", "The applied source has unavailable entries. Restore them and refresh the session receipt before re-saving.")
352
+ : props.draft?.appliedSourceIssue !== null || !Number.isSafeInteger(props.draft?.revision) || props.draft.revision < 0 || !/^[a-f0-9]{64}$/.test(props.draft?.appliedDigest ?? "")
353
+ ? t("capability.presets.appliedReceiptMissing", "The applied source cannot be verified from this receipt. Refresh the session receipt before re-saving; the current draft is still available.") : null;
354
+ const openRowEdit = (row, kind) => { setEditAlert(null); setRowAction({ ...rowIdentity(row), kind, name: row.name, from: "draft", busy: false, error: null, stale: false }); };
355
+ const submitRowEdit = (row) => {
356
+ if (!rowAction || rowAction.busy || rowAction.stale || !props.draft || !Number.isSafeInteger(row.revision) || row.revision < 1) return;
357
+ const rename = rowAction.kind === "rename";
358
+ const name = rowAction.name.trim();
359
+ if (rename && !name) { setRowAction({ ...rowAction, error: t("capability.presets.errorName", "Enter a name.") }); return; }
360
+ const inspectCurrent = (outcome) => {
361
+ const base = { ...rowAction, busy: false, stale: outcome.kind !== "name-conflict", error: editMessage(outcome) };
362
+ setRowAction(base);
363
+ setNotice(null);
364
+ if (outcome.kind !== "name-conflict") setEditAlert(editMessage(outcome));
365
+ refreshPresets();
366
+ if (outcome.kind === "name-conflict" || typeof props.presetLoad !== "function") return;
367
+ // Read the exact ID without staging it. A read failure remains uncertain.
368
+ Promise.resolve().then(() => props.presetLoad(props.sessionId, { scope: row.scope, presetId: row.presetId })).then((current) => {
369
+ const detail = current?.status === "ok" && Number.isSafeInteger(current.revision)
370
+ ? t("capability.presets.currentRevision", " Current stored revision: {revision}.").replace("{revision}", String(current.revision))
371
+ : current?.status === "absent" || current?.status === "deleted"
372
+ ? " " + t("capability.presets.gone", "This preset was deleted or is missing. Refresh the list; it was not recreated.") : "";
373
+ setRowAction({ ...base, error: base.error + detail });
374
+ }).catch(() => {});
375
+ };
376
+ const verb = rename ? props.presetRename : props.presetResave;
377
+ if (typeof verb !== "function") return;
378
+ const spec = { ...rowIdentity(row) };
379
+ if (rename) spec.name = name;
380
+ else {
381
+ spec.from = rowAction.from;
382
+ if (spec.from === "draft") {
383
+ // Snapshot all three arrays together at confirmation time.
384
+ if (![props.draft.skills, props.draft.mcpServers, props.draft.unresolvedRefs].every(Array.isArray)) {
385
+ setRowAction({ ...rowAction, error: t("capability.presets.missingSelection", "The draft selection is incomplete. Refresh before saving.") }); return;
386
+ }
387
+ spec.skills = structuredClone(props.draft.skills);
388
+ spec.mcpServers = structuredClone(props.draft.mcpServers);
389
+ spec.unresolvedRefs = structuredClone(props.draft.unresolvedRefs);
390
+ } else {
391
+ const issue = appliedSourceIssue();
392
+ if (issue) { setRowAction({ ...rowAction, error: issue }); return; }
393
+ spec.expectedSelectionRevision = props.draft.revision;
394
+ spec.expectedSelectionDigest = props.draft.appliedDigest;
395
+ }
396
+ }
397
+ setRowAction({ ...rowAction, busy: true, error: null });
398
+ Promise.resolve().then(() => verb(props.sessionId, spec)).then((response) => {
399
+ const outcome = model.presetWriteOutcomeOf(response);
400
+ if (outcome.kind === "edited" && outcome.presetId === row.presetId) {
401
+ setRowAction(null);
402
+ setEditAlert(null);
403
+ setNotice(rename ? t("capability.presets.renamed", "Preset renamed; current draft and applied selection unchanged.") : t("capability.presets.resaved", "Preset re-saved; current draft and applied selection unchanged."));
404
+ } else inspectCurrent(outcome);
405
+ if (outcome.kind === "edited" && outcome.presetId === row.presetId) refreshPresets();
406
+ }).catch(() => inspectCurrent({ kind: "error" }));
319
407
  };
320
408
  // ---- Load into the local draft (never the applied set) ----
321
409
  const loadPreset = (row) => {
322
410
  if (typeof props.presetLoad !== "function" || rowAction?.busy) return;
323
411
  setRowAction({ presetId: row.presetId, scope: row.scope, kind: "load", busy: true, error: null });
324
412
  props.presetLoad(props.sessionId, { scope: row.scope, presetId: row.presetId }).then((response) => {
325
- if (response && !response.error && response.status === "ok" && response.document && typeof response.document === "object") {
413
+ if (model.loadablePresetOf(response)) {
326
414
  if (typeof props.stagePreset === "function") props.stagePreset(response.document);
327
415
  const unresolved = Array.isArray(response.document.selection?.unresolvedRefs) ? response.document.selection.unresolvedRefs : [];
328
416
  setNotice(unresolved.length > 0
@@ -421,7 +509,12 @@ window.__ModuleLoader__.load({
421
509
  }
422
510
  }
423
511
  const spec = { document, scope: importBox.scope };
424
- if (onNameConflict) spec.onNameConflict = onNameConflict;
512
+ if (onNameConflict === "replace") {
513
+ const target = importBox.feedback;
514
+ if (!target || typeof target.with !== "string" || !Number.isSafeInteger(target.withRevision) || target.name !== document?.name || target.scope !== importBox.scope) return;
515
+ spec.onNameConflict = "replace";
516
+ spec.replaceTarget = { presetId: target.with, expectedRevision: target.withRevision, name: document.name };
517
+ }
425
518
  // D6 phase one: a version-2 package NEVER installs on the first call —
426
519
  // the dry-run summarizes targets/counts/collisions with zero writes.
427
520
  if (model.packageVersionOf(document) === 2) spec.dryRun = true;
@@ -438,17 +531,18 @@ window.__ModuleLoader__.load({
438
531
  return;
439
532
  }
440
533
  const feedback = model.importFeedbackOf(response);
441
- if (feedback.kind === "created") {
534
+ if (feedback.kind === "created" || feedback.kind === "edited") {
442
535
  setImportBox({ open: false, text: "", scope: importBox.scope, busy: false, feedback: null, document: null, summary: null, decision: "cancel", result: null });
443
- setNotice(t("capability.presets.imported", "Imported: {bound} MCP binding(s), {unresolved} unresolved ref(s).")
444
- .replace("{bound}", String(feedback.bound))
445
- .replace("{unresolved}", String(feedback.unresolved)));
536
+ setNotice(feedback.kind === "edited"
537
+ ? t("capability.presets.replaced", "Replaced the confirmed preset under ID {id}; no second preset was created.").replace("{id}", String(feedback.presetId))
538
+ : t("capability.presets.imported", "Imported: {bound} MCP binding(s), {unresolved} unresolved ref(s).")
539
+ .replace("{bound}", String(feedback.bound)).replace("{unresolved}", String(feedback.unresolved)));
446
540
  refreshPresets();
447
541
  } else {
448
- setImportBox({ ...importBox, busy: false, feedback });
449
- if (feedback.kind === "error") refreshPresets();
542
+ setImportBox({ ...importBox, busy: false, feedback: feedback.kind === "name-conflict" ? { ...feedback, name: document?.name, scope: importBox.scope } : { ...feedback, message: editMessage(feedback) } });
543
+ if (feedback.kind !== "name-conflict") refreshPresets();
450
544
  }
451
- }).catch(() => setImportBox({ ...importBox, busy: false, feedback: { kind: "error" } }));
545
+ }).catch(() => { setImportBox({ ...importBox, busy: false, feedback: { kind: "error", message: editMessage({ kind: "error" }) } }); refreshPresets(); });
452
546
  };
453
547
  // D6 phase two: the explicit confirm — installation is this call's
454
548
  // main effect, carrying the collision decision from the summary.
@@ -456,28 +550,38 @@ window.__ModuleLoader__.load({
456
550
  if (typeof props.presetImport !== "function" || importBox.busy || !importBox.summary) return;
457
551
  if (!model.importConfirmReadyOf(importBox.summary, importBox.decision)) return;
458
552
  const spec = { document: importBox.document, scope: importBox.scope, onCollision: importBox.decision };
459
- if (onNameConflict) spec.onNameConflict = onNameConflict;
553
+ if (onNameConflict === "replace") {
554
+ const target = importBox.feedback;
555
+ if (!target || typeof target.with !== "string" || !Number.isSafeInteger(target.withRevision) || target.name !== importBox.document?.name || target.scope !== importBox.scope) return;
556
+ spec.onNameConflict = "replace";
557
+ spec.replaceTarget = { presetId: target.with, expectedRevision: target.withRevision, name: target.name };
558
+ }
460
559
  setImportBox({ ...importBox, busy: true, feedback: null });
461
560
  props.presetImport(props.sessionId, spec).then((response) => {
462
561
  const outcome = model.importConfirmOutcomeOf(response);
463
- if (outcome.kind === "created") {
562
+ if (outcome.kind === "created" || outcome.kind === "edited") {
464
563
  setImportBox({ ...importBox, busy: false, feedback: null, summary: null, result: outcome });
465
- setNotice(t("capability.presets.importedPackage", "Imported: {installed} Skill(s) installed, {bound} MCP binding(s), {unresolved} unresolved ref(s).")
466
- .replace("{installed}", String(outcome.installed.length))
467
- .replace("{bound}", String(outcome.bound))
468
- .replace("{unresolved}", String(outcome.unresolved)));
564
+ setNotice(outcome.kind === "edited"
565
+ ? t("capability.presets.replaced", "Replaced the confirmed preset under ID {id}; no second preset was created.").replace("{id}", String(outcome.presetId))
566
+ : t("capability.presets.importedPackage", "Imported: {installed} Skill(s) installed, {bound} MCP binding(s), {unresolved} unresolved ref(s).")
567
+ .replace("{installed}", String(outcome.installed.length)).replace("{bound}", String(outcome.bound)).replace("{unresolved}", String(outcome.unresolved)));
469
568
  refreshPresets();
470
569
  } else if (outcome.kind === "name-conflict") {
471
570
  // The summary stays up; the decision row offers replace/cancel.
472
- setImportBox({ ...importBox, busy: false, feedback: { kind: "name-conflict", with: outcome.with } });
571
+ setImportBox({ ...importBox, busy: false, feedback: { kind: "name-conflict", with: outcome.with, withRevision: outcome.withRevision, name: importBox.document?.name, scope: importBox.scope } });
572
+ } else if (outcome.installed?.length > 0 || outcome.kind === "preset-unconfirmed" || outcome.kind === "write-failed" || outcome.kind === "commit-failed") {
573
+ setImportBox({ ...importBox, busy: false, feedback: null, summary: null, result: outcome });
574
+ refreshPresets();
473
575
  } else if (outcome.kind === "error") {
474
- setImportBox({ ...importBox, busy: false, feedback: { kind: "error" } });
576
+ setImportBox({ ...importBox, busy: false, feedback: { kind: "error", message: editMessage(outcome) }, summary: null });
577
+ refreshPresets();
475
578
  } else {
476
579
  // install-failed (with the rollback count), no-target-root,
477
580
  // rejected, no-workspace: the result surface names them.
478
581
  setImportBox({ ...importBox, busy: false, feedback: null, summary: null, result: outcome });
582
+ if (outcome.kind !== "install-failed" && outcome.kind !== "no-target-root") refreshPresets();
479
583
  }
480
- }).catch(() => setImportBox({ ...importBox, busy: false, feedback: { kind: "error" } }));
584
+ }).catch(() => { setImportBox({ ...importBox, busy: false, feedback: { kind: "error", message: editMessage({ kind: "error" }) }, summary: null }); refreshPresets(); });
481
585
  };
482
586
  // Cancel after the summary: only the dry-run ran, so nothing was
483
587
  // written; the pasted text stays for editing.
@@ -569,6 +673,16 @@ window.__ModuleLoader__.load({
569
673
  onClick: () => (active && rowAction.kind === "export" ? setRowAction(null) : openExport(row)),
570
674
  children: t("capability.presets.export", "Export")
571
675
  }),
676
+ react_jsx_runtime.jsx("button", {
677
+ type: "button", style: (!props.draft || typeof props.presetRename !== "function" || (active && rowAction.busy)) ? { ...S.button, ...S.disabled } : S.button,
678
+ ...ring, disabled: !props.draft || typeof props.presetRename !== "function" || (active && rowAction.busy),
679
+ onClick: () => openRowEdit(row, "rename"), children: t("capability.presets.renameRow", "Rename preset…")
680
+ }),
681
+ react_jsx_runtime.jsx("button", {
682
+ type: "button", style: (!props.draft || typeof props.presetResave !== "function" || (active && rowAction.busy)) ? { ...S.button, ...S.disabled } : S.button,
683
+ ...ring, disabled: !props.draft || typeof props.presetResave !== "function" || (active && rowAction.busy),
684
+ onClick: () => openRowEdit(row, "resave"), children: t("capability.presets.resaveRow", "Re-save…")
685
+ }),
572
686
  react_jsx_runtime.jsx("button", {
573
687
  type: "button",
574
688
  style: active && rowAction.busy ? { ...S.dangerOutline, ...S.disabled } : S.dangerOutline,
@@ -580,6 +694,35 @@ window.__ModuleLoader__.load({
580
694
  })
581
695
  ]
582
696
  }),
697
+ active && (rowAction.kind === "rename" || rowAction.kind === "resave")
698
+ ? react_jsx_runtime.jsxs("div", {
699
+ style: S.strip, "data-weir-preset-edit": rowAction.kind, children: [
700
+ react_jsx_runtime.jsx("span", { children: t("capability.presets.editTarget", "Target: {name} · {scope} · ID {id} · revision {revision}")
701
+ .replace("{name}", row.name).replace("{scope}", row.scope).replace("{id}", row.presetId).replace("{revision}", String(row.revision)) }),
702
+ rowAction.kind === "rename" ? react_jsx_runtime.jsx("input", {
703
+ style: S.input, ...ring, "aria-label": t("capability.presets.newName", "New preset name"),
704
+ value: rowAction.name, onChange: (event) => setRowAction({ ...rowAction, name: event.target.value, error: null }),
705
+ onKeyDown: (event) => { if (event.key === "Escape" && !rowAction.busy) setRowAction(null); if (event.key === "Enter") submitRowEdit(row); }
706
+ }) : react_jsx_runtime.jsxs("label", { style: S.label, children: [
707
+ t("capability.presets.source", "From"), react_jsx_runtime.jsxs("select", { style: S.select, ...ring, value: rowAction.from,
708
+ onChange: (event) => setRowAction({ ...rowAction, from: event.target.value, error: null }), children: [
709
+ react_jsx_runtime.jsx("option", { value: "draft", children: t("capability.presets.fromDraft", "current draft") }),
710
+ react_jsx_runtime.jsx("option", { value: "applied", children: t("capability.presets.fromApplied", "applied selection") })
711
+ ] }) ] }),
712
+ rowAction.kind === "resave" ? react_jsx_runtime.jsx("span", { children: t("capability.presets.resaveConfirm", "Overwrite this preset from {source}: {skills} Skills · {mcp} MCP · {unresolved} unresolved. Current session stays unchanged.")
713
+ .replace("{source}", rowAction.from === "draft" ? t("capability.presets.fromDraft", "current draft") : t("capability.presets.fromApplied", "applied selection"))
714
+ .replace("{skills}", String((rowAction.from === "draft" ? props.draft?.skills : props.draft?.applied?.skills)?.length ?? 0))
715
+ .replace("{mcp}", String((rowAction.from === "draft" ? props.draft?.mcpServers : props.draft?.applied?.mcpServers)?.length ?? 0))
716
+ .replace("{unresolved}", String((rowAction.from === "draft" ? props.draft?.unresolvedRefs : props.draft?.applied?.unresolvedRefs)?.length ?? 0)) }) : null,
717
+ react_jsx_runtime.jsxs("div", { style: S.buttonRow, children: [
718
+ react_jsx_runtime.jsx("button", { type: "button", style: (rowAction.busy || rowAction.stale || (rowAction.kind === "resave" && rowAction.from === "applied" && appliedSourceIssue())) ? { ...S.primary, ...S.disabled } : S.primary, ...ring,
719
+ disabled: Boolean(rowAction.busy || rowAction.stale || (rowAction.kind === "resave" && rowAction.from === "applied" && appliedSourceIssue())), onClick: () => submitRowEdit(row), children: rowAction.kind === "rename" ? t("capability.presets.renameSubmit", "Save new name") : t("capability.presets.resaveSubmit", "Confirm re-save") }),
720
+ react_jsx_runtime.jsx("button", { type: "button", style: rowAction.busy ? { ...S.button, ...S.disabled } : S.button, ...ring,
721
+ disabled: rowAction.busy, onClick: () => setRowAction(null), children: t("capability.presets.cancel", "Cancel") }) ] }),
722
+ rowAction.error ? react_jsx_runtime.jsx("span", { role: rowAction.stale ? "status" : "alert", style: S.warn, children: rowAction.error }) : null,
723
+ rowAction.kind === "resave" && rowAction.from === "applied" && appliedSourceIssue() ? react_jsx_runtime.jsx("span", { role: "alert", style: S.warn, children: appliedSourceIssue() }) : null
724
+ ]
725
+ }) : null,
583
726
  active && rowAction.kind === "load" && rowAction.error
584
727
  ? react_jsx_runtime.jsx("div", { style: S.warn, children: rowAction.error })
585
728
  : null,
@@ -738,15 +881,15 @@ window.__ModuleLoader__.load({
738
881
  ? react_jsx_runtime.jsxs("div", {
739
882
  style: S.strip,
740
883
  children: [
741
- react_jsx_runtime.jsx("span", { children: t("capability.presets.importNameConflict", "A preset with this name already exists here.") }),
884
+ react_jsx_runtime.jsx("span", { children: t("capability.presets.replaceTarget", "Replace preset ID {id} at revision {revision} in {scope}?").replace("{id}", String(importFeedback.with)).replace("{revision}", String(importFeedback.withRevision ?? "?")).replace("{scope}", importBox.scope) }),
742
885
  react_jsx_runtime.jsxs("div", {
743
886
  style: S.buttonRow,
744
887
  children: [
745
888
  react_jsx_runtime.jsx("button", {
746
889
  type: "button",
747
- style: importBox.busy ? { ...S.dangerOutline, ...S.disabled } : S.dangerOutline,
890
+ style: (importBox.busy || !Number.isSafeInteger(importFeedback.withRevision)) ? { ...S.dangerOutline, ...S.disabled } : S.dangerOutline,
748
891
  ...ring,
749
- disabled: importBox.busy,
892
+ disabled: importBox.busy || !Number.isSafeInteger(importFeedback.withRevision),
750
893
  onClick: () => confirmImport("replace"),
751
894
  children: t("capability.presets.replace", "Replace it")
752
895
  }),
@@ -792,16 +935,19 @@ window.__ModuleLoader__.load({
792
935
  // stay UNSELECTED until a draft pick + Apply), collision decisions,
793
936
  // or the failure with its rollback note.
794
937
  const importResultChildren = (result) => {
795
- if (result.kind !== "created") {
938
+ if (result.kind !== "created" && result.kind !== "edited") {
796
939
  const text = result.kind === "install-failed"
797
940
  ? t("capability.presets.importInstallFailed", "Installation failed: {reason} — rolled back {n} file(s); no preset was created.").replace("{reason}", result.reason).replace("{n}", String(result.rolledBack))
798
941
  : result.kind === "no-target-root"
799
942
  ? t("capability.presets.importNoTargetRoot", "No {scope} Skill root is available on this host — nothing was installed.").replace("{scope}", result.targetScope)
800
943
  : result.kind === "rejected"
801
944
  ? t("capability.presets.importRejected", "Rejected: {reason} — nothing was written.").replace("{reason}", result.reason)
802
- : t("capability.presets.noWorkspace", "This session has no workspace.");
945
+ : result.kind === "preset-unconfirmed" || result.installed?.length > 0 || result.kind === "commit-failed" || result.kind === "write-failed"
946
+ ? t("capability.presets.importPartial", "Installed Skills: {names}. Preset status is unconfirmed. Inspect the installed files and refresh the preset before deciding how to recover.")
947
+ .replace("{names}", result.installed?.length ? result.installed.map(row => row.target || row.name || "unknown").join(", ") : t("capability.presets.noneKnown", "none reported"))
948
+ : editMessage(result);
803
949
  return [
804
- react_jsx_runtime.jsx("div", { style: S.warn, children: text }),
950
+ react_jsx_runtime.jsx("div", { role: "alert", style: S.warn, children: text }),
805
951
  react_jsx_runtime.jsx("div", {
806
952
  style: S.buttonRow,
807
953
  children: react_jsx_runtime.jsx("button", {
@@ -874,7 +1020,8 @@ window.__ModuleLoader__.load({
874
1020
  })
875
1021
  ]
876
1022
  }),
877
- notice ? react_jsx_runtime.jsx("div", { style: S.notice, children: notice }) : null,
1023
+ notice ? react_jsx_runtime.jsx("div", { role: "status", "aria-live": "polite", style: S.notice, children: notice }) : null,
1024
+ editAlert ? react_jsx_runtime.jsx("div", { role: "alert", style: S.warn, children: editAlert }) : null,
878
1025
  saveForm.open
879
1026
  ? react_jsx_runtime.jsxs("div", {
880
1027
  style: S.card,
@@ -928,7 +1075,7 @@ window.__ModuleLoader__.load({
928
1075
  ? react_jsx_runtime.jsxs("div", {
929
1076
  style: S.strip,
930
1077
  children: [
931
- react_jsx_runtime.jsx("span", { children: t("capability.presets.nameConflict", "A preset named \"{name}\" already exists in this namespace.").replace("{name}", saveForm.name.trim()) }),
1078
+ react_jsx_runtime.jsx("span", { children: t("capability.presets.replaceTarget", "Replace preset ID {id} at revision {revision} in {scope}?").replace("{id}", String(saveForm.conflict.with)).replace("{revision}", String(saveForm.conflict.withRevision ?? "?")).replace("{scope}", saveForm.scope) }),
932
1079
  react_jsx_runtime.jsxs("div", {
933
1080
  style: S.buttonRow,
934
1081
  children: [
@@ -943,9 +1090,9 @@ window.__ModuleLoader__.load({
943
1090
  }),
944
1091
  react_jsx_runtime.jsx("button", {
945
1092
  type: "button",
946
- style: saveForm.busy ? { ...S.dangerOutline, ...S.disabled } : S.dangerOutline,
1093
+ style: (saveForm.busy || !Number.isSafeInteger(saveForm.conflict.withRevision) || (saveForm.from === "applied" && appliedSourceIssue())) ? { ...S.dangerOutline, ...S.disabled } : S.dangerOutline,
947
1094
  ...ring,
948
- disabled: saveForm.busy,
1095
+ disabled: Boolean(saveForm.busy || !Number.isSafeInteger(saveForm.conflict.withRevision) || (saveForm.from === "applied" && appliedSourceIssue())),
949
1096
  onClick: () => submitSave("replace"),
950
1097
  children: t("capability.presets.replace", "Replace it")
951
1098
  }),
@@ -968,14 +1115,15 @@ window.__ModuleLoader__.load({
968
1115
  children: [
969
1116
  react_jsx_runtime.jsx("button", {
970
1117
  type: "button",
971
- style: saveForm.busy ? { ...S.primary, ...S.disabled } : S.primary,
1118
+ style: (saveForm.busy || (saveForm.from === "applied" && appliedSourceIssue())) ? { ...S.primary, ...S.disabled } : S.primary,
972
1119
  ...ring,
973
1120
  ...(saveForm.busy ? {} : hover(ACCENT_HOVER, ACCENT)),
974
- disabled: saveForm.busy,
1121
+ disabled: Boolean(saveForm.busy || (saveForm.from === "applied" && appliedSourceIssue())),
975
1122
  onClick: () => submitSave(undefined),
976
1123
  children: saveForm.busy ? t("capability.presets.saving", "Saving…") : t("capability.presets.save", "Save preset")
977
1124
  }),
978
- saveForm.error ? react_jsx_runtime.jsx("span", { style: S.warn, children: saveForm.error }) : null
1125
+ saveForm.error ? react_jsx_runtime.jsx("span", { style: S.warn, children: saveForm.error }) : null,
1126
+ saveForm.from === "applied" && appliedSourceIssue() ? react_jsx_runtime.jsx("span", { role: "alert", style: S.warn, children: appliedSourceIssue() }) : null
979
1127
  ]
980
1128
  })
981
1129
  ]
@@ -1041,15 +1189,15 @@ window.__ModuleLoader__.load({
1041
1189
  ? react_jsx_runtime.jsxs("div", {
1042
1190
  style: S.strip,
1043
1191
  children: [
1044
- react_jsx_runtime.jsx("span", { children: t("capability.presets.importNameConflict", "A preset with this name already exists here.") }),
1192
+ react_jsx_runtime.jsx("span", { children: t("capability.presets.replaceTarget", "Replace preset ID {id} at revision {revision} in {scope}?").replace("{id}", String(importFeedback.with)).replace("{revision}", String(importFeedback.withRevision ?? "?")).replace("{scope}", importBox.scope) }),
1045
1193
  react_jsx_runtime.jsxs("div", {
1046
1194
  style: S.buttonRow,
1047
1195
  children: [
1048
1196
  react_jsx_runtime.jsx("button", {
1049
1197
  type: "button",
1050
- style: importBox.busy ? { ...S.dangerOutline, ...S.disabled } : S.dangerOutline,
1198
+ style: (importBox.busy || !Number.isSafeInteger(importFeedback.withRevision)) ? { ...S.dangerOutline, ...S.disabled } : S.dangerOutline,
1051
1199
  ...ring,
1052
- disabled: importBox.busy,
1200
+ disabled: importBox.busy || !Number.isSafeInteger(importFeedback.withRevision),
1053
1201
  onClick: () => submitImport("replace"),
1054
1202
  children: t("capability.presets.replace", "Replace it")
1055
1203
  }),
@@ -1071,7 +1219,7 @@ window.__ModuleLoader__.load({
1071
1219
  ? react_jsx_runtime.jsx("div", { style: S.warn, children: t("capability.presets.noWorkspace", "This session has no workspace.") })
1072
1220
  : null,
1073
1221
  importFeedback && importFeedback.kind === "error"
1074
- ? react_jsx_runtime.jsx("div", { style: S.warn, children: t("capability.presets.importFailed", "Import failed — nothing was written.") })
1222
+ ? react_jsx_runtime.jsx("div", { role: "alert", style: S.warn, children: importFeedback.message ?? t("capability.presets.uncertain", "Result unknown. Refresh and inspect the preset before deciding whether to retry.") })
1075
1223
  : null
1076
1224
  ]
1077
1225
  })
@@ -12,7 +12,7 @@ window.__ModuleLoader__.load({
12
12
  // semantics) plus read-only authority inspection per server-derived
13
13
  // domain root, over raw fetch ("/api/weir-edit-lock/maintenance/*").
14
14
  // The panel never sends a path the server did not list first, and it
15
- // offers no mutation: the switch itself stays an ordinary settings
15
+ // offers recovery only while the manager is mounted. The switch itself
16
16
  // field. Style constants are verbatim copies of the settings-page
17
17
  // constants this panel uses (same-package sync require is impossible
18
18
  // in the ModuleLoader).
@@ -20,7 +20,7 @@ window.__ModuleLoader__.load({
20
20
  const labelGroupStyle = { display: "flex", flexDirection: "column", gap: "2px", minWidth: 0 };
21
21
  const labelStyle = { fontSize: "14px", fontWeight: 500, lineHeight: "20px" };
22
22
  const hintStyle = { fontSize: "12px", lineHeight: "16px", color: "var(--dsw-alias-label-secondary)" };
23
- const warnStyle = { fontSize: "12px", lineHeight: "16px", color: "var(--dsw-alias-state-business-warning, #b25f00)" };
23
+ const warnStyle = { fontSize: "12px", lineHeight: "16px", color: "var(--dsw-alias-state-warn-primary)" };
24
24
  const dangerStyle = { fontSize: "12px", lineHeight: "16px", color: "var(--dsw-alias-state-business-danger, #d64545)" };
25
25
  const chainPanelStyle = { display: "flex", flexDirection: "column", gap: "12px", padding: "12px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "var(--dsw-radius-md)", background: "var(--dsw-alias-interactive-bg-solid)", marginTop: "8px" };
26
26
  const chainCategoryStyle = { fontSize: "13px", fontWeight: 600, lineHeight: "18px" };
@@ -267,6 +267,7 @@ window.__ModuleLoader__.load({
267
267
  }
268
268
  /** Switch-state banner keys (state names contain hyphens). */
269
269
  const STATE_KEYS = { enforced: "Enforced", "disable-requested": "DisableRequested", "enable-requested": "EnableRequested", disabled: "Disabled", unknown: "Unknown" };
270
+ const onlineRecoveryAvailable = (state) => state === "enforced" || state === "disable-requested";
270
271
  const post = (url, body) => fetch(url, {
271
272
  method: "POST",
272
273
  credentials: "include",
@@ -290,6 +291,7 @@ window.__ModuleLoader__.load({
290
291
  * A refusal is shown next to a freshly reloaded scope.
291
292
  * @param {string} root @param {ReturnType<typeof recoveryCandidates>[number]} candidate */
292
293
  const recover = (root, candidate) => {
294
+ if (view?.status !== "ready" || !onlineRecoveryAvailable(view.value.state)) return;
293
295
  setRecoveries((previous) => ({ ...previous, [recoveryKey(root, candidate.owner)]: { status: "busy" } }));
294
296
  post("api/weir-edit-lock/maintenance/recover-online", {
295
297
  root,
@@ -451,13 +453,12 @@ window.__ModuleLoader__.load({
451
453
  ...snapshot.retainedLocks.map((lock, index) => react_jsx_runtime.jsx("div", { style: chainDescStyle, children: `${lock.resourceId} · ${lock.owner} · ${lock.status}${lock.reason ? `: ${lock.reason}` : ""} · gen ${lock.generation}` }, index))
452
454
  ] })
453
455
  : null,
454
- recoveryCandidates(root, snapshot).length === 0
455
- ? null
456
- : react_jsx_runtime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "6px" }, children: [
456
+ onlineRecoveryAvailable(view?.status === "ready" ? view.value.state : null) && recoveryCandidates(root, snapshot).length > 0
457
+ ? react_jsx_runtime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "6px" }, children: [
457
458
  react_jsx_runtime.jsx("div", { style: chainCategoryStyle, children: t("editLockMaintRecoveries") }),
458
459
  react_jsx_runtime.jsx("div", { style: chainDescStyle, children: t("editLockMaintRecoverHint") }),
459
460
  ...recoveryCandidates(root, snapshot).map((candidate) => recoveryCard(root, candidate))
460
- ] })
461
+ ] }) : null
461
462
  ] });
462
463
  const inspectionBody = (root) => {
463
464
  const inspection = inspections[root];
@@ -501,10 +502,8 @@ window.__ModuleLoader__.load({
501
502
  }
502
503
  const value = view.value;
503
504
  const stateKey = STATE_KEYS[value.state] ?? "Unknown";
504
- // Recovery UX D1: aggregate the zones from every auto-inspected root.
505
- // Blocked rows (with a force-release action) render first, then the
506
- // owners whose preconditions fail with the named reason; everything
507
- // else is the normal zone (banner, warnings, per-domain detail).
505
+ // Retained authority is history, not a current block, without a mounted manager.
506
+ const online = onlineRecoveryAvailable(value.state);
508
507
  const zoneGroups = new Map();
509
508
  const zoneUnmet = [];
510
509
  for (const root of Object.keys(inspections)) {
@@ -522,6 +521,15 @@ window.__ModuleLoader__.load({
522
521
  }
523
522
  const blockedGroups = [...zoneGroups.values()];
524
523
  zoneUnmet.sort((a, b) => a.entry.owner.localeCompare(b.entry.owner));
524
+ const historyRows = [...blockedGroups.flatMap((group) => group.rows), ...zoneUnmet.flatMap(({ entry }) => entry.rows)];
525
+ const historyScopes = zoneUnmet.flatMap(({ entry }) => entry.scopePaths);
526
+ for (const root of Object.keys(inspections)) {
527
+ const inspection = inspections[root];
528
+ if (inspection?.status !== "ready" || inspection.value?.presence !== "valid") continue;
529
+ for (const op of inspection.value.snapshot.unresolved) {
530
+ if (op.scope?.kind !== "file" && typeof op.scope?.path === "string" && !historyScopes.includes(op.scope.path)) historyScopes.push(op.scope.path);
531
+ }
532
+ }
525
533
  return react_jsx_runtime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "10px" }, children: [
526
534
  react_jsx_runtime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "2px" }, children: [
527
535
  react_jsx_runtime.jsx("span", { style: chainCategoryStyle, children: t(`editLockMaintState${stateKey}`) }),
@@ -530,18 +538,25 @@ window.__ModuleLoader__.load({
530
538
  value.pinned ? react_jsx_runtime.jsx("span", { style: warnStyle, children: t("editLockMaintPinned") }) : null,
531
539
  react_jsx_runtime.jsx("span", { style: chainDescStyle, children: t("editLockMaintScopeNote") })
532
540
  ] }),
541
+ !online ? react_jsx_runtime.jsx("div", { role: "alert", style: warnStyle, children: t(value.state === "unknown" ? "editLockMaintUnknownRisk" : "editLockMaintOffRisk") }) : null,
542
+ !online ? react_jsx_runtime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
543
+ react_jsx_runtime.jsx("span", { style: chainCategoryStyle, children: t(value.state === "unknown" ? "editLockMaintUnknownHistory" : "editLockMaintHistory") }),
544
+ react_jsx_runtime.jsx("span", { style: chainDescStyle, children: t(value.state === "unknown" ? "editLockMaintUnknownHistoryHint" : "editLockMaintHistoryHint") }),
545
+ ...historyRows.map((row, index) => react_jsx_runtime.jsx("span", { style: monoStyle, children: `${row.resourceId} · ${row.owner}${row.lockStatus ? ` · ${row.lockStatus}` : ""}${row.fence ? ` · ${RECOVERY_UX.stateFence}` : ""}` }, index)),
546
+ ...historyScopes.map((path, index) => react_jsx_runtime.jsx("span", { style: monoStyle, children: path }, `scope-${index}`))
547
+ ] }) : null,
533
548
  react_jsx_runtime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "2px" }, children: [
534
549
  react_jsx_runtime.jsx("span", { style: warnStyle, children: t("editLockMaintWarnKeepHistory") }),
535
550
  react_jsx_runtime.jsx("span", { style: warnStyle, children: t("editLockMaintWarnUnlock") })
536
551
  ] }),
537
- blockedGroups.length > 0
552
+ online && blockedGroups.length > 0
538
553
  ? react_jsx_runtime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
539
554
  react_jsx_runtime.jsx("span", { style: chainCategoryStyle, children: RECOVERY_UX.blockedHeader }),
540
555
  react_jsx_runtime.jsx("span", { style: chainDescStyle, children: RECOVERY_UX.blockedHint }),
541
556
  ...blockedGroups.map((group) => blockedZoneCard(group.root, group.candidate, group.rows))
542
557
  ] })
543
558
  : null,
544
- zoneUnmet.length > 0
559
+ online && zoneUnmet.length > 0
545
560
  ? react_jsx_runtime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
546
561
  react_jsx_runtime.jsx("span", { style: chainCategoryStyle, children: RECOVERY_UX.unmetHeader }),
547
562
  ...zoneUnmet.map(({ root, entry }) => unmetZoneRow(root, entry))