@corenel/cli 0.4.0 → 0.4.2

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.
Files changed (3) hide show
  1. package/LICENSE +93 -0
  2. package/dist/cli.js +457 -182
  3. package/package.json +11 -6
package/dist/cli.js CHANGED
@@ -1177,8 +1177,8 @@ var require_stringifyString = __commonJS({
1177
1177
  case "u":
1178
1178
  {
1179
1179
  str += json.slice(start, i);
1180
- const code = json.substr(i + 2, 4);
1181
- switch (code) {
1180
+ const code2 = json.substr(i + 2, 4);
1181
+ switch (code2) {
1182
1182
  case "0000":
1183
1183
  str += "\\0";
1184
1184
  break;
@@ -1204,8 +1204,8 @@ var require_stringifyString = __commonJS({
1204
1204
  str += "\\P";
1205
1205
  break;
1206
1206
  default:
1207
- if (code.substr(0, 2) === "00")
1208
- str += "\\x" + code.substr(2);
1207
+ if (code2.substr(0, 2) === "00")
1208
+ str += "\\x" + code2.substr(2);
1209
1209
  else
1210
1210
  str += json.substr(i, 6);
1211
1211
  }
@@ -3704,22 +3704,22 @@ var require_errors = __commonJS({
3704
3704
  "../../node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/errors.js"(exports) {
3705
3705
  "use strict";
3706
3706
  var YAMLError = class extends Error {
3707
- constructor(name, pos, code, message) {
3707
+ constructor(name, pos, code2, message) {
3708
3708
  super();
3709
3709
  this.name = name;
3710
- this.code = code;
3710
+ this.code = code2;
3711
3711
  this.message = message;
3712
3712
  this.pos = pos;
3713
3713
  }
3714
3714
  };
3715
3715
  var YAMLParseError = class extends YAMLError {
3716
- constructor(pos, code, message) {
3717
- super("YAMLParseError", pos, code, message);
3716
+ constructor(pos, code2, message) {
3717
+ super("YAMLParseError", pos, code2, message);
3718
3718
  }
3719
3719
  };
3720
3720
  var YAMLWarning = class extends YAMLError {
3721
- constructor(pos, code, message) {
3722
- super("YAMLWarning", pos, code, message);
3721
+ constructor(pos, code2, message) {
3722
+ super("YAMLWarning", pos, code2, message);
3723
3723
  }
3724
3724
  };
3725
3725
  var prettifyError = (src, lc) => (error) => {
@@ -4625,7 +4625,7 @@ var require_resolve_flow_scalar = __commonJS({
4625
4625
  const { offset, type, source, end } = scalar;
4626
4626
  let _type;
4627
4627
  let value;
4628
- const _onError = (rel, code, msg) => onError(offset + rel, code, msg);
4628
+ const _onError = (rel, code2, msg) => onError(offset + rel, code2, msg);
4629
4629
  switch (type) {
4630
4630
  case "scalar":
4631
4631
  _type = Scalar.Scalar.PLAIN;
@@ -4820,9 +4820,9 @@ var require_resolve_flow_scalar = __commonJS({
4820
4820
  function parseCharCode(source, offset, length, onError) {
4821
4821
  const cc = source.substr(offset, length);
4822
4822
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
4823
- const code = ok ? parseInt(cc, 16) : NaN;
4823
+ const code2 = ok ? parseInt(cc, 16) : NaN;
4824
4824
  try {
4825
- return String.fromCodePoint(code);
4825
+ return String.fromCodePoint(code2);
4826
4826
  } catch {
4827
4827
  const raw = source.substr(offset - 2, length + 2);
4828
4828
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
@@ -5144,12 +5144,12 @@ var require_composer = __commonJS({
5144
5144
  this.prelude = [];
5145
5145
  this.errors = [];
5146
5146
  this.warnings = [];
5147
- this.onError = (source, code, message, warning) => {
5147
+ this.onError = (source, code2, message, warning) => {
5148
5148
  const pos = getErrorPos(source);
5149
5149
  if (warning)
5150
- this.warnings.push(new errors.YAMLWarning(pos, code, message));
5150
+ this.warnings.push(new errors.YAMLWarning(pos, code2, message));
5151
5151
  else
5152
- this.errors.push(new errors.YAMLParseError(pos, code, message));
5152
+ this.errors.push(new errors.YAMLParseError(pos, code2, message));
5153
5153
  };
5154
5154
  this.directives = new directives.Directives({ version: options.version || "1.2" });
5155
5155
  this.options = options;
@@ -5311,12 +5311,12 @@ var require_cst_scalar = __commonJS({
5311
5311
  var stringifyString = require_stringifyString();
5312
5312
  function resolveAsScalar(token, strict = true, onError) {
5313
5313
  if (token) {
5314
- const _onError = (pos, code, message) => {
5314
+ const _onError = (pos, code2, message) => {
5315
5315
  const offset = typeof pos === "number" ? pos : Array.isArray(pos) ? pos[0] : pos.offset;
5316
5316
  if (onError)
5317
- onError(offset, code, message);
5317
+ onError(offset, code2, message);
5318
5318
  else
5319
- throw new errors.YAMLParseError([offset, offset + 1], code, message);
5319
+ throw new errors.YAMLParseError([offset, offset + 1], code2, message);
5320
5320
  };
5321
5321
  switch (token.type) {
5322
5322
  case "scalar":
@@ -6897,14 +6897,14 @@ var require_parser = __commonJS({
6897
6897
  case "scalar":
6898
6898
  case "single-quoted-scalar":
6899
6899
  case "double-quoted-scalar": {
6900
- const fs3 = this.flowScalar(this.type);
6900
+ const fs4 = this.flowScalar(this.type);
6901
6901
  if (atNextItem || it.value) {
6902
- map.items.push({ start, key: fs3, sep: [] });
6902
+ map.items.push({ start, key: fs4, sep: [] });
6903
6903
  this.onKeyLine = true;
6904
6904
  } else if (it.sep) {
6905
- this.stack.push(fs3);
6905
+ this.stack.push(fs4);
6906
6906
  } else {
6907
- Object.assign(it, { key: fs3, sep: [] });
6907
+ Object.assign(it, { key: fs4, sep: [] });
6908
6908
  this.onKeyLine = true;
6909
6909
  }
6910
6910
  return;
@@ -7032,13 +7032,13 @@ var require_parser = __commonJS({
7032
7032
  case "scalar":
7033
7033
  case "single-quoted-scalar":
7034
7034
  case "double-quoted-scalar": {
7035
- const fs3 = this.flowScalar(this.type);
7035
+ const fs4 = this.flowScalar(this.type);
7036
7036
  if (!it || it.value)
7037
- fc.items.push({ start: [], key: fs3, sep: [] });
7037
+ fc.items.push({ start: [], key: fs4, sep: [] });
7038
7038
  else if (it.sep)
7039
- this.stack.push(fs3);
7039
+ this.stack.push(fs4);
7040
7040
  else
7041
- Object.assign(it, { key: fs3, sep: [] });
7041
+ Object.assign(it, { key: fs4, sep: [] });
7042
7042
  return;
7043
7043
  }
7044
7044
  case "flow-map-end":
@@ -12241,11 +12241,11 @@ var require_compiler = __commonJS({
12241
12241
  _proto._popBuffer = function _popBuffer() {
12242
12242
  this.buffer = this.bufferStack.pop();
12243
12243
  };
12244
- _proto._emit = function _emit(code) {
12245
- this.codebuf.push(code);
12244
+ _proto._emit = function _emit(code2) {
12245
+ this.codebuf.push(code2);
12246
12246
  };
12247
- _proto._emitLine = function _emitLine(code) {
12248
- this._emit(code + "\n");
12247
+ _proto._emitLine = function _emitLine(code2) {
12248
+ this._emit(code2 + "\n");
12249
12249
  };
12250
12250
  _proto._emitLines = function _emitLines() {
12251
12251
  var _this = this;
@@ -13704,7 +13704,7 @@ var require_node_loaders = __commonJS({
13704
13704
  };
13705
13705
  return _setPrototypeOf(o, p);
13706
13706
  }
13707
- var fs3 = __require("fs");
13707
+ var fs4 = __require("fs");
13708
13708
  var path = __require("path");
13709
13709
  var Loader2 = require_loader();
13710
13710
  var _require = require_precompiled_loader();
@@ -13733,7 +13733,7 @@ var require_node_loaders = __commonJS({
13733
13733
  } catch (e) {
13734
13734
  throw new Error("watch requires chokidar to be installed");
13735
13735
  }
13736
- var paths = _this.searchPaths.filter(fs3.existsSync);
13736
+ var paths = _this.searchPaths.filter(fs4.existsSync);
13737
13737
  var watcher = chokidar.watch(paths);
13738
13738
  watcher.on("all", function(event, fullname) {
13739
13739
  fullname = path.resolve(fullname);
@@ -13754,7 +13754,7 @@ var require_node_loaders = __commonJS({
13754
13754
  for (var i = 0; i < paths.length; i++) {
13755
13755
  var basePath = path.resolve(paths[i]);
13756
13756
  var p = path.resolve(paths[i], name);
13757
- if (p.indexOf(basePath) === 0 && fs3.existsSync(p)) {
13757
+ if (p.indexOf(basePath) === 0 && fs4.existsSync(p)) {
13758
13758
  fullpath = p;
13759
13759
  break;
13760
13760
  }
@@ -13764,7 +13764,7 @@ var require_node_loaders = __commonJS({
13764
13764
  }
13765
13765
  this.pathsToNames[fullpath] = name;
13766
13766
  var source = {
13767
- src: fs3.readFileSync(fullpath, "utf-8"),
13767
+ src: fs4.readFileSync(fullpath, "utf-8"),
13768
13768
  path: fullpath,
13769
13769
  noCache: this.noCache
13770
13770
  };
@@ -13816,7 +13816,7 @@ var require_node_loaders = __commonJS({
13816
13816
  }
13817
13817
  this.pathsToNames[fullpath] = name;
13818
13818
  var source = {
13819
- src: fs3.readFileSync(fullpath, "utf-8"),
13819
+ src: fs4.readFileSync(fullpath, "utf-8"),
13820
13820
  path: fullpath,
13821
13821
  noCache: this.noCache
13822
13822
  };
@@ -14573,7 +14573,7 @@ var require_precompile_global = __commonJS({
14573
14573
  var require_precompile = __commonJS({
14574
14574
  "../../node_modules/.pnpm/nunjucks@3.2.4/node_modules/nunjucks/src/precompile.js"(exports, module) {
14575
14575
  "use strict";
14576
- var fs3 = __require("fs");
14576
+ var fs4 = __require("fs");
14577
14577
  var path = __require("path");
14578
14578
  var _require = require_lib();
14579
14579
  var _prettifyError = _require._prettifyError;
@@ -14606,14 +14606,14 @@ var require_precompile = __commonJS({
14606
14606
  if (opts.isString) {
14607
14607
  return precompileString(input, opts);
14608
14608
  }
14609
- var pathStats = fs3.existsSync(input) && fs3.statSync(input);
14609
+ var pathStats = fs4.existsSync(input) && fs4.statSync(input);
14610
14610
  var precompiled = [];
14611
14611
  var templates = [];
14612
14612
  function addTemplates(dir) {
14613
- fs3.readdirSync(dir).forEach(function(file) {
14613
+ fs4.readdirSync(dir).forEach(function(file) {
14614
14614
  var filepath = path.join(dir, file);
14615
14615
  var subpath = filepath.substr(path.join(input, "/").length);
14616
- var stat = fs3.statSync(filepath);
14616
+ var stat = fs4.statSync(filepath);
14617
14617
  if (stat && stat.isDirectory()) {
14618
14618
  subpath += "/";
14619
14619
  if (!match(subpath, opts.exclude)) {
@@ -14625,13 +14625,13 @@ var require_precompile = __commonJS({
14625
14625
  });
14626
14626
  }
14627
14627
  if (pathStats.isFile()) {
14628
- precompiled.push(_precompile(fs3.readFileSync(input, "utf-8"), opts.name || input, env));
14628
+ precompiled.push(_precompile(fs4.readFileSync(input, "utf-8"), opts.name || input, env));
14629
14629
  } else if (pathStats.isDirectory()) {
14630
14630
  addTemplates(input);
14631
14631
  for (var i = 0; i < templates.length; i++) {
14632
14632
  var name = templates[i].replace(path.join(input, "/"), "");
14633
14633
  try {
14634
- precompiled.push(_precompile(fs3.readFileSync(templates[i], "utf-8"), name, env));
14634
+ precompiled.push(_precompile(fs4.readFileSync(templates[i], "utf-8"), name, env));
14635
14635
  } catch (e) {
14636
14636
  if (opts.force) {
14637
14637
  console.error(e);
@@ -15707,8 +15707,8 @@ var require_validation = __commonJS({
15707
15707
  0
15708
15708
  // 112 - 127
15709
15709
  ];
15710
- function isValidStatusCode(code) {
15711
- return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
15710
+ function isValidStatusCode(code2) {
15711
+ return code2 >= 1e3 && code2 <= 1014 && code2 !== 1004 && code2 !== 1005 && code2 !== 1006 || code2 >= 3e3 && code2 <= 4999;
15712
15712
  }
15713
15713
  function _isValidUTF8(buf) {
15714
15714
  const len = buf.length;
@@ -16321,11 +16321,11 @@ var require_receiver = __commonJS({
16321
16321
  this.emit("conclude", 1005, EMPTY_BUFFER);
16322
16322
  this.end();
16323
16323
  } else {
16324
- const code = data.readUInt16BE(0);
16325
- if (!isValidStatusCode(code)) {
16324
+ const code2 = data.readUInt16BE(0);
16325
+ if (!isValidStatusCode(code2)) {
16326
16326
  const error = this.createError(
16327
16327
  RangeError,
16328
- `invalid status code ${code}`,
16328
+ `invalid status code ${code2}`,
16329
16329
  true,
16330
16330
  1002,
16331
16331
  "WS_ERR_INVALID_CLOSE_CODE"
@@ -16350,7 +16350,7 @@ var require_receiver = __commonJS({
16350
16350
  return;
16351
16351
  }
16352
16352
  this._loop = false;
16353
- this.emit("conclude", code, buf);
16353
+ this.emit("conclude", code2, buf);
16354
16354
  this.end();
16355
16355
  }
16356
16356
  this._state = GET_INFO;
@@ -16540,22 +16540,22 @@ var require_sender = __commonJS({
16540
16540
  * @param {Function} [cb] Callback
16541
16541
  * @public
16542
16542
  */
16543
- close(code, data, mask, cb) {
16543
+ close(code2, data, mask, cb) {
16544
16544
  let buf;
16545
- if (code === void 0) {
16545
+ if (code2 === void 0) {
16546
16546
  buf = EMPTY_BUFFER;
16547
- } else if (typeof code !== "number" || !isValidStatusCode(code)) {
16547
+ } else if (typeof code2 !== "number" || !isValidStatusCode(code2)) {
16548
16548
  throw new TypeError("First argument must be a valid error code number");
16549
16549
  } else if (data === void 0 || !data.length) {
16550
16550
  buf = Buffer.allocUnsafe(2);
16551
- buf.writeUInt16BE(code, 0);
16551
+ buf.writeUInt16BE(code2, 0);
16552
16552
  } else {
16553
16553
  const length = Buffer.byteLength(data);
16554
16554
  if (length > 123) {
16555
16555
  throw new RangeError("The message must not be greater than 123 bytes");
16556
16556
  }
16557
16557
  buf = Buffer.allocUnsafe(2 + length);
16558
- buf.writeUInt16BE(code, 0);
16558
+ buf.writeUInt16BE(code2, 0);
16559
16559
  if (typeof data === "string") {
16560
16560
  buf.write(data, 2);
16561
16561
  } else if (isUint8Array(data)) {
@@ -17050,9 +17050,9 @@ var require_event_target = __commonJS({
17050
17050
  callListener(handler, this, event);
17051
17051
  };
17052
17052
  } else if (type === "close") {
17053
- wrapper = function onClose(code, message) {
17053
+ wrapper = function onClose(code2, message) {
17054
17054
  const event = new CloseEvent("close", {
17055
- code,
17055
+ code: code2,
17056
17056
  reason: message.toString(),
17057
17057
  wasClean: this._closeFrameReceived && this._closeFrameSent
17058
17058
  });
@@ -17136,23 +17136,23 @@ var require_extension = __commonJS({
17136
17136
  let extensionName;
17137
17137
  let paramName;
17138
17138
  let start = -1;
17139
- let code = -1;
17139
+ let code2 = -1;
17140
17140
  let end = -1;
17141
17141
  let i = 0;
17142
17142
  for (; i < header.length; i++) {
17143
- code = header.charCodeAt(i);
17143
+ code2 = header.charCodeAt(i);
17144
17144
  if (extensionName === void 0) {
17145
- if (end === -1 && tokenChars[code] === 1) {
17145
+ if (end === -1 && tokenChars[code2] === 1) {
17146
17146
  if (start === -1) start = i;
17147
- } else if (i !== 0 && (code === 32 || code === 9)) {
17147
+ } else if (i !== 0 && (code2 === 32 || code2 === 9)) {
17148
17148
  if (end === -1 && start !== -1) end = i;
17149
- } else if (code === 59 || code === 44) {
17149
+ } else if (code2 === 59 || code2 === 44) {
17150
17150
  if (start === -1) {
17151
17151
  throw new SyntaxError(`Unexpected character at index ${i}`);
17152
17152
  }
17153
17153
  if (end === -1) end = i;
17154
17154
  const name = header.slice(start, end);
17155
- if (code === 44) {
17155
+ if (code2 === 44) {
17156
17156
  push(offers, name, params);
17157
17157
  params = /* @__PURE__ */ Object.create(null);
17158
17158
  } else {
@@ -17163,23 +17163,23 @@ var require_extension = __commonJS({
17163
17163
  throw new SyntaxError(`Unexpected character at index ${i}`);
17164
17164
  }
17165
17165
  } else if (paramName === void 0) {
17166
- if (end === -1 && tokenChars[code] === 1) {
17166
+ if (end === -1 && tokenChars[code2] === 1) {
17167
17167
  if (start === -1) start = i;
17168
- } else if (code === 32 || code === 9) {
17168
+ } else if (code2 === 32 || code2 === 9) {
17169
17169
  if (end === -1 && start !== -1) end = i;
17170
- } else if (code === 59 || code === 44) {
17170
+ } else if (code2 === 59 || code2 === 44) {
17171
17171
  if (start === -1) {
17172
17172
  throw new SyntaxError(`Unexpected character at index ${i}`);
17173
17173
  }
17174
17174
  if (end === -1) end = i;
17175
17175
  push(params, header.slice(start, end), true);
17176
- if (code === 44) {
17176
+ if (code2 === 44) {
17177
17177
  push(offers, extensionName, params);
17178
17178
  params = /* @__PURE__ */ Object.create(null);
17179
17179
  extensionName = void 0;
17180
17180
  }
17181
17181
  start = end = -1;
17182
- } else if (code === 61 && start !== -1 && end === -1) {
17182
+ } else if (code2 === 61 && start !== -1 && end === -1) {
17183
17183
  paramName = header.slice(start, i);
17184
17184
  start = end = -1;
17185
17185
  } else {
@@ -17187,30 +17187,30 @@ var require_extension = __commonJS({
17187
17187
  }
17188
17188
  } else {
17189
17189
  if (isEscaping) {
17190
- if (tokenChars[code] !== 1) {
17190
+ if (tokenChars[code2] !== 1) {
17191
17191
  throw new SyntaxError(`Unexpected character at index ${i}`);
17192
17192
  }
17193
17193
  if (start === -1) start = i;
17194
17194
  else if (!mustUnescape) mustUnescape = true;
17195
17195
  isEscaping = false;
17196
17196
  } else if (inQuotes) {
17197
- if (tokenChars[code] === 1) {
17197
+ if (tokenChars[code2] === 1) {
17198
17198
  if (start === -1) start = i;
17199
- } else if (code === 34 && start !== -1) {
17199
+ } else if (code2 === 34 && start !== -1) {
17200
17200
  inQuotes = false;
17201
17201
  end = i;
17202
- } else if (code === 92) {
17202
+ } else if (code2 === 92) {
17203
17203
  isEscaping = true;
17204
17204
  } else {
17205
17205
  throw new SyntaxError(`Unexpected character at index ${i}`);
17206
17206
  }
17207
- } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
17207
+ } else if (code2 === 34 && header.charCodeAt(i - 1) === 61) {
17208
17208
  inQuotes = true;
17209
- } else if (end === -1 && tokenChars[code] === 1) {
17209
+ } else if (end === -1 && tokenChars[code2] === 1) {
17210
17210
  if (start === -1) start = i;
17211
- } else if (start !== -1 && (code === 32 || code === 9)) {
17211
+ } else if (start !== -1 && (code2 === 32 || code2 === 9)) {
17212
17212
  if (end === -1) end = i;
17213
- } else if (code === 59 || code === 44) {
17213
+ } else if (code2 === 59 || code2 === 44) {
17214
17214
  if (start === -1) {
17215
17215
  throw new SyntaxError(`Unexpected character at index ${i}`);
17216
17216
  }
@@ -17221,7 +17221,7 @@ var require_extension = __commonJS({
17221
17221
  mustUnescape = false;
17222
17222
  }
17223
17223
  push(params, paramName, value);
17224
- if (code === 44) {
17224
+ if (code2 === 44) {
17225
17225
  push(offers, extensionName, params);
17226
17226
  params = /* @__PURE__ */ Object.create(null);
17227
17227
  extensionName = void 0;
@@ -17233,7 +17233,7 @@ var require_extension = __commonJS({
17233
17233
  }
17234
17234
  }
17235
17235
  }
17236
- if (start === -1 || inQuotes || code === 32 || code === 9) {
17236
+ if (start === -1 || inQuotes || code2 === 32 || code2 === 9) {
17237
17237
  throw new SyntaxError("Unexpected end of input");
17238
17238
  }
17239
17239
  if (end === -1) end = i;
@@ -17524,7 +17524,7 @@ var require_websocket = __commonJS({
17524
17524
  * closing
17525
17525
  * @public
17526
17526
  */
17527
- close(code, data) {
17527
+ close(code2, data) {
17528
17528
  if (this.readyState === _WebSocket.CLOSED) return;
17529
17529
  if (this.readyState === _WebSocket.CONNECTING) {
17530
17530
  const msg = "WebSocket was closed before the connection was established";
@@ -17538,7 +17538,7 @@ var require_websocket = __commonJS({
17538
17538
  return;
17539
17539
  }
17540
17540
  this._readyState = _WebSocket.CLOSING;
17541
- this._sender.close(code, data, !this._isServer, (err) => {
17541
+ this._sender.close(code2, data, !this._isServer, (err) => {
17542
17542
  if (err) return;
17543
17543
  this._closeFrameSent = true;
17544
17544
  if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
@@ -18061,16 +18061,16 @@ var require_websocket = __commonJS({
18061
18061
  process.nextTick(cb, err);
18062
18062
  }
18063
18063
  }
18064
- function receiverOnConclude(code, reason) {
18064
+ function receiverOnConclude(code2, reason) {
18065
18065
  const websocket = this[kWebSocket];
18066
18066
  websocket._closeFrameReceived = true;
18067
18067
  websocket._closeMessage = reason;
18068
- websocket._closeCode = code;
18068
+ websocket._closeCode = code2;
18069
18069
  if (websocket._socket[kWebSocket] === void 0) return;
18070
18070
  websocket._socket.removeListener("data", socketOnData);
18071
18071
  process.nextTick(resume, websocket._socket);
18072
- if (code === 1005) websocket.close();
18073
- else websocket.close(code, reason);
18072
+ if (code2 === 1005) websocket.close();
18073
+ else websocket.close(code2, reason);
18074
18074
  }
18075
18075
  function receiverOnDrain() {
18076
18076
  const websocket = this[kWebSocket];
@@ -18276,12 +18276,12 @@ var require_subprotocol = __commonJS({
18276
18276
  let end = -1;
18277
18277
  let i = 0;
18278
18278
  for (i; i < header.length; i++) {
18279
- const code = header.charCodeAt(i);
18280
- if (end === -1 && tokenChars[code] === 1) {
18279
+ const code2 = header.charCodeAt(i);
18280
+ if (end === -1 && tokenChars[code2] === 1) {
18281
18281
  if (start === -1) start = i;
18282
- } else if (i !== 0 && (code === 32 || code === 9)) {
18282
+ } else if (i !== 0 && (code2 === 32 || code2 === 9)) {
18283
18283
  if (end === -1 && start !== -1) end = i;
18284
- } else if (code === 44) {
18284
+ } else if (code2 === 44) {
18285
18285
  if (start === -1) {
18286
18286
  throw new SyntaxError(`Unexpected character at index ${i}`);
18287
18287
  }
@@ -18583,9 +18583,9 @@ var require_websocket_server = __commonJS({
18583
18583
  req
18584
18584
  };
18585
18585
  if (this.options.verifyClient.length === 2) {
18586
- this.options.verifyClient(info, (verified, code, message, headers) => {
18586
+ this.options.verifyClient(info, (verified, code2, message, headers) => {
18587
18587
  if (!verified) {
18588
- return abortHandshake(socket, code || 401, message, headers);
18588
+ return abortHandshake(socket, code2 || 401, message, headers);
18589
18589
  }
18590
18590
  this.completeUpgrade(
18591
18591
  extensions,
@@ -18685,8 +18685,8 @@ var require_websocket_server = __commonJS({
18685
18685
  function socketOnError() {
18686
18686
  this.destroy();
18687
18687
  }
18688
- function abortHandshake(socket, code, message, headers) {
18689
- message = message || http.STATUS_CODES[code];
18688
+ function abortHandshake(socket, code2, message, headers) {
18689
+ message = message || http.STATUS_CODES[code2];
18690
18690
  headers = {
18691
18691
  Connection: "close",
18692
18692
  "Content-Type": "text/html",
@@ -18695,17 +18695,17 @@ var require_websocket_server = __commonJS({
18695
18695
  };
18696
18696
  socket.once("finish", socket.destroy);
18697
18697
  socket.end(
18698
- `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
18698
+ `HTTP/1.1 ${code2} ${http.STATUS_CODES[code2]}\r
18699
18699
  ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
18700
18700
  );
18701
18701
  }
18702
- function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
18702
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code2, message, headers) {
18703
18703
  if (server.listenerCount("wsClientError")) {
18704
18704
  const err = new Error(message);
18705
18705
  Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
18706
18706
  server.emit("wsClientError", err, socket, req);
18707
18707
  } else {
18708
- abortHandshake(socket, code, message, headers);
18708
+ abortHandshake(socket, code2, message, headers);
18709
18709
  }
18710
18710
  }
18711
18711
  }
@@ -18715,7 +18715,6 @@ var require_websocket_server = __commonJS({
18715
18715
  import { runAgent as runAgent2 } from "@corenel/harness/core/loop";
18716
18716
  import { createChatClient as createChatClient2, setGatewayBase as setGatewayBase2 } from "@corenel/harness/providers/gateway";
18717
18717
  import { resolveContextWindow as resolveContextWindow2 } from "@corenel/harness/providers/contextWindow";
18718
- import { join as join6 } from "node:path";
18719
18718
  import { allTools as allTools3 } from "@corenel/harness/tools/builtins";
18720
18719
  import { registerGuard as registerGuard2 } from "@corenel/harness/guards";
18721
18720
  import { setPromptHost } from "@corenel/harness/prompts/host";
@@ -18833,7 +18832,7 @@ var NodeFileService = class {
18833
18832
  out.push({ name: e.name, path, kind: "directory", children: await walk(absChild) });
18834
18833
  } else {
18835
18834
  const st = await fs.stat(absChild).catch(() => null);
18836
- out.push({ name: e.name, path, kind: "file", size: st?.size, ext: extOf(e.name) });
18835
+ out.push({ name: e.name, path, kind: "file", size: st?.size, mtime: st?.mtimeMs, ext: extOf(e.name) });
18837
18836
  }
18838
18837
  }
18839
18838
  return out;
@@ -18846,7 +18845,7 @@ var NodeFileService = class {
18846
18845
  async stat(path) {
18847
18846
  try {
18848
18847
  const st = await fs.stat(this.abs(path));
18849
- return { path: normalizeFilePath(path), kind: st.isDirectory() ? "directory" : "file", size: st.size, ext: extOf(path) };
18848
+ return { path: normalizeFilePath(path), kind: st.isDirectory() ? "directory" : "file", size: st.size, mtime: st.mtimeMs, ext: extOf(path) };
18850
18849
  } catch {
18851
18850
  return null;
18852
18851
  }
@@ -18911,41 +18910,152 @@ var NodeFileService = class {
18911
18910
  import { promises as fs2 } from "node:fs";
18912
18911
  import { homedir } from "node:os";
18913
18912
  import { join as join2 } from "node:path";
18914
- import { stateDirName } from "@corenel/protocol";
18915
- function corenelDir() {
18916
- return join2(homedir(), stateDirName());
18913
+ import { stateDirName, DEFAULT_API_BASE } from "@corenel/protocol";
18914
+ function corenelDir(base = homedir()) {
18915
+ return join2(base, stateDirName());
18916
+ }
18917
+ function sidecarDir(base = homedir()) {
18918
+ return join2(corenelDir(base), "sidecar");
18919
+ }
18920
+ function authTokenPath(base = homedir()) {
18921
+ return join2(corenelDir(base), "token");
18917
18922
  }
18918
- function authTokenPath() {
18919
- return join2(corenelDir(), "token");
18923
+ function credentialDir(stateDir) {
18924
+ return stateDir ?? corenelDir();
18920
18925
  }
18921
- async function writeAuthToken(token) {
18922
- await fs2.mkdir(corenelDir(), { recursive: true, mode: 448 });
18923
- await fs2.writeFile(authTokenPath(), token.trim() + "\n", { mode: 384 });
18926
+ function tokenFilePath(stateDir) {
18927
+ return join2(credentialDir(stateDir), "token");
18928
+ }
18929
+ function credentialFilePath(stateDir) {
18930
+ return join2(credentialDir(stateDir), "auth.json");
18931
+ }
18932
+ var TOKEN_ENV = "CORENEL_TOKEN";
18933
+ var API_BASE_ENV = "CORENEL_API_BASE";
18934
+ async function writeAuthToken(token, stateDir) {
18935
+ const dir = credentialDir(stateDir);
18936
+ const path = tokenFilePath(stateDir);
18937
+ await fs2.mkdir(dir, { recursive: true, mode: 448 });
18938
+ await fs2.writeFile(path, token.trim() + "\n", { mode: 384 });
18939
+ try {
18940
+ await fs2.chmod(path, 384);
18941
+ } catch {
18942
+ }
18924
18943
  try {
18925
- await fs2.chmod(authTokenPath(), 384);
18944
+ await fs2.chmod(dir, 448);
18926
18945
  } catch {
18927
18946
  }
18947
+ }
18948
+ async function writeLoginCredential(token, opts = {}) {
18949
+ const cred = {
18950
+ accessToken: token.trim(),
18951
+ ...opts.account ? { account: opts.account } : {},
18952
+ ...opts.apiBase ? { apiBase: opts.apiBase } : {}
18953
+ };
18954
+ const path = credentialFilePath(opts.stateDir);
18955
+ await fs2.mkdir(credentialDir(opts.stateDir), { recursive: true, mode: 448 });
18956
+ await fs2.writeFile(path, `${JSON.stringify(cred, null, 2)}
18957
+ `, { mode: 384 });
18928
18958
  try {
18929
- await fs2.chmod(corenelDir(), 448);
18959
+ await fs2.chmod(path, 384);
18930
18960
  } catch {
18931
18961
  }
18962
+ await writeAuthToken(cred.accessToken, opts.stateDir);
18932
18963
  }
18933
- async function readAuthToken() {
18964
+ async function readAuthToken(stateDir) {
18934
18965
  try {
18935
- const t = (await fs2.readFile(authTokenPath(), "utf8")).trim();
18966
+ const t = (await fs2.readFile(tokenFilePath(stateDir), "utf8")).trim();
18936
18967
  return t || null;
18937
18968
  } catch {
18938
18969
  return null;
18939
18970
  }
18940
18971
  }
18941
- async function clearAuthToken() {
18972
+ async function clearAuthToken(stateDir) {
18942
18973
  try {
18943
- await fs2.rm(authTokenPath(), { force: true });
18974
+ await fs2.rm(tokenFilePath(stateDir), { force: true });
18944
18975
  } catch {
18945
18976
  }
18946
18977
  }
18947
- function nodeAuthToken() {
18948
- return { getToken: async () => await readAuthToken() ?? process.env.CORENEL_TOKEN ?? null };
18978
+ async function readCredentialFile(stateDir) {
18979
+ let raw;
18980
+ try {
18981
+ raw = await fs2.readFile(credentialFilePath(stateDir), "utf8");
18982
+ } catch {
18983
+ return null;
18984
+ }
18985
+ try {
18986
+ const parsed = JSON.parse(raw);
18987
+ if (typeof parsed !== "object" || parsed === null) return null;
18988
+ const c = parsed;
18989
+ if (typeof c.accessToken !== "string" || !c.accessToken) return null;
18990
+ return {
18991
+ accessToken: c.accessToken,
18992
+ ...typeof c.refreshToken === "string" ? { refreshToken: c.refreshToken } : {},
18993
+ ...typeof c.expiresAt === "number" ? { expiresAt: c.expiresAt } : {},
18994
+ ...typeof c.account === "string" ? { account: c.account } : {},
18995
+ ...typeof c.apiBase === "string" && c.apiBase ? { apiBase: c.apiBase } : {}
18996
+ };
18997
+ } catch {
18998
+ return null;
18999
+ }
19000
+ }
19001
+ async function clearAllCredentials(stateDir) {
19002
+ await clearAuthToken(stateDir);
19003
+ try {
19004
+ await fs2.rm(credentialFilePath(stateDir), { force: true });
19005
+ } catch {
19006
+ }
19007
+ }
19008
+ async function resolveNodeCredential(opts = {}) {
19009
+ const env = opts.env ?? process.env;
19010
+ const now = opts.now ?? Date.now;
19011
+ const stateDir = opts.stateDir;
19012
+ const fromEnv = env[TOKEN_ENV]?.trim();
19013
+ if (fromEnv) return { token: fromEnv, source: "env" };
19014
+ const cred = await readCredentialFile(stateDir);
19015
+ const fileToken = await readAuthToken(stateDir);
19016
+ if (fileToken) {
19017
+ const same = cred && cred.accessToken === fileToken ? cred : null;
19018
+ return withExpiry({ token: fileToken, source: "token-file", path: tokenFilePath(stateDir) }, same, now);
19019
+ }
19020
+ if (cred) {
19021
+ return withExpiry(
19022
+ { token: cred.accessToken, source: "credential-file", path: credentialFilePath(stateDir) },
19023
+ cred,
19024
+ now
19025
+ );
19026
+ }
19027
+ return { token: null, source: "none" };
19028
+ }
19029
+ function withExpiry(base, cred, now) {
19030
+ if (!cred) return base;
19031
+ const expired = typeof cred.expiresAt === "number" && cred.expiresAt <= now();
19032
+ return {
19033
+ ...base,
19034
+ ...typeof cred.expiresAt === "number" ? { expiresAt: cred.expiresAt } : {},
19035
+ ...expired ? { expired: true } : {},
19036
+ ...cred.account ? { account: cred.account } : {},
19037
+ ...cred.apiBase ? { apiBase: cred.apiBase } : {}
19038
+ };
19039
+ }
19040
+ async function resolveApiBase(opts = {}) {
19041
+ const explicit = opts.explicit?.trim();
19042
+ if (explicit) return { base: explicit, source: "explicit" };
19043
+ const fromEnv = (opts.env ?? process.env)[API_BASE_ENV]?.trim();
19044
+ if (fromEnv) return { base: fromEnv, source: "env" };
19045
+ const cred = await resolveNodeCredential({
19046
+ env: {},
19047
+ ...opts.stateDir ? { stateDir: opts.stateDir } : {}
19048
+ });
19049
+ if (cred.apiBase) return { base: cred.apiBase, source: "credential" };
19050
+ return { base: DEFAULT_API_BASE, source: "default" };
19051
+ }
19052
+ function maskToken(token) {
19053
+ const t = token.trim();
19054
+ if (t.length <= 8) return "****";
19055
+ return `${t.slice(0, 4)}\u2026${t.slice(-2)} (${t.length} chars)`;
19056
+ }
19057
+ function nodeAuthToken(stateDir) {
19058
+ return { getToken: async () => (await resolveNodeCredential(stateDir ? { stateDir } : {})).token };
18949
19059
  }
18950
19060
 
18951
19061
  // ../../node_modules/.pnpm/@prompd+core@0.5.0-beta.10/node_modules/@prompd/core/dist/index.js
@@ -20703,12 +20813,12 @@ var TemplateProcessingStage = class {
20703
20813
  */
20704
20814
  async loadPackageResource(context, packagePath, resourcePath, prefix) {
20705
20815
  try {
20706
- const fs3 = context.fileSystem;
20816
+ const fs4 = context.fileSystem;
20707
20817
  const possibleExtensions = ["", ".prmd", ".md", ".txt"];
20708
20818
  for (const ext of possibleExtensions) {
20709
20819
  const filePath = resolvePackageFile(packagePath, resourcePath + ext);
20710
- if (await fs3.exists(filePath)) {
20711
- const contentData = await fs3.readFile(filePath);
20820
+ if (await fs4.exists(filePath)) {
20821
+ const contentData = await fs4.readFile(filePath);
20712
20822
  if (isPrompdFile(filePath)) {
20713
20823
  const parser2 = new PrompdParser();
20714
20824
  try {
@@ -20742,16 +20852,16 @@ var TemplateProcessingStage = class {
20742
20852
  return content;
20743
20853
  }
20744
20854
  try {
20745
- const fs3 = context.fileSystem;
20855
+ const fs4 = context.fileSystem;
20746
20856
  const parser2 = new PrompdParser();
20747
20857
  let parentFile = null;
20748
- if (isPrompdFile(parentPath) && await fs3.exists(parentPath)) {
20858
+ if (isPrompdFile(parentPath) && await fs4.exists(parentPath)) {
20749
20859
  parentFile = parentPath;
20750
- } else if (await fs3.exists(parentPath) && await fs3.isDirectory(parentPath)) {
20751
- const files = (await fs3.readdir(parentPath)).filter((f) => isPrompdFile(f));
20860
+ } else if (await fs4.exists(parentPath) && await fs4.isDirectory(parentPath)) {
20861
+ const files = (await fs4.readdir(parentPath)).filter((f) => isPrompdFile(f));
20752
20862
  if (files.length > 0) {
20753
20863
  const mainFile = files.find((f) => f === "main.prmd" || f === "main.md");
20754
- parentFile = fs3.join(parentPath, mainFile || files[0]);
20864
+ parentFile = fs4.join(parentPath, mainFile || files[0]);
20755
20865
  }
20756
20866
  }
20757
20867
  if (!parentFile) {
@@ -20765,14 +20875,14 @@ var TemplateProcessingStage = class {
20765
20875
  });
20766
20876
  return content;
20767
20877
  }
20768
- const parentFileContent = await fs3.readFile(parentFile);
20878
+ const parentFileContent = await fs4.readFile(parentFile);
20769
20879
  const parentData = parser2.parseContent(parentFileContent);
20770
- await this.validateParentFileReferences(context, parentData.metadata, fs3, parentFile);
20880
+ await this.validateParentFileReferences(context, parentData.metadata, fs4, parentFile);
20771
20881
  if (context.hasErrors()) {
20772
20882
  return content;
20773
20883
  }
20774
20884
  if (parentData.content) {
20775
- const parentDir = fs3.dirname(parentFile);
20885
+ const parentDir = fs4.dirname(parentFile);
20776
20886
  parentData.content = this.resolveIncludePaths(parentData.content, parentDir);
20777
20887
  }
20778
20888
  const overrides = context.metadata?.override || {};
@@ -21323,10 +21433,10 @@ ${content}` : parentData.content;
21323
21433
  * Called during inheritance processing because AssetExtractionStage only runs on
21324
21434
  * the child file's metadata — the parent is only parsed, never fully compiled.
21325
21435
  */
21326
- async validateParentFileReferences(context, metadata, fs3, parentFile) {
21436
+ async validateParentFileReferences(context, metadata, fs4, parentFile) {
21327
21437
  if (!metadata) return;
21328
21438
  const metadataAsRecord = metadata;
21329
- const parentDir = fs3.dirname(parentFile);
21439
+ const parentDir = fs4.dirname(parentFile);
21330
21440
  const fileFields = ["system", "task", "user", "assistant", "response", "output", "context"];
21331
21441
  for (const field of fileFields) {
21332
21442
  const fieldValue = metadataAsRecord[field];
@@ -21334,8 +21444,8 @@ ${content}` : parentData.content;
21334
21444
  const refs = Array.isArray(fieldValue) ? fieldValue.filter((v) => typeof v === "string") : typeof fieldValue === "string" ? [fieldValue] : [];
21335
21445
  for (const ref of refs) {
21336
21446
  if (!ref.startsWith("./") && !ref.startsWith("../")) continue;
21337
- const resolvedPath = fs3.resolve(parentDir, ref);
21338
- const exists = await Promise.resolve(fs3.exists(resolvedPath));
21447
+ const resolvedPath = fs4.resolve(parentDir, ref);
21448
+ const exists = await Promise.resolve(fs4.exists(resolvedPath));
21339
21449
  if (!exists) {
21340
21450
  const location = context.findLocation(/inherits:/);
21341
21451
  context.addDiagnostic({
@@ -21922,15 +22032,20 @@ async function preload(svc) {
21922
22032
  }
21923
22033
  async function compile(src, values, fileSystem, mainPath) {
21924
22034
  const mp = mainPath || "/main.prmd";
21925
- const fs3 = fileSystem || new MemoryFileSystem({ [mp]: src });
21926
- const ctx = await compiler.compileWithContext(mp, { parameters: values || {}, fileSystem: fs3, outputFormat: "markdown" });
22035
+ const fs4 = fileSystem || new MemoryFileSystem({ [mp]: src });
22036
+ const ctx = await compiler.compileWithContext(mp, { parameters: values || {}, fileSystem: fs4, outputFormat: "markdown" });
21927
22037
  const compiled = ctx.compiledResult;
21928
22038
  const output = typeof compiled === "string" ? compiled : compiled ? new TextDecoder().decode(compiled) : "";
21929
22039
  return { output };
21930
22040
  }
21931
- function nodePromptHost(workspace) {
22041
+ function nodePromptHost(workspace, project) {
21932
22042
  return {
21933
22043
  workspace,
22044
+ /* The user's PROJECT files, when the caller has them, so skills installed
22045
+ * into `.prompd/skills/` are visible. Omitted rather than faked when there
22046
+ * is none: a CLI invoked outside a project genuinely has no installed
22047
+ * skills, and saying so beats inventing an empty directory. */
22048
+ ...project ? { projectWorkspace: () => project } : {},
21934
22049
  seed: async (defaults) => {
21935
22050
  for (const [p, content] of Object.entries(defaults)) {
21936
22051
  if (!await workspace.stat(p)) await workspace.write(p, content);
@@ -21949,9 +22064,99 @@ function nodePromptHost(workspace) {
21949
22064
  };
21950
22065
  }
21951
22066
 
22067
+ // ../tools-node/migrateHome.ts
22068
+ import { promises as fs3 } from "node:fs";
22069
+ import { homedir as homedir2 } from "node:os";
22070
+ import { join as join3, dirname as dirname2 } from "node:path";
22071
+ var SIDECAR_FILES = [
22072
+ "daemon.id",
22073
+ "daemon.token",
22074
+ "hosts.json",
22075
+ "sidecar.crt",
22076
+ "sidecar.key",
22077
+ "sidecar.sans.json"
22078
+ ];
22079
+ var SIDECAR_DIRS = ["hosts"];
22080
+ async function isDir(p) {
22081
+ return fs3.stat(p).then((s) => s.isDirectory()).catch(() => false);
22082
+ }
22083
+ async function present(p) {
22084
+ return fs3.stat(p).then(() => true).catch(() => false);
22085
+ }
22086
+ function code(e) {
22087
+ return e?.code;
22088
+ }
22089
+ async function moveEntry(from, to, report) {
22090
+ if (!await present(from)) return;
22091
+ if (await present(to)) {
22092
+ report.skipped.push({ path: to, reason: "destination already exists" });
22093
+ return;
22094
+ }
22095
+ await fs3.mkdir(dirname2(to), { recursive: true });
22096
+ try {
22097
+ await fs3.rename(from, to);
22098
+ report.moved.push(to);
22099
+ } catch (e) {
22100
+ const c = code(e);
22101
+ if (c === "EEXIST" || c === "ENOTEMPTY") {
22102
+ report.skipped.push({ path: to, reason: "moved concurrently" });
22103
+ return;
22104
+ }
22105
+ if (c === "ENOENT") {
22106
+ report.skipped.push({ path: to, reason: "moved concurrently" });
22107
+ return;
22108
+ }
22109
+ if (c === "EXDEV") {
22110
+ await fs3.cp(from, to, { recursive: true });
22111
+ await fs3.rm(from, { recursive: true, force: true });
22112
+ report.moved.push(to);
22113
+ return;
22114
+ }
22115
+ throw e;
22116
+ }
22117
+ }
22118
+ async function mergeDir(from, to, report) {
22119
+ const entries = await fs3.readdir(from, { withFileTypes: true }).catch(() => []);
22120
+ for (const e of entries) {
22121
+ const src = join3(from, e.name);
22122
+ const dst = join3(to, e.name);
22123
+ if (e.isDirectory() && await isDir(dst)) await mergeDir(src, dst, report);
22124
+ else await moveEntry(src, dst, report);
22125
+ }
22126
+ await fs3.rmdir(from).catch(() => {
22127
+ });
22128
+ }
22129
+ async function migrateHomeLayout(base = homedir2()) {
22130
+ const report = { moved: [], skipped: [] };
22131
+ const home = corenelDir(base);
22132
+ if (!await present(home)) return report;
22133
+ const config = join3(home, "config");
22134
+ if (await isDir(config)) await mergeDir(config, home, report);
22135
+ const side = sidecarDir(base);
22136
+ for (const name of SIDECAR_FILES) {
22137
+ await moveEntry(join3(home, name), join3(side, name), report);
22138
+ }
22139
+ for (const name of SIDECAR_DIRS) {
22140
+ const src = join3(home, name);
22141
+ if (!await isDir(src)) continue;
22142
+ const dst = join3(side, name);
22143
+ if (await isDir(dst)) await mergeDir(src, dst, report);
22144
+ else await moveEntry(src, dst, report);
22145
+ }
22146
+ if (report.moved.length) await fs3.chmod(home, 448).catch(() => {
22147
+ });
22148
+ return report;
22149
+ }
22150
+
22151
+ // src/configRoot.ts
22152
+ function configWorkspaceRoot(base) {
22153
+ return corenelDir(base);
22154
+ }
22155
+
21952
22156
  // src/cli.ts
21953
22157
  import { FileRecallStore, UNATTACHED_SESSION } from "@corenel/harness/sessions/fileRecallStore";
21954
- import { PermissionService as PermissionService3 } from "@corenel/harness/guardrail/permission-service";
22158
+ import { stateDirName as stateDirName6 } from "@corenel/protocol";
22159
+ import { PermissionService as PermissionService4 } from "@corenel/harness/guardrail/permission-service";
21955
22160
 
21956
22161
  // src/nodeContext.ts
21957
22162
  import { ROOT_NODE_ID } from "@corenel/protocol";
@@ -22047,10 +22252,10 @@ function tokenGuard(getToken) {
22047
22252
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
22048
22253
  var MIN_POLL_MS = 1e3;
22049
22254
  var DEFAULT_LIFETIME_S = 900;
22050
- function defaultOpen(uri, code) {
22255
+ function defaultOpen(uri, code2) {
22051
22256
  process.stdout.write(`
22052
22257
  To authorize, open: ${uri}
22053
- and enter the code: ${code}
22258
+ and enter the code: ${code2}
22054
22259
 
22055
22260
  Waiting for authorization\u2026
22056
22261
  `);
@@ -22112,7 +22317,7 @@ import { runAgent } from "@corenel/harness/core/loop";
22112
22317
  import { createChatClient, setGatewayBase } from "@corenel/harness/providers/gateway";
22113
22318
 
22114
22319
  // src/apiBase.ts
22115
- var DEFAULT_API_BASE = "https://api.corenel.ai/api";
22320
+ import { DEFAULT_API_BASE as DEFAULT_API_BASE2 } from "@corenel/protocol";
22116
22321
  var InvalidApiBaseError = class extends Error {
22117
22322
  constructor(value, why) {
22118
22323
  super(`invalid API base ${JSON.stringify(value)} -- ${why}`);
@@ -22126,8 +22331,13 @@ function isLoopback(hostname) {
22126
22331
  return h === "localhost" || h === "127.0.0.1" || h === "::1" || h.endsWith(".localhost");
22127
22332
  }
22128
22333
  var warnedCleartext = false;
22129
- function apiBase(explicit) {
22130
- const value = explicit || process.env.CORENEL_API_BASE || DEFAULT_API_BASE;
22334
+ async function apiBase(explicit, opts = {}) {
22335
+ const resolved = await resolveApiBase({
22336
+ explicit,
22337
+ env: opts.env ?? process.env,
22338
+ ...opts.stateDir ? { stateDir: opts.stateDir } : {}
22339
+ });
22340
+ const value = resolved.base;
22131
22341
  let url;
22132
22342
  try {
22133
22343
  url = new URL(value);
@@ -22293,6 +22503,14 @@ function parseCanCall(meta) {
22293
22503
  if (!Array.isArray(raw)) return [];
22294
22504
  return raw.filter((x) => typeof x === "string" && isValidAgentName(x));
22295
22505
  }
22506
+ function parseWorkRoots(raw) {
22507
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
22508
+ const out = {};
22509
+ for (const [id, dir] of Object.entries(raw)) {
22510
+ if (typeof dir === "string" && dir) out[id] = dir;
22511
+ }
22512
+ return Object.keys(out).length ? out : void 0;
22513
+ }
22296
22514
  function parseSettings(text) {
22297
22515
  try {
22298
22516
  const raw = JSON.parse(text);
@@ -22300,7 +22518,13 @@ function parseSettings(text) {
22300
22518
  const o = raw;
22301
22519
  return {
22302
22520
  model: typeof o.model === "string" ? o.model : void 0,
22303
- temperature: typeof o.temperature === "number" ? o.temperature : void 0
22521
+ temperature: typeof o.temperature === "number" ? o.temperature : void 0,
22522
+ /* Carried through as-is. Validation belongs to the daemon, which is the
22523
+ * only side that knows its own approved roots -- checking here would be
22524
+ * checking against the wrong list, on the wrong machine. Non-string
22525
+ * values are dropped per entry rather than failing the whole file: one
22526
+ * bad key must not cost an agent every other machine's setting. */
22527
+ workRoots: parseWorkRoots(o.workRoots)
22304
22528
  };
22305
22529
  }
22306
22530
  } catch {
@@ -22343,7 +22567,7 @@ async function loadCrewAgentAtIfExists(files, root, name, scope = "workspace") {
22343
22567
  import { saveCustomPolicy } from "@corenel/harness/guardrail";
22344
22568
  import { allTools } from "@corenel/harness/tools/builtins";
22345
22569
  import { makeCallAgentTool } from "@corenel/harness/tools/callAgent";
22346
- function buildSystemExtra(def) {
22570
+ function buildSystemExtra(def, memoryLocation) {
22347
22571
  const parts = [];
22348
22572
  if (def.jobTitle?.trim()) parts.push(`--- Role ---
22349
22573
  ${def.jobTitle.trim()}`);
@@ -22353,12 +22577,57 @@ ${def.soul.trim()}`);
22353
22577
  ${def.persona.trim()}`);
22354
22578
  if (def.instructions.trim()) parts.push(`--- Instructions ---
22355
22579
  ${def.instructions.trim()}`);
22580
+ const location = memoryLocation ?? "memory/";
22581
+ const dir = location.replace(/\/+$/, "");
22582
+ const index = `${dir}/MEMORY.md`;
22583
+ parts.push(
22584
+ `--- Memory ---
22585
+ You keep durable notes in your own memory folder, \`${dir}/\`, one Markdown file per note, alongside \`${index}\`, an index you maintain for yourself.
22586
+ Read \`${index}\` at the start of a run to recall what you already know, and call recall_memory to look up one note by name. If you can call save_memory, use it for what is worth knowing on a later run, and keep \`${index}\` current as you do. If a file tool you have takes a \`root\` argument, you can pass \`${dir}/\` as \`root\` to read and edit those files directly.`
22587
+ );
22588
+ const selfDirection = selfDirectionBlock(def);
22589
+ if (selfDirection) parts.push(selfDirection);
22356
22590
  return parts.join("\n\n");
22357
22591
  }
22592
+ function selfDirectionBlock(def) {
22593
+ const trigger = def.triggers?.find((t) => t.type === "self-directed");
22594
+ if (!trigger) return null;
22595
+ const raw = trigger.config?.fallbackMs;
22596
+ const fallbackMs = typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : null;
22597
+ const consequence = fallbackMs == null ? "If this run ends without that call, nothing will wake it again and your work stops here until someone starts you by hand." : `If this run ends without that call you will be woken anyway, about ${Math.round(fallbackMs / 6e4)} minutes from now -- but that is a backstop for a run that could not schedule itself, not a substitute for choosing when you should next run.`;
22598
+ return `--- Self-direction ---
22599
+ You run on your own schedule. You will not run again unless you call \`schedule_self\` with the time you should next wake, before this run ends.
22600
+ ${consequence}
22601
+ So decide, before you finish, whether there is more to do and when it should happen.`;
22602
+ }
22603
+
22604
+ // ../crew/memory.ts
22605
+ import { flattenFiles as flattenFiles4 } from "@corenel/protocol";
22606
+ import { parseFact, renderFact, slugify, uniqueSlug, FACT_INDEX } from "@corenel/harness/core/factFile";
22607
+
22608
+ // ../crew/room/store.ts
22609
+ import { flattenFiles as flattenFiles5 } from "@corenel/protocol";
22610
+ import { encodeLine, foldSession } from "@corenel/harness/sessions/jsonl";
22611
+ import { FINDINGS_FILE, encodeFindingLine, foldFindings } from "@corenel/harness/rooms/findings";
22612
+
22613
+ // ../crew/room/prompt.ts
22614
+ import { MAX_ROOM_FINDINGS, renderFindings } from "@corenel/harness/rooms/findings";
22615
+
22616
+ // ../crew/room/turn.ts
22617
+ import { readRoomOutcome } from "@corenel/harness/tools/roomTools";
22618
+
22619
+ // ../crew/room/turnRuntime.ts
22620
+ import { PermissionService } from "@corenel/harness/guardrail";
22621
+ import { BudgetMeter, mergeSignals } from "@corenel/harness/core/budget";
22622
+ import { makeRoomTools, ROOM_TOOL_NAMES } from "@corenel/harness/tools/roomTools";
22623
+
22624
+ // ../crew/room/engine.ts
22625
+ import { describeParticipants, resolveAddressee } from "@corenel/harness/tools/roomTools";
22626
+ import { planFindingEdit, planFindingEdits } from "@corenel/harness/rooms/findings";
22358
22627
 
22359
22628
  // src/runAgent.ts
22360
22629
  import { stateDirName as stateDirName3 } from "@corenel/protocol";
22361
- import { PermissionService } from "@corenel/harness/guardrail/permission-service";
22630
+ import { PermissionService as PermissionService2 } from "@corenel/harness/guardrail/permission-service";
22362
22631
  import { STANDARD_POLICY } from "@corenel/harness/guardrail/builtins";
22363
22632
  import { toolAddress } from "@corenel/harness/tools/namespaces";
22364
22633
 
@@ -22397,7 +22666,7 @@ async function runCrewAgentCli(opts) {
22397
22666
  opts.warn(`agent "${opts.agent}" is disabled; enable it before running`);
22398
22667
  return 2;
22399
22668
  }
22400
- setGatewayBase(apiBase(opts.base));
22669
+ setGatewayBase(await apiBase(opts.base));
22401
22670
  const token = await nodeAuthToken().getToken();
22402
22671
  if (!token) {
22403
22672
  opts.warn("not signed in: set CORENEL_TOKEN, or run `corenel login` on this machine");
@@ -22432,7 +22701,7 @@ ${extra}` : base;
22432
22701
  if (operatorUnattended === "park" && !unattendedAllow) {
22433
22702
  opts.warn(`corenel: policy "${effectivePolicy.name}" asks to park an unattended action, but run-agent cannot wait -- refusing.`);
22434
22703
  }
22435
- const permission = new PermissionService({
22704
+ const permission = new PermissionService2({
22436
22705
  policy: effectivePolicy,
22437
22706
  ceiling: mutatingCeiling(tools, "ask"),
22438
22707
  ...unattendedAllow ? { prompt: { ask: async () => "allow" } } : {}
@@ -22467,7 +22736,7 @@ ${extra}` : base;
22467
22736
  import { spawn } from "node:child_process";
22468
22737
  import { createRequire } from "node:module";
22469
22738
  import { existsSync, readFileSync } from "node:fs";
22470
- import { dirname as dirname2, join as join3 } from "node:path";
22739
+ import { dirname as dirname3, join as join4 } from "node:path";
22471
22740
  import { fileURLToPath } from "node:url";
22472
22741
 
22473
22742
  // src/extensions.ts
@@ -22535,12 +22804,12 @@ function findExtensionEntry(pkg, entry, look = {}) {
22535
22804
  if (exists(direct)) return direct;
22536
22805
  } catch {
22537
22806
  }
22538
- let dir = look.fromDir ?? dirname2(fileURLToPath(import.meta.url));
22807
+ let dir = look.fromDir ?? dirname3(fileURLToPath(import.meta.url));
22539
22808
  const parts = [...pkg.split("/"), ...entry.split("/")];
22540
22809
  for (let up = 0; up < 8; up++) {
22541
- const candidate = join3(dir, "node_modules", ...parts);
22810
+ const candidate = join4(dir, "node_modules", ...parts);
22542
22811
  if (exists(candidate)) return candidate;
22543
- const parent = dirname2(dir);
22812
+ const parent = dirname3(dir);
22544
22813
  if (parent === dir) break;
22545
22814
  dir = parent;
22546
22815
  }
@@ -22548,7 +22817,7 @@ function findExtensionEntry(pkg, entry, look = {}) {
22548
22817
  }
22549
22818
  function versionAt(entry, read = readFileSyncUtf8) {
22550
22819
  try {
22551
- const parsed = JSON.parse(read(join3(dirname2(dirname2(entry)), "package.json")));
22820
+ const parsed = JSON.parse(read(join4(dirname3(dirname3(entry)), "package.json")));
22552
22821
  const v = parsed.version;
22553
22822
  return typeof v === "string" ? v : "?";
22554
22823
  } catch {
@@ -22592,8 +22861,8 @@ async function runExtension(ext, rest, look = {}) {
22592
22861
  try {
22593
22862
  return await new Promise((resolve2, reject) => {
22594
22863
  child.on("error", reject);
22595
- child.on("exit", (code, signal) => {
22596
- resolve2(code ?? (signal === "SIGINT" ? 130 : signal ? 143 : 1));
22864
+ child.on("exit", (code2, signal) => {
22865
+ resolve2(code2 ?? (signal === "SIGINT" ? 130 : signal ? 143 : 1));
22597
22866
  });
22598
22867
  });
22599
22868
  } finally {
@@ -22674,7 +22943,7 @@ function helpText(version2) {
22674
22943
  // src/version.ts
22675
22944
  import { createRequire as createRequire2 } from "node:module";
22676
22945
  import { readFileSync as readFileSync2 } from "node:fs";
22677
- import { dirname as dirname3, join as join4 } from "node:path";
22946
+ import { dirname as dirname4, join as join5 } from "node:path";
22678
22947
  import { fileURLToPath as fileURLToPath2 } from "node:url";
22679
22948
  function selfPath() {
22680
22949
  try {
@@ -22684,15 +22953,15 @@ function selfPath() {
22684
22953
  }
22685
22954
  }
22686
22955
  function version(read = (p) => readFileSync2(p, "utf8")) {
22687
- let dir = dirname3(selfPath());
22956
+ let dir = dirname4(selfPath());
22688
22957
  for (let up = 0; up < 4; up++) {
22689
22958
  try {
22690
- const parsed = JSON.parse(read(join4(dir, "package.json")));
22959
+ const parsed = JSON.parse(read(join5(dir, "package.json")));
22691
22960
  const v = parsed;
22692
22961
  if (v.name === "@corenel/cli" && typeof v.version === "string") return v.version;
22693
22962
  } catch {
22694
22963
  }
22695
- const parent = dirname3(dir);
22964
+ const parent = dirname4(dir);
22696
22965
  if (parent === dir) break;
22697
22966
  dir = parent;
22698
22967
  }
@@ -22708,16 +22977,13 @@ function version(read = (p) => readFileSync2(p, "utf8")) {
22708
22977
 
22709
22978
  // src/auth.ts
22710
22979
  function hintOf(token) {
22711
- const t = token.trim();
22712
- if (t.length <= 8) return "****";
22713
- return `${t.slice(0, 4)}\u2026${t.slice(-2)} (${t.length} chars)`;
22980
+ return maskToken(token);
22714
22981
  }
22715
- async function authState(read = readAuthToken, env = process.env) {
22716
- const path = authTokenPath();
22717
- const stored = await read();
22718
- if (stored) return { source: "file", path, hint: hintOf(stored) };
22719
- if (env.CORENEL_TOKEN) return { source: "env", path, hint: hintOf(env.CORENEL_TOKEN) };
22720
- return { source: "none", path };
22982
+ async function authState(resolve2 = (env2) => resolveNodeCredential({ env: env2 }), env = process.env) {
22983
+ const r = await resolve2(env);
22984
+ if (!r.token) return { source: "none", path: authTokenPath() };
22985
+ const source = r.source === "env" ? "env" : "file";
22986
+ return { source, path: r.path ?? authTokenPath(), hint: hintOf(r.token) };
22721
22987
  }
22722
22988
  function describeAuth(s, base) {
22723
22989
  if (s.source === "none") {
@@ -22735,12 +23001,12 @@ function describeAuth(s, base) {
22735
23001
  ].filter(Boolean).join("\n");
22736
23002
  }
22737
23003
  async function runAuth(out = (s) => process.stdout.write(s)) {
22738
- out(`${describeAuth(await authState(), apiBase())}
23004
+ out(`${describeAuth(await authState(), await apiBase())}
22739
23005
  `);
22740
23006
  }
22741
23007
  async function runLogout(out = (s) => process.stdout.write(s)) {
22742
23008
  const before = await authState();
22743
- await clearAuthToken();
23009
+ await clearAllCredentials();
22744
23010
  if (before.source === "file") out(`Signed out. Removed ${before.path}
22745
23011
  `);
22746
23012
  else out("Nothing to forget \u2014 no stored token.\n");
@@ -22781,7 +23047,7 @@ async function checkToken(base, token, f = fetch) {
22781
23047
  return { name: "token", status: "ok", detail: `accepted by ${base} (${res.status})` };
22782
23048
  }
22783
23049
  async function collectChecks(f = fetch, modelId = DEFAULT_MODEL) {
22784
- const base = apiBase();
23050
+ const base = await apiBase();
22785
23051
  const checks = [
22786
23052
  { name: "binary", status: "ok", detail: selfPath() },
22787
23053
  { name: "version", status: "ok", detail: `@corenel/cli ${version()}` },
@@ -22789,7 +23055,7 @@ async function collectChecks(f = fetch, modelId = DEFAULT_MODEL) {
22789
23055
  {
22790
23056
  name: "api",
22791
23057
  status: "ok",
22792
- detail: base === DEFAULT_API_BASE ? base : `${base} (overridden; default is ${DEFAULT_API_BASE})`
23058
+ detail: base === DEFAULT_API_BASE2 ? base : `${base} (overridden; default is ${DEFAULT_API_BASE2})`
22793
23059
  }
22794
23060
  ];
22795
23061
  try {
@@ -22806,7 +23072,7 @@ async function collectChecks(f = fetch, modelId = DEFAULT_MODEL) {
22806
23072
  status: auth.source === "none" ? "warn" : "ok",
22807
23073
  detail: auth.source === "none" ? "no" : `yes, from ${auth.source === "env" ? "CORENEL_TOKEN" : auth.path} (${auth.hint})`
22808
23074
  });
22809
- checks.push(await checkToken(base, await readAuthToken() ?? process.env.CORENEL_TOKEN ?? null, f));
23075
+ checks.push(await checkToken(base, (await resolveNodeCredential()).token, f));
22810
23076
  const sidecar = findSidecarEntry();
22811
23077
  checks.push({
22812
23078
  name: "sidecar",
@@ -22837,7 +23103,7 @@ ${failed.length} problem${failed.length > 1 ? "s" : ""} above.
22837
23103
 
22838
23104
  // src/repl.ts
22839
23105
  import { createInterface } from "node:readline";
22840
- import { PermissionService as PermissionService2 } from "@corenel/harness/guardrail/permission-service";
23106
+ import { PermissionService as PermissionService3 } from "@corenel/harness/guardrail/permission-service";
22841
23107
  import { STANDARD_POLICY as STANDARD_POLICY2 } from "@corenel/harness/guardrail/builtins";
22842
23108
  import { TermSession } from "@corenel/term/session";
22843
23109
  import { describeToolCall, formatOrd } from "@corenel/term/describe";
@@ -23015,7 +23281,7 @@ async function runRepl(deps) {
23015
23281
  }
23016
23282
  };
23017
23283
  rl.on("SIGINT", onSigint);
23018
- const permission = new PermissionService2({
23284
+ const permission = new PermissionService3({
23019
23285
  policy: deps.policy ?? STANDARD_POLICY2,
23020
23286
  prompt: {
23021
23287
  ask: async (req) => {
@@ -23139,16 +23405,16 @@ function execute(command, opts) {
23139
23405
  killTree(child);
23140
23406
  };
23141
23407
  opts.signal?.addEventListener("abort", onAbort, { once: true });
23142
- const finish = (code) => {
23408
+ const finish = (code2) => {
23143
23409
  clearTimeout(timer);
23144
23410
  opts.signal?.removeEventListener("abort", onAbort);
23145
- resolve2({ code, stdout, stderr, timedOut });
23411
+ resolve2({ code: code2, stdout, stderr, timedOut });
23146
23412
  };
23147
23413
  child.on("error", (e) => {
23148
23414
  stderr += String(e);
23149
23415
  finish(null);
23150
23416
  });
23151
- child.on("close", (code) => finish(code));
23417
+ child.on("close", (code2) => finish(code2));
23152
23418
  });
23153
23419
  }
23154
23420
  function shellTool(cwd) {
@@ -23620,8 +23886,8 @@ async function resolveStrategyPrompt(files, id) {
23620
23886
 
23621
23887
  // src/policyResolve.ts
23622
23888
  import { readFile } from "node:fs/promises";
23623
- import { homedir as homedir2 } from "node:os";
23624
- import { join as join5 } from "node:path";
23889
+ import { homedir as homedir3 } from "node:os";
23890
+ import { join as join6 } from "node:path";
23625
23891
  import { stateDirName as stateDirName5 } from "@corenel/protocol";
23626
23892
  import { BUILTIN_POLICIES, STANDARD_POLICY as STANDARD_POLICY3, policyFromYaml } from "@corenel/harness/guardrail";
23627
23893
  var PolicyResolutionError = class extends Error {
@@ -23681,10 +23947,10 @@ async function resolvePolicy(opts) {
23681
23947
  );
23682
23948
  return { policy, source: { kind: "file", path: flag2 } };
23683
23949
  }
23684
- const projectPath = join5(cwd, stateDirName5(), "policy.yaml");
23950
+ const projectPath = join6(cwd, stateDirName5(), "policy.yaml");
23685
23951
  const project = await loadDiscoveredPolicyFile(projectPath);
23686
23952
  if (project) return { policy: project, source: { kind: "project", path: projectPath } };
23687
- const userPath = join5(homedir2(), stateDirName5(), "policy.yaml");
23953
+ const userPath = join6(homedir3(), stateDirName5(), "policy.yaml");
23688
23954
  const user = await loadDiscoveredPolicyFile(userPath);
23689
23955
  if (user) return { policy: user, source: { kind: "user", path: userPath } };
23690
23956
  return { policy: STANDARD_POLICY3, source: { kind: "default" } };
@@ -23693,7 +23959,7 @@ async function resolvePolicy(opts) {
23693
23959
  // src/cli.ts
23694
23960
  var EXIT_POLICY_PARK_REFUSED = 3;
23695
23961
  async function agentSetup(argv) {
23696
- setGatewayBase2(apiBase(flag(argv, "base", "")));
23962
+ setGatewayBase2(await apiBase(flag(argv, "base", "")));
23697
23963
  const token = await nodeAuthToken().getToken();
23698
23964
  if (!token) {
23699
23965
  process.stderr.write("corenel: not signed in.\n Run `corenel login`, or set CORENEL_TOKEN=<token> (a gateway bearer token), then try again.\n");
@@ -23703,7 +23969,16 @@ async function agentSetup(argv) {
23703
23969
  const tools = [...allTools3(), shellTool(process.cwd())];
23704
23970
  const sidecarProcs = await connectSidecarProcs();
23705
23971
  if (sidecarProcs) tools.push(...procTools(sidecarProcs.procs, { session: "corenel-cli" }));
23706
- setPromptHost(nodePromptHost(new NodeFileService(join6(corenelDir(), "config"))));
23972
+ try {
23973
+ const migrated = await migrateHomeLayout();
23974
+ if (migrated.moved.length) {
23975
+ console.error(`layout: moved ${migrated.moved.length} item(s) into the current ~/${stateDirName6()} layout`);
23976
+ }
23977
+ for (const left of migrated.skipped) console.error(`layout: left ${left.path} alone (${left.reason})`);
23978
+ } catch (e) {
23979
+ console.error(`layout: migration skipped (${e instanceof Error ? e.message : String(e)})`);
23980
+ }
23981
+ setPromptHost(nodePromptHost(new NodeFileService(configWorkspaceRoot()), new NodeFileService(process.cwd())));
23707
23982
  const identity = createIdentityState();
23708
23983
  let system = "You are corenel, a concise CLI assistant.";
23709
23984
  try {
@@ -23770,7 +24045,7 @@ async function run(argv) {
23770
24045
  process.exitCode = EXIT_POLICY_PARK_REFUSED;
23771
24046
  return;
23772
24047
  }
23773
- const permission = new PermissionService3({
24048
+ const permission = new PermissionService4({
23774
24049
  policy,
23775
24050
  ceiling: mutatingCeiling(tools, "ask"),
23776
24051
  ...unattendedAllow ? { prompt: { ask: async () => "allow" } } : {}
@@ -23942,7 +24217,7 @@ async function main() {
23942
24217
  process.exit(2);
23943
24218
  }
23944
24219
  const policyOverride = hasValueFlag(rest, "policy") ? (await resolvePolicy({ flag: flag(rest, "policy", ""), cwd: process.cwd() })).policy : void 0;
23945
- const code = await runCrewAgentCli({
24220
+ const code2 = await runCrewAgentCli({
23946
24221
  cwd: process.cwd(),
23947
24222
  agent,
23948
24223
  input: flag(rest, "input", ""),
@@ -23958,7 +24233,7 @@ async function main() {
23958
24233
  warn: (line) => process.stderr.write(`corenel: ${line}
23959
24234
  `)
23960
24235
  });
23961
- process.exitCode = code;
24236
+ process.exitCode = code2;
23962
24237
  break;
23963
24238
  }
23964
24239
  case "sidecar":
@@ -23969,8 +24244,8 @@ async function main() {
23969
24244
  break;
23970
24245
  }
23971
24246
  case "login": {
23972
- const base = apiBase(flag(rest, "base", ""));
23973
- await deviceLogin({ base, store: writeAuthToken });
24247
+ const base = await apiBase(flag(rest, "base", ""));
24248
+ await deviceLogin({ base, store: (token) => writeLoginCredential(token, { apiBase: base }) });
23974
24249
  process.stdout.write(`
23975
24250
  Logged in. Token saved to ${authTokenPath()}
23976
24251
  `);