opencode-codex-memory 0.9.4 → 0.9.6

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 CHANGED
@@ -35,7 +35,7 @@ to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
35
35
  {
36
36
  "$schema": "https://opencode.ai/config.json",
37
37
  "plugins": [
38
- { "package": "opencode-codex-memory@0.9.4" }
38
+ { "package": "opencode-codex-memory@0.9.6" }
39
39
  ]
40
40
  }
41
41
  ```
@@ -45,7 +45,7 @@ to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
45
45
  ```json
46
46
  {
47
47
  "$schema": "https://opencode.ai/config.json",
48
- "plugin": ["opencode-codex-memory@0.9.4"]
48
+ "plugin": ["opencode-codex-memory@0.9.6"]
49
49
  }
50
50
  ```
51
51
 
@@ -17,8 +17,14 @@ export interface V2AgentDefinition {
17
17
  }
18
18
  /** V2-native memorize definition (V2 action names: edit covers write/patch). */
19
19
  export declare function buildMemorizeAgent(): V2AgentDefinition;
20
- /** Session rules run after agent rules: a concurrent helper gets one root only. */
21
- export declare function consolidationPermissions(root: string): V2AgentDefinition["permissions"];
20
+ /**
21
+ * Session rules run after agent rules: a concurrent helper gets one root only.
22
+ * `sessionDir` is the helper location. OpenCode 2 asserts a session-relative
23
+ * resource when the target is inside the session or project directory, so
24
+ * absolute grants alone miss and the leading wildcard deny blocks the global
25
+ * store. Pass the same directory the session is created in.
26
+ */
27
+ export declare function consolidationPermissions(root: string, sessionDir?: string): V2AgentDefinition["permissions"];
22
28
  /**
23
29
  * Hidden extraction definition. Unused at runtime (extraction goes through
24
30
  * generate.text), kept for parity with the V1 bundle and the health
@@ -32,23 +32,31 @@ export function buildMemorizeAgent() {
32
32
  system: MEMORIZE_SYSTEM,
33
33
  permissions: [
34
34
  { action: "*", resource: "*", effect: "deny" },
35
- // Memories live outside every project: without this grant the wildcard
36
- // deny blocks consolidation from touching the memory workspace (same
37
- // role as external_directory in the V1 definition).
35
+ // Absolute grants cover a memory root outside the session (same role as
36
+ // external_directory in the V1 definition). The helper session adds the
37
+ // session-relative form; see consolidationPermissions.
38
38
  ...writeMemoryVersions().flatMap((version) => workspacePermissions(memoryRoot(version))),
39
39
  ],
40
40
  };
41
41
  }
42
- /** Session rules run after agent rules: a concurrent helper gets one root only. */
43
- export function consolidationPermissions(root) {
42
+ /**
43
+ * Session rules run after agent rules: a concurrent helper gets one root only.
44
+ * `sessionDir` is the helper location. OpenCode 2 asserts a session-relative
45
+ * resource when the target is inside the session or project directory, so
46
+ * absolute grants alone miss and the leading wildcard deny blocks the global
47
+ * store. Pass the same directory the session is created in.
48
+ */
49
+ export function consolidationPermissions(root, sessionDir) {
44
50
  return [
45
51
  { action: "*", resource: "*", effect: "deny" },
46
- ...workspacePermissions(root),
52
+ ...workspacePermissions(root, sessionDir),
47
53
  ];
48
54
  }
49
- function workspacePermissions(root) {
55
+ function workspacePermissions(root, sessionDir) {
56
+ const absolute = [root, path.join(root, "*")];
50
57
  return [
51
- ...["read", "edit", "external_directory"].flatMap((action) => [root, path.join(root, "*")].map((resource) => ({
58
+ ...sessionRelativePermissions(root, sessionDir),
59
+ ...["read", "edit", "external_directory"].flatMap((action) => absolute.map((resource) => ({
52
60
  action, resource, effect: "allow",
53
61
  }))),
54
62
  // These actions check the search pattern, not a path. search-sandbox.ts
@@ -56,6 +64,26 @@ function workspacePermissions(root) {
56
64
  ...["glob", "grep"].map((action) => ({ action, resource: "*", effect: "allow" })),
57
65
  ];
58
66
  }
67
+ /**
68
+ * FileAccess resolves and normalizes paths before permission evaluation.
69
+ * When the session is within the memory root, allow relative paths but deny
70
+ * absolute paths and traversal above that root. Absolute workspace grants run
71
+ * afterwards. external_directory always uses absolute resources.
72
+ */
73
+ function sessionRelativePermissions(root, sessionDir) {
74
+ if (!sessionDir)
75
+ return [];
76
+ const rel = path.relative(sessionDir, root);
77
+ if (path.isAbsolute(rel))
78
+ return []; // Different Windows drives.
79
+ const posix = rel.split(path.sep).join("/");
80
+ const inside = !posix || posix.split("/").every((seg) => seg === "..");
81
+ const escape = posix ? `${posix}/..` : "..";
82
+ return ["read", "edit"].flatMap((action) => inside ? [
83
+ { action, resource: "*", effect: "allow" },
84
+ ...["/*", "?:/*", escape, `${escape}/*`].map((resource) => ({ action, resource, effect: "deny" })),
85
+ ] : [posix, `${posix}/*`].map((resource) => ({ action, resource, effect: "allow" })));
86
+ }
59
87
  /**
60
88
  * Hidden extraction definition. Unused at runtime (extraction goes through
61
89
  * generate.text), kept for parity with the V1 bundle and the health
@@ -528,13 +528,14 @@ export function buildV1ClientShim() {
528
528
  releasedSubSessions.delete(EXTRACT_STUB_SESSION_ID);
529
529
  return { data: { id: EXTRACT_STUB_SESSION_ID } };
530
530
  }
531
+ const directory = opts?.query?.directory ?? memoryRoot();
531
532
  const res = await ctx().session.create({
532
533
  ...(opts?.body?.title ? { title: opts.body.title } : {}),
533
534
  ...(opts?.body?.metadata ? { metadata: opts.body.metadata } : {}),
534
535
  ...(opts?.body?.title === "codex-memory-consolidate"
535
- ? { permissions: consolidationPermissions(memoryRoot()) }
536
+ ? { permissions: consolidationPermissions(memoryRoot(), directory) }
536
537
  : {}),
537
- location: { directory: opts?.query?.directory ?? memoryRoot() },
538
+ location: { directory },
538
539
  });
539
540
  return { data: { id: und(res)?.id } };
540
541
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codex-memory",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "description": "Persistent memory plugin for opencode — ports codex's two-phase memory system (extraction → consolidation → injection → citation feedback)",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
@@ -65,11 +65,11 @@
65
65
  "@opencode/client": "2.0.5",
66
66
  "diff": "^9.0.0",
67
67
  "isomorphic-git": "^1.38.6",
68
- "xdg-basedir": "^5.1.0"
68
+ "xdg-basedir": "^5.1.0",
69
+ "zod": "4.1.8"
69
70
  },
70
71
  "devDependencies": {
71
72
  "@opencode/plugin": "2.0.3",
72
- "zod": "4.1.8",
73
73
  "@opencode/theme": "2.0.3",
74
74
  "@opentui/core": "0.5.10",
75
75
  "@opentui/solid": "0.5.10",
@@ -82,16 +82,14 @@
82
82
  "@opencode/plugin": ">=2.0.3",
83
83
  "@opentui/core": ">=0.5.10",
84
84
  "@opentui/solid": ">=0.5.10",
85
- "solid-js": ">=1.9.0",
86
- "zod": ">=4"
85
+ "solid-js": ">=1.9.0"
87
86
  },
88
87
  "peerDependenciesMeta": {
89
88
  "@opencode/client": { "optional": true },
90
89
  "@opencode/plugin": { "optional": true },
91
90
  "@opentui/core": { "optional": true },
92
91
  "@opentui/solid": { "optional": true },
93
- "solid-js": { "optional": true },
94
- "zod": { "optional": true }
92
+ "solid-js": { "optional": true }
95
93
  },
96
94
  "engines": {
97
95
  "bun": ">=1.1.0"