@howaboua/pi-notes-compaction 0.0.15 → 0.0.16
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 +15 -0
- package/LICENSE +21 -0
- package/README.md +5 -2
- package/index.ts +8 -0
- package/package.json +16 -13
- package/src/board/context-briefing.ts +245 -0
- package/src/board/delivery.ts +85 -0
- package/src/guidance.ts +121 -0
- package/src/notes/AGENTS.md +27 -0
- package/src/{activation.ts → notes/activation.ts} +8 -10
- package/src/{attachment-sharing.ts → notes/attachment-sharing.ts} +1 -1
- package/src/{attachment-snapshot.ts → notes/attachment-snapshot.ts} +33 -20
- package/src/{context-sharing.ts → notes/context-sharing.ts} +7 -2
- package/src/{extension-hooks.ts → notes/extension-hooks.ts} +1 -12
- package/src/{extension-sharing.ts → notes/extension-sharing.ts} +1 -1
- package/src/notes/feature.ts +168 -0
- package/src/{history-windows.ts → notes/history-windows.ts} +10 -22
- package/src/{history.ts → notes/history.ts} +6 -5
- package/src/{index.ts → notes/index.ts} +20 -11
- package/src/{integrations.ts → notes/integrations.ts} +19 -3
- package/src/{lifecycle.ts → notes/lifecycle.ts} +0 -2
- package/src/{note-query.ts → notes/note-query.ts} +3 -5
- package/src/notes/note-result.ts +119 -0
- package/src/{note-save-marker.ts → notes/note-save-marker.ts} +3 -1
- package/src/{query-executor.ts → notes/query-executor.ts} +7 -2
- package/src/{query-input.ts → notes/query-input.ts} +1 -0
- package/src/{remote.ts → notes/remote.ts} +1 -1
- package/src/{saved-session-access.ts → notes/saved-session-access.ts} +14 -10
- package/src/{saved-session.ts → notes/saved-session.ts} +31 -15
- package/src/notes/saved-sharing-records.ts +170 -0
- package/src/{session-pruning.ts → notes/session-pruning.ts} +5 -5
- package/src/{settings-command.ts → notes/settings-command.ts} +29 -42
- package/src/{settings-controls.ts → notes/settings-controls.ts} +62 -72
- package/src/{settings-screen.ts → notes/settings-screen.ts} +25 -7
- package/src/{settings.ts → notes/settings.ts} +37 -6
- package/src/{shared-notes.ts → notes/shared-notes.ts} +21 -13
- package/src/{shared-session-reader.ts → notes/shared-session-reader.ts} +8 -11
- package/src/{sharing-service.ts → notes/sharing-service.ts} +1 -1
- package/src/{tool-contracts.ts → notes/tool-contracts.ts} +71 -44
- package/src/{tools.ts → notes/tools.ts} +2 -2
- package/src/{tree-handoff-read.ts → notes/tree-handoff-read.ts} +47 -32
- package/src/{window-message.ts → notes/window-message.ts} +15 -20
- package/src/settings-navigation.ts +11 -0
- package/src/timestamps.ts +3 -0
- package/tsconfig.json +9 -0
- package/src/note-result.ts +0 -70
- package/src/saved-sharing-records.ts +0 -135
- /package/src/{agent-identity.ts → notes/agent-identity.ts} +0 -0
- /package/src/{binding-startup.ts → notes/binding-startup.ts} +0 -0
- /package/src/{bridge.ts → notes/bridge.ts} +0 -0
- /package/src/{compaction-projection.ts → notes/compaction-projection.ts} +0 -0
- /package/src/{context-owner.ts → notes/context-owner.ts} +0 -0
- /package/src/{fresh-checkpoint.ts → notes/fresh-checkpoint.ts} +0 -0
- /package/src/{fresh-notes.ts → notes/fresh-notes.ts} +0 -0
- /package/src/{history-search-protocol.ts → notes/history-search-protocol.ts} +0 -0
- /package/src/{history-search-pruning.mjs → notes/history-search-pruning.mjs} +0 -0
- /package/src/{history-search-worker.mjs → notes/history-search-worker.mjs} +0 -0
- /package/src/{history-search.ts → notes/history-search.ts} +0 -0
- /package/src/{idle-admission.ts → notes/idle-admission.ts} +0 -0
- /package/src/{model-role-config.ts → notes/model-role-config.ts} +0 -0
- /package/src/{model-role-screen.ts → notes/model-role-screen.ts} +0 -0
- /package/src/{model-roles.ts → notes/model-roles.ts} +0 -0
- /package/src/{notes-lookup.ts → notes/notes-lookup.ts} +0 -0
- /package/src/{notes.ts → notes/notes.ts} +0 -0
- /package/src/{rollover.ts → notes/rollover.ts} +0 -0
- /package/src/{saved-session-index.mjs → notes/saved-session-index.mjs} +0 -0
- /package/src/{saved-session.mjs → notes/saved-session.mjs} +0 -0
- /package/src/{session-pruning-content.ts → notes/session-pruning-content.ts} +0 -0
- /package/src/{session-pruning-plan.ts → notes/session-pruning-plan.ts} +0 -0
- /package/src/{session-pruning-policy.ts → notes/session-pruning-policy.ts} +0 -0
- /package/src/{session-pruning-screen.ts → notes/session-pruning-screen.ts} +0 -0
- /package/src/{session-pruning-source.ts → notes/session-pruning-source.ts} +0 -0
- /package/src/{session-pruning-transaction.ts → notes/session-pruning-transaction.ts} +0 -0
- /package/src/{sqlite.mjs → notes/sqlite.mjs} +0 -0
- /package/src/{store.ts → notes/store.ts} +0 -0
- /package/src/{task-boundary.ts → notes/task-boundary.ts} +0 -0
- /package/src/{tree-archive-manifest.mjs → notes/tree-archive-manifest.mjs} +0 -0
- /package/src/{tree-archive.ts → notes/tree-archive.ts} +0 -0
- /package/src/{tree-checkpoint.ts → notes/tree-checkpoint.ts} +0 -0
- /package/src/{window-checkpoint.ts → notes/window-checkpoint.ts} +0 -0
- /package/src/{windows.ts → notes/windows.ts} +0 -0
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
ToolDefinition,
|
|
6
6
|
} from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import {
|
|
7
|
+
import { obj } from "@earendil-works/pi-schema";
|
|
8
8
|
import type { LookupQuery, SharedNotesDetails } from "./bridge.js";
|
|
9
9
|
import type { HistorySearch } from "./history-search.js";
|
|
10
10
|
import type { NotesLifecycle } from "./lifecycle.js";
|
|
@@ -123,7 +123,7 @@ export function createTools(
|
|
|
123
123
|
name: "get_context_remaining",
|
|
124
124
|
label: "get_context_remaining",
|
|
125
125
|
description: "Remaining context tokens",
|
|
126
|
-
parameters:
|
|
126
|
+
parameters: obj({}, { open: false }),
|
|
127
127
|
async execute(_id, _input, _signal, _update, ctx) {
|
|
128
128
|
assertActive();
|
|
129
129
|
const remaining = lifecycle.windows.remaining(ctx);
|
|
@@ -4,45 +4,60 @@ import {
|
|
|
4
4
|
buildSessionProjection,
|
|
5
5
|
type SessionEntry,
|
|
6
6
|
} from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
arr,
|
|
9
|
+
compile,
|
|
10
|
+
lit,
|
|
11
|
+
num,
|
|
12
|
+
obj,
|
|
13
|
+
opt,
|
|
14
|
+
str,
|
|
15
|
+
union,
|
|
16
|
+
unknown,
|
|
17
|
+
unsafe,
|
|
18
|
+
} from "@earendil-works/pi-schema";
|
|
9
19
|
|
|
10
20
|
const READ_KEY = "codexContextNoteRead";
|
|
11
|
-
const READ_SCHEMA =
|
|
21
|
+
const READ_SCHEMA = obj(
|
|
12
22
|
{
|
|
13
|
-
protocol:
|
|
14
|
-
origin:
|
|
15
|
-
id:
|
|
16
|
-
path:
|
|
17
|
-
namespace:
|
|
18
|
-
api:
|
|
19
|
-
provider:
|
|
20
|
-
model:
|
|
21
|
-
timestamp:
|
|
22
|
-
content:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
]),
|
|
35
|
-
),
|
|
36
|
-
}),
|
|
23
|
+
protocol: lit(1),
|
|
24
|
+
origin: lit("host"),
|
|
25
|
+
id: str({ pattern: "^[a-f0-9-]{36}$" }),
|
|
26
|
+
path: str({ minLength: 1 }),
|
|
27
|
+
namespace: opt(lit("notes")),
|
|
28
|
+
api: str({ minLength: 1 }),
|
|
29
|
+
provider: str({ minLength: 1 }),
|
|
30
|
+
model: str({ minLength: 1 }),
|
|
31
|
+
timestamp: num({ minimum: 0 }),
|
|
32
|
+
content: arr(
|
|
33
|
+
union([
|
|
34
|
+
obj({ type: lit("text"), text: str() }, { open: true }),
|
|
35
|
+
obj(
|
|
36
|
+
{
|
|
37
|
+
type: lit("image"),
|
|
38
|
+
data: str(),
|
|
39
|
+
mimeType: str(),
|
|
40
|
+
detail: opt(union([lit("auto"), lit("high"), lit("original")])),
|
|
41
|
+
},
|
|
42
|
+
{ open: true },
|
|
43
|
+
),
|
|
37
44
|
]),
|
|
38
45
|
),
|
|
39
|
-
details:
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
details: obj(
|
|
47
|
+
{
|
|
48
|
+
codexHistoryNotes: unsafe<Record<string, unknown>>({
|
|
49
|
+
type: "object",
|
|
50
|
+
patternProperties: { "^.*$": unknown() },
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
{ open: true },
|
|
54
|
+
),
|
|
42
55
|
},
|
|
43
|
-
{
|
|
56
|
+
{ open: false },
|
|
44
57
|
);
|
|
45
58
|
|
|
59
|
+
const readSchemaValidator = compile(READ_SCHEMA);
|
|
60
|
+
|
|
46
61
|
function callId(id: string): string {
|
|
47
62
|
const name = "tree_handoff_" + id.replaceAll("-", "");
|
|
48
63
|
return `${name}|fc_${name}`;
|
|
@@ -95,7 +110,7 @@ export function projectTreeHandoffReads(
|
|
|
95
110
|
if (!details || typeof details !== "object" || !(READ_KEY in details))
|
|
96
111
|
return [message];
|
|
97
112
|
const read = details[READ_KEY];
|
|
98
|
-
if (!
|
|
113
|
+
if (!readSchemaValidator.check(read))
|
|
99
114
|
throw new Error("Invalid persisted tree handoff read");
|
|
100
115
|
const resultDetails = read.details;
|
|
101
116
|
if (!isJson(resultDetails))
|
|
@@ -15,31 +15,31 @@ export interface WindowDetails {
|
|
|
15
15
|
trim: boolean;
|
|
16
16
|
}
|
|
17
17
|
const GUIDANCE = `<context_window_guidance>
|
|
18
|
-
Notes are recovery state, not diary.
|
|
18
|
+
Notes are recovery state, not diary. Storage is virtual, not disk. Create relative paths.
|
|
19
19
|
|
|
20
|
-
MUST maintain one authoritative checkpoint per task/topic
|
|
20
|
+
MUST maintain one authoritative checkpoint per task/topic: request, constraints, decision, status, next steps and relevant history IDs.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Near a substantive turn's end, before replying, consolidate changed recovery state. notes write creates or replaces; append adds. Do not interleave saves with ordinary tool calls. Skip routine turns and unchanged state. Explicit reminders and earlier handoffs still apply.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Link existing notes rather than duplicate. Recording does not authorise implementation.
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Immediately before new_context, MUST save the checkpoint via notes. Save before handoff too. For rollover, call new_context after saving.
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
When recovering context, read the checkpoint and necessary links if available, then retrieve a few relevant user messages with history for intent and communication preferences. Past messages are context, not renewed requests. Current instructions take precedence. Resume the current task; read further history only as needed. Do not reread unchanged notes.
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Skill reads do not survive rollover. MUST reread required skills.
|
|
30
|
+
MUST reread required skills after rollover.
|
|
33
31
|
</context_window_guidance>`;
|
|
34
32
|
|
|
35
33
|
const GPT_GUIDANCE = `<context_window_guidance>
|
|
36
|
-
Notes=recovery
|
|
34
|
+
Notes=virtual recovery state, NOT disk/diary. Create relative paths. MUST maintain one authoritative checkpoint/task→request/constraints/decision/status/next steps/history IDs. Link existing notes≠duplicate; recording≠implementation permission.
|
|
35
|
+
|
|
36
|
+
Near substantive turn end, before reply→consolidate CHANGED recovery. notes write→create/replace; append→add. No saves amid ordinary tool calls; skip routine/unchanged state. Explicit reminders/earlier handoffs still apply.
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
Immediately before new_context MUST save checkpoint via notes; before handoff too. Rollover→new_context after save.
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
Context recovery→notes checkpoint/necessary links if available→a few relevant user messages via history for intent/communication preferences→resume current task. Past messages=context≠renewed requests; current instructions win. Further history as needed; no unchanged-note rereads.
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
After rollover MUST reread required skills.
|
|
43
43
|
</context_window_guidance>`;
|
|
44
44
|
|
|
45
45
|
export function registerWindowRenderer(pi: ExtensionAPI): void {
|
|
@@ -167,13 +167,8 @@ export function windowMessage(
|
|
|
167
167
|
kind: "window" | "identity" = "window",
|
|
168
168
|
gpt = false,
|
|
169
169
|
): CustomMessageEntryDraft {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
`First context window id: ${ids.firstWindowId}`,
|
|
173
|
-
`Current context window id: ${ids.currentWindowId}`,
|
|
174
|
-
];
|
|
175
|
-
if (ids.previousWindowId)
|
|
176
|
-
lines.push(`Previous context window id: ${ids.previousWindowId}`);
|
|
170
|
+
// History exposes lookup IDs on demand; rollover must not churn this text just for UUIDs.
|
|
171
|
+
const lines = [`Agent name: ${agent}`];
|
|
177
172
|
if (hint) lines.push(hint);
|
|
178
173
|
return {
|
|
179
174
|
type: "custom_message",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
export type SettingsTab = "notes" | "board";
|
|
4
|
+
export type OpenSettings = (
|
|
5
|
+
ctx: ExtensionCommandContext,
|
|
6
|
+
tab: SettingsTab,
|
|
7
|
+
) => Promise<void>;
|
|
8
|
+
|
|
9
|
+
export interface FeatureSettings {
|
|
10
|
+
openSettings(ctx: ExtensionCommandContext): Promise<SettingsTab | undefined>;
|
|
11
|
+
}
|
package/tsconfig.json
ADDED
package/src/note-result.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { Type } from "typebox";
|
|
3
|
-
import { Check } from "typebox/value";
|
|
4
|
-
|
|
5
|
-
const OPTIONAL_STRING = Type.Optional(Type.String());
|
|
6
|
-
const OPTIONAL_BOOLEAN = Type.Optional(Type.Boolean());
|
|
7
|
-
const MATCH = Type.Object({ line_number: Type.Integer(), line: Type.String() });
|
|
8
|
-
|
|
9
|
-
// Pi codemode needs this declaration to return structuredContent rather than text.
|
|
10
|
-
export const NOTES_OUTPUT_SCHEMA = Type.Object(
|
|
11
|
-
{},
|
|
12
|
-
{ additionalProperties: true },
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const NOTES_RESULT_SCHEMA = Type.Object(
|
|
16
|
-
{
|
|
17
|
-
file: Type.Optional(
|
|
18
|
-
Type.Union([
|
|
19
|
-
Type.Object({
|
|
20
|
-
path: Type.String(),
|
|
21
|
-
content: OPTIONAL_STRING,
|
|
22
|
-
start_line: Type.Optional(Type.Integer()),
|
|
23
|
-
stop_line: Type.Optional(Type.Integer()),
|
|
24
|
-
total_lines: Type.Optional(Type.Integer()),
|
|
25
|
-
append_only: OPTIONAL_BOOLEAN,
|
|
26
|
-
}),
|
|
27
|
-
Type.Null(),
|
|
28
|
-
]),
|
|
29
|
-
),
|
|
30
|
-
files: Type.Optional(
|
|
31
|
-
Type.Array(
|
|
32
|
-
Type.Object({
|
|
33
|
-
path: Type.String(),
|
|
34
|
-
updated_at: OPTIONAL_STRING,
|
|
35
|
-
created_at: OPTIONAL_STRING,
|
|
36
|
-
matches: Type.Optional(Type.Array(MATCH)),
|
|
37
|
-
truncated: OPTIONAL_BOOLEAN,
|
|
38
|
-
append_only: OPTIONAL_BOOLEAN,
|
|
39
|
-
}),
|
|
40
|
-
),
|
|
41
|
-
),
|
|
42
|
-
usage: OPTIONAL_STRING,
|
|
43
|
-
warnings: Type.Optional(Type.Array(Type.String())),
|
|
44
|
-
warning: OPTIONAL_STRING,
|
|
45
|
-
truncated: OPTIONAL_BOOLEAN,
|
|
46
|
-
read_only: OPTIONAL_BOOLEAN,
|
|
47
|
-
saved_at: OPTIONAL_STRING,
|
|
48
|
-
captured_at: OPTIONAL_STRING,
|
|
49
|
-
results: OPTIONAL_STRING,
|
|
50
|
-
actions: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
51
|
-
writes: OPTIONAL_STRING,
|
|
52
|
-
paths: OPTIONAL_STRING,
|
|
53
|
-
ranges: OPTIONAL_STRING,
|
|
54
|
-
defaults: OPTIONAL_STRING,
|
|
55
|
-
},
|
|
56
|
-
{ additionalProperties: false },
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
/** One canonical payload for native text and every programmatic caller. */
|
|
60
|
-
export function noteResult(payload: unknown): AgentToolResult<unknown> {
|
|
61
|
-
if (!Check(NOTES_RESULT_SCHEMA, payload))
|
|
62
|
-
throw new Error(
|
|
63
|
-
"Notes returned invalid data. Read the note before retrying a write.",
|
|
64
|
-
);
|
|
65
|
-
return {
|
|
66
|
-
content: [{ type: "text", text: JSON.stringify(payload) }],
|
|
67
|
-
structuredContent: payload,
|
|
68
|
-
details: {},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { type Static, Type } from "typebox";
|
|
2
|
-
import { Check } from "typebox/value";
|
|
3
|
-
import {
|
|
4
|
-
CONTEXT_AGENT_PATTERN,
|
|
5
|
-
canonicalAgentName,
|
|
6
|
-
canonicalContextIdentity,
|
|
7
|
-
contextStorageAgentName,
|
|
8
|
-
pinnedContextIdentity,
|
|
9
|
-
} from "./agent-identity.js";
|
|
10
|
-
import type { SavedNotesSession } from "./saved-session.js";
|
|
11
|
-
|
|
12
|
-
const Agent = Type.String({ pattern: CONTEXT_AGENT_PATTERN });
|
|
13
|
-
export const Identity = Type.Object({
|
|
14
|
-
protocol: Type.Literal(1),
|
|
15
|
-
sessionId: Type.String(),
|
|
16
|
-
threadId: Type.String(),
|
|
17
|
-
agentName: Agent,
|
|
18
|
-
storageAgentName: Type.Optional(Agent),
|
|
19
|
-
storage: Type.Optional(
|
|
20
|
-
Type.Union([Type.Literal("session"), Type.Literal("remote")]),
|
|
21
|
-
),
|
|
22
|
-
routing: Type.Optional(Type.Unknown()),
|
|
23
|
-
});
|
|
24
|
-
export const Member = Type.Object({
|
|
25
|
-
threadId: Type.String(),
|
|
26
|
-
sessionId: Type.String(),
|
|
27
|
-
agentName: Agent,
|
|
28
|
-
machine: Type.String(),
|
|
29
|
-
sessionFile: Type.String(),
|
|
30
|
-
});
|
|
31
|
-
export const Plan = Type.Object({
|
|
32
|
-
controllerSessionId: Type.String(),
|
|
33
|
-
targetSessionId: Type.String(),
|
|
34
|
-
context: Type.Optional(
|
|
35
|
-
Type.Object({
|
|
36
|
-
controller: Identity,
|
|
37
|
-
target: Identity,
|
|
38
|
-
alias: Agent,
|
|
39
|
-
controllerAlias: Agent,
|
|
40
|
-
controllerFile: Type.Optional(Type.String()),
|
|
41
|
-
controllerMachine: Type.Optional(Type.String()),
|
|
42
|
-
controllerNotes: Type.Unknown(),
|
|
43
|
-
targetNotes: Type.Unknown(),
|
|
44
|
-
}),
|
|
45
|
-
),
|
|
46
|
-
});
|
|
47
|
-
export const Route = Type.Object({
|
|
48
|
-
plan: Plan,
|
|
49
|
-
machine: Type.String(),
|
|
50
|
-
sessionFile: Type.String(),
|
|
51
|
-
phase: Type.Union([Type.Literal("pending"), Type.Literal("ready")]),
|
|
52
|
-
detached: Type.Optional(
|
|
53
|
-
Type.Object({ context: Type.Optional(Type.Unknown()) }),
|
|
54
|
-
),
|
|
55
|
-
});
|
|
56
|
-
export const Detachment = Type.Object({
|
|
57
|
-
plan: Plan,
|
|
58
|
-
context: Type.Optional(Type.Unknown()),
|
|
59
|
-
});
|
|
60
|
-
export const Snapshot = Type.Object({
|
|
61
|
-
protocol: Type.Literal(1),
|
|
62
|
-
timestamp: Type.Number(),
|
|
63
|
-
files: Type.Array(
|
|
64
|
-
Type.Object({
|
|
65
|
-
path: Type.String(),
|
|
66
|
-
text: Type.String(),
|
|
67
|
-
createdAt: Type.Number(),
|
|
68
|
-
updatedAt: Type.Number(),
|
|
69
|
-
operation: Type.Union([
|
|
70
|
-
Type.Literal("local_append_overlay"),
|
|
71
|
-
Type.Literal("local_replacement"),
|
|
72
|
-
]),
|
|
73
|
-
}),
|
|
74
|
-
),
|
|
75
|
-
});
|
|
76
|
-
export const Parent = Type.Object({
|
|
77
|
-
transport: Type.Literal("shepherdr"),
|
|
78
|
-
parent: Type.String(),
|
|
79
|
-
savedParent: Type.Optional(
|
|
80
|
-
Type.Object({ machine: Type.String(), sessionFile: Type.String() }),
|
|
81
|
-
),
|
|
82
|
-
});
|
|
83
|
-
export type Identity = Static<typeof Identity>;
|
|
84
|
-
|
|
85
|
-
/** Ordinary family membership is immutable, explicit and native-session owned. */
|
|
86
|
-
export function savedFamilyIdentity(
|
|
87
|
-
session: Pick<SavedNotesSession, "threadId" | "entries">,
|
|
88
|
-
): Identity | undefined {
|
|
89
|
-
const identity = savedNotesIdentity(session);
|
|
90
|
-
if (
|
|
91
|
-
identity.storage === undefined ||
|
|
92
|
-
!session.entries.some(
|
|
93
|
-
(entry) =>
|
|
94
|
-
entry.type === "custom" &&
|
|
95
|
-
entry.customType === "codex-context-agent" &&
|
|
96
|
-
Check(Identity, entry.data) &&
|
|
97
|
-
entry.data.threadId === session.threadId,
|
|
98
|
-
)
|
|
99
|
-
)
|
|
100
|
-
return;
|
|
101
|
-
return identity;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Persisted sharing is session-scoped. Forks never inherit the source agent's address. */
|
|
105
|
-
export function savedNotesIdentity(
|
|
106
|
-
session: Pick<SavedNotesSession, "threadId" | "entries">,
|
|
107
|
-
): Identity {
|
|
108
|
-
let found: Identity | undefined;
|
|
109
|
-
for (const entry of session.entries) {
|
|
110
|
-
if (entry.type !== "custom" || entry.customType !== "codex-context-agent")
|
|
111
|
-
continue;
|
|
112
|
-
if (!Check(Identity, entry.data))
|
|
113
|
-
throw new Error("Invalid saved notes identity");
|
|
114
|
-
if (entry.data.threadId !== session.threadId) continue;
|
|
115
|
-
if (found) throw new Error("Conflicting saved notes identities");
|
|
116
|
-
found = entry.data;
|
|
117
|
-
}
|
|
118
|
-
return canonicalContextIdentity(
|
|
119
|
-
found ??
|
|
120
|
-
pinnedContextIdentity(session.threadId, session.entries) ?? {
|
|
121
|
-
protocol: 1,
|
|
122
|
-
threadId: session.threadId,
|
|
123
|
-
sessionId: session.threadId,
|
|
124
|
-
agentName: canonicalAgentName(session.threadId),
|
|
125
|
-
},
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function sameOwner(a: Identity, b: Identity): boolean {
|
|
130
|
-
return (
|
|
131
|
-
a.threadId === b.threadId &&
|
|
132
|
-
a.sessionId === b.sessionId &&
|
|
133
|
-
contextStorageAgentName(a) === contextStorageAgentName(b)
|
|
134
|
-
);
|
|
135
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|