@howaboua/pi-agent-comms 0.0.1-dev.14.1.g7d1d3da173aa → 0.0.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 +11 -0
- package/README.md +3 -3
- package/docs/BOARD.md +1 -1
- package/docs/NOTES.md +1 -1
- package/package.json +5 -5
- package/src/board/contract.ts +31 -27
- package/src/board/identity.ts +49 -29
- package/src/board/protocol.ts +98 -59
- package/src/board/tool.ts +5 -0
- package/src/notes/attachment-snapshot.ts +33 -20
- package/src/notes/integrations.ts +6 -3
- package/src/notes/note-result.ts +70 -39
- package/src/notes/query-input.ts +1 -0
- package/src/notes/saved-session-access.ts +12 -8
- package/src/notes/saved-session.ts +31 -15
- package/src/notes/saved-sharing-records.ts +110 -75
- package/src/notes/shared-notes.ts +19 -11
- package/src/notes/shared-session-reader.ts +4 -2
- package/src/notes/tool-contracts.ts +71 -44
- package/src/notes/tools.ts +2 -2
- package/src/notes/tree-handoff-read.ts +47 -32
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2
1
|
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
bool,
|
|
4
|
+
compile,
|
|
5
|
+
int,
|
|
6
|
+
nul,
|
|
7
|
+
obj,
|
|
8
|
+
oneOf,
|
|
9
|
+
opt,
|
|
10
|
+
type Schema,
|
|
11
|
+
str,
|
|
12
|
+
union,
|
|
13
|
+
type Validator,
|
|
14
|
+
} from "@earendil-works/pi-schema";
|
|
5
15
|
import type { LookupQuery } from "./bridge.js";
|
|
6
16
|
import { noteResult } from "./note-result.js";
|
|
7
17
|
import { internalQueryArguments, normalizeQueryInput } from "./query-input.js";
|
|
@@ -29,14 +39,14 @@ export const NOTES_ROUTING_GUIDELINE =
|
|
|
29
39
|
export const NEW_CONTEXT_DESCRIPTION =
|
|
30
40
|
"Start fresh context window. MUST save notes before calling";
|
|
31
41
|
export const GPT_NEW_CONTEXT_DESCRIPTION = "Save notes→fresh context";
|
|
32
|
-
const STRING =
|
|
33
|
-
const INTEGER =
|
|
34
|
-
const LINE =
|
|
35
|
-
export const NOTES_SCHEMA =
|
|
42
|
+
const STRING = opt(str());
|
|
43
|
+
const INTEGER = opt(int({ minimum: 1 }));
|
|
44
|
+
const LINE = opt(union([int(), nul()]));
|
|
45
|
+
export const NOTES_SCHEMA = obj(
|
|
36
46
|
{
|
|
37
|
-
action:
|
|
38
|
-
path:
|
|
39
|
-
|
|
47
|
+
action: opt({ ...oneOf(NOTES_ACTIONS), type: "string" }),
|
|
48
|
+
path: opt(
|
|
49
|
+
union([str(), nul()], {
|
|
40
50
|
description:
|
|
41
51
|
"File for read/write/append; prefix for list/search; virtual filesystem, not files in the project",
|
|
42
52
|
}),
|
|
@@ -47,49 +57,52 @@ export const NOTES_SCHEMA = Type.Object(
|
|
|
47
57
|
stop_line: LINE,
|
|
48
58
|
limit: INTEGER,
|
|
49
59
|
max_matches_per_file: INTEGER,
|
|
50
|
-
file_order:
|
|
51
|
-
file_order_by:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
file_order: opt({ ...oneOf(["ascending", "descending"]), type: "string" }),
|
|
61
|
+
file_order_by: opt({
|
|
62
|
+
...oneOf(["name", "created_at", "updated_at"]),
|
|
63
|
+
type: "string",
|
|
64
|
+
}),
|
|
65
|
+
recent_file_first: opt(bool()),
|
|
55
66
|
},
|
|
56
|
-
{
|
|
67
|
+
{ open: false },
|
|
57
68
|
);
|
|
58
|
-
const NEW_CONTEXT_SCHEMA =
|
|
69
|
+
const NEW_CONTEXT_SCHEMA = obj(
|
|
59
70
|
{
|
|
60
|
-
role:
|
|
61
|
-
|
|
71
|
+
role: opt(
|
|
72
|
+
str({
|
|
62
73
|
minLength: 1,
|
|
63
74
|
description:
|
|
64
75
|
"Configured model-role ID, not an agent name or handoff text",
|
|
65
76
|
}),
|
|
66
77
|
),
|
|
67
78
|
},
|
|
68
|
-
{
|
|
79
|
+
{ open: false },
|
|
69
80
|
);
|
|
70
81
|
|
|
82
|
+
const newContextSchemaValidator = compile(NEW_CONTEXT_SCHEMA);
|
|
83
|
+
|
|
71
84
|
export function newContextSchema(roleIds: string[]) {
|
|
72
|
-
return
|
|
73
|
-
roleIds.length ? { role:
|
|
74
|
-
{
|
|
85
|
+
return obj(
|
|
86
|
+
roleIds.length ? { role: opt({ ...oneOf(roleIds), type: "string" }) } : {},
|
|
87
|
+
{ open: false },
|
|
75
88
|
);
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
export function prepareNewContextArguments(input: unknown) {
|
|
79
92
|
const args = input ?? {};
|
|
80
|
-
if (!
|
|
93
|
+
if (!newContextSchemaValidator.check(args))
|
|
81
94
|
throw new Error(
|
|
82
95
|
'Use {} to keep the current model, or {role: "name"} for a configured role.',
|
|
83
96
|
);
|
|
84
97
|
return args;
|
|
85
98
|
}
|
|
86
|
-
export const HISTORY_SCHEMA =
|
|
99
|
+
export const HISTORY_SCHEMA = obj(
|
|
87
100
|
{
|
|
88
|
-
action:
|
|
89
|
-
agent_name:
|
|
90
|
-
item_id:
|
|
91
|
-
window_id:
|
|
92
|
-
|
|
101
|
+
action: opt({ ...oneOf(HISTORY_ACTIONS), type: "string" }),
|
|
102
|
+
agent_name: opt(union([str(), nul()])),
|
|
103
|
+
item_id: opt(str()),
|
|
104
|
+
window_id: opt(
|
|
105
|
+
union([str(), nul()], {
|
|
93
106
|
description: "Required with item_id for read",
|
|
94
107
|
}),
|
|
95
108
|
),
|
|
@@ -97,18 +110,21 @@ export const HISTORY_SCHEMA = Type.Object(
|
|
|
97
110
|
limit: INTEGER,
|
|
98
111
|
limit_chars: INTEGER,
|
|
99
112
|
max_chars_per_item: INTEGER,
|
|
100
|
-
offset_chars:
|
|
101
|
-
recent_first:
|
|
102
|
-
role:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
113
|
+
offset_chars: opt(int({ minimum: 0 })),
|
|
114
|
+
recent_first: opt(bool()),
|
|
115
|
+
role: opt(
|
|
116
|
+
union([
|
|
117
|
+
{
|
|
118
|
+
...oneOf(["user", "assistant", "tool", "system", "developer"]),
|
|
119
|
+
type: "string",
|
|
120
|
+
},
|
|
121
|
+
nul(),
|
|
106
122
|
]),
|
|
107
123
|
),
|
|
108
|
-
tool_name:
|
|
109
|
-
tool_namespace:
|
|
124
|
+
tool_name: opt(union([str(), nul()])),
|
|
125
|
+
tool_namespace: opt(union([str(), nul()])),
|
|
110
126
|
},
|
|
111
|
-
{
|
|
127
|
+
{ open: false },
|
|
112
128
|
);
|
|
113
129
|
|
|
114
130
|
const FIELDS: Record<string, readonly string[]> = {
|
|
@@ -272,25 +288,36 @@ export function queryHelp(
|
|
|
272
288
|
|
|
273
289
|
export function prepareNotesArguments(args: unknown) {
|
|
274
290
|
const params = normalizeQueryInput("notes", args);
|
|
275
|
-
validateArguments("notes", params,
|
|
291
|
+
validateArguments("notes", params, NOTES_FIELD_VALIDATORS);
|
|
276
292
|
return params;
|
|
277
293
|
}
|
|
278
294
|
|
|
279
295
|
export function prepareHistoryArguments(args: unknown) {
|
|
280
296
|
const params = normalizeQueryInput("history", args);
|
|
281
|
-
validateArguments("history", params,
|
|
297
|
+
validateArguments("history", params, HISTORY_FIELD_VALIDATORS);
|
|
282
298
|
return params;
|
|
283
299
|
}
|
|
284
300
|
|
|
301
|
+
const NOTES_FIELD_VALIDATORS = fieldValidators(NOTES_SCHEMA);
|
|
302
|
+
const HISTORY_FIELD_VALIDATORS = fieldValidators(HISTORY_SCHEMA);
|
|
303
|
+
|
|
304
|
+
function fieldValidators(schema: Schema): Record<string, Validator> {
|
|
305
|
+
return Object.fromEntries(
|
|
306
|
+
Object.entries(schema["properties"] as Record<string, Schema>).map(
|
|
307
|
+
([field, property]) => [field, compile(property)],
|
|
308
|
+
),
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
285
312
|
function validateArguments(
|
|
286
313
|
namespace: LookupQuery["namespace"],
|
|
287
314
|
params: Record<string, unknown>,
|
|
288
|
-
|
|
315
|
+
validators: Record<string, Validator>,
|
|
289
316
|
) {
|
|
290
317
|
if (!queryHelp(namespace, params)) queryArguments(namespace, params);
|
|
291
318
|
for (const [field, value] of Object.entries(params)) {
|
|
292
|
-
const
|
|
293
|
-
if (!
|
|
319
|
+
const validator = validators[field];
|
|
320
|
+
if (!validator || !validator.check(value))
|
|
294
321
|
throw new Error(
|
|
295
322
|
`Invalid ${namespace} ${field}; use {} for exact arguments`,
|
|
296
323
|
);
|
package/src/notes/tools.ts
CHANGED
|
@@ -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))
|