Commit 2d8caad
fix(plugin-host-hooks): batch review-comment fixes round 2
Addresses 12 Copilot review threads on PR #72287 in one consolidated commit.
- host-hook-state.ts: short-circuit drainPluginNextTurnInjections before
updateSessionStore when no injections are queued; add Array.isArray
guards in both enqueue and drain so a malformed/hand-edited persisted
value can't crash prompt-build for the whole session.
- host-hooks.ts: drop the redundant local isPluginJsonValue import that
was already covered by the re-export.
- trusted-tool-policy.ts: block:false is no longer terminal — only
block:true short-circuits the policy chain (matches the regular
before_tool_call hook pipeline). Normalize block:true decisions to
always carry a deterministic blockReason.
- operator-scopes.ts + registry.ts: validate registerControlUiDescriptor's
requiredScopes against the known OperatorScope set so untyped/JS plugins
cannot project arbitrary strings to clients as if they were valid
operator scopes.
- registry.ts: scope tool-metadata uniqueness to (pluginId + toolName)
instead of global toolName uniqueness, so different plugins owning
different tools that happen to share a name can each register metadata.
- tools-effective-inventory.ts + tools-catalog.ts: project tool metadata
by `${pluginId} ${toolName}` keyed against the tool's owning pluginId,
so plugin-X cannot spoof/override the displayName/description/risk/tags
of plugin-Y's tool (or a core tool).
- host-hook-runtime.ts: setPluginRunContext now requires explicit
unset:true to delete (matches sessions.pluginPatch semantics);
clearPluginRunContext normalizes the namespace through the same trim()
used by set/get so callers passing whitespace don't leave orphan
entries.
- attempt.prompt-helpers.ts + run.ts: cache drained next-turn injections
by hookCtx.runId so retries within the same run reuse the first-attempt
drain (the destructive consume would otherwise return [] on retry).
FIFO-bounded at 256 entries; cleared explicitly from the run-scoped
finally in run.ts via forgetPromptBuildDrainCacheForRun.
Test coverage: 3 new attempt.prompt-helpers.test.ts cases lock in the
runId cache behavior. Existing 2,084 plugin + contracts-plugin tests
still pass.1 parent d7d9e47 commit 2d8caad
11 files changed
Lines changed: 250 additions & 18 deletions
File tree
- src
- agents
- pi-embedded-runner
- run
- gateway
- server-methods
- plugins
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
2432 | 2433 | | |
2433 | 2434 | | |
2434 | 2435 | | |
| 2436 | + | |
2435 | 2437 | | |
2436 | 2438 | | |
2437 | 2439 | | |
| |||
Lines changed: 88 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
| 17 | + | |
13 | 18 | | |
14 | 19 | | |
| 20 | + | |
15 | 21 | | |
16 | 22 | | |
| 23 | + | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
| |||
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
Lines changed: 47 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
57 | 91 | | |
58 | 92 | | |
59 | 93 | | |
60 | 94 | | |
61 | 95 | | |
62 | 96 | | |
63 | 97 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
67 | 111 | | |
68 | 112 | | |
69 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |