@dsh-ray/assistant-verifier 0.0.1-seed.0 → 0.2.1

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 (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +285 -1
  3. package/cordis.patch.yml +10 -0
  4. package/lib/config.d.ts +47 -0
  5. package/lib/config.d.ts.map +1 -0
  6. package/lib/config.js +82 -0
  7. package/lib/config.js.map +1 -0
  8. package/lib/creation-review-native.d.ts +30 -0
  9. package/lib/creation-review-native.d.ts.map +1 -0
  10. package/lib/creation-review-native.js +137 -0
  11. package/lib/creation-review-native.js.map +1 -0
  12. package/lib/creation-review-store.d.ts +108 -0
  13. package/lib/creation-review-store.d.ts.map +1 -0
  14. package/lib/creation-review-store.js +715 -0
  15. package/lib/creation-review-store.js.map +1 -0
  16. package/lib/creation-review.d.ts +317 -0
  17. package/lib/creation-review.d.ts.map +1 -0
  18. package/lib/creation-review.js +842 -0
  19. package/lib/creation-review.js.map +1 -0
  20. package/lib/drivers.d.ts +153 -0
  21. package/lib/drivers.d.ts.map +1 -0
  22. package/lib/drivers.js +825 -0
  23. package/lib/drivers.js.map +1 -0
  24. package/lib/host.d.ts +93 -0
  25. package/lib/host.d.ts.map +1 -0
  26. package/lib/host.js +2 -0
  27. package/lib/host.js.map +1 -0
  28. package/lib/index.d.ts +26 -0
  29. package/lib/index.d.ts.map +1 -0
  30. package/lib/index.js +18 -0
  31. package/lib/index.js.map +1 -0
  32. package/lib/linux-behavior-assets.d.ts +19 -0
  33. package/lib/linux-behavior-assets.d.ts.map +1 -0
  34. package/lib/linux-behavior-assets.js +89 -0
  35. package/lib/linux-behavior-assets.js.map +1 -0
  36. package/lib/linux-behavior-runner.d.ts +10 -0
  37. package/lib/linux-behavior-runner.d.ts.map +1 -0
  38. package/lib/linux-behavior-runner.js +69 -0
  39. package/lib/linux-behavior-runner.js.map +1 -0
  40. package/lib/linux-behavior-runtime.d.ts +67 -0
  41. package/lib/linux-behavior-runtime.d.ts.map +1 -0
  42. package/lib/linux-behavior-runtime.js +500 -0
  43. package/lib/linux-behavior-runtime.js.map +1 -0
  44. package/lib/memory-review-native.d.ts +50 -0
  45. package/lib/memory-review-native.d.ts.map +1 -0
  46. package/lib/memory-review-native.js +166 -0
  47. package/lib/memory-review-native.js.map +1 -0
  48. package/lib/memory-review.d.ts +50 -0
  49. package/lib/memory-review.d.ts.map +1 -0
  50. package/lib/memory-review.js +363 -0
  51. package/lib/memory-review.js.map +1 -0
  52. package/lib/native-behavior-artifact.d.ts +9 -0
  53. package/lib/native-behavior-artifact.d.ts.map +1 -0
  54. package/lib/native-behavior-artifact.js +144 -0
  55. package/lib/native-behavior-artifact.js.map +1 -0
  56. package/lib/native-behavior-worker.d.ts +3 -0
  57. package/lib/native-behavior-worker.d.ts.map +1 -0
  58. package/lib/native-behavior-worker.js +453 -0
  59. package/lib/native-behavior-worker.js.map +1 -0
  60. package/lib/plugin-behavior-config.d.ts +34 -0
  61. package/lib/plugin-behavior-config.d.ts.map +1 -0
  62. package/lib/plugin-behavior-config.js +170 -0
  63. package/lib/plugin-behavior-config.js.map +1 -0
  64. package/lib/plugin-behavior-runner.d.ts +57 -0
  65. package/lib/plugin-behavior-runner.d.ts.map +1 -0
  66. package/lib/plugin-behavior-runner.js +910 -0
  67. package/lib/plugin-behavior-runner.js.map +1 -0
  68. package/lib/review-authority-lineage.d.ts +109 -0
  69. package/lib/review-authority-lineage.d.ts.map +1 -0
  70. package/lib/review-authority-lineage.js +135 -0
  71. package/lib/review-authority-lineage.js.map +1 -0
  72. package/lib/review-maintenance.d.ts +20 -0
  73. package/lib/review-maintenance.d.ts.map +1 -0
  74. package/lib/review-maintenance.js +24 -0
  75. package/lib/review-maintenance.js.map +1 -0
  76. package/lib/revision-regression-review.d.ts +41 -0
  77. package/lib/revision-regression-review.d.ts.map +1 -0
  78. package/lib/revision-regression-review.js +379 -0
  79. package/lib/revision-regression-review.js.map +1 -0
  80. package/lib/revision-review.d.ts +242 -0
  81. package/lib/revision-review.d.ts.map +1 -0
  82. package/lib/revision-review.js +600 -0
  83. package/lib/revision-review.js.map +1 -0
  84. package/lib/service.d.ts +138 -0
  85. package/lib/service.d.ts.map +1 -0
  86. package/lib/service.js +878 -0
  87. package/lib/service.js.map +1 -0
  88. package/lib/source-review-git.d.ts +32 -0
  89. package/lib/source-review-git.d.ts.map +1 -0
  90. package/lib/source-review-git.js +241 -0
  91. package/lib/source-review-git.js.map +1 -0
  92. package/lib/source-review-native.d.ts +27 -0
  93. package/lib/source-review-native.d.ts.map +1 -0
  94. package/lib/source-review-native.js +149 -0
  95. package/lib/source-review-native.js.map +1 -0
  96. package/lib/source-review-store.d.ts +44 -0
  97. package/lib/source-review-store.d.ts.map +1 -0
  98. package/lib/source-review-store.js +212 -0
  99. package/lib/source-review-store.js.map +1 -0
  100. package/lib/source-review.d.ts +86 -0
  101. package/lib/source-review.d.ts.map +1 -0
  102. package/lib/source-review.js +255 -0
  103. package/lib/source-review.js.map +1 -0
  104. package/lib/store.d.ts +84 -0
  105. package/lib/store.d.ts.map +1 -0
  106. package/lib/store.js +386 -0
  107. package/lib/store.js.map +1 -0
  108. package/lib/version.d.ts +2 -0
  109. package/lib/version.d.ts.map +1 -0
  110. package/lib/version.js +2 -0
  111. package/lib/version.js.map +1 -0
  112. package/package.json +137 -4
  113. package/runtime/plugin-observer-launcher.c +246 -0
@@ -0,0 +1,453 @@
1
+ /** Fixed source passed to the native Seatbelt runner. Candidate files are staged read-only by the trusted runner. */
2
+ export const NATIVE_BEHAVIOR_SOURCE = String.raw `
3
+ import { createHash } from 'node:crypto'
4
+ import { createRequire, registerHooks } from 'node:module'
5
+ import { existsSync, readdirSync, readFileSync, writeSync } from 'node:fs'
6
+ import { join } from 'node:path'
7
+ import { pathToFileURL } from 'node:url'
8
+
9
+ const stringify = JSON.stringify.bind(JSON)
10
+ const createNull = Object.create.bind(Object)
11
+ const assign = Object.assign.bind(Object)
12
+ const digest = value => createHash('sha256').update(value).digest('hex')
13
+ const safeTool = /^[a-z][a-z0-9_-]{0,95}$/
14
+ const safeEnum = /^[A-Za-z0-9_.:-]{1,64}$/
15
+ const safeMethod = /^[A-Za-z][A-Za-z0-9_]{0,63}$/
16
+ const kinds = new Set(['tool', 'service', 'channel', 'ui'])
17
+ const skipMethods = new Set(['constructor', 'start', 'stop', 'dispose', 'init'])
18
+ const cordisOrig = Symbol.for('cordis.original')
19
+ const unwrap = v => (v && typeof v === 'object' ? v[cordisOrig] : undefined) ?? v
20
+ const badHealth = h => !h || typeof h !== 'object' || h.ready === false || h.ok === false || h.status === 'error' || h.status === 'unhealthy'
21
+ const stripComment = line => {
22
+ let q = ''
23
+ for (let i = 0; i < line.length; i += 1) {
24
+ const c = line[i]
25
+ if (q) { if (c === q && line[i - 1] !== '\\') q = '' }
26
+ else if (c === "'" || c === '"') q = c
27
+ else if (c === '#' && (i === 0 || /\s/.test(line[i - 1]))) return line.slice(0, i)
28
+ }
29
+ return line
30
+ }
31
+ const parseScalar = raw => {
32
+ const s = stripComment(raw).trim()
33
+ if (!s || s.startsWith('!!js') || s.startsWith('#')) return undefined
34
+ if (s === 'true') return true
35
+ if (s === 'false') return false
36
+ if (s === 'null' || s === '~') return null
37
+ if (s === '[]') return []
38
+ if (s === '{}') return createNull(null)
39
+ if (/^-?\d+(?:\.\d+)?$/.test(s)) return Number(s)
40
+ if ((s.startsWith("'") && s.endsWith("'")) || (s.startsWith('"') && s.endsWith('"'))) return s.slice(1, -1)
41
+ return s
42
+ }
43
+ const isNonEmptyDecl = raw => {
44
+ const val = parseScalar(raw)
45
+ if (val === undefined || val === false || val === null || val === '') return false
46
+ if (Array.isArray(val)) return val.length > 0
47
+ if (typeof val === 'object') return Object.keys(val).length > 0
48
+ return true
49
+ }
50
+ function parsePatchMeta(rawYaml) {
51
+ const inject = []
52
+ const config = createNull(null)
53
+ let inInject = false, injectIndent = -1, inConfig = false, configIndent = -1, configStack = []
54
+ let hasEntry = false, hasUiDecl = false, hasChannelDecl = false, hasServiceDecl = false, pendingDecl = null
55
+ for (const rawLine of rawYaml.split(/\r?\n/)) {
56
+ const line = stripComment(rawLine)
57
+ if (!line.trim()) continue
58
+ const indent = line.length - line.trimStart().length
59
+ const trimmed = line.trim()
60
+ if (pendingDecl) {
61
+ if (indent > pendingDecl.indent) {
62
+ const kv = /^(?:-\s+)?[A-Za-z0-9_-]+\s*:\s*(.*)$/.exec(trimmed)
63
+ if (!kv || !kv[1].trim() || isNonEmptyDecl(kv[1])) {
64
+ if (pendingDecl.kind === 'ui') hasUiDecl = true
65
+ else if (pendingDecl.kind === 'channel') hasChannelDecl = true
66
+ else hasServiceDecl = true
67
+ pendingDecl = null
68
+ }
69
+ } else pendingDecl = null
70
+ }
71
+ if (/^-+\s*insert\s*:/.test(trimmed) || /^name\s*:/.test(trimmed)) hasEntry = true
72
+ if (inInject) {
73
+ if (indent > injectIndent && trimmed.startsWith('- ')) {
74
+ const val = parseScalar(trimmed.slice(2))
75
+ if (typeof val === 'string' && val) inject.push(val)
76
+ continue
77
+ }
78
+ if (indent <= injectIndent && !trimmed.startsWith('- ')) inInject = false
79
+ }
80
+ if (inConfig) {
81
+ if (indent <= configIndent) { inConfig = false; configStack = [] }
82
+ else {
83
+ while (configStack.length > 1 && indent <= configStack[configStack.length - 1].indent) configStack.pop()
84
+ const match = /^([A-Za-z0-9_-]+)\s*:\s*(.*)$/.exec(trimmed)
85
+ if (match && match[1] !== '__proto__' && match[1] !== 'constructor' && match[1] !== 'prototype') {
86
+ const rest = match[2].trim(), targetObj = configStack[configStack.length - 1].obj
87
+ if (!rest) {
88
+ const child = createNull(null)
89
+ targetObj[match[1]] = child
90
+ configStack.push({ obj: child, indent })
91
+ } else {
92
+ const val = parseScalar(rest)
93
+ if (val !== undefined) targetObj[match[1]] = val
94
+ }
95
+ }
96
+ continue
97
+ }
98
+ }
99
+ const injectMatch = /^(?:-\s+)?inject\s*:\s*(.*)$/.exec(trimmed)
100
+ if (injectMatch) {
101
+ const rest = injectMatch[1].trim()
102
+ if (rest.startsWith('[') && rest.endsWith(']')) {
103
+ for (const item of rest.slice(1, -1).split(',')) {
104
+ const val = parseScalar(item)
105
+ if (typeof val === 'string' && val) inject.push(val)
106
+ }
107
+ } else if (!rest) { inInject = true; injectIndent = indent }
108
+ continue
109
+ }
110
+ const configMatch = /^(?:-\s+)?config\s*:\s*(.*)$/.exec(trimmed)
111
+ if (configMatch) {
112
+ if (!configMatch[1].trim()) { inConfig = true; configIndent = indent; configStack = [{ obj: config, indent }] }
113
+ continue
114
+ }
115
+ const declMatch = /^(?:-\s+)?(ui|routes|sections|settings|channel|services|provides)\s*:\s*(.*)$/.exec(trimmed)
116
+ if (declMatch) {
117
+ const key = declMatch[1], rest = declMatch[2].trim()
118
+ const kind = key === 'channel' ? 'channel' : (key === 'services' || key === 'provides') ? 'service' : 'ui'
119
+ if (rest) {
120
+ if (isNonEmptyDecl(rest)) {
121
+ if (kind === 'ui') hasUiDecl = true
122
+ else if (kind === 'channel') hasChannelDecl = true
123
+ else hasServiceDecl = true
124
+ }
125
+ } else pendingDecl = { kind, indent }
126
+ }
127
+ }
128
+ return { hasEntry, inject, config, hasUiDecl, hasChannelDecl, hasServiceDecl }
129
+ }
130
+ const hasNonEmptyObj = v => Boolean(v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length > 0)
131
+ function readPackageMeta(pkgDir) {
132
+ const manifest = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8'))
133
+ const dsh = manifest.dsh && typeof manifest.dsh === 'object' ? manifest.dsh : {}
134
+ const clientExp = manifest.exports && typeof manifest.exports === 'object' ? manifest.exports['./client'] : undefined
135
+ const clientPath = typeof clientExp === 'string' ? clientExp
136
+ : clientExp && typeof clientExp === 'object' ? (clientExp.default ?? clientExp.import) : undefined
137
+ let hasClientExport = false, clientExportMissing = false
138
+ if (typeof clientPath === 'string') {
139
+ if (/^\.\/lib\/[A-Za-z0-9._/-]+\.js$/.test(clientPath) && !clientPath.split('/').includes('..')
140
+ && existsSync(join(pkgDir, clientPath))) hasClientExport = true
141
+ else clientExportMissing = true
142
+ }
143
+ const pkg = {
144
+ dshKind: kinds.has(dsh.kind) ? dsh.kind : undefined,
145
+ dshClient: hasNonEmptyObj(dsh.client),
146
+ dshUi: hasNonEmptyObj(dsh.ui),
147
+ dshChannel: hasNonEmptyObj(dsh.channel),
148
+ hasClientExport, clientExportMissing,
149
+ }
150
+ let patch = { hasEntry: false, inject: [], config: createNull(null), hasUiDecl: false, hasChannelDecl: false, hasServiceDecl: false }
151
+ const patchPath = join(pkgDir, 'cordis.patch.yml')
152
+ if (existsSync(patchPath)) {
153
+ const rawPatch = readFileSync(patchPath, 'utf8')
154
+ if (Buffer.byteLength(rawPatch) <= 65536) patch = parsePatchMeta(rawPatch)
155
+ }
156
+ return { pkg, patch }
157
+ }
158
+ const listMethods = val => {
159
+ if (!val || typeof val !== 'object') return []
160
+ const seen = new Set()
161
+ for (let obj = val; obj && obj !== Object.prototype; obj = Object.getPrototypeOf(obj)) {
162
+ for (const k of Object.getOwnPropertyNames(obj)) {
163
+ if (!skipMethods.has(k) && !k.startsWith('_') && safeMethod.test(k) && safeEnum.test(k) && typeof val[k] === 'function') seen.add(k)
164
+ }
165
+ }
166
+ return [...seen].slice(0, 16)
167
+ }
168
+ const checkAdapter = a => Boolean(a && typeof a === 'object' && typeof a.channel === 'string' && a.channel
169
+ && typeof a.account === 'string' && a.account && a.capabilities && typeof a.capabilities === 'object'
170
+ && typeof a.start === 'function' && typeof a.send === 'function')
171
+ const hasNonEmpty = (v, seen = new Set()) => {
172
+ if (typeof v === 'function') return true
173
+ if (!v || typeof v !== 'object' || seen.has(v)) return false
174
+ seen.add(v)
175
+ const ok = Array.isArray(v)
176
+ ? v.some(x => typeof x === 'function' || (x !== undefined && x !== null && x !== false && x !== '' && (typeof x !== 'object' || hasNonEmpty(x, seen))))
177
+ : Object.values(v).some(x => typeof x === 'function' || (x !== undefined && x !== null && x !== false && x !== '' && (typeof x !== 'object' || hasNonEmpty(x, seen))))
178
+ seen.delete(v)
179
+ return ok
180
+ }
181
+ const validTypertObj = v => Boolean(v && typeof v === 'object' && !Array.isArray(v)
182
+ && typeof v.package === 'string' && v.package.trim().length > 0
183
+ && (hasNonEmpty(v.schemas) || hasNonEmpty(v.invocations) || hasNonEmpty(v.descriptors)
184
+ || hasNonEmpty(v.routes) || hasNonEmpty(v.sections) || hasNonEmpty(v.settings) || hasNonEmpty(v.model)))
185
+ const validUiObj = v => typeof v === 'function' || Boolean(v && typeof v === 'object' && !Array.isArray(v)
186
+ && (hasNonEmpty(v.routes) || hasNonEmpty(v.sections) || hasNonEmpty(v.settings)
187
+ || validTypertObj(v) || validTypertObj(v.TYPERT)
188
+ || typeof v.render === 'function' || typeof v.mount === 'function' || typeof v.component === 'function'))
189
+ let frame
190
+ let nonce
191
+ let artifactSha256
192
+ let operationDigest
193
+ let fiber
194
+ let ctx
195
+ let disposed = true
196
+ let providedNames = []
197
+ const channelAdapters = new Set()
198
+ const typertContributions = new Set()
199
+ try {
200
+ const chunks = []
201
+ let bytes = 0
202
+ for await (const chunk of process.stdin) {
203
+ bytes += chunk.length
204
+ if (bytes > 65536) throw new Error('candidate-input-too-large')
205
+ chunks.push(chunk)
206
+ }
207
+ const request = JSON.parse(Buffer.concat(chunks).toString('utf8'))
208
+ if (!request || request.schemaVersion !== 1 || typeof request.nonce !== 'string'
209
+ || !/^[a-f0-9]{64}$/.test(request.nonce) || typeof request.artifactSha256 !== 'string'
210
+ || !/^[a-f0-9]{64}$/.test(request.artifactSha256) || typeof request.entry !== 'string'
211
+ || !/^package\/lib\/[A-Za-z0-9._/-]+\.js$/.test(request.entry)
212
+ || request.entry.split('/').includes('..') || typeof request.modulesPath !== 'string'
213
+ || !request.modulesPath.startsWith('/')
214
+ || (request.pluginKind !== undefined && !kinds.has(request.pluginKind))
215
+ || !request.operation || !['discover', 'invoke'].includes(request.operation.kind))
216
+ throw new Error('candidate-input-invalid')
217
+ nonce = request.nonce
218
+ artifactSha256 = request.artifactSha256
219
+ operationDigest = digest(stringify(request.operation))
220
+ const pkgDir = join(process.cwd(), 'package')
221
+ const { pkg, patch } = readPackageMeta(pkgDir)
222
+ const resolver = createRequire(pathToFileURL(join(request.modulesPath, '__native_resolver__.cjs')))
223
+ const approved = new Map()
224
+ for (const entry of readdirSync(request.modulesPath)) {
225
+ if (entry.startsWith('.')) continue
226
+ const names = entry.startsWith('@')
227
+ ? readdirSync(join(request.modulesPath, entry)).map(name => entry + '/' + name) : [entry]
228
+ for (const name of names) {
229
+ try { approved.set(name, resolver.resolve(name)) } catch { /* package has no runtime entry */ }
230
+ }
231
+ }
232
+ const candidateRoot = pathToFileURL(pkgDir + '/').href
233
+ registerHooks({ resolve(specifier, context, nextResolve) {
234
+ if (context.parentURL?.startsWith(candidateRoot)
235
+ && !specifier.startsWith('node:') && !specifier.startsWith('.')
236
+ && !specifier.startsWith('/') && !specifier.startsWith('file:')) {
237
+ const target = approved.get(specifier)
238
+ if (!target) throw new Error('candidate-bare-import-not-approved')
239
+ return nextResolve(pathToFileURL(target).href, context)
240
+ }
241
+ return nextResolve(specifier, context)
242
+ } })
243
+ const { Context, Service } = await import(pathToFileURL(approved.get('@deepseek-ai/cordis')).href)
244
+ class TypertSeam extends Service {
245
+ constructor(c) { super(c, 'typert') }
246
+ register(contribution) {
247
+ if (!validTypertObj(contribution)) throw new Error('invalid-ui-contribution')
248
+ return this.ctx.effect(() => {
249
+ typertContributions.add(contribution)
250
+ return () => { typertContributions.delete(contribution) }
251
+ }, 'typert.register()')
252
+ }
253
+ }
254
+ const { default: SystemPrompt } = await import(pathToFileURL(approved.get('@deepseek-ai/dsh-system-prompt')).href)
255
+ const { default: ToolRuntime, projectToolSchema } = await import(pathToFileURL(approved.get('@deepseek-ai/dsh-tools')).href)
256
+ const { ToolExecutionPipeline, executeToolBatch } = await import(pathToFileURL(resolver.resolve('@deepseek-ai/dsh-tools/pipeline')).href)
257
+ ctx = new Context()
258
+ await ctx.plugin(SystemPrompt, { includeHarnessIdentity: false, includeRuntimeContext: false, personaPrefix: '' })
259
+ await ctx.plugin(ToolRuntime)
260
+ const pipeline = new ToolExecutionPipeline(ctx)
261
+ ctx.tools.setExecutor({
262
+ describe: tools => ({ schemas: tools.map(definition => projectToolSchema(definition, false)) }),
263
+ execute: input => executeToolBatch(input, pipeline, () => 1),
264
+ })
265
+ const module = await import(pathToFileURL(join(process.cwd(), request.entry)).href)
266
+ const target = module.default ?? module
267
+ const declaredInject = [...new Set([
268
+ ...(Array.isArray(target?.inject) ? target.inject : []),
269
+ ...(Array.isArray(module?.inject) ? module.inject : []),
270
+ ...(Array.isArray(patch.inject) ? patch.inject : []),
271
+ ].filter(v => typeof v === 'string'))]
272
+ if (request.pluginKind === 'channel' || declaredInject.includes('assistantDelivery') || pkg.dshChannel || patch.hasChannelDecl) {
273
+ ctx.provide('assistantDelivery', {
274
+ registerAdapter(adapter) {
275
+ if (!checkAdapter(adapter)) throw new Error('invalid-channel-adapter')
276
+ channelAdapters.add(adapter)
277
+ return async () => { channelAdapters.delete(adapter) }
278
+ },
279
+ health: () => ({ ready: true }),
280
+ })
281
+ }
282
+ if (request.pluginKind === 'ui' || declaredInject.includes('typert') || pkg.dshClient || pkg.dshUi || patch.hasUiDecl) {
283
+ new TypertSeam(ctx)
284
+ }
285
+ const hasPatchCfg = patch.config && Object.keys(patch.config).length > 0
286
+ const pluginCfg = hasPatchCfg ? patch.config : (typeof target?.Config === 'function' || typeof module?.Config === 'function' ? {} : undefined)
287
+ fiber = pluginCfg !== undefined ? ctx.plugin(target, pluginCfg) : ctx.plugin(target)
288
+ let timer
289
+ try {
290
+ await Promise.race([fiber, new Promise((_, reject) => {
291
+ timer = setTimeout(() => reject(new Error('plugin-activation-timeout')), 5000)
292
+ })])
293
+ } finally { clearTimeout(timer) }
294
+ await new Promise(resolve => setImmediate(resolve))
295
+ if (fiber.state !== 2) throw new Error('plugin-fiber-not-active')
296
+ const toolSchemas = (await ctx.systemPrompt.assemble({})).tools ?? []
297
+ const provisions = [...(fiber.provisions ?? [])]
298
+ const uiExports = Boolean(validTypertObj(module.TYPERT) || validTypertObj(module.TYPERT_REMOTE)
299
+ || hasNonEmpty(module.routes) || hasNonEmpty(module.sections) || hasNonEmpty(module.settings) || validUiObj(module.ui)
300
+ || (target && typeof target === 'object' && (validTypertObj(target.TYPERT) || validTypertObj(target.TYPERT_REMOTE)
301
+ || hasNonEmpty(target.routes) || hasNonEmpty(target.sections) || hasNonEmpty(target.settings) || validUiObj(target.ui))))
302
+ const channelExports = Boolean(module.adapter || module.channel || (target && typeof target === 'object' && (target.adapter || target.channel)))
303
+ const channelProvisions = provisions.filter(p => checkAdapter(p.value))
304
+ const isChannelProvision = channelProvisions.length > 0
305
+ let effectiveKind = request.pluginKind
306
+ if (!effectiveKind) {
307
+ if (Array.isArray(toolSchemas) && toolSchemas.length >= 1) effectiveKind = 'tool'
308
+ else if (typertContributions.size > 0 || pkg.hasClientExport || pkg.clientExportMissing || uiExports) effectiveKind = 'ui'
309
+ else if (channelAdapters.size > 0 || pkg.dshChannel || patch.hasChannelDecl || declaredInject.includes('assistantDelivery') || channelExports || isChannelProvision) effectiveKind = 'channel'
310
+ else if (provisions.length > 0 || pkg.dshKind === 'service' || patch.hasServiceDecl || (typeof (target?.apply ?? target) === 'function' && ((fiber._disposables?.length ?? 0) > 0 || patch.hasEntry))) effectiveKind = 'service'
311
+ else throw new Error('invalid-tool-schemas')
312
+ }
313
+ providedNames = provisions.map(p => p.name)
314
+ let schemas = []
315
+ const toolNames = new Set()
316
+ for (const s of Array.isArray(toolSchemas) ? toolSchemas : []) {
317
+ if (!s || !safeTool.test(s.name) || toolNames.has(s.name)) throw new Error('invalid-tool-schemas')
318
+ toolNames.add(s.name)
319
+ }
320
+ let invokeNonTool
321
+ if (effectiveKind === 'tool') {
322
+ if (!Array.isArray(toolSchemas) || toolSchemas.length < 1 || toolSchemas.length > 64) throw new Error('invalid-tool-schemas')
323
+ schemas = toolSchemas
324
+ } else if (effectiveKind === 'service') {
325
+ if (provisions.length < 1 && !((fiber._disposables?.length ?? 0) >= 1 && typeof (target?.apply ?? target) === 'function')) throw new Error('invalid-service-plugin')
326
+ const svcMap = new Map(), svcMethods = new Map(), allMethods = new Set()
327
+ for (const p of provisions) {
328
+ if (unwrap(ctx.get(p.name)) !== p.value || (typeof p.check === 'function' && p.check() === false)) throw new Error('service-provision-invalid')
329
+ if (typeof p.value?.health === 'function' && badHealth(await p.value.health())) throw new Error('service-health-failed')
330
+ svcMap.set(p.name, p)
331
+ if (safeEnum.test(p.name)) {
332
+ const ms = listMethods(p.value)
333
+ if (ms.length > 0) { svcMethods.set(p.name, new Set(ms)); for (const m of ms) allMethods.add(m) }
334
+ }
335
+ }
336
+ schemas.push({ name: 'service_lifecycle_probe', parameters: { type: 'object', properties: {
337
+ check: { type: 'string', enum: ['status', 'health', 'provisions'] }, service: { type: 'string' },
338
+ }, additionalProperties: false } })
339
+ const svcNames = [...svcMethods.keys()].slice(0, 16), mNames = [...allMethods].slice(0, 16)
340
+ if (svcNames.length > 0 && mNames.length > 0) {
341
+ schemas.push({ name: 'service_method_probe', parameters: { type: 'object', properties: {
342
+ service: { type: 'string', enum: svcNames }, method: { type: 'string', enum: mNames }, input: { type: 'object', additionalProperties: true },
343
+ }, required: ['service', 'method'], additionalProperties: false } })
344
+ }
345
+ for (const s of toolSchemas) if (schemas.length < 64 && !schemas.some(x => x.name === s.name)) schemas.push(s)
346
+ invokeNonTool = async call => {
347
+ if (call.toolName === 'service_lifecycle_probe') {
348
+ const filter = typeof call.arguments?.service === 'string' ? call.arguments.service : undefined
349
+ if (filter && !svcMap.has(filter)) throw new Error('unknown-service')
350
+ const health = []
351
+ for (const [n, p] of svcMap) {
352
+ if (filter && n !== filter) continue
353
+ if (unwrap(ctx.get(n)) !== p.value || (typeof p.check === 'function' && p.check() === false)) throw new Error('service-provision-invalid')
354
+ const h = typeof p.value?.health === 'function' ? await p.value.health() : { ready: true }
355
+ if (badHealth(h)) throw new Error('service-health-failed')
356
+ health.push({ service: n, health: h })
357
+ }
358
+ const value = { kind: 'service', active: fiber.state === 2, provisions: providedNames, disposables: fiber._disposables?.length ?? 0, health }
359
+ return { isError: false, value, content: [{ type: 'text', text: stringify(value) }] }
360
+ }
361
+ if (call.toolName === 'service_method_probe') {
362
+ const s = call.arguments?.service, m = call.arguments?.method
363
+ if (typeof s !== 'string' || typeof m !== 'string' || !svcMethods.get(s)?.has(m)) throw new Error('invalid-service-method')
364
+ const res = await svcMap.get(s).value[m](call.arguments?.input)
365
+ const value = { kind: 'service', service: s, method: m, result: res ?? null }
366
+ return { isError: false, value, content: [{ type: 'text', text: stringify(value) }] }
367
+ }
368
+ return undefined
369
+ }
370
+ } else if (effectiveKind === 'channel') {
371
+ const exported = [module.adapter, module.channel, target?.adapter, target?.channel].filter(Boolean)
372
+ if (channelAdapters.size < 1 && channelProvisions.length < 1 && exported.length < 1) throw new Error('invalid-channel-plugin')
373
+ for (const a of [...channelAdapters, ...channelProvisions.map(p => p.value), ...exported]) if (!checkAdapter(a)) throw new Error('invalid-channel-plugin')
374
+ for (const p of provisions) if (typeof p.value?.health === 'function' && badHealth(await p.value.health())) throw new Error('channel-unhealthy')
375
+ schemas.push({ name: 'channel_readiness_probe', parameters: { type: 'object', properties: {
376
+ check: { type: 'string', enum: ['adapters', 'capabilities', 'health'] }, channel: { type: 'string' },
377
+ }, additionalProperties: false } })
378
+ for (const s of toolSchemas) if (schemas.length < 64 && !schemas.some(x => x.name === s.name)) schemas.push(s)
379
+ invokeNonTool = async call => {
380
+ if (call.toolName !== 'channel_readiness_probe') return undefined
381
+ const ch = typeof call.arguments?.channel === 'string' ? call.arguments.channel : undefined
382
+ const adapters = [...channelAdapters, ...channelProvisions.map(p => p.value), ...exported].filter(a => !ch || a.channel === ch).map(a => ({ channel: a.channel, account: a.account, capabilities: a.capabilities }))
383
+ if (ch && adapters.length === 0) throw new Error('unknown-channel')
384
+ const services = []
385
+ for (const p of provisions) if (typeof p.value?.health === 'function') {
386
+ const h = await p.value.health()
387
+ if (badHealth(h)) throw new Error('channel-unhealthy')
388
+ services.push({ service: p.name, health: h })
389
+ }
390
+ const value = { kind: 'channel', ready: true, adapters, services }
391
+ return { isError: false, value, content: [{ type: 'text', text: stringify(value) }] }
392
+ }
393
+ } else {
394
+ if (pkg.clientExportMissing) throw new Error('invalid-ui-plugin')
395
+ if (typertContributions.size < 1 && !uiExports && !pkg.hasClientExport) throw new Error('invalid-ui-plugin')
396
+ schemas.push({ name: 'ui_declaration_probe', parameters: { type: 'object', properties: {
397
+ check: { type: 'string', enum: ['contributions', 'routes', 'settings'] }, section: { type: 'string' },
398
+ }, additionalProperties: false } })
399
+ for (const s of toolSchemas) if (schemas.length < 64 && !schemas.some(x => x.name === s.name)) schemas.push(s)
400
+ invokeNonTool = async call => {
401
+ if (call.toolName !== 'ui_declaration_probe') return undefined
402
+ const contribs = [...typertContributions].map(c => ({ package: c.package, face: c.face ?? null, schemas: Object.keys(c.schemas ?? {}), invocations: Object.keys(c.invocations ?? {}).length }))
403
+ const value = { kind: 'ui', ready: true, contributions: contribs, hasClientExport: Boolean(pkg.hasClientExport),
404
+ routes: hasNonEmpty(module.routes) ? module.routes : hasNonEmpty(target?.routes) ? target.routes : [],
405
+ sections: hasNonEmpty(module.sections) ? module.sections : hasNonEmpty(target?.sections) ? target.sections : [],
406
+ settings: hasNonEmpty(module.settings) ? module.settings : hasNonEmpty(target?.settings) ? target.settings : [] }
407
+ return { isError: false, value, content: [{ type: 'text', text: stringify(value) }] }
408
+ }
409
+ }
410
+ const schemaDigest = digest(stringify(schemas))
411
+ if (request.operation.kind === 'invoke' && request.operation.schemaDigest !== schemaDigest)
412
+ throw new Error('schema-digest-changed')
413
+ const emitKind = request.pluginKind !== undefined || effectiveKind !== 'tool'
414
+ const kindOut = emitKind ? { pluginKind: effectiveKind } : {}
415
+ if (request.operation.kind === 'discover') frame = { status: 'result', schemaDigest, ...kindOut, schemas }
416
+ else {
417
+ const calls = []
418
+ const probeNames = new Set(schemas.map(s => s.name))
419
+ for (const call of request.operation.calls) {
420
+ if (!probeNames.has(call.toolName)) throw new Error('unknown-invoked-tool')
421
+ if (effectiveKind !== 'tool' && !toolNames.has(call.toolName)) {
422
+ const res = await invokeNonTool(call)
423
+ calls.push({ id: call.id, toolName: call.toolName, result: res })
424
+ } else {
425
+ const batch = await ctx.tools.execute({
426
+ calls: [{ type: 'tool-call', id: call.id, name: call.toolName, arguments: stringify(call.arguments) }],
427
+ signal: new AbortController().signal,
428
+ })
429
+ if (!batch || !Array.isArray(batch.results) || batch.results.length !== 1 || !batch.results[0]?.result)
430
+ throw new Error('tool-batch-invalid')
431
+ calls.push({ id: call.id, toolName: call.toolName, result: batch.results[0].result })
432
+ }
433
+ }
434
+ frame = { status: 'result', schemaDigest, ...kindOut, calls }
435
+ }
436
+ } catch (error) {
437
+ frame = { status: 'unknown', reason: error instanceof Error ? error.message.slice(0, 128) : 'candidate-error' }
438
+ } finally {
439
+ try { if (fiber) await fiber.dispose() } catch { disposed = false }
440
+ if (disposed) {
441
+ if (channelAdapters.size > 0 || typertContributions.size > 0) disposed = false
442
+ for (const svcName of providedNames) if (ctx?.get(svcName) !== undefined) disposed = false
443
+ }
444
+ try { if (ctx) await ctx.fiber.dispose() } catch { disposed = false }
445
+ }
446
+ if (!disposed) frame = { status: 'unknown', reason: 'plugin-disposal-unconfirmed' }
447
+ try {
448
+ const output = stringify(assign(createNull(null), { wireVersion: 1, nonce, artifactSha256, operationDigest }, frame))
449
+ if (Buffer.byteLength(output) > 60000) throw new Error('candidate-output-too-large')
450
+ writeSync(1, output + '\n')
451
+ } catch { process.exitCode = 1 }
452
+ `;
453
+ //# sourceMappingURL=native-behavior-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-behavior-worker.js","sourceRoot":"","sources":["../src/native-behavior-worker.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkc/C,CAAA"}
@@ -0,0 +1,34 @@
1
+ import type { NativeMacRuntime, NativeMacVerifierRunnerConfig, LinuxVerifierRunnerConfig } from '@dsh-ray/assistant-isolation';
2
+ import type { LinuxPluginBehaviorRuntime } from './linux-behavior-runtime.js';
3
+ export declare const NATIVE_BEHAVIOR_BOUNDARY = "macos-seatbelt-single-process-v1";
4
+ export declare const LINUX_BEHAVIOR_BOUNDARY = "linux-native-process-seccomp-v1";
5
+ export interface LinuxPluginBehaviorRunnerConfig extends Omit<LinuxVerifierRunnerConfig, 'command' | 'runtime' | 'limits'> {
6
+ runtime: LinuxPluginBehaviorRuntime;
7
+ }
8
+ export type PluginBehaviorRunnerConfig = Omit<NativeMacVerifierRunnerConfig, 'source'> | LinuxPluginBehaviorRunnerConfig;
9
+ export type CreationBehaviorDeploymentConfig = PluginBehaviorDeploymentConfig | Omit<LinuxPluginBehaviorRunnerConfig, 'authorityDigest'>;
10
+ export type PluginBehaviorDeploymentConfig = Omit<NativeMacVerifierRunnerConfig, 'source' | 'authorityDigest'>;
11
+ export declare function behaviorNativeRuntimeDigest(runtime: NativeMacRuntime): string;
12
+ /** Synchronous shape validation; the native runner rehashes approved runtime bytes before each dispatch. */
13
+ export declare function validatePluginBehaviorRunnerConfig(value: unknown): PluginBehaviorRunnerConfig;
14
+ /** Deployment values omit the digest, which the authenticated owner binds at construction. */
15
+ export declare function validateCreationBehaviorDeploymentConfig(value: unknown): CreationBehaviorDeploymentConfig;
16
+ /** Older behavior consumers cannot acquire Linux creation authority. */
17
+ export declare function validatePluginBehaviorDeploymentConfig(value: unknown): PluginBehaviorDeploymentConfig;
18
+ /** Docker-era review runner, readable only to recompute a historical authority digest.
19
+ * It can never construct a behavior runner or execute; the live deployment validator rejects it. */
20
+ export interface LegacyDockerBehaviorDeploymentConfig {
21
+ image: string;
22
+ dockerPath: string;
23
+ socketPath?: string;
24
+ stateRoot: string;
25
+ expiresAt: number;
26
+ maxRuns: number;
27
+ maxTotalDurationMs: number;
28
+ maxDurationMs: number;
29
+ maxOutputBytes: number;
30
+ }
31
+ export declare function isLegacyDockerBehaviorDeploymentConfig(value: unknown): value is LegacyDockerBehaviorDeploymentConfig;
32
+ /** Shape validation for a historical Docker-era review runner; never enables execution. */
33
+ export declare function validateLegacyDockerBehaviorDeploymentConfig(value: unknown): LegacyDockerBehaviorDeploymentConfig;
34
+ //# sourceMappingURL=plugin-behavior-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-behavior-config.d.ts","sourceRoot":"","sources":["../src/plugin-behavior-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AAC9H,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAA;AAE7E,eAAO,MAAM,wBAAwB,qCAAqC,CAAA;AAC1E,eAAO,MAAM,uBAAuB,oCAAoC,CAAA;AACxE,MAAM,WAAW,+BAAgC,SAAQ,IAAI,CAAC,yBAAyB,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxH,OAAO,EAAE,0BAA0B,CAAA;CACpC;AACD,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAAC,6BAA6B,EAAE,QAAQ,CAAC,GAAG,+BAA+B,CAAA;AACxH,MAAM,MAAM,gCAAgC,GAAG,8BAA8B,GAAG,IAAI,CAAC,+BAA+B,EAAE,iBAAiB,CAAC,CAAA;AACxI,MAAM,MAAM,8BAA8B,GAAG,IAAI,CAAC,6BAA6B,EAAE,QAAQ,GAAG,iBAAiB,CAAC,CAAA;AA4F9G,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAG7E;AAED,4GAA4G;AAC5G,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,OAAO,GAAG,0BAA0B,CAsB7F;AAED,8FAA8F;AAC9F,wBAAgB,wCAAwC,CAAC,KAAK,EAAE,OAAO,GAAG,gCAAgC,CASzG;AAED,wEAAwE;AACxE,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,OAAO,GAAG,8BAA8B,CAKrG;AAED;oGACoG;AACpG,MAAM,WAAW,oCAAoC;IACnD,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oCAAoC,CAMpH;AAED,2FAA2F;AAC3F,wBAAgB,4CAA4C,CAAC,KAAK,EAAE,OAAO,GAAG,oCAAoC,CAcjH"}