@principles/workbuddy-adapter 0.6.1 → 0.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/workbuddy-adapter",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "WorkBuddy host adapter for Principles Disciple — implements the HostAdapter interface for WorkBuddy's Git Bash command-hook model (ADR-0020 third host, SPEC workbuddy-host-adapter v0.3.0).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -42,9 +42,9 @@
42
42
  "lint": "eslint \"src/**/*.ts\""
43
43
  },
44
44
  "dependencies": {
45
- "@principles/core": "^7.5.0",
46
- "@principles/host-runtime": "^4.0.0",
47
- "@principles/install-layout": "^0.8.0"
45
+ "@principles/core": "^7.6.1",
46
+ "@principles/host-runtime": "^4.1.1",
47
+ "@principles/install-layout": "^0.8.1"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/node": "^26.6.6",
@@ -61,5 +61,5 @@
61
61
  "publishConfig": {
62
62
  "access": "public"
63
63
  },
64
- "gitHead": "95d49f9eae5bf499fc8e4f36fecb0ad5a490f05b"
64
+ "gitHead": "8582e5dde27a582c63f3ad6804675a84c0d0c11e"
65
65
  }
@@ -94,6 +94,76 @@ const logState = {
94
94
  exhausted: false,
95
95
  };
96
96
 
97
+ // ── Experiment isolation (P0, 2026-11-13 real-host E2E) ────────────────────
98
+ // The experiment gateway inherits this launcher's environment. When
99
+ // PD_EXPERIMENT_ROOT is present every PD-owned path used here must stay inside
100
+ // it: the log directory (default would be the PRODUCTION `~/.pd/logs/mcp`) and
101
+ // the binding workspace (a stale/inherited binding must never point the
102
+ // experiment at the production workspace). Refuse BEFORE any MCP traffic.
103
+ const EXPERIMENT_ROOT = typeof process.env.PD_EXPERIMENT_ROOT === 'string'
104
+ ? process.env.PD_EXPERIMENT_ROOT.trim()
105
+ : '';
106
+
107
+ function canonicalExisting(target) {
108
+ const resolved = path.resolve(target);
109
+ const missing = [];
110
+ let current = resolved;
111
+ for (;;) {
112
+ try {
113
+ const real = fs.realpathSync.native(current);
114
+ return missing.length === 0 ? real : path.join(real, ...missing.reverse());
115
+ } catch {
116
+ // Missing path (the log dir is created later): canonicalize the deepest
117
+ // existing ancestor so an 8.3-form ancestor cannot make two views of the
118
+ // same directory look different.
119
+ }
120
+ const parent = path.dirname(current);
121
+ if (parent === current) return resolved;
122
+ missing.push(path.basename(current));
123
+ current = parent;
124
+ }
125
+ }
126
+
127
+ function isInsideOrSame(parent, child) {
128
+ const relative = path.relative(path.resolve(parent), path.resolve(child));
129
+ return relative === '' || (!path.isAbsolute(relative) && relative !== '..' && !relative.startsWith('..' + path.sep));
130
+ }
131
+
132
+ function experimentRootRealPath() {
133
+ if (EXPERIMENT_ROOT === '') return null;
134
+ if (!path.isAbsolute(EXPERIMENT_ROOT)) {
135
+ fail('experiment_root_not_absolute', 'PD_EXPERIMENT_ROOT must be an absolute path; refusing to start the MCP server from an ambiguous root.');
136
+ }
137
+ try {
138
+ return fs.realpathSync.native(EXPERIMENT_ROOT);
139
+ } catch {
140
+ fail('experiment_root_missing', 'PD_EXPERIMENT_ROOT does not resolve to an existing directory; refusing to start the MCP server.');
141
+ }
142
+ }
143
+
144
+ function isLogDirAllowed(dir) {
145
+ if (EXPERIMENT_ROOT === '') return true;
146
+ const rootReal = experimentRootRealPath();
147
+ return rootReal !== null && isInsideOrSame(rootReal, canonicalExisting(dir));
148
+ }
149
+
150
+ if (EXPERIMENT_ROOT !== '') {
151
+ const logOverride = typeof process.env.PD_MCP_LOG_DIR === 'string' ? process.env.PD_MCP_LOG_DIR.trim() : '';
152
+ if (logOverride === '') {
153
+ fail(
154
+ 'experiment_mcp_log_dir_missing',
155
+ 'PD_MCP_LOG_DIR must be set for an experiment instance; the default log directory is the production ~/.pd/logs/mcp.',
156
+ );
157
+ }
158
+ const rootReal = experimentRootRealPath();
159
+ if (rootReal !== null && !isInsideOrSame(rootReal, canonicalExisting(logOverride))) {
160
+ fail(
161
+ 'experiment_mcp_log_dir_outside_root',
162
+ 'PD_MCP_LOG_DIR resolves outside PD_EXPERIMENT_ROOT; refusing to write MCP logs into production state.',
163
+ );
164
+ }
165
+ }
166
+
97
167
  function pad(value, width) {
98
168
  return String(value).padStart(width || 2, '0');
99
169
  }
@@ -176,6 +246,7 @@ function ensureLogFile() {
176
246
  if (logState.currentPath !== null) return logState.currentPath;
177
247
  try {
178
248
  const dir = logDir();
249
+ if (!isLogDirAllowed(dir)) return null;
179
250
  fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
180
251
  if (!fs.statSync(dir).isDirectory()) return null;
181
252
  maintainLogDir(dir, Date.now(), null);
@@ -497,6 +568,20 @@ if (!workspaceStat.isDirectory()) {
497
568
  }
498
569
  logState.workspaceResolution = 'ok';
499
570
 
571
+ // P0 (2026-11-13): an experiment must never bind a workspace outside its own
572
+ // root. The binding is untrusted input written by another process generation;
573
+ // a stale one (or one produced from an inherited production pointer) keeps the
574
+ // production path while every environment variable says "experiment".
575
+ if (EXPERIMENT_ROOT !== '') {
576
+ const rootReal = experimentRootRealPath();
577
+ if (rootReal !== null && !isInsideOrSame(rootReal, canonicalExisting(binding.workspaceDir))) {
578
+ fail(
579
+ 'experiment_binding_workspace_outside_root',
580
+ 'mcp-binding.json binds a workspace outside PD_EXPERIMENT_ROOT. Restart the experiment gateway so the PD plugin rewrites the binding for the experiment workspace.',
581
+ );
582
+ }
583
+ }
584
+
500
585
  // ── OpenClaw workspace-declaration gate (SPEC §3.5, final safety closure) ──
501
586
  // The OpenClaw binding is HOST-WIDE while agents have per-agent workspaces, so
502
587
  // a binding may only be trusted while it still matches the workspace the Owner