@promptframe/creation 0.2.3 → 0.2.5

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/dist/cli.mjs CHANGED
@@ -158,10 +158,10 @@ var require_code = __commonJS({
158
158
  function interpolate(x) {
159
159
  return typeof x == "number" || typeof x == "boolean" || x === null ? x : safeStringify(Array.isArray(x) ? x.join(",") : x);
160
160
  }
161
- function stringify(x) {
161
+ function stringify2(x) {
162
162
  return new _Code(safeStringify(x));
163
163
  }
164
- exports.stringify = stringify;
164
+ exports.stringify = stringify2;
165
165
  function safeStringify(x) {
166
166
  return JSON.stringify(x).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
167
167
  }
@@ -3834,7 +3834,7 @@ var require_fast_uri = __commonJS({
3834
3834
  normalizeString(uri, options);
3835
3835
  } else if (typeof uri === "object") {
3836
3836
  uri = /** @type {T} */
3837
- parse3(serialize(uri, options), options);
3837
+ parse4(serialize(uri, options), options);
3838
3838
  }
3839
3839
  return uri;
3840
3840
  }
@@ -3874,8 +3874,8 @@ var require_fast_uri = __commonJS({
3874
3874
  function resolveComponent(base, relative, options, skipNormalization) {
3875
3875
  const target = {};
3876
3876
  if (!skipNormalization) {
3877
- base = parse3(serialize(base, options), options);
3878
- relative = parse3(serialize(relative, options), options);
3877
+ base = parse4(serialize(base, options), options);
3878
+ relative = parse4(serialize(relative, options), options);
3879
3879
  }
3880
3880
  options = options || {};
3881
3881
  if (!options.tolerant && relative.scheme) {
@@ -4174,7 +4174,7 @@ var require_fast_uri = __commonJS({
4174
4174
  }
4175
4175
  return { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme };
4176
4176
  }
4177
- function parse3(uri, opts) {
4177
+ function parse4(uri, opts) {
4178
4178
  return parseWithStatus(uri, opts).parsed;
4179
4179
  }
4180
4180
  function normalizeString(uri, opts) {
@@ -4211,7 +4211,7 @@ var require_fast_uri = __commonJS({
4211
4211
  resolveComponent,
4212
4212
  equal,
4213
4213
  serialize,
4214
- parse: parse3
4214
+ parse: parse4
4215
4215
  };
4216
4216
  module.exports = fastUri;
4217
4217
  module.exports.default = fastUri;
@@ -7207,7 +7207,7 @@ var require_content_type = __commonJS({
7207
7207
  var QUOTE_REGEXP = /([\\"])/g;
7208
7208
  var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
7209
7209
  exports.format = format;
7210
- exports.parse = parse3;
7210
+ exports.parse = parse4;
7211
7211
  function format(obj) {
7212
7212
  if (!obj || typeof obj !== "object") {
7213
7213
  throw new TypeError("argument obj is required");
@@ -7231,7 +7231,7 @@ var require_content_type = __commonJS({
7231
7231
  }
7232
7232
  return string4;
7233
7233
  }
7234
- function parse3(string4) {
7234
+ function parse4(string4) {
7235
7235
  if (!string4) {
7236
7236
  throw new TypeError("argument string is required");
7237
7237
  }
@@ -7301,7 +7301,7 @@ var require_content_type = __commonJS({
7301
7301
  });
7302
7302
 
7303
7303
  // lib/version.mjs
7304
- var CLIENT_VERSION = "0.2.3";
7304
+ var CLIENT_VERSION = "0.2.5";
7305
7305
  var CLIENT_PROTOCOL = "creation-client/v1";
7306
7306
 
7307
7307
  // lib/cli.mjs
@@ -8505,17 +8505,17 @@ var validateAsync = async (schema, value2, _ctx) => {
8505
8505
  return result.issues.length === 0;
8506
8506
  };
8507
8507
  var _encode = (_Err) => {
8508
- const parse3 = _parse(_Err);
8508
+ const parse4 = _parse(_Err);
8509
8509
  const fn = (schema, value2, _ctx, _params) => {
8510
8510
  const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
8511
- return parse3(schema, value2, ctx, finalizeParams(fn, _params));
8511
+ return parse4(schema, value2, ctx, finalizeParams(fn, _params));
8512
8512
  };
8513
8513
  return fn;
8514
8514
  };
8515
8515
  var _decode = (_Err) => {
8516
- const parse3 = _parse(_Err);
8516
+ const parse4 = _parse(_Err);
8517
8517
  const fn = (schema, value2, _ctx, _params) => {
8518
- return parse3(schema, value2, _ctx, finalizeParams(fn, _params));
8518
+ return parse4(schema, value2, _ctx, finalizeParams(fn, _params));
8519
8519
  };
8520
8520
  return fn;
8521
8521
  };
@@ -9601,7 +9601,7 @@ function capSize(inst, size) {
9601
9601
  if (!caps.length)
9602
9602
  return;
9603
9603
  const cap = Math.min(...caps.map((c) => c[0]));
9604
- const parse3 = inst._zod.parse;
9604
+ const parse4 = inst._zod.parse;
9605
9605
  inst._zod.parse = (payload, ctx) => {
9606
9606
  const n = size(payload.value);
9607
9607
  if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
@@ -9615,7 +9615,7 @@ function capSize(inst, size) {
9615
9615
  }
9616
9616
  }
9617
9617
  }
9618
- return parse3(payload, ctx);
9618
+ return parse4(payload, ctx);
9619
9619
  };
9620
9620
  }
9621
9621
  var arraySize = (input) => Array.isArray(input) ? input.length : -1;
@@ -19720,6 +19720,7 @@ async function connectPlatform(credentials) {
19720
19720
  // lib/host-context.mjs
19721
19721
  var observations = /* @__PURE__ */ new Set([
19722
19722
  "platform_list_projects",
19723
+ "platform_read_onboarding",
19723
19724
  "platform_list_sessions",
19724
19725
  "platform_read_session",
19725
19726
  "platform_list_tools",
@@ -19749,8 +19750,11 @@ var independentReads = /* @__PURE__ */ new Set([
19749
19750
  "read_spec",
19750
19751
  "read_creative_plan",
19751
19752
  "get_creative_plan",
19752
- "list_assets"
19753
+ "list_assets",
19754
+ "skills_list",
19755
+ "read_skill"
19753
19756
  ]);
19757
+ var isIndependentRead = (params) => independentReads.has(params.arguments.tool) || params.arguments.tool === "skill_view" && [void 0, "view", "none"].includes(params.arguments.arguments?.usage);
19754
19758
  var authorityReads = /* @__PURE__ */ new Set([
19755
19759
  "platform_create_session",
19756
19760
  "platform_read_session",
@@ -19828,7 +19832,7 @@ function createHostCallBridge(client) {
19828
19832
  if (result2.isError) return result2;
19829
19833
  remember(read, result2);
19830
19834
  controlVersion = versions.get(key);
19831
- if (params.name === "platform_call_tool" && independentReads.has(params.arguments.tool)) {
19835
+ if (params.name === "platform_call_tool" && isIndependentRead(params)) {
19832
19836
  const observed = data(result2);
19833
19837
  if (observed?.sessionId !== params.arguments.sessionId || !["web", "client"].includes(observed.control?.editor?.kind) || !Number.isSafeInteger(observed.control?.controlVersion) || observed.control.controlVersion <= 0)
19834
19838
  throw new CreationClientError("creation.control_unverified");
@@ -19853,9 +19857,769 @@ function createHostCallBridge(client) {
19853
19857
  import { execFile } from "node:child_process";
19854
19858
  import { promisify } from "node:util";
19855
19859
  import { createHash, randomBytes as randomBytes2 } from "node:crypto";
19856
- import { lstat as lstat2, mkdir as mkdir2, readdir, readFile as readFile2, writeFile as writeFile2, rename as rename2, rm } from "node:fs/promises";
19860
+ import { lstat as lstat2, mkdir as mkdir2, readdir, readFile as readFile2, writeFile as writeFile2, rename as rename2, rm, open as open2 } from "node:fs/promises";
19857
19861
  import { homedir as homedir2 } from "node:os";
19858
19862
  import path2 from "node:path";
19863
+
19864
+ // node_modules/smol-toml/dist/error.js
19865
+ function getLineColFromPtr(string4, ptr) {
19866
+ let lines = string4.slice(0, ptr).split(/\r?\n/);
19867
+ return [lines.length, lines.pop().length + 1];
19868
+ }
19869
+ function makeCodeBlock(string4, line, column) {
19870
+ let lines = string4.split(/\r?\n/);
19871
+ let codeblock = "";
19872
+ let numberLen = (Math.log10(line + 1) | 0) + 1;
19873
+ for (let i = line - 1; i <= line + 1; i++) {
19874
+ let l = lines[i - 1];
19875
+ if (!l)
19876
+ continue;
19877
+ codeblock += i.toString().padEnd(numberLen, " ");
19878
+ codeblock += ": ";
19879
+ codeblock += l;
19880
+ codeblock += "\n";
19881
+ if (i === line) {
19882
+ codeblock += " ".repeat(numberLen + column + 2);
19883
+ codeblock += "^\n";
19884
+ }
19885
+ }
19886
+ return codeblock;
19887
+ }
19888
+ var TomlError = class _TomlError extends Error {
19889
+ line;
19890
+ column;
19891
+ codeblock;
19892
+ constructor(message, options) {
19893
+ const [line, column] = getLineColFromPtr(options.toml, options.ptr);
19894
+ const codeblock = makeCodeBlock(options.toml, line, column);
19895
+ super(`Invalid TOML document: ${message}
19896
+
19897
+ ${codeblock}`, options);
19898
+ this.line = line;
19899
+ this.column = column;
19900
+ this.codeblock = codeblock;
19901
+ }
19902
+ /** @internal */
19903
+ static x(message, ctx, ptr) {
19904
+ throw new _TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
19905
+ }
19906
+ };
19907
+
19908
+ // node_modules/smol-toml/dist/primitive.js
19909
+ function parseString(ctx) {
19910
+ let startPtr = ctx.p;
19911
+ let c = ctx.s.charCodeAt(ctx.p++);
19912
+ let first = c;
19913
+ let isLiteral = c === 39;
19914
+ let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
19915
+ if (isMultiline) {
19916
+ if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10)
19917
+ ctx.p++;
19918
+ else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)
19919
+ ctx.p += 2;
19920
+ }
19921
+ let parsed = "";
19922
+ let sliceStart = ctx.p;
19923
+ let state = 0;
19924
+ for (; ctx.p < ctx.s.length; ctx.p++) {
19925
+ c = ctx.s.charCodeAt(ctx.p);
19926
+ if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
19927
+ state = state && 3;
19928
+ } else if (c < 32 && c !== 9 || c === 127) {
19929
+ TomlError.x("control characters are not allowed in strings", ctx);
19930
+ } else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
19931
+ if (isMultiline) {
19932
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
19933
+ ctx.p++;
19934
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
19935
+ ctx.p++;
19936
+ }
19937
+ if (!state) {
19938
+ let s = ctx.s.slice(sliceStart, ctx.p);
19939
+ parsed = parsed ? parsed + s : s;
19940
+ }
19941
+ ctx.p += isMultiline ? 3 : 1;
19942
+ return parsed;
19943
+ } else if (!state) {
19944
+ if (!isLiteral && c === 92) {
19945
+ parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
19946
+ state = 1;
19947
+ }
19948
+ } else if (state === 1) {
19949
+ if (c === 120 || c === 117 || c === 85) {
19950
+ let errPtr = ctx.p++ - 1;
19951
+ let value2 = 0;
19952
+ let len = c === 120 ? 2 : c === 117 ? 4 : 8;
19953
+ for (let j = 0; j < len; j++, ctx.p++) {
19954
+ let hex = ctx.s.charCodeAt(ctx.p);
19955
+ let digit = (
19956
+ /* 0-9 */
19957
+ hex >= 48 && hex <= 57 ? hex - 48 : (
19958
+ /* A-F */
19959
+ hex >= 65 && hex <= 70 ? hex - 65 + 10 : (
19960
+ /* a-f */
19961
+ hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1
19962
+ )
19963
+ )
19964
+ );
19965
+ if (digit < 0)
19966
+ TomlError.x("invalid non-hex character in unicode escape", ctx);
19967
+ value2 = value2 << 4 | digit;
19968
+ }
19969
+ if (value2 < 0 || value2 > 1114111 || value2 >= 55296 && value2 <= 57343) {
19970
+ TomlError.x("invalid unicode escape", ctx, errPtr);
19971
+ }
19972
+ parsed += String.fromCodePoint(value2);
19973
+ sliceStart = ctx.p--;
19974
+ state = 0;
19975
+ } else if (isMultiline && (c === 32 || c === 9)) {
19976
+ state = 2;
19977
+ } else {
19978
+ if (c === 98)
19979
+ parsed += "\b";
19980
+ else if (c === 116)
19981
+ parsed += " ";
19982
+ else if (c === 110)
19983
+ parsed += "\n";
19984
+ else if (c === 102)
19985
+ parsed += "\f";
19986
+ else if (c === 114)
19987
+ parsed += "\r";
19988
+ else if (c === 101)
19989
+ parsed += "\x1B";
19990
+ else if (c === 34)
19991
+ parsed += '"';
19992
+ else if (c === 92)
19993
+ parsed += "\\";
19994
+ else
19995
+ TomlError.x("unrecognised escape sequence", ctx);
19996
+ sliceStart = ctx.p + 1;
19997
+ state = 0;
19998
+ }
19999
+ } else if (c !== 32 && c !== 9) {
20000
+ if (state === 2)
20001
+ TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
20002
+ state = !isLiteral && c === 92 ? 1 : 0;
20003
+ sliceStart = ctx.p;
20004
+ }
20005
+ }
20006
+ TomlError.x("unfinished string", ctx, startPtr);
20007
+ }
20008
+
20009
+ // node_modules/smol-toml/dist/date.js
20010
+ var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
20011
+ var TomlDate = class _TomlDate extends Date {
20012
+ #hasDate = false;
20013
+ #hasTime = false;
20014
+ #offset = null;
20015
+ constructor(date4, fasttype, unsafeDelim) {
20016
+ let hasDate = true;
20017
+ let hasTime = true;
20018
+ let offset = "Z";
20019
+ let c;
20020
+ if (typeof date4 === "string") {
20021
+ if (fasttype)
20022
+ prep: {
20023
+ if (fasttype < 3) {
20024
+ if (+date4.slice(11, 13) > 23) {
20025
+ date4 = "";
20026
+ break prep;
20027
+ }
20028
+ if (fasttype === 2) {
20029
+ offset = null;
20030
+ date4 += "Z";
20031
+ } else if ((c = date4.charCodeAt(date4.length - 1)) !== 90 && c !== 122) {
20032
+ offset = date4.slice(date4.length - 6);
20033
+ }
20034
+ if (unsafeDelim)
20035
+ date4 = date4.slice(0, 10) + "T" + date4.slice(11);
20036
+ } else if (fasttype === 4) {
20037
+ date4 = +date4.slice(0, 2) > 23 ? "" : `0000-01-01T${date4}Z`;
20038
+ }
20039
+ hasDate = fasttype !== 4;
20040
+ hasTime = fasttype !== 3;
20041
+ }
20042
+ else {
20043
+ let match = date4.match(DATE_TIME_RE);
20044
+ if (match) {
20045
+ if (!match[1]) {
20046
+ hasDate = false;
20047
+ date4 = `0000-01-01T${date4}`;
20048
+ }
20049
+ hasTime = !!match[2];
20050
+ hasTime && date4[10] === " " && (date4 = date4.replace(" ", "T"));
20051
+ if (match[2] && +match[2] > 23) {
20052
+ date4 = "";
20053
+ } else {
20054
+ offset = match[3] || null;
20055
+ if (!offset && hasTime)
20056
+ date4 += "Z";
20057
+ }
20058
+ } else {
20059
+ date4 = "";
20060
+ }
20061
+ }
20062
+ }
20063
+ super(date4);
20064
+ if (!isNaN(this.getTime())) {
20065
+ this.#hasDate = hasDate;
20066
+ this.#hasTime = hasTime;
20067
+ this.#offset = offset;
20068
+ }
20069
+ }
20070
+ isDateTime() {
20071
+ return this.#hasDate && this.#hasTime;
20072
+ }
20073
+ isLocal() {
20074
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
20075
+ }
20076
+ isDate() {
20077
+ return this.#hasDate && !this.#hasTime;
20078
+ }
20079
+ isTime() {
20080
+ return this.#hasTime && !this.#hasDate;
20081
+ }
20082
+ isValid() {
20083
+ return this.#hasDate || this.#hasTime;
20084
+ }
20085
+ toISOString() {
20086
+ let iso = super.toISOString();
20087
+ if (this.isDate())
20088
+ return iso.slice(0, 10);
20089
+ if (this.isTime())
20090
+ return iso.slice(11, 23);
20091
+ if (this.#offset === null)
20092
+ return iso.slice(0, -1);
20093
+ if (this.#offset === "Z" || this.#offset === "z")
20094
+ return iso;
20095
+ let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
20096
+ offset = this.#offset[0] === "-" ? offset : -offset;
20097
+ let offsetDate = new Date(this.getTime() - offset * 6e4);
20098
+ return offsetDate.toISOString().slice(0, -1) + this.#offset;
20099
+ }
20100
+ static wrapAsOffsetDateTime(jsDate, offset = "Z") {
20101
+ let date4 = new _TomlDate(jsDate);
20102
+ date4.#offset = offset;
20103
+ return date4;
20104
+ }
20105
+ static wrapAsLocalDateTime(jsDate) {
20106
+ let date4 = new _TomlDate(jsDate);
20107
+ date4.#offset = null;
20108
+ return date4;
20109
+ }
20110
+ static wrapAsLocalDate(jsDate) {
20111
+ let date4 = new _TomlDate(jsDate);
20112
+ date4.#hasTime = false;
20113
+ date4.#offset = null;
20114
+ return date4;
20115
+ }
20116
+ static wrapAsLocalTime(jsDate) {
20117
+ let date4 = new _TomlDate(jsDate);
20118
+ date4.#hasDate = false;
20119
+ date4.#offset = null;
20120
+ return date4;
20121
+ }
20122
+ };
20123
+
20124
+ // node_modules/smol-toml/dist/extract.js
20125
+ function isDigit(char, base = 10) {
20126
+ return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
20127
+ }
20128
+ function isEndOfValue(char, delim) {
20129
+ return char === 32 || char === 9 || char === 10 || char === 13 || // Structure end or next value delimiter
20130
+ delim && (char === delim || char === 44) || // Comment
20131
+ char === 35;
20132
+ }
20133
+ function extractValue(ctx, end) {
20134
+ let errPtr = ctx.p;
20135
+ let c = ctx.s.charCodeAt(ctx.p);
20136
+ if (c === 91 || c === 123) {
20137
+ ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
20138
+ let value2 = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
20139
+ ctx.d++;
20140
+ return value2;
20141
+ }
20142
+ if (c === 34 || c === 39) {
20143
+ return parseString(ctx);
20144
+ }
20145
+ if (c === 116) {
20146
+ if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
20147
+ TomlError.x("invalid value", ctx, errPtr);
20148
+ return ctx.p++, true;
20149
+ }
20150
+ if (c === 102) {
20151
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
20152
+ TomlError.x("invalid value", ctx, errPtr);
20153
+ return ctx.p++, false;
20154
+ }
20155
+ if (c === 43 || c === 45) {
20156
+ return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
20157
+ }
20158
+ if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) {
20159
+ return parseDate(ctx, c, end);
20160
+ }
20161
+ if (ctx.s.charCodeAt(ctx.p + 2) === 58) {
20162
+ return parseTime(ctx, c, end);
20163
+ }
20164
+ return parseNumber(ctx, ctx.p, c, 0, end);
20165
+ }
20166
+ function parseNumber(ctx, startPtr, startChr, sign, endChr) {
20167
+ let c = startChr;
20168
+ let state = 0;
20169
+ let hasUnderscores = false;
20170
+ if (c === 105) {
20171
+ if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102)
20172
+ TomlError.x("invalid value", ctx, startPtr);
20173
+ return ctx.p++, (sign || 1) / 0;
20174
+ }
20175
+ if (c === 110) {
20176
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110)
20177
+ TomlError.x("invalid value", ctx, startPtr);
20178
+ return ctx.p++, NaN;
20179
+ }
20180
+ if (c === 48) {
20181
+ if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
20182
+ return ctx.bi === true ? 0n : 0;
20183
+ if (!sign) {
20184
+ if (c === 120)
20185
+ return parseIntegerBaseN(ctx, startPtr, 16, endChr);
20186
+ else if (c === 98)
20187
+ return parseIntegerBaseN(ctx, startPtr, 2, endChr);
20188
+ else if (c === 111)
20189
+ return parseIntegerBaseN(ctx, startPtr, 8, endChr);
20190
+ }
20191
+ if (c === 46)
20192
+ state = 2;
20193
+ else if (c === 101 || c === 69)
20194
+ state = 4;
20195
+ else
20196
+ TomlError.x("illegal leading zero", ctx, startPtr);
20197
+ } else if (!isDigit(c))
20198
+ TomlError.x("invalid value", ctx, startPtr);
20199
+ while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
20200
+ if (!state)
20201
+ state = 1;
20202
+ if (c === 95) {
20203
+ if (!(state & 1))
20204
+ TomlError.x("illegal underscore", ctx);
20205
+ state += 11;
20206
+ hasUnderscores = true;
20207
+ } else if (state === 1 && c === 46)
20208
+ state = 2;
20209
+ else if ((state === 1 || state === 3) && (c === 101 || c === 69))
20210
+ state = 4;
20211
+ else if (state === 4 && (c === 43 || c === 45)) {
20212
+ state = 6;
20213
+ } else if (!isDigit(c))
20214
+ TomlError.x(`illegal character in numeric literal`, ctx);
20215
+ else if (state > 9)
20216
+ state -= 11;
20217
+ else if (!(state & 1))
20218
+ state++;
20219
+ }
20220
+ if (!state) {
20221
+ let val = (startChr - 48) * (sign || 1);
20222
+ return ctx.bi === true ? BigInt(val) : val;
20223
+ }
20224
+ if (!(state & 1))
20225
+ TomlError.x("unfinished numeric value", ctx, startPtr);
20226
+ let str = ctx.s.slice(startPtr, ctx.p);
20227
+ if (hasUnderscores)
20228
+ str = str.replaceAll("_", "");
20229
+ return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
20230
+ }
20231
+ function parseIntegerBaseN(ctx, startPtr, base, endChr) {
20232
+ let c, underscore = 1;
20233
+ while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
20234
+ if (c === 95) {
20235
+ if (underscore & 1)
20236
+ TomlError.x("illegal underscore", ctx);
20237
+ underscore = 3;
20238
+ } else if (!isDigit(c, base))
20239
+ TomlError.x(`illegal character in numeric literal`, ctx);
20240
+ else if (underscore & 1)
20241
+ underscore--;
20242
+ }
20243
+ if (underscore & 1)
20244
+ TomlError.x("unfinished numeric value", ctx);
20245
+ let str = ctx.s.slice(startPtr + 2, ctx.p);
20246
+ if (underscore)
20247
+ str = str.replaceAll("_", "");
20248
+ return parseInteger(ctx, str, base, startPtr);
20249
+ }
20250
+ function parseInteger(ctx, str, base, startPtr) {
20251
+ if (ctx.bi !== true)
20252
+ int: {
20253
+ let val = parseInt(str, base);
20254
+ if (!Number.isSafeInteger(val)) {
20255
+ if (ctx.bi)
20256
+ break int;
20257
+ TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
20258
+ }
20259
+ return val;
20260
+ }
20261
+ return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
20262
+ }
20263
+ function parseDate(ctx, c, endChr) {
20264
+ let startPtr = ctx.p++, unsafeSeparator;
20265
+ if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) {
20266
+ return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
20267
+ }
20268
+ ctx.p += 5;
20269
+ if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
20270
+ TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
20271
+ if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) {
20272
+ let t2 = ctx.s.slice(startPtr, ctx.p);
20273
+ return readDate(ctx, t2, 3, false, startPtr);
20274
+ }
20275
+ if (ctx.s.charCodeAt(ctx.p += 3) !== 58)
20276
+ TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
20277
+ if (ctx.s.charCodeAt(ctx.p += 3) === 58)
20278
+ ctx.p += 3;
20279
+ if (ctx.s.charCodeAt(ctx.p) === 46)
20280
+ while (isDigit(ctx.s.charCodeAt(++ctx.p)))
20281
+ ;
20282
+ if (c = ctx.s.charCodeAt(ctx.p)) {
20283
+ if (c === 90 || c === 122) {
20284
+ let t2 = ctx.s.slice(startPtr, ++ctx.p);
20285
+ return readDate(ctx, t2, 1, unsafeSeparator, startPtr, "[+00:00]");
20286
+ }
20287
+ if (c === 43 || c === 45) {
20288
+ let t2 = ctx.s.slice(startPtr, ctx.p += 6);
20289
+ return readDate(ctx, t2, 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
20290
+ }
20291
+ }
20292
+ let t = ctx.s.slice(startPtr, ctx.p);
20293
+ return readDate(ctx, t, 2, unsafeSeparator, startPtr);
20294
+ }
20295
+ function parseTime(ctx, c, endChr) {
20296
+ let start = ctx.p;
20297
+ if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) {
20298
+ return parseNumber(ctx, --ctx.p, c, 0, endChr);
20299
+ }
20300
+ if (ctx.s.charCodeAt(ctx.p += 4) === 58)
20301
+ ctx.p += 3;
20302
+ if (ctx.s.charCodeAt(ctx.p) === 46)
20303
+ while (isDigit(ctx.s.charCodeAt(++ctx.p)))
20304
+ ;
20305
+ let t = ctx.s.slice(start, ctx.p);
20306
+ return readDate(ctx, t, 4, false, start);
20307
+ }
20308
+ function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
20309
+ if (ctx.ld) {
20310
+ let date4 = new TomlDate(str, type, unsafeDelim);
20311
+ if (!date4.isValid())
20312
+ TomlError.x("invalid date", ctx, errPtr);
20313
+ return date4;
20314
+ }
20315
+ try {
20316
+ if (temporalSuffix)
20317
+ str += temporalSuffix;
20318
+ switch (type) {
20319
+ case 1:
20320
+ return Temporal.ZonedDateTime.from(str);
20321
+ case 2:
20322
+ return Temporal.PlainDateTime.from(str);
20323
+ case 3:
20324
+ return Temporal.PlainDate.from(str);
20325
+ case 4:
20326
+ return Temporal.PlainTime.from(str);
20327
+ }
20328
+ } catch (e) {
20329
+ TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
20330
+ }
20331
+ }
20332
+
20333
+ // node_modules/smol-toml/dist/util.js
20334
+ function skipComment(ctx) {
20335
+ for (; ctx.p < ctx.s.length; ctx.p++) {
20336
+ let c = ctx.s.charCodeAt(ctx.p);
20337
+ if (c === 10)
20338
+ break;
20339
+ if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
20340
+ ctx.p++;
20341
+ break;
20342
+ }
20343
+ if (c < 32 && c !== 9 || c === 127) {
20344
+ TomlError.x("control characters are not allowed in comments", ctx);
20345
+ }
20346
+ }
20347
+ }
20348
+ function skipVoid(ctx, banNewLines, banComments) {
20349
+ let c;
20350
+ while (ctx.p < ctx.s.length) {
20351
+ while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)))
20352
+ ctx.p++;
20353
+ if (banComments || c !== 35)
20354
+ break;
20355
+ skipComment(ctx);
20356
+ }
20357
+ }
20358
+
20359
+ // node_modules/smol-toml/dist/struct.js
20360
+ function parseKey(ctx, end = 61) {
20361
+ let startPtr;
20362
+ let state = 0;
20363
+ let parsed = [];
20364
+ let sliceStart;
20365
+ let c = ctx.s.charCodeAt(startPtr = ctx.p);
20366
+ do {
20367
+ if (c === end) {
20368
+ if (!state)
20369
+ TomlError.x("unexpected end of key", ctx);
20370
+ if (state === 1)
20371
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
20372
+ return ctx.p++, parsed;
20373
+ } else if (c === 46) {
20374
+ if (!state)
20375
+ TomlError.x("illegal empty bare key", ctx);
20376
+ if (state === 1)
20377
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
20378
+ state = 0;
20379
+ } else if (!state && (c === 34 || c === 39)) {
20380
+ if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2))
20381
+ TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
20382
+ parsed.push(parseString(ctx));
20383
+ state = 2;
20384
+ ctx.p--;
20385
+ } else if (c === 32 || c === 9) {
20386
+ if (state === 1) {
20387
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
20388
+ state = 2;
20389
+ }
20390
+ } else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) {
20391
+ TomlError.x("illegal character in key", ctx);
20392
+ } else if (!state) {
20393
+ state = 1;
20394
+ sliceStart = ctx.p;
20395
+ }
20396
+ } while (c = ctx.s.charCodeAt(++ctx.p));
20397
+ TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
20398
+ }
20399
+ function parseInlineTable(ctx) {
20400
+ let startPtr = ctx.p++;
20401
+ let res = /* @__PURE__ */ Object.create(null);
20402
+ let seen = /* @__PURE__ */ new Set();
20403
+ let c;
20404
+ while (ctx.p < ctx.s.length) {
20405
+ skipVoid(ctx);
20406
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
20407
+ ctx.p++;
20408
+ return res;
20409
+ }
20410
+ let k;
20411
+ let t = res;
20412
+ let hasOwn = false;
20413
+ let errPtr = ctx.p;
20414
+ let key = parseKey(ctx);
20415
+ for (let i = 0; i < key.length; i++) {
20416
+ if (i)
20417
+ t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
20418
+ k = key[i];
20419
+ if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
20420
+ TomlError.x("trying to redefine an already defined value", ctx, errPtr);
20421
+ }
20422
+ let unsafe = k === "__proto__";
20423
+ if (ctx.uk && (unsafe || k === "constructor")) {
20424
+ t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
20425
+ break;
20426
+ }
20427
+ if (!hasOwn && unsafe) {
20428
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
20429
+ }
20430
+ }
20431
+ if (hasOwn) {
20432
+ TomlError.x("trying to redefine an already defined value", ctx, errPtr);
20433
+ }
20434
+ skipVoid(ctx, true, true);
20435
+ let value2 = extractValue(
20436
+ ctx,
20437
+ 125
20438
+ /* } */
20439
+ );
20440
+ if (t && typeof (t[k] = value2) === "object")
20441
+ seen.add(value2);
20442
+ skipVoid(ctx);
20443
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
20444
+ return res;
20445
+ }
20446
+ if (c !== 44)
20447
+ TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
20448
+ }
20449
+ TomlError.x("unfinished table", ctx, startPtr);
20450
+ }
20451
+ function parseArray(ctx) {
20452
+ let startPtr = ctx.p++;
20453
+ let res = [];
20454
+ let c;
20455
+ while (ctx.p < ctx.s.length) {
20456
+ skipVoid(ctx);
20457
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
20458
+ ctx.p++;
20459
+ return res;
20460
+ }
20461
+ res.push(extractValue(
20462
+ ctx,
20463
+ 93
20464
+ /* ] */
20465
+ ));
20466
+ skipVoid(ctx);
20467
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
20468
+ return res;
20469
+ }
20470
+ if (c !== 44)
20471
+ TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
20472
+ }
20473
+ TomlError.x("unfinished array", ctx, startPtr);
20474
+ }
20475
+
20476
+ // node_modules/smol-toml/dist/parse.js
20477
+ function peekTable(ctx, key, table, meta2, type) {
20478
+ let t = table;
20479
+ let m = meta2;
20480
+ let k;
20481
+ let hasOwn = false;
20482
+ let state;
20483
+ for (let i = 0; i < key.length; i++) {
20484
+ if (i) {
20485
+ t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
20486
+ m = (state = m[k]).c;
20487
+ if (type === 0 && (state.t === 1 || state.t === 2)) {
20488
+ return null;
20489
+ }
20490
+ if (state.t === 2) {
20491
+ let l = t.length - 1;
20492
+ t = t[l];
20493
+ m = m[l].c;
20494
+ }
20495
+ }
20496
+ k = key[i];
20497
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
20498
+ return null;
20499
+ }
20500
+ if (!hasOwn) {
20501
+ let unsafe = k === "__proto__";
20502
+ if (ctx.uk && (unsafe || k === "constructor"))
20503
+ return false;
20504
+ if (unsafe) {
20505
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
20506
+ Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
20507
+ }
20508
+ m[k] = {
20509
+ t: i < key.length - 1 && type === 2 ? 3 : type,
20510
+ d: false,
20511
+ i: 0,
20512
+ c: /* @__PURE__ */ Object.create(null)
20513
+ };
20514
+ }
20515
+ }
20516
+ state = m[k];
20517
+ if (state.t !== type && !(type === 1 && state.t === 3)) {
20518
+ return null;
20519
+ }
20520
+ if (type === 2) {
20521
+ if (!state.d) {
20522
+ state.d = true;
20523
+ t[k] = [];
20524
+ }
20525
+ t[k].push(t = /* @__PURE__ */ Object.create(null));
20526
+ state.c[state.i++] = state = { t: 1, d: false, i: 0, c: /* @__PURE__ */ Object.create(null) };
20527
+ }
20528
+ if (state.d) {
20529
+ return null;
20530
+ }
20531
+ state.d = true;
20532
+ if (type === 1) {
20533
+ t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
20534
+ } else if (type === 0 && hasOwn) {
20535
+ return null;
20536
+ }
20537
+ return [k, t, state.c];
20538
+ }
20539
+ function validateTablePeek(ctx, peek, ptr) {
20540
+ if (peek === null || ctx.uk === 2)
20541
+ TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
20542
+ }
20543
+ function parse3(toml, options = {}) {
20544
+ let ctx = {
20545
+ s: toml,
20546
+ p: 0,
20547
+ d: options.maxDepth ?? 1e3,
20548
+ bi: options.integersAsBigInt ?? false,
20549
+ ld: options.useLegacyDate ?? true,
20550
+ uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
20551
+ };
20552
+ let res = /* @__PURE__ */ Object.create(null);
20553
+ let meta2 = /* @__PURE__ */ Object.create(null);
20554
+ let tmp;
20555
+ let skipping = false;
20556
+ let tbl = res;
20557
+ let m = meta2;
20558
+ if (toml.charCodeAt(0) === 65279)
20559
+ ctx.p++;
20560
+ skipVoid(ctx);
20561
+ while (ctx.p < toml.length) {
20562
+ if (toml.charCodeAt(ctx.p) === 91) {
20563
+ let isTableArray = toml.charCodeAt(++ctx.p) === 91;
20564
+ tmp = ctx.p += +isTableArray;
20565
+ skipping = false;
20566
+ let k = parseKey(
20567
+ ctx,
20568
+ 93
20569
+ /* ] */
20570
+ );
20571
+ if (isTableArray) {
20572
+ if (toml.charCodeAt(ctx.p) !== 93) {
20573
+ TomlError.x("expected end of table array declaration", ctx);
20574
+ }
20575
+ ctx.p++;
20576
+ }
20577
+ let p = peekTable(
20578
+ ctx,
20579
+ k,
20580
+ res,
20581
+ meta2,
20582
+ isTableArray ? 2 : 1
20583
+ /* Type.EXPLICIT */
20584
+ );
20585
+ if (!p) {
20586
+ validateTablePeek(ctx, p, tmp);
20587
+ skipping = true;
20588
+ } else {
20589
+ m = p[2];
20590
+ tbl = p[1];
20591
+ }
20592
+ } else {
20593
+ tmp = ctx.p;
20594
+ let k = parseKey(ctx);
20595
+ let p = peekTable(
20596
+ ctx,
20597
+ k,
20598
+ tbl,
20599
+ m,
20600
+ 0
20601
+ /* Type.DOTTED */
20602
+ );
20603
+ if (!p && !skipping)
20604
+ validateTablePeek(ctx, p, tmp);
20605
+ skipVoid(ctx, true, true);
20606
+ let v = extractValue(ctx, void 0);
20607
+ if (p && !skipping)
20608
+ p[1][p[0]] = v;
20609
+ }
20610
+ skipVoid(ctx, true);
20611
+ if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) {
20612
+ TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
20613
+ }
20614
+ skipVoid(ctx);
20615
+ }
20616
+ return res;
20617
+ }
20618
+
20619
+ // node_modules/smol-toml/dist/stringify.js
20620
+ var HAS_WELLFORMED = !!"".isWellFormed;
20621
+
20622
+ // lib/user-installation.mjs
19859
20623
  var execute = promisify(execFile);
19860
20624
  var hash = (b) => createHash("sha256").update(b).digest("hex");
19861
20625
  var InstallationError = class extends CreationClientError {
@@ -19963,8 +20727,20 @@ async function officialNpmInstallation(installed, servers, env, profile, configF
19963
20727
  async function atomicJSON(file, value2) {
19964
20728
  const temp = file + "." + randomBytes2(12).toString("hex") + ".tmp";
19965
20729
  try {
19966
- await writeFile2(temp, JSON.stringify(value2, null, 2) + "\n", { flag: "wx", mode: 384 });
20730
+ const out = await open2(temp, "wx", 384);
20731
+ try {
20732
+ await out.writeFile(JSON.stringify(value2, null, 2) + "\n");
20733
+ await out.sync();
20734
+ } finally {
20735
+ await out.close();
20736
+ }
19967
20737
  await rename2(temp, file);
20738
+ const directory = await open2(path2.dirname(file), "r");
20739
+ try {
20740
+ await directory.sync();
20741
+ } finally {
20742
+ await directory.close();
20743
+ }
19968
20744
  } finally {
19969
20745
  await rm(temp, { force: true });
19970
20746
  }
@@ -20018,12 +20794,89 @@ async function acquire(root, signal) {
20018
20794
  }
20019
20795
  return () => rm(lock, { recursive: true, force: true });
20020
20796
  }
20797
+ function commandKind(args2) {
20798
+ if (args2[0] === "--version") return "host_version";
20799
+ if (args2[0] === "mcp" && args2[1] === "list") return "mcp_read";
20800
+ if (args2[1] === "marketplace") return args2[2] === "list" ? "marketplace_read" : "marketplace_register";
20801
+ return args2[1] === "list" ? "plugin_read" : "plugin_register";
20802
+ }
20021
20803
  async function runCodexCommand(args2, { env = process.env } = {}) {
20804
+ const kind = commandKind(args2), write = kind.endsWith("_register"), timeoutMs = write ? 3e4 : 5e3, start = performance.now();
20022
20805
  try {
20023
- return (await execute("codex", args2, { env, encoding: "utf8", timeout: 3e4, maxBuffer: 2 * 1024 * 1024 })).stdout;
20806
+ return (await execute("codex", args2, { env, encoding: "utf8", timeout: timeoutMs, maxBuffer: 2 * 1024 * 1024 })).stdout;
20024
20807
  } catch (e) {
20025
- throw new CreationClientError(e.code === "ENOENT" ? "installation.codex_required" : "installation.codex_command_unconfirmed");
20808
+ const cause = e.code === "ENOENT" ? "codex_required" : e.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER" ? "command_output_limit" : e.killed ? "command_timeout" : "command_failed";
20809
+ fail(cause, {
20810
+ phase: write ? "registration" : "local_check",
20811
+ commandKind: kind,
20812
+ elapsedMs: Math.round(performance.now() - start),
20813
+ timeoutMs,
20814
+ exitCode: Number.isInteger(e.code) ? e.code : null,
20815
+ signal: ["SIGTERM", "SIGKILL", "SIGINT"].includes(e.signal) ? e.signal : null,
20816
+ localRegistrationState: "unknown",
20817
+ action: write ? "observe_same_registration_before_retry" : "retry_local_read"
20818
+ });
20819
+ }
20820
+ }
20821
+ async function codexJSON(runCodex, args2) {
20822
+ const body = await runCodex(args2);
20823
+ try {
20824
+ if (typeof body !== "string" || Buffer.byteLength(body) > 2 * 1024 * 1024) throw Error();
20825
+ return JSON.parse(body);
20826
+ } catch {
20827
+ fail("command_json_unconfirmed", { phase: "local_check", commandKind: commandKind(args2), localRegistrationState: "unknown", action: "retry_local_read" });
20828
+ }
20829
+ }
20830
+ async function relatedPlugins(runCodex, pluginName, env) {
20831
+ const related = /* @__PURE__ */ new Set(), registered = /* @__PURE__ */ new Set(), config2 = path2.join(path2.resolve(env.CODEX_HOME ?? path2.join(homedir2(), ".codex")), "config.toml");
20832
+ try {
20833
+ const s = await info(config2);
20834
+ if (s) {
20835
+ if (!s.isFile() || s.isSymbolicLink() || s.size > 2 * 1024 * 1024) throw Error();
20836
+ const plugins = parse3(await readFile2(config2, "utf8")).plugins ?? {};
20837
+ if (!plugins || typeof plugins !== "object" || Array.isArray(plugins) || Object.keys(plugins).length > 1024) throw Error();
20838
+ for (const id of Object.keys(plugins)) if (id.startsWith(pluginName + "@")) {
20839
+ const market = id.slice(pluginName.length + 1);
20840
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(market)) throw Error();
20841
+ related.add(market);
20842
+ registered.add(id);
20843
+ }
20844
+ }
20845
+ } catch {
20846
+ fail("local_config_unconfirmed", { phase: "local_check", commandKind: "local_config_read", localRegistrationState: "unknown", action: "review_local_plugin_registration" });
20026
20847
  }
20848
+ const state = await codexJSON(runCodex, ["plugin", "marketplace", "list", "--json"]);
20849
+ if (!Array.isArray(state?.marketplaces) || state.marketplaces.length > 128) fail("local_catalog_unconfirmed");
20850
+ for (const market of state.marketplaces) {
20851
+ if (typeof market.name !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(market.name) || typeof market.root !== "string" || !path2.isAbsolute(market.root)) fail("local_catalog_unconfirmed");
20852
+ let catalog;
20853
+ try {
20854
+ catalog = await packageJSON(path2.join(market.root, ".agents/plugins/marketplace.json"));
20855
+ } catch {
20856
+ fail("local_catalog_unconfirmed", { phase: "local_check", commandKind: "marketplace_read", localRegistrationState: "unknown", action: "restore_local_marketplace_catalog" });
20857
+ }
20858
+ if (!Array.isArray(catalog?.plugins) || catalog.plugins.length > 1024) fail("local_catalog_unconfirmed");
20859
+ if (catalog.plugins.some((p) => p?.name === pluginName)) related.add(market.name);
20860
+ }
20861
+ const installed = [];
20862
+ for (const market of related) {
20863
+ const list = await codexJSON(runCodex, ["plugin", "list", "--marketplace", market, "--json"]);
20864
+ if (!Array.isArray(list?.installed) || list.installed.length > 1024) fail("local_registration_unconfirmed");
20865
+ for (const p of list.installed) {
20866
+ if (typeof p?.pluginId !== "string" || typeof p.enabled !== "boolean") fail("local_registration_unconfirmed");
20867
+ if (p?.pluginId !== pluginName + "@" + market) continue;
20868
+ if (p.marketplaceName !== void 0 && p.marketplaceName !== market) fail("local_registration_unconfirmed");
20869
+ installed.push(p);
20870
+ }
20871
+ }
20872
+ if (new Set(installed.map((p) => p.pluginId)).size !== installed.length) fail("local_registration_unconfirmed");
20873
+ if ([...registered].some((id) => !installed.some((p) => p.pluginId === id))) fail("local_registration_unconfirmed", {
20874
+ phase: "local_check",
20875
+ commandKind: "plugin_read",
20876
+ localRegistrationState: "unknown",
20877
+ action: "review_same_local_registration"
20878
+ });
20879
+ return installed;
20027
20880
  }
20028
20881
  async function runNode(root, version2) {
20029
20882
  try {
@@ -20071,24 +20924,37 @@ async function installForUser({
20071
20924
  const root = path2.resolve(env.XDG_DATA_HOME ?? path2.join(homedir2(), ".local/share"), "promptframe-creation", profile);
20072
20925
  await privateDirectory(root);
20073
20926
  const release = await acquire(root, signal);
20074
- const versions = path2.join(root, "versions"), currentFile = path2.join(root, "current.json");
20927
+ const versions = path2.join(root, "versions"), currentFile = path2.join(root, "current.json"), pendingFile = path2.join(root, "registration-pending.json");
20075
20928
  const marketplaceFile = path2.join(root, ".agents/plugins/marketplace.json");
20076
20929
  const pluginName = "promptframe-creation" + (profile === "default" ? "" : "-" + profile), marketplace = "promptframe-creation-user" + (profile === "default" ? "" : "-" + profile);
20077
20930
  const pluginId = pluginName + "@" + marketplace;
20078
20931
  const versionRoot = path2.join(versions, payload.version), temporary = path2.join(versions, ".partial-" + randomBytes2(12).toString("hex"));
20079
- let previousCatalog, previous, registrationStarted = false, newFiles = 0;
20932
+ let previous, registrationStarted = false, newFiles = 0;
20080
20933
  try {
20081
20934
  signal?.throwIfAborted();
20082
20935
  await privateDirectory(versions);
20083
20936
  await privateDirectory(path2.dirname(marketplaceFile));
20084
20937
  previous = await privateRead(currentFile);
20085
- previousCatalog = await privateRead(marketplaceFile);
20086
20938
  if (previous && (previous.profile !== profile || previous.pluginId !== pluginId || previous.configFile !== configFile2)) fail("profile_binding_conflict");
20087
- const state = JSON.parse(await runCodex(["plugin", "list", "--json"]));
20088
- const installed = state.installed?.find((x) => x.pluginId === pluginId);
20089
- const legacy = JSON.parse(await runCodex(["mcp", "list", "--json"]));
20939
+ const state = { installed: await relatedPlugins(runCodex, pluginName, env) };
20940
+ const installed = state.installed.find((x) => x.pluginId === pluginId);
20941
+ const legacy = await codexJSON(runCodex, ["mcp", "list", "--json"]);
20942
+ if (!Array.isArray(legacy)) fail("local_registration_unconfirmed");
20090
20943
  const serverName = "promptframe" + (profile === "default" ? "" : "-" + profile);
20091
20944
  const servers = legacy.filter((x) => x.name === serverName);
20945
+ const pending = await privateRead(pendingFile);
20946
+ if (pending) {
20947
+ if (pending.profile !== profile || pending.pluginId !== pluginId || pending.configFile !== configFile2 || pending.versionRoot !== path2.join(versions, pending.version)) fail("profile_binding_conflict");
20948
+ if (installed?.version !== pending.version || installed.enabled !== true || installed.source?.path !== pending.versionRoot)
20949
+ fail("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
20950
+ const transport = await managedTransport(installed, versions, serverName, profile, configFile2);
20951
+ if (servers.length !== 1 || servers[0].enabled === false || !sameTransport(servers[0].transport, transport)) fail("registration_unconfirmed_keep_existing");
20952
+ const ready = await privateRead(path2.join(pending.versionRoot, "installation.json"));
20953
+ if (ready?.payloadDigest !== pending.payloadDigest) fail("installed_files_invalid");
20954
+ previous = pending;
20955
+ await atomicJSON(currentFile, pending);
20956
+ await rm(pendingFile);
20957
+ }
20092
20958
  const official = await officialNpmInstallation(state.installed ?? [], servers, env, profile, configFile2);
20093
20959
  if (official) {
20094
20960
  if (installed || previous) fail("existing_registration_requires_review");
@@ -20110,6 +20976,7 @@ async function installForUser({
20110
20976
  if (x.name !== serverName) return false;
20111
20977
  return !recorded || !sameTransport(x.transport, recorded);
20112
20978
  })) fail("legacy_mcp_entry_requires_review");
20979
+ if (state.installed.some((p) => p.pluginId !== pluginId)) fail("existing_registration_requires_review");
20113
20980
  if (installed && compareVersions(installed.version, payload.version) > 0) {
20114
20981
  if (!previous || previous.version !== installed.version || previous.versionRoot !== installed.source.path || installed.enabled !== true)
20115
20982
  fail("existing_registration_requires_review");
@@ -20179,12 +21046,19 @@ async function installForUser({
20179
21046
  }] };
20180
21047
  await atomicJSON(marketplaceFile, catalog);
20181
21048
  signal?.throwIfAborted();
21049
+ await atomicJSON(pendingFile, complete);
20182
21050
  registrationStarted = true;
20183
21051
  await runCodex(["plugin", "marketplace", "add", root, "--json"]);
20184
21052
  await runCodex(["plugin", "add", pluginId, "--json"]);
20185
- const observed = JSON.parse(await runCodex(["plugin", "list", "--json"])).installed?.find((x) => x.pluginId === pluginId);
21053
+ const observed = (await relatedPlugins(runCodex, pluginName, env)).find((x) => x.pluginId === pluginId);
20186
21054
  if (observed?.version !== payload.version || observed.enabled !== true) fail("registration_unconfirmed");
21055
+ const launch = await managedTransport(observed, versions, serverName, profile, configFile2);
21056
+ const hostMcp = await codexJSON(runCodex, ["mcp", "list", "--json"]);
21057
+ if (!Array.isArray(hostMcp)) fail("registration_unconfirmed");
21058
+ const effective = hostMcp.filter((x) => x.name === serverName);
21059
+ if (effective.length !== 1 || effective[0].enabled === false || !sameTransport(effective[0].transport, launch)) fail("registration_unconfirmed");
20187
21060
  await atomicJSON(currentFile, complete);
21061
+ await rm(pendingFile);
20188
21062
  }
20189
21063
  return {
20190
21064
  ...complete,
@@ -20199,18 +21073,12 @@ async function installForUser({
20199
21073
  };
20200
21074
  } catch (error2) {
20201
21075
  if (registrationStarted) {
20202
- if (previousCatalog) {
20203
- await atomicJSON(marketplaceFile, previousCatalog);
20204
- if (previous) {
20205
- try {
20206
- await runCodex(["plugin", "add", pluginId, "--json"]);
20207
- const restored = JSON.parse(await runCodex(["plugin", "list", "--json"])).installed?.find((x) => x.pluginId === pluginId);
20208
- if (restored?.version !== previous.version || restored.enabled !== true) fail("registration_unconfirmed");
20209
- } catch {
20210
- }
20211
- }
20212
- } else await rm(marketplaceFile, { force: true });
20213
- fail("registration_unconfirmed_keep_existing");
21076
+ fail("registration_unconfirmed_keep_existing", {
21077
+ ...installationErrorDetails(error2),
21078
+ phase: "registration_observation",
21079
+ localRegistrationState: "unknown",
21080
+ action: "inspect_same_registration_no_second_add"
21081
+ });
20214
21082
  }
20215
21083
  if (error2 instanceof CreationClientError) throw error2;
20216
21084
  if (signal?.aborted) fail("interrupted_keep_existing");
@@ -20418,12 +21286,16 @@ try {
20418
21286
  ...connection,
20419
21287
  pluginRegistered: installed.registered,
20420
21288
  version: installed.version,
21289
+ pluginInstalled: true,
21290
+ pluginEnabled: true,
21291
+ hostMcpConnected: "not_verified",
21292
+ sessionLoaded: "not_verified",
20421
21293
  installationReused: installed.reused,
20422
21294
  profile: installed.profile,
20423
21295
  requestedVersion: installed.requestedVersion,
20424
21296
  versionStatus: installed.versionStatus,
20425
21297
  recordedRuntimeRetained: installed.recordedRuntimeRetained ?? false,
20426
- next: installed.recordedRuntimeRetained ? "This version retains its recorded Node path. Keep that Node available; a new version uses the installer's current Node." : installed.reloadRequired ? "Open a new Codex chat or reload plugins, then use the creation Skill." : "Use the creation Skill in a chat that has this plugin loaded.",
21298
+ next: "On this host, open a new Local chat (CLI: start a new session). Check creation-setup, video-creation and the PromptFrame MCP tools together. Keep the existing Token; no reinstall or product repository is needed." + (installed.recordedRuntimeRetained ? " Keep this version's recorded Node path available." : ""),
20427
21299
  hostThreadIdentity: "verified_by_the_platform_on_actual_host_tool_calls"
20428
21300
  });
20429
21301
  } finally {