opencode-self-improvement 0.14.27 → 0.14.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/host.ts +9 -5
- package/src/index.ts +2 -0
- package/src/viewer/server.ts +19 -2
package/README.md
CHANGED
|
@@ -90,6 +90,7 @@ What is established, from tests and fixtures (no live store involved):
|
|
|
90
90
|
|
|
91
91
|
- **The trigger events are ones the host actually emits.** Capture subscribes to `session.execution.succeeded` and `session.execution.interrupted`, the two turn-end events present in a recording of the desktop service (`test/fixtures/host-events.jsonl`). `session.idle`, `session.status` and `session.execution.failed` are *declared* by the host but absent from that recording, so they deliberately do not trigger capture; `test/event-fidelity.test.ts` refuses a trigger that is only declared. An earlier revision subscribed to `session.idle` and stayed silent for days with no signal — reading a declared event as an emitted one is the failure that fixture exists to prevent.
|
|
92
92
|
- **The path runs under simulated host traffic** — unit tests hand the plugin the recorded envelopes and assert a candidate lands through the write gate, including conservation (a near-duplicate collapses at the gate instead of writing a second row): `test/capture.test.ts`, `test/capture-compaction.test.ts`. No terminal e2e scenario covers the trigger, so the simulated envelope is the strongest evidence that exists — and fabricating the envelope is exactly what passed while this feature was dead.
|
|
93
|
+
- **Identity triggers have their own recording check.** `test/event-fidelity.test.ts` checks `IDENTITY_EVENT_TYPES` against the original 2.1.4 recording plus `test/fixtures/host-session-move.json`, a normalized one-frame extract from a separate 2.2.2 move capture. The extract must declare nonempty provenance and its retained envelopes must round-trip through the lockfile-pinned `@opencode/schema` 2.0.32 decoder. These checks reject missing metadata and malformed envelopes; they do not authenticate the capture. The identity replay uses the plugin subscription, but live plugin rebinding remains unverified. The recording version is distinct from the CI host pin (2.0.26).
|
|
93
94
|
|
|
94
95
|
What is not established:
|
|
95
96
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.28",
|
|
4
4
|
"description": "Durable memory for opencode: remember facts, decisions, and commands across sessions, plus a one-command per-repo setup (/repo-init).",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"exports": {
|
package/src/host.ts
CHANGED
|
@@ -23,14 +23,18 @@ export interface SessionIdentity {
|
|
|
23
23
|
directory?: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// Shared with the recording-backed fidelity checks. Adding a trigger requires
|
|
27
|
+
// both a protocol declaration and an observation from a live host.
|
|
28
|
+
export const IDENTITY_EVENT_TYPES: readonly string[] = Object.freeze([
|
|
29
|
+
"session.created",
|
|
30
|
+
"session.execution.started",
|
|
31
|
+
"session.moved",
|
|
32
|
+
]);
|
|
33
|
+
|
|
26
34
|
/** A directory-less identity still lets the caller resolve the session row. */
|
|
27
35
|
export function sessionIdentityEvent(raw: unknown): SessionIdentity | undefined {
|
|
28
36
|
const event = fields(raw);
|
|
29
|
-
if (
|
|
30
|
-
event.type !== "session.created" &&
|
|
31
|
-
event.type !== "session.execution.started" &&
|
|
32
|
-
event.type !== "session.moved"
|
|
33
|
-
) return undefined;
|
|
37
|
+
if (typeof event.type !== "string" || !IDENTITY_EVENT_TYPES.includes(event.type)) return undefined;
|
|
34
38
|
const data = fields(event.data ?? event.properties);
|
|
35
39
|
const info = fields(data.info ?? data);
|
|
36
40
|
const sessionID = info.sessionID ?? data.sessionID;
|
package/src/index.ts
CHANGED
|
@@ -220,6 +220,8 @@ export function resetCaptureCooldowns(): void {
|
|
|
220
220
|
// test/event-fidelity.test.ts requires every trigger to appear in both that
|
|
221
221
|
// recording and the installed @opencode/schema manifest: a declared event
|
|
222
222
|
// alone is insufficient evidence that the host emits it (#78, #136).
|
|
223
|
+
// Identity triggers have a separate observed check in that test, combining
|
|
224
|
+
// this recording with the 2.2.2 move extract in host-session-move.json (#176).
|
|
223
225
|
export const TURN_END_EVENTS = ["session.execution.succeeded", "session.execution.interrupted"] as const;
|
|
224
226
|
|
|
225
227
|
/** Every event type the capture subscription reacts to (fidelity-tested). */
|
package/src/viewer/server.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Memory Viewer server. Bundled with the plugin: run `bun memory-view` (or
|
|
2
2
|
// `bun run src/viewer/server.ts`) from the repo root and open the printed URL.
|
|
3
|
-
//
|
|
3
|
+
// Defaults to 127.0.0.1 — the memory store is local, personal data. All reads go
|
|
4
4
|
// through the same loadAll() used by recall/inject (so blocked entries are
|
|
5
5
|
// hidden), and all mutations are non-destructive (snapshot + audit + supersede).
|
|
6
6
|
// I2: serves only file data; never writes into any repo.
|
|
7
7
|
import { basename, join } from "node:path";
|
|
8
|
+
import { isIP } from "node:net";
|
|
8
9
|
import { serve, type Server } from "bun";
|
|
9
10
|
import { z, type ZodTypeAny } from "zod";
|
|
10
11
|
import { BlockBody, DeleteBody, EditBody, RestoreEntryBody, UnblockBody, UnrejectBody } from "../schema.ts";
|
|
@@ -59,6 +60,18 @@ function allowedHostnames(): Set<string> {
|
|
|
59
60
|
return new Set(names);
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
function isLoopbackHostname(name: string): boolean {
|
|
64
|
+
// allowedHostnames supplies trimmed, lower-cased names (IPv6 bracketed).
|
|
65
|
+
const host = name.replace(/^\[|\]$/g, "");
|
|
66
|
+
if (host === "localhost") return true;
|
|
67
|
+
if (isIP(host) === 4) return host.startsWith("127.");
|
|
68
|
+
// Closed spellings only: URL parsing throws on IPv6 zone ids. Ambiguous
|
|
69
|
+
// aliases (including abbreviated IPv4) conservatively trigger the warning.
|
|
70
|
+
return host === "::1" || host === "0:0:0:0:0:0:0:1";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const EXPOSURE_WARNING = "[memory-viewer] WARNING: non-loopback hosts are allowed. The viewer serves private memory over plain HTTP without authentication; anyone who can reach it with an allowed Host can read or modify the store. Use only on a network you trust.";
|
|
74
|
+
|
|
62
75
|
function rejectRequest(req: Request, url: URL, port: number): Response | null {
|
|
63
76
|
if (!allowedHostnames().has(url.hostname) || (url.port || "80") !== String(port)) {
|
|
64
77
|
return error("unexpected Host header", 403);
|
|
@@ -171,6 +184,10 @@ export async function startViewer(port: number = PORT): Promise<ViewerServer> {
|
|
|
171
184
|
},
|
|
172
185
|
});
|
|
173
186
|
const bound = server.port ?? port;
|
|
187
|
+
// Warn after binding; wildcard binds (0.0.0.0 and ::) are non-loopback too.
|
|
188
|
+
if ([...allowedHostnames()].some((host) => !isLoopbackHostname(host))) {
|
|
189
|
+
console.warn(EXPOSURE_WARNING);
|
|
190
|
+
}
|
|
174
191
|
return { server, url: `http://${HOST}:${bound}/` };
|
|
175
192
|
}
|
|
176
193
|
|
|
@@ -325,6 +342,6 @@ async function restoreRoute(body: Record<string, unknown>): Promise<Response> {
|
|
|
325
342
|
|
|
326
343
|
if (import.meta.main) {
|
|
327
344
|
startViewer(PORT).then(({ url }) => {
|
|
328
|
-
console.log(`\nMemory Viewer: ${url}\n(
|
|
345
|
+
console.log(`\nMemory Viewer: ${url}\n(snapshot+audit are mandatory on every edit/delete)`);
|
|
329
346
|
});
|
|
330
347
|
}
|