opencode-self-improvement 0.15.12 → 0.15.14
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 +2 -0
- package/package.json +1 -1
- package/src/capture/runtime.ts +271 -0
- package/src/core/hooks.ts +9 -0
- package/src/core/host.ts +34 -0
- package/src/events.ts +223 -0
- package/src/identity/session-context.ts +150 -0
- package/src/index.ts +24 -621
- package/src/store/model/visibility.ts +24 -7
- package/src/tools/forget.ts +6 -1
- package/src/tools/merge-review.ts +7 -1
- package/src/tools/undo.ts +7 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// visibility
|
|
2
|
-
import {
|
|
1
|
+
// Repository visibility, shared by memory rows, restore lines, and evidence.
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { normalizeDirPath, repoScopeFor, sessionScope, type RepoScope } from "../../identity/repokey.ts";
|
|
3
4
|
import { getCurrent } from "../../core/state.ts";
|
|
4
5
|
import { parseLine } from "../../core/logfmt/format.ts";
|
|
5
6
|
import { prune } from "../files/prune.ts";
|
|
@@ -60,6 +61,25 @@ export function readerFromSid(sid?: unknown): Reader {
|
|
|
60
61
|
: readerForAmbient();
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
// Before #109, path-derived keys on win32/darwin hashed the whole canonical
|
|
65
|
+
// path in lowercase, even on case-sensitive volumes. Such a key can equal a
|
|
66
|
+
// distinct lowercase sibling's current key (#254). The stored path identifies
|
|
67
|
+
// these legacy stamps without a migration: require the same directory, allowing
|
|
68
|
+
// real symlink/case-insensitive aliases, instead of trusting that key alone.
|
|
69
|
+
// Remote-derived keys still share across clones with different paths. A stamp
|
|
70
|
+
// without repoPath cannot be classified this way and keeps key-only matching.
|
|
71
|
+
function matchesRepository(repo: string, repoPath: string | undefined, scope: RepoScope): boolean {
|
|
72
|
+
if (repoPath === scope.path) return true; // pre-hash and legacy owner access
|
|
73
|
+
if (repoPath) {
|
|
74
|
+
// The historical hash used realpath too: repoPath itself may name a
|
|
75
|
+
// symlink/junction, a short Windows spelling, or contain dot segments.
|
|
76
|
+
const canonical = normalizeDirPath(repoPath);
|
|
77
|
+
const legacyKey = createHash("sha1").update(canonical.toLowerCase()).digest("hex").slice(0, 12);
|
|
78
|
+
if (repo === legacyKey) return canonical === normalizeDirPath(scope.path);
|
|
79
|
+
}
|
|
80
|
+
return repo === scope.key;
|
|
81
|
+
}
|
|
82
|
+
|
|
63
83
|
// The ONLY repo filter every read path uses (injection sinks, recall, list,
|
|
64
84
|
// update targeting, prune, decay, gate scope reads). A row is visible when it
|
|
65
85
|
// is global (explicit marker OR no stamp — legacy rows and writes by
|
|
@@ -70,7 +90,7 @@ export function isVisibleTo(m: Pick<Memory, "repo" | "repoPath">, reader: Reader
|
|
|
70
90
|
if (reader.kind === "admin") return true;
|
|
71
91
|
if (!m.repo || m.repo === "global") return true;
|
|
72
92
|
if (reader.kind === "global-only") return false;
|
|
73
|
-
return m.repo
|
|
93
|
+
return matchesRepository(m.repo, m.repoPath, reader.scope);
|
|
74
94
|
}
|
|
75
95
|
|
|
76
96
|
export function visibleTo(mems: Memory[], reader: Reader): Memory[] {
|
|
@@ -116,10 +136,7 @@ export function evidenceVisibleTo(
|
|
|
116
136
|
if (repo === "global") return true;
|
|
117
137
|
if (reader.kind === "global-only") return false;
|
|
118
138
|
const repoPath = fields.repoPath;
|
|
119
|
-
return (
|
|
120
|
-
repo === reader.scope.key ||
|
|
121
|
-
(typeof repoPath === "string" && !!repoPath && repoPath === reader.scope.path)
|
|
122
|
-
);
|
|
139
|
+
return matchesRepository(repo, typeof repoPath === "string" ? repoPath : undefined, reader.scope);
|
|
123
140
|
}
|
|
124
141
|
const sid = fields.sid;
|
|
125
142
|
if (typeof sid === "string" && sid !== "" && sid !== "?") {
|
package/src/tools/forget.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { pruneMemory } from "../store/prune.ts";
|
|
|
6
6
|
import { ForgetArgs, validated } from "./schema.ts";
|
|
7
7
|
|
|
8
8
|
export const register: ToolRegister = (editor, deps) => {
|
|
9
|
-
const { toolIds, direct } = deps;
|
|
9
|
+
const { toolIds, bindSessionIdentity, direct } = deps;
|
|
10
10
|
editor.add(validated(ForgetArgs, {
|
|
11
11
|
name: "memory_forget",
|
|
12
12
|
description:
|
|
@@ -14,6 +14,11 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
14
14
|
options: direct,
|
|
15
15
|
async execute(args, context): Promise<{ content: string }> {
|
|
16
16
|
const { sid } = toolIds(context);
|
|
17
|
+
// Identity before the prune's repo floor (#260): resolve the session
|
|
18
|
+
// from the host (messages, then session row) before pruneMemory
|
|
19
|
+
// captures the Reader, so an unseen serve-host session is partitioned
|
|
20
|
+
// by its own repository, not the instance's provisional binding.
|
|
21
|
+
await bindSessionIdentity(sid);
|
|
17
22
|
const res = await pruneMemory(args.scope, args.type, args.reason, sid);
|
|
18
23
|
if (res.error) return { content: `memory_forget PARTIAL: deleted row(s) ${res.deleted.map((d) => d.memory.ts).join(", ")}; stopped: ${res.error}. Rejection tombstones or audit lines may be incomplete. Inspect memory_evidence / memory_undo before retrying.` };
|
|
19
24
|
if (!res.deleted.length) return { content: `No memories found for ${args.type} in ${args.scope}` };
|
|
@@ -11,7 +11,7 @@ import { MergeReviewArgs, validated } from "./schema.ts";
|
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
|
|
13
13
|
export const register: ToolRegister = (editor, deps) => {
|
|
14
|
-
const { toolIds, direct } = deps;
|
|
14
|
+
const { toolIds, bindSessionIdentity, direct } = deps;
|
|
15
15
|
editor.add(validated(MergeReviewArgs, {
|
|
16
16
|
name: "memory_merge_review",
|
|
17
17
|
description:
|
|
@@ -19,6 +19,12 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
19
19
|
options: direct,
|
|
20
20
|
async execute(args, context): Promise<{ content: string }> {
|
|
21
21
|
const { sid } = toolIds(context);
|
|
22
|
+
// Identity before authorization (#260): the entry binding is only
|
|
23
|
+
// provisional on the INSTANCE's directory. On a serve host the session
|
|
24
|
+
// row is the sole truth, and a tool call can be the first thing this
|
|
25
|
+
// instance sees for a session — resolve it like the write tools do
|
|
26
|
+
// before the Reader below partitions the seats.
|
|
27
|
+
await bindSessionIdentity(sid);
|
|
22
28
|
if (!args.loser || !args.survivor || !args.reason) {
|
|
23
29
|
return { content: "merge_review blocked: loser, survivor, and reason are all required (fail-closed)." };
|
|
24
30
|
}
|
package/src/tools/undo.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { listSnapshots, restoreSnapshot } from "../store/undo.ts";
|
|
|
9
9
|
import { basename } from "node:path";
|
|
10
10
|
|
|
11
11
|
export const register: ToolRegister = (editor, deps) => {
|
|
12
|
-
const { toolIds, direct } = deps;
|
|
12
|
+
const { toolIds, bindSessionIdentity, direct } = deps;
|
|
13
13
|
editor.add(validated(UndoArgs, {
|
|
14
14
|
name: "memory_undo",
|
|
15
15
|
description:
|
|
@@ -22,6 +22,12 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
22
22
|
// carries the CALLER's reader, so rows another repo owns survive
|
|
23
23
|
// untouched in every mode instead of riding the snapshot wholesale.
|
|
24
24
|
const { sid } = toolIds(context);
|
|
25
|
+
// Identity before ownership partitioning (#260): the caller's
|
|
26
|
+
// repository must be resolved from the host before the Reader
|
|
27
|
+
// decides which lines are foreign, exactly as merge and forget now
|
|
28
|
+
// do; the day file is shared (#153) and a wrong reader is a write
|
|
29
|
+
// into another repository's history.
|
|
30
|
+
await bindSessionIdentity(sid);
|
|
25
31
|
const res = await restoreSnapshot(args.snapshot, memoryRoot(), mode, readerFromSid(sid));
|
|
26
32
|
if (!res.restored) {
|
|
27
33
|
const parts = [...res.concurrentAdded, ...res.concurrentChanged];
|