gestalt-mobile 0.55.8 → 0.57.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/dist/client/assets/index-Cp-JfcNd.css +1 -0
- package/dist/client/assets/index-DeNYHfGR.js +123 -0
- package/dist/client/index.html +2 -2
- package/dist/server/client/features/chat/chat-projection.js +11 -0
- package/dist/server/server/composition.contracts.js +219 -1
- package/dist/server/server/composition.js +26 -1
- package/dist/server/server/features/agent-activity/tool-efficiency-projection.js +179 -0
- package/dist/server/server/features/agent-activity/tool-efficiency.js +13 -0
- package/dist/server/server/features/catalog/get-xerj-status/endpoint.js +3 -1
- package/dist/server/server/features/control-plane-trace/export-trace.js +18 -3
- package/dist/server/server/features/sessions/get-history/endpoint.js +3 -0
- package/dist/server/server/features/sessions/get-retrieval-readiness/endpoint.js +19 -0
- package/dist/server/server/features/sessions/get-session/endpoint.js +3 -1
- package/dist/server/server/features/sessions/register-routes.js +7 -1
- package/dist/server/server/platform/codex/activity-facts.js +2 -0
- package/dist/server/server/platform/codex/codex-capabilities.js +4 -0
- package/dist/server/server/platform/codex/codex-serena.js +16 -3
- package/dist/server/server/platform/codex/mcp-startup-failure.js +96 -0
- package/dist/server/server/platform/codex/normalizer.js +69 -0
- package/dist/server/server/platform/codex/session-runtime.js +101 -4
- package/dist/server/server/platform/codex/tool-efficiency-facts.js +178 -0
- package/dist/server/server/platform/persistence/migrate.js +1 -0
- package/dist/server/server/platform/persistence/sqlite-event-journal.js +16 -0
- package/dist/server/server/platform/persistence/sqlite-tool-efficiency-store.js +23 -0
- package/dist/server/server/platform/retrieval/codex-xerj.js +17 -3
- package/dist/server/server/platform/retrieval/read-authority.js +55 -0
- package/dist/server/server/platform/retrieval/readiness-evidence.js +92 -0
- package/dist/server/server/platform/retrieval/repository-readiness.js +464 -0
- package/dist/server/server/platform/retrieval/xerj-indexer.js +19 -1
- package/dist/server/shared/contracts/mcp-startup-failure.js +158 -0
- package/dist/server/shared/contracts/retrieval-readiness.js +47 -0
- package/dist/server/shared/contracts/tool-efficiency.js +125 -0
- package/dist/server/shared/contracts/tool-efficiency.test-fixture.js +77 -0
- package/package.json +1 -1
- package/dist/client/assets/index-CGA0jSom.css +0 -1
- package/dist/client/assets/index-DOfpAofv.js +0 -116
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { providerTokenFields, } from '../../features/agent-activity/tool-efficiency.js';
|
|
7
|
+
const record = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
8
|
+
? value
|
|
9
|
+
: undefined;
|
|
10
|
+
const id = (value) => typeof value === 'string' && /^[a-zA-Z0-9_.:/-]{1,256}$/.test(value) ? value : null;
|
|
11
|
+
const counter = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
12
|
+
const measure = (value, unit, source) => ({ value, unit, source: value === null ? null : source });
|
|
13
|
+
const completeness = (value, source) => measure(value === 'complete' || value === 'partial' || value === 'unknown' ? value : null, 'completeness', source);
|
|
14
|
+
/** Pure, bounded metadata projection. It never parses executable bodies or retains results. */
|
|
15
|
+
export function decodeToolEfficiencyFacts(sessionId, occurredAt, input, correlation = {}) {
|
|
16
|
+
const params = record(input.params);
|
|
17
|
+
if (!params || !Number.isFinite(Date.parse(occurredAt)))
|
|
18
|
+
return [];
|
|
19
|
+
const threadId = id(correlation.physicalThreadId) ?? id(params.threadId);
|
|
20
|
+
const runtimeId = id(correlation.runtimeId);
|
|
21
|
+
const rootThreadId = id(correlation.rootThreadId);
|
|
22
|
+
const identity = {
|
|
23
|
+
sessionId,
|
|
24
|
+
runtimeId,
|
|
25
|
+
threadId,
|
|
26
|
+
turnId: id(correlation.physicalTurnId) ?? id(params.turnId),
|
|
27
|
+
actor: correlation.actor ??
|
|
28
|
+
(threadId && rootThreadId
|
|
29
|
+
? threadId === rootThreadId
|
|
30
|
+
? 'root'
|
|
31
|
+
: 'child'
|
|
32
|
+
: 'unknown'),
|
|
33
|
+
};
|
|
34
|
+
if (input.method === 'thread/tokenUsage/updated') {
|
|
35
|
+
if (!threadId)
|
|
36
|
+
return [];
|
|
37
|
+
const usage = record(params.tokenUsage);
|
|
38
|
+
const tokens = (scope) => Object.fromEntries(providerTokenFields.map((field) => [
|
|
39
|
+
field,
|
|
40
|
+
measure(counter(record(usage?.[scope])?.[field]), 'tokens', `tokenUsage.${scope}.${field}`),
|
|
41
|
+
]));
|
|
42
|
+
const last = tokens('last');
|
|
43
|
+
const total = tokens('total');
|
|
44
|
+
if (![...Object.values(last), ...Object.values(total)].some((metric) => metric.value !== null))
|
|
45
|
+
return [];
|
|
46
|
+
return [
|
|
47
|
+
{ kind: 'providerUsage', identity, occurredAt, scope: 'threadUsageSnapshot', last, total },
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
if (input.method !== 'item/started' && input.method !== 'item/completed')
|
|
51
|
+
return [];
|
|
52
|
+
const item = record(params.item);
|
|
53
|
+
const itemId = id(item?.id);
|
|
54
|
+
const family = toolFamily(item);
|
|
55
|
+
if (!item || !itemId || !family)
|
|
56
|
+
return [];
|
|
57
|
+
const phase = input.method === 'item/started' ? 'started' : 'completed';
|
|
58
|
+
const result = record(item.result);
|
|
59
|
+
let delivered = null;
|
|
60
|
+
let deliveredScope = null;
|
|
61
|
+
let deliveredSource = '';
|
|
62
|
+
if (phase === 'completed') {
|
|
63
|
+
if (item.type === 'commandExecution' && typeof item.aggregatedOutput === 'string') {
|
|
64
|
+
delivered = Buffer.byteLength(item.aggregatedOutput, 'utf8');
|
|
65
|
+
deliveredScope = 'commandOutputUtf8';
|
|
66
|
+
deliveredSource = 'item.aggregatedOutput';
|
|
67
|
+
}
|
|
68
|
+
else if (item.type === 'mcpToolCall' || item.type === 'dynamicToolCall') {
|
|
69
|
+
const content = item.type === 'mcpToolCall' ? result?.content : item.contentItems;
|
|
70
|
+
if (Array.isArray(content)) {
|
|
71
|
+
// This is the serialized visible content only; arguments, _meta and duplicate
|
|
72
|
+
// structuredContent are excluded. It is not a raw-output or token measurement.
|
|
73
|
+
try {
|
|
74
|
+
delivered = Buffer.byteLength(JSON.stringify(content), 'utf8');
|
|
75
|
+
deliveredScope =
|
|
76
|
+
item.type === 'mcpToolCall' ? 'serializedMcpContent' : 'serializedDynamicContent';
|
|
77
|
+
deliveredSource =
|
|
78
|
+
item.type === 'mcpToolCall' ? 'item.result.content' : 'item.contentItems';
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
/* Non-JSON input has unknown byte coverage. */
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const quality = phase === 'completed' && family === 'contextMode' ? contextModeQuality(result) : undefined;
|
|
87
|
+
const duration = measure(phase === 'completed' &&
|
|
88
|
+
(item.type === 'commandExecution' ||
|
|
89
|
+
item.type === 'mcpToolCall' ||
|
|
90
|
+
item.type === 'dynamicToolCall')
|
|
91
|
+
? counter(item.durationMs)
|
|
92
|
+
: null, 'milliseconds', 'item.durationMs');
|
|
93
|
+
const capture = completeness(quality?.captureCompleteness, 'contextMode.captureCompleteness');
|
|
94
|
+
const display = completeness(quality?.displayCompleteness, 'contextMode.displayCompleteness');
|
|
95
|
+
const evidence = completeness(quality?.evidenceCompleteness, 'contextMode.evidenceCompleteness');
|
|
96
|
+
return [
|
|
97
|
+
{
|
|
98
|
+
kind: 'tool',
|
|
99
|
+
identity,
|
|
100
|
+
occurredAt,
|
|
101
|
+
itemId,
|
|
102
|
+
phase,
|
|
103
|
+
family,
|
|
104
|
+
scope: 'toolCall',
|
|
105
|
+
eventKey: runtimeId && threadId
|
|
106
|
+
? JSON.stringify([sessionId, runtimeId, threadId, itemId, phase])
|
|
107
|
+
: null,
|
|
108
|
+
status: item.status === 'failed' ||
|
|
109
|
+
(item.type === 'dynamicToolCall' && item.success === false) ||
|
|
110
|
+
(item.type === 'commandExecution' &&
|
|
111
|
+
typeof item.exitCode === 'number' &&
|
|
112
|
+
Number.isSafeInteger(item.exitCode) &&
|
|
113
|
+
item.exitCode !== 0)
|
|
114
|
+
? 'failed'
|
|
115
|
+
: phase === 'started' || item.status === 'inProgress'
|
|
116
|
+
? 'running'
|
|
117
|
+
: item.status === 'completed'
|
|
118
|
+
? 'succeeded'
|
|
119
|
+
: 'unknown',
|
|
120
|
+
duration,
|
|
121
|
+
retries: measure(null, 'retries', ''),
|
|
122
|
+
reuse: measure(null, 'boolean', ''),
|
|
123
|
+
bytes: {
|
|
124
|
+
raw: measure(null, 'bytes', ''),
|
|
125
|
+
processed: measure(null, 'bytes', ''),
|
|
126
|
+
delivered: measure(delivered, 'bytes', deliveredSource),
|
|
127
|
+
deliveredScope,
|
|
128
|
+
},
|
|
129
|
+
// Partial display is explicit truncation; absence of this flag is not proof of no truncation.
|
|
130
|
+
truncated: measure(display.value === 'partial' ? true : null, 'boolean', 'contextMode.displayCompleteness'),
|
|
131
|
+
completeness: { capture, display, evidence },
|
|
132
|
+
coverage: delivered !== null ||
|
|
133
|
+
duration.value !== null ||
|
|
134
|
+
[capture, display, evidence].some((metric) => metric.value !== null)
|
|
135
|
+
? 'partial'
|
|
136
|
+
: 'unknown',
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
function toolFamily(item) {
|
|
141
|
+
if (item?.type === 'commandExecution')
|
|
142
|
+
return 'command';
|
|
143
|
+
if (item?.type === 'collabAgentToolCall' || item?.type === 'collabToolCall')
|
|
144
|
+
return 'collaboration';
|
|
145
|
+
if (item?.type === 'mcpToolCall') {
|
|
146
|
+
return item.server === 'context-mode' &&
|
|
147
|
+
typeof item.tool === 'string' &&
|
|
148
|
+
/^ctx_[a-z_]+$/.test(item.tool)
|
|
149
|
+
? 'contextMode'
|
|
150
|
+
: 'mcp';
|
|
151
|
+
}
|
|
152
|
+
if (item?.type === 'dynamicToolCall')
|
|
153
|
+
return item.namespace === 'functions' && item.tool === 'exec' ? 'executionWrapper' : 'dynamic';
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
/** Only the first documented context-mode metadata block is read; previews/nested output are opaque. */
|
|
157
|
+
function contextModeQuality(result) {
|
|
158
|
+
if (!Array.isArray(result?.content))
|
|
159
|
+
return undefined;
|
|
160
|
+
const first = record(result.content[0]);
|
|
161
|
+
if (first?.type !== 'text' || typeof first.text !== 'string')
|
|
162
|
+
return undefined;
|
|
163
|
+
const line = first.text.slice(0, 16_385).split('\n', 1)[0];
|
|
164
|
+
if (line.length > 16_384)
|
|
165
|
+
return undefined;
|
|
166
|
+
try {
|
|
167
|
+
const value = record(JSON.parse(line.startsWith('Execution: ') ? line.slice(11) : line));
|
|
168
|
+
// Documented execution provenance or response-budget envelope, never arbitrary tool text.
|
|
169
|
+
return id(value?.operationId) ||
|
|
170
|
+
id(record(value?.provenance)?.operationId) ||
|
|
171
|
+
record(value?.overflow)
|
|
172
|
+
? value
|
|
173
|
+
: undefined;
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -28,6 +28,7 @@ function migrateWorkspaceGitDefaults(database) {
|
|
|
28
28
|
}
|
|
29
29
|
export function migrate(database) {
|
|
30
30
|
database.exec(schema);
|
|
31
|
+
database.exec('CREATE TABLE IF NOT EXISTS tool_efficiency (session_id TEXT PRIMARY KEY REFERENCES relay_sessions(id) ON DELETE CASCADE, state_json TEXT NOT NULL)');
|
|
31
32
|
database.exec(`CREATE TABLE IF NOT EXISTS chat_transport_diagnostics (
|
|
32
33
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
33
34
|
session_id TEXT NOT NULL REFERENCES relay_sessions(id) ON DELETE CASCADE,
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { boundedAttentionReport } from '../../../shared/contracts/attention-report.js';
|
|
7
7
|
import { eventRetentionCutoff } from './retention.js';
|
|
8
8
|
import { replayOrResync } from '../events/replay.js';
|
|
9
|
+
import { mcpStartupActivity, parseMcpStartupStatus, } from '../../../shared/contracts/mcp-startup-failure.js';
|
|
9
10
|
export const autopilotAuditEventTypes = [
|
|
10
11
|
'autopilot.turn-started',
|
|
11
12
|
'autopilot.turn-failed',
|
|
@@ -45,6 +46,21 @@ export class SqliteEventJournal {
|
|
|
45
46
|
this.retain = retain;
|
|
46
47
|
}
|
|
47
48
|
append(sessionId, type, payload, occurredAt, autopilotOutboxId) {
|
|
49
|
+
if (type === 'agent.activity.mcp-startup') {
|
|
50
|
+
const status = parseMcpStartupStatus(payload);
|
|
51
|
+
if (!status)
|
|
52
|
+
throw new Error('INVALID_MCP_STARTUP_STATUS');
|
|
53
|
+
payload = status;
|
|
54
|
+
}
|
|
55
|
+
else if (type === 'activity.updated' &&
|
|
56
|
+
payload &&
|
|
57
|
+
typeof payload === 'object' &&
|
|
58
|
+
'mcpStartup' in payload) {
|
|
59
|
+
const status = parseMcpStartupStatus(payload.mcpStartup);
|
|
60
|
+
if (!status)
|
|
61
|
+
throw new Error('INVALID_MCP_STARTUP_STATUS');
|
|
62
|
+
payload = mcpStartupActivity(status);
|
|
63
|
+
}
|
|
48
64
|
this.db.exec('BEGIN IMMEDIATE');
|
|
49
65
|
try {
|
|
50
66
|
const row = this.db
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
/** Separate from journal retention so reconnect and server restarts retain deduplication keys. */
|
|
7
|
+
export class SqliteToolEfficiencyStore {
|
|
8
|
+
db;
|
|
9
|
+
constructor(db) {
|
|
10
|
+
this.db = db;
|
|
11
|
+
}
|
|
12
|
+
load(sessionId) {
|
|
13
|
+
const row = this.db
|
|
14
|
+
.prepare('SELECT state_json FROM tool_efficiency WHERE session_id = ?')
|
|
15
|
+
.get(sessionId);
|
|
16
|
+
return row ? JSON.parse(row.state_json) : null;
|
|
17
|
+
}
|
|
18
|
+
save(sessionId, state) {
|
|
19
|
+
this.db
|
|
20
|
+
.prepare('INSERT INTO tool_efficiency (session_id,state_json) VALUES (?,?) ON CONFLICT(session_id) DO UPDATE SET state_json = excluded.state_json')
|
|
21
|
+
.run(sessionId, JSON.stringify(state));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
6
|
import { readFile } from 'node:fs/promises';
|
|
7
|
+
import { ReadinessEvidence } from './readiness-evidence.js';
|
|
7
8
|
export const xerjServerName = 'gestalt-xerj';
|
|
8
9
|
export const xerjTools = ['xerj_search', 'xerj_map', 'xerj_code_search'];
|
|
9
10
|
/** Ephemeral native thread configuration; no installation or daemon ownership. */
|
|
@@ -14,7 +15,12 @@ export class CodexXerj {
|
|
|
14
15
|
}
|
|
15
16
|
async prepare(input) {
|
|
16
17
|
const skill = input.skills.find((entry) => entry.name === 'gestalt:xerj');
|
|
18
|
+
const evidence = new ReadinessEvidence();
|
|
17
19
|
const state = {
|
|
20
|
+
evidence,
|
|
21
|
+
get readiness() {
|
|
22
|
+
return evidence.snapshot();
|
|
23
|
+
},
|
|
18
24
|
ready: false,
|
|
19
25
|
deadline: input.deadline,
|
|
20
26
|
config: { ...input.config },
|
|
@@ -45,6 +51,7 @@ export class CodexXerj {
|
|
|
45
51
|
}
|
|
46
52
|
const instructions = typeof native.developer_instructions === 'string' ? native.developer_instructions : '';
|
|
47
53
|
state.fallback = () => {
|
|
54
|
+
evidence.connection('unavailable');
|
|
48
55
|
state.ready = false;
|
|
49
56
|
state.skillsConfig = state.skillsConfig.map((entry) => ({
|
|
50
57
|
...entry,
|
|
@@ -104,9 +111,10 @@ export class CodexXerj {
|
|
|
104
111
|
default_tools_approval_mode: 'approve',
|
|
105
112
|
},
|
|
106
113
|
},
|
|
107
|
-
developer_instructions: `${instructions}\n<gestalt_xerj_capability>\n${guidance}\n</gestalt_xerj_capability>`,
|
|
114
|
+
developer_instructions: `${instructions}\n<gestalt_xerj_capability>\nWorkspace index counts do not establish coverage or freshness for a selected repository. Verify hit identity and current source before relying on it.\n${guidance}\n</gestalt_xerj_capability>`,
|
|
108
115
|
};
|
|
109
116
|
state.ready = true;
|
|
117
|
+
evidence.connection('unknown');
|
|
110
118
|
}
|
|
111
119
|
catch {
|
|
112
120
|
state.fallback();
|
|
@@ -127,15 +135,21 @@ export class CodexXerj {
|
|
|
127
135
|
const server = result.data?.find((entry) => entry.name === xerjServerName);
|
|
128
136
|
if (server?.runtimeStatus === 'connected' &&
|
|
129
137
|
!server.toolsError &&
|
|
130
|
-
xerjTools.every((tool) => Object.hasOwn(server.tools ?? {}, tool)))
|
|
138
|
+
xerjTools.every((tool) => Object.hasOwn(server.tools ?? {}, tool))) {
|
|
139
|
+
state.evidence?.connection('ready');
|
|
131
140
|
return true;
|
|
132
|
-
|
|
141
|
+
}
|
|
142
|
+
if (server?.runtimeStatus !== 'starting') {
|
|
143
|
+
state.evidence?.connection('unavailable');
|
|
133
144
|
return false;
|
|
145
|
+
}
|
|
134
146
|
await beforeDeadline(new Promise((resolve) => setTimeout(resolve, 25)), state.deadline);
|
|
135
147
|
}
|
|
148
|
+
state.evidence?.connection('unavailable');
|
|
136
149
|
return false;
|
|
137
150
|
}
|
|
138
151
|
catch {
|
|
152
|
+
state.evidence?.connection('unavailable');
|
|
139
153
|
return false;
|
|
140
154
|
}
|
|
141
155
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
const record = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
7
|
+
? value
|
|
8
|
+
: undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Codex 0.164 reports only the legacy sandbox projection, not resolved profile
|
|
11
|
+
* read/deny rules. It proves unrestricted reads only without a named profile or
|
|
12
|
+
* profile configuration. Never infer read grants from cwd or writableRoots.
|
|
13
|
+
*/
|
|
14
|
+
export function hasUnrestrictedReadAuthority(settings, configuration, cwd) {
|
|
15
|
+
const observed = record(settings);
|
|
16
|
+
const config = record(configuration);
|
|
17
|
+
if (!observed || observed.cwd !== cwd || !config)
|
|
18
|
+
return false;
|
|
19
|
+
if (observed.activePermissionProfile != null ||
|
|
20
|
+
config.permissions != null ||
|
|
21
|
+
config.default_permissions != null ||
|
|
22
|
+
config.file_system != null ||
|
|
23
|
+
config.fileSystem != null ||
|
|
24
|
+
config.permission_profile != null ||
|
|
25
|
+
config.sandbox_read_only != null)
|
|
26
|
+
return false;
|
|
27
|
+
const policy = record(observed.sandboxPolicy);
|
|
28
|
+
if (!policy)
|
|
29
|
+
return false;
|
|
30
|
+
const keys = Object.keys(policy);
|
|
31
|
+
if (policy.networkAccess !== undefined && typeof policy.networkAccess !== 'boolean')
|
|
32
|
+
return false;
|
|
33
|
+
if (['excludeSlashTmp', 'excludeTmpdirEnvVar'].some((key) => policy[key] !== undefined && typeof policy[key] !== 'boolean'))
|
|
34
|
+
return false;
|
|
35
|
+
if (policy.writableRoots !== undefined &&
|
|
36
|
+
(!Array.isArray(policy.writableRoots) ||
|
|
37
|
+
!policy.writableRoots.every((root) => typeof root === 'string' && root.startsWith('/'))))
|
|
38
|
+
return false;
|
|
39
|
+
switch (policy.type) {
|
|
40
|
+
case 'dangerFullAccess':
|
|
41
|
+
return keys.every((key) => key === 'type');
|
|
42
|
+
case 'readOnly':
|
|
43
|
+
return keys.every((key) => ['type', 'networkAccess'].includes(key));
|
|
44
|
+
case 'workspaceWrite':
|
|
45
|
+
return keys.every((key) => [
|
|
46
|
+
'type',
|
|
47
|
+
'networkAccess',
|
|
48
|
+
'writableRoots',
|
|
49
|
+
'excludeSlashTmp',
|
|
50
|
+
'excludeTmpdirEnvVar',
|
|
51
|
+
].includes(key));
|
|
52
|
+
default:
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { unknownReadiness, } from '../../../shared/contracts/retrieval-readiness.js';
|
|
8
|
+
/** Demand-driven observations only: this class never invokes a tool or scans source. */
|
|
9
|
+
export class ReadinessEvidence {
|
|
10
|
+
value = unknownReadiness();
|
|
11
|
+
key;
|
|
12
|
+
token = randomUUID();
|
|
13
|
+
get generation() {
|
|
14
|
+
return this.token;
|
|
15
|
+
}
|
|
16
|
+
snapshot() {
|
|
17
|
+
return structuredClone(this.value);
|
|
18
|
+
}
|
|
19
|
+
/** The caller owns the source/config/tool generation; even negative results expire on change. */
|
|
20
|
+
bind(key, repository = null) {
|
|
21
|
+
if (this.key !== key) {
|
|
22
|
+
if (this.key !== undefined)
|
|
23
|
+
this.invalidate();
|
|
24
|
+
this.key = key;
|
|
25
|
+
}
|
|
26
|
+
this.value.repository = repository
|
|
27
|
+
? {
|
|
28
|
+
...repository,
|
|
29
|
+
state: 'ready',
|
|
30
|
+
observedAt: new Date().toISOString(),
|
|
31
|
+
generation: this.token,
|
|
32
|
+
}
|
|
33
|
+
: null;
|
|
34
|
+
return this.token;
|
|
35
|
+
}
|
|
36
|
+
invalidate() {
|
|
37
|
+
this.token = randomUUID();
|
|
38
|
+
if (this.value.repository)
|
|
39
|
+
this.value.repository = { ...this.value.repository, state: 'stale' };
|
|
40
|
+
for (const kind of ['connection', 'symbols', 'references', 'coverage']) {
|
|
41
|
+
const prior = this.value[kind];
|
|
42
|
+
this.value[kind] = {
|
|
43
|
+
...prior,
|
|
44
|
+
state: prior.observedAt ? 'stale' : 'unknown',
|
|
45
|
+
reason: 'invalidated',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
connection(state) {
|
|
50
|
+
if (state === 'unavailable' && this.value.connection.state === 'ready')
|
|
51
|
+
this.invalidate();
|
|
52
|
+
this.value.connection = { state, observedAt: new Date().toISOString(), generation: this.token };
|
|
53
|
+
}
|
|
54
|
+
/** Accept only a completed supported native operation, never a catalog/tool-list inference. */
|
|
55
|
+
semantic(generation, tool, succeeded, sourceId) {
|
|
56
|
+
if (generation !== this.token || this.value.connection.state !== 'ready')
|
|
57
|
+
return false;
|
|
58
|
+
const kind = tool === 'get_symbols_overview' || tool === 'find_symbol'
|
|
59
|
+
? 'symbols'
|
|
60
|
+
: tool === 'find_referencing_symbols'
|
|
61
|
+
? 'references'
|
|
62
|
+
: undefined;
|
|
63
|
+
if (!kind)
|
|
64
|
+
return false;
|
|
65
|
+
this.value[kind] = {
|
|
66
|
+
state: succeeded ? 'ready' : 'unavailable',
|
|
67
|
+
observedAt: new Date().toISOString(),
|
|
68
|
+
generation,
|
|
69
|
+
scope: 'source',
|
|
70
|
+
...(sourceId ? { sourceId } : {}),
|
|
71
|
+
...(succeeded ? {} : { reason: 'operation-failed' }),
|
|
72
|
+
};
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
needsProbe(kind) {
|
|
76
|
+
return this.value[kind].generation !== this.token;
|
|
77
|
+
}
|
|
78
|
+
coverage(state, counts = {}) {
|
|
79
|
+
const safe = (value) => value !== undefined && Number.isSafeInteger(value) && value >= 0;
|
|
80
|
+
this.value.coverage = {
|
|
81
|
+
state,
|
|
82
|
+
observedAt: new Date().toISOString(),
|
|
83
|
+
generation: this.token,
|
|
84
|
+
scope: 'workspace-index',
|
|
85
|
+
...(safe(counts.files) ? { files: counts.files } : {}),
|
|
86
|
+
...(safe(counts.records) ? { records: counts.records } : {}),
|
|
87
|
+
...(state === 'unavailable' && counts.records === 0
|
|
88
|
+
? { reason: 'empty-index' }
|
|
89
|
+
: {}),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|