@ai-ecoverse/slicc-agent 5.8.3 → 5.10.0
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/README.md +18 -11
- package/bin/agent +3 -1
- package/dist/agent.js +4 -0
- package/dist/agent.js.map +2 -2
- package/dist/approvals/index.js +14 -0
- package/dist/approvals/index.js.map +2 -2
- package/dist/approvals/record.js +14 -6
- package/dist/approvals/record.js.map +2 -2
- package/dist/gelatiere/index.js +16 -19
- package/dist/gelatiere/index.js.map +2 -2
- package/dist/guests/client.js +0 -2
- package/dist/guests/client.js.map +2 -2
- package/dist/guests/guard.js +19 -5
- package/dist/guests/guard.js.map +2 -2
- package/dist/guests/index.js +1 -2
- package/dist/guests/index.js.map +2 -2
- package/dist/guests/policy.js +2 -4
- package/dist/guests/policy.js.map +2 -2
- package/dist/guests/scoop.js +268 -0
- package/dist/guests/scoop.js.map +7 -0
- package/dist/host.js +13 -4
- package/dist/host.js.map +2 -2
- package/dist/kernel/agent-users.js +11 -0
- package/dist/kernel/agent-users.js.map +2 -2
- package/dist/licks/boot.js +10 -1
- package/dist/licks/boot.js.map +2 -2
- package/dist/licks/config.js +0 -37
- package/dist/licks/config.js.map +3 -3
- package/dist/licks/crontab.js +141 -0
- package/dist/licks/crontab.js.map +7 -0
- package/dist/licks/extension.js +4 -69
- package/dist/licks/extension.js.map +2 -2
- package/dist/licks/index.js +3 -5
- package/dist/licks/index.js.map +2 -2
- package/dist/licks/sources.js +42 -14
- package/dist/licks/sources.js.map +2 -2
- package/dist/main.js +9 -5
- package/dist/main.js.map +2 -2
- package/dist/scoops/cli.js +47 -0
- package/dist/scoops/cli.js.map +2 -2
- package/dist/scoops/index.js +7 -5
- package/dist/scoops/index.js.map +2 -2
- package/dist/scoops/requests.js +22 -7
- package/dist/scoops/requests.js.map +2 -2
- package/dist/spectrum/monitor-port.js +0 -1
- package/dist/spectrum/monitor-port.js.map +2 -2
- package/dist/types/agent.d.ts +2 -0
- package/dist/types/approvals/index.d.ts +5 -0
- package/dist/types/approvals/record.d.ts +8 -2
- package/dist/types/gelatiere/index.d.ts +2 -1
- package/dist/types/guests/guard.d.ts +8 -2
- package/dist/types/guests/policy.d.ts +0 -1
- package/dist/types/guests/scoop.d.ts +45 -0
- package/dist/types/host.d.ts +3 -0
- package/dist/types/kernel/agent-users.d.ts +2 -0
- package/dist/types/licks/boot.d.ts +12 -1
- package/dist/types/licks/config.d.ts +0 -7
- package/dist/types/licks/crontab.d.ts +37 -0
- package/dist/types/licks/extension.d.ts +1 -17
- package/dist/types/licks/index.d.ts +1 -1
- package/dist/types/licks/sources.d.ts +1 -3
- package/dist/types/main.d.ts +1 -0
- package/dist/types/scoops/cli.d.ts +2 -0
- package/dist/types/scoops/requests.d.ts +5 -1
- package/package.json +6 -6
- package/packages/vfs-root/skills/gelatiere/SKILL.md +2 -2
- package/packages/vfs-root/skills/licks/SKILL.md +16 -12
- package/dist/licks/cron.js +0 -120
- package/dist/licks/cron.js.map +0 -7
- package/dist/licks/schedules.js +0 -50
- package/dist/licks/schedules.js.map +0 -7
- package/dist/types/licks/cron.d.ts +0 -16
- package/dist/types/licks/schedules.d.ts +0 -25
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/spectrum/monitor-port.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n MonitorAlert,\n MonitorEvents,\n MonitorPort,\n MonitorRow,\n MonitorSection,\n MonitorSnapshot,\n MonitorStatus,\n MonitorVital,\n} from '@ai-ecoverse/slicc-spectrum/ui';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { AgentConnection } from '../client.ts';\nimport { contextRatio } from '../context.ts';\nimport type {\n BudgetState,\n ModelChoice,\n MonitorAgent,\n MonitorFeed,\n MonitorProcess,\n MonitorTask,\n} from '../services.ts';\nimport { Emitter } from './emitter.ts';\n\nexport const RENEW_MS = 10000;\nexport const SAMPLE_MS = 2000;\nexport const ROWS_MAX = 200;\nexport const HISTORY = 24;\nexport const CPU_HISTORY = 30;\nexport const CPU_QUIET = 0.01;\nexport const BUDGET_WARN = 80;\nexport const BUDGET_ERROR = 95;\nexport const RETRY_WARN = 3;\nexport const RETRY_ERROR = 6;\nexport const RETRY_SLOW_MS = 120000;\nexport const FAILED_MS = 600000;\nexport const ABORT_MS = 30000;\nexport const ABORT_ROW_MS = 10000;\nexport const GROUP_MAX = 32;\nexport const TOTAL_MAX = 128;\nexport const ZOMBIE_MS = 60000;\nexport const STALE_MS = 1800000;\nexport const CPU_SHARE = 0.9;\nexport const CPU_SUSTAIN_MS = 120000;\nexport const CONTEXT_WARN = 0.8;\nexport const DEPTH_MAX = 6;\nconst MINUTE = 60000;\nconst HOUR = 3600000;\nconst DAY = 86400000;\n\nexport type AgentMonitorAlert = MonitorAlert & { command?: string; commandLabel?: string };\n\nexport interface Sample {\n at: number;\n cost: number;\n tokens: number;\n active: number;\n}\n\nexport interface MonitorInput {\n feed: MonitorFeed | undefined;\n budget: BudgetState | null | undefined;\n models: readonly ModelChoice[];\n changes: readonly { path: string; status: string }[];\n sprinkles?: readonly { name: string; title: string }[];\n extra: readonly MonitorSection[];\n history: readonly Sample[];\n now: number;\n hot?: ReadonlyMap<number, number>;\n cpu?: readonly number[];\n processes?: readonly number[];\n memory?: readonly number[];\n}\n\nexport function record<T>(list: T[], value: T, max: number): void {\n list.push(value);\n if (list.length > max) list.shift();\n}\n\nfunction trend(series: readonly number[] | undefined): { series?: number[] } {\n return series && series.length > 1 ? { series: [...series] } : {};\n}\n\nconst KINDS: Record<string, string> = {\n 'pi.generation': 'generating',\n 'pi.compaction': 'compacting',\n 'slicc.cron': 'cron',\n 'slicc.scoop-wait': 'agent wait',\n 'slicc.scoop-reporter': 'report',\n 'slicc.memory-extract': 'memory extraction',\n};\n\nexport function age(ms: number): string {\n const seconds = Math.max(0, Math.round(ms / 1000));\n if (seconds < 60) return `${seconds}s`;\n if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;\n return `${Math.floor(seconds / 3600)}h`;\n}\n\nexport function money(value: number): string {\n if (value > 0 && value < 0.01) return '<$0.01';\n return `$${value.toFixed(2)}`;\n}\n\nexport function count(value: number): string {\n if (value < 1000) return String(value);\n if (value < 1000000) return `${(value / 1000).toFixed(1)}k`;\n return `${(value / 1000000).toFixed(1)}M`;\n}\n\nexport function bytes(value: number): string {\n if (value < 1024) return `${value} B`;\n const units = ['KiB', 'MiB', 'GiB', 'TiB'];\n let size = value / 1024;\n let unit = 0;\n while (size >= 1024 && unit < units.length - 1) {\n size /= 1024;\n unit++;\n }\n return `${size.toFixed(size < 10 ? 1 : 0)} ${units[unit]}`;\n}\n\nexport function cpuText(share: number | null | undefined): string | null {\n if (typeof share !== 'number' || share < CPU_QUIET) return null;\n return `${Math.round(share * 100)}%\\u00a0CPU`;\n}\n\nexport function agentsCpu(feed: MonitorFeed): number | null {\n const shares = feed.agents\n .map((agent) => agent.cpu)\n .filter((share): share is number => typeof share === 'number');\n return shares.length ? shares.reduce((sum, share) => sum + share, 0) : null;\n}\n\nfunction cpuVital(feed: MonitorFeed, history: readonly number[]): MonitorVital[] {\n const share = agentsCpu(feed);\n if (share === null) return [];\n return [\n {\n id: 'cpu',\n label: 'CPU',\n value: `${Math.round(share * 100)}%`,\n unit: 'of one core',\n ...trend(history.map((value) => Math.round(value * 100))),\n },\n ];\n}\n\nfunction measuredOf(processes: readonly MonitorProcess[]): MonitorProcess[] {\n return processes.filter((row) => typeof row.rss === 'number');\n}\n\nexport function memoryTotal(processes: readonly MonitorProcess[]): number | null {\n const measured = measuredOf(processes);\n return measured.length ? measured.reduce((sum, row) => sum + (row.rss as number), 0) : null;\n}\n\nfunction memoryVital(\n processes: readonly MonitorProcess[],\n history: readonly number[] | undefined\n): MonitorVital[] {\n const total = memoryTotal(processes);\n if (total === null) return [];\n const measured = measuredOf(processes);\n const agents = measured\n .filter((row) => row.agentId)\n .reduce((sum, row) => sum + (row.rss as number), 0);\n return [\n {\n id: 'memory',\n label: 'Process memory',\n value: bytes(total),\n unit: `${bytes(agents)} by agents`,\n ...trend(history),\n },\n ];\n}\n\nexport function taskLabel(task: MonitorTask): string {\n if (task.kind === 'pi.tool') return task.detail ? `tool ${task.detail}` : 'tool';\n if (task.kind === 'slicc.scoop-anchor') return task.detail ? `scoop ${task.detail}` : 'scoop';\n return KINDS[task.kind] ?? task.kind;\n}\n\nfunction coneOf(agents: ReadonlyMap<string, MonitorAgent>, id: string | null): string | null {\n const visited = new Set<string>();\n let current = id === null ? undefined : agents.get(id);\n while (current?.parentId && !visited.has(current.id)) {\n visited.add(current.id);\n const parent = agents.get(current.parentId);\n if (!parent) break;\n current = parent;\n }\n return current ? current.id : null;\n}\n\nfunction ordered(feed: MonitorFeed): MonitorAgent[] {\n const byId = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const out: MonitorAgent[] = [];\n for (const cone of feed.agents.filter((agent) => agent.kind === 'cone')) {\n out.push(cone);\n for (const agent of feed.agents)\n if (agent.kind === 'scoop' && coneOf(byId, agent.id) === cone.id) out.push(agent);\n }\n for (const agent of feed.agents) if (!out.includes(agent)) out.push(agent);\n return out;\n}\n\nexport function taskTree(feed: MonitorFeed): { task: MonitorTask; depth: number }[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const order = ordered(feed).map((agent) => agent.id);\n const rank = (task: MonitorTask) => {\n const at = task.agentId === null ? -1 : order.indexOf(task.agentId);\n return at < 0 ? order.length : at;\n };\n const groupOf = (task: MonitorTask) => coneOf(agents, task.agentId) ?? '';\n const byId = new Map(feed.tasks.map((task) => [task.id, task]));\n const children = new Map<string, MonitorTask[]>();\n const roots: MonitorTask[] = [];\n for (const task of feed.tasks) {\n const owner = task.owner === null ? undefined : byId.get(task.owner);\n if (owner && groupOf(owner) === groupOf(task)) {\n const list = children.get(owner.id) ?? [];\n list.push(task);\n children.set(owner.id, list);\n } else roots.push(task);\n }\n const sort = (list: MonitorTask[]) =>\n list.sort((a, b) => rank(a) - rank(b) || Number(a.id) - Number(b.id));\n const out: { task: MonitorTask; depth: number }[] = [];\n const visit = (task: MonitorTask, depth: number) => {\n out.push({ task, depth });\n for (const child of sort(children.get(task.id) ?? [])) visit(child, depth + 1);\n };\n for (const root of sort(roots)) visit(root, 0);\n return out;\n}\n\nfunction capped(rows: MonitorRow[]): MonitorRow[] {\n if (rows.length <= ROWS_MAX) return rows;\n const shown = rows.slice(0, ROWS_MAX - 1);\n return [\n ...shown,\n { id: 'more', name: `+${rows.length - shown.length} more`, meta: '', status: 'idle' },\n ];\n}\n\nfunction agentContext(agent: MonitorAgent, models: readonly ModelChoice[]): number | null {\n return contextRatio(agent.context, agent.model, models);\n}\n\nfunction rate(history: readonly Sample[], pick: (sample: Sample) => number): number | null {\n const first = history[0];\n const last = history.at(-1);\n if (!first || !last || last.at - first.at < MINUTE) return null;\n return ((pick(last) - pick(first)) / (last.at - first.at)) * HOUR;\n}\n\nconst RELATIVE = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });\n\nfunction resetsIn(at: number, now: number): string {\n const ms = at - now;\n if (ms <= 0) return 'resets soon';\n if (ms >= DAY)\n return `resets ${RELATIVE.format(Math.floor(at / DAY) - Math.floor(now / DAY), 'day')}`;\n if (ms >= HOUR) return `resets ${RELATIVE.format(Math.floor(ms / HOUR), 'hour')}`;\n return `resets ${RELATIVE.format(Math.ceil(ms / MINUTE), 'minute')}`;\n}\n\nfunction budgetVital(budget: BudgetState, now: number): MonitorVital {\n const resets = new Date(budget.resets);\n return {\n id: 'budget',\n label: `Budget (${budget.window})`,\n value: `${budget.percent}%`,\n ...(Number.isNaN(resets.getTime())\n ? {}\n : {\n unit: resetsIn(resets.getTime(), now),\n hint: `resets ${resets.toISOString().slice(0, 16).replace('T', ' ')} UTC`,\n }),\n ratio: Math.min(1, Math.max(0, budget.percent / 100)),\n };\n}\n\nfunction vitals(input: MonitorInput, feed: MonitorFeed): MonitorVital[] {\n const out: MonitorVital[] = [];\n if (feed.usage) {\n const free = feed.usage.free;\n const pick = (sample: Sample) => (free ? sample.tokens : sample.cost);\n const perHour = rate(input.history, pick);\n const series = input.history.map(pick);\n out.push({\n id: 'spend',\n label: free ? 'Tokens' : 'Spend',\n value: free ? count(feed.usage.tokens) : money(feed.usage.cost),\n unit: free ? 'tokens' : `${count(feed.usage.tokens)} tokens`,\n ...(perHour === null ? {} : { delta: `${free ? count(perHour) : money(perHour)}/h` }),\n ...trend(series),\n });\n }\n const active = feed.agents.filter((agent) => agent.running).length;\n out.push({\n id: 'agents',\n label: 'Active agents',\n value: String(active),\n unit: `of ${feed.agents.length}`,\n ...trend(input.history.map((sample) => sample.active)),\n });\n const tools = feed.tasks.filter(\n (task) => task.kind === 'pi.tool' && task.status === 'running'\n ).length;\n out.push({\n id: 'tasks',\n label: 'Running',\n value: String(tools),\n unit: `${tools === 1 ? 'tool' : 'tools'} \u00B7 ${feed.tasks.length} ${feed.tasks.length === 1 ? 'task' : 'tasks'}`,\n });\n out.push(\n feed.processes\n ? {\n id: 'processes',\n label: 'Processes',\n value: String(feed.processes.length),\n unit: `${feed.processes.filter((row) => row.agentId).length} by agents`,\n ...trend(input.processes),\n }\n : feed.kernel === 'checking'\n ? { id: 'processes', label: 'Processes', value: '\u2026', unit: 'checking' }\n : { id: 'processes', label: 'Processes', value: '\u2014', unit: 'kernel not reachable' }\n );\n out.push(...memoryVital(feed.processes ?? [], input.memory));\n out.push(...cpuVital(feed, input.cpu ?? []));\n const ratios = feed.agents\n .map((agent) => agentContext(agent, input.models))\n .filter((ratio): ratio is number => ratio !== null);\n if (ratios.length) {\n const fullest = Math.max(...ratios);\n out.push({\n id: 'context',\n label: 'Fullest context',\n value: `${Math.round(fullest * 100)}%`,\n ratio: fullest,\n });\n }\n return out;\n}\n\nfunction stale(process: MonitorProcess, agents: ReadonlyMap<string, MonitorAgent>, now: number) {\n if (!process.agentId || process.state === 'Z' || !process.started) return false;\n if (typeof process.utime === 'number') return false;\n if (agents.get(process.agentId)?.tool === 'bash') return false;\n return now - process.started > STALE_MS;\n}\n\nfunction zombied(process: MonitorProcess, now: number): boolean {\n return process.zombie !== null && now - process.zombie > ZOMBIE_MS;\n}\n\nfunction groups(processes: readonly MonitorProcess[]): Map<number, MonitorProcess[]> {\n const out = new Map<number, MonitorProcess[]>();\n for (const process of processes) {\n if (!process.agentId) continue;\n const list = out.get(process.pgid) ?? [];\n list.push(process);\n out.set(process.pgid, list);\n }\n return out;\n}\n\ntype Names = (id: string | null) => string;\n\nexport function groupCpu(\n processes: readonly MonitorProcess[]\n): Map<number, { agentId: string; share: number }> {\n const out = new Map<number, { agentId: string; share: number }>();\n for (const [pgid, members] of groups(processes)) {\n const measured = members.filter((row) => typeof row.cpu === 'number');\n if (!measured.length) continue;\n const share = measured.reduce((sum, row) => sum + (row.cpu as number), 0);\n out.set(pgid, { agentId: (members[0] as MonitorProcess).agentId as string, share });\n }\n return out;\n}\n\nexport function hotGroups(\n processes: readonly MonitorProcess[],\n at: number,\n previous: ReadonlyMap<number, number>\n): Map<number, number> {\n const out = new Map<number, number>();\n for (const [pgid, { share }] of groupCpu(processes))\n if (share >= CPU_SHARE) out.set(pgid, previous.get(pgid) ?? at);\n return out;\n}\n\nfunction busy(input: MonitorInput, processes: readonly MonitorProcess[]) {\n const shares = groupCpu(processes);\n const out: { pgid: number; agentId: string; share: number; held: number }[] = [];\n for (const [pgid, since] of input.hot ?? []) {\n const group = shares.get(pgid);\n const held = input.now - since;\n if (group && group.share >= CPU_SHARE && held >= CPU_SUSTAIN_MS)\n out.push({ pgid, ...group, held });\n }\n return out;\n}\n\nfunction cpuAlerts(input: MonitorInput, processes: readonly MonitorProcess[], nameOf: Names) {\n return busy(input, processes).map(\n (group): AgentMonitorAlert => ({\n id: `runaway-cpu-${group.pgid}`,\n title: `${nameOf(group.agentId)} is using a lot of CPU`,\n detail: `${Math.round(group.share * 100)}% of one core for ${Math.floor(group.held / MINUTE)} minutes.`,\n command: `kill -- -${group.pgid}`,\n commandLabel: 'To stop it, run',\n severity: cpuSeverity(group),\n })\n );\n}\n\nfunction cpuSeverity(group: { share: number; held: number }): 'warn' | 'error' {\n return group.share >= CPU_SHARE * 2 || group.held >= CPU_SUSTAIN_MS * 2 ? 'error' : 'warn';\n}\n\nfunction crowdSeverity(members: readonly MonitorProcess[]): 'warn' | 'error' {\n return members.length > GROUP_MAX * 2 ? 'error' : 'warn';\n}\n\nfunction staleSeverity(process: MonitorProcess, now: number): 'warn' | 'error' {\n return now - process.started > STALE_MS * 2 ? 'error' : 'warn';\n}\n\nfunction worse(\n a: 'warn' | 'error' | undefined,\n b: 'warn' | 'error' | undefined\n): 'warn' | 'error' | undefined {\n return a === 'error' || b === 'error' ? 'error' : (a ?? b);\n}\n\nfunction resetLine(budget: BudgetState): string {\n const resets = new Date(budget.resets);\n return Number.isNaN(resets.getTime())\n ? `The ${budget.window} budget is nearly used up.`\n : `Resets ${resets.toISOString().slice(0, 16).replace('T', ' ')} UTC.`;\n}\n\nfunction budgetAlerts(budget: BudgetState | null | undefined): AgentMonitorAlert[] {\n if (!budget || budget.percent < BUDGET_WARN) return [];\n return [\n {\n id: 'budget',\n title: `Budget ${budget.percent}% used`,\n detail: resetLine(budget),\n severity: budget.percent >= BUDGET_ERROR ? 'error' : 'warn',\n },\n ];\n}\n\nfunction agentAlerts(input: MonitorInput, feed: MonitorFeed): AgentMonitorAlert[] {\n const out: AgentMonitorAlert[] = [];\n for (const agent of feed.agents) {\n const retry = agent.retry;\n if (retry && (retry.attempt >= RETRY_WARN || input.now - retry.since > RETRY_SLOW_MS))\n out.push({\n id: `retry-${agent.id}`,\n title: `${agent.name} is retrying (attempt ${retry.attempt})`,\n detail: retry.error,\n severity: retry.attempt >= RETRY_ERROR ? 'error' : 'warn',\n });\n if (agent.failed && !agent.running)\n out.push({\n id: `turn-${agent.id}`,\n title: `${agent.name}'s last turn failed`,\n detail: agent.failed,\n severity: 'error',\n });\n }\n return out;\n}\n\nfunction taskAlerts(input: MonitorInput, feed: MonitorFeed, nameOf: Names): AgentMonitorAlert[] {\n const out: AgentMonitorAlert[] = [];\n for (const problem of feed.problems)\n if (problem.kind === 'task' && input.now - problem.at < FAILED_MS)\n out.push({\n id: `failed-${problem.id}`,\n title: `A task of ${nameOf(problem.agentId)} failed`,\n detail: problem.message,\n severity: 'error',\n });\n for (const task of feed.tasks)\n if (task.aborting !== null && input.now - task.aborting > ABORT_MS)\n out.push({\n id: `abort-${task.id}`,\n title: `Stop is still waiting for ${taskLabel(task)}`,\n detail: `${nameOf(task.agentId)} asked it to stop ${age(input.now - task.aborting)} ago.`,\n severity: 'warn',\n });\n return out;\n}\n\nfunction crowdAlerts(processes: readonly MonitorProcess[], nameOf: Names): AgentMonitorAlert[] {\n const out: AgentMonitorAlert[] = [];\n for (const [pgid, members] of groups(processes))\n if (members.length > GROUP_MAX)\n out.push({\n id: `runaway-${pgid}`,\n title: `${nameOf((members[0] as MonitorProcess).agentId)} has ${members.length} processes`,\n detail: 'Something in it may be starting processes in a loop.',\n command: `kill -- -${pgid}`,\n commandLabel: 'To stop them, run',\n severity: crowdSeverity(members),\n });\n if (processes.length > TOTAL_MAX)\n out.push({\n id: 'runaway-total',\n title: `The kernel has ${processes.length} processes`,\n detail: 'Something may be starting processes in a loop.',\n severity: processes.length > TOTAL_MAX * 2 ? 'error' : 'warn',\n });\n return out;\n}\n\nfunction processAlerts(input: MonitorInput, feed: MonitorFeed, nameOf: Names): AgentMonitorAlert[] {\n const processes = feed.processes ?? [];\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const out = [...crowdAlerts(processes, nameOf), ...cpuAlerts(input, processes, nameOf)];\n for (const process of processes) {\n if (zombied(process, input.now))\n out.push({\n id: `zombie-${process.pid}`,\n title: `Process ${process.pid} is a zombie`,\n detail: `Its parent ${process.ppid} hasn't reaped it.`,\n ...(process.ppid > 1\n ? { command: `kill ${process.ppid}`, commandLabel: 'To clear it, stop the parent' }\n : {}),\n severity: 'warn',\n });\n if (stale(process, agents, input.now))\n out.push({\n id: `stale-${process.pid}`,\n title: `${process.command || `Process ${process.pid}`} has run for ${age(input.now - process.started)}`,\n detail: `${nameOf(process.agentId)} started it in the background.`,\n command: `kill ${process.pid}`,\n commandLabel: 'To stop it, run',\n severity: staleSeverity(process, input.now),\n });\n }\n return out;\n}\n\nfunction contextAlerts(input: MonitorInput, feed: MonitorFeed): AgentMonitorAlert[] {\n const out: AgentMonitorAlert[] = [];\n for (const agent of feed.agents) {\n const ratio = agentContext(agent, input.models);\n if (ratio !== null && ratio >= CONTEXT_WARN)\n out.push({\n id: `context-${agent.id}`,\n title: `${agent.name} is ${Math.round(ratio * 100)}% full`,\n detail: 'Compact it soon to keep replies fast.',\n severity: 'warn',\n });\n }\n if (feed.paused)\n out.push({\n id: 'scheduler',\n title: \"The agent isn't scheduling work\",\n detail: 'Its scheduler is paused.',\n severity: 'warn',\n });\n return out;\n}\n\nfunction alerts(input: MonitorInput, feed: MonitorFeed): AgentMonitorAlert[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const nameOf: Names = (id) => (id ? (agents.get(id)?.name ?? id) : 'the session');\n return [\n ...budgetAlerts(input.budget),\n ...agentAlerts(input, feed),\n ...taskAlerts(input, feed, nameOf),\n ...processAlerts(input, feed, nameOf),\n ...contextAlerts(input, feed),\n ];\n}\n\nfunction taskRow(\n task: MonitorTask,\n depth: number,\n nameOf: (id: string | null) => string,\n now: number\n): MonitorRow {\n const aborting = task.aborting !== null && now - task.aborting > ABORT_ROW_MS;\n const status: MonitorStatus = aborting\n ? 'warn'\n : task.status === 'running' || task.status === 'completing'\n ? 'active'\n : 'idle';\n const badges = [\n ...(task.background ? ['background'] : []),\n ...(task.aborting !== null ? ['aborting'] : []),\n ...(task.waits ? [`waits on ${task.waits}`] : []),\n ];\n return {\n id: task.id,\n name: taskLabel(task),\n depth: Math.min(depth, DEPTH_MAX),\n meta: [nameOf(task.agentId), task.phase, age(now - task.since)].filter(Boolean).join(' \u00B7 '),\n status,\n ...(badges.length ? { badges } : {}),\n };\n}\n\nfunction drivers(members: readonly MonitorProcess[]): MonitorProcess[] {\n const hot = members.filter((row) => (row.cpu ?? 0) >= CPU_SHARE);\n if (hot.length) return hot;\n const top = members.reduce((best, row) => ((row.cpu ?? 0) > (best.cpu ?? 0) ? row : best));\n return [top];\n}\n\nfunction processRows(input: MonitorInput, feed: MonitorFeed): MonitorRow[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const members = groups(feed.processes ?? []);\n const flagged = new Map<number, 'warn' | 'error'>();\n for (const group of busy(input, feed.processes ?? []))\n for (const row of drivers(members.get(group.pgid) as MonitorProcess[]))\n flagged.set(row.pid, cpuSeverity(group));\n return (feed.processes ?? []).map((process) => {\n const runaway = worse(\n worse(\n flagged.get(process.pid),\n stale(process, agents, input.now) ? staleSeverity(process, input.now) : undefined\n ),\n zombied(process, input.now) ? 'warn' : undefined\n );\n const badges = [\n ...(process.agentId ? [agents.get(process.agentId)?.name ?? process.agentId] : []),\n ...(process.tty ? ['terminal'] : []),\n ];\n return {\n id: String(process.pid),\n name: process.command || `[${process.pid}]`,\n meta: [\n `pid ${process.pid}`,\n process.user,\n typeof process.rss === 'number' ? bytes(process.rss) : null,\n cpuText(process.cpu),\n process.started ? age(input.now - process.started) : null,\n ]\n .filter(Boolean)\n .join(' \u00B7 '),\n status: runaway ?? 'idle',\n ...(badges.length ? { badges } : {}),\n };\n });\n}\n\nconst PROBLEM_KINDS = { task: 'task failed', retry: 'retry', turn: 'turn failed' } as const;\n\nfunction sections(input: MonitorInput, feed: MonitorFeed): MonitorSection[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const nameOf = (id: string | null) => (id ? (agents.get(id)?.name ?? id) : 'session');\n return [\n {\n id: 'tasks',\n label: 'Tasks',\n rows: capped(\n taskTree(feed).map(({ task, depth }) => taskRow(task, depth, nameOf, input.now))\n ),\n },\n { id: 'processes', label: 'Processes', rows: capped(processRows(input, feed)) },\n {\n id: 'problems',\n label: 'Recent problems',\n rows: feed.problems.map((problem) => ({\n id: problem.id,\n name: `${nameOf(problem.agentId)} \u00B7 ${PROBLEM_KINDS[problem.kind]}`,\n meta: problem.message,\n status: problem.kind === 'retry' ? 'warn' : 'error',\n })),\n },\n ];\n}\n\nfunction pageSections(input: MonitorInput): MonitorSection[] {\n return [\n {\n id: 'changes',\n label: 'Pending changes',\n rows: input.changes.map((change) => ({\n id: change.path,\n name: change.path,\n meta: change.status,\n status: 'warn',\n })),\n },\n ...input.extra,\n ];\n}\n\nexport function monitorSnapshot(input: MonitorInput): MonitorSnapshot {\n const budget = input.budget ? [budgetVital(input.budget, input.now)] : [];\n const feed = input.feed;\n if (!feed?.at)\n return {\n vitals: budget,\n alerts: [],\n sections: pageSections(input),\n updatedAt: input.now,\n };\n return {\n vitals: [...budget, ...vitals(input, feed)],\n alerts: alerts(input, feed),\n sections: [...sections(input, feed), ...pageSections(input)],\n updatedAt: feed.at,\n };\n}\n\nexport interface Intervals {\n every(run: () => void, ms: number): unknown;\n stop(handle: unknown): void;\n}\n\nexport const globalIntervals: Intervals = {\n every: (run, ms) => setInterval(run, ms),\n stop: (handle) => clearInterval(handle as ReturnType<typeof setInterval>),\n};\n\nexport interface MonitorAdapterOptions {\n extra?: () => readonly MonitorSection[];\n renewMs?: number;\n sampleMs?: number;\n intervals?: Intervals;\n now?: () => number;\n}\n\ninterface Open {\n lease: Promise<string | null>;\n timer: unknown;\n sampler: unknown;\n}\n\nexport class MonitorAdapter implements MonitorPort {\n readonly #connection: AgentConnection;\n readonly #emitter = new Emitter<MonitorEvents>();\n readonly #extra: () => readonly MonitorSection[];\n readonly #renewMs: number;\n readonly #sampleMs: number;\n readonly #intervals: Intervals;\n readonly #now: () => number;\n #listeners = 0;\n #open: Open | undefined;\n #history: Sample[] = [];\n #hot = new Map<number, number>();\n #hotAt = -1;\n #cpu: number[] = [];\n #processes: number[] = [];\n #memory: number[] = [];\n\n constructor(connection: AgentConnection, options: MonitorAdapterOptions = {}) {\n this.#connection = connection;\n this.#extra = options.extra ?? (() => []);\n this.#renewMs = options.renewMs ?? RENEW_MS;\n this.#sampleMs = options.sampleMs ?? SAMPLE_MS;\n this.#intervals = options.intervals ?? globalIntervals;\n this.#now = options.now ?? Date.now;\n connection.monitor?.subscribe(() => this.#update());\n connection.settings.state.subscribe(() => this.#update());\n connection.changes?.subscribe(() => this.#update());\n }\n\n on<K extends keyof MonitorEvents>(\n type: K,\n listener: (detail: MonitorEvents[K]) => void\n ): () => void {\n const off = this.#emitter.on(type, listener);\n this.#listeners++;\n if (this.#listeners === 1) this.#start();\n let done = false;\n return () => {\n if (done) return;\n done = true;\n off();\n this.#listeners--;\n if (!this.#listeners) this.#stop();\n };\n }\n\n snapshot(): MonitorSnapshot {\n const settings = this.#connection.settings.state.value;\n return monitorSnapshot({\n feed: this.#connection.monitor?.value,\n budget: settings?.budget,\n models: settings?.models ?? [],\n changes: this.#connection.changes?.value?.changes ?? [],\n extra: this.#extra(),\n history: this.#history,\n now: this.#now(),\n hot: this.#hot,\n cpu: this.#cpu,\n processes: this.#processes,\n memory: this.#memory,\n });\n }\n\n resync(): void {\n const open = this.#open;\n const control = this.#connection.control;\n if (open)\n void open.lease\n .then((lease) => (lease ? control.monitorOpen(lease, true, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n this.#emitter.emit('snapshot', this.snapshot());\n }\n\n #start(): void {\n const control = this.#connection.control;\n this.#history = [];\n this.#hot = new Map();\n this.#hotAt = -1;\n this.#cpu = [];\n this.#processes = [];\n this.#memory = [];\n void control.changesOpen(BACKGROUND_CONTEXT).catch(() => undefined);\n const lease = control.monitorOpen(null, true, BACKGROUND_CONTEXT).then(\n (opened) => opened.lease || null,\n () => null\n );\n const renew = () =>\n void lease\n .then((held) => (held ? control.monitorOpen(held, false, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n this.#open = {\n lease,\n timer: this.#intervals.every(renew, this.#renewMs),\n sampler: this.#intervals.every(() => this.#poll(), this.#sampleMs),\n };\n }\n\n #stop(): void {\n const open = this.#open;\n if (!open) return;\n this.#open = undefined;\n this.#intervals.stop(open.timer);\n this.#intervals.stop(open.sampler);\n const control = this.#connection.control;\n void open.lease\n .then((held) => (held ? control.monitorClose(held, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n }\n\n #sample(): void {\n const feed = this.#connection.monitor?.value;\n if (!feed?.open || !feed.usage || this.#history.at(-1)?.at === feed.at) return;\n record(\n this.#history,\n {\n at: feed.at,\n cost: feed.usage.cost,\n tokens: feed.usage.tokens,\n active: feed.agents.filter((agent) => agent.running).length,\n },\n HISTORY\n );\n }\n\n #track(): void {\n const feed = this.#connection.monitor?.value;\n if (!feed?.open || feed.at === this.#hotAt) return;\n this.#hotAt = feed.at;\n this.#hot = hotGroups(feed.processes ?? [], feed.at, this.#hot);\n const share = agentsCpu(feed);\n if (share !== null) record(this.#cpu, share, CPU_HISTORY);\n }\n\n #poll(): void {\n const feed = this.#connection.monitor?.value;\n if (!feed?.open || !feed.processes) return;\n record(this.#processes, feed.processes.length, CPU_HISTORY);\n const memory = memoryTotal(feed.processes);\n if (memory !== null) record(this.#memory, memory, CPU_HISTORY);\n this.#emitter.emit('snapshot', this.snapshot());\n }\n\n #update(): void {\n if (!this.#listeners) return;\n this.#sample();\n this.#track();\n this.#emitter.emit('snapshot', this.snapshot());\n }\n}\n"],
|
|
5
|
-
"mappings": "AAUA,SAAS,0BAA0B;AAEnC,SAAS,oBAAoB;AAS7B,SAAS,eAAe;AAEjB,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,WAAW;AACjB,MAAM,UAAU;AAChB,MAAM,cAAc;AACpB,MAAM,YAAY;AAClB,MAAM,cAAc;AACpB,MAAM,eAAe;AACrB,MAAM,aAAa;AACnB,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,YAAY;AAClB,MAAM,WAAW;AACjB,MAAM,eAAe;AACrB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,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GAAG,EAAE,GAAG,OAAO,KAAK,GAAI;AACxE;AAAA,MACE,KAAK;AAAA,MACL;AAAA,QACE,IAAI,KAAK;AAAA,QACT,MAAM,KAAK,MAAM;AAAA,QACjB,QAAQ,KAAK,MAAM;AAAA,QACnB,QAAQ,KAAK,OAAO,OAAO,CAAC,UAAU,MAAM,OAAO,EAAE;AAAA,MACvD;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAe;AACb,UAAM,OAAO,KAAK,YAAY,SAAS;AACvC,QAAI,CAAC,MAAM,QAAQ,KAAK,OAAO,KAAK,OAAQ;AAC5C,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,UAAU,KAAK,aAAa,CAAC,GAAG,KAAK,IAAI,KAAK,IAAI;AAC9D,UAAM,QAAQ,UAAU,IAAI;AAC5B,QAAI,UAAU,KAAM,QAAO,KAAK,MAAM,OAAO,WAAW;AAAA,EAC1D;AAAA,EAEA,QAAc;AACZ,UAAM,OAAO,KAAK,YAAY,SAAS;AACvC,QAAI,CAAC,MAAM,QAAQ,CAAC,KAAK,UAAW;AACpC,WAAO,KAAK,YAAY,KAAK,UAAU,QAAQ,WAAW;AAC1D,UAAM,SAAS,YAAY,KAAK,SAAS;AACzC,QAAI,WAAW,KAAM,QAAO,KAAK,SAAS,QAAQ,WAAW;AAC7D,SAAK,SAAS,KAAK,YAAY,KAAK,SAAS,CAAC;AAAA,EAChD;AAAA,EAEA,UAAgB;AACd,QAAI,CAAC,KAAK,WAAY;AACtB,SAAK,QAAQ;AACb,SAAK,OAAO;AACZ,SAAK,SAAS,KAAK,YAAY,KAAK,SAAS,CAAC;AAAA,EAChD;AACF;",
|
|
4
|
+
"sourcesContent": ["import type {\n MonitorAlert,\n MonitorEvents,\n MonitorPort,\n MonitorRow,\n MonitorSection,\n MonitorSnapshot,\n MonitorStatus,\n MonitorVital,\n} from '@ai-ecoverse/slicc-spectrum/ui';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { AgentConnection } from '../client.ts';\nimport { contextRatio } from '../context.ts';\nimport type {\n BudgetState,\n ModelChoice,\n MonitorAgent,\n MonitorFeed,\n MonitorProcess,\n MonitorTask,\n} from '../services.ts';\nimport { Emitter } from './emitter.ts';\n\nexport const RENEW_MS = 10000;\nexport const SAMPLE_MS = 2000;\nexport const ROWS_MAX = 200;\nexport const HISTORY = 24;\nexport const CPU_HISTORY = 30;\nexport const CPU_QUIET = 0.01;\nexport const BUDGET_WARN = 80;\nexport const BUDGET_ERROR = 95;\nexport const RETRY_WARN = 3;\nexport const RETRY_ERROR = 6;\nexport const RETRY_SLOW_MS = 120000;\nexport const FAILED_MS = 600000;\nexport const ABORT_MS = 30000;\nexport const ABORT_ROW_MS = 10000;\nexport const GROUP_MAX = 32;\nexport const TOTAL_MAX = 128;\nexport const ZOMBIE_MS = 60000;\nexport const STALE_MS = 1800000;\nexport const CPU_SHARE = 0.9;\nexport const CPU_SUSTAIN_MS = 120000;\nexport const CONTEXT_WARN = 0.8;\nexport const DEPTH_MAX = 6;\nconst MINUTE = 60000;\nconst HOUR = 3600000;\nconst DAY = 86400000;\n\nexport type AgentMonitorAlert = MonitorAlert & { command?: string; commandLabel?: string };\n\nexport interface Sample {\n at: number;\n cost: number;\n tokens: number;\n active: number;\n}\n\nexport interface MonitorInput {\n feed: MonitorFeed | undefined;\n budget: BudgetState | null | undefined;\n models: readonly ModelChoice[];\n changes: readonly { path: string; status: string }[];\n sprinkles?: readonly { name: string; title: string }[];\n extra: readonly MonitorSection[];\n history: readonly Sample[];\n now: number;\n hot?: ReadonlyMap<number, number>;\n cpu?: readonly number[];\n processes?: readonly number[];\n memory?: readonly number[];\n}\n\nexport function record<T>(list: T[], value: T, max: number): void {\n list.push(value);\n if (list.length > max) list.shift();\n}\n\nfunction trend(series: readonly number[] | undefined): { series?: number[] } {\n return series && series.length > 1 ? { series: [...series] } : {};\n}\n\nconst KINDS: Record<string, string> = {\n 'pi.generation': 'generating',\n 'pi.compaction': 'compacting',\n 'slicc.scoop-wait': 'agent wait',\n 'slicc.scoop-reporter': 'report',\n 'slicc.memory-extract': 'memory extraction',\n};\n\nexport function age(ms: number): string {\n const seconds = Math.max(0, Math.round(ms / 1000));\n if (seconds < 60) return `${seconds}s`;\n if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;\n return `${Math.floor(seconds / 3600)}h`;\n}\n\nexport function money(value: number): string {\n if (value > 0 && value < 0.01) return '<$0.01';\n return `$${value.toFixed(2)}`;\n}\n\nexport function count(value: number): string {\n if (value < 1000) return String(value);\n if (value < 1000000) return `${(value / 1000).toFixed(1)}k`;\n return `${(value / 1000000).toFixed(1)}M`;\n}\n\nexport function bytes(value: number): string {\n if (value < 1024) return `${value} B`;\n const units = ['KiB', 'MiB', 'GiB', 'TiB'];\n let size = value / 1024;\n let unit = 0;\n while (size >= 1024 && unit < units.length - 1) {\n size /= 1024;\n unit++;\n }\n return `${size.toFixed(size < 10 ? 1 : 0)} ${units[unit]}`;\n}\n\nexport function cpuText(share: number | null | undefined): string | null {\n if (typeof share !== 'number' || share < CPU_QUIET) return null;\n return `${Math.round(share * 100)}%\\u00a0CPU`;\n}\n\nexport function agentsCpu(feed: MonitorFeed): number | null {\n const shares = feed.agents\n .map((agent) => agent.cpu)\n .filter((share): share is number => typeof share === 'number');\n return shares.length ? shares.reduce((sum, share) => sum + share, 0) : null;\n}\n\nfunction cpuVital(feed: MonitorFeed, history: readonly number[]): MonitorVital[] {\n const share = agentsCpu(feed);\n if (share === null) return [];\n return [\n {\n id: 'cpu',\n label: 'CPU',\n value: `${Math.round(share * 100)}%`,\n unit: 'of one core',\n ...trend(history.map((value) => Math.round(value * 100))),\n },\n ];\n}\n\nfunction measuredOf(processes: readonly MonitorProcess[]): MonitorProcess[] {\n return processes.filter((row) => typeof row.rss === 'number');\n}\n\nexport function memoryTotal(processes: readonly MonitorProcess[]): number | null {\n const measured = measuredOf(processes);\n return measured.length ? measured.reduce((sum, row) => sum + (row.rss as number), 0) : null;\n}\n\nfunction memoryVital(\n processes: readonly MonitorProcess[],\n history: readonly number[] | undefined\n): MonitorVital[] {\n const total = memoryTotal(processes);\n if (total === null) return [];\n const measured = measuredOf(processes);\n const agents = measured\n .filter((row) => row.agentId)\n .reduce((sum, row) => sum + (row.rss as number), 0);\n return [\n {\n id: 'memory',\n label: 'Process memory',\n value: bytes(total),\n unit: `${bytes(agents)} by agents`,\n ...trend(history),\n },\n ];\n}\n\nexport function taskLabel(task: MonitorTask): string {\n if (task.kind === 'pi.tool') return task.detail ? `tool ${task.detail}` : 'tool';\n if (task.kind === 'slicc.scoop-anchor') return task.detail ? `scoop ${task.detail}` : 'scoop';\n return KINDS[task.kind] ?? task.kind;\n}\n\nfunction coneOf(agents: ReadonlyMap<string, MonitorAgent>, id: string | null): string | null {\n const visited = new Set<string>();\n let current = id === null ? undefined : agents.get(id);\n while (current?.parentId && !visited.has(current.id)) {\n visited.add(current.id);\n const parent = agents.get(current.parentId);\n if (!parent) break;\n current = parent;\n }\n return current ? current.id : null;\n}\n\nfunction ordered(feed: MonitorFeed): MonitorAgent[] {\n const byId = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const out: MonitorAgent[] = [];\n for (const cone of feed.agents.filter((agent) => agent.kind === 'cone')) {\n out.push(cone);\n for (const agent of feed.agents)\n if (agent.kind === 'scoop' && coneOf(byId, agent.id) === cone.id) out.push(agent);\n }\n for (const agent of feed.agents) if (!out.includes(agent)) out.push(agent);\n return out;\n}\n\nexport function taskTree(feed: MonitorFeed): { task: MonitorTask; depth: number }[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const order = ordered(feed).map((agent) => agent.id);\n const rank = (task: MonitorTask) => {\n const at = task.agentId === null ? -1 : order.indexOf(task.agentId);\n return at < 0 ? order.length : at;\n };\n const groupOf = (task: MonitorTask) => coneOf(agents, task.agentId) ?? '';\n const byId = new Map(feed.tasks.map((task) => [task.id, task]));\n const children = new Map<string, MonitorTask[]>();\n const roots: MonitorTask[] = [];\n for (const task of feed.tasks) {\n const owner = task.owner === null ? undefined : byId.get(task.owner);\n if (owner && groupOf(owner) === groupOf(task)) {\n const list = children.get(owner.id) ?? [];\n list.push(task);\n children.set(owner.id, list);\n } else roots.push(task);\n }\n const sort = (list: MonitorTask[]) =>\n list.sort((a, b) => rank(a) - rank(b) || Number(a.id) - Number(b.id));\n const out: { task: MonitorTask; depth: number }[] = [];\n const visit = (task: MonitorTask, depth: number) => {\n out.push({ task, depth });\n for (const child of sort(children.get(task.id) ?? [])) visit(child, depth + 1);\n };\n for (const root of sort(roots)) visit(root, 0);\n return out;\n}\n\nfunction capped(rows: MonitorRow[]): MonitorRow[] {\n if (rows.length <= ROWS_MAX) return rows;\n const shown = rows.slice(0, ROWS_MAX - 1);\n return [\n ...shown,\n { id: 'more', name: `+${rows.length - shown.length} more`, meta: '', status: 'idle' },\n ];\n}\n\nfunction agentContext(agent: MonitorAgent, models: readonly ModelChoice[]): number | null {\n return contextRatio(agent.context, agent.model, models);\n}\n\nfunction rate(history: readonly Sample[], pick: (sample: Sample) => number): number | null {\n const first = history[0];\n const last = history.at(-1);\n if (!first || !last || last.at - first.at < MINUTE) return null;\n return ((pick(last) - pick(first)) / (last.at - first.at)) * HOUR;\n}\n\nconst RELATIVE = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });\n\nfunction resetsIn(at: number, now: number): string {\n const ms = at - now;\n if (ms <= 0) return 'resets soon';\n if (ms >= DAY)\n return `resets ${RELATIVE.format(Math.floor(at / DAY) - Math.floor(now / DAY), 'day')}`;\n if (ms >= HOUR) return `resets ${RELATIVE.format(Math.floor(ms / HOUR), 'hour')}`;\n return `resets ${RELATIVE.format(Math.ceil(ms / MINUTE), 'minute')}`;\n}\n\nfunction budgetVital(budget: BudgetState, now: number): MonitorVital {\n const resets = new Date(budget.resets);\n return {\n id: 'budget',\n label: `Budget (${budget.window})`,\n value: `${budget.percent}%`,\n ...(Number.isNaN(resets.getTime())\n ? {}\n : {\n unit: resetsIn(resets.getTime(), now),\n hint: `resets ${resets.toISOString().slice(0, 16).replace('T', ' ')} UTC`,\n }),\n ratio: Math.min(1, Math.max(0, budget.percent / 100)),\n };\n}\n\nfunction vitals(input: MonitorInput, feed: MonitorFeed): MonitorVital[] {\n const out: MonitorVital[] = [];\n if (feed.usage) {\n const free = feed.usage.free;\n const pick = (sample: Sample) => (free ? sample.tokens : sample.cost);\n const perHour = rate(input.history, pick);\n const series = input.history.map(pick);\n out.push({\n id: 'spend',\n label: free ? 'Tokens' : 'Spend',\n value: free ? count(feed.usage.tokens) : money(feed.usage.cost),\n unit: free ? 'tokens' : `${count(feed.usage.tokens)} tokens`,\n ...(perHour === null ? {} : { delta: `${free ? count(perHour) : money(perHour)}/h` }),\n ...trend(series),\n });\n }\n const active = feed.agents.filter((agent) => agent.running).length;\n out.push({\n id: 'agents',\n label: 'Active agents',\n value: String(active),\n unit: `of ${feed.agents.length}`,\n ...trend(input.history.map((sample) => sample.active)),\n });\n const tools = feed.tasks.filter(\n (task) => task.kind === 'pi.tool' && task.status === 'running'\n ).length;\n out.push({\n id: 'tasks',\n label: 'Running',\n value: String(tools),\n unit: `${tools === 1 ? 'tool' : 'tools'} \u00B7 ${feed.tasks.length} ${feed.tasks.length === 1 ? 'task' : 'tasks'}`,\n });\n out.push(\n feed.processes\n ? {\n id: 'processes',\n label: 'Processes',\n value: String(feed.processes.length),\n unit: `${feed.processes.filter((row) => row.agentId).length} by agents`,\n ...trend(input.processes),\n }\n : feed.kernel === 'checking'\n ? { id: 'processes', label: 'Processes', value: '\u2026', unit: 'checking' }\n : { id: 'processes', label: 'Processes', value: '\u2014', unit: 'kernel not reachable' }\n );\n out.push(...memoryVital(feed.processes ?? [], input.memory));\n out.push(...cpuVital(feed, input.cpu ?? []));\n const ratios = feed.agents\n .map((agent) => agentContext(agent, input.models))\n .filter((ratio): ratio is number => ratio !== null);\n if (ratios.length) {\n const fullest = Math.max(...ratios);\n out.push({\n id: 'context',\n label: 'Fullest context',\n value: `${Math.round(fullest * 100)}%`,\n ratio: fullest,\n });\n }\n return out;\n}\n\nfunction stale(process: MonitorProcess, agents: ReadonlyMap<string, MonitorAgent>, now: number) {\n if (!process.agentId || process.state === 'Z' || !process.started) return false;\n if (typeof process.utime === 'number') return false;\n if (agents.get(process.agentId)?.tool === 'bash') return false;\n return now - process.started > STALE_MS;\n}\n\nfunction zombied(process: MonitorProcess, now: number): boolean {\n return process.zombie !== null && now - process.zombie > ZOMBIE_MS;\n}\n\nfunction groups(processes: readonly MonitorProcess[]): Map<number, MonitorProcess[]> {\n const out = new Map<number, MonitorProcess[]>();\n for (const process of processes) {\n if (!process.agentId) continue;\n const list = out.get(process.pgid) ?? [];\n list.push(process);\n out.set(process.pgid, list);\n }\n return out;\n}\n\ntype Names = (id: string | null) => string;\n\nexport function groupCpu(\n processes: readonly MonitorProcess[]\n): Map<number, { agentId: string; share: number }> {\n const out = new Map<number, { agentId: string; share: number }>();\n for (const [pgid, members] of groups(processes)) {\n const measured = members.filter((row) => typeof row.cpu === 'number');\n if (!measured.length) continue;\n const share = measured.reduce((sum, row) => sum + (row.cpu as number), 0);\n out.set(pgid, { agentId: (members[0] as MonitorProcess).agentId as string, share });\n }\n return out;\n}\n\nexport function hotGroups(\n processes: readonly MonitorProcess[],\n at: number,\n previous: ReadonlyMap<number, number>\n): Map<number, number> {\n const out = new Map<number, number>();\n for (const [pgid, { share }] of groupCpu(processes))\n if (share >= CPU_SHARE) out.set(pgid, previous.get(pgid) ?? at);\n return out;\n}\n\nfunction busy(input: MonitorInput, processes: readonly MonitorProcess[]) {\n const shares = groupCpu(processes);\n const out: { pgid: number; agentId: string; share: number; held: number }[] = [];\n for (const [pgid, since] of input.hot ?? []) {\n const group = shares.get(pgid);\n const held = input.now - since;\n if (group && group.share >= CPU_SHARE && held >= CPU_SUSTAIN_MS)\n out.push({ pgid, ...group, held });\n }\n return out;\n}\n\nfunction cpuAlerts(input: MonitorInput, processes: readonly MonitorProcess[], nameOf: Names) {\n return busy(input, processes).map(\n (group): AgentMonitorAlert => ({\n id: `runaway-cpu-${group.pgid}`,\n title: `${nameOf(group.agentId)} is using a lot of CPU`,\n detail: `${Math.round(group.share * 100)}% of one core for ${Math.floor(group.held / MINUTE)} minutes.`,\n command: `kill -- -${group.pgid}`,\n commandLabel: 'To stop it, run',\n severity: cpuSeverity(group),\n })\n );\n}\n\nfunction cpuSeverity(group: { share: number; held: number }): 'warn' | 'error' {\n return group.share >= CPU_SHARE * 2 || group.held >= CPU_SUSTAIN_MS * 2 ? 'error' : 'warn';\n}\n\nfunction crowdSeverity(members: readonly MonitorProcess[]): 'warn' | 'error' {\n return members.length > GROUP_MAX * 2 ? 'error' : 'warn';\n}\n\nfunction staleSeverity(process: MonitorProcess, now: number): 'warn' | 'error' {\n return now - process.started > STALE_MS * 2 ? 'error' : 'warn';\n}\n\nfunction worse(\n a: 'warn' | 'error' | undefined,\n b: 'warn' | 'error' | undefined\n): 'warn' | 'error' | undefined {\n return a === 'error' || b === 'error' ? 'error' : (a ?? b);\n}\n\nfunction resetLine(budget: BudgetState): string {\n const resets = new Date(budget.resets);\n return Number.isNaN(resets.getTime())\n ? `The ${budget.window} budget is nearly used up.`\n : `Resets ${resets.toISOString().slice(0, 16).replace('T', ' ')} UTC.`;\n}\n\nfunction budgetAlerts(budget: BudgetState | null | undefined): AgentMonitorAlert[] {\n if (!budget || budget.percent < BUDGET_WARN) return [];\n return [\n {\n id: 'budget',\n title: `Budget ${budget.percent}% used`,\n detail: resetLine(budget),\n severity: budget.percent >= BUDGET_ERROR ? 'error' : 'warn',\n },\n ];\n}\n\nfunction agentAlerts(input: MonitorInput, feed: MonitorFeed): AgentMonitorAlert[] {\n const out: AgentMonitorAlert[] = [];\n for (const agent of feed.agents) {\n const retry = agent.retry;\n if (retry && (retry.attempt >= RETRY_WARN || input.now - retry.since > RETRY_SLOW_MS))\n out.push({\n id: `retry-${agent.id}`,\n title: `${agent.name} is retrying (attempt ${retry.attempt})`,\n detail: retry.error,\n severity: retry.attempt >= RETRY_ERROR ? 'error' : 'warn',\n });\n if (agent.failed && !agent.running)\n out.push({\n id: `turn-${agent.id}`,\n title: `${agent.name}'s last turn failed`,\n detail: agent.failed,\n severity: 'error',\n });\n }\n return out;\n}\n\nfunction taskAlerts(input: MonitorInput, feed: MonitorFeed, nameOf: Names): AgentMonitorAlert[] {\n const out: AgentMonitorAlert[] = [];\n for (const problem of feed.problems)\n if (problem.kind === 'task' && input.now - problem.at < FAILED_MS)\n out.push({\n id: `failed-${problem.id}`,\n title: `A task of ${nameOf(problem.agentId)} failed`,\n detail: problem.message,\n severity: 'error',\n });\n for (const task of feed.tasks)\n if (task.aborting !== null && input.now - task.aborting > ABORT_MS)\n out.push({\n id: `abort-${task.id}`,\n title: `Stop is still waiting for ${taskLabel(task)}`,\n detail: `${nameOf(task.agentId)} asked it to stop ${age(input.now - task.aborting)} ago.`,\n severity: 'warn',\n });\n return out;\n}\n\nfunction crowdAlerts(processes: readonly MonitorProcess[], nameOf: Names): AgentMonitorAlert[] {\n const out: AgentMonitorAlert[] = [];\n for (const [pgid, members] of groups(processes))\n if (members.length > GROUP_MAX)\n out.push({\n id: `runaway-${pgid}`,\n title: `${nameOf((members[0] as MonitorProcess).agentId)} has ${members.length} processes`,\n detail: 'Something in it may be starting processes in a loop.',\n command: `kill -- -${pgid}`,\n commandLabel: 'To stop them, run',\n severity: crowdSeverity(members),\n });\n if (processes.length > TOTAL_MAX)\n out.push({\n id: 'runaway-total',\n title: `The kernel has ${processes.length} processes`,\n detail: 'Something may be starting processes in a loop.',\n severity: processes.length > TOTAL_MAX * 2 ? 'error' : 'warn',\n });\n return out;\n}\n\nfunction processAlerts(input: MonitorInput, feed: MonitorFeed, nameOf: Names): AgentMonitorAlert[] {\n const processes = feed.processes ?? [];\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const out = [...crowdAlerts(processes, nameOf), ...cpuAlerts(input, processes, nameOf)];\n for (const process of processes) {\n if (zombied(process, input.now))\n out.push({\n id: `zombie-${process.pid}`,\n title: `Process ${process.pid} is a zombie`,\n detail: `Its parent ${process.ppid} hasn't reaped it.`,\n ...(process.ppid > 1\n ? { command: `kill ${process.ppid}`, commandLabel: 'To clear it, stop the parent' }\n : {}),\n severity: 'warn',\n });\n if (stale(process, agents, input.now))\n out.push({\n id: `stale-${process.pid}`,\n title: `${process.command || `Process ${process.pid}`} has run for ${age(input.now - process.started)}`,\n detail: `${nameOf(process.agentId)} started it in the background.`,\n command: `kill ${process.pid}`,\n commandLabel: 'To stop it, run',\n severity: staleSeverity(process, input.now),\n });\n }\n return out;\n}\n\nfunction contextAlerts(input: MonitorInput, feed: MonitorFeed): AgentMonitorAlert[] {\n const out: AgentMonitorAlert[] = [];\n for (const agent of feed.agents) {\n const ratio = agentContext(agent, input.models);\n if (ratio !== null && ratio >= CONTEXT_WARN)\n out.push({\n id: `context-${agent.id}`,\n title: `${agent.name} is ${Math.round(ratio * 100)}% full`,\n detail: 'Compact it soon to keep replies fast.',\n severity: 'warn',\n });\n }\n if (feed.paused)\n out.push({\n id: 'scheduler',\n title: \"The agent isn't scheduling work\",\n detail: 'Its scheduler is paused.',\n severity: 'warn',\n });\n return out;\n}\n\nfunction alerts(input: MonitorInput, feed: MonitorFeed): AgentMonitorAlert[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const nameOf: Names = (id) => (id ? (agents.get(id)?.name ?? id) : 'the session');\n return [\n ...budgetAlerts(input.budget),\n ...agentAlerts(input, feed),\n ...taskAlerts(input, feed, nameOf),\n ...processAlerts(input, feed, nameOf),\n ...contextAlerts(input, feed),\n ];\n}\n\nfunction taskRow(\n task: MonitorTask,\n depth: number,\n nameOf: (id: string | null) => string,\n now: number\n): MonitorRow {\n const aborting = task.aborting !== null && now - task.aborting > ABORT_ROW_MS;\n const status: MonitorStatus = aborting\n ? 'warn'\n : task.status === 'running' || task.status === 'completing'\n ? 'active'\n : 'idle';\n const badges = [\n ...(task.background ? ['background'] : []),\n ...(task.aborting !== null ? ['aborting'] : []),\n ...(task.waits ? [`waits on ${task.waits}`] : []),\n ];\n return {\n id: task.id,\n name: taskLabel(task),\n depth: Math.min(depth, DEPTH_MAX),\n meta: [nameOf(task.agentId), task.phase, age(now - task.since)].filter(Boolean).join(' \u00B7 '),\n status,\n ...(badges.length ? { badges } : {}),\n };\n}\n\nfunction drivers(members: readonly MonitorProcess[]): MonitorProcess[] {\n const hot = members.filter((row) => (row.cpu ?? 0) >= CPU_SHARE);\n if (hot.length) return hot;\n const top = members.reduce((best, row) => ((row.cpu ?? 0) > (best.cpu ?? 0) ? row : best));\n return [top];\n}\n\nfunction processRows(input: MonitorInput, feed: MonitorFeed): MonitorRow[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const members = groups(feed.processes ?? []);\n const flagged = new Map<number, 'warn' | 'error'>();\n for (const group of busy(input, feed.processes ?? []))\n for (const row of drivers(members.get(group.pgid) as MonitorProcess[]))\n flagged.set(row.pid, cpuSeverity(group));\n return (feed.processes ?? []).map((process) => {\n const runaway = worse(\n worse(\n flagged.get(process.pid),\n stale(process, agents, input.now) ? staleSeverity(process, input.now) : undefined\n ),\n zombied(process, input.now) ? 'warn' : undefined\n );\n const badges = [\n ...(process.agentId ? [agents.get(process.agentId)?.name ?? process.agentId] : []),\n ...(process.tty ? ['terminal'] : []),\n ];\n return {\n id: String(process.pid),\n name: process.command || `[${process.pid}]`,\n meta: [\n `pid ${process.pid}`,\n process.user,\n typeof process.rss === 'number' ? bytes(process.rss) : null,\n cpuText(process.cpu),\n process.started ? age(input.now - process.started) : null,\n ]\n .filter(Boolean)\n .join(' \u00B7 '),\n status: runaway ?? 'idle',\n ...(badges.length ? { badges } : {}),\n };\n });\n}\n\nconst PROBLEM_KINDS = { task: 'task failed', retry: 'retry', turn: 'turn failed' } as const;\n\nfunction sections(input: MonitorInput, feed: MonitorFeed): MonitorSection[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const nameOf = (id: string | null) => (id ? (agents.get(id)?.name ?? id) : 'session');\n return [\n {\n id: 'tasks',\n label: 'Tasks',\n rows: capped(\n taskTree(feed).map(({ task, depth }) => taskRow(task, depth, nameOf, input.now))\n ),\n },\n { id: 'processes', label: 'Processes', rows: capped(processRows(input, feed)) },\n {\n id: 'problems',\n label: 'Recent problems',\n rows: feed.problems.map((problem) => ({\n id: problem.id,\n name: `${nameOf(problem.agentId)} \u00B7 ${PROBLEM_KINDS[problem.kind]}`,\n meta: problem.message,\n status: problem.kind === 'retry' ? 'warn' : 'error',\n })),\n },\n ];\n}\n\nfunction pageSections(input: MonitorInput): MonitorSection[] {\n return [\n {\n id: 'changes',\n label: 'Pending changes',\n rows: input.changes.map((change) => ({\n id: change.path,\n name: change.path,\n meta: change.status,\n status: 'warn',\n })),\n },\n ...input.extra,\n ];\n}\n\nexport function monitorSnapshot(input: MonitorInput): MonitorSnapshot {\n const budget = input.budget ? [budgetVital(input.budget, input.now)] : [];\n const feed = input.feed;\n if (!feed?.at)\n return {\n vitals: budget,\n alerts: [],\n sections: pageSections(input),\n updatedAt: input.now,\n };\n return {\n vitals: [...budget, ...vitals(input, feed)],\n alerts: alerts(input, feed),\n sections: [...sections(input, feed), ...pageSections(input)],\n updatedAt: feed.at,\n };\n}\n\nexport interface Intervals {\n every(run: () => void, ms: number): unknown;\n stop(handle: unknown): void;\n}\n\nexport const globalIntervals: Intervals = {\n every: (run, ms) => setInterval(run, ms),\n stop: (handle) => clearInterval(handle as ReturnType<typeof setInterval>),\n};\n\nexport interface MonitorAdapterOptions {\n extra?: () => readonly MonitorSection[];\n renewMs?: number;\n sampleMs?: number;\n intervals?: Intervals;\n now?: () => number;\n}\n\ninterface Open {\n lease: Promise<string | null>;\n timer: unknown;\n sampler: unknown;\n}\n\nexport class MonitorAdapter implements MonitorPort {\n readonly #connection: AgentConnection;\n readonly #emitter = new Emitter<MonitorEvents>();\n readonly #extra: () => readonly MonitorSection[];\n readonly #renewMs: number;\n readonly #sampleMs: number;\n readonly #intervals: Intervals;\n readonly #now: () => number;\n #listeners = 0;\n #open: Open | undefined;\n #history: Sample[] = [];\n #hot = new Map<number, number>();\n #hotAt = -1;\n #cpu: number[] = [];\n #processes: number[] = [];\n #memory: number[] = [];\n\n constructor(connection: AgentConnection, options: MonitorAdapterOptions = {}) {\n this.#connection = connection;\n this.#extra = options.extra ?? (() => []);\n this.#renewMs = options.renewMs ?? RENEW_MS;\n this.#sampleMs = options.sampleMs ?? SAMPLE_MS;\n this.#intervals = options.intervals ?? globalIntervals;\n this.#now = options.now ?? Date.now;\n connection.monitor?.subscribe(() => this.#update());\n connection.settings.state.subscribe(() => this.#update());\n connection.changes?.subscribe(() => this.#update());\n }\n\n on<K extends keyof MonitorEvents>(\n type: K,\n listener: (detail: MonitorEvents[K]) => void\n ): () => void {\n const off = this.#emitter.on(type, listener);\n this.#listeners++;\n if (this.#listeners === 1) this.#start();\n let done = false;\n return () => {\n if (done) return;\n done = true;\n off();\n this.#listeners--;\n if (!this.#listeners) this.#stop();\n };\n }\n\n snapshot(): MonitorSnapshot {\n const settings = this.#connection.settings.state.value;\n return monitorSnapshot({\n feed: this.#connection.monitor?.value,\n budget: settings?.budget,\n models: settings?.models ?? [],\n changes: this.#connection.changes?.value?.changes ?? [],\n extra: this.#extra(),\n history: this.#history,\n now: this.#now(),\n hot: this.#hot,\n cpu: this.#cpu,\n processes: this.#processes,\n memory: this.#memory,\n });\n }\n\n resync(): void {\n const open = this.#open;\n const control = this.#connection.control;\n if (open)\n void open.lease\n .then((lease) => (lease ? control.monitorOpen(lease, true, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n this.#emitter.emit('snapshot', this.snapshot());\n }\n\n #start(): void {\n const control = this.#connection.control;\n this.#history = [];\n this.#hot = new Map();\n this.#hotAt = -1;\n this.#cpu = [];\n this.#processes = [];\n this.#memory = [];\n void control.changesOpen(BACKGROUND_CONTEXT).catch(() => undefined);\n const lease = control.monitorOpen(null, true, BACKGROUND_CONTEXT).then(\n (opened) => opened.lease || null,\n () => null\n );\n const renew = () =>\n void lease\n .then((held) => (held ? control.monitorOpen(held, false, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n this.#open = {\n lease,\n timer: this.#intervals.every(renew, this.#renewMs),\n sampler: this.#intervals.every(() => this.#poll(), this.#sampleMs),\n };\n }\n\n #stop(): void {\n const open = this.#open;\n if (!open) return;\n this.#open = undefined;\n this.#intervals.stop(open.timer);\n this.#intervals.stop(open.sampler);\n const control = this.#connection.control;\n void open.lease\n .then((held) => (held ? control.monitorClose(held, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n }\n\n #sample(): void {\n const feed = this.#connection.monitor?.value;\n if (!feed?.open || !feed.usage || this.#history.at(-1)?.at === feed.at) return;\n record(\n this.#history,\n {\n at: feed.at,\n cost: feed.usage.cost,\n tokens: feed.usage.tokens,\n active: feed.agents.filter((agent) => agent.running).length,\n },\n HISTORY\n );\n }\n\n #track(): void {\n const feed = this.#connection.monitor?.value;\n if (!feed?.open || feed.at === this.#hotAt) return;\n this.#hotAt = feed.at;\n this.#hot = hotGroups(feed.processes ?? [], feed.at, this.#hot);\n const share = agentsCpu(feed);\n if (share !== null) record(this.#cpu, share, CPU_HISTORY);\n }\n\n #poll(): void {\n const feed = this.#connection.monitor?.value;\n if (!feed?.open || !feed.processes) return;\n record(this.#processes, feed.processes.length, CPU_HISTORY);\n const memory = memoryTotal(feed.processes);\n if (memory !== null) record(this.#memory, memory, CPU_HISTORY);\n this.#emitter.emit('snapshot', this.snapshot());\n }\n\n #update(): void {\n if (!this.#listeners) return;\n this.#sample();\n this.#track();\n this.#emitter.emit('snapshot', this.snapshot());\n }\n}\n"],
|
|
5
|
+
"mappings": "AAUA,SAAS,0BAA0B;AAEnC,SAAS,oBAAoB;AAS7B,SAAS,eAAe;AAEjB,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,WAAW;AACjB,MAAM,UAAU;AAChB,MAAM,cAAc;AACpB,MAAM,YAAY;AAClB,MAAM,cAAc;AACpB,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d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type Agents } from './agents.ts';
|
|
|
5
5
|
import type { Cones } from './cone.ts';
|
|
6
6
|
import { type GuestToolGate } from './guests/guard.ts';
|
|
7
7
|
import { type GuestReviews } from './guests/review.ts';
|
|
8
|
+
import { type ScoopReviews } from './guests/scoop.ts';
|
|
8
9
|
export interface AgentOptions {
|
|
9
10
|
models: Models;
|
|
10
11
|
model: ModelRef;
|
|
@@ -22,6 +23,7 @@ export interface Agent extends Cones {
|
|
|
22
23
|
readonly agents: Agents;
|
|
23
24
|
readonly reviews: GuestReviews;
|
|
24
25
|
readonly gate: GuestToolGate;
|
|
26
|
+
readonly scoopReviews: ScoopReviews;
|
|
25
27
|
onCone(listener: (conversation: Conversation) => void | Promise<void>): () => void;
|
|
26
28
|
prompt(text: string): Promise<string>;
|
|
27
29
|
close(): Promise<void>;
|
|
@@ -25,16 +25,21 @@ export interface Approvals {
|
|
|
25
25
|
}, context: Context): Promise<Approval>;
|
|
26
26
|
decide(id: string, answer: unknown, reason: string | null, by: Decider, context: Context): Promise<ApprovalDecided>;
|
|
27
27
|
settled(id: string, context: Context): Promise<Approval>;
|
|
28
|
+
assign(id: string, reviewer: string, context: Context): Promise<Approval | undefined>;
|
|
28
29
|
withdraw(id: string, reason: string | null, context: Context): Promise<Approval | undefined>;
|
|
29
30
|
withdrawSeat(seat: string, context: Context): Promise<number>;
|
|
30
31
|
expire(id: string, context: Context): Promise<Approval | undefined>;
|
|
31
32
|
close(): void;
|
|
32
33
|
}
|
|
34
|
+
export interface ScoopRouter {
|
|
35
|
+
route(item: Approval): Promise<void>;
|
|
36
|
+
}
|
|
33
37
|
export interface ApprovalsAttach {
|
|
34
38
|
harness: Pick<Harness, 'commit' | 'documentState'>;
|
|
35
39
|
now?: () => number;
|
|
36
40
|
ttlMs?: number;
|
|
37
41
|
judge?: ApprovalJudge;
|
|
42
|
+
scoops?: ScoopRouter;
|
|
38
43
|
guestAlways?: (kind: ApprovalKind) => boolean;
|
|
39
44
|
sudoApprover?: () => unknown;
|
|
40
45
|
}
|
|
@@ -2,7 +2,7 @@ export type ApprovalKind = 'guest-message' | 'guest-tool' | 'sudo';
|
|
|
2
2
|
export type ApprovalState = 'pending' | 'approved' | 'rejected' | 'unanswered' | 'withdrawn';
|
|
3
3
|
export type ApprovalTier = 'user' | 'agent' | 'cone' | `scoop:${string}`;
|
|
4
4
|
export type ApprovalAnswer = 'once' | 'always' | 'deny';
|
|
5
|
-
export type DecidedBy = 'owner' | 'follower' | 'judge' | 'host'
|
|
5
|
+
export type DecidedBy = 'owner' | 'follower' | 'judge' | 'host' | `scoop:${string}`;
|
|
6
6
|
export type ApprovalRequester = {
|
|
7
7
|
kind: 'guest' | 'agent' | 'user';
|
|
8
8
|
name: string;
|
|
@@ -49,6 +49,7 @@ type Base = {
|
|
|
49
49
|
decidedBy: DecidedBy | null;
|
|
50
50
|
device?: string;
|
|
51
51
|
answer?: 'once' | 'always';
|
|
52
|
+
reviewer?: string;
|
|
52
53
|
reason?: string;
|
|
53
54
|
verdict?: ApprovalVerdict;
|
|
54
55
|
always: boolean;
|
|
@@ -93,13 +94,18 @@ export declare const REASONS: {
|
|
|
93
94
|
readonly revoked: 'revoked';
|
|
94
95
|
readonly aborted: 'aborted';
|
|
95
96
|
readonly disconnected: 'disconnected';
|
|
97
|
+
readonly noScoop: 'no-scoop';
|
|
98
|
+
readonly scoopStopped: 'scoop-stopped';
|
|
99
|
+
readonly scoopAsked: 'scoop-asked';
|
|
100
|
+
readonly scoopUndecided: 'scoop-undecided';
|
|
96
101
|
};
|
|
97
102
|
export declare const guestKind: (kind: ApprovalKind) => boolean;
|
|
103
|
+
export declare const scoopTier: (tier: unknown) => tier is `scoop:${string}`;
|
|
98
104
|
export declare function knownTier(tier: unknown): tier is ApprovalTier;
|
|
99
105
|
export declare function routable(kind: ApprovalKind, tier: ApprovalTier): boolean;
|
|
100
106
|
export declare function answerOf(value: unknown): ApprovalAnswer | null;
|
|
101
107
|
export declare const personal: (by: DecidedBy) => boolean;
|
|
102
|
-
export declare function answerer(by: DecidedBy,
|
|
108
|
+
export declare function answerer(by: DecidedBy, item: Pick<Approval, 'tier' | 'reviewer'>): boolean;
|
|
103
109
|
export type SudoApprover = 'user' | 'agent';
|
|
104
110
|
export declare const sudoApprover: (value: unknown) => SudoApprover;
|
|
105
111
|
export declare const tierOf: (kind: ApprovalKind, tier: string, sudo: SudoApprover) => string;
|
|
@@ -31,6 +31,7 @@ export interface GelatiereAttach {
|
|
|
31
31
|
profile?: string;
|
|
32
32
|
shared?: string;
|
|
33
33
|
as?: (caller: string | null, context: Context) => Promise<Caller | undefined>;
|
|
34
|
+
cronUser?: (folder: string) => Promise<string>;
|
|
34
35
|
}
|
|
35
36
|
export interface Caller {
|
|
36
37
|
env: ExecutionEnv;
|
|
@@ -42,7 +43,7 @@ export interface GelatiereRuntime {
|
|
|
42
43
|
readonly seeded: Promise<Seeded>;
|
|
43
44
|
}
|
|
44
45
|
export declare const USAGE = "usage:\n gelatiere init start the gelatiere scoop and its nightly crontab line\n gelatiere run ask the gelatiere for a pass now\n gelatiere suggest <file> fold a JSON array of suggestions into the store\n gelatiere deliver lick each cone with the suggestions that are new for it\n gelatiere catalog [--refresh] [--all] [--json]\n rank the www.sliccy.com skill and use-case catalog for this user\n gelatiere install <id> install a suggested skill with upskill into ~/.pi/agent/skills\n gelatiere list [--all] [--json]\n gelatiere dismiss <id> mark a suggestion as not wanted\n gelatiere status\n\nThe store is /home/.gelatiere/suggestions.json; the suggestions sprinkle shows it.\n";
|
|
45
|
-
export declare
|
|
46
|
+
export declare const PASS = "Nightly pass: read ~/.pi/agent/GELATIERE.md and follow it.";
|
|
46
47
|
export declare const SHIPPED: string[];
|
|
47
48
|
export type Seeded = 'written' | 'updated' | 'current' | 'kept' | 'none';
|
|
48
49
|
export declare const INSTALLER = "https://raw.githubusercontent.com/ai-ecoverse/gh-upskill/main/install.sh";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Context } from '@earendil-works/chord';
|
|
2
|
+
import { type Extension, type Harness, type SubmissionId } from '@earendil-works/pi-durable';
|
|
2
3
|
import type { Approval, Approvals } from '../approvals/index.ts';
|
|
3
4
|
import { type GuestPolicy } from './policy.ts';
|
|
5
|
+
import { type SeatRecord } from './seats.ts';
|
|
4
6
|
export declare const GUEST_GUARD = "slicc-guest-guard";
|
|
5
7
|
export declare const GUEST_REQUEST = "guest:";
|
|
6
8
|
export declare const GUEST_TOOL_MEMO = "slicc.guest-tool";
|
|
@@ -12,7 +14,6 @@ export declare const GATE_REASONS: {
|
|
|
12
14
|
readonly judged: 'The automatic check declined this tool call in a run a guest started';
|
|
13
15
|
readonly unanswered: 'Nobody approved this tool call in a run a guest started in time.';
|
|
14
16
|
readonly unroutable: "The cone can't review a tool call it is itself waiting on.";
|
|
15
|
-
readonly scoop: "This review isn't available yet.";
|
|
16
17
|
readonly withdrawn: 'The review of this tool call was withdrawn.';
|
|
17
18
|
};
|
|
18
19
|
export interface GateHost {
|
|
@@ -25,8 +26,13 @@ export interface GuestToolGate {
|
|
|
25
26
|
bind(host: GateHost): void;
|
|
26
27
|
}
|
|
27
28
|
type Held = Pick<Harness, 'submission' | 'commit' | 'waitForTask'>;
|
|
29
|
+
type Taint = {
|
|
30
|
+
seat: SeatRecord | null;
|
|
31
|
+
tier: string;
|
|
32
|
+
};
|
|
28
33
|
export declare function canonical(value: unknown): string;
|
|
29
34
|
export declare function summaryOf(args: Record<string, unknown>): string;
|
|
30
35
|
export declare function reasonOf(item: Approval): string;
|
|
36
|
+
export declare function taintsOf(inputs: readonly SubmissionId[], seats: Readonly<Record<string, SeatRecord>>, harness: Pick<Harness, 'submission'>, context: Context): Promise<Taint[]>;
|
|
31
37
|
export declare function guestToolGate(harness: () => Held | undefined): GuestToolGate;
|
|
32
38
|
export {};
|
|
@@ -13,7 +13,6 @@ export type GuestPolicy = {
|
|
|
13
13
|
export type GuestPolicyChange = Partial<GuestPolicy>;
|
|
14
14
|
export declare const GATE_KINDS: readonly GateKind[];
|
|
15
15
|
export declare const DEFAULT_GUEST_POLICY: GuestPolicy;
|
|
16
|
-
export declare const SCOOP_REVIEW_LATER = "This review isn't available yet.";
|
|
17
16
|
export declare const MAX_SEAT_DAYS = 365;
|
|
18
17
|
export declare const DAY_MS: number;
|
|
19
18
|
export declare const GUESTS_MANAGE_DENIED = "The owner's guest policy doesn't let guests manage guests.";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Context } from '@earendil-works/chord';
|
|
2
|
+
import { type Extension, type Harness } from '@earendil-works/pi-durable';
|
|
3
|
+
import { type AgentsState, type ScoopRecord } from '../agents.ts';
|
|
4
|
+
import type { Approval, Approvals } from '../approvals/index.ts';
|
|
5
|
+
import { type OwnerIntent } from '../approvals/judge.ts';
|
|
6
|
+
export declare const SCOOP_DECIDE = "approval_decide";
|
|
7
|
+
export declare const SCOOP_APPROVALS = "slicc-scoop-approvals";
|
|
8
|
+
export declare const SCOOP_REVIEW_TASK = "slicc.scoop-approval";
|
|
9
|
+
export declare const SCOOP_REQUEST = "scoop-approval:";
|
|
10
|
+
export type ScoopReview = {
|
|
11
|
+
approval: string;
|
|
12
|
+
scoop: string;
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const ScoopReviewDoc: import("@earendil-works/pi-durable").ConversationDocToken<ScoopReview>;
|
|
16
|
+
export declare const ScoopRoutesDoc: import("@earendil-works/pi-durable").SessionDocToken<{
|
|
17
|
+
routes: Record<string, number>;
|
|
18
|
+
}>;
|
|
19
|
+
export interface ScoopReviewHost {
|
|
20
|
+
approvals: Pick<Approvals, 'decide' | 'assign'>;
|
|
21
|
+
agents: {
|
|
22
|
+
state(): Readonly<AgentsState>;
|
|
23
|
+
};
|
|
24
|
+
harness: Pick<Harness, 'commit'>;
|
|
25
|
+
intent?: (item: Approval, context: Context) => Promise<OwnerIntent | null>;
|
|
26
|
+
nonce?: () => string;
|
|
27
|
+
}
|
|
28
|
+
export interface ScoopReviews {
|
|
29
|
+
readonly extension: Extension;
|
|
30
|
+
route(item: Approval): Promise<void>;
|
|
31
|
+
bind(host: ScoopReviewHost): void;
|
|
32
|
+
}
|
|
33
|
+
export type Reviewer = {
|
|
34
|
+
id: string;
|
|
35
|
+
record: ScoopRecord;
|
|
36
|
+
};
|
|
37
|
+
export declare function reviewerOf(state: Readonly<AgentsState>, agentId: string, tier: string): Reviewer | undefined;
|
|
38
|
+
export declare function askedOf(item: Approval, reviewer: Reviewer): boolean;
|
|
39
|
+
export declare function reviewersOf(harness: Pick<Harness, 'snapshot' | 'submission'>, state: Readonly<AgentsState>, cone: string, context: Context): Promise<string[]>;
|
|
40
|
+
export declare function reviewPrompt(item: Approval, name: string, seat: {
|
|
41
|
+
id: string;
|
|
42
|
+
label: string;
|
|
43
|
+
gates: object;
|
|
44
|
+
} | null, intent: OwnerIntent | null, nonce: string): string;
|
|
45
|
+
export declare function scoopReviews(): ScoopReviews;
|
package/dist/types/host.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { ChangesRuntime } from './changes/index.ts';
|
|
|
6
6
|
import { type HostLicks, type HostScoops } from './control.ts';
|
|
7
7
|
import type { FreezerRuntime } from './freezer/index.ts';
|
|
8
8
|
import { type Guests } from './guests/index.ts';
|
|
9
|
+
import type { ScoopReviewHost } from './guests/scoop.ts';
|
|
9
10
|
import type { UserClients } from './kernel/users.ts';
|
|
10
11
|
import type { McpRuntime } from './mcp/index.ts';
|
|
11
12
|
import type { MemoryRuntime } from './memory/index.ts';
|
|
@@ -67,6 +68,8 @@ export declare function hostAgent(agent: Agent, options?: {
|
|
|
67
68
|
labels?: LabelsRuntime;
|
|
68
69
|
approvals?: Approvals;
|
|
69
70
|
judge?: ApprovalJudge;
|
|
71
|
+
intent?: ScoopReviewHost['intent'];
|
|
72
|
+
approvalMs?: number;
|
|
70
73
|
}): Promise<AgentHost>;
|
|
71
74
|
interface Served {
|
|
72
75
|
trusted: AgentControl;
|
|
@@ -2,6 +2,7 @@ import type { Context } from '@earendil-works/chord';
|
|
|
2
2
|
import type { Agents, AgentsState } from '../agents.ts';
|
|
3
3
|
import type { GelatiereAttach } from '../gelatiere/index.ts';
|
|
4
4
|
import { type Layout } from '../layout.ts';
|
|
5
|
+
import type { LickTarget } from '../licks/lick.ts';
|
|
5
6
|
import type { LickDir } from '../licks/sources.ts';
|
|
6
7
|
import type { Spools } from '../scoops/index.ts';
|
|
7
8
|
import type { SkillPeople } from '../skills/index.ts';
|
|
@@ -21,6 +22,7 @@ export interface AgentUsers {
|
|
|
21
22
|
reconcile?(context: Context): Promise<void>;
|
|
22
23
|
}[]): void;
|
|
23
24
|
lickDirs(): Promise<LickDir[]>;
|
|
25
|
+
cronUser(target: LickTarget, place: LickDir): string | undefined;
|
|
24
26
|
sprinklePlaces(): SprinklePlace[];
|
|
25
27
|
sprinkles(): Partial<SprinklesAttach>;
|
|
26
28
|
envOfAgent(agentId: string): Promise<SliccKernelEnv | undefined>;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { Context } from '@earendil-works/chord';
|
|
2
|
-
import type
|
|
2
|
+
import { type Conversation, type EntryRecord, type Harness } from '@earendil-works/pi-durable';
|
|
3
3
|
import type { Deliver } from './fswatch.ts';
|
|
4
|
+
type HostState = {
|
|
5
|
+
cron: Record<string, {
|
|
6
|
+
task: number;
|
|
7
|
+
}>;
|
|
8
|
+
agent: string | null;
|
|
9
|
+
boot: string | null;
|
|
10
|
+
mark: number;
|
|
11
|
+
upgrades: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const LicksHostDoc: import("@earendil-works/pi-durable").SessionDocToken<HostState>;
|
|
4
14
|
export interface BootFacts {
|
|
5
15
|
version: string;
|
|
6
16
|
boot: string | null;
|
|
7
17
|
}
|
|
8
18
|
export declare function bashCommands(entries: readonly EntryRecord[], after: number): string[];
|
|
9
19
|
export declare function bootLicks(harness: Harness, cone: Conversation, deliver: Deliver, facts: BootFacts, context: Context): Promise<void>;
|
|
20
|
+
export {};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import type { LickTarget } from './lick.ts';
|
|
2
|
-
export interface CronEntry {
|
|
3
|
-
name: string;
|
|
4
|
-
schedule: string;
|
|
5
|
-
target: LickTarget;
|
|
6
|
-
message: string;
|
|
7
|
-
}
|
|
8
2
|
export interface WatchEntry {
|
|
9
3
|
name: string;
|
|
10
4
|
path: string;
|
|
@@ -31,7 +25,6 @@ export interface Parsed<T> {
|
|
|
31
25
|
}
|
|
32
26
|
export declare function isName(value: string): boolean;
|
|
33
27
|
export declare function isTarget(value: string): value is LickTarget;
|
|
34
|
-
export declare function parseCrontab(file: string, text: string): Parsed<CronEntry>;
|
|
35
28
|
export declare function nameOf(file: string): string;
|
|
36
29
|
export declare function parseWatch(file: string, source: string, home: string): WatchEntry;
|
|
37
30
|
export declare function parseWebhook(file: string, source: string): WebhookEntry;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Context } from '@earendil-works/chord';
|
|
2
|
+
import type { ExecutionEnv } from '@earendil-works/pi-durable/env';
|
|
3
|
+
import type { LickTarget } from './lick.ts';
|
|
4
|
+
import type { LickEvent } from './licks.ts';
|
|
5
|
+
export interface CronJob {
|
|
6
|
+
name: string;
|
|
7
|
+
schedule: string;
|
|
8
|
+
command: string;
|
|
9
|
+
line?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface CronProblem {
|
|
12
|
+
line?: number;
|
|
13
|
+
error: string;
|
|
14
|
+
}
|
|
15
|
+
export interface LegacyJob {
|
|
16
|
+
name: string;
|
|
17
|
+
schedule: string;
|
|
18
|
+
target: LickTarget;
|
|
19
|
+
message: string;
|
|
20
|
+
line: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function legacyJobs(text: string): {
|
|
23
|
+
jobs: LegacyJob[];
|
|
24
|
+
problems: CronProblem[];
|
|
25
|
+
};
|
|
26
|
+
export declare function sendCommand(target: LickTarget, message: string): string;
|
|
27
|
+
export declare function readTable(env: ExecutionEnv, user: string, context: Context): Promise<string | CronProblem>;
|
|
28
|
+
export declare function withoutJobs(table: string, names: ReadonlySet<string>): string[];
|
|
29
|
+
export declare function scheduleOf(table: string, name: string): string | undefined;
|
|
30
|
+
export declare function installJobs(env: ExecutionEnv, user: string, jobs: readonly CronJob[], context: Context): Promise<CronProblem[]>;
|
|
31
|
+
export interface CronRun {
|
|
32
|
+
job: string;
|
|
33
|
+
due: string;
|
|
34
|
+
missed: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function cronText(run: CronRun, at: number): string;
|
|
37
|
+
export declare function cronLick(run: CronRun, target: LickTarget, message: string): LickEvent;
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import type { Context } from '@earendil-works/chord';
|
|
2
2
|
import { type Conversation, type ConversationId } from '@earendil-works/pi-durable';
|
|
3
|
-
import { type Missed } from './cron.ts';
|
|
4
|
-
import type { LickTarget } from './lick.ts';
|
|
5
3
|
import type { Licks } from './licks.ts';
|
|
6
4
|
export declare const LICKS_SECTION: string;
|
|
7
5
|
export type ConversationLookup = (id: ConversationId, context: Context) => Promise<Conversation>;
|
|
8
|
-
export
|
|
9
|
-
name: string;
|
|
10
|
-
schedule: string;
|
|
11
|
-
target: LickTarget;
|
|
12
|
-
message: string;
|
|
13
|
-
from: number;
|
|
14
|
-
}
|
|
15
|
-
type CronState = {
|
|
16
|
-
phase: 'wait';
|
|
17
|
-
at: number | null;
|
|
18
|
-
};
|
|
19
|
-
export declare function cronText(schedule: string, at: number, missed: Missed): string;
|
|
20
|
-
export declare function cronTask(licks: Licks): import("@earendil-works/pi-durable").Task<CronInput, CronState, null, object>;
|
|
21
|
-
export declare function licksExtension(licks: Licks, conversation: ConversationLookup, cron?: ReturnType<typeof cronTask>): import("@earendil-works/pi-durable").Extension<import("@earendil-works/pi-durable").ToolRegistration>;
|
|
22
|
-
export {};
|
|
6
|
+
export declare function licksExtension(licks: Licks, conversation: ConversationLookup): import("@earendil-works/pi-durable").Extension<import("@earendil-works/pi-durable").ToolRegistration>;
|
|
@@ -18,10 +18,10 @@ export interface LicksSetup {
|
|
|
18
18
|
attach(agent: LicksAgent, options: {
|
|
19
19
|
env: ExecutionEnv;
|
|
20
20
|
home: string;
|
|
21
|
-
now?: () => number;
|
|
22
21
|
flushEvery?: number;
|
|
23
22
|
activity?: Activity;
|
|
24
23
|
dirs?: () => Promise<readonly LickDir[]>;
|
|
24
|
+
cronUser?: (target: LickTarget, place: LickDir) => string | undefined;
|
|
25
25
|
}): LickSources;
|
|
26
26
|
}
|
|
27
27
|
export declare function setupLicks(registry: Registry): LicksSetup;
|
|
@@ -4,7 +4,6 @@ import type { ExecutionEnv } from '@earendil-works/pi-durable/env';
|
|
|
4
4
|
import type { Activity } from '../kernel/activity.ts';
|
|
5
5
|
import { type BootFacts } from './boot.ts';
|
|
6
6
|
import { type ConfigError, type WebhookEntry } from './config.ts';
|
|
7
|
-
import type { cronTask } from './extension.ts';
|
|
8
7
|
import type { LickTarget } from './lick.ts';
|
|
9
8
|
import type { LickEvent, Licks } from './licks.ts';
|
|
10
9
|
export declare const SLICC_DIR = ".slicc";
|
|
@@ -15,11 +14,10 @@ export interface LickSourcesOptions {
|
|
|
15
14
|
env: ExecutionEnv;
|
|
16
15
|
home: string;
|
|
17
16
|
licks: Licks;
|
|
18
|
-
cron: ReturnType<typeof cronTask>;
|
|
19
|
-
now?: () => number;
|
|
20
17
|
flushEvery?: number;
|
|
21
18
|
activity?: Activity;
|
|
22
19
|
dirs?: () => readonly LickDir[] | Promise<readonly LickDir[]>;
|
|
20
|
+
cronUser?: (target: LickTarget, place: LickDir) => string | undefined;
|
|
23
21
|
}
|
|
24
22
|
export interface LickDir {
|
|
25
23
|
dir: string;
|
package/dist/types/main.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export interface AgentWorkerOptions {
|
|
|
31
31
|
catalog?: string;
|
|
32
32
|
users?: boolean;
|
|
33
33
|
mcpRedirect?: string;
|
|
34
|
+
approvalMs?: number;
|
|
34
35
|
}
|
|
35
36
|
export declare function usersOf(admin: MessagePort | undefined, wanted: boolean | undefined, attach: KernelAttach): UserClients | undefined;
|
|
36
37
|
export declare const STORE_DIR = "/.slicc";
|