@visual-z/xeno 0.8.4 → 0.9.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/CHANGELOG.md +19 -0
- package/README.md +31 -746
- package/bin/xeno.exe +26 -0
- package/install.cjs +88 -0
- package/package.json +18 -48
- package/docs/app-server.md +0 -115
- package/docs/foundations.md +0 -88
- package/docs/install.md +0 -244
- package/docs/providers.md +0 -172
- package/docs/research/foundation-clients-2026-10-09.md +0 -27
- package/docs/research/foundation-editing-2026-10-09.md +0 -56
- package/docs/research/foundation-network-2026-10-09.md +0 -37
- package/docs/research/foundation-workflow-2026-10-09.md +0 -37
- package/src/apps/acp-server.ts +0 -41
- package/src/apps/agent-profiles.ts +0 -19
- package/src/apps/app-server.ts +0 -30
- package/src/apps/approve.ts +0 -49
- package/src/apps/cli.ts +0 -99
- package/src/apps/commands.ts +0 -319
- package/src/apps/completions.ts +0 -87
- package/src/apps/control-transport.ts +0 -90
- package/src/apps/export-cli.ts +0 -24
- package/src/apps/goal-flow.ts +0 -70
- package/src/apps/image-draft.ts +0 -46
- package/src/apps/input.ts +0 -312
- package/src/apps/model-catalog.ts +0 -69
- package/src/apps/preferences.ts +0 -20
- package/src/apps/project-trust.ts +0 -9
- package/src/apps/provider-connect.ts +0 -346
- package/src/apps/question-ui.ts +0 -27
- package/src/apps/render.ts +0 -181
- package/src/apps/resources.ts +0 -66
- package/src/apps/review.ts +0 -109
- package/src/apps/session-hub.ts +0 -96
- package/src/apps/session-lifecycle.ts +0 -64
- package/src/apps/shell.ts +0 -2071
- package/src/apps/startup-input.ts +0 -135
- package/src/apps/startup.ts +0 -1677
- package/src/apps/ui/app.ts +0 -1818
- package/src/apps/ui/control-model.ts +0 -43
- package/src/apps/ui/extension-host.ts +0 -194
- package/src/apps/ui/image-cache.ts +0 -121
- package/src/apps/ui/palette.ts +0 -88
- package/src/apps/ui/project.ts +0 -127
- package/src/apps/ui/standalone.ts +0 -148
- package/src/apps/ui/status-model.ts +0 -68
- package/src/apps/ui/surface.ts +0 -91
- package/src/apps/ui/theme.ts +0 -86
- package/src/apps/update-check.ts +0 -112
- package/src/apps/workflow.ts +0 -58
- package/src/core/acceptance.ts +0 -139
- package/src/core/action-defaults.ts +0 -58
- package/src/core/activity-status.ts +0 -52
- package/src/core/agent-profile.ts +0 -130
- package/src/core/attachment-input.ts +0 -17
- package/src/core/blind-checks.ts +0 -72
- package/src/core/boundary.ts +0 -174
- package/src/core/branch-receipt.ts +0 -26
- package/src/core/catalog-merge.ts +0 -19
- package/src/core/checkpoints.ts +0 -85
- package/src/core/churn.ts +0 -61
- package/src/core/command-artifacts.ts +0 -94
- package/src/core/command-contract.ts +0 -151
- package/src/core/completion-action.ts +0 -20
- package/src/core/completion-review.ts +0 -98
- package/src/core/context-detail.ts +0 -37
- package/src/core/context-policy.ts +0 -133
- package/src/core/context-window.ts +0 -54
- package/src/core/continuation.ts +0 -130
- package/src/core/control-protocol.ts +0 -69
- package/src/core/control-view.ts +0 -39
- package/src/core/cycle.ts +0 -17
- package/src/core/data-query.ts +0 -201
- package/src/core/deadline.ts +0 -40
- package/src/core/derive.ts +0 -516
- package/src/core/draft-images.ts +0 -56
- package/src/core/edit-plan.ts +0 -200
- package/src/core/environment.ts +0 -181
- package/src/core/event-validation.ts +0 -220
- package/src/core/events.ts +0 -670
- package/src/core/evidence-ladder.ts +0 -62
- package/src/core/evidence-links.ts +0 -68
- package/src/core/evidence.ts +0 -240
- package/src/core/execution.ts +0 -18
- package/src/core/exhaustive.ts +0 -18
- package/src/core/export.ts +0 -179
- package/src/core/extension-flags.ts +0 -14
- package/src/core/external-effects.ts +0 -488
- package/src/core/failure-recovery.ts +0 -173
- package/src/core/file-precondition.ts +0 -78
- package/src/core/file-references.ts +0 -35
- package/src/core/frontmatter.ts +0 -213
- package/src/core/git-status.ts +0 -29
- package/src/core/goal-view.ts +0 -64
- package/src/core/goal.ts +0 -200
- package/src/core/handoff.ts +0 -479
- package/src/core/history-query.ts +0 -139
- package/src/core/history.ts +0 -237
- package/src/core/image-limits.ts +0 -72
- package/src/core/images.ts +0 -46
- package/src/core/integration-health.ts +0 -34
- package/src/core/json-event.ts +0 -131
- package/src/core/json-pointer.ts +0 -46
- package/src/core/keymap.ts +0 -153
- package/src/core/lsp-framing.ts +0 -34
- package/src/core/mcp-config.ts +0 -68
- package/src/core/model-picker.ts +0 -64
- package/src/core/model-preferences.ts +0 -28
- package/src/core/model-replay.ts +0 -22
- package/src/core/model-scope.ts +0 -53
- package/src/core/note-guidance.ts +0 -34
- package/src/core/oauth-fields.ts +0 -44
- package/src/core/observation-view.ts +0 -152
- package/src/core/outcome.ts +0 -44
- package/src/core/overflow.ts +0 -59
- package/src/core/packages.ts +0 -47
- package/src/core/patch.ts +0 -130
- package/src/core/path-suggestions.ts +0 -59
- package/src/core/permissions.ts +0 -410
- package/src/core/process-receipt.ts +0 -105
- package/src/core/process-state.ts +0 -37
- package/src/core/program-status.ts +0 -40
- package/src/core/progress.ts +0 -150
- package/src/core/project.ts +0 -431
- package/src/core/prompt-policy.ts +0 -46
- package/src/core/prompts.ts +0 -111
- package/src/core/question.ts +0 -94
- package/src/core/queue.ts +0 -78
- package/src/core/read-bounds.ts +0 -24
- package/src/core/read-observation.ts +0 -106
- package/src/core/recovery-sources.ts +0 -74
- package/src/core/regex-dialect.ts +0 -25
- package/src/core/request-budget.ts +0 -23
- package/src/core/request-progress.ts +0 -87
- package/src/core/request-state.ts +0 -273
- package/src/core/resource-selection.ts +0 -36
- package/src/core/response-recovery.ts +0 -59
- package/src/core/resume.ts +0 -59
- package/src/core/review.ts +0 -68
- package/src/core/ripgrep-release.ts +0 -64
- package/src/core/runtime-target.ts +0 -94
- package/src/core/scheduling.ts +0 -8
- package/src/core/search-observation.ts +0 -97
- package/src/core/secrets.ts +0 -188
- package/src/core/session-archive.ts +0 -4
- package/src/core/session-browser.ts +0 -82
- package/src/core/session-entry.ts +0 -61
- package/src/core/session-exit.ts +0 -42
- package/src/core/session-format.ts +0 -169
- package/src/core/session-position.ts +0 -26
- package/src/core/session-tree.ts +0 -147
- package/src/core/settings.ts +0 -192
- package/src/core/skills.ts +0 -165
- package/src/core/sql-query.ts +0 -211
- package/src/core/stall.ts +0 -128
- package/src/core/stop-report.ts +0 -68
- package/src/core/text-normalize.ts +0 -81
- package/src/core/theme.ts +0 -166
- package/src/core/thinking.ts +0 -26
- package/src/core/tokens.ts +0 -151
- package/src/core/tool-contract.ts +0 -153
- package/src/core/tool-discovery.ts +0 -87
- package/src/core/tool-failure.ts +0 -81
- package/src/core/tool-input.ts +0 -44
- package/src/core/transcript.ts +0 -108
- package/src/core/tui-mode.ts +0 -29
- package/src/core/update-check.ts +0 -157
- package/src/core/version.ts +0 -55
- package/src/core/web-content.ts +0 -80
- package/src/core/work-state.ts +0 -154
- package/src/core/workflow-mode.ts +0 -34
- package/src/core/working-set.ts +0 -119
- package/src/core/yaml.ts +0 -282
- package/src/runtime/acp-agent.ts +0 -289
- package/src/runtime/agent-profiles.ts +0 -21
- package/src/runtime/auth.ts +0 -367
- package/src/runtime/blind-check.ts +0 -36
- package/src/runtime/branch-jobs.ts +0 -36
- package/src/runtime/catalog.ts +0 -285
- package/src/runtime/clipboard.ts +0 -125
- package/src/runtime/command-artifacts.ts +0 -64
- package/src/runtime/connection-reuse.ts +0 -40
- package/src/runtime/control-client.ts +0 -149
- package/src/runtime/control-connection.ts +0 -139
- package/src/runtime/counter-check.ts +0 -74
- package/src/runtime/environment-tools.ts +0 -60
- package/src/runtime/evidence-notes.ts +0 -35
- package/src/runtime/exec-sessions.ts +0 -456
- package/src/runtime/execution-control.ts +0 -40
- package/src/runtime/extension-loader.ts +0 -37
- package/src/runtime/extension-ui.ts +0 -47
- package/src/runtime/extensions.ts +0 -370
- package/src/runtime/formatter-tool.ts +0 -38
- package/src/runtime/formatter.ts +0 -50
- package/src/runtime/foundation.ts +0 -116
- package/src/runtime/history-cache.ts +0 -57
- package/src/runtime/history-tools.ts +0 -168
- package/src/runtime/images.ts +0 -80
- package/src/runtime/integrations.ts +0 -216
- package/src/runtime/loop.ts +0 -3108
- package/src/runtime/lsp-client.ts +0 -201
- package/src/runtime/mcp-client.ts +0 -264
- package/src/runtime/mcp-oauth.ts +0 -168
- package/src/runtime/mcp-schema.ts +0 -51
- package/src/runtime/model-config.ts +0 -232
- package/src/runtime/model-data.LICENSE +0 -27
- package/src/runtime/model-data.ts +0 -21
- package/src/runtime/model-discovery.ts +0 -208
- package/src/runtime/model-replay.ts +0 -10
- package/src/runtime/model-scope.ts +0 -20
- package/src/runtime/model-sources.ts +0 -151
- package/src/runtime/model.ts +0 -686
- package/src/runtime/models-fetch.ts +0 -57
- package/src/runtime/oauth-device.ts +0 -86
- package/src/runtime/oauth.ts +0 -853
- package/src/runtime/open-image.ts +0 -42
- package/src/runtime/openai-responses.ts +0 -304
- package/src/runtime/openai.ts +0 -697
- package/src/runtime/output-schema.ts +0 -26
- package/src/runtime/package-manager.ts +0 -125
- package/src/runtime/patch-tool.ts +0 -38
- package/src/runtime/permission-resources.ts +0 -18
- package/src/runtime/pi-provider.ts +0 -423
- package/src/runtime/program-status.ts +0 -38
- package/src/runtime/progress.ts +0 -26
- package/src/runtime/provider-access.ts +0 -21
- package/src/runtime/provider-connect.ts +0 -109
- package/src/runtime/provider-presets.ts +0 -98
- package/src/runtime/provider-protocols.ts +0 -29
- package/src/runtime/provider-request.ts +0 -87
- package/src/runtime/provider-tool-policy.ts +0 -33
- package/src/runtime/provider.ts +0 -580
- package/src/runtime/question-tool.ts +0 -62
- package/src/runtime/retry.ts +0 -447
- package/src/runtime/review-tool.ts +0 -48
- package/src/runtime/rich-text.ts +0 -36
- package/src/runtime/runtime-target.ts +0 -149
- package/src/runtime/secrets.ts +0 -79
- package/src/runtime/self-update.ts +0 -74
- package/src/runtime/session-control.ts +0 -265
- package/src/runtime/session-hub.ts +0 -85
- package/src/runtime/stream-idle.ts +0 -80
- package/src/runtime/tool-broker.ts +0 -137
- package/src/runtime/tool-discovery.ts +0 -58
- package/src/runtime/tool-queue.ts +0 -77
- package/src/runtime/tools.ts +0 -1820
- package/src/runtime/turn-effects.ts +0 -31
- package/src/runtime/update-check.ts +0 -48
- package/src/runtime/usage.ts +0 -253
- package/src/runtime/version.ts +0 -12
- package/src/runtime/web-http.ts +0 -56
- package/src/runtime/web-tools.ts +0 -88
- package/src/runtime/working-notes.ts +0 -60
- package/src/runtime/workspace-lifecycle.ts +0 -141
- package/src/store/acceptance.ts +0 -15
- package/src/store/agent-profile-files.ts +0 -13
- package/src/store/atomic.ts +0 -31
- package/src/store/auth-store.ts +0 -50
- package/src/store/blind-checks.ts +0 -32
- package/src/store/blobs.ts +0 -143
- package/src/store/checkpoint-history.ts +0 -32
- package/src/store/command-artifacts.ts +0 -96
- package/src/store/command.ts +0 -111
- package/src/store/config.ts +0 -69
- package/src/store/context-files.ts +0 -436
- package/src/store/file-checkpoints.ts +0 -108
- package/src/store/file-index.ts +0 -174
- package/src/store/foundation-config.ts +0 -24
- package/src/store/git-checkpoints.ts +0 -67
- package/src/store/git-status.ts +0 -15
- package/src/store/history-search.ts +0 -19
- package/src/store/log.ts +0 -725
- package/src/store/lsp-document.ts +0 -30
- package/src/store/mcp-credentials.ts +0 -85
- package/src/store/models.ts +0 -60
- package/src/store/observations.ts +0 -224
- package/src/store/packages.ts +0 -98
- package/src/store/patch.ts +0 -92
- package/src/store/permission-paths.ts +0 -34
- package/src/store/process-receipts.ts +0 -34
- package/src/store/query-source.ts +0 -49
- package/src/store/recovery.ts +0 -44
- package/src/store/replay.ts +0 -76
- package/src/store/resource-index.ts +0 -170
- package/src/store/resources.ts +0 -285
- package/src/store/restore.ts +0 -110
- package/src/store/review.ts +0 -109
- package/src/store/runtime-target.ts +0 -64
- package/src/store/search.ts +0 -728
- package/src/store/secrets.ts +0 -44
- package/src/store/serial.ts +0 -13
- package/src/store/session-archive.ts +0 -165
- package/src/store/session-browser.ts +0 -68
- package/src/store/session-position.ts +0 -27
- package/src/store/sessions.ts +0 -525
- package/src/store/source-cancellation.ts +0 -6
- package/src/store/tool-binaries.ts +0 -90
- package/src/store/trust.ts +0 -82
- package/src/store/update-cache.ts +0 -36
- package/src/store/user-settings.ts +0 -30
- package/src/store/workspace-clone.ts +0 -42
- package/src/store/workspace-observation.ts +0 -113
- package/src/store/workspace.ts +0 -115
- package/src/store/worktree.ts +0 -278
- package/src/tui/ansi-spans.ts +0 -126
- package/src/tui/diff.ts +0 -160
- package/src/tui/exhaustive.ts +0 -14
- package/src/tui/fuzzy.ts +0 -75
- package/src/tui/style.ts +0 -208
- package/src/tui/ui/atomic-draft.ts +0 -121
- package/src/tui/ui/branch-panel.ts +0 -47
- package/src/tui/ui/canvas.ts +0 -96
- package/src/tui/ui/colors.ts +0 -70
- package/src/tui/ui/composer.ts +0 -199
- package/src/tui/ui/control-panel.ts +0 -25
- package/src/tui/ui/control-sidebar.ts +0 -49
- package/src/tui/ui/dialog.ts +0 -398
- package/src/tui/ui/draft.ts +0 -23
- package/src/tui/ui/duration.ts +0 -16
- package/src/tui/ui/edge.ts +0 -186
- package/src/tui/ui/image-size.ts +0 -44
- package/src/tui/ui/ink.ts +0 -210
- package/src/tui/ui/items.ts +0 -42
- package/src/tui/ui/keys.ts +0 -40
- package/src/tui/ui/layout.ts +0 -74
- package/src/tui/ui/list-model.ts +0 -86
- package/src/tui/ui/list-view.ts +0 -172
- package/src/tui/ui/mascot.ts +0 -67
- package/src/tui/ui/messages.ts +0 -518
- package/src/tui/ui/motion.ts +0 -28
- package/src/tui/ui/paths.ts +0 -10
- package/src/tui/ui/pictures.ts +0 -108
- package/src/tui/ui/prompt-history.ts +0 -60
- package/src/tui/ui/screen.ts +0 -579
- package/src/tui/ui/status.ts +0 -403
- package/src/tui/ui/styled.ts +0 -85
- package/src/tui/ui/tool-card.ts +0 -150
- package/src/tui/width.ts +0 -567
- package/src/vendor/pi-rich/LICENSE.upstream +0 -21
- package/src/vendor/pi-rich/UPSTREAM.json +0 -17
- package/src/vendor/pi-rich/clipboard-command.ts +0 -44
- package/src/vendor/pi-rich/exif-orientation.ts +0 -182
- package/src/vendor/pi-rich/html.ts +0 -51
- package/src/vendor/pi-rich/image-convert.ts +0 -49
- package/src/vendor/pi-rich/image-resize-core.ts +0 -164
- package/src/vendor/pi-rich/image-resize-worker.ts +0 -42
- package/src/vendor/pi-rich/image-resize.ts +0 -123
- package/src/vendor/pi-rich/mime.ts +0 -116
- package/src/vendor/pi-rich/photon.ts +0 -139
- package/src/vendor/pi-rich/syntax-highlight.ts +0 -214
package/src/core/derive.ts
DELETED
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* deriveHandoff: segment events + previous handoff -> next handoff.
|
|
3
|
-
*
|
|
4
|
-
* Pure and total. No I/O, no clock, no randomness, no model call. Same inputs
|
|
5
|
-
* always produce the same object, which is what makes the handoff diffable,
|
|
6
|
-
* unit-testable and cheap enough that segments can be short (decisions D1, D2).
|
|
7
|
-
*
|
|
8
|
-
* Evidence freshness rule: a completion claim must cite an event from the SAME
|
|
9
|
-
* segment. A gate that passed three segments ago is not proof about code that has
|
|
10
|
-
* changed since -- that is the stale-evidence problem, so the citation fails.
|
|
11
|
-
* Verification status, by contrast, carries forward as last-known with its
|
|
12
|
-
* original timestamp, which is honest about what it is.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import type {
|
|
16
|
-
LogEvent, LineRange, NodeRef, EventId, CarryableEvent,
|
|
17
|
-
} from "./events.ts";
|
|
18
|
-
import { CARRYABLE_EVENTS } from "./events.ts";
|
|
19
|
-
import { deriveWorkItems } from "./work-state.ts";
|
|
20
|
-
import { deriveAcceptance } from "./acceptance.ts";
|
|
21
|
-
import { deriveLoadedSkills } from "./skills.ts";
|
|
22
|
-
import { deriveProcesses } from "./process-state.ts";
|
|
23
|
-
import { deriveEvidenceLinks } from "./evidence-links.ts";
|
|
24
|
-
import { deriveProgress } from "./progress.ts";
|
|
25
|
-
import { isCommandResult, resolveEvidence, evidenceStale, eligibleProgressChecks } from "./evidence.ts";
|
|
26
|
-
import type { BranchRecord } from "./handoff.ts";
|
|
27
|
-
import {
|
|
28
|
-
HANDOFF_VERSION,
|
|
29
|
-
type Handoff, type CompletedItem, type UnverifiedClaim, type InFlightItem,
|
|
30
|
-
type BlockedItem, type DecisionItem, type PitfallItem, type FileAnchor,
|
|
31
|
-
type VerificationItem, type UserTurnRecord,
|
|
32
|
-
} from "./handoff.ts";
|
|
33
|
-
|
|
34
|
-
export interface DeriveConfig {
|
|
35
|
-
/** Where the agent can grep for anything a cap dropped. */
|
|
36
|
-
manifestPath: string;
|
|
37
|
-
maxUserTurns: number;
|
|
38
|
-
maxUserTurnBytes: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Marks the open questions this module generates from branch state, so they
|
|
43
|
-
* can be rebuilt each derivation instead of accumulating.
|
|
44
|
-
*/
|
|
45
|
-
const UNRESOLVED_BRANCH_PREFIX = "branch ";
|
|
46
|
-
|
|
47
|
-
export const DEFAULT_DERIVE_CONFIG: DeriveConfig = {
|
|
48
|
-
manifestPath: "log/manifest.json",
|
|
49
|
-
maxUserTurns: 200,
|
|
50
|
-
maxUserTurnBytes: 64_000,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export interface DeriveInput {
|
|
54
|
-
/** Previous segment's handoff, or null for segment 0. */
|
|
55
|
-
prev: Handoff | null;
|
|
56
|
-
/**
|
|
57
|
-
* Length of the path from the root to this node, inclusive.
|
|
58
|
-
*
|
|
59
|
-
* Supplied by the caller rather than derived from a node number, because
|
|
60
|
-
* allocation order is not an ordering over the tree: a node forked from an
|
|
61
|
-
* earlier one has a short path and a high number. deriveHandoff is pure and
|
|
62
|
-
* cannot read the log to count it, but readAncestry already returns
|
|
63
|
-
* `visited`, so the caller has the length in hand.
|
|
64
|
-
*/
|
|
65
|
-
depth: number;
|
|
66
|
-
events: readonly LogEvent[];
|
|
67
|
-
/** Ref to the segment being closed, recorded as the next segment's predecessor. */
|
|
68
|
-
self: NodeRef;
|
|
69
|
-
config?: Partial<DeriveConfig>;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// --- helpers ---------------------------------------------------------------
|
|
73
|
-
|
|
74
|
-
/** Coalesce overlapping or adjacent ranges into a minimal sorted set. */
|
|
75
|
-
export function mergeRanges(ranges: readonly LineRange[]): LineRange[] {
|
|
76
|
-
if (ranges.length === 0) return [];
|
|
77
|
-
const sorted = [...ranges].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
78
|
-
const out: LineRange[] = [[sorted[0]![0], sorted[0]![1]]];
|
|
79
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
80
|
-
const cur = sorted[i]!;
|
|
81
|
-
const last = out[out.length - 1]!;
|
|
82
|
-
if (cur[0] <= last[1] + 1) {
|
|
83
|
-
out[out.length - 1] = [last[0], Math.max(last[1], cur[1])];
|
|
84
|
-
} else {
|
|
85
|
-
out.push([cur[0], cur[1]]);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return out;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** First occurrence wins, so accumulation across segments is order-stable. */
|
|
92
|
-
function dedupe<T>(items: readonly T[], key: (t: T) => string): T[] {
|
|
93
|
-
const seen = new Set<string>();
|
|
94
|
-
const out: T[] = [];
|
|
95
|
-
for (const it of items) {
|
|
96
|
-
const k = key(it);
|
|
97
|
-
if (!seen.has(k)) {
|
|
98
|
-
seen.add(k);
|
|
99
|
-
out.push(it);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return out;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// --- main ------------------------------------------------------------------
|
|
106
|
-
|
|
107
|
-
export function deriveHandoff(input: DeriveInput): Handoff {
|
|
108
|
-
const cfg = { ...DEFAULT_DERIVE_CONFIG, ...input.config };
|
|
109
|
-
const { prev, depth, events } = input;
|
|
110
|
-
|
|
111
|
-
// Command results in this segment, in log order. The evidence index and the
|
|
112
|
-
// verification table are both built from this and nothing else -- exit codes,
|
|
113
|
-
// never the model's account of them.
|
|
114
|
-
const commands = events.filter(isCommandResult);
|
|
115
|
-
|
|
116
|
-
// -- objective: verbatim, set once, never rewritten -----------------------
|
|
117
|
-
// Skip user events a later interrupt cancelled: an abandoned prompt is not
|
|
118
|
-
// what the next segment is doing. If every user event in the segment was
|
|
119
|
-
// abandoned, keep the last one so EMPTY_OBJECTIVE cannot fire -- the mark
|
|
120
|
-
// lives on user_turns, not by blanking the field.
|
|
121
|
-
const abandonedIds = new Set(
|
|
122
|
-
events.filter((e): e is Extract<LogEvent, { t: "interrupt" }> => e.t === "interrupt")
|
|
123
|
-
.map((e) => e.user_id),
|
|
124
|
-
);
|
|
125
|
-
const users = events.filter((e): e is Extract<LogEvent, { t: "user" }> => e.t === "user");
|
|
126
|
-
const liveUsers = users.filter((e) => !abandonedIds.has(e.id));
|
|
127
|
-
const firstUser = liveUsers[0] ?? users.at(-1);
|
|
128
|
-
const objective = prev?.objective ?? (firstUser !== undefined ? firstUser.text : "");
|
|
129
|
-
|
|
130
|
-
// -- user turns: all of them, verbatim, accumulated ----------------------
|
|
131
|
-
// Abandoned turns stay: deleting them would rewrite history. The interrupt
|
|
132
|
-
// is a later record, so the mark is derived here rather than written back
|
|
133
|
-
// onto the user event (D8).
|
|
134
|
-
const newTurns: UserTurnRecord[] = users.map((e) => ({
|
|
135
|
-
at: e.at,
|
|
136
|
-
text: e.text,
|
|
137
|
-
...(abandonedIds.has(e.id) ? { abandoned: true as const } : {}),
|
|
138
|
-
}));
|
|
139
|
-
const userTurns: UserTurnRecord[] = [...(prev?.user_turns ?? []), ...newTurns];
|
|
140
|
-
|
|
141
|
-
let dropped = prev?.user_turns_truncated?.dropped ?? 0;
|
|
142
|
-
// Drop oldest first: the very first turn survives in `objective` regardless.
|
|
143
|
-
while (
|
|
144
|
-
userTurns.length > cfg.maxUserTurns ||
|
|
145
|
-
(userTurns.length > 1 &&
|
|
146
|
-
userTurns.reduce((n, t) => n + t.text.length, 0) > cfg.maxUserTurnBytes)
|
|
147
|
-
) {
|
|
148
|
-
userTurns.shift();
|
|
149
|
-
dropped++;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// -- completion claims resolved against the log --------------------------
|
|
153
|
-
const newCompleted: CompletedItem[] = [];
|
|
154
|
-
const unverified: UnverifiedClaim[] = [];
|
|
155
|
-
|
|
156
|
-
for (let i = 0; i < events.length; i++) {
|
|
157
|
-
const e = events[i]!;
|
|
158
|
-
if (e.t !== "claim" || e.work_id !== undefined) continue;
|
|
159
|
-
// Resolve against the most recent match AT OR BEFORE the claim. A claim is a
|
|
160
|
-
// statement about evidence available when it was made, so a later run must not
|
|
161
|
-
// retroactively change it -- that non-locality would mean appending an event
|
|
162
|
-
// could silently rewrite an earlier conclusion. Whether the gate is red *now*
|
|
163
|
-
// is separate information, carried by `verification` and repeated inline as
|
|
164
|
-
// `evidence_superseded` below.
|
|
165
|
-
const resolved = resolveEvidence(events.slice(0, i), e.evidence);
|
|
166
|
-
if (resolved.ok) newCompleted.push({ what: e.what, evidence: resolved.evidence });
|
|
167
|
-
else unverified.push({ what: e.what, claimed: e.evidence, reason: resolved.reason,
|
|
168
|
-
...(resolved.exit !== undefined ? { exit: resolved.exit } : {}) });
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const workItems = deriveWorkItems(prev?.state.work_items ?? [], events);
|
|
172
|
-
const identifiedCompleted: CompletedItem[] = workItems.flatMap(item => item.status === "completed" && item.evidence
|
|
173
|
-
? [{ work_id: item.id, what: item.what, evidence: item.evidence }] : []);
|
|
174
|
-
const legacyCompleted = dedupe([...(prev?.state.completed ?? []).filter(item => item.work_id === undefined), ...newCompleted], c => c.what);
|
|
175
|
-
const completed = [...legacyCompleted, ...identifiedCompleted];
|
|
176
|
-
const completedSet = new Set(legacyCompleted.map(c => c.what));
|
|
177
|
-
|
|
178
|
-
// -- in flight: latest note per item wins --------------------------------
|
|
179
|
-
const inFlightMap = new Map<string, InFlightItem>();
|
|
180
|
-
for (const i of prev?.state.in_flight ?? []) if (i.work_id === undefined) inFlightMap.set(i.what, i);
|
|
181
|
-
for (const e of events) {
|
|
182
|
-
if (e.t === "next_action" && e.work_id === undefined) inFlightMap.set(e.what, { what: e.what, next_action: e.next_action });
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// -- blocked -------------------------------------------------------------
|
|
186
|
-
const blockedItems: BlockedItem[] = [
|
|
187
|
-
...(prev?.state.blocked ?? []).filter(item => item.work_id === undefined),
|
|
188
|
-
...events.filter((e): e is Extract<LogEvent, { t: "blocked" }> => e.t === "blocked" && e.work_id === undefined)
|
|
189
|
-
.map((e) => ({ what: e.what, reason: e.reason })),
|
|
190
|
-
];
|
|
191
|
-
const legacyBlocked = dedupe(blockedItems, b => b.what).filter(b => !completedSet.has(b.what));
|
|
192
|
-
const blocked = [...legacyBlocked, ...workItems.filter(item => item.status === "blocked")
|
|
193
|
-
.map(item => ({ work_id: item.id, what: item.what, reason: item.reason ?? "blocked" }))];
|
|
194
|
-
const blockedSet = new Set(legacyBlocked.map(b => b.what));
|
|
195
|
-
|
|
196
|
-
// Completed beats blocked beats in-flight, so an item never appears twice.
|
|
197
|
-
const inFlight = [...inFlightMap.values()].filter(
|
|
198
|
-
(i) => !completedSet.has(i.what) && !blockedSet.has(i.what),
|
|
199
|
-
).concat(workItems.filter(item => item.status === "active")
|
|
200
|
-
.map(item => ({ work_id: item.id, what: item.what, next_action: item.next_action ?? "" })));
|
|
201
|
-
|
|
202
|
-
// -- branches: what this node opened, and what became of it --------------
|
|
203
|
-
//
|
|
204
|
-
// Spawn creates the record; joined attaches the reference; adopt and
|
|
205
|
-
// discard resolve it. An unresolved branch stays visible rather than
|
|
206
|
-
// silently accumulating, which is the whole of D16.
|
|
207
|
-
const branchMap = new Map<number, BranchRecord>();
|
|
208
|
-
for (const b of prev?.branches ?? []) branchMap.set(b.node, b);
|
|
209
|
-
for (const e of events) {
|
|
210
|
-
if (e.t === "spawn") {
|
|
211
|
-
branchMap.set(e.branch.node, {
|
|
212
|
-
node: e.branch.node,
|
|
213
|
-
spawned_at: e.id,
|
|
214
|
-
purpose: e.purpose,
|
|
215
|
-
...(e.background ? { background: e.background } : {}),
|
|
216
|
-
resolution: null,
|
|
217
|
-
});
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (e.t !== "joined" && e.t !== "adopt" && e.t !== "discard") continue;
|
|
221
|
-
// A lifecycle event for a branch this node never spawned still records
|
|
222
|
-
// the branch: dropping it would hide a branch that exists.
|
|
223
|
-
const existing = branchMap.get(e.branch.node) ?? {
|
|
224
|
-
node: e.branch.node,
|
|
225
|
-
spawned_at: e.id,
|
|
226
|
-
purpose: "(spawn not recorded in this node)",
|
|
227
|
-
resolution: null,
|
|
228
|
-
};
|
|
229
|
-
if (e.t === "joined") {
|
|
230
|
-
branchMap.set(e.branch.node, {
|
|
231
|
-
...existing,
|
|
232
|
-
handoff_ref: e.handoff_ref,
|
|
233
|
-
summary: e.summary,
|
|
234
|
-
...(e.receipt_ref ? { receipt_ref: e.receipt_ref } : {}),
|
|
235
|
-
...(e.outcome ? { outcome: e.outcome } : {}),
|
|
236
|
-
});
|
|
237
|
-
} else {
|
|
238
|
-
branchMap.set(e.branch.node, {
|
|
239
|
-
...existing,
|
|
240
|
-
resolution: e.t === "adopt" ? "merged" : "discarded",
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const branches = [...branchMap.values()].sort((a, b) => a.node - b.node);
|
|
245
|
-
|
|
246
|
-
// -- decisions / pitfalls / questions ------------------------------------
|
|
247
|
-
const decisions = dedupe<DecisionItem>(
|
|
248
|
-
[
|
|
249
|
-
...(prev?.decisions ?? []),
|
|
250
|
-
...events.filter((e): e is Extract<LogEvent, { t: "decision" }> => e.t === "decision")
|
|
251
|
-
.map((e) => ({
|
|
252
|
-
chose: e.chose, because: e.because,
|
|
253
|
-
...(e.work_id ? { work_id: e.work_id, source: { node: input.self.node, event_id: e.id } } : {}),
|
|
254
|
-
...(e.rejected !== undefined ? { rejected: e.rejected } : {}),
|
|
255
|
-
})),
|
|
256
|
-
],
|
|
257
|
-
(d) => JSON.stringify([d.chose, d.because, ...(d.work_id ? [d.work_id] : [])]),
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
const pitfalls = dedupe<PitfallItem>(
|
|
261
|
-
[
|
|
262
|
-
...(prev?.pitfalls ?? []),
|
|
263
|
-
...events.filter((e): e is Extract<LogEvent, { t: "pitfall" }> => e.t === "pitfall")
|
|
264
|
-
.map((e) => ({ tried: e.tried, failed_because: e.failed_because,
|
|
265
|
-
...(e.work_id ? { work_id: e.work_id, source: { node: input.self.node, event_id: e.id } } : {}) })),
|
|
266
|
-
],
|
|
267
|
-
(p) => JSON.stringify([p.tried, p.failed_because, ...(p.work_id ? [p.work_id] : [])]),
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
const openQuestions = dedupe(
|
|
271
|
-
[
|
|
272
|
-
...(prev?.open_questions ?? []).filter((q) => !q.startsWith(UNRESOLVED_BRANCH_PREFIX)),
|
|
273
|
-
...events.filter((e): e is Extract<LogEvent, { t: "question" }> => e.t === "question")
|
|
274
|
-
.map((e) => e.text),
|
|
275
|
-
// Rebuilt from the current branch state each time rather than carried,
|
|
276
|
-
// so resolving a branch removes its question instead of leaving a stale
|
|
277
|
-
// one behind. The text names the node and the handoff so the next
|
|
278
|
-
// context can go read it rather than only learning that it exists.
|
|
279
|
-
...branches
|
|
280
|
-
.filter((b) => b.resolution === null)
|
|
281
|
-
.map((b) =>
|
|
282
|
-
`${UNRESOLVED_BRANCH_PREFIX}${b.node} (${b.purpose}) is unresolved` +
|
|
283
|
-
`${b.handoff_ref ? `; it joined with ${b.handoff_ref}` : "; it has not joined yet"}` +
|
|
284
|
-
` -- adopt it or discard it`,
|
|
285
|
-
),
|
|
286
|
-
],
|
|
287
|
-
(q) => q,
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
// -- file anchors: reference plus fingerprint, never content -------------
|
|
291
|
-
const anchors = new Map<string, {
|
|
292
|
-
path: string; sha256: string; ranges: LineRange[]; touched: Set<"read" | "edit">; stale?: true;
|
|
293
|
-
}>();
|
|
294
|
-
for (const a of prev?.file_anchors ?? []) {
|
|
295
|
-
anchors.set(a.path, {
|
|
296
|
-
path: a.path, sha256: a.sha256,
|
|
297
|
-
ranges: [...(a.read_ranges ?? [])], touched: new Set(a.touched),
|
|
298
|
-
...(a.stale ? { stale: true } : {}),
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
for (const e of events) {
|
|
302
|
-
if (e.t === "checkpoint" && e.phase === "applied") for (const [path, change] of Object.entries(e.changes)) {
|
|
303
|
-
const anchor = anchors.get(path);
|
|
304
|
-
if (anchor) {
|
|
305
|
-
if (change.after?.sha256 !== anchor.sha256) anchor.stale = true;
|
|
306
|
-
else delete anchor.stale;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
if (e.t === "workspace_observation" && e.changed || e.t === "checkpoint" && e.phase === "unavailable") {
|
|
310
|
-
for (const anchor of anchors.values()) anchor.stale = true;
|
|
311
|
-
}
|
|
312
|
-
if (e.t !== "tool_result" || !e.effect) continue;
|
|
313
|
-
const eff = e.effect;
|
|
314
|
-
if (eff.kind === "read") {
|
|
315
|
-
const cur = anchors.get(eff.path) ?? {
|
|
316
|
-
path: eff.path, sha256: eff.sha256, ranges: [], touched: new Set<"read" | "edit">(),
|
|
317
|
-
};
|
|
318
|
-
cur.sha256 = eff.sha256;
|
|
319
|
-
delete cur.stale;
|
|
320
|
-
cur.ranges.push(...(eff.ranges ?? []));
|
|
321
|
-
cur.touched.add("read");
|
|
322
|
-
anchors.set(eff.path, cur);
|
|
323
|
-
} else if (eff.kind === "edit") {
|
|
324
|
-
const cur = anchors.get(eff.path) ?? {
|
|
325
|
-
path: eff.path, sha256: eff.sha256_after, ranges: [], touched: new Set<"read" | "edit">(),
|
|
326
|
-
};
|
|
327
|
-
cur.sha256 = eff.sha256_after;
|
|
328
|
-
delete cur.stale;
|
|
329
|
-
cur.touched.add("edit");
|
|
330
|
-
anchors.set(eff.path, cur);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
const fileAnchors: FileAnchor[] = [...anchors.values()]
|
|
334
|
-
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))
|
|
335
|
-
.map((a) => {
|
|
336
|
-
const merged = mergeRanges(a.ranges);
|
|
337
|
-
return {
|
|
338
|
-
path: a.path, sha256: a.sha256,
|
|
339
|
-
...(a.stale ? { stale: true } : {}),
|
|
340
|
-
...(merged.length > 0 ? { read_ranges: merged } : {}),
|
|
341
|
-
touched: (["read", "edit"] as const).filter((k) => a.touched.has(k)),
|
|
342
|
-
};
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
// -- verification: last run per gate; unrun gates stay not_run -----------
|
|
346
|
-
const gateState = new Map<string, VerificationItem>();
|
|
347
|
-
for (const item of prev?.verification ?? []) gateState.set(item.gate, { ...item });
|
|
348
|
-
for (const c of commands) {
|
|
349
|
-
const gate = c.effect.gate;
|
|
350
|
-
if (gate === undefined) continue;
|
|
351
|
-
gateState.set(gate, {
|
|
352
|
-
gate, status: c.effect.exit === 0 ? "pass" : "fail", at: c.at, exit: c.effect.exit,
|
|
353
|
-
...(c.effect.workspace_scope ? { workspace_scope: c.effect.workspace_scope } : {}),
|
|
354
|
-
...(c.effect.workspace_observed === false ? { stale: true } : {}),
|
|
355
|
-
...(c.effect.workspace_sha256 ? { workspace_sha256: c.effect.workspace_sha256 } : {}),
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
const verification = [...gateState.values()].sort((a, b) =>
|
|
359
|
-
a.gate < b.gate ? -1 : a.gate > b.gate ? 1 : 0,
|
|
360
|
-
);
|
|
361
|
-
for (const item of verification) {
|
|
362
|
-
const hit = commands.filter((c) => c.effect.gate === item.gate).at(-1);
|
|
363
|
-
if (evidenceStale(events, { command: hit?.effect.cmd ?? "", event_id: hit?.id ?? "", at: item.at ?? "", exit: item.exit ?? -1,
|
|
364
|
-
...(item.workspace_scope ? { workspace_scope: item.workspace_scope } : {}),
|
|
365
|
-
...(item.workspace_sha256 ? { workspace_sha256: item.workspace_sha256 } : {}),
|
|
366
|
-
}, item.stale)) item.stale = true;
|
|
367
|
-
else delete item.stale;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// -- mark completions whose gate has since gone red -------------------------
|
|
371
|
-
const failingGates = new Map(
|
|
372
|
-
verification.filter((v) => v.status === "fail").map((v) => [v.gate, v]),
|
|
373
|
-
);
|
|
374
|
-
const completedMarked: CompletedItem[] = completed.map((original) => {
|
|
375
|
-
const { evidence_stale: _old, ...base } = original;
|
|
376
|
-
const item: CompletedItem = evidenceStale(events, original.evidence, original.evidence_stale)
|
|
377
|
-
? { ...base, evidence_stale: true } : base;
|
|
378
|
-
const gate = item.evidence.gate;
|
|
379
|
-
const failing = gate === undefined ? undefined : failingGates.get(gate);
|
|
380
|
-
if (!failing) {
|
|
381
|
-
// Drop any stale marker: the gate went green again.
|
|
382
|
-
const { evidence_superseded: _drop, ...rest } = item;
|
|
383
|
-
return rest;
|
|
384
|
-
}
|
|
385
|
-
return {
|
|
386
|
-
...item,
|
|
387
|
-
evidence_superseded: {
|
|
388
|
-
gate: failing.gate,
|
|
389
|
-
status: "fail" as const,
|
|
390
|
-
...(failing.exit !== undefined ? { exit: failing.exit } : {}),
|
|
391
|
-
...(failing.at !== undefined ? { at: failing.at } : {}),
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
// -- last activity: derived, so it is present even with zero annotations --
|
|
397
|
-
let lastActivity: string | null = null;
|
|
398
|
-
for (const e of events) {
|
|
399
|
-
if (e.t === "tool_result" && e.effect) {
|
|
400
|
-
const eff = e.effect;
|
|
401
|
-
lastActivity =
|
|
402
|
-
eff.kind === "command" ? `ran ${eff.cmd} (exit ${eff.exit})`
|
|
403
|
-
: eff.kind === "edit" ? `edited ${eff.path}`
|
|
404
|
-
: `read ${eff.path}`;
|
|
405
|
-
} else if (e.t === "assistant") {
|
|
406
|
-
const text = e.blocks.find((b) => b.type === "text");
|
|
407
|
-
if (text && text.type === "text" && text.text.trim()) {
|
|
408
|
-
lastActivity = firstLine(text.text);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if (lastActivity === null) lastActivity = prev?.state.last_activity ?? null;
|
|
413
|
-
|
|
414
|
-
// -- progress (decision D9) ----------------------------------------------
|
|
415
|
-
const eligibleChecks = eligibleProgressChecks(events, new Set([...newCompleted, ...identifiedCompleted].map(item => item.evidence.event_id)), failingGates);
|
|
416
|
-
// A bounded view is presentation, not derivation input. Refuse to forget an
|
|
417
|
-
// omitted ledger, which would make old observations appear new after a cut.
|
|
418
|
-
if (prev?.history && Object.values(prev.history.sections).some((range) => range.offset > 0)) {
|
|
419
|
-
throw new Error("deriveHandoff requires full replay state, not a paginated handoff");
|
|
420
|
-
}
|
|
421
|
-
const progress = deriveProgress(prev?.progress_evidence ?? [], events, input.self.node, eligibleChecks);
|
|
422
|
-
const links = deriveEvidenceLinks(prev?.evidence_links ?? [], events);
|
|
423
|
-
const acceptance = deriveAcceptance(prev?.acceptance, events);
|
|
424
|
-
const loadedSkills = deriveLoadedSkills(prev?.loaded_skills ?? [], events, input.self.node);
|
|
425
|
-
const processes = deriveProcesses(prev?.processes ?? [], events, input.self.node);
|
|
426
|
-
|
|
427
|
-
const hasRemaining = inFlight.length > 0 || blocked.length > 0 || openQuestions.length > 0;
|
|
428
|
-
// A next action is a statement about the current state of the work, so it
|
|
429
|
-
// follows the evidence rule above: only one this segment recorded or
|
|
430
|
-
// refreshed counts. A carried one stays listed but no longer suppresses the
|
|
431
|
-
// boundary and continuation reminders that ask the model to confirm it.
|
|
432
|
-
const thisSegment = new Set(events.map((e) => e.id));
|
|
433
|
-
const freshUnscoped = new Set(events.flatMap((e) => e.t === "next_action" && e.work_id === undefined ? [e.what] : []));
|
|
434
|
-
const freshWork = new Set(workItems.filter((item) => thisSegment.has(item.updated_at)).map((item) => item.id));
|
|
435
|
-
const hasNextAction = inFlight.some((i) => i.next_action.trim().length > 0 &&
|
|
436
|
-
(i.work_id === undefined ? freshUnscoped.has(i.what) : freshWork.has(i.work_id)));
|
|
437
|
-
|
|
438
|
-
return {
|
|
439
|
-
handoff_version: HANDOFF_VERSION,
|
|
440
|
-
predecessor: input.self,
|
|
441
|
-
objective,
|
|
442
|
-
user_turns: userTurns,
|
|
443
|
-
...(dropped > 0
|
|
444
|
-
? { user_turns_truncated: { dropped, recover_from: [cfg.manifestPath] } }
|
|
445
|
-
: {}),
|
|
446
|
-
state: {
|
|
447
|
-
...(workItems.length > 0 ? { work_items: workItems } : {}),
|
|
448
|
-
completed: completedMarked,
|
|
449
|
-
unverified_claims: dedupe([...(prev?.state.unverified_claims ?? []), ...unverified], (c) => JSON.stringify(c))
|
|
450
|
-
.filter((c) => !completedSet.has(c.what)),
|
|
451
|
-
in_flight: inFlight,
|
|
452
|
-
blocked,
|
|
453
|
-
last_activity: lastActivity,
|
|
454
|
-
},
|
|
455
|
-
decisions,
|
|
456
|
-
...(acceptance ? { acceptance } : {}),
|
|
457
|
-
pitfalls,
|
|
458
|
-
file_anchors: fileAnchors,
|
|
459
|
-
verification,
|
|
460
|
-
branches,
|
|
461
|
-
open_questions: openQuestions,
|
|
462
|
-
progress_evidence: progress.evidence,
|
|
463
|
-
...(links.length > 0 ? { evidence_links: links } : {}),
|
|
464
|
-
...(loadedSkills.length > 0 ? { loaded_skills: loadedSkills } : {}),
|
|
465
|
-
...(processes.length > 0 ? { processes } : {}),
|
|
466
|
-
continuation_valid: hasRemaining && hasNextAction,
|
|
467
|
-
budget: {
|
|
468
|
-
nodes_on_path: depth,
|
|
469
|
-
nodes_without_progress: progress.progressed
|
|
470
|
-
? 0
|
|
471
|
-
: (prev?.budget.nodes_without_progress ?? 0) + 1,
|
|
472
|
-
},
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function firstLine(s: string): string {
|
|
477
|
-
const line = s.trim().split("\n")[0] ?? "";
|
|
478
|
-
return line.length > 200 ? line.slice(0, 197) + "..." : line;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Events an adopt carries into the node it opens.
|
|
483
|
-
*
|
|
484
|
-
* Adopting a branch replaces the mainline with it, and the branch's ancestry
|
|
485
|
-
* stops at the fork point -- so everything the parent recorded after forking
|
|
486
|
-
* is outside it, including the decision that chose the branch. That is the
|
|
487
|
-
* least disposable record in the log, so it is carried rather than lost.
|
|
488
|
-
*
|
|
489
|
-
* Only annotations are carried. Harness events are either already in the
|
|
490
|
-
* branch's ancestry (before the fork) or are parent actions the branch never
|
|
491
|
-
* saw and should not inherit. Carrying annotations is free in context terms
|
|
492
|
-
* because they never replay as messages; only derivation reads them.
|
|
493
|
-
*
|
|
494
|
-
* A fork point that is not in `events` carries nothing, rather than falling
|
|
495
|
-
* back to all of them: an unknown fork point means the caller's picture of
|
|
496
|
-
* the tree is wrong, and carrying everything would silently duplicate work
|
|
497
|
-
* the branch already has.
|
|
498
|
-
*/
|
|
499
|
-
export function carryForward(
|
|
500
|
-
events: readonly LogEvent[],
|
|
501
|
-
since: EventId,
|
|
502
|
-
fromNode = 0,
|
|
503
|
-
): CarryableEvent[] {
|
|
504
|
-
const at = events.findIndex((e) => e.id === since);
|
|
505
|
-
if (at < 0) return [];
|
|
506
|
-
const carryable = new Set<string>(CARRYABLE_EVENTS);
|
|
507
|
-
return events
|
|
508
|
-
.slice(at + 1)
|
|
509
|
-
.filter((e): e is CarryableEvent => carryable.has(e.t))
|
|
510
|
-
.map((e) => ({
|
|
511
|
-
...e,
|
|
512
|
-
// Provenance, so the handoff can tell what this node produced from what
|
|
513
|
-
// it inherited through an adopt.
|
|
514
|
-
carried_from: e.carried_from ?? { node: fromNode, event: e.id },
|
|
515
|
-
}));
|
|
516
|
-
}
|
package/src/core/draft-images.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { ImageRef } from "./images.ts";
|
|
2
|
-
|
|
3
|
-
/** D8: draft labels carry identity; bytes remain immutable blob references. */
|
|
4
|
-
export interface DraftImageSpan {
|
|
5
|
-
readonly id: number;
|
|
6
|
-
readonly start: number;
|
|
7
|
-
readonly end: number;
|
|
8
|
-
readonly image: ImageRef;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function imageMarker(id: number): string { return `[Image #${id}]`; }
|
|
12
|
-
|
|
13
|
-
export function draftImageSpans(text: string, registry: ReadonlyMap<number, ImageRef>): DraftImageSpan[] {
|
|
14
|
-
const spans: DraftImageSpan[] = [];
|
|
15
|
-
for (const match of text.matchAll(/\[Image #(\d+)\]/g)) {
|
|
16
|
-
const id = Number(match[1]), image = registry.get(id);
|
|
17
|
-
if (image) spans.push({ id, start: match.index, end: match.index + match[0].length, image });
|
|
18
|
-
}
|
|
19
|
-
return spans;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Only registered, surviving tags are sent. Unknown lookalikes remain literal text. */
|
|
23
|
-
export function draftImageInput(text: string, registry: ReadonlyMap<number, ImageRef>): { text: string; images: ImageRef[] } {
|
|
24
|
-
const spans = draftImageSpans(text, registry), images: ImageRef[] = [], seen = new Set<number>();
|
|
25
|
-
let plain = "", from = 0;
|
|
26
|
-
for (const span of spans) {
|
|
27
|
-
plain += text.slice(from, span.start); from = span.end;
|
|
28
|
-
if (!seen.has(span.id)) { images.push(span.image); seen.add(span.id); }
|
|
29
|
-
}
|
|
30
|
-
return { text: (plain + text.slice(from)).trim(), images };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Adjacency includes one horizontal space, never another line or distant prose. */
|
|
34
|
-
export function focusedDraftImage(text: string, cursor: number, registry: ReadonlyMap<number, ImageRef>): DraftImageSpan | undefined {
|
|
35
|
-
const spans = draftImageSpans(text, registry);
|
|
36
|
-
return spans.find(span => cursor >= span.start && cursor < span.end)
|
|
37
|
-
?? spans.find(span => cursor === span.end)
|
|
38
|
-
?? spans.find(span => (cursor === span.end + 1 && /[ \t]/.test(text[span.end] ?? "")) ||
|
|
39
|
-
(cursor === span.start - 1 && /[ \t]/.test(text[cursor] ?? "")));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Merge registered labels before word/grapheme navigation and wrapping share them. */
|
|
43
|
-
export function segmentDraftImages(text: string, segments: Iterable<Intl.SegmentData>, registry: ReadonlyMap<number, ImageRef>): Intl.SegmentData[] {
|
|
44
|
-
const spans = draftImageSpans(text, registry);
|
|
45
|
-
if (!spans.length) return [...segments];
|
|
46
|
-
const result: Intl.SegmentData[] = [];
|
|
47
|
-
let index = 0;
|
|
48
|
-
for (const segment of segments) {
|
|
49
|
-
while (spans[index] && spans[index]!.end <= segment.index) index++;
|
|
50
|
-
const span = spans[index];
|
|
51
|
-
if (span && segment.index >= span.start && segment.index < span.end) {
|
|
52
|
-
if (segment.index === span.start) result.push({ segment: text.slice(span.start, span.end), index: span.start, input: text });
|
|
53
|
-
} else result.push(segment);
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|