@pellux/goodvibes-tui 0.18.12 → 0.18.13
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/CHANGELOG.md +50 -0
- package/README.md +1 -1
- package/docs/foundation-artifacts/operator-contract.json +1 -1
- package/package.json +2 -2
- package/src/config/index.ts +1 -138
- package/src/config/subscription-providers.ts +1 -127
- package/src/core/conversation-rendering.ts +3 -3
- package/src/core/conversation.ts +176 -423
- package/src/core/history.ts +45 -0
- package/src/core/orchestrator.ts +3 -735
- package/src/core/system-message-router.ts +19 -58
- package/src/input/handler-content-actions.ts +2 -2
- package/src/input/handler-feed.ts +1 -1
- package/src/input/handler-modal-token-routes.ts +1 -1
- package/src/input/handler-ui-state.ts +1 -1
- package/src/input/handler.ts +1 -1
- package/src/input/search.ts +1 -1
- package/src/input/selection.ts +2 -2
- package/src/main.ts +1 -1
- package/src/panels/agent-inspector-panel.ts +3 -3
- package/src/panels/agent-logs-panel.ts +3 -3
- package/src/panels/approval-panel.ts +2 -2
- package/src/panels/automation-control-panel.ts +3 -3
- package/src/panels/base-panel.ts +14 -14
- package/src/panels/builtin/operations.ts +1 -1
- package/src/panels/builtin/session.ts +1 -1
- package/src/panels/builtin/shared.ts +3 -3
- package/src/panels/cockpit-panel.ts +2 -2
- package/src/panels/communication-panel.ts +3 -3
- package/src/panels/context-visualizer-panel.ts +2 -2
- package/src/panels/control-plane-panel.ts +3 -3
- package/src/panels/cost-tracker-panel.ts +3 -3
- package/src/panels/debug-panel.ts +2 -2
- package/src/panels/diff-panel.ts +2 -2
- package/src/panels/docs-panel.ts +1 -1
- package/src/panels/eval-panel.ts +2 -2
- package/src/panels/file-explorer-panel.ts +3 -3
- package/src/panels/file-preview-panel.ts +3 -3
- package/src/panels/forensics-panel.ts +2 -2
- package/src/panels/git-panel.ts +1 -1
- package/src/panels/hooks-panel.ts +3 -3
- package/src/panels/incident-review-panel.ts +1 -1
- package/src/panels/intelligence-panel.ts +2 -2
- package/src/panels/knowledge-panel.ts +1 -1
- package/src/panels/local-auth-panel.ts +2 -2
- package/src/panels/marketplace-panel.ts +1 -1
- package/src/panels/mcp-panel.ts +3 -3
- package/src/panels/memory-panel.ts +1 -1
- package/src/panels/ops-control-panel.ts +3 -3
- package/src/panels/ops-strategy-panel.ts +2 -2
- package/src/panels/orchestration-panel.ts +2 -2
- package/src/panels/panel-list-panel.ts +6 -6
- package/src/panels/plan-dashboard-panel.ts +1 -1
- package/src/panels/plugins-panel.ts +2 -2
- package/src/panels/policy-panel.ts +2 -2
- package/src/panels/polish.ts +3 -3
- package/src/panels/provider-accounts-panel.ts +2 -2
- package/src/panels/provider-health-panel.ts +2 -2
- package/src/panels/provider-stats-panel.ts +3 -3
- package/src/panels/remote-panel.ts +3 -3
- package/src/panels/routes-panel.ts +3 -3
- package/src/panels/sandbox-panel.ts +2 -2
- package/src/panels/schedule-panel.ts +1 -1
- package/src/panels/security-panel.ts +2 -2
- package/src/panels/services-panel.ts +2 -2
- package/src/panels/session-browser-panel.ts +2 -2
- package/src/panels/settings-sync-panel.ts +2 -2
- package/src/panels/skills-panel.ts +6 -6
- package/src/panels/subscription-panel.ts +2 -2
- package/src/panels/symbol-outline-panel.ts +3 -3
- package/src/panels/system-messages-panel.ts +4 -4
- package/src/panels/tasks-panel.ts +2 -2
- package/src/panels/thinking-panel.ts +3 -3
- package/src/panels/token-budget-panel.ts +1 -1
- package/src/panels/tool-inspector-panel.ts +3 -3
- package/src/panels/types.ts +5 -5
- package/src/panels/watchers-panel.ts +3 -3
- package/src/panels/welcome-panel.ts +1 -1
- package/src/panels/worktree-panel.ts +2 -2
- package/src/panels/wrfc-panel.ts +3 -3
- package/src/permissions/prompt.ts +3 -22
- package/src/plugins/loader.ts +15 -304
- package/src/renderer/agent-detail-modal.ts +1 -1
- package/src/renderer/autocomplete-overlay.ts +2 -2
- package/src/renderer/bookmark-modal.ts +1 -1
- package/src/renderer/bottom-bar.ts +2 -2
- package/src/renderer/buffer.ts +1 -1
- package/src/renderer/code-block.ts +2 -2
- package/src/renderer/compositor.ts +2 -2
- package/src/renderer/context-inspector.ts +1 -1
- package/src/renderer/conversation-layout.ts +2 -2
- package/src/renderer/conversation-overlays.ts +1 -1
- package/src/renderer/conversation-surface.ts +2 -2
- package/src/renderer/diff-view.ts +2 -2
- package/src/renderer/diff.ts +1 -1
- package/src/renderer/file-picker-overlay.ts +2 -2
- package/src/renderer/file-tree.ts +2 -2
- package/src/renderer/help-overlay.ts +1 -1
- package/src/renderer/history-search-overlay.ts +2 -2
- package/src/renderer/live-tail-modal.ts +1 -1
- package/src/renderer/markdown.ts +2 -2
- package/src/renderer/modal-factory.ts +3 -3
- package/src/renderer/model-picker-overlay.ts +2 -2
- package/src/renderer/overlay-box.ts +2 -2
- package/src/renderer/panel-composite.ts +1 -1
- package/src/renderer/panel-picker-overlay.ts +2 -2
- package/src/renderer/panel-tab-bar.ts +1 -1
- package/src/renderer/panel-workspace-bar.ts +1 -1
- package/src/renderer/process-indicator.ts +2 -2
- package/src/renderer/process-modal.ts +1 -1
- package/src/renderer/profile-picker-modal.ts +2 -2
- package/src/renderer/progress.ts +2 -2
- package/src/renderer/search-overlay.ts +2 -2
- package/src/renderer/selection-modal-overlay.ts +2 -2
- package/src/renderer/session-picker-modal.ts +2 -2
- package/src/renderer/settings-modal.ts +2 -2
- package/src/renderer/shell-surface.ts +1 -1
- package/src/renderer/system-message.ts +1 -1
- package/src/renderer/tab-strip.ts +2 -2
- package/src/renderer/text-layout.ts +1 -1
- package/src/renderer/thinking.ts +1 -1
- package/src/renderer/tool-call.ts +2 -2
- package/src/renderer/ui-factory.ts +2 -2
- package/src/runtime/bootstrap-command-context.ts +4 -5
- package/src/runtime/bootstrap-command-parts.ts +1 -3
- package/src/runtime/bootstrap-core.ts +3 -2
- package/src/runtime/bootstrap-hook-bridge.ts +15 -174
- package/src/runtime/bootstrap-shell.ts +4 -4
- package/src/runtime/bootstrap.ts +1 -1
- package/src/runtime/context.ts +4 -20
- package/src/runtime/diagnostics/panels/index.ts +1 -1
- package/src/runtime/diagnostics/panels/ops.ts +1 -1
- package/src/runtime/diagnostics/panels/panel-resources.ts +118 -0
- package/src/runtime/perf/panel-contracts.ts +32 -0
- package/src/runtime/perf/panel-health-monitor.ts +18 -0
- package/src/runtime/services.ts +4 -4
- package/src/runtime/store/domains/conversation.ts +1 -181
- package/src/runtime/store/domains/permissions.ts +1 -143
- package/src/runtime/store/helpers/reducers/conversation.ts +1 -228
- package/src/runtime/store/helpers/reducers/lifecycle.ts +1 -440
- package/src/runtime/store/selectors/index.ts +11 -6
- package/src/runtime/store/state.ts +12 -4
- package/src/runtime/ui-events.ts +46 -0
- package/src/runtime/ui-services.ts +1 -1
- package/src/shell/ui-openers.ts +1 -1
- package/src/tools/index.ts +1 -186
- package/src/types/grid.ts +48 -0
- package/src/utils/clipboard.ts +21 -0
- package/src/utils/splash-lines.ts +1 -1
- package/src/utils/terminal-width.ts +185 -0
- package/src/version.ts +1 -1
- package/src/daemon/facade-composition.ts +0 -398
- package/src/daemon/facade.ts +0 -638
- package/src/daemon/surface-policy.ts +0 -60
- package/src/daemon/types.ts +0 -191
- package/src/runtime/ui-read-models-core.ts +0 -95
- package/src/runtime/ui-read-models-operations.ts +0 -203
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Panel resource contracts — backward-compat shim.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the SDK's component contract types and helpers. TUI code that
|
|
5
|
+
* previously used local `ComponentResourceContract` / `ComponentHealthState`
|
|
6
|
+
* types (with `panelId`) now uses the SDK types (with `componentId`).
|
|
7
|
+
*
|
|
8
|
+
* Backward-compat aliases are re-exported:
|
|
9
|
+
* - `PanelResourceContract` = `Omit<ComponentResourceContract,'componentId'> & { panelId }`
|
|
10
|
+
* - `PanelHealthState` = `Omit<ComponentHealthState,'componentId'> & { panelId }`
|
|
11
|
+
*
|
|
12
|
+
* These keep TUI-internal code that still uses `.panelId` compiling while
|
|
13
|
+
* the broader migration to `.componentId` proceeds.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export type {
|
|
17
|
+
ComponentThrottleStatus,
|
|
18
|
+
ComponentHealthStatus,
|
|
19
|
+
ComponentResourceContract,
|
|
20
|
+
ComponentHealthState,
|
|
21
|
+
PanelThrottleStatus,
|
|
22
|
+
PanelHealthStatus,
|
|
23
|
+
PanelResourceContract,
|
|
24
|
+
PanelHealthState,
|
|
25
|
+
} from '@pellux/goodvibes-sdk/platform/runtime/perf/component-contracts';
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
CATEGORY_CONTRACTS,
|
|
29
|
+
buildContract,
|
|
30
|
+
createInitialComponentHealthState,
|
|
31
|
+
createInitialPanelHealthState,
|
|
32
|
+
} from '@pellux/goodvibes-sdk/platform/runtime/perf/component-contracts';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Panel health monitor — backward-compat shim.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the SDK's ComponentHealthMonitor so that the TUI and the SDK
|
|
5
|
+
* share a single class declaration. This eliminates the TypeScript nominal
|
|
6
|
+
* incompatibility that arises from two classes having separate `private`
|
|
7
|
+
* field declarations with the same name.
|
|
8
|
+
*
|
|
9
|
+
* All call-sites that previously imported the TUI-local ComponentHealthMonitor
|
|
10
|
+
* now receive the SDK's canonical class without any behavioral change —
|
|
11
|
+
* the public API is identical (register/deregister/canRender/recordRender/
|
|
12
|
+
* getHealth/getAllHealth/getContract/resetHealth).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
ComponentHealthMonitor,
|
|
17
|
+
PanelHealthMonitor,
|
|
18
|
+
} from '@pellux/goodvibes-sdk/platform/runtime/perf/component-health-monitor';
|
package/src/runtime/services.ts
CHANGED
|
@@ -62,7 +62,7 @@ import { ProjectIndex } from '@pellux/goodvibes-sdk/platform/state/project-index
|
|
|
62
62
|
import { IdempotencyStore } from '@pellux/goodvibes-sdk/platform/runtime/idempotency/index';
|
|
63
63
|
import { OverflowHandler } from '@pellux/goodvibes-sdk/platform/tools/shared/overflow';
|
|
64
64
|
import { ToolLLM } from '@pellux/goodvibes-sdk/platform/config/tool-llm';
|
|
65
|
-
import {
|
|
65
|
+
import { ComponentHealthMonitor } from '@pellux/goodvibes-sdk/platform/runtime/perf/component-health-monitor';
|
|
66
66
|
import { WorktreeRegistry } from '@pellux/goodvibes-sdk/platform/runtime/worktree/registry';
|
|
67
67
|
import { SandboxSessionRegistry } from '@pellux/goodvibes-sdk/platform/runtime/sandbox/session-registry';
|
|
68
68
|
import { createShellPathService, type ShellPathService } from '@pellux/goodvibes-sdk/platform/runtime/shell-paths';
|
|
@@ -133,7 +133,7 @@ export interface RuntimeServices {
|
|
|
133
133
|
readonly channelPolicy: ChannelPolicyManager;
|
|
134
134
|
readonly mcpRegistry: McpRegistry;
|
|
135
135
|
readonly tokenAuditor: ApiTokenAuditor;
|
|
136
|
-
readonly
|
|
136
|
+
readonly componentHealthMonitor: ComponentHealthMonitor;
|
|
137
137
|
readonly worktreeRegistry: WorktreeRegistry;
|
|
138
138
|
readonly sandboxSessionRegistry: SandboxSessionRegistry;
|
|
139
139
|
readonly webhookNotifier: WebhookNotifier;
|
|
@@ -393,7 +393,7 @@ export function createRuntimeServices(options: RuntimeServicesOptions): RuntimeS
|
|
|
393
393
|
mcpRegistry.setRuntimeBus(options.runtimeBus);
|
|
394
394
|
mcpRegistry.setSandboxRuntime(configManager, sandboxSessionRegistry);
|
|
395
395
|
const tokenAuditor = new ApiTokenAuditor({ managed: false });
|
|
396
|
-
const
|
|
396
|
+
const componentHealthMonitor = new ComponentHealthMonitor();
|
|
397
397
|
const worktreeRegistry = new WorktreeRegistry(workingDirectory);
|
|
398
398
|
const webhookNotifier = new WebhookNotifier();
|
|
399
399
|
const replayEngine = new DeterministicReplayEngine(workingDirectory);
|
|
@@ -511,7 +511,7 @@ export function createRuntimeServices(options: RuntimeServicesOptions): RuntimeS
|
|
|
511
511
|
channelPolicy,
|
|
512
512
|
mcpRegistry,
|
|
513
513
|
tokenAuditor,
|
|
514
|
-
|
|
514
|
+
componentHealthMonitor,
|
|
515
515
|
worktreeRegistry,
|
|
516
516
|
sandboxSessionRegistry,
|
|
517
517
|
webhookNotifier,
|
|
@@ -1,181 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Conversation domain state — tracks the active turn lifecycle,
|
|
3
|
-
* message buffer, streaming deltas, and tool dispatch state.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { TurnStopReason } from '@pellux/goodvibes-sdk/platform/runtime/events/turn';
|
|
7
|
-
|
|
8
|
-
/** States for the turn lifecycle machine. */
|
|
9
|
-
export type TurnState =
|
|
10
|
-
| 'idle'
|
|
11
|
-
| 'preflight'
|
|
12
|
-
| 'streaming'
|
|
13
|
-
| 'tool_dispatch'
|
|
14
|
-
| 'post_hooks'
|
|
15
|
-
| 'completed'
|
|
16
|
-
| 'failed'
|
|
17
|
-
| 'cancelled';
|
|
18
|
-
|
|
19
|
-
/** States for the tool execution machine. */
|
|
20
|
-
export type ToolExecutionState =
|
|
21
|
-
| 'received'
|
|
22
|
-
| 'validated'
|
|
23
|
-
| 'prehooked'
|
|
24
|
-
| 'permissioned'
|
|
25
|
-
| 'executing'
|
|
26
|
-
| 'mapped'
|
|
27
|
-
| 'posthooked'
|
|
28
|
-
| 'succeeded'
|
|
29
|
-
| 'failed'
|
|
30
|
-
| 'cancelled';
|
|
31
|
-
|
|
32
|
-
/** A lightweight record of an in-progress or recently completed tool call. */
|
|
33
|
-
export interface ActiveToolCall {
|
|
34
|
-
/** Tool call ID from the provider. */
|
|
35
|
-
callId: string;
|
|
36
|
-
/** Tool name. */
|
|
37
|
-
toolName: string;
|
|
38
|
-
/** Serialized arguments (JSON string). */
|
|
39
|
-
args: string;
|
|
40
|
-
/** Current execution state. */
|
|
41
|
-
state: ToolExecutionState;
|
|
42
|
-
/** Epoch ms when this call entered the current state. */
|
|
43
|
-
stateEnteredAt: number;
|
|
44
|
-
/** Phase timestamps keyed by ToolExecutionState. */
|
|
45
|
-
phaseTimestamps: Partial<Record<ToolExecutionState, number>>;
|
|
46
|
-
/** Error message if state === 'failed'. */
|
|
47
|
-
error?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Token usage accumulated for the current or most recent turn. */
|
|
51
|
-
export interface TurnUsage {
|
|
52
|
-
inputTokens: number;
|
|
53
|
-
outputTokens: number;
|
|
54
|
-
cacheReadTokens: number;
|
|
55
|
-
cacheWriteTokens: number;
|
|
56
|
-
reasoningTokens: number;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Streaming progress for the current turn. */
|
|
60
|
-
export interface StreamProgress {
|
|
61
|
-
/** Accumulated text content so far. */
|
|
62
|
-
accumulated: string;
|
|
63
|
-
/** Latest reasoning delta (if any). */
|
|
64
|
-
reasoningAccumulated: string;
|
|
65
|
-
/** Compact preview of the most recent partial tool call streamed so far. */
|
|
66
|
-
partialToolPreview?: string;
|
|
67
|
-
/** Number of delta events received. */
|
|
68
|
-
deltaCount: number;
|
|
69
|
-
/** Epoch ms of the first delta. */
|
|
70
|
-
firstDeltaAt?: number;
|
|
71
|
-
/** Epoch ms of the most recent delta. */
|
|
72
|
-
lastDeltaAt?: number;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface TurnReconciliationRecord {
|
|
76
|
-
count: number;
|
|
77
|
-
callIds: string[];
|
|
78
|
-
toolNames: string[];
|
|
79
|
-
reason: string;
|
|
80
|
-
timestamp: number;
|
|
81
|
-
isMalformed: boolean;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* ConversationDomainState — turn lifecycle and streaming state.
|
|
86
|
-
*/
|
|
87
|
-
export interface ConversationDomainState {
|
|
88
|
-
// ── Domain metadata ────────────────────────────────────────────────────────
|
|
89
|
-
/** Monotonic revision counter; increments on every mutation. */
|
|
90
|
-
revision: number;
|
|
91
|
-
/** Timestamp of last mutation (Date.now()). */
|
|
92
|
-
lastUpdatedAt: number;
|
|
93
|
-
/** Subsystem that triggered the last mutation. */
|
|
94
|
-
source: string;
|
|
95
|
-
|
|
96
|
-
// ── Turn lifecycle ─────────────────────────────────────────────────────────
|
|
97
|
-
/** Current state of the turn lifecycle machine. */
|
|
98
|
-
turnState: TurnState;
|
|
99
|
-
/** Unique ID of the current turn (undefined when idle). */
|
|
100
|
-
currentTurnId?: string;
|
|
101
|
-
/** Epoch ms when the current turn started (undefined when idle). */
|
|
102
|
-
turnStartedAt?: number;
|
|
103
|
-
/** Epoch ms when the current turn completed/failed (undefined while active). */
|
|
104
|
-
turnEndedAt?: number;
|
|
105
|
-
/** Error from the most recent failed turn. */
|
|
106
|
-
lastTurnError?: string;
|
|
107
|
-
/** Explicit terminal reason for the most recently finished turn. */
|
|
108
|
-
lastTurnStopReason?: TurnStopReason;
|
|
109
|
-
/** Final assistant response for the most recently completed turn. */
|
|
110
|
-
lastTurnResponse?: string;
|
|
111
|
-
/** Most recent preflight failure message, if any. */
|
|
112
|
-
lastPreflightFailure?: string;
|
|
113
|
-
/** Total number of turns completed in this session. */
|
|
114
|
-
totalTurns: number;
|
|
115
|
-
|
|
116
|
-
// ── Streaming ──────────────────────────────────────────────────────────────
|
|
117
|
-
/** Live streaming progress (populated during 'streaming' state). */
|
|
118
|
-
stream: StreamProgress;
|
|
119
|
-
|
|
120
|
-
// ── Tool dispatch ──────────────────────────────────────────────────────────
|
|
121
|
-
/** Map of callId → ActiveToolCall for all in-flight tool calls. */
|
|
122
|
-
activeToolCalls: Map<string, ActiveToolCall>;
|
|
123
|
-
/** Count of tool calls dispatched in the current turn. */
|
|
124
|
-
toolCallsThisTurn: number;
|
|
125
|
-
/** Most recent reconciliation record for unresolved or malformed tool calls. */
|
|
126
|
-
lastToolReconciliation?: TurnReconciliationRecord;
|
|
127
|
-
|
|
128
|
-
// ── Token accounting ───────────────────────────────────────────────────────
|
|
129
|
-
/** Usage for the current or most recent turn. */
|
|
130
|
-
currentTurnUsage: TurnUsage;
|
|
131
|
-
/** Cumulative usage across all turns in this session. */
|
|
132
|
-
sessionUsage: TurnUsage;
|
|
133
|
-
|
|
134
|
-
// ── Context window ─────────────────────────────────────────────────────────
|
|
135
|
-
/** Estimated token count of the current context window. */
|
|
136
|
-
estimatedContextTokens: number;
|
|
137
|
-
/** Whether a context warning threshold has been crossed. */
|
|
138
|
-
contextWarningActive: boolean;
|
|
139
|
-
/** Message count in the current session conversation. */
|
|
140
|
-
messageCount: number;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function makeEmptyUsage(): TurnUsage {
|
|
144
|
-
return { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, reasoningTokens: 0 };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Returns the default initial state for the conversation domain.
|
|
149
|
-
*/
|
|
150
|
-
export function createInitialConversationState(): ConversationDomainState {
|
|
151
|
-
return {
|
|
152
|
-
revision: 0,
|
|
153
|
-
lastUpdatedAt: 0,
|
|
154
|
-
source: 'init',
|
|
155
|
-
turnState: 'idle',
|
|
156
|
-
currentTurnId: undefined,
|
|
157
|
-
turnStartedAt: undefined,
|
|
158
|
-
turnEndedAt: undefined,
|
|
159
|
-
lastTurnError: undefined,
|
|
160
|
-
lastTurnStopReason: undefined,
|
|
161
|
-
lastTurnResponse: undefined,
|
|
162
|
-
lastPreflightFailure: undefined,
|
|
163
|
-
totalTurns: 0,
|
|
164
|
-
stream: {
|
|
165
|
-
accumulated: '',
|
|
166
|
-
reasoningAccumulated: '',
|
|
167
|
-
partialToolPreview: undefined,
|
|
168
|
-
deltaCount: 0,
|
|
169
|
-
firstDeltaAt: undefined,
|
|
170
|
-
lastDeltaAt: undefined,
|
|
171
|
-
},
|
|
172
|
-
activeToolCalls: new Map(),
|
|
173
|
-
toolCallsThisTurn: 0,
|
|
174
|
-
lastToolReconciliation: undefined,
|
|
175
|
-
currentTurnUsage: makeEmptyUsage(),
|
|
176
|
-
sessionUsage: makeEmptyUsage(),
|
|
177
|
-
estimatedContextTokens: 0,
|
|
178
|
-
contextWarningActive: false,
|
|
179
|
-
messageCount: 0,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
1
|
+
export * from '@pellux/goodvibes-sdk/platform/runtime/store/domains/conversation';
|
|
@@ -1,143 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Permissions domain state — tracks the permission mode, session approvals,
|
|
3
|
-
* and the most recent permission decision with full audit trail.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { PermissionCategory } from '@pellux/goodvibes-sdk/platform/permissions/manager';
|
|
7
|
-
import type { PermissionRiskLevel } from '@pellux/goodvibes-sdk/platform/permissions/types';
|
|
8
|
-
|
|
9
|
-
/** Permission evaluation modes (maps to PermissionsToolConfig). */
|
|
10
|
-
export type PermissionMode =
|
|
11
|
-
| 'default'
|
|
12
|
-
| 'plan'
|
|
13
|
-
| 'allow-all'
|
|
14
|
-
| 'custom'
|
|
15
|
-
| 'background-restricted';
|
|
16
|
-
|
|
17
|
-
/** States for the permission decision machine. */
|
|
18
|
-
export type PermissionDecisionMachineState =
|
|
19
|
-
| 'collect_rules'
|
|
20
|
-
| 'normalize_input'
|
|
21
|
-
| 'evaluate_policy'
|
|
22
|
-
| 'evaluate_runtime_mode'
|
|
23
|
-
| 'evaluate_session_override'
|
|
24
|
-
| 'final_safety_checks'
|
|
25
|
-
| 'decision_emitted';
|
|
26
|
-
|
|
27
|
-
/** The outcome of a permission decision. */
|
|
28
|
-
export type PermissionDecisionOutcome = 'approved' | 'denied' | 'deferred';
|
|
29
|
-
|
|
30
|
-
/** Source layer that determined the permission outcome. */
|
|
31
|
-
export type PermissionSourceLayer =
|
|
32
|
-
| 'config_policy'
|
|
33
|
-
| 'managed_policy'
|
|
34
|
-
| 'runtime_mode'
|
|
35
|
-
| 'session_override'
|
|
36
|
-
| 'safety_check'
|
|
37
|
-
| 'user_prompt';
|
|
38
|
-
|
|
39
|
-
/** Reason codes for a permission decision. */
|
|
40
|
-
export type PermissionDecisionReason =
|
|
41
|
-
| 'config_allow'
|
|
42
|
-
| 'config_deny'
|
|
43
|
-
| 'managed_policy_allow'
|
|
44
|
-
| 'managed_policy_deny'
|
|
45
|
-
| 'mode_allow_all'
|
|
46
|
-
| 'mode_denied'
|
|
47
|
-
| 'mode_plan_deny'
|
|
48
|
-
| 'mode_background_restricted'
|
|
49
|
-
| 'session_cached_approval'
|
|
50
|
-
| 'session_cached_denial'
|
|
51
|
-
| 'safety_guardrail'
|
|
52
|
-
| 'user_approved'
|
|
53
|
-
| 'user_denied';
|
|
54
|
-
|
|
55
|
-
/** Full record of the most recent permission decision. */
|
|
56
|
-
export interface PermissionDecision {
|
|
57
|
-
/** Tool call ID this decision is for. */
|
|
58
|
-
callId: string;
|
|
59
|
-
/** Tool name. */
|
|
60
|
-
toolName: string;
|
|
61
|
-
/** Permission category. */
|
|
62
|
-
category: PermissionCategory;
|
|
63
|
-
/** State machine state when the decision was emitted. */
|
|
64
|
-
machineState: PermissionDecisionMachineState;
|
|
65
|
-
/** Final outcome. */
|
|
66
|
-
outcome: PermissionDecisionOutcome;
|
|
67
|
-
/** Primary reason code. */
|
|
68
|
-
reason: PermissionDecisionReason;
|
|
69
|
-
/** Source layer that yielded the decision. */
|
|
70
|
-
sourceLayer: PermissionSourceLayer;
|
|
71
|
-
/** Whether the decision was persisted to session approvals. */
|
|
72
|
-
persisted: boolean;
|
|
73
|
-
/** Semantic classification surfaced with the decision. */
|
|
74
|
-
classification?: string;
|
|
75
|
-
/** Risk level surfaced with the decision. */
|
|
76
|
-
riskLevel?: PermissionRiskLevel;
|
|
77
|
-
/** Human-readable summary for operators and the prompt UI. */
|
|
78
|
-
summary?: string;
|
|
79
|
-
/** Epoch ms when the decision was emitted. */
|
|
80
|
-
decidedAt: number;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* PermissionDomainState — permission configuration and decision state.
|
|
85
|
-
*/
|
|
86
|
-
export interface PermissionDomainState {
|
|
87
|
-
// ── Domain metadata ────────────────────────────────────────────────────────
|
|
88
|
-
/** Monotonic revision counter; increments on every mutation. */
|
|
89
|
-
revision: number;
|
|
90
|
-
/** Timestamp of last mutation (Date.now()). */
|
|
91
|
-
lastUpdatedAt: number;
|
|
92
|
-
/** Subsystem that triggered the last mutation. */
|
|
93
|
-
source: string;
|
|
94
|
-
|
|
95
|
-
// ── Mode ───────────────────────────────────────────────────────────────────
|
|
96
|
-
/** Current global permission mode. */
|
|
97
|
-
mode: PermissionMode;
|
|
98
|
-
/** Whether the user is currently being prompted for a permission decision. */
|
|
99
|
-
awaitingDecision: boolean;
|
|
100
|
-
/** Current state of the decision state machine (while a decision is in flight). */
|
|
101
|
-
decisionMachineState?: PermissionDecisionMachineState;
|
|
102
|
-
|
|
103
|
-
// ── Session approvals ──────────────────────────────────────────────────────
|
|
104
|
-
/**
|
|
105
|
-
* Per-session tool approval cache.
|
|
106
|
-
* Key format: "<toolName>:<argsHash>" → boolean (approved/denied).
|
|
107
|
-
*/
|
|
108
|
-
sessionApprovals: Map<string, boolean>;
|
|
109
|
-
/** Number of approvals granted this session. */
|
|
110
|
-
approvalCount: number;
|
|
111
|
-
/** Number of denials issued this session. */
|
|
112
|
-
denialCount: number;
|
|
113
|
-
|
|
114
|
-
// ── Last decision ──────────────────────────────────────────────────────────
|
|
115
|
-
/** The most recent permission decision record. */
|
|
116
|
-
lastDecision?: PermissionDecision;
|
|
117
|
-
|
|
118
|
-
// ── Statistics ─────────────────────────────────────────────────────────────
|
|
119
|
-
/** Total permission checks performed this session. */
|
|
120
|
-
totalChecks: number;
|
|
121
|
-
/** Total checks that were served from session cache. */
|
|
122
|
-
cachedChecks: number;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Returns the default initial state for the permissions domain.
|
|
127
|
-
*/
|
|
128
|
-
export function createInitialPermissionsState(): PermissionDomainState {
|
|
129
|
-
return {
|
|
130
|
-
revision: 0,
|
|
131
|
-
lastUpdatedAt: 0,
|
|
132
|
-
source: 'init',
|
|
133
|
-
mode: 'default',
|
|
134
|
-
awaitingDecision: false,
|
|
135
|
-
decisionMachineState: undefined,
|
|
136
|
-
sessionApprovals: new Map(),
|
|
137
|
-
approvalCount: 0,
|
|
138
|
-
denialCount: 0,
|
|
139
|
-
lastDecision: undefined,
|
|
140
|
-
totalChecks: 0,
|
|
141
|
-
cachedChecks: 0,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
1
|
+
export * from '@pellux/goodvibes-sdk/platform/runtime/store/domains/permissions';
|
|
@@ -1,228 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ToolEvent } from '@pellux/goodvibes-sdk/platform/runtime/events/tools';
|
|
3
|
-
import type { ConversationDomainState, ActiveToolCall, ToolExecutionState } from '@pellux/goodvibes-sdk/platform/runtime/store/domains/conversation';
|
|
4
|
-
import { canStartNewTurn, formatPartialToolPreview, isCurrentTurnEvent, isTerminalTurnState, now, resetStreamState, updateDomainMetadata } from '@pellux/goodvibes-sdk/platform/runtime/store/helpers/reducers/shared';
|
|
5
|
-
|
|
6
|
-
function formatToolArgs(event: ToolEvent | TurnEvent): string {
|
|
7
|
-
if ('args' in event) {
|
|
8
|
-
return JSON.stringify(event.args);
|
|
9
|
-
}
|
|
10
|
-
return '{}';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function updateConversationState(
|
|
14
|
-
domain: ConversationDomainState,
|
|
15
|
-
event: TurnEvent | ToolEvent,
|
|
16
|
-
): ConversationDomainState {
|
|
17
|
-
const source = event.type;
|
|
18
|
-
if ('callId' in event) {
|
|
19
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || isTerminalTurnState(domain.turnState)) {
|
|
20
|
-
return domain;
|
|
21
|
-
}
|
|
22
|
-
const activeToolCalls = new Map(domain.activeToolCalls);
|
|
23
|
-
const existing = activeToolCalls.get(event.callId);
|
|
24
|
-
const stateByEvent: Partial<Record<ToolEvent['type'], ToolExecutionState>> = {
|
|
25
|
-
TOOL_RECEIVED: 'received',
|
|
26
|
-
TOOL_VALIDATED: 'validated',
|
|
27
|
-
TOOL_PREHOOKED: 'prehooked',
|
|
28
|
-
TOOL_PERMISSIONED: 'permissioned',
|
|
29
|
-
TOOL_EXECUTING: 'executing',
|
|
30
|
-
TOOL_MAPPED: 'mapped',
|
|
31
|
-
TOOL_POSTHOOKED: 'posthooked',
|
|
32
|
-
TOOL_SUCCEEDED: 'succeeded',
|
|
33
|
-
TOOL_FAILED: 'failed',
|
|
34
|
-
TOOL_CANCELLED: 'cancelled',
|
|
35
|
-
BUDGET_EXCEEDED_MS: 'failed',
|
|
36
|
-
BUDGET_EXCEEDED_TOKENS: 'failed',
|
|
37
|
-
BUDGET_EXCEEDED_COST: 'failed',
|
|
38
|
-
};
|
|
39
|
-
const nextState = stateByEvent[event.type];
|
|
40
|
-
const timestamp = now();
|
|
41
|
-
const nextRecord: ActiveToolCall = {
|
|
42
|
-
callId: event.callId,
|
|
43
|
-
toolName: event.tool,
|
|
44
|
-
args: existing?.args ?? formatToolArgs(event),
|
|
45
|
-
state: nextState ?? existing?.state ?? 'received',
|
|
46
|
-
stateEnteredAt: 'startedAt' in event ? event.startedAt : timestamp,
|
|
47
|
-
phaseTimestamps: {
|
|
48
|
-
...(existing?.phaseTimestamps ?? {}),
|
|
49
|
-
...(nextState ? { [nextState]: timestamp } : {}),
|
|
50
|
-
},
|
|
51
|
-
error:
|
|
52
|
-
'error' in event
|
|
53
|
-
? event.error
|
|
54
|
-
: event.type === 'BUDGET_EXCEEDED_MS'
|
|
55
|
-
? `${event.phase} exceeded ${event.limitMs}ms budget`
|
|
56
|
-
: event.type === 'BUDGET_EXCEEDED_TOKENS'
|
|
57
|
-
? `${event.phase} exceeded ${event.limitTokens} token budget`
|
|
58
|
-
: event.type === 'BUDGET_EXCEEDED_COST'
|
|
59
|
-
? `${event.phase} exceeded $${event.limitCostUsd} cost budget`
|
|
60
|
-
: existing?.error,
|
|
61
|
-
};
|
|
62
|
-
activeToolCalls.set(event.callId, nextRecord);
|
|
63
|
-
return {
|
|
64
|
-
...updateDomainMetadata(domain, source),
|
|
65
|
-
activeToolCalls,
|
|
66
|
-
currentTurnId: domain.currentTurnId ?? event.turnId,
|
|
67
|
-
toolCallsThisTurn: event.type === 'TOOL_RECEIVED' ? domain.toolCallsThisTurn + 1 : domain.toolCallsThisTurn,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
switch (event.type) {
|
|
72
|
-
case 'TURN_SUBMITTED':
|
|
73
|
-
if (!canStartNewTurn(domain)) return domain;
|
|
74
|
-
return {
|
|
75
|
-
...updateDomainMetadata(domain, source),
|
|
76
|
-
turnState: 'preflight',
|
|
77
|
-
currentTurnId: event.turnId,
|
|
78
|
-
turnStartedAt: now(),
|
|
79
|
-
turnEndedAt: undefined,
|
|
80
|
-
lastTurnError: undefined,
|
|
81
|
-
lastTurnStopReason: undefined,
|
|
82
|
-
lastTurnResponse: undefined,
|
|
83
|
-
lastPreflightFailure: undefined,
|
|
84
|
-
stream: resetStreamState(),
|
|
85
|
-
activeToolCalls: new Map(),
|
|
86
|
-
toolCallsThisTurn: 0,
|
|
87
|
-
lastToolReconciliation: undefined,
|
|
88
|
-
};
|
|
89
|
-
case 'PREFLIGHT_OK':
|
|
90
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || domain.turnState !== 'preflight') return domain;
|
|
91
|
-
return {
|
|
92
|
-
...updateDomainMetadata(domain, source),
|
|
93
|
-
currentTurnId: event.turnId,
|
|
94
|
-
turnState: 'preflight',
|
|
95
|
-
};
|
|
96
|
-
case 'PREFLIGHT_FAIL':
|
|
97
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || domain.turnState !== 'preflight') return domain;
|
|
98
|
-
return {
|
|
99
|
-
...updateDomainMetadata(domain, source),
|
|
100
|
-
currentTurnId: event.turnId,
|
|
101
|
-
turnState: 'failed',
|
|
102
|
-
turnEndedAt: now(),
|
|
103
|
-
lastTurnError: event.reason,
|
|
104
|
-
lastTurnStopReason: event.stopReason,
|
|
105
|
-
lastPreflightFailure: event.reason,
|
|
106
|
-
stream: resetStreamState(),
|
|
107
|
-
};
|
|
108
|
-
case 'STREAM_START':
|
|
109
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || domain.turnState !== 'preflight') return domain;
|
|
110
|
-
return {
|
|
111
|
-
...updateDomainMetadata(domain, source),
|
|
112
|
-
currentTurnId: event.turnId,
|
|
113
|
-
turnState: 'streaming',
|
|
114
|
-
stream: resetStreamState(),
|
|
115
|
-
};
|
|
116
|
-
case 'STREAM_DELTA':
|
|
117
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || domain.turnState !== 'streaming') return domain;
|
|
118
|
-
return {
|
|
119
|
-
...updateDomainMetadata(domain, source),
|
|
120
|
-
currentTurnId: event.turnId,
|
|
121
|
-
turnState: 'streaming',
|
|
122
|
-
stream: {
|
|
123
|
-
accumulated: event.accumulated,
|
|
124
|
-
reasoningAccumulated: `${domain.stream.reasoningAccumulated}${event.reasoning ?? ''}`,
|
|
125
|
-
partialToolPreview: formatPartialToolPreview(event.toolCalls),
|
|
126
|
-
deltaCount: domain.stream.deltaCount + 1,
|
|
127
|
-
firstDeltaAt: domain.stream.firstDeltaAt ?? now(),
|
|
128
|
-
lastDeltaAt: now(),
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
case 'STREAM_END':
|
|
132
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || domain.turnState !== 'streaming') return domain;
|
|
133
|
-
return {
|
|
134
|
-
...updateDomainMetadata(domain, source),
|
|
135
|
-
currentTurnId: event.turnId,
|
|
136
|
-
stream: {
|
|
137
|
-
...domain.stream,
|
|
138
|
-
partialToolPreview: undefined,
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
case 'LLM_RESPONSE_RECEIVED':
|
|
142
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || isTerminalTurnState(domain.turnState)) return domain;
|
|
143
|
-
return {
|
|
144
|
-
...updateDomainMetadata(domain, source),
|
|
145
|
-
currentTurnId: event.turnId,
|
|
146
|
-
};
|
|
147
|
-
case 'TOOL_BATCH_READY':
|
|
148
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || domain.turnState !== 'tool_dispatch') return domain;
|
|
149
|
-
return {
|
|
150
|
-
...updateDomainMetadata(domain, source),
|
|
151
|
-
currentTurnId: event.turnId,
|
|
152
|
-
turnState: 'post_hooks',
|
|
153
|
-
};
|
|
154
|
-
case 'TOOLS_DONE':
|
|
155
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || domain.turnState !== 'tool_dispatch') return domain;
|
|
156
|
-
return {
|
|
157
|
-
...updateDomainMetadata(domain, source),
|
|
158
|
-
currentTurnId: event.turnId,
|
|
159
|
-
turnState: 'post_hooks',
|
|
160
|
-
};
|
|
161
|
-
case 'POST_HOOKS_DONE':
|
|
162
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || domain.turnState !== 'post_hooks') return domain;
|
|
163
|
-
return {
|
|
164
|
-
...updateDomainMetadata(domain, source),
|
|
165
|
-
currentTurnId: event.turnId,
|
|
166
|
-
turnState: 'post_hooks',
|
|
167
|
-
};
|
|
168
|
-
case 'TOOL_RECONCILED':
|
|
169
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || isTerminalTurnState(domain.turnState)) return domain;
|
|
170
|
-
return {
|
|
171
|
-
...updateDomainMetadata(domain, source),
|
|
172
|
-
currentTurnId: event.turnId,
|
|
173
|
-
lastToolReconciliation: {
|
|
174
|
-
count: event.count,
|
|
175
|
-
callIds: [...event.callIds],
|
|
176
|
-
toolNames: [...event.toolNames],
|
|
177
|
-
reason: event.reason,
|
|
178
|
-
timestamp: event.timestamp,
|
|
179
|
-
isMalformed: event.isMalformed ?? false,
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
case 'TURN_COMPLETED':
|
|
183
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || isTerminalTurnState(domain.turnState)) return domain;
|
|
184
|
-
return {
|
|
185
|
-
...updateDomainMetadata(domain, source),
|
|
186
|
-
currentTurnId: event.turnId,
|
|
187
|
-
turnState: 'completed',
|
|
188
|
-
turnEndedAt: now(),
|
|
189
|
-
totalTurns: domain.totalTurns + 1,
|
|
190
|
-
lastTurnResponse: event.response,
|
|
191
|
-
lastTurnStopReason: event.stopReason,
|
|
192
|
-
stream: {
|
|
193
|
-
...domain.stream,
|
|
194
|
-
partialToolPreview: undefined,
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
case 'TURN_ERROR':
|
|
198
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || isTerminalTurnState(domain.turnState)) return domain;
|
|
199
|
-
return {
|
|
200
|
-
...updateDomainMetadata(domain, source),
|
|
201
|
-
currentTurnId: event.turnId,
|
|
202
|
-
turnState: 'failed',
|
|
203
|
-
turnEndedAt: now(),
|
|
204
|
-
lastTurnError: event.error,
|
|
205
|
-
lastTurnStopReason: event.stopReason,
|
|
206
|
-
stream: {
|
|
207
|
-
...domain.stream,
|
|
208
|
-
partialToolPreview: undefined,
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
case 'TURN_CANCEL':
|
|
212
|
-
if (!isCurrentTurnEvent(domain, event.turnId) || isTerminalTurnState(domain.turnState)) return domain;
|
|
213
|
-
return {
|
|
214
|
-
...updateDomainMetadata(domain, source),
|
|
215
|
-
currentTurnId: event.turnId,
|
|
216
|
-
turnState: 'cancelled',
|
|
217
|
-
turnEndedAt: now(),
|
|
218
|
-
lastTurnError: event.reason,
|
|
219
|
-
lastTurnStopReason: event.stopReason,
|
|
220
|
-
stream: {
|
|
221
|
-
...domain.stream,
|
|
222
|
-
partialToolPreview: undefined,
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
default:
|
|
226
|
-
return updateDomainMetadata(domain, source);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
1
|
+
export * from '@pellux/goodvibes-sdk/platform/runtime/store/helpers/reducers/conversation';
|