@sjawhar/pi-legion-envoy 5.14.0 → 5.15.0
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/envoy.js +59 -42
- package/dist/legion.js +3047 -632
- package/dist/skills/dispatch/SKILL.md +5 -2
- package/package.json +2 -2
package/dist/envoy.js
CHANGED
|
@@ -32173,6 +32173,15 @@ function resolveDispatchConfig(env, options = {}) {
|
|
|
32173
32173
|
}
|
|
32174
32174
|
return { enabled: true, url: url2.url, token, error: null };
|
|
32175
32175
|
}
|
|
32176
|
+
function activeDispatchConfig(env, options = {}) {
|
|
32177
|
+
const config2 = resolveDispatchConfig(env, options);
|
|
32178
|
+
if (config2.error !== null)
|
|
32179
|
+
throw new Error(`dispatch config: ${config2.error}`);
|
|
32180
|
+
const { url: url2, token } = config2;
|
|
32181
|
+
if (!config2.enabled || url2 === null || token === null)
|
|
32182
|
+
return null;
|
|
32183
|
+
return { ...config2, url: url2, token };
|
|
32184
|
+
}
|
|
32176
32185
|
|
|
32177
32186
|
// ../envoy-client/src/dispatch-execute.ts
|
|
32178
32187
|
import { resolve as resolvePath } from "path";
|
|
@@ -33242,13 +33251,23 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, serverUrl, pro
|
|
|
33242
33251
|
const issue2 = `${repo2}#${legionIssue}`;
|
|
33243
33252
|
return { args: { ...args, issue: issue2 }, ref, owner: { kind: "issue", issue: issue2 } };
|
|
33244
33253
|
}
|
|
33245
|
-
function artifactByReference(artifacts, artifactReference, owner) {
|
|
33246
|
-
const
|
|
33247
|
-
if (
|
|
33248
|
-
return
|
|
33254
|
+
function artifactByReference(artifacts, artifactReference, owner, canonical) {
|
|
33255
|
+
const bySlug = artifacts.find((candidate) => candidate.slug === artifactReference);
|
|
33256
|
+
if (canonical && bySlug !== undefined)
|
|
33257
|
+
return bySlug;
|
|
33258
|
+
const byId = artifacts.find((candidate) => candidate.id === artifactReference);
|
|
33259
|
+
if (byId !== undefined)
|
|
33260
|
+
return byId;
|
|
33249
33261
|
const byName = artifacts.filter((candidate) => candidate.name === artifactReference);
|
|
33262
|
+
if (bySlug !== undefined) {
|
|
33263
|
+
const named = byName.filter((candidate) => candidate.id !== bySlug.id && candidate.kind === "doc");
|
|
33264
|
+
if (named.length > 0) {
|
|
33265
|
+
throw new Error(documentReferenceProblem(artifactReference, [bySlug, ...named], owner, "id"));
|
|
33266
|
+
}
|
|
33267
|
+
return bySlug;
|
|
33268
|
+
}
|
|
33250
33269
|
if (byName.length > 1) {
|
|
33251
|
-
throw new Error(documentReferenceProblem(artifactReference, byName, owner,
|
|
33270
|
+
throw new Error(documentReferenceProblem(artifactReference, byName, owner, "slug"));
|
|
33252
33271
|
}
|
|
33253
33272
|
const [artifact] = byName;
|
|
33254
33273
|
if (artifact === undefined) {
|
|
@@ -33256,43 +33275,45 @@ function artifactByReference(artifacts, artifactReference, owner) {
|
|
|
33256
33275
|
}
|
|
33257
33276
|
return artifact;
|
|
33258
33277
|
}
|
|
33259
|
-
async function resolveArtifact(client, owner, artifactReference) {
|
|
33278
|
+
async function resolveArtifact(client, owner, artifactReference, { canonical = false } = {}) {
|
|
33260
33279
|
if (owner.kind === "project") {
|
|
33261
33280
|
if (artifactReference === undefined) {
|
|
33262
33281
|
throw new Error("artifact is required for a project document");
|
|
33263
33282
|
}
|
|
33264
|
-
|
|
33265
|
-
return {
|
|
33266
|
-
owner,
|
|
33267
|
-
artifact: await client.getProjectArtifact(owner.project, artifactReference)
|
|
33268
|
-
};
|
|
33269
|
-
} catch (error48) {
|
|
33283
|
+
const routed = await client.getProjectArtifact(owner.project, artifactReference).catch((error48) => {
|
|
33270
33284
|
if (!(error48 instanceof DispatchServiceError) || error48.status !== 404)
|
|
33271
33285
|
throw error48;
|
|
33272
|
-
|
|
33273
|
-
|
|
33274
|
-
|
|
33275
|
-
|
|
33276
|
-
|
|
33277
|
-
|
|
33286
|
+
return;
|
|
33287
|
+
});
|
|
33288
|
+
if (canonical && routed !== undefined)
|
|
33289
|
+
return { owner, artifact: routed };
|
|
33290
|
+
const unlinked = await client.listProjectArtifacts(owner.project, true);
|
|
33291
|
+
const artifacts = routed === undefined ? unlinked : [routed, ...unlinked.filter((candidate) => candidate.id !== routed.id)];
|
|
33292
|
+
return {
|
|
33293
|
+
owner,
|
|
33294
|
+
artifact: artifactByReference(artifacts, artifactReference, "project", canonical)
|
|
33295
|
+
};
|
|
33278
33296
|
}
|
|
33279
33297
|
const issue2 = await client.getIssue(owner.issue);
|
|
33280
33298
|
let artifact;
|
|
33281
33299
|
if (artifactReference === undefined || artifactReference === "spec") {
|
|
33282
33300
|
artifact = issue2.artifacts.find((candidate) => candidate.primary || candidate.id === issue2.primary_artifact_id);
|
|
33283
33301
|
} else {
|
|
33284
|
-
artifact = artifactByReference(issue2.artifacts, artifactReference, "issue");
|
|
33302
|
+
artifact = artifactByReference(issue2.artifacts, artifactReference, "issue", canonical);
|
|
33285
33303
|
}
|
|
33286
33304
|
if (!artifact) {
|
|
33287
33305
|
throw new Error(documentReferenceProblem(artifactReference ?? "spec", issue2.artifacts, "issue"));
|
|
33288
33306
|
}
|
|
33289
33307
|
return { owner, issue: issue2, artifact };
|
|
33290
33308
|
}
|
|
33309
|
+
async function resolveIssueDocumentId(client, issue2, reference) {
|
|
33310
|
+
return (await resolveArtifact(client, { kind: "issue", issue: issue2 }, reference)).artifact.id;
|
|
33311
|
+
}
|
|
33291
33312
|
var documentHintLimit = 8;
|
|
33292
|
-
function documentReferenceProblem(reference, documents, owner,
|
|
33293
|
-
const hints = documents.slice(0, documentHintLimit).map((document) => `${document.slug} (${document.name})`);
|
|
33313
|
+
function documentReferenceProblem(reference, documents, owner, use) {
|
|
33314
|
+
const hints = documents.slice(0, documentHintLimit).map((document) => use === "id" ? `${document.id} (${document.slug}, ${document.name})` : `${document.slug} (${document.name})`);
|
|
33294
33315
|
const list = hints.length === 0 ? "none" : hints.join(", ");
|
|
33295
|
-
return
|
|
33316
|
+
return use === undefined ? `document "${reference}" not found by slug; this ${owner}'s documents: ${list}` : `"${reference}" names ${documents.length} documents on this ${owner}; use ${use === "id" ? "the id" : "a slug"}: ${list}`;
|
|
33296
33317
|
}
|
|
33297
33318
|
var askHintLimit = 8;
|
|
33298
33319
|
function askIDInputProblem(asks, scope) {
|
|
@@ -33682,6 +33703,10 @@ async function executeDispatchTool(input) {
|
|
|
33682
33703
|
const args = parsed.success ? parsed.data : ownerArguments.args;
|
|
33683
33704
|
const actor = toolActor(await resolveOrigin(env, exec, input.cwd), input);
|
|
33684
33705
|
const client = dispatchClient();
|
|
33706
|
+
const refDocument = ownerArguments.ref?.kind === "artifact" ? ownerArguments.ref.id : ownerArguments.ref?.artifact;
|
|
33707
|
+
const resolveDocument = (documentOwner2, reference) => resolveArtifact(client, documentOwner2, reference, {
|
|
33708
|
+
canonical: reference !== undefined && reference === refDocument
|
|
33709
|
+
});
|
|
33685
33710
|
const owner = ownerArguments.owner?.kind === "issue" ? {
|
|
33686
33711
|
kind: "issue",
|
|
33687
33712
|
issue: await resolveExistingIssue(client, ownerArguments.owner.issue)
|
|
@@ -33972,7 +33997,7 @@ async function executeDispatchTool(input) {
|
|
|
33972
33997
|
const issueKey = ref.owner.issue;
|
|
33973
33998
|
id = await resolveIdPrefix(input.tool, "comment", ref.id, refOwnerName(ref), () => client.getComments(issueKey));
|
|
33974
33999
|
} else if (ref !== null) {
|
|
33975
|
-
const artifact = (await resolveArtifact(client, ref.owner, ref.artifact)).artifact;
|
|
34000
|
+
const artifact = (await resolveArtifact(client, ref.owner, ref.artifact, { canonical: true })).artifact;
|
|
33976
34001
|
document = artifact;
|
|
33977
34002
|
id = await resolveIdPrefix(input.tool, "comment", ref.id, refOwnerName(ref), () => client.getArtifactComments(artifact.id));
|
|
33978
34003
|
}
|
|
@@ -33984,7 +34009,7 @@ async function executeDispatchTool(input) {
|
|
|
33984
34009
|
const anchorArgs = asObject(args.anchor);
|
|
33985
34010
|
const owner2 = documentOwner();
|
|
33986
34011
|
const artifactReference = optionalString(args, "artifact") ?? (anchorArgs === null ? undefined : optionalString(anchorArgs, "artifact"));
|
|
33987
|
-
const resolved = owner2.kind === "project" || artifactReference === undefined ? owner2.kind === "project" ? await
|
|
34012
|
+
const resolved = owner2.kind === "project" || artifactReference === undefined ? owner2.kind === "project" ? await resolveDocument(owner2, artifactReference) : undefined : await resolveDocument(owner2, artifactReference);
|
|
33988
34013
|
const options = args.options;
|
|
33989
34014
|
const multiple = optionalBoolean(args, "multiple");
|
|
33990
34015
|
const urgency = askUrgency(args);
|
|
@@ -34034,7 +34059,7 @@ ${followsAsk(askOwner)}`,
|
|
|
34034
34059
|
case "dispatch_comment": {
|
|
34035
34060
|
const artifactReference = optionalString(args, "artifact");
|
|
34036
34061
|
const owner2 = documentOwner();
|
|
34037
|
-
const resolved = owner2.kind === "project" || artifactReference === undefined ? owner2.kind === "project" ? await
|
|
34062
|
+
const resolved = owner2.kind === "project" || artifactReference === undefined ? owner2.kind === "project" ? await resolveDocument(owner2, artifactReference) : undefined : await resolveDocument(owner2, artifactReference);
|
|
34038
34063
|
const anchored = resolved ? anchor(resolved.artifact, args) : undefined;
|
|
34039
34064
|
const replyTo = optionalString(args, "reply_to");
|
|
34040
34065
|
const replyToAskReference = optionalString(args, "reply_to_ask");
|
|
@@ -34087,7 +34112,7 @@ ${followsAsk(askOwner)}`,
|
|
|
34087
34112
|
};
|
|
34088
34113
|
}
|
|
34089
34114
|
case "dispatch_suggest": {
|
|
34090
|
-
const resolved = await
|
|
34115
|
+
const resolved = await resolveDocument(documentOwner(), stringArg(args, "artifact"));
|
|
34091
34116
|
const anchored = anchor(resolved.artifact, args);
|
|
34092
34117
|
if (anchored === undefined)
|
|
34093
34118
|
throw new Error("quote is required");
|
|
@@ -34142,7 +34167,7 @@ ${followsAsk(askOwner)}`,
|
|
|
34142
34167
|
};
|
|
34143
34168
|
}
|
|
34144
34169
|
case "dispatch_doc_edit": {
|
|
34145
|
-
const resolved = await
|
|
34170
|
+
const resolved = await resolveDocument(documentOwner(), stringArg(args, "artifact"));
|
|
34146
34171
|
const ops = args.ops;
|
|
34147
34172
|
const summary = optionalString(args, "summary");
|
|
34148
34173
|
const { precondition: rawPrecondition } = args;
|
|
@@ -34184,7 +34209,7 @@ ${followsAsk(askOwner)}`,
|
|
|
34184
34209
|
}
|
|
34185
34210
|
case "dispatch_doc_read": {
|
|
34186
34211
|
const artifactReference = optionalString(args, "artifact") ?? (ownerArguments.ref?.kind === "spec" || ownerArguments.ref?.kind === "artifact" ? ownerArguments.ref.id : undefined);
|
|
34187
|
-
const resolved = await
|
|
34212
|
+
const resolved = await resolveDocument(documentOwner(), artifactReference);
|
|
34188
34213
|
const version2 = optionalNumber(args, "version") ?? ownerArguments.ref?.version;
|
|
34189
34214
|
const documentPromise = client.docRead(resolved.artifact.id, version2);
|
|
34190
34215
|
const marksPromise = openArtifactMarks(client, resolved);
|
|
@@ -34213,7 +34238,7 @@ ${trailer.join(`
|
|
|
34213
34238
|
}
|
|
34214
34239
|
case "dispatch_request_approval": {
|
|
34215
34240
|
const artifactReference = optionalString(args, "artifact") ?? (ownerArguments.ref?.kind === "spec" || ownerArguments.ref?.kind === "artifact" ? ownerArguments.ref.id : undefined);
|
|
34216
|
-
const resolved = await
|
|
34241
|
+
const resolved = await resolveDocument(documentOwner(), artifactReference);
|
|
34217
34242
|
const result = await client.requestApproval(resolved.artifact.id, { actor });
|
|
34218
34243
|
if (result.ask === null) {
|
|
34219
34244
|
return {
|
|
@@ -34291,7 +34316,7 @@ ${trailer.join(`
|
|
|
34291
34316
|
case "dispatch_read": {
|
|
34292
34317
|
if (ownerArguments.ref?.kind === "ask") {
|
|
34293
34318
|
const ref = ownerArguments.ref;
|
|
34294
|
-
const id = await resolveIdPrefix(input.tool, "ask", ref.id, refOwnerName(ref), async () => ref.owner.kind === "issue" ? client.listIssueAsks(ref.owner.issue) : client.getArtifactAsks((await
|
|
34319
|
+
const id = await resolveIdPrefix(input.tool, "ask", ref.id, refOwnerName(ref), async () => ref.owner.kind === "issue" ? client.listIssueAsks(ref.owner.issue) : client.getArtifactAsks((await resolveDocument(ref.owner, ref.artifact)).artifact.id, "all"));
|
|
34295
34320
|
const askRead = await client.getAsk(id);
|
|
34296
34321
|
const askRef = refTarget(ref, "ask", id);
|
|
34297
34322
|
return {
|
|
@@ -34301,7 +34326,7 @@ ${trailer.join(`
|
|
|
34301
34326
|
}
|
|
34302
34327
|
if (ownerArguments.ref?.kind === "comment") {
|
|
34303
34328
|
const ref = ownerArguments.ref;
|
|
34304
|
-
const id = await resolveIdPrefix(input.tool, "comment", ref.id, refOwnerName(ref), async () => ref.owner.kind === "issue" ? client.getComments(ref.owner.issue) : client.getArtifactComments((await
|
|
34329
|
+
const id = await resolveIdPrefix(input.tool, "comment", ref.id, refOwnerName(ref), async () => ref.owner.kind === "issue" ? client.getComments(ref.owner.issue) : client.getArtifactComments((await resolveDocument(ref.owner, ref.artifact)).artifact.id));
|
|
34305
34330
|
const comment = await client.getComment(id);
|
|
34306
34331
|
const commentRef = refTarget(ref, "comment", id);
|
|
34307
34332
|
return {
|
|
@@ -34321,7 +34346,7 @@ ${trailer.join(`
|
|
|
34321
34346
|
};
|
|
34322
34347
|
}
|
|
34323
34348
|
if (documentOwner().kind === "project") {
|
|
34324
|
-
const resolved = await
|
|
34349
|
+
const resolved = await resolveDocument(documentOwner(), stringArg(args, "artifact"));
|
|
34325
34350
|
const documentRef = dispatchDocumentRef(resolved.artifact.project, resolved.artifact.slug);
|
|
34326
34351
|
return {
|
|
34327
34352
|
text: [
|
|
@@ -35403,16 +35428,8 @@ function envoyExtension(pi) {
|
|
|
35403
35428
|
logger.debug("extension instance loaded", { extension: import.meta.url });
|
|
35404
35429
|
const defaults = envoyDefaultsFromEnvironment(process.env);
|
|
35405
35430
|
const dispatchConfig = resolveDispatchConfig(process.env, { cwd: process.cwd() });
|
|
35406
|
-
const activeDispatchConfig = () => {
|
|
35407
|
-
const fresh = resolveDispatchConfig(process.env, { cwd: process.cwd() });
|
|
35408
|
-
if (fresh.error !== null)
|
|
35409
|
-
throw new Error(`dispatch config: ${fresh.error}`);
|
|
35410
|
-
if (!fresh.enabled || fresh.url === null || fresh.token === null)
|
|
35411
|
-
return null;
|
|
35412
|
-
return fresh;
|
|
35413
|
-
};
|
|
35414
35431
|
const currentDispatchConfig = () => {
|
|
35415
|
-
const config2 = activeDispatchConfig();
|
|
35432
|
+
const config2 = activeDispatchConfig(process.env, { cwd: process.cwd() });
|
|
35416
35433
|
if (config2 === null) {
|
|
35417
35434
|
throw new Error("Dispatch is no longer configured (dispatch.serverUrl/token missing)");
|
|
35418
35435
|
}
|
|
@@ -35476,7 +35493,7 @@ function envoyExtension(pi) {
|
|
|
35476
35493
|
});
|
|
35477
35494
|
};
|
|
35478
35495
|
const queryOpenAsks = async (requestedSessionID, since) => {
|
|
35479
|
-
const config2 = activeDispatchConfig();
|
|
35496
|
+
const config2 = activeDispatchConfig(process.env, { cwd: process.cwd() });
|
|
35480
35497
|
if (config2 === null)
|
|
35481
35498
|
return null;
|
|
35482
35499
|
const snapshot = await new DispatchClient(config2.url, config2.token, fetch, AbortSignal.timeout(OPEN_ASKS_TIMEOUT_MS)).openAsks(requestedSessionID, since);
|