dsh-permission-plan 0.2.1 → 0.2.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.
- package/index.mjs +55 -10
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -279,13 +279,35 @@ const APPROVAL_TOOL_BY_CLUSTER = {
|
|
|
279
279
|
destructive: 'pwsh'
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Resolve a host service both ways: `ctx.get(name)` returns only providers whose fiber is already
|
|
284
|
+
* active (0.2.2), while a plain property read needs a declared `inject`. Reading both lets the
|
|
285
|
+
* plugin work no matter which of the two the apply-time context happens to expose.
|
|
286
|
+
*/
|
|
287
|
+
function serviceOf(ctx, name) {
|
|
288
|
+
try {
|
|
289
|
+
if (typeof ctx?.get === 'function') {
|
|
290
|
+
const live = ctx.get(name)
|
|
291
|
+
if (live !== undefined && live !== null) return live
|
|
292
|
+
}
|
|
293
|
+
} catch {
|
|
294
|
+
// Fall through to the property read.
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
const own = ctx?.[name]
|
|
298
|
+
return own === null ? undefined : own
|
|
299
|
+
} catch {
|
|
300
|
+
return undefined
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
282
304
|
/**
|
|
283
305
|
* Raise the host's own approval card for one permission instead of a batch dialog.
|
|
284
306
|
* Returns undefined when the host has no approval service, so the caller can fall back.
|
|
285
307
|
*/
|
|
286
308
|
async function requestNativeApproval(ctx, agent, cluster, item, detailLines) {
|
|
287
309
|
if (agent === undefined) return undefined
|
|
288
|
-
const approval =
|
|
310
|
+
const approval = serviceOf(ctx, 'approval')
|
|
289
311
|
if (approval === undefined || typeof approval.request !== 'function') return undefined
|
|
290
312
|
const reason = [item, ...detailLines].filter((line) => typeof line === 'string' && line !== '').join('\n')
|
|
291
313
|
try {
|
|
@@ -732,8 +754,19 @@ function sendSound(response, name) {
|
|
|
732
754
|
export function apply(ctx) {
|
|
733
755
|
// ---------------------------------------------------------------- own approval card routes
|
|
734
756
|
// The browser half polls `pending` (which doubles as a heartbeat) and answers with `answer`.
|
|
757
|
+
// `webServer` may still be starting when this plugin applies, and `ctx.get()` only returns
|
|
758
|
+
// already-active providers, so a missing server is queued and installed by a child fiber below.
|
|
759
|
+
const pendingRegistrations = []
|
|
735
760
|
try {
|
|
736
|
-
|
|
761
|
+
let web = serviceOf(ctx, 'webServer')
|
|
762
|
+
if (web === undefined || web === null || typeof web.register !== 'function') {
|
|
763
|
+
web = {
|
|
764
|
+
register: (options) => {
|
|
765
|
+
pendingRegistrations.push({ options, label: options?.path ?? 'permission-plan route' })
|
|
766
|
+
return () => {}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
737
770
|
if (web !== undefined && web !== null && typeof web.register === 'function') {
|
|
738
771
|
ctx.effect?.(
|
|
739
772
|
() =>
|
|
@@ -925,6 +958,19 @@ setTimeout(() => {
|
|
|
925
958
|
} catch {
|
|
926
959
|
// Without the web server the native approval flow still works.
|
|
927
960
|
}
|
|
961
|
+
if (pendingRegistrations.length > 0) {
|
|
962
|
+
// Snapshot before handing the table to a child fiber: that fiber may start after this call.
|
|
963
|
+
const queued = pendingRegistrations.splice(0)
|
|
964
|
+
const install = (child) => {
|
|
965
|
+
const server = serviceOf(child, 'webServer')
|
|
966
|
+
if (server === undefined || server === null || typeof server.register !== 'function') return
|
|
967
|
+
for (const { options, label } of queued) {
|
|
968
|
+
child.effect(() => server.register(options), `permission-plan: ${label}`)
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
if (typeof ctx.inject === 'function') ctx.inject(['webServer'], install)
|
|
972
|
+
else install(ctx)
|
|
973
|
+
}
|
|
928
974
|
|
|
929
975
|
const current = () => {
|
|
930
976
|
const store = loadStore()
|
|
@@ -1003,13 +1049,7 @@ setTimeout(() => {
|
|
|
1003
1049
|
)
|
|
1004
1050
|
|
|
1005
1051
|
// ---------------------------------------------------------------- tools
|
|
1006
|
-
const tools = (
|
|
1007
|
-
try {
|
|
1008
|
-
return typeof ctx.get === 'function' ? ctx.get('tools') : ctx.tools
|
|
1009
|
-
} catch {
|
|
1010
|
-
return undefined
|
|
1011
|
-
}
|
|
1012
|
-
})()
|
|
1052
|
+
const tools = serviceOf(ctx, 'tools')
|
|
1013
1053
|
if (tools === undefined || tools === null || typeof tools.register !== 'function') return
|
|
1014
1054
|
|
|
1015
1055
|
const disposers = []
|
|
@@ -1128,7 +1168,7 @@ setTimeout(() => {
|
|
|
1128
1168
|
|
|
1129
1169
|
let approved = false
|
|
1130
1170
|
try {
|
|
1131
|
-
const questions =
|
|
1171
|
+
const questions = serviceOf(ctx, 'userQuestions')
|
|
1132
1172
|
if (questions !== undefined && typeof questions.ask === 'function') {
|
|
1133
1173
|
const answer = await questions.ask({
|
|
1134
1174
|
...(agent === undefined ? {} : { agent }),
|
|
@@ -1393,4 +1433,9 @@ setTimeout(() => {
|
|
|
1393
1433
|
|
|
1394
1434
|
export const name = 'dsh-permission-plan'
|
|
1395
1435
|
|
|
1436
|
+
// Declaring the dependency makes Cordis apply this plugin only once the tool registry is active,
|
|
1437
|
+
// so `ctx.get('tools')`/`ctx.tools` can no longer come back undefined on a cold boot. `webServer`
|
|
1438
|
+
// stays optional on purpose (headless sessions have none) and is handled inside `apply`.
|
|
1439
|
+
export const inject = ['tools']
|
|
1440
|
+
|
|
1396
1441
|
export { classify, extractKeywords, clustersOf, matchedKeywords, CLUSTERS, WEAK_KEYWORDS, DANGER_PATTERN }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-permission-plan",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "One approval dialog for everything a task will need, then keyword memory instead of per-command prompts. Splits the batch pre-approval out of dsh-mod-build-auto-approve and merges it with generic keyword learning.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|