@zergai/ztc 0.19.0-beta.1 → 0.20.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +222 -6
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/agent/agent.d.ts +17 -0
- package/dist/agent/agent.js +77 -4
- package/dist/agent/backends/index.js +5 -3
- package/dist/agent/backends/zrouter_stream.js +8 -4
- package/dist/agent/commands/goal.d.ts +2 -0
- package/dist/agent/commands/goal.js +7 -2
- package/dist/agent/factory.d.ts +2 -0
- package/dist/agent/factory.js +1 -0
- package/dist/agent/request_encoder.d.ts +2 -1
- package/dist/agent/request_encoder.js +4 -3
- package/dist/agent/runtime/policy.d.ts +1 -0
- package/dist/agent/runtime/policy.js +23 -3
- package/dist/agent/runtime/tool_runtime.js +13 -12
- package/dist/agent/subagent.js +2 -1
- package/dist/agent/tools/ask_user.d.ts +1 -1
- package/dist/agent/tools/ask_user.js +15 -8
- package/dist/agent/tools/pane.d.ts +6 -0
- package/dist/agent/tools/pane.js +18 -4
- package/dist/agent/tools/search.js +1 -1
- package/dist/agent/tools/sim_domain_tools.d.ts +4 -0
- package/dist/agent/tools/sim_domain_tools.js +28 -2
- package/dist/agent/tools/types.d.ts +3 -0
- package/dist/app/correlated_turn.d.ts +14 -0
- package/dist/app/correlated_turn.js +78 -0
- package/dist/app/prompt_turn.d.ts +2 -1
- package/dist/app/prompt_turn.js +15 -2
- package/dist/app/session_manager.d.ts +17 -11
- package/dist/app/session_manager.js +74 -30
- package/dist/app/tool_callbacks.d.ts +1 -1
- package/dist/app/workspace_layout_controller.d.ts +21 -2
- package/dist/app/workspace_layout_controller.js +61 -10
- package/dist/app/workspace_monitor.js +67 -7
- package/dist/app/workspace_presets.d.ts +1 -0
- package/dist/app/workspace_presets.js +2 -2
- package/dist/cli.js +6 -2
- package/dist/cli_args.js +1 -0
- package/dist/cli_main.js +48 -2
- package/dist/cli_ratatui.d.ts +56 -8
- package/dist/cli_ratatui.js +689 -109
- package/dist/config/permissions.js +1 -1
- package/dist/config/router_required.d.ts +11 -0
- package/dist/config/router_required.js +23 -0
- package/dist/config/types.d.ts +5 -0
- package/dist/config.d.ts +3 -1
- package/dist/config.js +66 -49
- package/dist/desktop/daily/broker.d.ts +26 -0
- package/dist/desktop/daily/broker.js +140 -0
- package/dist/desktop/daily/codex_config.d.ts +2 -0
- package/dist/desktop/daily/codex_config.js +119 -0
- package/dist/desktop/daily/codex_exec_adapter.d.ts +42 -0
- package/dist/desktop/daily/codex_exec_adapter.js +251 -0
- package/dist/desktop/daily/control_client.d.ts +4 -0
- package/dist/desktop/daily/control_client.js +214 -0
- package/dist/desktop/daily/control_credentials.d.ts +15 -0
- package/dist/desktop/daily/control_credentials.js +85 -0
- package/dist/desktop/daily/control_hello.d.ts +10 -0
- package/dist/desktop/daily/control_hello.js +6 -0
- package/dist/desktop/daily/control_protocol.d.ts +39 -0
- package/dist/desktop/daily/control_protocol.js +4 -0
- package/dist/desktop/daily/control_schema.d.ts +9 -0
- package/dist/desktop/daily/control_schema.js +25 -0
- package/dist/desktop/daily/control_server.d.ts +44 -0
- package/dist/desktop/daily/control_server.js +286 -0
- package/dist/desktop/daily/daily_store.d.ts +71 -0
- package/dist/desktop/daily/daily_store.js +290 -0
- package/dist/desktop/daily/delegated_ztc_contract.d.ts +37 -0
- package/dist/desktop/daily/delegated_ztc_contract.js +90 -0
- package/dist/desktop/daily/desktop_wiring.d.ts +112 -0
- package/dist/desktop/daily/desktop_wiring.js +1048 -0
- package/dist/desktop/daily/enrollment.d.ts +74 -0
- package/dist/desktop/daily/enrollment.js +77 -0
- package/dist/desktop/daily/file_facts.d.ts +2 -0
- package/dist/desktop/daily/file_facts.js +41 -0
- package/dist/desktop/daily/lease.d.ts +57 -0
- package/dist/desktop/daily/lease.js +332 -0
- package/dist/desktop/daily/legacy_codex_homes.d.ts +1 -0
- package/dist/desktop/daily/legacy_codex_homes.js +26 -0
- package/dist/desktop/daily/native_pane_launcher.d.ts +31 -0
- package/dist/desktop/daily/native_pane_launcher.js +226 -0
- package/dist/desktop/daily/native_records.d.ts +13 -0
- package/dist/desktop/daily/native_records.js +81 -0
- package/dist/desktop/daily/native_status.d.ts +4 -0
- package/dist/desktop/daily/native_status.js +28 -0
- package/dist/desktop/daily/native_tool.d.ts +134 -0
- package/dist/desktop/daily/native_tool.js +91 -0
- package/dist/desktop/daily/owner_files.d.ts +3 -0
- package/dist/desktop/daily/owner_files.js +88 -0
- package/dist/desktop/daily/owner_seals.d.ts +9 -0
- package/dist/desktop/daily/owner_seals.js +56 -0
- package/dist/desktop/daily/process_identity.d.ts +13 -0
- package/dist/desktop/daily/process_identity.js +137 -0
- package/dist/desktop/daily/profile_bootstrap.d.ts +60 -0
- package/dist/desktop/daily/profile_bootstrap.js +194 -0
- package/dist/desktop/daily/raw_receipts.d.ts +1 -0
- package/dist/desktop/daily/raw_receipts.js +18 -0
- package/dist/desktop/daily/recipes.d.ts +36 -0
- package/dist/desktop/daily/recipes.js +177 -0
- package/dist/desktop/daily/router_state.d.ts +33 -0
- package/dist/desktop/daily/router_state.js +39 -0
- package/dist/desktop/daily/schema_registry.d.ts +19 -0
- package/dist/desktop/daily/schema_registry.js +71 -0
- package/dist/desktop/daily/source_baseline.d.ts +13 -0
- package/dist/desktop/daily/source_baseline.js +44 -0
- package/dist/desktop/daily/status_restore.d.ts +9 -0
- package/dist/desktop/daily/status_restore.js +114 -0
- package/dist/desktop/daily/summary.d.ts +59 -0
- package/dist/desktop/daily/summary.js +75 -0
- package/dist/desktop/daily/worker_provenance.d.ts +2 -0
- package/dist/desktop/daily/worker_provenance.js +18 -0
- package/dist/desktop/daily/worker_stop.d.ts +2 -0
- package/dist/desktop/daily/worker_stop.js +26 -0
- package/dist/desktop/daily/ztc_headless_adapter.d.ts +40 -0
- package/dist/desktop/daily/ztc_headless_adapter.js +194 -0
- package/dist/domain.d.ts +1 -1
- package/dist/domain.js +1 -1
- package/dist/events.d.ts +23 -1
- package/dist/headless.d.ts +9 -0
- package/dist/headless.js +161 -26
- package/dist/headless_approval.d.ts +29 -0
- package/dist/headless_approval.js +69 -0
- package/dist/headless_cli.js +2 -0
- package/dist/headless_cli_args.d.ts +4 -0
- package/dist/headless_cli_args.js +5 -0
- package/dist/library.d.ts +20 -0
- package/dist/library.js +66 -12
- package/dist/mcp/client.d.ts +16 -1
- package/dist/mcp/client.js +11 -5
- package/dist/mcp/registry.d.ts +3 -1
- package/dist/mcp/registry.js +10 -1
- package/dist/panes/pane_registry.js +14 -3
- package/dist/panes/types.d.ts +7 -1
- package/dist/panes/ztc_launch.d.ts +5 -0
- package/dist/panes/ztc_launch.js +30 -14
- package/dist/session.d.ts +6 -3
- package/dist/session.js +21 -2
- package/dist/simulation/domain_types.d.ts +2 -0
- package/dist/simulation/domains/loader.d.ts +7 -1
- package/dist/simulation/domains/loader.js +33 -1
- package/dist/simulation/living/context.d.ts +19 -19
- package/dist/simulation/living/definition.d.ts +2 -2
- package/dist/simulation/living/frame.d.ts +1 -1
- package/dist/simulation/living/open-world.d.ts +3 -3
- package/dist/simulation/living/types.d.ts +24 -24
- package/dist/simulation/toolkit/dynamic_state.d.ts +1 -1
- package/dist/skills/bundled/init-context/SKILL.md +16 -0
- package/dist/skills/registry.js +7 -3
- package/dist/tools.d.ts +6 -0
- package/dist/tools.js +14 -0
- package/dist/types.d.ts +30 -0
- package/dist/ui/ratatui/mux_persistence.d.ts +3 -1
- package/dist/ui/ratatui/mux_persistence.js +9 -2
- package/dist/ui/ratatui/pane_credential_broker.d.ts +8 -4
- package/dist/ui/ratatui/pane_credential_broker.js +26 -11
- package/dist/ui/ratatui/pane_relay.d.ts +2 -0
- package/dist/ui/ratatui/process.d.ts +6 -0
- package/dist/ui/ratatui/process.js +104 -6
- package/dist/ui/ratatui/protocol.d.ts +13 -0
- package/dist/ui/ratatui/protocol.js +1 -0
- package/dist/utils/compaction.js +6 -4
- package/dist/utils/subprocess_env.js +2 -0
- package/dist/web/browser_events.d.ts +10 -0
- package/dist/web/browser_events.js +9 -0
- package/dist/web/mirror_stream.d.ts +17 -5
- package/dist/web/mirror_stream.js +105 -13
- package/dist/web/pane_credentials.d.ts +6 -3
- package/dist/web/pane_credentials.js +20 -12
- package/dist/web/pane_registry.js +1 -0
- package/dist/workspace_agent.d.ts +2 -1
- package/dist/workspace_agent.js +7 -1
- package/dist/workspace_collision.d.ts +3 -0
- package/dist/workspace_collision.js +1 -1
- package/dist/workspace_layout.d.ts +3 -2
- package/dist/workspace_layout.js +8 -2
- package/dist/workspace_runtime.d.ts +7 -1
- package/dist/workspace_runtime.js +3 -3
- package/dist/zerg/manifest_builder_tools.js +35 -4
- package/dist/zerg/manifest_validator.js +55 -0
- package/dist/zlm-embed.mjs +261 -116
- package/node_modules/@zerg/model-contracts/README.md +19 -0
- package/node_modules/@zerg/model-contracts/index.js +19 -1
- package/node_modules/@ztc/sim-graph/dist/index.d.ts +1 -0
- package/node_modules/@ztc/sim-graph/dist/index.js +1 -0
- package/node_modules/@ztc/sim-graph/dist/sim_graph.d.ts +351 -0
- package/node_modules/@ztc/sim-graph/dist/sim_graph.js +795 -0
- package/node_modules/@ztc/sim-graph/package.json +37 -0
- package/node_modules/@ztc/sim-graph/src/index.ts +1 -0
- package/node_modules/@ztc/sim-graph/src/sim_graph.ts +1305 -0
- package/package.json +25 -24
- package/packages/model-contracts/README.md +19 -0
- package/packages/model-contracts/index.js +19 -1
|
@@ -25,6 +25,7 @@ import { readRepoConfig } from '../config/repo_config.js';
|
|
|
25
25
|
import { runtimeDiag } from '../utils/debug_log.js';
|
|
26
26
|
import { getModelCatalogPayload } from '../panes/model_catalog.js';
|
|
27
27
|
import { isMeaningfulUserInput } from '../app/input_validation.js';
|
|
28
|
+
import { validTurnCorrelation } from '../app/correlated_turn.js';
|
|
28
29
|
import { receiveIntakeRequest, listIntakeReceipts } from '../intake/store.js';
|
|
29
30
|
import { AttentionQueue } from '../attention/queue.js';
|
|
30
31
|
import { ObserverQueryRedaction } from './observer_query_redaction.js';
|
|
@@ -97,8 +98,11 @@ const OBSERVER_EVENT_TYPES = new Set([
|
|
|
97
98
|
*/
|
|
98
99
|
const PANE_CREDENTIAL_PATHS = ['/bus/connect', '/bus/send', '/pane-publication', '/pane-events'];
|
|
99
100
|
const PANE_CREDENTIAL_EXACT_PATHS = new Set(['/pane-store-event', '/input', '/submit', '/pane-input', '/colony/agents/restart']);
|
|
100
|
-
/**
|
|
101
|
-
|
|
101
|
+
/**
|
|
102
|
+
* What a workspace monitor's credential also reaches: the runtime it shows, the decisions it answers, and, for the
|
|
103
|
+
* desktop's Status, the native pane its row drills into and back out of.
|
|
104
|
+
*/
|
|
105
|
+
const WORKSPACE_MONITOR_PATHS = new Set(['/workspace/runtime', '/ask-user-answer', '/workspace/pane-action']);
|
|
102
106
|
/** How long a request presenting a pane credential waits for its owner to hear the pane was created. */
|
|
103
107
|
const PANE_CREDENTIAL_SETTLE_MS = 10_000;
|
|
104
108
|
const OBSERVER_GET_PATHS = new Set([
|
|
@@ -166,6 +170,9 @@ export class MirrorStreamServer {
|
|
|
166
170
|
startedAt = Date.now();
|
|
167
171
|
runtimeStatsProvider = null;
|
|
168
172
|
inputCallback = null;
|
|
173
|
+
correlatedInputCallback = null;
|
|
174
|
+
correlatedInputAvailable = () => true;
|
|
175
|
+
promptTurnsProvider = () => [];
|
|
169
176
|
mediaDir;
|
|
170
177
|
toolImageJobs = new Set();
|
|
171
178
|
mediaById = new Map();
|
|
@@ -175,6 +182,9 @@ export class MirrorStreamServer {
|
|
|
175
182
|
/** Active requests belong to a pane; retained transcript capacity is not their lifecycle. */
|
|
176
183
|
pendingQuestions = new Map();
|
|
177
184
|
workspaceOwnerId = randomUUID();
|
|
185
|
+
dailyProvider = null;
|
|
186
|
+
dailyRefresh = null;
|
|
187
|
+
dailyAction = null;
|
|
178
188
|
widgetAnswerCallback = null;
|
|
179
189
|
hookApprovalCallback = null;
|
|
180
190
|
// EPO-638/637 — pending captures keyed by capture_id. Resolvers wait for
|
|
@@ -241,6 +251,13 @@ export class MirrorStreamServer {
|
|
|
241
251
|
setRuntimeStatsProvider(fn) {
|
|
242
252
|
this.runtimeStatsProvider = fn;
|
|
243
253
|
}
|
|
254
|
+
setPromptTurnsProvider(fn) {
|
|
255
|
+
this.promptTurnsProvider = fn;
|
|
256
|
+
}
|
|
257
|
+
onCorrelatedInput(callback, available = () => true) {
|
|
258
|
+
this.correlatedInputCallback = callback;
|
|
259
|
+
this.correlatedInputAvailable = available;
|
|
260
|
+
}
|
|
244
261
|
/**
|
|
245
262
|
* Number of live SSE viewers — browser clients on `GET /events`. zmux and
|
|
246
263
|
* other native renderers use their own socket, not `/events`, so this counts
|
|
@@ -259,6 +276,12 @@ export class MirrorStreamServer {
|
|
|
259
276
|
buildStatsPayload() {
|
|
260
277
|
const memory = process.memoryUsage();
|
|
261
278
|
const appStats = this.runtimeStatsProvider ? this.runtimeStatsProvider() : {};
|
|
279
|
+
const primary = this.panes.get(0);
|
|
280
|
+
// The actual CLI session exists before its first usage receipt. A history
|
|
281
|
+
// filename or an accounting session must never substitute for this binding.
|
|
282
|
+
const primarySession = primary?.sessionId
|
|
283
|
+
? { schema_version: 1, pane_id: 0, session_id: primary.sessionId, is_alive: primary.isAlive !== false }
|
|
284
|
+
: null;
|
|
262
285
|
return {
|
|
263
286
|
clients: this.clients.size,
|
|
264
287
|
historyLength: this.history.length(),
|
|
@@ -269,6 +292,8 @@ export class MirrorStreamServer {
|
|
|
269
292
|
multiPaneMode: this.multiPaneMode,
|
|
270
293
|
paneCount: this.multiPaneMode ? this.panes.size() : 1,
|
|
271
294
|
panes: this.multiPaneMode ? this.panes.ids() : [],
|
|
295
|
+
primary_session: primarySession,
|
|
296
|
+
turns: { schema_version: 1, input_supported: this.correlatedInputCallback !== null && this.correlatedInputAvailable(), items: this.promptTurnsProvider() },
|
|
272
297
|
uptimeMs: Date.now() - this.startedAt,
|
|
273
298
|
memory: {
|
|
274
299
|
rss: memory.rss,
|
|
@@ -315,7 +340,7 @@ export class MirrorStreamServer {
|
|
|
315
340
|
busObservers = [];
|
|
316
341
|
// Global observers that see every published mirror event.
|
|
317
342
|
eventObservers = [];
|
|
318
|
-
constructor(port = 3940, host = '::', persistEvents = true, persistenceKey) {
|
|
343
|
+
constructor(port = 3940, host = '::', persistEvents = true, persistenceKey, primarySessionId) {
|
|
319
344
|
this.port = port;
|
|
320
345
|
this.host = host;
|
|
321
346
|
this.server.on('upgrade', this.handleUpgrade.bind(this));
|
|
@@ -356,6 +381,12 @@ export class MirrorStreamServer {
|
|
|
356
381
|
// (Seam A) owns the bounded ring, the seq counter, and JSONL replay.
|
|
357
382
|
this.persistenceKey = (persistenceKey || process.env.ZTC_MIRROR_PERSISTENCE_KEY || process.env.COLONY_SESSION_ID || '').trim() || null;
|
|
358
383
|
this.originSessionId = this.persistenceKey ?? randomUUID();
|
|
384
|
+
// A history filename is not proof of a live conversation. Only the CLI's
|
|
385
|
+
// explicitly supplied session identity seeds the primary runtime pane.
|
|
386
|
+
if (typeof primarySessionId === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]{0,255}$/.test(primarySessionId)) {
|
|
387
|
+
this.panes.ensureOverseer();
|
|
388
|
+
this.panes.get(0).sessionId = primarySessionId;
|
|
389
|
+
}
|
|
359
390
|
this.history = persistEvents
|
|
360
391
|
? new JsonlHistoryStore(JsonlHistoryStore.sessionFilePath(this.persistenceKey), undefined, undefined, (event) => this.isEphemeralWidgetEvent(event.type))
|
|
361
392
|
: new MemoryHistoryStore();
|
|
@@ -445,8 +476,13 @@ export class MirrorStreamServer {
|
|
|
445
476
|
getEventHistory() {
|
|
446
477
|
return this.history.snapshot();
|
|
447
478
|
}
|
|
479
|
+
setDailyDesktop(provider, refresh, action) {
|
|
480
|
+
this.dailyProvider = provider;
|
|
481
|
+
this.dailyRefresh = refresh;
|
|
482
|
+
this.dailyAction = action;
|
|
483
|
+
}
|
|
448
484
|
getWorkspaceRuntimeSnapshot() {
|
|
449
|
-
return buildWorkspaceRuntimeSnapshot(this.workspaceOwnerId, this.panes.entries(), [...this.pendingQuestions.values()]);
|
|
485
|
+
return buildWorkspaceRuntimeSnapshot(this.workspaceOwnerId, this.panes.entries(), [...this.pendingQuestions.values()], new Date(), this.dailyProvider?.());
|
|
450
486
|
}
|
|
451
487
|
setSuperuser(value) {
|
|
452
488
|
this.operatorIsSuperuser = value;
|
|
@@ -2092,6 +2128,8 @@ export class MirrorStreamServer {
|
|
|
2092
2128
|
return this.readMultipartMessageInput(req, contentType);
|
|
2093
2129
|
const body = await this.readBuffer(req, MAX_MIRROR_UPLOAD_BYTES);
|
|
2094
2130
|
const parsed = JSON.parse(body.toString('utf8'));
|
|
2131
|
+
if (parsed.correlation_id !== undefined && !validTurnCorrelation(parsed.correlation_id))
|
|
2132
|
+
throw new Error('invalid turn correlation');
|
|
2095
2133
|
const text = typeof parsed.text === 'string' ? parsed.text : '';
|
|
2096
2134
|
const attachments = Array.isArray(parsed.attachments)
|
|
2097
2135
|
? parsed.attachments
|
|
@@ -2100,7 +2138,8 @@ export class MirrorStreamServer {
|
|
|
2100
2138
|
.slice(0, MAX_MIRROR_IMAGE_COUNT)
|
|
2101
2139
|
: [];
|
|
2102
2140
|
const paneId = Number(parsed.pane_id);
|
|
2103
|
-
return { text: stripForeignMediaTokens(text), attachments, ...(Number.isFinite(paneId) ? { pane_id: paneId } : {})
|
|
2141
|
+
return { text: stripForeignMediaTokens(text), attachments, ...(Number.isFinite(paneId) ? { pane_id: paneId } : {}),
|
|
2142
|
+
...(parsed.correlation_id !== undefined ? { correlation_id: parsed.correlation_id } : {}) };
|
|
2104
2143
|
}
|
|
2105
2144
|
async readMultipartMessageInput(req, contentType) {
|
|
2106
2145
|
const match = contentType.match(/boundary=(?:(?:"([^"]+)")|([^;]+))/i);
|
|
@@ -2111,10 +2150,17 @@ export class MirrorStreamServer {
|
|
|
2111
2150
|
const parts = this.parseMultipartBody(body, boundary);
|
|
2112
2151
|
let text = '';
|
|
2113
2152
|
let paneId;
|
|
2153
|
+
let correlationId;
|
|
2114
2154
|
const attachments = [];
|
|
2115
2155
|
for (const part of parts) {
|
|
2116
2156
|
if (part.name === 'text')
|
|
2117
2157
|
text = part.data.toString('utf8');
|
|
2158
|
+
else if (part.name === 'correlation_id') {
|
|
2159
|
+
const value = part.data.toString('utf8');
|
|
2160
|
+
if (correlationId !== undefined || !validTurnCorrelation(value))
|
|
2161
|
+
throw new Error('invalid turn correlation');
|
|
2162
|
+
correlationId = value;
|
|
2163
|
+
}
|
|
2118
2164
|
else if (part.name === 'pane_id') {
|
|
2119
2165
|
const parsedPaneId = Number(part.data.toString('utf8'));
|
|
2120
2166
|
if (Number.isFinite(parsedPaneId))
|
|
@@ -2124,7 +2170,8 @@ export class MirrorStreamServer {
|
|
|
2124
2170
|
attachments.push(await this.storeMirrorImage(part.data, part.filename));
|
|
2125
2171
|
}
|
|
2126
2172
|
}
|
|
2127
|
-
return { text: stripForeignMediaTokens(text), attachments, ...(paneId !== undefined ? { pane_id: paneId } : {})
|
|
2173
|
+
return { text: stripForeignMediaTokens(text), attachments, ...(paneId !== undefined ? { pane_id: paneId } : {}),
|
|
2174
|
+
...(correlationId !== undefined ? { correlation_id: correlationId } : {}) };
|
|
2128
2175
|
}
|
|
2129
2176
|
parseMultipartBody(body, boundary) {
|
|
2130
2177
|
const bodyText = body.toString('latin1');
|
|
@@ -3068,6 +3115,32 @@ export class MirrorStreamServer {
|
|
|
3068
3115
|
}
|
|
3069
3116
|
return;
|
|
3070
3117
|
}
|
|
3118
|
+
if (url.pathname === '/workspace/pane-action') {
|
|
3119
|
+
// Status posts with its own workspace monitor's credential; it holds no internal token.
|
|
3120
|
+
if (!this.requireWorkspaceMonitor(auth, res))
|
|
3121
|
+
return;
|
|
3122
|
+
let status = 400;
|
|
3123
|
+
let ok = false;
|
|
3124
|
+
if (req.headers['x-ztc-workspace-owner'] !== this.workspaceOwnerId)
|
|
3125
|
+
status = 409;
|
|
3126
|
+
else if (req.method !== 'POST')
|
|
3127
|
+
status = 405;
|
|
3128
|
+
else {
|
|
3129
|
+
try {
|
|
3130
|
+
const input = await this.readJsonBody(req, 1024);
|
|
3131
|
+
if (input && Object.keys(input).every(key => ['action', 'pane_id'].includes(key))
|
|
3132
|
+
&& (input.action === 'zoom' || input.action === 'collapse') && Number.isSafeInteger(input.pane_id)
|
|
3133
|
+
&& this.dailyProvider?.().children.some(child => child.paneId === input.pane_id)) {
|
|
3134
|
+
ok = this.dailyAction?.(input.action, input.pane_id) ?? false;
|
|
3135
|
+
status = ok ? 200 : 503;
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
catch { }
|
|
3139
|
+
}
|
|
3140
|
+
res.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
3141
|
+
res.end(JSON.stringify(ok ? { ok } : { ok, error: 'Native pane action refused' }));
|
|
3142
|
+
return;
|
|
3143
|
+
}
|
|
3071
3144
|
if (url.pathname === '/workspace/runtime') {
|
|
3072
3145
|
if (!this.requireWorkspaceMonitor(auth, res))
|
|
3073
3146
|
return;
|
|
@@ -3082,6 +3155,8 @@ export class MirrorStreamServer {
|
|
|
3082
3155
|
return;
|
|
3083
3156
|
}
|
|
3084
3157
|
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
3158
|
+
if (url.searchParams.get('refresh') === '1')
|
|
3159
|
+
await this.dailyRefresh?.();
|
|
3085
3160
|
res.end(JSON.stringify(this.getWorkspaceRuntimeSnapshot()));
|
|
3086
3161
|
return;
|
|
3087
3162
|
}
|
|
@@ -3545,6 +3620,11 @@ export class MirrorStreamServer {
|
|
|
3545
3620
|
if ((url.pathname === '/input' || url.pathname === '/submit') && req.method === 'POST') {
|
|
3546
3621
|
try {
|
|
3547
3622
|
const input = await this.readMessageInput(req);
|
|
3623
|
+
if (input.correlation_id !== undefined) {
|
|
3624
|
+
res.writeHead(409, { 'Content-Type': 'application/json' });
|
|
3625
|
+
res.end(JSON.stringify({ ok: false, error: 'correlated input requires /pane-input' }));
|
|
3626
|
+
return;
|
|
3627
|
+
}
|
|
3548
3628
|
if ((isMeaningfulUserInput(input.text) || input.attachments.length > 0) && this.inputCallback) {
|
|
3549
3629
|
await this.maybeCreateColonyCheckpoint(input.text, 0);
|
|
3550
3630
|
// The person's only from the browser; from a ZTC process or a pane, relayed (see MirrorInputVia).
|
|
@@ -4271,10 +4351,22 @@ export class MirrorStreamServer {
|
|
|
4271
4351
|
const cleanText = input.text.replace(/\n$/, '');
|
|
4272
4352
|
const bodyPaneId = Number(input.pane_id);
|
|
4273
4353
|
const hasContent = isMeaningfulUserInput(cleanText) || input.attachments.length > 0;
|
|
4354
|
+
if (input.correlation_id !== undefined && bodyPaneId !== 0) {
|
|
4355
|
+
res.writeHead(409, { 'Content-Type': 'application/json' });
|
|
4356
|
+
res.end(JSON.stringify({ ok: false, error: 'correlated input requires the primary session' }));
|
|
4357
|
+
return;
|
|
4358
|
+
}
|
|
4274
4359
|
const sender = this.inputSender(auth);
|
|
4275
4360
|
if (bodyPaneId === 0) {
|
|
4276
4361
|
// Route to parent's input callback (Overseer / pane 0)
|
|
4277
4362
|
if (hasContent && this.inputCallback) {
|
|
4363
|
+
if (input.correlation_id !== undefined) {
|
|
4364
|
+
const receipt = await this.correlatedInputCallback?.({ text: cleanText, attachments: input.attachments,
|
|
4365
|
+
pane_id: 0, correlation_id: input.correlation_id });
|
|
4366
|
+
res.writeHead(receipt?.ok ? 200 : 409, { 'Content-Type': 'application/json' });
|
|
4367
|
+
res.end(JSON.stringify(receipt ?? { ok: false, error: 'correlated input unavailable' }));
|
|
4368
|
+
return;
|
|
4369
|
+
}
|
|
4278
4370
|
await this.maybeCreateColonyCheckpoint(cleanText, 0);
|
|
4279
4371
|
this.inputCallback({ text: cleanText, attachments: input.attachments }, this.inputVia(auth));
|
|
4280
4372
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
@@ -4430,7 +4522,7 @@ export class MirrorStreamServer {
|
|
|
4430
4522
|
return;
|
|
4431
4523
|
}
|
|
4432
4524
|
if (url.pathname === '/status' || url.pathname === '/stats') {
|
|
4433
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
4525
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
4434
4526
|
res.end(JSON.stringify(this.buildStatsPayload()));
|
|
4435
4527
|
return;
|
|
4436
4528
|
}
|
|
@@ -4516,17 +4608,17 @@ function resolveMirrorHost(host) {
|
|
|
4516
4608
|
// proxies (including Fly) expect.
|
|
4517
4609
|
return host ?? process.env.ZTC_MIRROR_HOST ?? '0.0.0.0';
|
|
4518
4610
|
}
|
|
4519
|
-
export function createIsolatedMirrorStreamServer(port = 3940, persistEvents = true, persistenceKey, host) {
|
|
4520
|
-
return new MirrorStreamServer(port, resolveMirrorHost(host), persistEvents, persistenceKey);
|
|
4611
|
+
export function createIsolatedMirrorStreamServer(port = 3940, persistEvents = true, persistenceKey, host, primarySessionId) {
|
|
4612
|
+
return new MirrorStreamServer(port, resolveMirrorHost(host), persistEvents, persistenceKey, primarySessionId);
|
|
4521
4613
|
}
|
|
4522
|
-
export function createMirrorStreamServer(port = 3940, persistEvents = true, persistenceKey, host) {
|
|
4614
|
+
export function createMirrorStreamServer(port = 3940, persistEvents = true, persistenceKey, host, primarySessionId) {
|
|
4523
4615
|
if (!mirrorStreamServer) {
|
|
4524
|
-
mirrorStreamServer = createIsolatedMirrorStreamServer(port, persistEvents, persistenceKey, host);
|
|
4616
|
+
mirrorStreamServer = createIsolatedMirrorStreamServer(port, persistEvents, persistenceKey, host, primarySessionId);
|
|
4525
4617
|
}
|
|
4526
4618
|
return mirrorStreamServer;
|
|
4527
4619
|
}
|
|
4528
|
-
export async function startMirrorStreamServer(port = 3940, persistenceKey) {
|
|
4529
|
-
const server = createMirrorStreamServer(port, true, persistenceKey);
|
|
4620
|
+
export async function startMirrorStreamServer(port = 3940, persistenceKey, primarySessionId) {
|
|
4621
|
+
const server = createMirrorStreamServer(port, true, persistenceKey, undefined, primarySessionId);
|
|
4530
4622
|
await server.start();
|
|
4531
4623
|
return server;
|
|
4532
4624
|
}
|
|
@@ -44,12 +44,14 @@ export declare function withoutMirrorCredentials(env: NodeJS.ProcessEnv): NodeJS
|
|
|
44
44
|
export type PaneCredentialScope = 'pane' | 'workspace-monitor';
|
|
45
45
|
/**
|
|
46
46
|
* The values a launcher puts under PANE_CREDENTIAL_ENV in a create_pane env to ask for a credential. The pane
|
|
47
|
-
* transport always replaces the value: with a plain credential, or with '' when it hands a workspace monitor's
|
|
48
|
-
* one-time file (PANE_CREDENTIAL_FILE_FLAG) or no mirror in this process has listened on the pane's port.
|
|
49
|
-
* given a credential in such a file without asking
|
|
47
|
+
* transport always replaces the value: with a plain credential, or with '' when it hands a workspace monitor's, or a
|
|
48
|
+
* ZTC's, in a one-time file (PANE_CREDENTIAL_FILE_FLAG) or no mirror in this process has listened on the pane's port.
|
|
49
|
+
* A ZTC pane is given a credential in such a file without asking; ZTC_PANE_CREDENTIAL_REQUEST asks for the same for a
|
|
50
|
+
* pane of another type that runs a ZTC (a native ZTC pane, whose launcher starts it as a process pane).
|
|
50
51
|
*/
|
|
51
52
|
export declare const PANE_CREDENTIAL_REQUEST = "request";
|
|
52
53
|
export declare const WORKSPACE_MONITOR_CREDENTIAL_REQUEST = "request:workspace-monitor";
|
|
54
|
+
export declare const ZTC_PANE_CREDENTIAL_REQUEST = "request:ztc";
|
|
53
55
|
/** Who a bound credential authenticates as. */
|
|
54
56
|
export interface PanePrincipal {
|
|
55
57
|
readonly paneId: number;
|
|
@@ -116,6 +118,7 @@ export declare function removePaneCredentialHandoff(path: string): void;
|
|
|
116
118
|
* text whatever it says, and stays as it is. Returns whether a credential was taken.
|
|
117
119
|
*/
|
|
118
120
|
export declare function consumePaneCredentialHandoff(argv?: string[]): boolean;
|
|
121
|
+
export declare function takePaneCredentialHandoff(path: string): string | null;
|
|
119
122
|
/**
|
|
120
123
|
* The header a pane's program presents to its mirror: the pane's own credential, the one this process took from its
|
|
121
124
|
* handoff or else the one ENV holds (a Claude Code or Codex pane's workspace tools), or, under a ZTC from before
|
|
@@ -52,12 +52,14 @@ export function withoutMirrorCredentials(env) {
|
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* The values a launcher puts under PANE_CREDENTIAL_ENV in a create_pane env to ask for a credential. The pane
|
|
55
|
-
* transport always replaces the value: with a plain credential, or with '' when it hands a workspace monitor's
|
|
56
|
-
* one-time file (PANE_CREDENTIAL_FILE_FLAG) or no mirror in this process has listened on the pane's port.
|
|
57
|
-
* given a credential in such a file without asking
|
|
55
|
+
* transport always replaces the value: with a plain credential, or with '' when it hands a workspace monitor's, or a
|
|
56
|
+
* ZTC's, in a one-time file (PANE_CREDENTIAL_FILE_FLAG) or no mirror in this process has listened on the pane's port.
|
|
57
|
+
* A ZTC pane is given a credential in such a file without asking; ZTC_PANE_CREDENTIAL_REQUEST asks for the same for a
|
|
58
|
+
* pane of another type that runs a ZTC (a native ZTC pane, whose launcher starts it as a process pane).
|
|
58
59
|
*/
|
|
59
60
|
export const PANE_CREDENTIAL_REQUEST = 'request';
|
|
60
61
|
export const WORKSPACE_MONITOR_CREDENTIAL_REQUEST = 'request:workspace-monitor';
|
|
62
|
+
export const ZTC_PANE_CREDENTIAL_REQUEST = 'request:ztc';
|
|
61
63
|
/** How long an unbound credential waits for its pane before it is dropped. */
|
|
62
64
|
const PENDING_TTL_MS = 30_000;
|
|
63
65
|
function digest(token) {
|
|
@@ -235,35 +237,41 @@ export function consumePaneCredentialHandoff(argv = process.argv) {
|
|
|
235
237
|
const value = argv[at + 1];
|
|
236
238
|
const path = value !== undefined && !value.startsWith('-') ? value : '';
|
|
237
239
|
argv.splice(at, path ? 2 : 1);
|
|
240
|
+
const token = takePaneCredentialHandoff(path);
|
|
241
|
+
if (token === null)
|
|
242
|
+
return false;
|
|
243
|
+
heldCredential = token;
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
export function takePaneCredentialHandoff(path) {
|
|
238
247
|
const directory = path ? handoffDirectory(path) : null;
|
|
239
248
|
if (!directory)
|
|
240
|
-
return
|
|
249
|
+
return null;
|
|
241
250
|
let folder;
|
|
242
251
|
try {
|
|
243
252
|
folder = lstatSync(directory);
|
|
244
253
|
}
|
|
245
254
|
catch {
|
|
246
|
-
return
|
|
255
|
+
return null;
|
|
247
256
|
}
|
|
248
257
|
const posix = process.platform !== 'win32';
|
|
249
258
|
const uid = posix ? process.getuid?.() : undefined;
|
|
250
259
|
// Never read, or delete, a directory that isn't a real one of this user's.
|
|
251
260
|
if (!folder.isDirectory() || (uid !== undefined && folder.uid !== uid))
|
|
252
|
-
return
|
|
261
|
+
return null;
|
|
253
262
|
try {
|
|
254
263
|
const file = lstatSync(path);
|
|
255
264
|
if (!file.isFile() || file.size > 512 || (uid !== undefined && file.uid !== uid))
|
|
256
|
-
return
|
|
265
|
+
return null;
|
|
257
266
|
if (posix && ((folder.mode | file.mode) & 0o077) !== 0)
|
|
258
|
-
return
|
|
267
|
+
return null;
|
|
259
268
|
const token = readFileSync(path, 'utf8').trim();
|
|
260
269
|
if (!HANDOFF_TOKEN.test(token))
|
|
261
|
-
return
|
|
262
|
-
|
|
263
|
-
return true;
|
|
270
|
+
return null;
|
|
271
|
+
return token;
|
|
264
272
|
}
|
|
265
273
|
catch {
|
|
266
|
-
return
|
|
274
|
+
return null;
|
|
267
275
|
}
|
|
268
276
|
finally {
|
|
269
277
|
try {
|
|
@@ -94,6 +94,7 @@ export class PaneRegistry {
|
|
|
94
94
|
commandJobs: prev?.commandJobs,
|
|
95
95
|
commandPane: prev?.commandPane,
|
|
96
96
|
todos: prev?.todos,
|
|
97
|
+
sessionId: prev?.sessionId,
|
|
97
98
|
usage: prev?.usage,
|
|
98
99
|
usageSessionId: prev?.usageSessionId,
|
|
99
100
|
// Preserve cached content across a relayout — SSE reconnect replay
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type NativeWorkspaceState } from './desktop/daily/native_records.js';
|
|
1
2
|
import { type Session } from './session.js';
|
|
2
3
|
import type { MuxSessionState } from './ui/ratatui/protocol.js';
|
|
3
4
|
import type { PaneSessionSpec } from './panes/types.js';
|
|
4
5
|
/** Canonical links add ownership context without replacing captured executable intent. */
|
|
5
|
-
export declare function linkWorkspaceAgentSessions(state:
|
|
6
|
+
export declare function linkWorkspaceAgentSessions(state: NativeWorkspaceState, specs: PaneSessionSpec[]): NativeWorkspaceState;
|
|
6
7
|
/** Resolve within the saved project only; reading does not pin or replay the session. */
|
|
7
8
|
export declare function resolveWorkspaceAgentSession(reference: NonNullable<MuxSessionState['panes'][number]['agent_session']>): Promise<Session>;
|
package/dist/workspace_agent.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nativeWorkspaceState } from './desktop/daily/native_records.js';
|
|
1
2
|
import { realpath } from 'node:fs/promises';
|
|
2
3
|
import { resolve } from 'node:path';
|
|
3
4
|
import { randomUUID } from 'node:crypto';
|
|
@@ -7,12 +8,17 @@ import { inspectWorkspaceSessions } from './workspace_collision.js';
|
|
|
7
8
|
/** Canonical links add ownership context without replacing captured executable intent. */
|
|
8
9
|
export function linkWorkspaceAgentSessions(state, specs) {
|
|
9
10
|
const copy = structuredClone(state);
|
|
11
|
+
for (const spec of specs)
|
|
12
|
+
if (spec.launchSpec?.kind === 'native_tool' && copy.panes.some(pane => pane.id === spec.paneId)) {
|
|
13
|
+
copy.native_tools ??= {};
|
|
14
|
+
copy.native_tools[String(spec.paneId)] = spec.launchSpec.record;
|
|
15
|
+
}
|
|
10
16
|
for (const pane of copy.panes) {
|
|
11
17
|
const spec = specs.find(entry => entry.paneId === pane.id)?.launchSpec;
|
|
12
18
|
if (!pane.agent_session && spec?.kind === 'ztc' && spec.cwd)
|
|
13
19
|
pane.agent_session = { session_id: spec.session.id, project_path: resolve(spec.cwd) };
|
|
14
20
|
}
|
|
15
|
-
return copy;
|
|
21
|
+
return nativeWorkspaceState(copy);
|
|
16
22
|
}
|
|
17
23
|
/** Resolve within the saved project only; reading does not pin or replay the session. */
|
|
18
24
|
export async function resolveWorkspaceAgentSession(reference) {
|
|
@@ -43,6 +43,9 @@ export declare class WorkspaceIsolationError extends Error {
|
|
|
43
43
|
readonly retainedTarget: string | null;
|
|
44
44
|
constructor(message: string, retainedTarget?: string | null);
|
|
45
45
|
}
|
|
46
|
+
/** Kernel start time distinguishes a reused PID from the captured process.
|
|
47
|
+
* Missing/unsupported observations remain uncertain; presence is advisory. */
|
|
48
|
+
export declare function observedProcessStart(pid: number, timeout: number): Promise<number | null>;
|
|
46
49
|
/** Missing work context is advisory; actual presence, branch and path risks still require admission. */
|
|
47
50
|
export declare function hasWorkspaceCollisionRisk(snapshot: WorkspaceCollisionSnapshot): boolean;
|
|
48
51
|
/** Read-only: never call the legacy registry's pruning/reaping readers. */
|
|
@@ -126,7 +126,7 @@ async function readBounded(path) {
|
|
|
126
126
|
}
|
|
127
127
|
/** Kernel start time distinguishes a reused PID from the captured process.
|
|
128
128
|
* Missing/unsupported observations remain uncertain; presence is advisory. */
|
|
129
|
-
async function observedProcessStart(pid, timeout) {
|
|
129
|
+
export async function observedProcessStart(pid, timeout) {
|
|
130
130
|
try {
|
|
131
131
|
const result = await execFileAsync('ps', ['-p', String(pid), '-o', 'lstart='], {
|
|
132
132
|
timeout, maxBuffer: 1024, env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' },
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { type NativeWorkspaceState } from './desktop/daily/native_records.js';
|
|
1
2
|
import type { MuxSessionState, RustCommand, RustEvent } from './ui/ratatui/protocol.js';
|
|
2
3
|
/** Same versioned artifact as ztc-core; separate from chat session cleanup. */
|
|
3
4
|
export declare class WorkspaceLayoutStore {
|
|
4
5
|
readonly directory: string;
|
|
5
6
|
constructor(directory?: string);
|
|
6
7
|
private path;
|
|
7
|
-
save(name: string, state:
|
|
8
|
-
load(name: string):
|
|
8
|
+
save(name: string, state: NativeWorkspaceState): void;
|
|
9
|
+
load(name: string): NativeWorkspaceState;
|
|
9
10
|
list(): string[];
|
|
10
11
|
delete(name: string): void;
|
|
11
12
|
private syncDirectory;
|
package/dist/workspace_layout.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nativeWorkspaceState, parseNativeRecords } from './desktop/daily/native_records.js';
|
|
1
2
|
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
3
|
import { homedir } from 'node:os';
|
|
3
4
|
import { join } from 'node:path';
|
|
@@ -18,7 +19,9 @@ export class WorkspaceLayoutStore {
|
|
|
18
19
|
save(name, state) {
|
|
19
20
|
const destination = this.path(name);
|
|
20
21
|
validateWorkspaceState(state);
|
|
21
|
-
const
|
|
22
|
+
const clean = nativeWorkspaceState(state);
|
|
23
|
+
const { native_tools, ...renderer } = clean;
|
|
24
|
+
const bytes = JSON.stringify({ schema_version: 1, name, state: renderer, ...(native_tools ? { native_tools } : {}) });
|
|
22
25
|
if (Buffer.byteLength(bytes) > MAX_BYTES)
|
|
23
26
|
throw new Error('Workspace layout exceeds 8 MiB');
|
|
24
27
|
mkdirSync(this.directory, { recursive: true });
|
|
@@ -58,7 +61,10 @@ export class WorkspaceLayoutStore {
|
|
|
58
61
|
if (envelope.name !== name)
|
|
59
62
|
throw new Error('Workspace layout name does not match its saved identity');
|
|
60
63
|
validateWorkspaceState(envelope.state);
|
|
61
|
-
|
|
64
|
+
const state = envelope.state;
|
|
65
|
+
if (envelope.native_tools !== undefined)
|
|
66
|
+
state.native_tools = parseNativeRecords(envelope.native_tools, new Set(state.panes.map(pane => pane.id)));
|
|
67
|
+
return nativeWorkspaceState(state);
|
|
62
68
|
}
|
|
63
69
|
list() {
|
|
64
70
|
if (!existsSync(this.directory))
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DailyDesktopSnapshot } from './desktop/daily/desktop_wiring.js';
|
|
1
2
|
import type { AskUserQuestion } from './agent/tools/ask_user.js';
|
|
2
3
|
import type { PaneRunStatus } from './panes/types.js';
|
|
3
4
|
import { type UsageView } from './usage_projection.js';
|
|
@@ -27,6 +28,7 @@ export interface WorkspaceRuntimePane {
|
|
|
27
28
|
} | null;
|
|
28
29
|
blockers: string[];
|
|
29
30
|
usage: UsageView;
|
|
31
|
+
session_id: string | null;
|
|
30
32
|
usage_session_id: string | null;
|
|
31
33
|
}
|
|
32
34
|
/** A projection of the canonical pane registry and live request admission, never transcript inference. */
|
|
@@ -37,8 +39,12 @@ export interface WorkspaceRuntimeSnapshot {
|
|
|
37
39
|
panes: WorkspaceRuntimePane[];
|
|
38
40
|
decisions: WorkspaceDecision[];
|
|
39
41
|
omitted_panes: number;
|
|
42
|
+
status_pane?: DailyDesktopSnapshot['status_pane'];
|
|
43
|
+
children?: DailyDesktopSnapshot['children'];
|
|
44
|
+
routerAuth?: DailyDesktopSnapshot['routerAuth'];
|
|
45
|
+
routerFunding?: DailyDesktopSnapshot['routerFunding'];
|
|
40
46
|
}
|
|
41
47
|
export declare function parseWorkspaceTodos(value: unknown): WorkspaceTodo[] | undefined;
|
|
42
48
|
/** Refuse partial wizards: missing/oversized labels must never change the answer identity. */
|
|
43
49
|
export declare function parseWorkspaceQuestions(data: Record<string, unknown>): AskUserQuestion[] | null;
|
|
44
|
-
export declare function buildWorkspaceRuntimeSnapshot(ownerId: string, entries: ReadonlyArray<readonly [number, MirrorPaneRecord]>, requests: readonly MirrorEvent[], now?: Date): WorkspaceRuntimeSnapshot;
|
|
50
|
+
export declare function buildWorkspaceRuntimeSnapshot(ownerId: string, entries: ReadonlyArray<readonly [number, MirrorPaneRecord]>, requests: readonly MirrorEvent[], now?: Date, daily?: DailyDesktopSnapshot): WorkspaceRuntimeSnapshot;
|
|
@@ -48,7 +48,7 @@ export function parseWorkspaceQuestions(data) {
|
|
|
48
48
|
}
|
|
49
49
|
return questions;
|
|
50
50
|
}
|
|
51
|
-
export function buildWorkspaceRuntimeSnapshot(ownerId, entries, requests, now = new Date()) {
|
|
51
|
+
export function buildWorkspaceRuntimeSnapshot(ownerId, entries, requests, now = new Date(), daily) {
|
|
52
52
|
const decisions = requests.map(event => {
|
|
53
53
|
const paneId = event.data.pane_id;
|
|
54
54
|
const pane = entries.find(([id]) => id === paneId)?.[1];
|
|
@@ -75,8 +75,8 @@ export function buildWorkspaceRuntimeSnapshot(ownerId, entries, requests, now =
|
|
|
75
75
|
status: pane.status ?? 'unknown', is_alive: pane.isAlive ?? null,
|
|
76
76
|
task: (todos?.find(todo => todo.status === 'in_progress')?.content ?? currentGoal?.objective)?.slice(0, 4096) ?? null,
|
|
77
77
|
progress: todos?.length ? { completed: todos.filter(todo => todo.status === 'completed').length, total: todos.length } : null,
|
|
78
|
-
blockers, usage: projectUsage(pane.usage?.receipts ?? [], 'Pane'), usage_session_id: pane.usageSessionId ?? null };
|
|
78
|
+
blockers, session_id: pane.sessionId ?? null, usage: projectUsage(pane.usage?.receipts ?? [], 'Pane'), usage_session_id: pane.usageSessionId ?? null };
|
|
79
79
|
});
|
|
80
80
|
return { schema_version: 1, owner_id: ownerId, observed_at: now.toISOString(), panes, decisions,
|
|
81
|
-
omitted_panes: Math.max(0, entries.length - panes.length) };
|
|
81
|
+
omitted_panes: Math.max(0, entries.length - panes.length), ...(daily ?? {}) };
|
|
82
82
|
}
|
|
@@ -457,11 +457,42 @@ function generateTestCode(entryPoint, moduleName, className, configNamesUsed, as
|
|
|
457
457
|
else {
|
|
458
458
|
lines.push(` instance = ${className}()`);
|
|
459
459
|
}
|
|
460
|
-
//
|
|
460
|
+
// Preserve nested suites. Lines inside multiline strings are data, so adding
|
|
461
|
+
// indentation there would change the asserted value rather than the suite.
|
|
462
|
+
let quote = '';
|
|
463
|
+
let triple = false;
|
|
461
464
|
for (const line of assertionCode.split('\n')) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
+
lines.push(quote ? line : ` ${line}`);
|
|
466
|
+
let escaped = false;
|
|
467
|
+
for (let index = 0; index < line.length; index++) {
|
|
468
|
+
const character = line[index];
|
|
469
|
+
if (escaped) {
|
|
470
|
+
escaped = false;
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (quote) {
|
|
474
|
+
if (character === '\\') {
|
|
475
|
+
escaped = true;
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
if (triple && line.slice(index, index + 3) === quote.repeat(3)) {
|
|
479
|
+
quote = '';
|
|
480
|
+
triple = false;
|
|
481
|
+
index += 2;
|
|
482
|
+
}
|
|
483
|
+
else if (!triple && character === quote)
|
|
484
|
+
quote = '';
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
if (character === '#')
|
|
488
|
+
break;
|
|
489
|
+
if (character === '"' || character === "'") {
|
|
490
|
+
quote = character;
|
|
491
|
+
triple = line.slice(index, index + 3) === character.repeat(3);
|
|
492
|
+
if (triple)
|
|
493
|
+
index += 2;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
465
496
|
}
|
|
466
497
|
}
|
|
467
498
|
lines.push(' return True');
|
|
@@ -228,8 +228,63 @@ export function checkReferenceWarnings(includes, references) {
|
|
|
228
228
|
// ---------------------------------------------------------------------------
|
|
229
229
|
// Python syntax validation (lightweight, no Python runtime needed)
|
|
230
230
|
// ---------------------------------------------------------------------------
|
|
231
|
+
function hasUnsupportedMultilineFString(code) {
|
|
232
|
+
let quote = '';
|
|
233
|
+
let triple = false;
|
|
234
|
+
let formatted = false;
|
|
235
|
+
let escaped = false;
|
|
236
|
+
let comment = false;
|
|
237
|
+
for (let index = 0; index < code.length; index++) {
|
|
238
|
+
const character = code[index];
|
|
239
|
+
if (comment) {
|
|
240
|
+
if (character === '\n')
|
|
241
|
+
comment = false;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (escaped) {
|
|
245
|
+
escaped = false;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (quote) {
|
|
249
|
+
if (formatted && character === '\n')
|
|
250
|
+
return true;
|
|
251
|
+
if (character === '\\') {
|
|
252
|
+
escaped = true;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (triple && code.slice(index, index + 3) === quote.repeat(3)) {
|
|
256
|
+
quote = '';
|
|
257
|
+
triple = false;
|
|
258
|
+
index += 2;
|
|
259
|
+
}
|
|
260
|
+
else if (!triple && character === quote) {
|
|
261
|
+
if (formatted && code.slice(index, index + 3) === quote.repeat(3))
|
|
262
|
+
return true;
|
|
263
|
+
quote = '';
|
|
264
|
+
formatted = false;
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (character === '#') {
|
|
269
|
+
comment = true;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (character === '"' || character === "'") {
|
|
273
|
+
triple = code.slice(index, index + 3) === character.repeat(3);
|
|
274
|
+
formatted = /(?:^|[^\w])(?:f|fr|rf)$/i.test(code.slice(Math.max(0, index - 3), index));
|
|
275
|
+
if (triple && formatted)
|
|
276
|
+
return true;
|
|
277
|
+
quote = character;
|
|
278
|
+
if (triple)
|
|
279
|
+
index += 2;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
231
284
|
export function validatePythonSyntax(code) {
|
|
232
285
|
const errors = [];
|
|
286
|
+
if (hasUnsupportedMultilineFString(code))
|
|
287
|
+
return ['Multiline f-strings cannot be embedded safely; use ordinary strings or separate expressions.'];
|
|
233
288
|
const stack = [];
|
|
234
289
|
const openers = { '(': ')', '[': ']', '{': '}' };
|
|
235
290
|
const closers = { ')': '(', ']': '[', '}': '{' };
|