@agent-deck/backend 2.5.1 → 2.5.2

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 (98) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/deck-assignment-validation.d.ts +20 -0
  3. package/dist/deck-assignment-validation.d.ts.map +1 -0
  4. package/dist/deck-assignment-validation.js +75 -0
  5. package/dist/deck-assignment-validation.js.map +1 -0
  6. package/dist/execution-authority/bearer.d.ts +15 -0
  7. package/dist/execution-authority/bearer.d.ts.map +1 -0
  8. package/dist/execution-authority/bearer.js +35 -0
  9. package/dist/execution-authority/bearer.js.map +1 -0
  10. package/dist/execution-authority/index.d.ts +6 -0
  11. package/dist/execution-authority/index.d.ts.map +1 -0
  12. package/dist/execution-authority/index.js +8 -0
  13. package/dist/execution-authority/index.js.map +1 -0
  14. package/dist/execution-authority/ledger.d.ts +85 -0
  15. package/dist/execution-authority/ledger.d.ts.map +1 -0
  16. package/dist/execution-authority/ledger.js +507 -0
  17. package/dist/execution-authority/ledger.js.map +1 -0
  18. package/dist/execution-authority/store.d.ts +55 -0
  19. package/dist/execution-authority/store.d.ts.map +1 -0
  20. package/dist/execution-authority/store.js +256 -0
  21. package/dist/execution-authority/store.js.map +1 -0
  22. package/dist/execution-authority/types.d.ts +119 -0
  23. package/dist/execution-authority/types.d.ts.map +1 -0
  24. package/dist/execution-authority/types.js +9 -0
  25. package/dist/execution-authority/types.js.map +1 -0
  26. package/dist/lib/execution-authority-http.d.ts +23 -0
  27. package/dist/lib/execution-authority-http.d.ts.map +1 -0
  28. package/dist/lib/execution-authority-http.js +101 -0
  29. package/dist/lib/execution-authority-http.js.map +1 -0
  30. package/dist/mcp-server.d.ts +35 -4
  31. package/dist/mcp-server.d.ts.map +1 -1
  32. package/dist/mcp-server.js +293 -36
  33. package/dist/mcp-server.js.map +1 -1
  34. package/dist/mcp-session-binding.d.ts +73 -2
  35. package/dist/mcp-session-binding.d.ts.map +1 -1
  36. package/dist/mcp-session-binding.js +108 -2
  37. package/dist/mcp-session-binding.js.map +1 -1
  38. package/dist/mcp-stdio.d.ts +2 -0
  39. package/dist/mcp-stdio.d.ts.map +1 -0
  40. package/dist/mcp-stdio.js.map +1 -0
  41. package/dist/mcp-tools/deck-assignment-elicitation.d.ts +91 -0
  42. package/dist/mcp-tools/deck-assignment-elicitation.d.ts.map +1 -0
  43. package/dist/mcp-tools/deck-assignment-elicitation.js +222 -0
  44. package/dist/mcp-tools/deck-assignment-elicitation.js.map +1 -0
  45. package/dist/mcp-tools/register.d.ts +16 -0
  46. package/dist/mcp-tools/register.d.ts.map +1 -1
  47. package/dist/mcp-tools/register.js +213 -61
  48. package/dist/mcp-tools/register.js.map +1 -1
  49. package/dist/mcp-unassigned.d.ts +28 -2
  50. package/dist/mcp-unassigned.d.ts.map +1 -1
  51. package/dist/mcp-unassigned.js +30 -3
  52. package/dist/mcp-unassigned.js.map +1 -1
  53. package/dist/playbooks/playbook-parser.d.ts +8 -0
  54. package/dist/playbooks/playbook-parser.d.ts.map +1 -0
  55. package/dist/playbooks/playbook-parser.js +76 -0
  56. package/dist/playbooks/playbook-parser.js.map +1 -0
  57. package/dist/playbooks/playbook-service.d.ts +9 -0
  58. package/dist/playbooks/playbook-service.d.ts.map +1 -0
  59. package/dist/playbooks/playbook-service.js +107 -0
  60. package/dist/playbooks/playbook-service.js.map +1 -0
  61. package/dist/routes/default-deck.d.ts +13 -0
  62. package/dist/routes/default-deck.d.ts.map +1 -0
  63. package/dist/routes/default-deck.js +36 -0
  64. package/dist/routes/default-deck.js.map +1 -0
  65. package/dist/routes/execution-authority.d.ts +8 -0
  66. package/dist/routes/execution-authority.d.ts.map +1 -0
  67. package/dist/routes/execution-authority.js +498 -0
  68. package/dist/routes/execution-authority.js.map +1 -0
  69. package/dist/routes/trusted-session.d.ts.map +1 -1
  70. package/dist/routes/trusted-session.js +285 -0
  71. package/dist/routes/trusted-session.js.map +1 -1
  72. package/dist/scope/bindings-sidecar.d.ts +9 -0
  73. package/dist/scope/bindings-sidecar.d.ts.map +1 -0
  74. package/dist/scope/bindings-sidecar.js +57 -0
  75. package/dist/scope/bindings-sidecar.js.map +1 -0
  76. package/dist/scope/repo-deck.d.ts +10 -0
  77. package/dist/scope/repo-deck.d.ts.map +1 -0
  78. package/dist/scope/repo-deck.js +63 -0
  79. package/dist/scope/repo-deck.js.map +1 -0
  80. package/dist/server/index.d.ts.map +1 -1
  81. package/dist/server/index.js +2 -0
  82. package/dist/server/index.js.map +1 -1
  83. package/dist/test-local-mcp-e2e.d.ts +3 -0
  84. package/dist/test-local-mcp-e2e.d.ts.map +1 -0
  85. package/dist/test-local-mcp-e2e.js +104 -0
  86. package/dist/test-local-mcp-e2e.js.map +1 -0
  87. package/dist/trusted-session/route-policy-registry.d.ts.map +1 -1
  88. package/dist/trusted-session/route-policy-registry.js +35 -0
  89. package/dist/trusted-session/route-policy-registry.js.map +1 -1
  90. package/dist/trusted-session/store.d.ts +131 -0
  91. package/dist/trusted-session/store.d.ts.map +1 -1
  92. package/dist/trusted-session/store.js +347 -1
  93. package/dist/trusted-session/store.js.map +1 -1
  94. package/package.json +2 -2
  95. package/static-ui/assets/{index-Bbu6K9ON.js → index-B5GT9yb2.js} +72 -57
  96. package/static-ui/assets/{index-BKJkKaDa.css → index-DBeN8gfw.css} +1 -1
  97. package/static-ui/favicon.png +0 -0
  98. package/static-ui/index.html +2 -2
