@oisin-ee/pi-todo 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/package.json +34 -3
- package/src/generated/todo_core.d.ts +140 -0
- package/src/generated/todo_core.js +681 -0
- package/src/generated/todo_core_bg.wasm +0 -0
- package/src/generated/todo_core_bg.wasm.d.ts +13 -0
- package/src/index.ts +63 -0
- package/src/lifecycle.ts +90 -0
- package/src/reminder.ts +30 -0
- package/src/source.ts +18 -0
- package/src/state.ts +28 -0
- package/src/tool.ts +55 -0
- package/src/wasm.ts +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Momokaya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @oisin-ee/pi-todo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A `todo` tool for [pi](https://pi.dev). The model keeps one ordered task list for the session. Exactly one task is active.
|
|
4
|
+
The list rules run in Rust, compiled to WebAssembly.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pi install npm:@oisin-ee/pi-todo
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
To install it together with prewalk, use [`@oisin-ee/pi-prewalk-kit`](https://www.npmjs.com/package/@oisin-ee/pi-prewalk-kit).
|
|
11
|
+
|
|
12
|
+
## The tool
|
|
13
|
+
|
|
14
|
+
The model calls `todo` with one `op`. Tasks are addressed by their exact content.
|
|
15
|
+
|
|
16
|
+
| `op` | Effect |
|
|
17
|
+
| -------- | ------------------------------------------------------------ |
|
|
18
|
+
| `init` | Replaces the list with `items`. |
|
|
19
|
+
| `append` | Adds `items` to the end. |
|
|
20
|
+
| `start` | Makes `task` the active task. |
|
|
21
|
+
| `done` | Completes `task`. Without `task`, completes every open task. |
|
|
22
|
+
| `drop` | Abandons `task`. Without `task`, abandons every open task. |
|
|
23
|
+
| `view` | Returns the list. It does not change it. |
|
|
24
|
+
|
|
25
|
+
When the active task closes, the next open task starts. An empty task, a repeated task, or an unknown task is an error,
|
|
26
|
+
and the list stays as it was.
|
|
27
|
+
|
|
28
|
+
## State
|
|
29
|
+
|
|
30
|
+
Each change is saved as a `todo-state` entry on the session branch. There is no other state. So a resumed session,
|
|
31
|
+
a `/tree` move, and calls made from inside codemode all see the list of the current branch. A widget shows the list,
|
|
32
|
+
and `/todos` prints it.
|
|
33
|
+
|
|
34
|
+
## Reminder
|
|
35
|
+
|
|
36
|
+
When the agent stops with open tasks, pi-todo adds a hidden reminder that lists them and continues the turn.
|
|
37
|
+
It sends at most 3 reminders per user message. After a reminder, it waits for the list to change before it sends
|
|
38
|
+
another. A new user message resets the count.
|
|
39
|
+
|
|
40
|
+
## Other todo tools
|
|
41
|
+
|
|
42
|
+
If another package already registers `todo`, pi-todo stays inactive and shows a warning that names that package.
|
|
43
|
+
|
|
44
|
+
## Source
|
|
45
|
+
|
|
46
|
+
The operations, the active-task rule, and the reminder follow
|
|
47
|
+
[oh-my-pi](https://github.com/can1357/oh-my-pi/tree/e7fe318/packages/coding-agent/src) (`tools/todo`,
|
|
48
|
+
`todo-tracker.ts`), MIT. Saving a custom entry on every change follows
|
|
49
|
+
[rpiv-todo](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo).
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oisin-ee/pi-todo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A todo tool for pi with a Rust core: one active task, state on the session branch.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-extension",
|
|
7
|
+
"pi-package",
|
|
8
|
+
"todo"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/oisin-ee/pi-prewalk.git",
|
|
14
|
+
"directory": "packages/pi-todo"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src/",
|
|
18
|
+
"!src/**/*.test.ts"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@earendil-works/pi-ai": "1.3.0",
|
|
23
|
+
"@earendil-works/pi-coding-agent": "1.3.0",
|
|
24
|
+
"typebox": "1.3.27"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@earendil-works/pi-ai": "*",
|
|
28
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
29
|
+
"typebox": "*"
|
|
30
|
+
},
|
|
31
|
+
"pi": {
|
|
32
|
+
"extensions": [
|
|
33
|
+
"./src/index.ts"
|
|
34
|
+
],
|
|
35
|
+
"image": "https://raw.githubusercontent.com/oisin-ee/pi-prewalk/main/assets/prewalk.png"
|
|
36
|
+
}
|
|
6
37
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* A successful operation; views never persist a snapshot.
|
|
5
|
+
*/
|
|
6
|
+
export interface Change {
|
|
7
|
+
list: TodoList;
|
|
8
|
+
persist: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Branch facts supplied to the reminder boundary.
|
|
13
|
+
*/
|
|
14
|
+
export interface ReminderHistory {
|
|
15
|
+
facts: ReminderFact[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* One operation, with task content used as an exact identifier.
|
|
20
|
+
*/
|
|
21
|
+
export interface Request {
|
|
22
|
+
op: Operation;
|
|
23
|
+
items: string[] | undefined;
|
|
24
|
+
task: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* One task, addressed by its exact content.
|
|
29
|
+
*/
|
|
30
|
+
export interface Task {
|
|
31
|
+
content: string;
|
|
32
|
+
status: Status;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Relevant facts in branch order, including proposed boundary entries.
|
|
37
|
+
*/
|
|
38
|
+
export type ReminderFact = { kind: "user" } | { kind: "snapshot"; list: TodoList } | { kind: "reminder" };
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Supported model-facing operations.
|
|
42
|
+
*/
|
|
43
|
+
export type Operation = "init" | "start" | "done" | "drop" | "append" | "view";
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The state of one task.
|
|
47
|
+
*/
|
|
48
|
+
export type Status = "pending" | "in_progress" | "completed" | "abandoned";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The whole todo list of a session branch.
|
|
52
|
+
*/
|
|
53
|
+
export interface TodoList {
|
|
54
|
+
tasks: Task[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Applies one validated operation.
|
|
60
|
+
*
|
|
61
|
+
* # Errors
|
|
62
|
+
*
|
|
63
|
+
* Throws for malformed input or a rejected operation.
|
|
64
|
+
*/
|
|
65
|
+
export function apply(list: TodoList, request: Request): Change;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Computes completion policy from branch facts.
|
|
69
|
+
*
|
|
70
|
+
* # Errors
|
|
71
|
+
*
|
|
72
|
+
* Throws for malformed facts.
|
|
73
|
+
*/
|
|
74
|
+
export function completion_reminder(facts: ReminderHistory): string | undefined;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Replaces the whole list with `items`.
|
|
78
|
+
*
|
|
79
|
+
* # Errors
|
|
80
|
+
*
|
|
81
|
+
* Throws the core's message for an empty list, an empty task, or a repeat.
|
|
82
|
+
*/
|
|
83
|
+
export function init(items: string[]): TodoList;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Validates a stored snapshot. It comes from the session file, so it is typed
|
|
87
|
+
* `unknown` and checked here, by the type that owns its shape.
|
|
88
|
+
*
|
|
89
|
+
* # Errors
|
|
90
|
+
*
|
|
91
|
+
* Throws when `snapshot` is not a valid todo list.
|
|
92
|
+
*/
|
|
93
|
+
export function parse(snapshot: unknown): TodoList;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The model-facing summary of `list`.
|
|
97
|
+
*
|
|
98
|
+
* # Errors
|
|
99
|
+
*
|
|
100
|
+
* Throws when `list` is not a valid todo list.
|
|
101
|
+
*/
|
|
102
|
+
export function view(list: TodoList): string;
|
|
103
|
+
|
|
104
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
105
|
+
|
|
106
|
+
export interface InitOutput {
|
|
107
|
+
readonly memory: WebAssembly.Memory;
|
|
108
|
+
readonly apply: (a: number, b: number, c: number) => void;
|
|
109
|
+
readonly completion_reminder: (a: number, b: number) => void;
|
|
110
|
+
readonly init: (a: number, b: number, c: number) => void;
|
|
111
|
+
readonly parse: (a: number, b: number) => void;
|
|
112
|
+
readonly view: (a: number, b: number) => void;
|
|
113
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
114
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
115
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
116
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
117
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
124
|
+
* a precompiled `WebAssembly.Module`.
|
|
125
|
+
*
|
|
126
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
127
|
+
*
|
|
128
|
+
* @returns {InitOutput}
|
|
129
|
+
*/
|
|
130
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
134
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
135
|
+
*
|
|
136
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
137
|
+
*
|
|
138
|
+
* @returns {Promise<InitOutput>}
|
|
139
|
+
*/
|
|
140
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
/* @ts-self-types="./todo_core.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Applies one validated operation.
|
|
5
|
+
*
|
|
6
|
+
* # Errors
|
|
7
|
+
*
|
|
8
|
+
* Throws for malformed input or a rejected operation.
|
|
9
|
+
* @param {TodoList} list
|
|
10
|
+
* @param {Request} request
|
|
11
|
+
* @returns {Change}
|
|
12
|
+
*/
|
|
13
|
+
export function apply(list, request) {
|
|
14
|
+
try {
|
|
15
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
16
|
+
wasm.apply(retptr, addBorrowedObject(list), addBorrowedObject(request));
|
|
17
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
18
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
19
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
20
|
+
if (r2) {
|
|
21
|
+
throw takeObject(r1);
|
|
22
|
+
}
|
|
23
|
+
return takeObject(r0);
|
|
24
|
+
} finally {
|
|
25
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
26
|
+
heap[stack_pointer++] = undefined;
|
|
27
|
+
heap[stack_pointer++] = undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Computes completion policy from branch facts.
|
|
33
|
+
*
|
|
34
|
+
* # Errors
|
|
35
|
+
*
|
|
36
|
+
* Throws for malformed facts.
|
|
37
|
+
* @param {ReminderHistory} facts
|
|
38
|
+
* @returns {string | undefined}
|
|
39
|
+
*/
|
|
40
|
+
export function completion_reminder(facts) {
|
|
41
|
+
try {
|
|
42
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
43
|
+
wasm.completion_reminder(retptr, addBorrowedObject(facts));
|
|
44
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
45
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
46
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
47
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
48
|
+
if (r3) {
|
|
49
|
+
throw takeObject(r2);
|
|
50
|
+
}
|
|
51
|
+
let v1;
|
|
52
|
+
if (r0 !== 0) {
|
|
53
|
+
v1 = getStringFromWasm0(r0, r1);
|
|
54
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
55
|
+
}
|
|
56
|
+
return v1;
|
|
57
|
+
} finally {
|
|
58
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
59
|
+
heap[stack_pointer++] = undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Replaces the whole list with `items`.
|
|
65
|
+
*
|
|
66
|
+
* # Errors
|
|
67
|
+
*
|
|
68
|
+
* Throws the core's message for an empty list, an empty task, or a repeat.
|
|
69
|
+
* @param {string[]} items
|
|
70
|
+
* @returns {TodoList}
|
|
71
|
+
*/
|
|
72
|
+
export function init(items) {
|
|
73
|
+
try {
|
|
74
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
75
|
+
const ptr0 = passArrayJsValueToWasm0(items, wasm.__wbindgen_export);
|
|
76
|
+
const len0 = WASM_VECTOR_LEN;
|
|
77
|
+
wasm.init(retptr, ptr0, len0);
|
|
78
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
79
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
80
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
81
|
+
if (r2) {
|
|
82
|
+
throw takeObject(r1);
|
|
83
|
+
}
|
|
84
|
+
return takeObject(r0);
|
|
85
|
+
} finally {
|
|
86
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Validates a stored snapshot. It comes from the session file, so it is typed
|
|
92
|
+
* `unknown` and checked here, by the type that owns its shape.
|
|
93
|
+
*
|
|
94
|
+
* # Errors
|
|
95
|
+
*
|
|
96
|
+
* Throws when `snapshot` is not a valid todo list.
|
|
97
|
+
* @param {unknown} snapshot
|
|
98
|
+
* @returns {TodoList}
|
|
99
|
+
*/
|
|
100
|
+
export function parse(snapshot) {
|
|
101
|
+
try {
|
|
102
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
103
|
+
wasm.parse(retptr, addHeapObject(snapshot));
|
|
104
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
105
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
106
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
107
|
+
if (r2) {
|
|
108
|
+
throw takeObject(r1);
|
|
109
|
+
}
|
|
110
|
+
return takeObject(r0);
|
|
111
|
+
} finally {
|
|
112
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The model-facing summary of `list`.
|
|
118
|
+
*
|
|
119
|
+
* # Errors
|
|
120
|
+
*
|
|
121
|
+
* Throws when `list` is not a valid todo list.
|
|
122
|
+
* @param {TodoList} list
|
|
123
|
+
* @returns {string}
|
|
124
|
+
*/
|
|
125
|
+
export function view(list) {
|
|
126
|
+
let deferred2_0;
|
|
127
|
+
let deferred2_1;
|
|
128
|
+
try {
|
|
129
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
130
|
+
wasm.view(retptr, addBorrowedObject(list));
|
|
131
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
132
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
133
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
134
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
135
|
+
var ptr1 = r0;
|
|
136
|
+
var len1 = r1;
|
|
137
|
+
if (r3) {
|
|
138
|
+
ptr1 = 0; len1 = 0;
|
|
139
|
+
throw takeObject(r2);
|
|
140
|
+
}
|
|
141
|
+
deferred2_0 = ptr1;
|
|
142
|
+
deferred2_1 = len1;
|
|
143
|
+
return getStringFromWasm0(ptr1, len1);
|
|
144
|
+
} finally {
|
|
145
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
146
|
+
heap[stack_pointer++] = undefined;
|
|
147
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function __wbg_get_imports() {
|
|
151
|
+
const import0 = {
|
|
152
|
+
__proto__: null,
|
|
153
|
+
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
|
|
154
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
155
|
+
return addHeapObject(ret);
|
|
156
|
+
},
|
|
157
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
158
|
+
const ret = String(getObject(arg1));
|
|
159
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
160
|
+
const len1 = WASM_VECTOR_LEN;
|
|
161
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
162
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
163
|
+
},
|
|
164
|
+
__wbg___wbindgen_bigint_get_as_i64_a2383202b9353e4c: function(arg0, arg1) {
|
|
165
|
+
const v = getObject(arg1);
|
|
166
|
+
const ret = typeof(v) === 'bigint' ? v : undefined;
|
|
167
|
+
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
168
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
169
|
+
},
|
|
170
|
+
__wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
|
|
171
|
+
const v = getObject(arg0);
|
|
172
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
173
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
174
|
+
},
|
|
175
|
+
__wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
|
|
176
|
+
const ret = debugString(getObject(arg1));
|
|
177
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
178
|
+
const len1 = WASM_VECTOR_LEN;
|
|
179
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
180
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
181
|
+
},
|
|
182
|
+
__wbg___wbindgen_in_92f62ee1427d9e49: function(arg0, arg1) {
|
|
183
|
+
const ret = getObject(arg0) in getObject(arg1);
|
|
184
|
+
return ret;
|
|
185
|
+
},
|
|
186
|
+
__wbg___wbindgen_is_bigint_b123553bed3bb382: function(arg0) {
|
|
187
|
+
const ret = typeof(getObject(arg0)) === 'bigint';
|
|
188
|
+
return ret;
|
|
189
|
+
},
|
|
190
|
+
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
|
|
191
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
192
|
+
return ret;
|
|
193
|
+
},
|
|
194
|
+
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
|
|
195
|
+
const val = getObject(arg0);
|
|
196
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
197
|
+
return ret;
|
|
198
|
+
},
|
|
199
|
+
__wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
|
|
200
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
201
|
+
return ret;
|
|
202
|
+
},
|
|
203
|
+
__wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
|
|
204
|
+
const ret = getObject(arg0) === undefined;
|
|
205
|
+
return ret;
|
|
206
|
+
},
|
|
207
|
+
__wbg___wbindgen_jsval_eq_02babf21faa37971: function(arg0, arg1) {
|
|
208
|
+
const ret = getObject(arg0) === getObject(arg1);
|
|
209
|
+
return ret;
|
|
210
|
+
},
|
|
211
|
+
__wbg___wbindgen_jsval_loose_eq_677f21e468d6b461: function(arg0, arg1) {
|
|
212
|
+
const ret = getObject(arg0) == getObject(arg1);
|
|
213
|
+
return ret;
|
|
214
|
+
},
|
|
215
|
+
__wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
|
|
216
|
+
const obj = getObject(arg1);
|
|
217
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
218
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
219
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
220
|
+
},
|
|
221
|
+
__wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
|
|
222
|
+
const obj = getObject(arg1);
|
|
223
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
224
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
225
|
+
var len1 = WASM_VECTOR_LEN;
|
|
226
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
227
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
228
|
+
},
|
|
229
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
230
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
231
|
+
},
|
|
232
|
+
__wbg_call_6137034ef55c9d0f: function() { return handleError(function (arg0, arg1) {
|
|
233
|
+
const ret = getObject(arg0).call(getObject(arg1));
|
|
234
|
+
return addHeapObject(ret);
|
|
235
|
+
}, arguments); },
|
|
236
|
+
__wbg_done_b41a1d26cdb37fb6: function(arg0) {
|
|
237
|
+
const ret = getObject(arg0).done;
|
|
238
|
+
return ret;
|
|
239
|
+
},
|
|
240
|
+
__wbg_entries_fb6397112b1de25f: function(arg0) {
|
|
241
|
+
const ret = Object.entries(getObject(arg0));
|
|
242
|
+
return addHeapObject(ret);
|
|
243
|
+
},
|
|
244
|
+
__wbg_get_658f6698067d9515: function() { return handleError(function (arg0, arg1) {
|
|
245
|
+
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
|
246
|
+
return addHeapObject(ret);
|
|
247
|
+
}, arguments); },
|
|
248
|
+
__wbg_get_6c896e0571ddae51: function(arg0, arg1) {
|
|
249
|
+
const ret = getObject(arg0)[arg1 >>> 0];
|
|
250
|
+
return addHeapObject(ret);
|
|
251
|
+
},
|
|
252
|
+
__wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
|
|
253
|
+
const ret = getObject(arg0)[arg1 >>> 0];
|
|
254
|
+
return addHeapObject(ret);
|
|
255
|
+
},
|
|
256
|
+
__wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
|
|
257
|
+
const ret = getObject(arg0)[getObject(arg1)];
|
|
258
|
+
return addHeapObject(ret);
|
|
259
|
+
},
|
|
260
|
+
__wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
|
|
261
|
+
let result;
|
|
262
|
+
try {
|
|
263
|
+
result = getObject(arg0) instanceof ArrayBuffer;
|
|
264
|
+
} catch (_) {
|
|
265
|
+
result = false;
|
|
266
|
+
}
|
|
267
|
+
const ret = result;
|
|
268
|
+
return ret;
|
|
269
|
+
},
|
|
270
|
+
__wbg_instanceof_Map_b2611749102d7ba3: function(arg0) {
|
|
271
|
+
let result;
|
|
272
|
+
try {
|
|
273
|
+
result = getObject(arg0) instanceof Map;
|
|
274
|
+
} catch (_) {
|
|
275
|
+
result = false;
|
|
276
|
+
}
|
|
277
|
+
const ret = result;
|
|
278
|
+
return ret;
|
|
279
|
+
},
|
|
280
|
+
__wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
|
|
281
|
+
let result;
|
|
282
|
+
try {
|
|
283
|
+
result = getObject(arg0) instanceof Uint8Array;
|
|
284
|
+
} catch (_) {
|
|
285
|
+
result = false;
|
|
286
|
+
}
|
|
287
|
+
const ret = result;
|
|
288
|
+
return ret;
|
|
289
|
+
},
|
|
290
|
+
__wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
|
|
291
|
+
const ret = Array.isArray(getObject(arg0));
|
|
292
|
+
return ret;
|
|
293
|
+
},
|
|
294
|
+
__wbg_isSafeInteger_717808ad6a54bd9e: function(arg0) {
|
|
295
|
+
const ret = Number.isSafeInteger(getObject(arg0));
|
|
296
|
+
return ret;
|
|
297
|
+
},
|
|
298
|
+
__wbg_iterator_e3c31c892080e444: function() {
|
|
299
|
+
const ret = Symbol.iterator;
|
|
300
|
+
return addHeapObject(ret);
|
|
301
|
+
},
|
|
302
|
+
__wbg_length_7f3c00c40364105e: function(arg0) {
|
|
303
|
+
const ret = getObject(arg0).length;
|
|
304
|
+
return ret;
|
|
305
|
+
},
|
|
306
|
+
__wbg_length_d4bdea10311bd9cf: function(arg0) {
|
|
307
|
+
const ret = getObject(arg0).length;
|
|
308
|
+
return ret;
|
|
309
|
+
},
|
|
310
|
+
__wbg_new_1dbf7428bba60a42: function(arg0) {
|
|
311
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
312
|
+
return addHeapObject(ret);
|
|
313
|
+
},
|
|
314
|
+
__wbg_new_617a8cdb8bb1130e: function() {
|
|
315
|
+
const ret = new Object();
|
|
316
|
+
return addHeapObject(ret);
|
|
317
|
+
},
|
|
318
|
+
__wbg_new_ee2291f50781bf1d: function() {
|
|
319
|
+
const ret = new Array();
|
|
320
|
+
return addHeapObject(ret);
|
|
321
|
+
},
|
|
322
|
+
__wbg_next_33784799010f1bbe: function(arg0) {
|
|
323
|
+
const ret = getObject(arg0).next;
|
|
324
|
+
return addHeapObject(ret);
|
|
325
|
+
},
|
|
326
|
+
__wbg_next_f4aac29c42af995c: function() { return handleError(function (arg0) {
|
|
327
|
+
const ret = getObject(arg0).next();
|
|
328
|
+
return addHeapObject(ret);
|
|
329
|
+
}, arguments); },
|
|
330
|
+
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
|
|
331
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
332
|
+
},
|
|
333
|
+
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
334
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
335
|
+
},
|
|
336
|
+
__wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
|
|
337
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
338
|
+
},
|
|
339
|
+
__wbg_value_f3c585ee8f5ba40c: function(arg0) {
|
|
340
|
+
const ret = getObject(arg0).value;
|
|
341
|
+
return addHeapObject(ret);
|
|
342
|
+
},
|
|
343
|
+
__wbindgen_generic_0000000000000001: function(arg0) {
|
|
344
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
345
|
+
const ret = arg0;
|
|
346
|
+
return addHeapObject(ret);
|
|
347
|
+
},
|
|
348
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
349
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
350
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
351
|
+
return addHeapObject(ret);
|
|
352
|
+
},
|
|
353
|
+
__wbindgen_generic_0000000000000003: function(arg0) {
|
|
354
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
355
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
356
|
+
return addHeapObject(ret);
|
|
357
|
+
},
|
|
358
|
+
__wbindgen_object_clone_ref: function(arg0) {
|
|
359
|
+
const ret = getObject(arg0);
|
|
360
|
+
return addHeapObject(ret);
|
|
361
|
+
},
|
|
362
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
363
|
+
takeObject(arg0);
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
return {
|
|
367
|
+
__proto__: null,
|
|
368
|
+
"./todo_core_bg.js": import0,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function addHeapObject(obj) {
|
|
373
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
374
|
+
const idx = heap_next;
|
|
375
|
+
heap_next = heap[idx];
|
|
376
|
+
|
|
377
|
+
heap[idx] = obj;
|
|
378
|
+
return idx;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function addBorrowedObject(obj) {
|
|
382
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
383
|
+
heap[--stack_pointer] = obj;
|
|
384
|
+
return stack_pointer;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function debugString(val) {
|
|
388
|
+
// primitive types
|
|
389
|
+
const type = typeof val;
|
|
390
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
391
|
+
return `${val}`;
|
|
392
|
+
}
|
|
393
|
+
if (type == 'string') {
|
|
394
|
+
return `"${val}"`;
|
|
395
|
+
}
|
|
396
|
+
if (type == 'symbol') {
|
|
397
|
+
const description = val.description;
|
|
398
|
+
if (description == null) {
|
|
399
|
+
return 'Symbol';
|
|
400
|
+
} else {
|
|
401
|
+
return `Symbol(${description})`;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (type == 'function') {
|
|
405
|
+
const name = val.name;
|
|
406
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
407
|
+
return `Function(${name})`;
|
|
408
|
+
} else {
|
|
409
|
+
return 'Function';
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// objects
|
|
413
|
+
if (Array.isArray(val)) {
|
|
414
|
+
const length = val.length;
|
|
415
|
+
let debug = '[';
|
|
416
|
+
if (length > 0) {
|
|
417
|
+
debug += debugString(val[0]);
|
|
418
|
+
}
|
|
419
|
+
for(let i = 1; i < length; i++) {
|
|
420
|
+
debug += ', ' + debugString(val[i]);
|
|
421
|
+
}
|
|
422
|
+
debug += ']';
|
|
423
|
+
return debug;
|
|
424
|
+
}
|
|
425
|
+
// Test for built-in
|
|
426
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
427
|
+
let className;
|
|
428
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
429
|
+
className = builtInMatches[1];
|
|
430
|
+
} else {
|
|
431
|
+
// Failed to match the standard '[object ClassName]'
|
|
432
|
+
return toString.call(val);
|
|
433
|
+
}
|
|
434
|
+
if (className == 'Object') {
|
|
435
|
+
// we're a user defined class or Object
|
|
436
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
437
|
+
// easier than looping through ownProperties of `val`.
|
|
438
|
+
try {
|
|
439
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
440
|
+
} catch (_) {
|
|
441
|
+
return 'Object';
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
// errors
|
|
445
|
+
if (val instanceof Error) {
|
|
446
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
447
|
+
}
|
|
448
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
449
|
+
return className;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function dropObject(idx) {
|
|
453
|
+
if (idx < 1028) return;
|
|
454
|
+
heap[idx] = heap_next;
|
|
455
|
+
heap_next = idx;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
459
|
+
ptr = ptr >>> 0;
|
|
460
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
let cachedDataViewMemory0 = null;
|
|
464
|
+
function getDataViewMemory0() {
|
|
465
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
466
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
467
|
+
}
|
|
468
|
+
return cachedDataViewMemory0;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function getStringFromWasm0(ptr, len) {
|
|
472
|
+
return decodeText(ptr >>> 0, len);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
let cachedUint8ArrayMemory0 = null;
|
|
476
|
+
function getUint8ArrayMemory0() {
|
|
477
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
478
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
479
|
+
}
|
|
480
|
+
return cachedUint8ArrayMemory0;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function getObject(idx) { return heap[idx]; }
|
|
484
|
+
|
|
485
|
+
function handleError(f, args) {
|
|
486
|
+
try {
|
|
487
|
+
return f.apply(this, args);
|
|
488
|
+
} catch (e) {
|
|
489
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
let heap = new Array(1024).fill(undefined);
|
|
494
|
+
heap.push(undefined, null, true, false);
|
|
495
|
+
|
|
496
|
+
let heap_next = heap.length;
|
|
497
|
+
|
|
498
|
+
function isLikeNone(x) {
|
|
499
|
+
return x === undefined || x === null;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function passArrayJsValueToWasm0(array, malloc) {
|
|
503
|
+
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
504
|
+
const mem = getDataViewMemory0();
|
|
505
|
+
for (let i = 0; i < array.length; i++) {
|
|
506
|
+
mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
|
|
507
|
+
}
|
|
508
|
+
WASM_VECTOR_LEN = array.length;
|
|
509
|
+
return ptr;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
513
|
+
if (realloc === undefined) {
|
|
514
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
515
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
516
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
517
|
+
WASM_VECTOR_LEN = buf.length;
|
|
518
|
+
return ptr;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
let len = arg.length;
|
|
522
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
523
|
+
|
|
524
|
+
const mem = getUint8ArrayMemory0();
|
|
525
|
+
|
|
526
|
+
let offset = 0;
|
|
527
|
+
|
|
528
|
+
for (; offset < len; offset++) {
|
|
529
|
+
const code = arg.charCodeAt(offset);
|
|
530
|
+
if (code > 0x7F) break;
|
|
531
|
+
mem[ptr + offset] = code;
|
|
532
|
+
}
|
|
533
|
+
if (offset !== len) {
|
|
534
|
+
if (offset !== 0) {
|
|
535
|
+
arg = arg.slice(offset);
|
|
536
|
+
}
|
|
537
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
538
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
539
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
540
|
+
|
|
541
|
+
offset += ret.written;
|
|
542
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
WASM_VECTOR_LEN = offset;
|
|
546
|
+
return ptr;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
let stack_pointer = 1024;
|
|
550
|
+
|
|
551
|
+
function takeObject(idx) {
|
|
552
|
+
const ret = getObject(idx);
|
|
553
|
+
dropObject(idx);
|
|
554
|
+
return ret;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
558
|
+
cachedTextDecoder.decode();
|
|
559
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
560
|
+
let numBytesDecoded = 0;
|
|
561
|
+
function decodeText(ptr, len) {
|
|
562
|
+
numBytesDecoded += len;
|
|
563
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
564
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
565
|
+
cachedTextDecoder.decode();
|
|
566
|
+
numBytesDecoded = len;
|
|
567
|
+
}
|
|
568
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const cachedTextEncoder = new TextEncoder();
|
|
572
|
+
|
|
573
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
574
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
575
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
576
|
+
view.set(buf);
|
|
577
|
+
return {
|
|
578
|
+
read: arg.length,
|
|
579
|
+
written: buf.length
|
|
580
|
+
};
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
let WASM_VECTOR_LEN = 0;
|
|
585
|
+
|
|
586
|
+
let wasmModule, wasmInstance, wasm;
|
|
587
|
+
function __wbg_finalize_init(instance, module) {
|
|
588
|
+
wasmInstance = instance;
|
|
589
|
+
wasm = instance.exports;
|
|
590
|
+
wasmModule = module;
|
|
591
|
+
cachedDataViewMemory0 = null;
|
|
592
|
+
cachedUint8ArrayMemory0 = null;
|
|
593
|
+
return wasm;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
async function __wbg_load(module, imports) {
|
|
597
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
598
|
+
if (!module.ok) {
|
|
599
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
603
|
+
try {
|
|
604
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
605
|
+
} catch (e) {
|
|
606
|
+
const validResponse = expectedResponseType(module.type);
|
|
607
|
+
|
|
608
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
609
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
610
|
+
|
|
611
|
+
} else { throw e; }
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const bytes = await module.arrayBuffer();
|
|
616
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
617
|
+
} else {
|
|
618
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
619
|
+
|
|
620
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
621
|
+
return { instance, module };
|
|
622
|
+
} else {
|
|
623
|
+
return instance;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function expectedResponseType(type) {
|
|
628
|
+
switch (type) {
|
|
629
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
630
|
+
}
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function initSync(module) {
|
|
636
|
+
if (wasm !== undefined) return wasm;
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
if (module !== undefined) {
|
|
640
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
641
|
+
({module} = module)
|
|
642
|
+
} else {
|
|
643
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const imports = __wbg_get_imports();
|
|
648
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
649
|
+
module = new WebAssembly.Module(module);
|
|
650
|
+
}
|
|
651
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
652
|
+
return __wbg_finalize_init(instance, module);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
async function __wbg_init(module_or_path) {
|
|
656
|
+
if (wasm !== undefined) return wasm;
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
if (module_or_path !== undefined) {
|
|
660
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
661
|
+
({module_or_path} = module_or_path)
|
|
662
|
+
} else {
|
|
663
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (module_or_path === undefined) {
|
|
668
|
+
module_or_path = new URL('todo_core_bg.wasm', import.meta.url);
|
|
669
|
+
}
|
|
670
|
+
const imports = __wbg_get_imports();
|
|
671
|
+
|
|
672
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
673
|
+
module_or_path = fetch(module_or_path);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
677
|
+
|
|
678
|
+
return __wbg_finalize_init(instance, module);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const apply: (a: number, b: number, c: number) => void;
|
|
5
|
+
export const completion_reminder: (a: number, b: number) => void;
|
|
6
|
+
export const init: (a: number, b: number, c: number) => void;
|
|
7
|
+
export const parse: (a: number, b: number) => void;
|
|
8
|
+
export const view: (a: number, b: number) => void;
|
|
9
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
10
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
11
|
+
export const __wbindgen_export3: (a: number) => void;
|
|
12
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
13
|
+
export const __wbindgen_export4: (a: number, b: number, c: number) => void;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ownsTodo, replay, settle, show, start } from "./lifecycle.ts";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
4
|
+
import { Type } from "typebox";
|
|
5
|
+
import { runTodo } from "./tool.ts";
|
|
6
|
+
|
|
7
|
+
type TodoAPI = Readonly<
|
|
8
|
+
Pick<ExtensionAPI, "appendEntry" | "getAllTools" | "on" | "registerCommand" | "registerTool">
|
|
9
|
+
>;
|
|
10
|
+
|
|
11
|
+
const items = Type.Immutable(
|
|
12
|
+
Type.Array(Type.String(), { description: "For init or append: tasks, in order." }),
|
|
13
|
+
),
|
|
14
|
+
parameters = Type.Object({
|
|
15
|
+
items: Type.Optional(items),
|
|
16
|
+
op: StringEnum(["init", "start", "done", "drop", "append", "view"] as const, {
|
|
17
|
+
description:
|
|
18
|
+
"init replaces; start selects; done completes; drop abandons; append adds; view reads.",
|
|
19
|
+
}),
|
|
20
|
+
task: Type.Optional(
|
|
21
|
+
Type.String({ description: "Exact task content. Omit for done/drop to close all tasks." }),
|
|
22
|
+
),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Registers the branch-backed `todo` tool and its completion reminder.
|
|
27
|
+
* @param {TodoAPI} pi The extension API methods used here.
|
|
28
|
+
*/
|
|
29
|
+
export default function piTodo(pi: TodoAPI): void {
|
|
30
|
+
pi.registerTool({
|
|
31
|
+
description:
|
|
32
|
+
"Keep the session todo list. Tasks are addressed by their exact content. One task is active; the next open task starts when it closes.",
|
|
33
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
34
|
+
const result = runTodo(params, {
|
|
35
|
+
append: (customType, list) => {
|
|
36
|
+
pi.appendEntry(customType, list);
|
|
37
|
+
},
|
|
38
|
+
branch: () => ctx.sessionManager.getBranch(),
|
|
39
|
+
});
|
|
40
|
+
replay(ctx);
|
|
41
|
+
return result;
|
|
42
|
+
},
|
|
43
|
+
executionMode: "sequential",
|
|
44
|
+
label: "Todo",
|
|
45
|
+
name: "todo",
|
|
46
|
+
parameters,
|
|
47
|
+
});
|
|
48
|
+
pi.on("session_start", (_event, ctx) => {
|
|
49
|
+
start(pi, ctx);
|
|
50
|
+
});
|
|
51
|
+
pi.on("session_tree", (_event, ctx) => {
|
|
52
|
+
if (ownsTodo(pi)) {
|
|
53
|
+
replay(ctx);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
pi.on("agent_before_settle", (event, ctx) => settle(pi, event, ctx));
|
|
57
|
+
pi.registerCommand("todos", {
|
|
58
|
+
description: "Show the todo list on this session branch.",
|
|
59
|
+
async handler(_args, ctx) {
|
|
60
|
+
show(ctx);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
package/src/lifecycle.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BoundaryResult,
|
|
3
|
+
ExtensionUIContext,
|
|
4
|
+
SessionBoundaryDraft,
|
|
5
|
+
SessionEntry,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { REMINDER_ENTRY, reminder } from "./reminder.ts";
|
|
8
|
+
import { parse, view } from "./wasm.ts";
|
|
9
|
+
import { isOwnSource } from "./source.ts";
|
|
10
|
+
import { latestSnapshot } from "./state.ts";
|
|
11
|
+
|
|
12
|
+
interface TodoContext {
|
|
13
|
+
readonly sessionManager: { readonly getBranch: () => readonly SessionEntry[] };
|
|
14
|
+
readonly ui: Readonly<Pick<ExtensionUIContext, "notify" | "setWidget">>;
|
|
15
|
+
}
|
|
16
|
+
interface SettleEvent {
|
|
17
|
+
readonly outcome: "completed" | "aborted" | "error";
|
|
18
|
+
readonly continue: boolean;
|
|
19
|
+
readonly context: { readonly canContinue: boolean };
|
|
20
|
+
readonly entries: readonly SessionBoundaryDraft[];
|
|
21
|
+
}
|
|
22
|
+
interface TodoHost {
|
|
23
|
+
readonly getAllTools: () => readonly {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly sourceInfo: { readonly path: string };
|
|
26
|
+
}[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether this source owns the todo registration.
|
|
31
|
+
* @param {TodoHost} pi Tool metadata reader.
|
|
32
|
+
* @returns {boolean} Whether this source won.
|
|
33
|
+
*/
|
|
34
|
+
const ownsTodo = (pi: TodoHost): boolean =>
|
|
35
|
+
pi.getAllTools().some((tool) => tool.name === "todo" && isOwnSource(tool.sourceInfo.path)),
|
|
36
|
+
/**
|
|
37
|
+
* Renders the selected branch snapshot.
|
|
38
|
+
* @param {TodoContext} ctx Branch and UI methods.
|
|
39
|
+
*/
|
|
40
|
+
replay = (ctx: TodoContext): void => {
|
|
41
|
+
const list = parse(latestSnapshot(ctx.sessionManager.getBranch()));
|
|
42
|
+
ctx.ui.setWidget("pi-todo", view(list).split("\n"));
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* Applies the completion decision at pi's final actionable boundary.
|
|
46
|
+
* @param {TodoHost} pi Tool metadata reader.
|
|
47
|
+
* @param {SettleEvent} event The boundary facts.
|
|
48
|
+
* @param {TodoContext} ctx Branch and UI methods.
|
|
49
|
+
* @returns {BoundaryResult} The unchanged boundary or an added hidden reminder.
|
|
50
|
+
*/
|
|
51
|
+
settle = (pi: TodoHost, event: SettleEvent, ctx: TodoContext): BoundaryResult => {
|
|
52
|
+
if (event.outcome !== "completed" || event.continue || !ownsTodo(pi)) {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
const content = reminder(ctx.sessionManager.getBranch(), event.entries);
|
|
56
|
+
return typeof content === "string"
|
|
57
|
+
? {
|
|
58
|
+
continue: true,
|
|
59
|
+
entries: [
|
|
60
|
+
...event.entries,
|
|
61
|
+
{ content, customType: REMINDER_ENTRY, display: false, type: "custom_message" },
|
|
62
|
+
],
|
|
63
|
+
}
|
|
64
|
+
: {};
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Prints the branch list for /todos.
|
|
68
|
+
* @param {TodoContext} ctx Branch and UI methods.
|
|
69
|
+
*/
|
|
70
|
+
show = (ctx: TodoContext): void => {
|
|
71
|
+
const list = parse(latestSnapshot(ctx.sessionManager.getBranch()));
|
|
72
|
+
ctx.ui.notify(view(list), "info");
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Replays or reports the winning source at startup.
|
|
76
|
+
* @param {TodoHost} pi Tool metadata reader.
|
|
77
|
+
* @param {TodoContext} ctx Branch and UI methods.
|
|
78
|
+
*/
|
|
79
|
+
start = (pi: TodoHost, ctx: TodoContext): void => {
|
|
80
|
+
if (ownsTodo(pi)) {
|
|
81
|
+
replay(ctx);
|
|
82
|
+
} else {
|
|
83
|
+
const owner = pi.getAllTools().find((tool) => tool.name === "todo"),
|
|
84
|
+
source = owner ? owner.sourceInfo.path : "another source";
|
|
85
|
+
ctx.ui.notify(`pi-todo is inactive: todo belongs to ${source}.`, "warning");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { ownsTodo, replay, settle, show, start };
|
|
90
|
+
export type { SettleEvent, TodoContext, TodoHost };
|
package/src/reminder.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SessionBoundaryDraft, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { completionReminder, parse } from "./wasm.ts";
|
|
3
|
+
import type { ReminderFact } from "./wasm.ts";
|
|
4
|
+
import { STATE_ENTRY } from "./state.ts";
|
|
5
|
+
|
|
6
|
+
const REMINDER_ENTRY = "todo-reminder",
|
|
7
|
+
/**
|
|
8
|
+
* Projects pi's branch and boundary drafts into core-owned reminder facts.
|
|
9
|
+
* @param {readonly SessionEntry[]} branch Persisted branch entries.
|
|
10
|
+
* @param {readonly SessionBoundaryDraft[]} drafts Proposed boundary entries.
|
|
11
|
+
* @returns {string | undefined} The next reminder, when permitted.
|
|
12
|
+
*/
|
|
13
|
+
reminder = (
|
|
14
|
+
branch: readonly SessionEntry[],
|
|
15
|
+
drafts: readonly SessionBoundaryDraft[],
|
|
16
|
+
): string | undefined => {
|
|
17
|
+
const facts: ReminderFact[] = [];
|
|
18
|
+
for (const entry of [...branch, ...drafts]) {
|
|
19
|
+
if (entry.type === "message" && entry.message.role === "user") {
|
|
20
|
+
facts.push({ kind: "user" });
|
|
21
|
+
} else if (entry.type === "custom" && entry.customType === STATE_ENTRY) {
|
|
22
|
+
facts.push({ kind: "snapshot", list: parse(entry.data) });
|
|
23
|
+
} else if (entry.type === "custom_message" && entry.customType === REMINDER_ENTRY) {
|
|
24
|
+
facts.push({ kind: "reminder" });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return completionReminder({ facts });
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { REMINDER_ENTRY, reminder };
|
package/src/source.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Which file registered a tool. pi reports a tool's `sourceInfo.path` as the
|
|
3
|
+
* path it was configured with, but `import.meta.url` names the module's real
|
|
4
|
+
* path. The two differ when the path has a symlink, such as macOS `/tmp` or a
|
|
5
|
+
* linked agent directory, so both are compared after resolving symlinks.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
8
|
+
|
|
9
|
+
const OWN = realpathSync(new URL("index.ts", import.meta.url)),
|
|
10
|
+
/**
|
|
11
|
+
* Whether `path` is this package's extension entry. A path that does not
|
|
12
|
+
* exist, such as a synthetic source, cannot be this file.
|
|
13
|
+
* @param {string} path A tool's `sourceInfo.path`.
|
|
14
|
+
* @returns {boolean} Whether the file is this package's `index.ts`.
|
|
15
|
+
*/
|
|
16
|
+
isOwnSource = (path: string): boolean => existsSync(path) && realpathSync(path) === OWN;
|
|
17
|
+
|
|
18
|
+
export { isOwnSource };
|
package/src/state.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CustomEntry, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
/** The snapshot of a branch with no list yet. */
|
|
4
|
+
const EMPTY: unknown = { tasks: [] },
|
|
5
|
+
/** The custom entry that holds the list after every change. */
|
|
6
|
+
STATE_ENTRY = "todo-state",
|
|
7
|
+
/**
|
|
8
|
+
* Whether `entry` is a stored list.
|
|
9
|
+
* @param {SessionEntry} entry A branch entry.
|
|
10
|
+
* @returns {boolean} True for a `todo-state` custom entry.
|
|
11
|
+
*/
|
|
12
|
+
isStateEntry = (entry: SessionEntry): entry is CustomEntry =>
|
|
13
|
+
entry.type === "custom" && entry.customType === STATE_ENTRY,
|
|
14
|
+
/**
|
|
15
|
+
* The latest stored snapshot on the branch, unvalidated: the core validates it.
|
|
16
|
+
* @param {readonly SessionEntry[]} branch The session branch, oldest entry first.
|
|
17
|
+
* @returns {unknown} The latest snapshot, or an empty list when there is none.
|
|
18
|
+
*/
|
|
19
|
+
latestSnapshot = (branch: readonly SessionEntry[]): unknown => {
|
|
20
|
+
for (const entry of branch.toReversed()) {
|
|
21
|
+
if (isStateEntry(entry)) {
|
|
22
|
+
return entry.data;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return EMPTY;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { STATE_ENTRY, latestSnapshot };
|
package/src/tool.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { STATE_ENTRY, latestSnapshot } from "./state.ts";
|
|
2
|
+
import { apply, parse, view } from "./wasm.ts";
|
|
3
|
+
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import type { TodoList } from "./wasm.ts";
|
|
5
|
+
|
|
6
|
+
/** One `todo` call, as the schema in `index.ts` admits it. */
|
|
7
|
+
interface TodoParams {
|
|
8
|
+
readonly op: "init" | "start" | "done" | "drop" | "append" | "view";
|
|
9
|
+
readonly items?: readonly string[];
|
|
10
|
+
readonly task?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** What a call reads from and writes to the session. */
|
|
14
|
+
interface TodoSession {
|
|
15
|
+
readonly branch: () => readonly SessionEntry[];
|
|
16
|
+
readonly append: (customType: string, list: TodoList) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The tool result: the summary for the model and the list for rendering. */
|
|
20
|
+
interface TodoResult {
|
|
21
|
+
readonly content: [{ readonly type: "text"; readonly text: string }];
|
|
22
|
+
readonly details: TodoList;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The result for `list`.
|
|
27
|
+
* @param {TodoList} list A valid list.
|
|
28
|
+
* @returns {TodoResult} The summary and the list.
|
|
29
|
+
*/
|
|
30
|
+
const result = (list: TodoList): TodoResult => ({
|
|
31
|
+
content: [{ text: view(list), type: "text" }],
|
|
32
|
+
details: list,
|
|
33
|
+
}),
|
|
34
|
+
/**
|
|
35
|
+
* Runs one call. A rejected operation throws the core's message, so pi marks
|
|
36
|
+
* the result failed, and nothing is stored.
|
|
37
|
+
* @param {TodoParams} params The validated tool arguments.
|
|
38
|
+
* @param {TodoSession} session The branch to read and the entry writer.
|
|
39
|
+
* @returns {TodoResult} The result for the model and the renderer.
|
|
40
|
+
*/
|
|
41
|
+
runTodo = (params: TodoParams, session: TodoSession): TodoResult => {
|
|
42
|
+
const current = parse(latestSnapshot(session.branch())),
|
|
43
|
+
{ list, persist } = apply(current, {
|
|
44
|
+
items: params.items ? [...params.items] : params.items,
|
|
45
|
+
op: params.op,
|
|
46
|
+
task: params.task,
|
|
47
|
+
});
|
|
48
|
+
if (persist) {
|
|
49
|
+
session.append(STATE_ENTRY, list);
|
|
50
|
+
}
|
|
51
|
+
return result(list);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { runTodo };
|
|
55
|
+
export type { TodoParams, TodoResult, TodoSession };
|
package/src/wasm.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Loads the Rust core. The `wasm-bindgen --target web` loader fetches its
|
|
3
|
+
* `.wasm` by URL, and Node's fetch rejects `file:` URLs, so the bytes are read
|
|
4
|
+
* from disk and instantiated synchronously, as pi-mcp-adapter does
|
|
5
|
+
* (`mcp-script-wasm.ts`). The extension factory is synchronous, so the core
|
|
6
|
+
* must be ready before it returns. An importer of this module runs after this
|
|
7
|
+
* body, so the re-exports below are always initialized.
|
|
8
|
+
*/
|
|
9
|
+
import { initSync } from "./generated/todo_core.js";
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
|
|
12
|
+
initSync({
|
|
13
|
+
module: readFileSync(new URL("generated/todo_core_bg.wasm", import.meta.url)),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
apply,
|
|
18
|
+
completion_reminder as completionReminder,
|
|
19
|
+
init,
|
|
20
|
+
parse,
|
|
21
|
+
view,
|
|
22
|
+
} from "./generated/todo_core.js";
|
|
23
|
+
export type {
|
|
24
|
+
Operation,
|
|
25
|
+
ReminderFact,
|
|
26
|
+
Request,
|
|
27
|
+
Status,
|
|
28
|
+
Task,
|
|
29
|
+
TodoList,
|
|
30
|
+
} from "./generated/todo_core.js";
|