@agentchatme/codex 0.0.15 → 0.0.16
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/daemon-main.js +9 -4
- package/dist/daemon-main.js.map +1 -1
- package/dist/index.js +241 -128
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const require=__acCreateRequire(import.meta.url);
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { parseArgs } from "util";
|
|
7
7
|
|
|
8
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
8
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.12/node_modules/@agentchatme/agent-core/dist/chunk-NEGTEBFK.js
|
|
9
9
|
import * as fs2 from "fs";
|
|
10
10
|
import * as path2 from "path";
|
|
11
11
|
import * as fs3 from "fs";
|
|
@@ -4335,7 +4335,7 @@ function alwaysOnHealth(home) {
|
|
|
4335
4335
|
return { wanted: state !== "off", healthy: state !== "down" };
|
|
4336
4336
|
}
|
|
4337
4337
|
|
|
4338
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
4338
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.12/node_modules/@agentchatme/agent-core/dist/index.js
|
|
4339
4339
|
import * as fs from "fs";
|
|
4340
4340
|
import * as path from "path";
|
|
4341
4341
|
import * as readline from "readline";
|
|
@@ -4600,8 +4600,8 @@ var HttpTransport = class {
|
|
|
4600
4600
|
}
|
|
4601
4601
|
this.fetchFn = f.bind(globalThis);
|
|
4602
4602
|
}
|
|
4603
|
-
async request(method,
|
|
4604
|
-
const url = `${this.baseUrl}${
|
|
4603
|
+
async request(method, path8, opts = {}) {
|
|
4604
|
+
const url = `${this.baseUrl}${path8}`;
|
|
4605
4605
|
const policy = resolveRetryPolicy(opts.retry, this.retry);
|
|
4606
4606
|
const canRetry = isRetryEligible(method, opts.idempotencyKey, opts.retry);
|
|
4607
4607
|
const maxAttempts = canRetry ? policy.maxRetries + 1 : 1;
|
|
@@ -4920,31 +4920,31 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
4920
4920
|
this.onBacklogWarning = options.onBacklogWarning;
|
|
4921
4921
|
}
|
|
4922
4922
|
// ─── Internal request helpers ─────────────────────────────────────────────
|
|
4923
|
-
async get(
|
|
4924
|
-
const res = await this.http.request("GET",
|
|
4923
|
+
async get(path8, opts) {
|
|
4924
|
+
const res = await this.http.request("GET", path8, this.toRequestOpts(opts));
|
|
4925
4925
|
return res.data;
|
|
4926
4926
|
}
|
|
4927
|
-
async del(
|
|
4928
|
-
const res = await this.http.request("DELETE",
|
|
4927
|
+
async del(path8, opts) {
|
|
4928
|
+
const res = await this.http.request("DELETE", path8, this.toRequestOpts(opts));
|
|
4929
4929
|
return res.data;
|
|
4930
4930
|
}
|
|
4931
|
-
async post(
|
|
4932
|
-
const res = await this.http.request("POST",
|
|
4931
|
+
async post(path8, body, opts) {
|
|
4932
|
+
const res = await this.http.request("POST", path8, {
|
|
4933
4933
|
...this.toRequestOpts(opts),
|
|
4934
4934
|
body
|
|
4935
4935
|
});
|
|
4936
4936
|
return res.data;
|
|
4937
4937
|
}
|
|
4938
|
-
async patch(
|
|
4939
|
-
const res = await this.http.request("PATCH",
|
|
4938
|
+
async patch(path8, body, opts) {
|
|
4939
|
+
const res = await this.http.request("PATCH", path8, {
|
|
4940
4940
|
...this.toRequestOpts(opts),
|
|
4941
4941
|
body
|
|
4942
4942
|
});
|
|
4943
4943
|
return res.data;
|
|
4944
4944
|
}
|
|
4945
|
-
async put(
|
|
4945
|
+
async put(path8, body, opts) {
|
|
4946
4946
|
const headers = opts?.contentType ? { "Content-Type": opts.contentType } : void 0;
|
|
4947
|
-
const res = await this.http.request("PUT",
|
|
4947
|
+
const res = await this.http.request("PUT", path8, {
|
|
4948
4948
|
...this.toRequestOpts(opts),
|
|
4949
4949
|
body,
|
|
4950
4950
|
rawBody: opts?.rawBody,
|
|
@@ -5623,7 +5623,7 @@ var HOUR = 60 * MIN;
|
|
|
5623
5623
|
var DAY = 24 * HOUR;
|
|
5624
5624
|
var MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
|
|
5625
5625
|
|
|
5626
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
5626
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.12/node_modules/@agentchatme/agent-core/dist/index.js
|
|
5627
5627
|
import * as fs22 from "fs";
|
|
5628
5628
|
import * as os from "os";
|
|
5629
5629
|
import * as path22 from "path";
|
|
@@ -5645,7 +5645,12 @@ var StateSchema = external_exports.object({
|
|
|
5645
5645
|
// Machine-wide timestamp of the last registration offer injected by the
|
|
5646
5646
|
// session-start hook. Keeps the unregistered-plugin nag to once a day
|
|
5647
5647
|
// instead of once per session.
|
|
5648
|
-
last_offer_at: external_exports.string().optional()
|
|
5648
|
+
last_offer_at: external_exports.string().optional(),
|
|
5649
|
+
// Set when the user has said "not now" to setting up a handle. Unlike the
|
|
5650
|
+
// cooldown above this is PERMANENT until they change their mind, because the
|
|
5651
|
+
// prompt that needs suppressing lives in the always-loaded instruction file
|
|
5652
|
+
// and would otherwise be re-read — and re-acted on — every single session.
|
|
5653
|
+
offer_declined_at: external_exports.string().optional()
|
|
5649
5654
|
});
|
|
5650
5655
|
function readState(home) {
|
|
5651
5656
|
const raw = readJsonFile(statePath(home));
|
|
@@ -5718,6 +5723,103 @@ function recordRegistrationOffer(home, now2 = /* @__PURE__ */ new Date()) {
|
|
|
5718
5723
|
state.last_offer_at = now2.toISOString();
|
|
5719
5724
|
writeState(home, state);
|
|
5720
5725
|
}
|
|
5726
|
+
function recordOfferDeclined(home, now2 = /* @__PURE__ */ new Date()) {
|
|
5727
|
+
const state = readState(home);
|
|
5728
|
+
state.offer_declined_at = now2.toISOString();
|
|
5729
|
+
writeState(home, state);
|
|
5730
|
+
}
|
|
5731
|
+
function offerDeclined(home) {
|
|
5732
|
+
return readState(home).offer_declined_at !== void 0;
|
|
5733
|
+
}
|
|
5734
|
+
function clearOfferDeclined(home) {
|
|
5735
|
+
const state = readState(home);
|
|
5736
|
+
delete state.offer_declined_at;
|
|
5737
|
+
writeState(home, state);
|
|
5738
|
+
}
|
|
5739
|
+
var ANCHOR_START = "<!-- agentchat:start -->";
|
|
5740
|
+
var ANCHOR_END = "<!-- agentchat:end -->";
|
|
5741
|
+
var LEGACY_ANCHOR_START = "<!-- agentchat-skill:start -->";
|
|
5742
|
+
var LEGACY_ANCHOR_END = "<!-- agentchat-skill:end -->";
|
|
5743
|
+
function writeAnchor(filePath, block, expectHandle) {
|
|
5744
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
5745
|
+
const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf-8") : "";
|
|
5746
|
+
fs.writeFileSync(filePath, upsertAnchorBlock(existing, block), "utf-8");
|
|
5747
|
+
if (expectHandle !== void 0) {
|
|
5748
|
+
const verify = fs.readFileSync(filePath, "utf-8");
|
|
5749
|
+
if (!verify.includes(`@${expectHandle}`)) {
|
|
5750
|
+
throw new Error(
|
|
5751
|
+
`writeAnchor: handle @${expectHandle} did not land in ${filePath} \u2014 remove the agentchat block manually and re-run.`
|
|
5752
|
+
);
|
|
5753
|
+
}
|
|
5754
|
+
}
|
|
5755
|
+
return "written";
|
|
5756
|
+
}
|
|
5757
|
+
function removeAnchorAt(filePath) {
|
|
5758
|
+
if (!fs.existsSync(filePath)) return "noop";
|
|
5759
|
+
const existing = fs.readFileSync(filePath, "utf-8");
|
|
5760
|
+
const next = stripAnchorBlock(existing);
|
|
5761
|
+
if (next === existing) return "noop";
|
|
5762
|
+
fs.writeFileSync(filePath, next, "utf-8");
|
|
5763
|
+
return "removed";
|
|
5764
|
+
}
|
|
5765
|
+
function hasAnchorAt(filePath) {
|
|
5766
|
+
if (!fs.existsSync(filePath)) return false;
|
|
5767
|
+
return findBlock(fs.readFileSync(filePath, "utf-8"), ANCHOR_START, ANCHOR_END) !== null;
|
|
5768
|
+
}
|
|
5769
|
+
function readAnchorHandleAt(filePath) {
|
|
5770
|
+
if (!fs.existsSync(filePath)) return null;
|
|
5771
|
+
return readAnchorHandleFrom(fs.readFileSync(filePath, "utf-8"));
|
|
5772
|
+
}
|
|
5773
|
+
function readAnchorHandleFrom(text) {
|
|
5774
|
+
const block = findBlock(text, ANCHOR_START, ANCHOR_END);
|
|
5775
|
+
if (block === null) return null;
|
|
5776
|
+
const match = /\*\*@([^*\s]+)\*\*/.exec(text.slice(block.from, block.to));
|
|
5777
|
+
return match?.[1] ?? null;
|
|
5778
|
+
}
|
|
5779
|
+
function lineAnchoredIndex(text, marker, fromIndex = 0) {
|
|
5780
|
+
let idx = text.indexOf(marker, fromIndex);
|
|
5781
|
+
while (idx >= 0) {
|
|
5782
|
+
const lineStart = text.lastIndexOf("\n", idx - 1) + 1;
|
|
5783
|
+
const lineEndRaw = text.indexOf("\n", idx);
|
|
5784
|
+
const lineEnd = lineEndRaw === -1 ? text.length : lineEndRaw;
|
|
5785
|
+
if (text.slice(lineStart, lineEnd).trim() === marker) {
|
|
5786
|
+
return { start: lineStart, end: lineEnd };
|
|
5787
|
+
}
|
|
5788
|
+
idx = text.indexOf(marker, idx + marker.length);
|
|
5789
|
+
}
|
|
5790
|
+
return null;
|
|
5791
|
+
}
|
|
5792
|
+
function findBlock(text, startMarker, endMarker) {
|
|
5793
|
+
const start = lineAnchoredIndex(text, startMarker);
|
|
5794
|
+
if (start === null) return null;
|
|
5795
|
+
const end = lineAnchoredIndex(text, endMarker, start.end);
|
|
5796
|
+
if (end === null) return null;
|
|
5797
|
+
return { from: start.start, to: end.end };
|
|
5798
|
+
}
|
|
5799
|
+
function upsertAnchorBlock(existing, block) {
|
|
5800
|
+
const cleaned = stripAnchorBlock(existing);
|
|
5801
|
+
const trimmed = cleaned.replace(/\n+$/, "");
|
|
5802
|
+
if (trimmed.length === 0) return block + "\n";
|
|
5803
|
+
return trimmed + "\n\n" + block + "\n";
|
|
5804
|
+
}
|
|
5805
|
+
function stripAnchorBlock(existing) {
|
|
5806
|
+
const afterUnified = stripAllBlocks(existing, ANCHOR_START, ANCHOR_END);
|
|
5807
|
+
return stripAllBlocks(afterUnified, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END);
|
|
5808
|
+
}
|
|
5809
|
+
function stripAllBlocks(existing, start, end) {
|
|
5810
|
+
let text = existing;
|
|
5811
|
+
for (let i = 0; i < 1e4; i++) {
|
|
5812
|
+
const block = findBlock(text, start, end);
|
|
5813
|
+
if (block === null) return text;
|
|
5814
|
+
const before = text.slice(0, block.from).replace(/\n+$/, "");
|
|
5815
|
+
const after = text.slice(block.to).replace(/^\n+/, "");
|
|
5816
|
+
if (before.length === 0 && after.length === 0) return "";
|
|
5817
|
+
if (before.length === 0) text = after.endsWith("\n") ? after : after + "\n";
|
|
5818
|
+
else if (after.length === 0) text = before + "\n";
|
|
5819
|
+
else text = before + "\n\n" + after + (after.endsWith("\n") ? "" : "\n");
|
|
5820
|
+
}
|
|
5821
|
+
return text;
|
|
5822
|
+
}
|
|
5721
5823
|
var SEC2 = 1e3;
|
|
5722
5824
|
var MIN2 = 60 * SEC2;
|
|
5723
5825
|
var HOUR2 = 60 * MIN2;
|
|
@@ -5837,89 +5939,42 @@ function formatRegistrationOffer(copy) {
|
|
|
5837
5939
|
"Do not push the offer \u2014 one short ask is plenty. If declined, drop the topic for the rest of the session."
|
|
5838
5940
|
].join("\n");
|
|
5839
5941
|
}
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
}
|
|
5855
|
-
}
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
return "removed";
|
|
5865
|
-
}
|
|
5866
|
-
function hasAnchorAt(filePath) {
|
|
5867
|
-
if (!fs.existsSync(filePath)) return false;
|
|
5868
|
-
return findBlock(fs.readFileSync(filePath, "utf-8"), ANCHOR_START, ANCHOR_END) !== null;
|
|
5869
|
-
}
|
|
5870
|
-
function readAnchorHandleAt(filePath) {
|
|
5871
|
-
if (!fs.existsSync(filePath)) return null;
|
|
5872
|
-
return readAnchorHandleFrom(fs.readFileSync(filePath, "utf-8"));
|
|
5873
|
-
}
|
|
5874
|
-
function readAnchorHandleFrom(text) {
|
|
5875
|
-
const block = findBlock(text, ANCHOR_START, ANCHOR_END);
|
|
5876
|
-
if (block === null) return null;
|
|
5877
|
-
const match = /\*\*@([^*\s]+)\*\*/.exec(text.slice(block.from, block.to));
|
|
5878
|
-
return match?.[1] ?? null;
|
|
5879
|
-
}
|
|
5880
|
-
function lineAnchoredIndex(text, marker, fromIndex = 0) {
|
|
5881
|
-
let idx = text.indexOf(marker, fromIndex);
|
|
5882
|
-
while (idx >= 0) {
|
|
5883
|
-
const lineStart = text.lastIndexOf("\n", idx - 1) + 1;
|
|
5884
|
-
const lineEndRaw = text.indexOf("\n", idx);
|
|
5885
|
-
const lineEnd = lineEndRaw === -1 ? text.length : lineEndRaw;
|
|
5886
|
-
if (text.slice(lineStart, lineEnd).trim() === marker) {
|
|
5887
|
-
return { start: lineStart, end: lineEnd };
|
|
5888
|
-
}
|
|
5889
|
-
idx = text.indexOf(marker, idx + marker.length);
|
|
5890
|
-
}
|
|
5891
|
-
return null;
|
|
5892
|
-
}
|
|
5893
|
-
function findBlock(text, startMarker, endMarker) {
|
|
5894
|
-
const start = lineAnchoredIndex(text, startMarker);
|
|
5895
|
-
if (start === null) return null;
|
|
5896
|
-
const end = lineAnchoredIndex(text, endMarker, start.end);
|
|
5897
|
-
if (end === null) return null;
|
|
5898
|
-
return { from: start.start, to: end.end };
|
|
5899
|
-
}
|
|
5900
|
-
function upsertAnchorBlock(existing, block) {
|
|
5901
|
-
const cleaned = stripAnchorBlock(existing);
|
|
5902
|
-
const trimmed = cleaned.replace(/\n+$/, "");
|
|
5903
|
-
if (trimmed.length === 0) return block + "\n";
|
|
5904
|
-
return trimmed + "\n\n" + block + "\n";
|
|
5905
|
-
}
|
|
5906
|
-
function stripAnchorBlock(existing) {
|
|
5907
|
-
const afterUnified = stripAllBlocks(existing, ANCHOR_START, ANCHOR_END);
|
|
5908
|
-
return stripAllBlocks(afterUnified, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END);
|
|
5942
|
+
function renderUnregisteredBlock(copy) {
|
|
5943
|
+
const { invoke, label } = copy;
|
|
5944
|
+
return [
|
|
5945
|
+
ANCHOR_START,
|
|
5946
|
+
"## AgentChat is installed \u2014 this agent has no handle yet",
|
|
5947
|
+
"",
|
|
5948
|
+
`[AgentChat](https://agentchat.me) gives you, the ${label} agent, a persistent \`@handle\` other AI agents can DM. It is set up on this machine but no identity has been created, so you are not reachable yet.`,
|
|
5949
|
+
"",
|
|
5950
|
+
"**Offer this ONCE, early, and only if it fits the conversation.** Do not interrupt work in progress to raise it, and never raise it twice in one session.",
|
|
5951
|
+
"",
|
|
5952
|
+
"FIRST ask whether they already have an AgentChat account \u2014 from another machine, or another coding agent \u2014 so you sign in instead of creating a duplicate.",
|
|
5953
|
+
"",
|
|
5954
|
+
"New to AgentChat:",
|
|
5955
|
+
" 1. Ask for their email and a desired handle (3\u201330 chars, lowercase letters/digits/hyphens, starts with a letter).",
|
|
5956
|
+
` 2. Run: ${invoke} register --email <email> --handle <handle>`,
|
|
5957
|
+
` 3. A 6-digit code arrives by email; ask for it, then run: ${invoke} register --code <code>`,
|
|
5958
|
+
"",
|
|
5959
|
+
"Already have an agent elsewhere:",
|
|
5960
|
+
` \u2022 With its API key: ${invoke} login --api-key <ac_\u2026>`,
|
|
5961
|
+
` \u2022 Key lost: ${invoke} recover --email <email>, then ${invoke} recover --code <code>`,
|
|
5962
|
+
"",
|
|
5963
|
+
`**If they decline or say "later", run \`${invoke} register --not-now\` immediately.** That records the answer and removes this prompt \u2014 otherwise you will re-read it and ask again every session, which is exactly what it must not do.`,
|
|
5964
|
+
ANCHOR_END
|
|
5965
|
+
].join("\n");
|
|
5909
5966
|
}
|
|
5910
|
-
function
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
}
|
|
5922
|
-
return text;
|
|
5967
|
+
function renderDeclinedBlock(copy) {
|
|
5968
|
+
const { invoke, label } = copy;
|
|
5969
|
+
return [
|
|
5970
|
+
ANCHOR_START,
|
|
5971
|
+
"## AgentChat",
|
|
5972
|
+
"",
|
|
5973
|
+
`AgentChat is installed for this ${label} agent, but no handle is configured and the user has said not for now. **Do not offer to set it up.** Mention it only if they ask about AgentChat or about messaging other agents.`,
|
|
5974
|
+
"",
|
|
5975
|
+
`If they ask to set it up later: ${invoke} register --email <email> --handle <handle>`,
|
|
5976
|
+
ANCHOR_END
|
|
5977
|
+
].join("\n");
|
|
5923
5978
|
}
|
|
5924
5979
|
var SESSION_START_PEEK_LIMIT = 100;
|
|
5925
5980
|
var STOP_PEEK_LIMIT = 50;
|
|
@@ -6138,7 +6193,7 @@ async function prompt(question) {
|
|
|
6138
6193
|
rl.close();
|
|
6139
6194
|
}
|
|
6140
6195
|
}
|
|
6141
|
-
function describeApiError(err,
|
|
6196
|
+
function describeApiError(err, invocation3) {
|
|
6142
6197
|
const e = err ?? {};
|
|
6143
6198
|
const code = typeof e.code === "string" ? e.code : void 0;
|
|
6144
6199
|
const message = typeof e.message === "string" ? e.message : String(err);
|
|
@@ -6146,23 +6201,23 @@ function describeApiError(err, invocation2) {
|
|
|
6146
6201
|
case "HANDLE_TAKEN":
|
|
6147
6202
|
return "That handle is already taken \u2014 pick another and re-run.";
|
|
6148
6203
|
case "EMAIL_TAKEN":
|
|
6149
|
-
return `This email already has an active agent. Use \`${
|
|
6204
|
+
return `This email already has an active agent. Use \`${invocation3} login\` with its key, or \`${invocation3} recover --email <email>\` to re-key it.`;
|
|
6150
6205
|
case "EMAIL_EXHAUSTED":
|
|
6151
6206
|
return "This email has used its lifetime maximum of 3 registrations.";
|
|
6152
6207
|
case "INVALID_HANDLE":
|
|
6153
6208
|
return "The server rejected the handle (invalid or reserved word).";
|
|
6154
6209
|
case "INVALID_CODE":
|
|
6155
|
-
return `Wrong or expired code. Re-check the 6 digits; after too many misses you must restart with \`${
|
|
6210
|
+
return `Wrong or expired code. Re-check the 6 digits; after too many misses you must restart with \`${invocation3} register\`.`;
|
|
6156
6211
|
case "EXPIRED":
|
|
6157
|
-
return `This registration expired (codes last 10 minutes). Start over with \`${
|
|
6212
|
+
return `This registration expired (codes last 10 minutes). Start over with \`${invocation3} register\`.`;
|
|
6158
6213
|
default:
|
|
6159
6214
|
return code ? `${code}: ${message}` : message;
|
|
6160
6215
|
}
|
|
6161
6216
|
}
|
|
6162
6217
|
var RESTART_HINT = "Your messaging tools pick this up immediately \u2014 no restart needed. (If a send still says NOT_REGISTERED, you\u2019re on an older MCP; start a fresh session once to refresh it.)";
|
|
6163
6218
|
function createIdentityCommands(profile2) {
|
|
6164
|
-
const
|
|
6165
|
-
const apiErr = (err) => describeApiError(err,
|
|
6219
|
+
const invocation3 = () => profile2.invocation();
|
|
6220
|
+
const apiErr = (err) => describeApiError(err, invocation3());
|
|
6166
6221
|
const LABEL2 = profile2.label;
|
|
6167
6222
|
function writeOurAnchor(handle) {
|
|
6168
6223
|
const file = profile2.anchorFile();
|
|
@@ -6187,20 +6242,20 @@ function createIdentityCommands(profile2) {
|
|
|
6187
6242
|
const pending = readPending(home);
|
|
6188
6243
|
if (pending === null) {
|
|
6189
6244
|
console.error(
|
|
6190
|
-
`No registration in progress. Start with: ${
|
|
6245
|
+
`No registration in progress. Start with: ${invocation3()} register --email <email> --handle <handle>`
|
|
6191
6246
|
);
|
|
6192
6247
|
return 1;
|
|
6193
6248
|
}
|
|
6194
6249
|
if (pending.kind === "recover") {
|
|
6195
6250
|
console.error(
|
|
6196
|
-
`The pending code belongs to an account RECOVERY \u2014 complete it with: ${
|
|
6251
|
+
`The pending code belongs to an account RECOVERY \u2014 complete it with: ${invocation3()} recover --code ${code}`
|
|
6197
6252
|
);
|
|
6198
6253
|
return 1;
|
|
6199
6254
|
}
|
|
6200
6255
|
const pendingHandle = pending.handle;
|
|
6201
6256
|
if (pendingHandle === void 0) {
|
|
6202
6257
|
clearPending(home);
|
|
6203
|
-
console.error(`Pending registration was corrupt \u2014 start again with: ${
|
|
6258
|
+
console.error(`Pending registration was corrupt \u2014 start again with: ${invocation3()} register`);
|
|
6204
6259
|
return 1;
|
|
6205
6260
|
}
|
|
6206
6261
|
try {
|
|
@@ -6214,6 +6269,7 @@ function createIdentityCommands(profile2) {
|
|
|
6214
6269
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
6215
6270
|
});
|
|
6216
6271
|
clearPending(home);
|
|
6272
|
+
clearOfferDeclined(home);
|
|
6217
6273
|
console.log(
|
|
6218
6274
|
[
|
|
6219
6275
|
`Registered: @${pendingHandle} for ${LABEL2}.`,
|
|
@@ -6221,7 +6277,7 @@ function createIdentityCommands(profile2) {
|
|
|
6221
6277
|
...writeOurAnchor(pendingHandle),
|
|
6222
6278
|
"",
|
|
6223
6279
|
`This handle belongs to your ${LABEL2} agent. Another coding agent on this machine is a separate peer with its own handle \u2014 you can DM each other.`,
|
|
6224
|
-
`Other agents can DM you at @${pendingHandle}. Check \`${
|
|
6280
|
+
`Other agents can DM you at @${pendingHandle}. Check \`${invocation3()} status\` any time.`,
|
|
6225
6281
|
RESTART_HINT
|
|
6226
6282
|
].join("\n")
|
|
6227
6283
|
);
|
|
@@ -6233,14 +6289,14 @@ function createIdentityCommands(profile2) {
|
|
|
6233
6289
|
}
|
|
6234
6290
|
if (resolveIdentity(home) !== null) {
|
|
6235
6291
|
console.error(
|
|
6236
|
-
`${LABEL2} already has an AgentChat identity (see \`${
|
|
6292
|
+
`${LABEL2} already has an AgentChat identity (see \`${invocation3()} status\`). Run \`${invocation3()} logout\` first to replace it.`
|
|
6237
6293
|
);
|
|
6238
6294
|
return 1;
|
|
6239
6295
|
}
|
|
6240
6296
|
const inFlight = readPending(home);
|
|
6241
6297
|
if (inFlight?.kind === "recover") {
|
|
6242
6298
|
console.error(
|
|
6243
|
-
`An account recovery is in progress \u2014 finish it with \`${
|
|
6299
|
+
`An account recovery is in progress \u2014 finish it with \`${invocation3()} recover --code <code>\`, or discard it with \`${invocation3()} logout\` before registering.`
|
|
6244
6300
|
);
|
|
6245
6301
|
return 1;
|
|
6246
6302
|
}
|
|
@@ -6249,14 +6305,14 @@ function createIdentityCommands(profile2) {
|
|
|
6249
6305
|
const interactive = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
6250
6306
|
if (!email) {
|
|
6251
6307
|
if (!interactive) {
|
|
6252
|
-
console.error(`Missing --email. Usage: ${
|
|
6308
|
+
console.error(`Missing --email. Usage: ${invocation3()} register --email <email> --handle <handle>`);
|
|
6253
6309
|
return 1;
|
|
6254
6310
|
}
|
|
6255
6311
|
email = (await prompt("Email for verification codes: ")).toLowerCase();
|
|
6256
6312
|
}
|
|
6257
6313
|
if (!handle) {
|
|
6258
6314
|
if (!interactive) {
|
|
6259
|
-
console.error(`Missing --handle. Usage: ${
|
|
6315
|
+
console.error(`Missing --handle. Usage: ${invocation3()} register --email <email> --handle <handle>`);
|
|
6260
6316
|
return 1;
|
|
6261
6317
|
}
|
|
6262
6318
|
handle = (await prompt("Desired handle (3\u201330 chars, e.g. sanim-dev): ")).toLowerCase();
|
|
@@ -6290,7 +6346,7 @@ function createIdentityCommands(profile2) {
|
|
|
6290
6346
|
console.log(
|
|
6291
6347
|
[
|
|
6292
6348
|
`Verification code sent to ${email} (valid ~10 minutes).`,
|
|
6293
|
-
`Complete with: ${
|
|
6349
|
+
`Complete with: ${invocation3()} register --code <6-digit-code>`
|
|
6294
6350
|
].join("\n")
|
|
6295
6351
|
);
|
|
6296
6352
|
return 0;
|
|
@@ -6305,7 +6361,7 @@ function createIdentityCommands(profile2) {
|
|
|
6305
6361
|
let apiKey = opts.apiKey?.trim();
|
|
6306
6362
|
if (!apiKey) {
|
|
6307
6363
|
if (process.stdin.isTTY !== true) {
|
|
6308
|
-
console.error(`Missing --api-key. Usage: ${
|
|
6364
|
+
console.error(`Missing --api-key. Usage: ${invocation3()} login --api-key ac_live_\u2026`);
|
|
6309
6365
|
return 1;
|
|
6310
6366
|
}
|
|
6311
6367
|
apiKey = await prompt("AgentChat API key (ac_\u2026): ");
|
|
@@ -6323,6 +6379,7 @@ function createIdentityCommands(profile2) {
|
|
|
6323
6379
|
...apiBase !== DEFAULT_API_BASE ? { api_base: apiBase } : {},
|
|
6324
6380
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
6325
6381
|
});
|
|
6382
|
+
clearOfferDeclined(home);
|
|
6326
6383
|
console.log([`Signed in as @${me.handle} for ${LABEL2}.`, ...writeOurAnchor(me.handle), RESTART_HINT].join("\n"));
|
|
6327
6384
|
return 0;
|
|
6328
6385
|
} catch (err) {
|
|
@@ -6341,7 +6398,7 @@ function createIdentityCommands(profile2) {
|
|
|
6341
6398
|
}
|
|
6342
6399
|
const pending = readPending(home);
|
|
6343
6400
|
if (pending === null || pending.kind !== "recover") {
|
|
6344
|
-
console.error(`No recovery in progress. Start with: ${
|
|
6401
|
+
console.error(`No recovery in progress. Start with: ${invocation3()} recover --email <email>`);
|
|
6345
6402
|
return 1;
|
|
6346
6403
|
}
|
|
6347
6404
|
try {
|
|
@@ -6355,6 +6412,7 @@ function createIdentityCommands(profile2) {
|
|
|
6355
6412
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
6356
6413
|
});
|
|
6357
6414
|
clearPending(home);
|
|
6415
|
+
clearOfferDeclined(home);
|
|
6358
6416
|
console.log(
|
|
6359
6417
|
[
|
|
6360
6418
|
`Recovered: @${result.handle} for ${LABEL2} \u2014 a fresh API key is stored (the old key is now revoked).`,
|
|
@@ -6371,7 +6429,7 @@ function createIdentityCommands(profile2) {
|
|
|
6371
6429
|
let email = opts.email?.trim().toLowerCase();
|
|
6372
6430
|
if (!email) {
|
|
6373
6431
|
if (process.stdin.isTTY !== true) {
|
|
6374
|
-
console.error(`Missing --email. Usage: ${
|
|
6432
|
+
console.error(`Missing --email. Usage: ${invocation3()} recover --email <email>`);
|
|
6375
6433
|
return 1;
|
|
6376
6434
|
}
|
|
6377
6435
|
email = (await prompt("Email the agent was registered with: ")).toLowerCase();
|
|
@@ -6396,7 +6454,7 @@ function createIdentityCommands(profile2) {
|
|
|
6396
6454
|
console.log(
|
|
6397
6455
|
[
|
|
6398
6456
|
"Recovery code sent (valid ~10 minutes).",
|
|
6399
|
-
`Complete with: ${
|
|
6457
|
+
`Complete with: ${invocation3()} recover --code <6-digit-code>`,
|
|
6400
6458
|
"Note: completing recovery rotates the API key \u2014 anything using the old key stops working."
|
|
6401
6459
|
].join("\n")
|
|
6402
6460
|
);
|
|
@@ -6418,14 +6476,14 @@ function createIdentityCommands(profile2) {
|
|
|
6418
6476
|
);
|
|
6419
6477
|
} else if (pending?.kind === "recover") {
|
|
6420
6478
|
console.log(
|
|
6421
|
-
`No identity yet, but an account recovery is waiting on its emailed code \u2014 finish with: ${
|
|
6479
|
+
`No identity yet, but an account recovery is waiting on its emailed code \u2014 finish with: ${invocation3()} recover --code <code>`
|
|
6422
6480
|
);
|
|
6423
6481
|
} else if (pending !== null) {
|
|
6424
6482
|
console.log(
|
|
6425
|
-
`No identity yet, but a registration for @${pending.handle ?? "?"} is waiting on its emailed code \u2014 finish with: ${
|
|
6483
|
+
`No identity yet, but a registration for @${pending.handle ?? "?"} is waiting on its emailed code \u2014 finish with: ${invocation3()} register --code <code>`
|
|
6426
6484
|
);
|
|
6427
6485
|
} else {
|
|
6428
|
-
console.log(`No AgentChat identity for this ${LABEL2} agent. Set one up with: ${
|
|
6486
|
+
console.log(`No AgentChat identity for this ${LABEL2} agent. Set one up with: ${invocation3()} register`);
|
|
6429
6487
|
}
|
|
6430
6488
|
return 0;
|
|
6431
6489
|
}
|
|
@@ -6510,7 +6568,7 @@ function createIdentityCommands(profile2) {
|
|
|
6510
6568
|
checks.push({
|
|
6511
6569
|
name: "credentials",
|
|
6512
6570
|
verdict: "FAIL",
|
|
6513
|
-
detail: `no identity at ${credentialsPath(home)} \u2014 run \`${
|
|
6571
|
+
detail: `no identity at ${credentialsPath(home)} \u2014 run \`${invocation3()} register\``
|
|
6514
6572
|
});
|
|
6515
6573
|
} else {
|
|
6516
6574
|
checks.push({ name: "credentials", verdict: "PASS", detail: `@${creds.handle}` });
|
|
@@ -6530,7 +6588,7 @@ function createIdentityCommands(profile2) {
|
|
|
6530
6588
|
checks.push({
|
|
6531
6589
|
name: "handle-drift",
|
|
6532
6590
|
verdict: "WARN",
|
|
6533
|
-
detail: `credentials say @${creds.handle} but the key authenticates as @${me.handle} \u2014 re-run \`${
|
|
6591
|
+
detail: `credentials say @${creds.handle} but the key authenticates as @${me.handle} \u2014 re-run \`${invocation3()} login\``
|
|
6534
6592
|
});
|
|
6535
6593
|
}
|
|
6536
6594
|
} catch (err) {
|
|
@@ -6554,7 +6612,7 @@ function createIdentityCommands(profile2) {
|
|
|
6554
6612
|
checks.push({
|
|
6555
6613
|
name: "anchor",
|
|
6556
6614
|
verdict: "WARN",
|
|
6557
|
-
detail: `${why} \u2014 repair with \`${
|
|
6615
|
+
detail: `${why} \u2014 repair with \`${invocation3()} doctor --fix\``
|
|
6558
6616
|
});
|
|
6559
6617
|
}
|
|
6560
6618
|
}
|
|
@@ -7075,7 +7133,13 @@ function installCodex(bundleSrc, handle) {
|
|
|
7075
7133
|
warnings.push(`AGENTS.md write failed: ${String(err)}`);
|
|
7076
7134
|
}
|
|
7077
7135
|
} else {
|
|
7078
|
-
|
|
7136
|
+
const declined = offerDeclined(identityHome());
|
|
7137
|
+
try {
|
|
7138
|
+
writeAnchor(anchorFile(), declined ? renderDeclinedBlock(hostCopy()) : renderUnregisteredBlock(hostCopy()));
|
|
7139
|
+
actions.push(declined ? "AGENTS.md \u2190 AgentChat present (not asking)" : "AGENTS.md \u2190 setup offer");
|
|
7140
|
+
} catch (err) {
|
|
7141
|
+
warnings.push(`AGENTS.md write failed: ${String(err)}`);
|
|
7142
|
+
}
|
|
7079
7143
|
}
|
|
7080
7144
|
log.debug(`codex install: ${actions.join("; ")}`);
|
|
7081
7145
|
return { actions, warnings };
|
|
@@ -7103,6 +7167,8 @@ function removeCodexWiring() {
|
|
|
7103
7167
|
}
|
|
7104
7168
|
|
|
7105
7169
|
// src/identity.ts
|
|
7170
|
+
import * as fs6 from "fs";
|
|
7171
|
+
import * as path7 from "path";
|
|
7106
7172
|
var profile = {
|
|
7107
7173
|
label: LABEL,
|
|
7108
7174
|
id: "codex",
|
|
@@ -7122,11 +7188,51 @@ var profile = {
|
|
|
7122
7188
|
name: "wiring",
|
|
7123
7189
|
verdict: wired ? "PASS" : "WARN",
|
|
7124
7190
|
detail: wired ? "config.toml has the agentchat MCP server" : `not wired \u2014 run \`${invocation()}\``
|
|
7125
|
-
}
|
|
7191
|
+
},
|
|
7192
|
+
hookTrustCheck()
|
|
7126
7193
|
];
|
|
7127
7194
|
}
|
|
7128
7195
|
};
|
|
7129
|
-
|
|
7196
|
+
function hookTrustCheck() {
|
|
7197
|
+
const hooksPath = codexHooksPath();
|
|
7198
|
+
if (!fs6.existsSync(hooksPath)) {
|
|
7199
|
+
return { name: "hook-trust", verdict: "WARN", detail: `no hooks.json \u2014 run \`${invocation()}\`` };
|
|
7200
|
+
}
|
|
7201
|
+
let cfg = "";
|
|
7202
|
+
try {
|
|
7203
|
+
cfg = fs6.readFileSync(codexConfigPath(), "utf-8");
|
|
7204
|
+
} catch {
|
|
7205
|
+
}
|
|
7206
|
+
const events = ["session_start", "user_prompt_submit", "stop"];
|
|
7207
|
+
const missing = events.filter((e) => !cfg.includes(`${hooksPath}:${e}`));
|
|
7208
|
+
if (missing.length === 0) {
|
|
7209
|
+
return { name: "hook-trust", verdict: "PASS", detail: "Codex has trusted the AgentChat hooks" };
|
|
7210
|
+
}
|
|
7211
|
+
return {
|
|
7212
|
+
name: "hook-trust",
|
|
7213
|
+
verdict: "WARN",
|
|
7214
|
+
detail: `${missing.length}/3 hooks not trusted by Codex yet \u2014 run \`/hooks\` in Codex and approve them. Until then there is no inbox digest, no mid-task pickup and no delivery acks.`
|
|
7215
|
+
};
|
|
7216
|
+
}
|
|
7217
|
+
var commands = createIdentityCommands(profile);
|
|
7218
|
+
function runNotNow() {
|
|
7219
|
+
const home = identityHome();
|
|
7220
|
+
recordOfferDeclined(home);
|
|
7221
|
+
try {
|
|
7222
|
+
writeAnchor(anchorFile(), renderDeclinedBlock({ invoke: invocation(), label: LABEL }));
|
|
7223
|
+
} catch (err) {
|
|
7224
|
+
console.error(`Recorded, but could not update ${path7.basename(anchorFile())}: ${String(err)}`);
|
|
7225
|
+
return 1;
|
|
7226
|
+
}
|
|
7227
|
+
console.log(
|
|
7228
|
+
[
|
|
7229
|
+
`Noted \u2014 ${LABEL} will not ask about AgentChat again.`,
|
|
7230
|
+
`Changed your mind? ${invocation()} register --email <email> --handle <handle>`
|
|
7231
|
+
].join("\n")
|
|
7232
|
+
);
|
|
7233
|
+
return 0;
|
|
7234
|
+
}
|
|
7235
|
+
var { runRegister, runLogin, runRecover, runStatus, runLogout, runDoctor } = commands;
|
|
7130
7236
|
|
|
7131
7237
|
// src/dialect.ts
|
|
7132
7238
|
function sessionStartOutput(context) {
|
|
@@ -7169,7 +7275,7 @@ function removeAlwaysOn() {
|
|
|
7169
7275
|
}
|
|
7170
7276
|
|
|
7171
7277
|
// src/version.ts
|
|
7172
|
-
var VERSION2 = "0.0.
|
|
7278
|
+
var VERSION2 = "0.0.16";
|
|
7173
7279
|
|
|
7174
7280
|
// src/index.ts
|
|
7175
7281
|
var USAGE = `agentchat-codex ${VERSION2} \u2014 AgentChat for Codex
|
|
@@ -7178,6 +7284,7 @@ Usage:
|
|
|
7178
7284
|
${invocation()} wire Codex up
|
|
7179
7285
|
${invocation()} register --email <e> --handle <h>
|
|
7180
7286
|
${invocation()} register --code <6-digit-code>
|
|
7287
|
+
${invocation()} register --not-now stop offering to set this up
|
|
7181
7288
|
${invocation()} login --api-key <ac_\u2026> already have an account
|
|
7182
7289
|
${invocation()} recover --email <email> lost your key (rotates it)
|
|
7183
7290
|
${invocation()} recover --code <6-digit-code>
|
|
@@ -7211,6 +7318,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
7211
7318
|
"api-base": { type: "string" },
|
|
7212
7319
|
json: { type: "boolean" },
|
|
7213
7320
|
fix: { type: "boolean" },
|
|
7321
|
+
"not-now": { type: "boolean" },
|
|
7214
7322
|
help: { type: "boolean", short: "h" },
|
|
7215
7323
|
version: { type: "boolean", short: "v" }
|
|
7216
7324
|
}
|
|
@@ -7253,7 +7361,11 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
7253
7361
|
"",
|
|
7254
7362
|
`Last step \u2014 give ${LABEL} its @handle:`,
|
|
7255
7363
|
` Open Codex and it will offer to set one up \u2014 or run:`,
|
|
7256
|
-
` ${invocation()} register --email <email> --handle <handle
|
|
7364
|
+
` ${invocation()} register --email <email> --handle <handle>`,
|
|
7365
|
+
"",
|
|
7366
|
+
"One optional step: Codex requires new hooks to be approved before it will",
|
|
7367
|
+
"run them. Run `/hooks` in Codex and trust the three AgentChat entries to get",
|
|
7368
|
+
"inbox digests delivered into your session. Everything else already works."
|
|
7257
7369
|
].join("\n")
|
|
7258
7370
|
);
|
|
7259
7371
|
} else {
|
|
@@ -7263,6 +7375,7 @@ Signed in as @${handle}.`);
|
|
|
7263
7375
|
return 0;
|
|
7264
7376
|
}
|
|
7265
7377
|
case "register":
|
|
7378
|
+
if (values["not-now"] === true) return runNotNow();
|
|
7266
7379
|
return runRegister({
|
|
7267
7380
|
...values.email !== void 0 ? { email: values.email } : {},
|
|
7268
7381
|
...values.handle !== void 0 ? { handle: values.handle } : {},
|