@@ -27,6 +27,7 @@ const mcp_unassigned_1 = require("./mcp-unassigned");
27
27
  const stub_sync_1 = require("./playbooks/stub-sync");
28
28
  const request_limiter_1 = require("./auth/request-limiter");
29
29
  const store_1 = require("./audit/store");
30
+ const deck_assignment_validation_1 = require("./deck-assignment-validation");
30
31
  function readWorkspaceRootHeader(req) {
31
32
  const raw = req.headers[shared_1.AGENT_DECK_WORKSPACE_HEADER];
32
33
  const value = typeof raw === 'string' ? raw.trim() : '';
@@ -44,10 +45,38 @@ function readLaunchDeckHeader(req) {
44
45
  * shared `readUseManifest`. Returns undefined when the file is missing,
45
46
  * unreadable, corrupt, or not a v3 manifest, so the caller keeps the
46
47
  * existing unassigned flow.
48
+ *
49
+ * NOT-604: also returns the saved `deckName` so the unassigned reply can
50
+ * name a deleted deck. The name is display-only; the id selects the deck.
51
+ */
52
+ function resolveUseManifestDeck(workspaceRoot) {
53
+ const manifest = (0, stub_sync_1.readUseManifest)(workspaceRoot);
54
+ const deckId = manifest?.deckId?.trim();
55
+ if (!deckId) {
56
+ return undefined;
57
+ }
58
+ return { deckId, deckName: manifest?.deckName?.trim() ?? '' };
59
+ }
60
+ /**
61
+ * NOT-600: the user default deck (`$AGENT_DECK_HOME/default-deck.json`),
62
+ * consulted only when no launch deck header and no folder assignment
63
+ * resolve. Empty when no default is set — a dangling default (deck
64
+ * deleted) still resolves here and degrades to the unassigned flow at
65
+ * bind time, like a dangling manifest.
66
+ *
67
+ * NOT-606: also surfaces the saved `deckName` and the unreadable-file
68
+ * path, so the unassigned reply can name a missing or unreadable default
69
+ * instead of behaving as if no default was ever set.
47
70
  */
48
- function resolveUseManifestDeckId(workspaceRoot) {
49
- const deckId = (0, stub_sync_1.readUseManifest)(workspaceRoot)?.deckId?.trim();
50
- return deckId || undefined;
71
+ function resolveUserDefaultDeck() {
72
+ const state = (0, shared_1.readDefaultDeckState)();
73
+ if (state.status === 'ok') {
74
+ return { deckId: state.deck.deckId, deckName: state.deck.deckName };
75
+ }
76
+ if (state.status === 'unreadable') {
77
+ return { unreadablePath: state.path };
78
+ }
79
+ return {};
51
80
  }
52
81
  /**
53
82
  * Opaque run-correlation id for launch-selected sessions (NOT-304).
@@ -365,7 +394,7 @@ class AgentDeckMCPServer {
365
394
  const unassigned = this.sessionBinding.isUnassigned(sessionId);
366
395
  let instructions;
367
396
  if (unassigned) {
368
- instructions = mcp_unassigned_1.UNASSIGNED_DECK_MESSAGE;
397
+ instructions = (0, mcp_unassigned_1.unassignedDeckMessage)(this.sessionBinding.getUnassignedMissingDeckName(sessionId), this.sessionBinding.getUnassignedDefaultDeckIssue(sessionId));
369
398
  }
370
399
  else {
371
400
  instructions = await this.resolveInitializeInstructions(sessionId);
@@ -908,14 +937,38 @@ class AgentDeckMCPServer {
908
937
  };
909
938
  }
910
939
  setupTools(sessionId) {
911
- // NOT-213: capture the session server while in the registration context;
912
- // the closures below run later at tool-call time and must not touch
913
- // `this.server` (registration-only getter).
914
- const elicitingServer = this.server;
940
+ this.setupToolsOnServer(this.server, sessionId, {
941
+ unassigned: this.sessionBinding.isUnassigned(sessionId),
942
+ skipExisting: false,
943
+ });
944
+ }
945
+ /**
946
+ * NOT-597: register tools on one session server. Initial registration
947
+ * (`skipExisting: false`) runs in the registration context; late
948
+ * promotion of an unassigned session reuses the same host with
949
+ * `skipExisting: true` so the already-registered bootstrap reads
950
+ * (promotion-aware) stay while the full tool list is added without a
951
+ * reload. `tools/list` reads the live registry, so the next list
952
+ * includes the newly registered tools.
953
+ */
954
+ setupToolsOnServer(elicitingServer, sessionId, opts) {
955
+ const registerTool = (name, config, handler) => {
956
+ try {
957
+ elicitingServer.registerTool(name, config, handler);
958
+ }
959
+ catch (error) {
960
+ if (opts.skipExisting &&
961
+ error instanceof Error &&
962
+ error.message.includes('already registered')) {
963
+ return;
964
+ }
965
+ throw error;
966
+ }
967
+ };
915
968
  (0, register_1.registerMcpTools)({
916
- registerTool: (name, config, handler) => this.registerTool(name, config, handler),
969
+ registerTool,
917
970
  profile: this.toolProfile,
918
- unassigned: this.sessionBinding.isUnassigned(sessionId),
971
+ unassigned: opts.unassigned,
919
972
  getSessionId: () => sessionId,
920
973
  getMode: () => this.sessionBinding.getMode(sessionId) ?? 'normal',
921
974
  refreshRuntimeSession: () => this.refreshRuntimeSession(sessionId),
@@ -931,6 +984,7 @@ class AgentDeckMCPServer {
931
984
  backendUrl: this.backendUrl,
932
985
  toolResult: (data) => this.toolResult(data),
933
986
  toolError: (error) => this.toolError(error),
987
+ tryPromoteUnassignedSession: (id) => this.tryPromoteUnassignedSession(id),
934
988
  // NOT-213: host-native approval form for this session. Capability
935
989
  // detection reads the capabilities the client reported at initialize;
936
990
  // elicitation itself goes through the session server so the host UI
@@ -953,6 +1007,66 @@ class AgentDeckMCPServer {
953
1007
  },
954
1008
  });
955
1009
  }
1010
+ /**
1011
+ * NOT-597: promote an unassigned session whose assignment was approved
1012
+ * elsewhere. Polls the consumed-assignment record by MCP session id;
1013
+ * on a hit, validates the folder again, records the trusted binding,
1014
+ * registers the full tool list on the live server, and registers the
1015
+ * live display — the same session then serves the deck without a
1016
+ * reload. Returns whether the session is now bound. Never throws for
1017
+ * poll-level failures: those mean "still unassigned".
1018
+ */
1019
+ async tryPromoteUnassignedSession(sessionId) {
1020
+ try {
1021
+ if (!this.sessionBinding.isUnassigned(sessionId)) {
1022
+ return true;
1023
+ }
1024
+ const response = await fetch(`${this.backendUrl}/api/trusted-session/deck-assignment/by-mcp/${encodeURIComponent(sessionId)}`, { headers: { Accept: 'application/json' } });
1025
+ if (!response.ok) {
1026
+ return false;
1027
+ }
1028
+ const body = (await response.json());
1029
+ const data = body?.data;
1030
+ if (!body?.success || !data) {
1031
+ return false;
1032
+ }
1033
+ const runtimeSessionId = typeof data.runtimeSessionId === 'string' ? data.runtimeSessionId.trim() : '';
1034
+ const deckId = typeof data.deckId === 'string' ? data.deckId.trim() : '';
1035
+ const validated = (0, deck_assignment_validation_1.validateAssignmentWorkspace)(data.workspaceRoot);
1036
+ if (!runtimeSessionId || !deckId || !validated.ok) {
1037
+ return false;
1038
+ }
1039
+ this.sessionBinding.promoteUnassignedToAssignment(sessionId, {
1040
+ runtimeSessionId,
1041
+ deckId,
1042
+ workspaceRoot: validated.workspaceRoot,
1043
+ });
1044
+ const live = this.sessions.get(sessionId);
1045
+ if (live) {
1046
+ try {
1047
+ this.setupToolsOnServer(live.server, sessionId, {
1048
+ unassigned: false,
1049
+ skipExisting: true,
1050
+ });
1051
+ }
1052
+ catch {
1053
+ // Best effort: the binding is committed; the bootstrap reads
1054
+ // are promotion-aware and return the deck even if the late
1055
+ // tool registration partially failed.
1056
+ }
1057
+ }
1058
+ try {
1059
+ await this.registerLiveDisplay(sessionId);
1060
+ }
1061
+ catch {
1062
+ // Best effort; the binding is already committed.
1063
+ }
1064
+ return true;
1065
+ }
1066
+ catch {
1067
+ return false;
1068
+ }
1069
+ }
956
1070
  setupResources(sessionId) {
957
1071
  this.server.resource("bound_deck_summary", "agent-deck://bound-deck/summary", {
958
1072
  description: "One-line summary of the workspace-bound deck for status display",
@@ -1581,7 +1695,9 @@ class AgentDeckMCPServer {
1581
1695
  this.adoptPlaybookPin(sessionId, req);
1582
1696
  }
1583
1697
  async disconnectTrustedSession(sessionId, _req) {
1584
- if (this.sessionBinding.isLaunchSession(sessionId) || this.sessionBinding.isGrantSession(sessionId)) {
1698
+ if (this.sessionBinding.isLaunchSession(sessionId) ||
1699
+ this.sessionBinding.isGrantSession(sessionId) ||
1700
+ this.sessionBinding.isAssignmentSession(sessionId)) {
1585
1701
  try {
1586
1702
  await fetch(`${this.backendUrl}/api/trusted-session/mcp/disconnect-deck`, {
1587
1703
  method: 'POST',
@@ -1605,7 +1721,41 @@ class AgentDeckMCPServer {
1605
1721
  const skipDeckHeader = (0, mcp_unassigned_1.skipDeckHeaderAuth)();
1606
1722
  // Unassigned sessions stay explain-only for their lifetime. A late deck header
1607
1723
  // must not promote them into a trusted launch session mid-flight (NOT-50).
1724
+ // NOT-597: the one promotion path is a human-approved assignment —
1725
+ // best-effort poll here so tools/list also sees the full list without
1726
+ // waiting for the next bootstrap read.
1608
1727
  if (this.sessionBinding.isUnassigned(sessionId)) {
1728
+ try {
1729
+ await this.tryPromoteUnassignedSession(sessionId);
1730
+ }
1731
+ catch {
1732
+ // Still unassigned.
1733
+ }
1734
+ if (this.sessionBinding.isUnassigned(sessionId)) {
1735
+ return true;
1736
+ }
1737
+ }
1738
+ // NOT-597: assignment sessions (promoted from unassigned) carry no
1739
+ // deck header on follow-ups — the headerless host never sends one.
1740
+ // Re-validate through the runtime lease refresh instead, best-effort:
1741
+ // an expired lease surfaces as a backend GRANT_REQUIRED on the next
1742
+ // tool call, not as an HTTP 401 here.
1743
+ if (this.sessionBinding.isAssignmentSession(sessionId)) {
1744
+ try {
1745
+ await this.refreshRuntimeSession(sessionId);
1746
+ }
1747
+ catch {
1748
+ // Best effort; the tool call surfaces the backend error.
1749
+ }
1750
+ const workspaceRoot = readWorkspaceRootHeader(req);
1751
+ if (workspaceRoot) {
1752
+ this.sessionBinding.setWorkspace(sessionId, workspaceRoot);
1753
+ }
1754
+ const followUpCorrelation = readCorrelationIdHeader(req);
1755
+ if (followUpCorrelation) {
1756
+ this.sessionBinding.setCorrelationId(sessionId, followUpCorrelation);
1757
+ }
1758
+ this.adoptPlaybookPin(sessionId, req);
1609
1759
  return true;
1610
1760
  }
1611
1761
  const launchDeck = readLaunchDeckHeader(req);
@@ -1619,7 +1769,16 @@ class AgentDeckMCPServer {
1619
1769
  const useManifestFollowUp = !launchDeck &&
1620
1770
  this.sessionBinding.isLaunchSession(sessionId) &&
1621
1771
  this.sessionBinding.isUseManifestSession(sessionId);
1622
- if (launchDeck || useManifestFollowUp) {
1772
+ // NOT-600: sessions bound from the user default deck carry no deck
1773
+ // header on follow-ups either — re-validate through the same launch
1774
+ // follow-up instead of demanding the header. The default file is
1775
+ // authoritative only at initialize: like a changed deck header, a
1776
+ // later default change is sticky for the session lifetime and takes
1777
+ // effect when the client re-initializes.
1778
+ const defaultDeckFollowUp = !launchDeck &&
1779
+ this.sessionBinding.isLaunchSession(sessionId) &&
1780
+ this.sessionBinding.isDefaultDeckSession(sessionId);
1781
+ if (launchDeck || useManifestFollowUp || defaultDeckFollowUp) {
1623
1782
  try {
1624
1783
  await this.authenticateLaunchDeck(sessionId, req, launchDeck ?? this.sessionBinding.getBinding(sessionId).deckId);
1625
1784
  return true;
@@ -1649,16 +1808,42 @@ class AgentDeckMCPServer {
1649
1808
  }
1650
1809
  /**
1651
1810
  * Resolve the deck a bearer-free request binds (NOT-562, shared by the
1652
- * initialize path and NOT-569 recovery so the two resolve identically):
1653
- * an explicit deck header wins, else the folder assignment from
1654
- * `<workspace>/.agent-deck/use.json`. Anything else is not a deck —
1655
- * recovery refuses it and initialize takes the unassigned flow.
1811
+ * initialize path and NOT-569 recovery so the two resolve identically).
1812
+ * Strict precedence (NOT-600): an explicit deck header wins, else the
1813
+ * folder assignment from `<workspace>/.agent-deck/use.json`, else the
1814
+ * user default deck. Anything else is not a deck — recovery refuses it
1815
+ * and initialize takes the unassigned flow.
1816
+ *
1817
+ * NOT-604: the default is resolved whenever no launch header is present,
1818
+ * even when a folder assignment exists, so a manifest naming a deleted
1819
+ * deck falls through to the default at bind time instead of dead-ending
1820
+ * in the unassigned flow. `manifestDeckName` carries the saved display
1821
+ * name for the unassigned reply when no usable default binds.
1822
+ *
1823
+ * NOT-606: `defaultDeckName` and `defaultUnreadablePath` carry the saved
1824
+ * default display name and the unreadable-file path for the same reply,
1825
+ * so a missing or unreadable default is named when no default applied.
1656
1826
  */
1657
1827
  resolveHeaderDeck(req) {
1658
1828
  const launchDeck = readLaunchDeckHeader(req);
1659
1829
  const workspaceRoot = readWorkspaceRootHeader(req);
1660
- const manifestDeck = !launchDeck && workspaceRoot ? resolveUseManifestDeckId(workspaceRoot) : undefined;
1661
- return { launchDeck, workspaceRoot, manifestDeck, effectiveDeck: launchDeck ?? manifestDeck };
1830
+ const manifest = !launchDeck && workspaceRoot ? resolveUseManifestDeck(workspaceRoot) : undefined;
1831
+ const manifestDeck = manifest?.deckId;
1832
+ const manifestDeckName = manifest?.deckName || undefined;
1833
+ const userDefault = !launchDeck ? resolveUserDefaultDeck() : undefined;
1834
+ const defaultDeck = userDefault?.deckId;
1835
+ const defaultDeckName = userDefault?.deckName || undefined;
1836
+ const defaultUnreadablePath = userDefault?.unreadablePath;
1837
+ return {
1838
+ launchDeck,
1839
+ workspaceRoot,
1840
+ manifestDeck,
1841
+ manifestDeckName,
1842
+ defaultDeck,
1843
+ defaultDeckName,
1844
+ defaultUnreadablePath,
1845
+ effectiveDeck: launchDeck ?? manifestDeck ?? defaultDeck,
1846
+ };
1662
1847
  }
1663
1848
  /**
1664
1849
  * NOT-318: initialize with a bearer grant. Authenticates before
@@ -1909,9 +2094,10 @@ class AgentDeckMCPServer {
1909
2094
  }
1910
2095
  // NOT-562: workspace-header-only hosts (pure MCP, no launcher) resolve
1911
2096
  // the deck from the folder assignment. An explicit deck header still
1912
- // wins; the manifest is consulted only when it is absent. Shared with
1913
- // NOT-569 recovery so both paths resolve identically.
1914
- const { launchDeck, workspaceRoot, manifestDeck, effectiveDeck } = this.resolveHeaderDeck(req);
2097
+ // wins; the manifest is consulted only when it is absent. NOT-600 adds
2098
+ // the user default deck as the last resort. Shared with NOT-569
2099
+ // recovery so both paths resolve identically.
2100
+ const { launchDeck, workspaceRoot, manifestDeck, manifestDeckName, defaultDeck, defaultDeckName, defaultUnreadablePath, effectiveDeck, } = this.resolveHeaderDeck(req);
1915
2101
  const skipDeckHeader = (0, mcp_unassigned_1.skipDeckHeaderAuth)();
1916
2102
  const unassigned = !effectiveDeck && !skipDeckHeader;
1917
2103
  // Authenticate before advertising mcp-session-id.
@@ -1919,21 +2105,65 @@ class AgentDeckMCPServer {
1919
2105
  if (effectiveDeck) {
1920
2106
  try {
1921
2107
  await this.authenticateLaunchDeck(sessionId, req, effectiveDeck);
1922
- if (manifestDeck && !launchDeck) {
2108
+ if (manifestDeck && !launchDeck && effectiveDeck === manifestDeck) {
1923
2109
  this.sessionBinding.markUseManifestSession(sessionId);
1924
2110
  }
2111
+ else if (defaultDeck && !launchDeck && effectiveDeck === defaultDeck) {
2112
+ this.sessionBinding.markDefaultDeckSession(sessionId);
2113
+ }
1925
2114
  }
1926
2115
  catch (error) {
1927
- // NOT-562: the assignment names a deck the backend cannot bind
1928
- // (deleted deck) or the bind itself failed — the file is an
1929
- // opportunistic hint, not a credential, so degrade to the existing
1930
- // unassigned flow rather than erroring. The header path below keeps
1931
- // its fail-closed 401.
1932
- if (manifestDeck && !launchDeck) {
2116
+ // NOT-604: a manifest naming a deleted deck falls through to the
2117
+ // user default deck — the session resolves as if the folder had no
2118
+ // assignment. Only when the default is absent, identical, or also
2119
+ // fails to bind does the session degrade to unassigned (naming the
2120
+ // missing deck). NOT-562: the assignment is an opportunistic hint,
2121
+ // not a credential, so a bind failure never errors. NOT-600: a
2122
+ // dangling user default degrades the same way; the file is left in
2123
+ // place and revalidated on every initialize. NOT-606: the unassigned
2124
+ // reply also names the missing or unreadable default when that is
2125
+ // the reason no default applied. The header path below keeps its
2126
+ // fail-closed 401.
2127
+ const canFallThroughToDefault = manifestDeck && !launchDeck && defaultDeck && defaultDeck !== manifestDeck;
2128
+ if (canFallThroughToDefault) {
2129
+ try {
2130
+ await this.authenticateLaunchDeck(sessionId, req, defaultDeck);
2131
+ this.sessionBinding.markDefaultDeckSession(sessionId);
2132
+ }
2133
+ catch {
2134
+ this.sessionBinding.markUnassigned(sessionId);
2135
+ if (workspaceRoot) {
2136
+ this.sessionBinding.setWorkspace(sessionId, workspaceRoot);
2137
+ }
2138
+ this.sessionBinding.setUnassignedMissingDeckName(sessionId, manifestDeckName);
2139
+ if (defaultDeckName) {
2140
+ this.sessionBinding.setUnassignedDefaultDeckIssue(sessionId, {
2141
+ kind: 'missing',
2142
+ deckName: defaultDeckName,
2143
+ });
2144
+ }
2145
+ }
2146
+ }
2147
+ else if ((manifestDeck || defaultDeck) && !launchDeck) {
1933
2148
  this.sessionBinding.markUnassigned(sessionId);
1934
2149
  if (workspaceRoot) {
1935
2150
  this.sessionBinding.setWorkspace(sessionId, workspaceRoot);
1936
2151
  }
2152
+ if (manifestDeck) {
2153
+ this.sessionBinding.setUnassignedMissingDeckName(sessionId, manifestDeckName);
2154
+ if (defaultUnreadablePath) {
2155
+ this.sessionBinding.setUnassignedDefaultDeckIssue(sessionId, {
2156
+ kind: 'unreadable',
2157
+ path: defaultUnreadablePath,
2158
+ });
2159
+ }
2160
+ }
2161
+ else if (defaultDeckName) {
2162
+ this.sessionBinding.setUnassignedDefaultDeckIssue(sessionId, {
2163
+ kind: 'missing',
2164
+ deckName: defaultDeckName,
2165
+ });
2166
+ }
1937
2167
  }
1938
2168
  else {
1939
2169
  this.getAuditStore()?.append({
@@ -1954,6 +2184,15 @@ class AgentDeckMCPServer {
1954
2184
  if (workspaceRoot) {
1955
2185
  this.sessionBinding.setWorkspace(sessionId, workspaceRoot);
1956
2186
  }
2187
+ // NOT-606: no deck resolved at all, but a default-deck.json exists
2188
+ // that cannot be used — name it instead of behaving as if no default
2189
+ // was ever set. With no default file the plain message is unchanged.
2190
+ if (defaultUnreadablePath) {
2191
+ this.sessionBinding.setUnassignedDefaultDeckIssue(sessionId, {
2192
+ kind: 'unreadable',
2193
+ path: defaultUnreadablePath,
2194
+ });
2195
+ }
1957
2196
  }
1958
2197
  await this.establishTransportSession(req, res, sessionId);
1959
2198
  }
@@ -1989,7 +2228,7 @@ class AgentDeckMCPServer {
1989
2228
  if (this.closedSessionIds.has(staleSessionId)) {
1990
2229
  return false;
1991
2230
  }
1992
- const { launchDeck, manifestDeck, effectiveDeck } = this.resolveHeaderDeck(req);
2231
+ const { launchDeck, manifestDeck, defaultDeck, effectiveDeck } = this.resolveHeaderDeck(req);
1993
2232
  if (!effectiveDeck) {
1994
2233
  return false;
1995
2234
  }
@@ -1998,18 +2237,36 @@ class AgentDeckMCPServer {
1998
2237
  return true;
1999
2238
  }
2000
2239
  const freshSessionId = (0, node_crypto_1.randomUUID)();
2240
+ let recoveredDeck = effectiveDeck;
2001
2241
  try {
2002
2242
  await this.authenticateLaunchDeck(freshSessionId, req, effectiveDeck);
2003
- if (manifestDeck && !launchDeck) {
2243
+ if (manifestDeck && !launchDeck && effectiveDeck === manifestDeck) {
2004
2244
  this.sessionBinding.markUseManifestSession(freshSessionId);
2005
2245
  }
2246
+ else if (defaultDeck && !launchDeck && effectiveDeck === defaultDeck) {
2247
+ this.sessionBinding.markDefaultDeckSession(freshSessionId);
2248
+ }
2006
2249
  }
2007
2250
  catch {
2008
- // Opportunistic: a bind failure falls back to the NOT-101 404 the
2009
- // call site answers — silently, so a retrying host cannot spam one
2010
- // line per request (the 404 path logs first-seen ids already).
2011
- this.sessionBinding.clearSession(freshSessionId);
2012
- return false;
2251
+ // NOT-604: like initialize, a manifest naming a deleted deck falls
2252
+ // through to the user default deck before recovery gives up.
2253
+ const canFallThroughToDefault = manifestDeck && !launchDeck && defaultDeck && defaultDeck !== manifestDeck;
2254
+ if (!canFallThroughToDefault) {
2255
+ // Opportunistic: a bind failure falls back to the NOT-101 404 the
2256
+ // call site answers — silently, so a retrying host cannot spam one
2257
+ // line per request (the 404 path logs first-seen ids already).
2258
+ this.sessionBinding.clearSession(freshSessionId);
2259
+ return false;
2260
+ }
2261
+ try {
2262
+ await this.authenticateLaunchDeck(freshSessionId, req, defaultDeck);
2263
+ this.sessionBinding.markDefaultDeckSession(freshSessionId);
2264
+ recoveredDeck = defaultDeck;
2265
+ }
2266
+ catch {
2267
+ this.sessionBinding.clearSession(freshSessionId);
2268
+ return false;
2269
+ }
2013
2270
  }
2014
2271
  // Adopt a concurrent winner instead of minting a second session.
2015
2272
  if (await this.serveFromRecoveryAlias(req, res, staleSessionId)) {
@@ -2061,7 +2318,7 @@ class AgentDeckMCPServer {
2061
2318
  // One line per recovered session id, not per request — the host keeps
2062
2319
  // sending the stale id on every later call.
2063
2320
  console.warn(`[agent-deck] MCP session ${staleSessionId} recovered from headers as ${freshSessionId} ` +
2064
- `(deck ${effectiveDeck}); the client never re-initialized after the restart.`);
2321
+ `(deck ${recoveredDeck}); the client never re-initialized after the restart.`);
2065
2322
  // NOT-513: adopt the host-side session id before the first live-display
2066
2323
  // register, so the entry carries it from the start.
2067
2324
  this.adoptHostSessionId(freshSessionId, req);