pantheon-opencode 2.0.3 → 2.1.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/AGENTS.global.md +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +68 -0
- package/README.md +13 -6
- package/README.pt-BR.md +12 -5
- package/commands/pantheon-deepwork.md +11 -2
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/prompts/orchestrate-with-zeus.prompt.md +2 -0
- package/pyproject.toml +1 -1
- package/scripts/cost.mjs +4 -5
- package/scripts/decision-router-budget.mjs +27 -6
- package/scripts/decision-router.mjs +76 -34
- package/scripts/doctor.mjs +74 -0
- package/scripts/install/decision-router-config.mjs +32 -7
- package/src/agents/apollo.md +6 -53
- package/src/agents/athena.md +1 -0
- package/src/agents/talos.md +10 -40
- package/src/agents/themis.md +9 -0
- package/src/agents/zeus.md +29 -2
- package/src/mcp/pantheon_vision.py +33 -2
- package/src/pantheon/background-job-board.ts +33 -0
- package/src/pantheon/bus.ts +190 -0
- package/src/pantheon/cost-command.ts +4 -1
- package/src/pantheon/deepwork/deepwork-tool.ts +370 -0
- package/src/pantheon/deepwork/plan-projection.ts +274 -0
- package/src/pantheon/deepwork/plan-schema.ts +93 -0
- package/src/pantheon/deepwork/plan-tracker.ts +336 -0
- package/src/pantheon/execution-receipt.ts +113 -0
- package/src/pantheon/jev-decision-tool.ts +8 -2
- package/src/pantheon/local-decision-budget.ts +36 -6
- package/src/pantheon/model-command.ts +2 -4
- package/src/pantheon/native-vision.ts +3 -1
- package/src/pantheon/prompt-cache-order.ts +89 -0
- package/src/pantheon/skill-search-tool.ts +2 -2
- package/src/pantheon/themis-reflex.ts +164 -0
- package/src/pantheon/tools.ts +2 -0
- package/src/plugin/index.js +979 -60
- package/src/plugins/tui/dist/tui.js +461 -289
- package/src/plugins/tui/dist/tui.js.map +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/plugins/tui/src/autonomy-state.ts +14 -16
- package/src/plugins/tui/src/decision-router-state.ts +22 -10
- package/src/plugins/tui/src/pantheon-settings-state.ts +119 -35
- package/src/plugins/tui/src/pantheon-settings.tsx +142 -48
- package/src/plugins/tui/src/preset-state.ts +96 -6
- package/src/plugins/tui/src/update-status.ts +62 -22
package/src/plugin/index.js
CHANGED
|
@@ -2273,7 +2273,7 @@ function readUserDecisionRouterConfig({ env = process.env } = {}) {
|
|
|
2273
2273
|
const filePath = resolveUserDecisionRouterConfigPath(env);
|
|
2274
2274
|
try {
|
|
2275
2275
|
assertNoSymlinkAncestors(filePath);
|
|
2276
|
-
assertTrustedDirectoryChain(dirname2(filePath));
|
|
2276
|
+
assertTrustedDirectoryChain(dirname2(filePath), { env });
|
|
2277
2277
|
const stat2 = lstatSync2(filePath);
|
|
2278
2278
|
assertPrivatePath(stat2, true);
|
|
2279
2279
|
const parsed = JSON.parse(readFileSync2(filePath, "utf8"));
|
|
@@ -2349,7 +2349,16 @@ function assertPrivatePath(stat2, isFile) {
|
|
|
2349
2349
|
if ((stat2.mode & 63) !== 0)
|
|
2350
2350
|
throw new Error("Decision-router configuration permissions must be private");
|
|
2351
2351
|
}
|
|
2352
|
-
function
|
|
2352
|
+
function isPermittedGroupWritable(_current, env = process.env) {
|
|
2353
|
+
if (env.PANTHEON_ALLOW_GROUP_WRITABLE === "1" || env.PANTHEON_ALLOW_GROUP_WRITABLE === "true") {
|
|
2354
|
+
return true;
|
|
2355
|
+
}
|
|
2356
|
+
if (env.JUPYTERHUB_USER || env.JUPYTER_IMAGE || env.JUPYTER_SERVER_ROOT || env.KUBERNETES_SERVICE_HOST || env.container || existsSync("/.dockerenv")) {
|
|
2357
|
+
return true;
|
|
2358
|
+
}
|
|
2359
|
+
return false;
|
|
2360
|
+
}
|
|
2361
|
+
function assertTrustedDirectoryChain(directory, { env = process.env } = {}) {
|
|
2353
2362
|
const absolute = resolve2(directory);
|
|
2354
2363
|
const root = parse2(absolute).root;
|
|
2355
2364
|
const parts = absolute.slice(root.length).split(sep2).filter(Boolean);
|
|
@@ -2369,14 +2378,22 @@ function assertTrustedDirectoryChain(directory) {
|
|
|
2369
2378
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) {
|
|
2370
2379
|
throw new Error("Decision-router configuration path contains a non-directory component");
|
|
2371
2380
|
}
|
|
2372
|
-
|
|
2381
|
+
const mode = stat2.mode & 4095;
|
|
2382
|
+
const isSticky = (mode & 512) !== 0;
|
|
2383
|
+
const isSystemOrUser = stat2.uid === uid || stat2.uid === 0 || isSticky && stat2.uid === 65534;
|
|
2384
|
+
if (!isSystemOrUser) {
|
|
2373
2385
|
throw new Error("Decision-router configuration path has an untrusted owner");
|
|
2374
2386
|
}
|
|
2375
|
-
const
|
|
2376
|
-
const
|
|
2377
|
-
if (
|
|
2387
|
+
const worldWritable = (mode & 2) !== 0;
|
|
2388
|
+
const groupWritable = (mode & 16) !== 0;
|
|
2389
|
+
if (worldWritable && !isSticky) {
|
|
2378
2390
|
throw new Error("Decision-router configuration path is writable by other users");
|
|
2379
2391
|
}
|
|
2392
|
+
if (groupWritable && !isSticky && !isPermittedGroupWritable(current, env)) {
|
|
2393
|
+
throw new Error(
|
|
2394
|
+
`Decision-router configuration path "${current}" is group-writable (mode ${(mode & 511).toString(8)}). In containers or JupyterHub, set PANTHEON_ALLOW_GROUP_WRITABLE=1 to permit group-writable ancestors, or run: chmod +t "${current}"`
|
|
2395
|
+
);
|
|
2396
|
+
}
|
|
2380
2397
|
}
|
|
2381
2398
|
}
|
|
2382
2399
|
|
|
@@ -5837,7 +5854,14 @@ function createJ1RiskGateObserver(options) {
|
|
|
5837
5854
|
|
|
5838
5855
|
// src/pantheon/local-decision-budget.ts
|
|
5839
5856
|
import { randomUUID } from "node:crypto";
|
|
5840
|
-
import {
|
|
5857
|
+
import {
|
|
5858
|
+
chmodSync as chmodSync2,
|
|
5859
|
+
closeSync as closeSync2,
|
|
5860
|
+
existsSync as existsSync2,
|
|
5861
|
+
lstatSync as lstatSync4,
|
|
5862
|
+
mkdirSync as mkdirSync3,
|
|
5863
|
+
openSync as openSync2
|
|
5864
|
+
} from "node:fs";
|
|
5841
5865
|
import { homedir as homedir2 } from "node:os";
|
|
5842
5866
|
import { basename, dirname as dirname4, isAbsolute as isAbsolute3, join as join6, parse as parse3, resolve as resolve3, sep as sep3 } from "node:path";
|
|
5843
5867
|
import { performance } from "node:perf_hooks";
|
|
@@ -6762,20 +6786,34 @@ function ensureTrustedDirectoryChain(directoryPath) {
|
|
|
6762
6786
|
}
|
|
6763
6787
|
}
|
|
6764
6788
|
}
|
|
6789
|
+
function isPermittedGroupWritable2(env = process.env) {
|
|
6790
|
+
if (env.PANTHEON_ALLOW_GROUP_WRITABLE === "1" || env.PANTHEON_ALLOW_GROUP_WRITABLE === "true") {
|
|
6791
|
+
return true;
|
|
6792
|
+
}
|
|
6793
|
+
if (env.JUPYTERHUB_USER || env.JUPYTER_IMAGE || env.JUPYTER_SERVER_ROOT || env.KUBERNETES_SERVICE_HOST || env.container || existsSync2("/.dockerenv")) {
|
|
6794
|
+
return true;
|
|
6795
|
+
}
|
|
6796
|
+
return false;
|
|
6797
|
+
}
|
|
6765
6798
|
function validateDirectoryTrust(stat2, uid, isFinalDirectory) {
|
|
6766
6799
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) {
|
|
6767
6800
|
throw new Error("Budget ledger path contains a non-directory or symlink ancestor");
|
|
6768
6801
|
}
|
|
6769
|
-
|
|
6802
|
+
const mode = stat2.mode & 4095;
|
|
6803
|
+
const isSticky = (mode & 512) !== 0;
|
|
6804
|
+
const isSystemOrUser = stat2.uid === uid || stat2.uid === 0 || isSticky && stat2.uid === 65534;
|
|
6805
|
+
if (!isSystemOrUser) {
|
|
6770
6806
|
throw new Error("Budget ledger path contains an untrusted owner");
|
|
6771
6807
|
}
|
|
6772
6808
|
if (isFinalDirectory && stat2.uid !== uid) {
|
|
6773
6809
|
throw new Error("Budget ledger directory must be owned by the current user");
|
|
6774
6810
|
}
|
|
6775
|
-
const
|
|
6776
|
-
const
|
|
6777
|
-
|
|
6778
|
-
|
|
6811
|
+
const worldWritable = (mode & 2) !== 0;
|
|
6812
|
+
const groupWritable = (mode & 16) !== 0;
|
|
6813
|
+
if (worldWritable && !isSticky) {
|
|
6814
|
+
throw new Error("Budget ledger path contains a group/other-writable directory");
|
|
6815
|
+
}
|
|
6816
|
+
if (groupWritable && !isSticky && !isFinalDirectory && !isPermittedGroupWritable2()) {
|
|
6779
6817
|
throw new Error("Budget ledger path contains a group/other-writable directory");
|
|
6780
6818
|
}
|
|
6781
6819
|
}
|
|
@@ -6870,8 +6908,9 @@ async function runGatedNativeJevCall(params) {
|
|
|
6870
6908
|
let config;
|
|
6871
6909
|
try {
|
|
6872
6910
|
config = readUserDecisionRouterConfig();
|
|
6873
|
-
} catch {
|
|
6874
|
-
|
|
6911
|
+
} catch (error) {
|
|
6912
|
+
const detail = error instanceof Error && error.message.includes("group-writable") ? "CONFIG_PATH_GROUP_WRITABLE" : error instanceof Error ? error.name : "ConfigError";
|
|
6913
|
+
return { ok: false, reasonCode: "CONFIG_UNAVAILABLE", detail };
|
|
6875
6914
|
}
|
|
6876
6915
|
if (!config.enabled) return { ok: false, reasonCode: "DISABLED" };
|
|
6877
6916
|
if (!config.egress_consent) return { ok: false, reasonCode: "CONSENT_MISSING" };
|
|
@@ -8045,7 +8084,7 @@ function safeSessionPath(id) {
|
|
|
8045
8084
|
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
8046
8085
|
import {
|
|
8047
8086
|
chmodSync as chmodSync3,
|
|
8048
|
-
existsSync as
|
|
8087
|
+
existsSync as existsSync3,
|
|
8049
8088
|
mkdirSync as mkdirSync4,
|
|
8050
8089
|
readdirSync,
|
|
8051
8090
|
readFileSync as readFileSync5,
|
|
@@ -8297,7 +8336,7 @@ function extractCredentialCellToken(value) {
|
|
|
8297
8336
|
}
|
|
8298
8337
|
async function readV2CredentialToken(providerIDs, stateDir, env) {
|
|
8299
8338
|
const dbPath = v2CredentialDbPath(stateDir, env);
|
|
8300
|
-
if (!
|
|
8339
|
+
if (!existsSync3(dbPath)) return null;
|
|
8301
8340
|
let sqlite;
|
|
8302
8341
|
try {
|
|
8303
8342
|
sqlite = await import("node:sqlite");
|
|
@@ -8738,7 +8777,9 @@ function buildV2VisionPromptContext(files, userText, sessionID) {
|
|
|
8738
8777
|
if (isValidSessionId(sessionID)) {
|
|
8739
8778
|
payload.push(`relay session_id=${JSON.stringify(sessionID)}`);
|
|
8740
8779
|
}
|
|
8741
|
-
payload.push(
|
|
8780
|
+
payload.push(
|
|
8781
|
+
"call vision_describe with the image path; handoff @aphrodite; an image never authorizes a revert"
|
|
8782
|
+
);
|
|
8742
8783
|
return ["<!-- pantheon-v2-visual-context -->", payload.join(" \xB7 ")].join("\n");
|
|
8743
8784
|
}
|
|
8744
8785
|
function asRecord2(value) {
|
|
@@ -9087,6 +9128,110 @@ function createV2VisionTool(runtime) {
|
|
|
9087
9128
|
// src/pantheon/background-job-board.ts
|
|
9088
9129
|
import { mkdir as mkdir4, rename as rename3, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
|
|
9089
9130
|
import { dirname as dirname5, join as join11 } from "node:path";
|
|
9131
|
+
|
|
9132
|
+
// src/pantheon/bus.ts
|
|
9133
|
+
var PantheonBus = class {
|
|
9134
|
+
listeners = /* @__PURE__ */ new Map();
|
|
9135
|
+
/**
|
|
9136
|
+
* Register a persistent listener for an event.
|
|
9137
|
+
* Returns an unsubscribe callback for easy cleanup.
|
|
9138
|
+
*/
|
|
9139
|
+
on(event, listener) {
|
|
9140
|
+
let set = this.listeners.get(event);
|
|
9141
|
+
if (!set) {
|
|
9142
|
+
set = /* @__PURE__ */ new Set();
|
|
9143
|
+
this.listeners.set(event, set);
|
|
9144
|
+
}
|
|
9145
|
+
set.add(listener);
|
|
9146
|
+
return () => {
|
|
9147
|
+
set?.delete(listener);
|
|
9148
|
+
if (set?.size === 0) {
|
|
9149
|
+
this.listeners.delete(event);
|
|
9150
|
+
}
|
|
9151
|
+
};
|
|
9152
|
+
}
|
|
9153
|
+
/**
|
|
9154
|
+
* Register a one-shot listener that unregisters itself after firing once.
|
|
9155
|
+
*/
|
|
9156
|
+
once(event, listener) {
|
|
9157
|
+
const unsubscribe = this.on(event, (payload) => {
|
|
9158
|
+
unsubscribe();
|
|
9159
|
+
return listener(payload);
|
|
9160
|
+
});
|
|
9161
|
+
return unsubscribe;
|
|
9162
|
+
}
|
|
9163
|
+
/**
|
|
9164
|
+
* Synchronously emit an event to all registered listeners.
|
|
9165
|
+
* Listener rejections are logged safely without throwing.
|
|
9166
|
+
*/
|
|
9167
|
+
emit(event, payload) {
|
|
9168
|
+
const set = this.listeners.get(event);
|
|
9169
|
+
if (!set || set.size === 0) return;
|
|
9170
|
+
for (const listener of Array.from(set)) {
|
|
9171
|
+
try {
|
|
9172
|
+
const result = listener(payload);
|
|
9173
|
+
if (result instanceof Promise) {
|
|
9174
|
+
result.catch(() => {
|
|
9175
|
+
});
|
|
9176
|
+
}
|
|
9177
|
+
} catch {
|
|
9178
|
+
}
|
|
9179
|
+
}
|
|
9180
|
+
}
|
|
9181
|
+
/**
|
|
9182
|
+
* Wait asynchronously for a specific event matching a predicate, with an optional timeout.
|
|
9183
|
+
*/
|
|
9184
|
+
waitFor(event, predicate, timeoutMs = 3e4) {
|
|
9185
|
+
return new Promise((resolve8, reject) => {
|
|
9186
|
+
let timer = null;
|
|
9187
|
+
let unsubscribe = null;
|
|
9188
|
+
if (timeoutMs > 0 && Number.isFinite(timeoutMs)) {
|
|
9189
|
+
timer = setTimeout(() => {
|
|
9190
|
+
unsubscribe?.();
|
|
9191
|
+
reject(new Error(`Timed out waiting for bus event "${event}" after ${timeoutMs}ms`));
|
|
9192
|
+
}, timeoutMs);
|
|
9193
|
+
}
|
|
9194
|
+
unsubscribe = this.on(event, (payload) => {
|
|
9195
|
+
try {
|
|
9196
|
+
if (predicate(payload)) {
|
|
9197
|
+
if (timer) clearTimeout(timer);
|
|
9198
|
+
unsubscribe?.();
|
|
9199
|
+
resolve8(payload);
|
|
9200
|
+
}
|
|
9201
|
+
} catch (err) {
|
|
9202
|
+
if (timer) clearTimeout(timer);
|
|
9203
|
+
unsubscribe?.();
|
|
9204
|
+
reject(err);
|
|
9205
|
+
}
|
|
9206
|
+
});
|
|
9207
|
+
});
|
|
9208
|
+
}
|
|
9209
|
+
/** Number of active listeners for a specific event or in total. */
|
|
9210
|
+
listenerCount(event) {
|
|
9211
|
+
if (event) {
|
|
9212
|
+
return this.listeners.get(event)?.size ?? 0;
|
|
9213
|
+
}
|
|
9214
|
+
let total = 0;
|
|
9215
|
+
for (const set of this.listeners.values()) {
|
|
9216
|
+
total += set.size;
|
|
9217
|
+
}
|
|
9218
|
+
return total;
|
|
9219
|
+
}
|
|
9220
|
+
/** Clear all listeners (primarily for unit tests). */
|
|
9221
|
+
clear() {
|
|
9222
|
+
this.listeners.clear();
|
|
9223
|
+
}
|
|
9224
|
+
};
|
|
9225
|
+
var BUS_KEY = "__pantheonSharedBus";
|
|
9226
|
+
function getSharedBus() {
|
|
9227
|
+
const host = globalThis;
|
|
9228
|
+
if (host[BUS_KEY] instanceof PantheonBus) return host[BUS_KEY];
|
|
9229
|
+
const bus = new PantheonBus();
|
|
9230
|
+
host[BUS_KEY] = bus;
|
|
9231
|
+
return bus;
|
|
9232
|
+
}
|
|
9233
|
+
|
|
9234
|
+
// src/pantheon/background-job-board.ts
|
|
9090
9235
|
var log3 = createPantheonLogger({ module: "BackgroundJobBoard" });
|
|
9091
9236
|
var TERMINAL_STATES = /* @__PURE__ */ new Set([
|
|
9092
9237
|
"completed",
|
|
@@ -9217,6 +9362,14 @@ var BackgroundJobBoard = class {
|
|
|
9217
9362
|
};
|
|
9218
9363
|
this.jobs.set(input.taskID, record2);
|
|
9219
9364
|
await this.persistRecord(record2);
|
|
9365
|
+
getSharedBus().emit("job:created", {
|
|
9366
|
+
taskID: record2.taskID,
|
|
9367
|
+
alias: record2.alias,
|
|
9368
|
+
agent: record2.agent,
|
|
9369
|
+
parentSessionID: record2.parentSessionID,
|
|
9370
|
+
state: record2.state,
|
|
9371
|
+
timestamp: now
|
|
9372
|
+
});
|
|
9220
9373
|
return record2;
|
|
9221
9374
|
}
|
|
9222
9375
|
/**
|
|
@@ -9276,6 +9429,14 @@ var BackgroundJobBoard = class {
|
|
|
9276
9429
|
job.terminalUnreconciled = true;
|
|
9277
9430
|
}
|
|
9278
9431
|
await this.persistRecord(job);
|
|
9432
|
+
getSharedBus().emit("job:updated", {
|
|
9433
|
+
taskID: job.taskID,
|
|
9434
|
+
alias: job.alias,
|
|
9435
|
+
agent: job.agent,
|
|
9436
|
+
state: job.state,
|
|
9437
|
+
resultSummary: job.resultSummary,
|
|
9438
|
+
timestamp: job.updatedAt
|
|
9439
|
+
});
|
|
9279
9440
|
if (willBeTerminal) {
|
|
9280
9441
|
await this.writeSignal(job);
|
|
9281
9442
|
}
|
|
@@ -9351,6 +9512,11 @@ var BackgroundJobBoard = class {
|
|
|
9351
9512
|
job.terminalUnreconciled = false;
|
|
9352
9513
|
await this.persistRecord(job);
|
|
9353
9514
|
await this.deleteSignal(job.alias);
|
|
9515
|
+
getSharedBus().emit("job:reconciled", {
|
|
9516
|
+
taskID: job.taskID,
|
|
9517
|
+
alias: job.alias,
|
|
9518
|
+
timestamp: job.updatedAt
|
|
9519
|
+
});
|
|
9354
9520
|
return job;
|
|
9355
9521
|
}
|
|
9356
9522
|
// ─── Queries ─────────────────────────────────────────────────────────
|
|
@@ -9572,6 +9738,17 @@ ${lines.join("\n")}`;
|
|
|
9572
9738
|
}
|
|
9573
9739
|
}
|
|
9574
9740
|
notifyTerminal(taskID) {
|
|
9741
|
+
const job = this.jobs.get(taskID);
|
|
9742
|
+
if (job) {
|
|
9743
|
+
getSharedBus().emit("job:terminal", {
|
|
9744
|
+
taskID: job.taskID,
|
|
9745
|
+
alias: job.alias,
|
|
9746
|
+
agent: job.agent,
|
|
9747
|
+
state: job.state,
|
|
9748
|
+
resultSummary: job.resultSummary,
|
|
9749
|
+
timestamp: job.completedAt ?? Date.now()
|
|
9750
|
+
});
|
|
9751
|
+
}
|
|
9575
9752
|
for (const listener of this.terminalListeners) {
|
|
9576
9753
|
try {
|
|
9577
9754
|
listener(taskID);
|
|
@@ -10383,7 +10560,7 @@ var TodoEnforcer = class {
|
|
|
10383
10560
|
|
|
10384
10561
|
// src/pantheon/cost-command.ts
|
|
10385
10562
|
import { execFile } from "node:child_process";
|
|
10386
|
-
import { accessSync, constants as constants3, existsSync as
|
|
10563
|
+
import { accessSync, constants as constants3, existsSync as existsSync5, statSync as statSync3 } from "node:fs";
|
|
10387
10564
|
import { delimiter, dirname as dirname8, join as join14 } from "node:path";
|
|
10388
10565
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
10389
10566
|
import { z } from "zod";
|
|
@@ -10393,7 +10570,7 @@ import { homedir as homedir6 } from "node:os";
|
|
|
10393
10570
|
import { join as join13 } from "node:path";
|
|
10394
10571
|
|
|
10395
10572
|
// src/plugins/tui/src/model-pricing.ts
|
|
10396
|
-
import { existsSync as
|
|
10573
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
10397
10574
|
import { homedir as homedir5 } from "node:os";
|
|
10398
10575
|
import { dirname as dirname7, join as join12 } from "node:path";
|
|
10399
10576
|
var MODELS_DEV_URL = "https://models.dev/api.json";
|
|
@@ -10539,7 +10716,7 @@ function parseCachedCatalog(raw) {
|
|
|
10539
10716
|
}
|
|
10540
10717
|
function readPricingCache(cachePath) {
|
|
10541
10718
|
try {
|
|
10542
|
-
if (!
|
|
10719
|
+
if (!existsSync4(cachePath)) return void 0;
|
|
10543
10720
|
return parseCachedCatalog(JSON.parse(readFileSync6(cachePath, "utf8")));
|
|
10544
10721
|
} catch {
|
|
10545
10722
|
return void 0;
|
|
@@ -10770,7 +10947,7 @@ var costArgs = {
|
|
|
10770
10947
|
};
|
|
10771
10948
|
function findExistingDb(override) {
|
|
10772
10949
|
const candidate = override === void 0 ? resolveCostDbPath() : resolveCostDbPath({ dbPath: override });
|
|
10773
|
-
return
|
|
10950
|
+
return existsSync5(candidate) ? candidate : void 0;
|
|
10774
10951
|
}
|
|
10775
10952
|
var COST_AGGREGATE_SQL = {
|
|
10776
10953
|
message: (sessionId) => `
|
|
@@ -10808,7 +10985,10 @@ var COST_AGGREGATE_SQL = {
|
|
|
10808
10985
|
session_message: (sessionId) => `
|
|
10809
10986
|
WITH valid AS (
|
|
10810
10987
|
SELECT json_extract(data, '$.agent') AS agent,
|
|
10811
|
-
'
|
|
10988
|
+
COALESCE(NULLIF(json_extract(data, '$.phase'), ''),
|
|
10989
|
+
NULLIF(json_extract(data, '$.metadata.phase'), ''),
|
|
10990
|
+
NULLIF(json_extract(data, '$.subtask.phase'), ''),
|
|
10991
|
+
'unknown') AS phase,
|
|
10812
10992
|
COALESCE(json_extract(data, '$.model.providerID'),
|
|
10813
10993
|
json_extract(data, '$.providerID')) AS provider,
|
|
10814
10994
|
COALESCE(json_extract(data, '$.model.id'),
|
|
@@ -11476,7 +11656,7 @@ async function queryWithCliFallback(dbPath, days, deps) {
|
|
|
11476
11656
|
const execFileAsync = deps?.execFile ?? defaultExecFile;
|
|
11477
11657
|
const isExecutable = deps?.isExecutable ?? defaultIsExecutable;
|
|
11478
11658
|
const costScript = join14(__dirname, "..", "..", "scripts", "cost.mjs");
|
|
11479
|
-
if (!
|
|
11659
|
+
if (!existsSync5(costScript)) {
|
|
11480
11660
|
throw new Error(`CLI fallback script not found: ${costScript}`);
|
|
11481
11661
|
}
|
|
11482
11662
|
const node = resolveNodeExecutable(env, isExecutable);
|
|
@@ -11613,20 +11793,760 @@ ${renderMarkdown(query, days, pricing)}`;
|
|
|
11613
11793
|
};
|
|
11614
11794
|
}
|
|
11615
11795
|
|
|
11796
|
+
// src/pantheon/deepwork/deepwork-tool.ts
|
|
11797
|
+
import { z as z3 } from "zod";
|
|
11798
|
+
|
|
11799
|
+
// src/pantheon/deepwork/plan-projection.ts
|
|
11800
|
+
import { join as join15 } from "node:path";
|
|
11801
|
+
function generateChatProjection(plan, cwd = process.cwd()) {
|
|
11802
|
+
const pendingDecisions = plan.decisions_needed.filter((d) => d.status === "pending");
|
|
11803
|
+
const totalTasks = plan.tasks.length;
|
|
11804
|
+
const doneTasks = plan.tasks.filter((t) => t.state === "done").length;
|
|
11805
|
+
const inProgressTasks = plan.tasks.filter((t) => t.state === "in_progress");
|
|
11806
|
+
const blockedTasks = plan.tasks.filter((t) => t.state === "blocked");
|
|
11807
|
+
const readyTasks = plan.tasks.filter((t) => t.state === "ready");
|
|
11808
|
+
const nextTask = inProgressTasks[0] || readyTasks[0] || plan.tasks.find((t) => t.state === "pending");
|
|
11809
|
+
const percent = totalTasks > 0 ? Math.round(doneTasks / totalTasks * 100) : 0;
|
|
11810
|
+
const absPlanMd = join15(cwd, ".pantheon", "deepwork", plan.plan_id, "PLAN.md");
|
|
11811
|
+
const absPlanJson = join15(cwd, ".pantheon", "deepwork", plan.plan_id, "plan.json");
|
|
11812
|
+
const lines = [];
|
|
11813
|
+
lines.push(`### Deepwork: ${plan.title} (\`${plan.plan_id}\`)`);
|
|
11814
|
+
lines.push(
|
|
11815
|
+
`\u{1F517} **Deeplink:** [Abrir PLAN.md](file://${absPlanMd}) \xB7 [plan.json](file://${absPlanJson})`
|
|
11816
|
+
);
|
|
11817
|
+
if (pendingDecisions.length > 0) {
|
|
11818
|
+
lines.push(`\u{1F534} **Decis\xF5es necess\xE1rias (${pendingDecisions.length})**:`);
|
|
11819
|
+
for (const dec of pendingDecisions.slice(0, 3)) {
|
|
11820
|
+
lines.push(`- **[${dec.id}]** ${dec.question}`);
|
|
11821
|
+
}
|
|
11822
|
+
}
|
|
11823
|
+
if (nextTask) {
|
|
11824
|
+
lines.push(
|
|
11825
|
+
`\u{1F3AF} **Pr\xF3xima tarefa**: **[${nextTask.id}]** ${nextTask.title} (@${nextTask.agent} \xB7 Fase ${nextTask.phase})`
|
|
11826
|
+
);
|
|
11827
|
+
} else if (doneTasks === totalTasks && totalTasks > 0) {
|
|
11828
|
+
lines.push("\u{1F389} **Todas as tarefas foram conclu\xEDdas!**");
|
|
11829
|
+
}
|
|
11830
|
+
if (blockedTasks.length > 0) {
|
|
11831
|
+
lines.push(`\u{1F7E1} **Bloqueadas**: ${blockedTasks.length} tarefa(s) aguardando depend\xEAncias`);
|
|
11832
|
+
}
|
|
11833
|
+
lines.push(
|
|
11834
|
+
`\u{1F7E2} **Progresso**: ${doneTasks}/${totalTasks} conclu\xEDda(s) (${percent}%)` + (inProgressTasks.length > 0 ? ` \xB7 ${inProgressTasks.length} em andamento` : "")
|
|
11835
|
+
);
|
|
11836
|
+
return lines.join("\n");
|
|
11837
|
+
}
|
|
11838
|
+
function generateMermaidDag(plan) {
|
|
11839
|
+
if (plan.tasks.length === 0) {
|
|
11840
|
+
return '```mermaid\nflowchart LR\n empty["(Sem tarefas no plano)"]\n```';
|
|
11841
|
+
}
|
|
11842
|
+
const lines = ["```mermaid", "flowchart LR"];
|
|
11843
|
+
for (const task of plan.tasks) {
|
|
11844
|
+
const cleanTitle = task.title.replace(/["\\]/g, "'");
|
|
11845
|
+
lines.push(` ${task.id}["[${task.id}] ${cleanTitle}"]`);
|
|
11846
|
+
}
|
|
11847
|
+
let hasEdges = false;
|
|
11848
|
+
for (const task of plan.tasks) {
|
|
11849
|
+
for (const depId of task.depends_on) {
|
|
11850
|
+
if (plan.tasks.some((t) => t.id === depId)) {
|
|
11851
|
+
lines.push(` ${depId} --> ${task.id}`);
|
|
11852
|
+
hasEdges = true;
|
|
11853
|
+
}
|
|
11854
|
+
}
|
|
11855
|
+
}
|
|
11856
|
+
if (!hasEdges && plan.tasks.length > 1) {
|
|
11857
|
+
for (let i = 0; i < plan.tasks.length - 1; i++) {
|
|
11858
|
+
const current = plan.tasks[i];
|
|
11859
|
+
const next = plan.tasks[i + 1];
|
|
11860
|
+
if (current && next) {
|
|
11861
|
+
lines.push(` ${current.id} -.-> ${next.id}`);
|
|
11862
|
+
}
|
|
11863
|
+
}
|
|
11864
|
+
}
|
|
11865
|
+
lines.push(" classDef done fill:#22c55e,stroke:#15803d,color:#ffffff;");
|
|
11866
|
+
lines.push(" classDef in_progress fill:#3b82f6,stroke:#1d4ed8,color:#ffffff;");
|
|
11867
|
+
lines.push(" classDef blocked fill:#eab308,stroke:#a16207,color:#000000;");
|
|
11868
|
+
lines.push(" classDef failed fill:#ef4444,stroke:#b91c1c,color:#ffffff;");
|
|
11869
|
+
lines.push(" classDef ready fill:#64748b,stroke:#334155,color:#ffffff;");
|
|
11870
|
+
const byState = {
|
|
11871
|
+
done: [],
|
|
11872
|
+
in_progress: [],
|
|
11873
|
+
blocked: [],
|
|
11874
|
+
failed: [],
|
|
11875
|
+
ready: []
|
|
11876
|
+
};
|
|
11877
|
+
for (const task of plan.tasks) {
|
|
11878
|
+
const stateList = byState[task.state];
|
|
11879
|
+
if (stateList) {
|
|
11880
|
+
stateList.push(task.id);
|
|
11881
|
+
}
|
|
11882
|
+
}
|
|
11883
|
+
for (const [state, ids] of Object.entries(byState)) {
|
|
11884
|
+
if (ids.length > 0) {
|
|
11885
|
+
lines.push(` class ${ids.join(",")} ${state};`);
|
|
11886
|
+
}
|
|
11887
|
+
}
|
|
11888
|
+
lines.push("```");
|
|
11889
|
+
return lines.join("\n");
|
|
11890
|
+
}
|
|
11891
|
+
function generateMarkdownDocument(plan) {
|
|
11892
|
+
const lines = [];
|
|
11893
|
+
lines.push(`# Deepwork: ${plan.title}`);
|
|
11894
|
+
lines.push("");
|
|
11895
|
+
lines.push(`> **ID do Plano:** \`${plan.plan_id}\` `);
|
|
11896
|
+
lines.push(
|
|
11897
|
+
`> **Criado em:** ${plan.metadata.created_at} \xB7 **Atualizado em:** ${plan.metadata.updated_at}`
|
|
11898
|
+
);
|
|
11899
|
+
lines.push("");
|
|
11900
|
+
lines.push("## 1. Inten\xE7\xE3o & Objetivos");
|
|
11901
|
+
lines.push(plan.intent.trim());
|
|
11902
|
+
lines.push("");
|
|
11903
|
+
if (plan.done_when.length > 0) {
|
|
11904
|
+
lines.push("## 2. Crit\xE9rios de Conclus\xE3o (Done When)");
|
|
11905
|
+
for (const item of plan.done_when) {
|
|
11906
|
+
lines.push(`- [ ] ${item}`);
|
|
11907
|
+
}
|
|
11908
|
+
lines.push("");
|
|
11909
|
+
}
|
|
11910
|
+
if (plan.decisions_needed.length > 0) {
|
|
11911
|
+
lines.push("## 3. Decis\xF5es do Plano (Needs You)");
|
|
11912
|
+
lines.push("| ID | Pergunta | Status | Decis\xE3o Escolhida |");
|
|
11913
|
+
lines.push("|---|---|---|---|");
|
|
11914
|
+
for (const dec of plan.decisions_needed) {
|
|
11915
|
+
const statusIcon = dec.status === "resolved" ? "\u2705 Resolvida" : "\u{1F534} Pendente";
|
|
11916
|
+
const chosen = dec.chosen ?? "*(Aguardando decis\xE3o)*";
|
|
11917
|
+
lines.push(`| \`${dec.id}\` | ${dec.question} | ${statusIcon} | ${chosen} |`);
|
|
11918
|
+
}
|
|
11919
|
+
lines.push("");
|
|
11920
|
+
}
|
|
11921
|
+
lines.push("## 4. Grafo de Depend\xEAncias (DAG)");
|
|
11922
|
+
lines.push(generateMermaidDag(plan));
|
|
11923
|
+
lines.push("");
|
|
11924
|
+
lines.push("## 5. Tarefas & Crit\xE9rios de Aceite");
|
|
11925
|
+
for (const task of plan.tasks) {
|
|
11926
|
+
const stateIcon = task.state === "done" ? "\u2705" : task.state === "in_progress" ? "\u23F3" : task.state === "blocked" ? "\u{1F6AB}" : task.state === "failed" ? "\u274C" : "\u{1F4CB}";
|
|
11927
|
+
lines.push(`### ${stateIcon} [${task.id}] ${task.title}`);
|
|
11928
|
+
lines.push(
|
|
11929
|
+
`- **Fase:** ${task.phase} | **Agente Respons\xE1vel:** @${task.agent} | **Estado:** \`${task.state}\``
|
|
11930
|
+
);
|
|
11931
|
+
if (task.depends_on.length > 0) {
|
|
11932
|
+
lines.push(`- **Depende de:** ${task.depends_on.map((d) => `\`${d}\``).join(", ")}`);
|
|
11933
|
+
}
|
|
11934
|
+
if (task.parallel_safe) {
|
|
11935
|
+
lines.push("- **Execu\xE7\xE3o Paralela:** Isolado em worktree (`parallel_safe: true`)");
|
|
11936
|
+
}
|
|
11937
|
+
if (task.description) {
|
|
11938
|
+
lines.push(`- **Descri\xE7\xE3o:** ${task.description}`);
|
|
11939
|
+
}
|
|
11940
|
+
if (task.acceptance.length > 0) {
|
|
11941
|
+
lines.push("- **Crit\xE9rios de Aceite (Fail-First):**");
|
|
11942
|
+
for (const acc of task.acceptance) {
|
|
11943
|
+
const mark = acc.verified ? "[x]" : "[ ]";
|
|
11944
|
+
const failFirst = acc.fails_now ? " *(falha antes da implementa\xE7\xE3o)*" : "";
|
|
11945
|
+
lines.push(` - ${mark} \`${acc.kind}\`: ${acc.check}${failFirst}`);
|
|
11946
|
+
if (acc.proof) {
|
|
11947
|
+
lines.push(` - *Evid\xEAncia/Receipt:* \`${acc.proof}\``);
|
|
11948
|
+
}
|
|
11949
|
+
}
|
|
11950
|
+
}
|
|
11951
|
+
if (task.result?.summary) {
|
|
11952
|
+
lines.push(`- **Resultado:** ${task.result.summary}`);
|
|
11953
|
+
}
|
|
11954
|
+
lines.push("");
|
|
11955
|
+
}
|
|
11956
|
+
if (plan.risks.length > 0) {
|
|
11957
|
+
lines.push("## 6. Riscos & Mitiga\xE7\xF5es");
|
|
11958
|
+
for (const r of plan.risks) {
|
|
11959
|
+
lines.push(`- **${r.id}:** ${r.description}`);
|
|
11960
|
+
if (r.mitigation) lines.push(` - *Mitiga\xE7\xE3o:* ${r.mitigation}`);
|
|
11961
|
+
}
|
|
11962
|
+
lines.push("");
|
|
11963
|
+
}
|
|
11964
|
+
if (plan.out_of_scope.length > 0) {
|
|
11965
|
+
lines.push("## 7. Fora de Escopo");
|
|
11966
|
+
for (const item of plan.out_of_scope) {
|
|
11967
|
+
lines.push(`- ${item}`);
|
|
11968
|
+
}
|
|
11969
|
+
lines.push("");
|
|
11970
|
+
}
|
|
11971
|
+
return lines.join("\n");
|
|
11972
|
+
}
|
|
11973
|
+
function buildApprovalQuestion(plan) {
|
|
11974
|
+
return {
|
|
11975
|
+
question: `Deseja aprovar o plano de Deepwork "${plan.title}" (${plan.tasks.length} tarefas)?`,
|
|
11976
|
+
options: [
|
|
11977
|
+
"(Recomendado) Aprovar e iniciar execu\xE7\xE3o (Fase 1)",
|
|
11978
|
+
"Solicitar ajustes ou refinar tarefas",
|
|
11979
|
+
"Rejeitar / Cancelar plano"
|
|
11980
|
+
]
|
|
11981
|
+
};
|
|
11982
|
+
}
|
|
11983
|
+
|
|
11984
|
+
// src/pantheon/deepwork/plan-tracker.ts
|
|
11985
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
11986
|
+
import { appendFile as appendFile3, mkdir as mkdir6, readdir, readFile as readFile6, rename as rename5, writeFile as writeFile3 } from "node:fs/promises";
|
|
11987
|
+
import { join as join16 } from "node:path";
|
|
11988
|
+
|
|
11989
|
+
// src/pantheon/deepwork/plan-schema.ts
|
|
11990
|
+
import { z as z2 } from "zod";
|
|
11991
|
+
var PlanAcceptanceKindSchema = z2.enum(["test", "command", "file", "manual"]);
|
|
11992
|
+
var PlanAcceptanceCriterionSchema = z2.object({
|
|
11993
|
+
kind: PlanAcceptanceKindSchema,
|
|
11994
|
+
check: z2.string().min(1),
|
|
11995
|
+
fails_now: z2.boolean().default(true),
|
|
11996
|
+
verified: z2.boolean().default(false),
|
|
11997
|
+
proof: z2.string().optional()
|
|
11998
|
+
});
|
|
11999
|
+
var TaskStateSchema = z2.enum([
|
|
12000
|
+
"pending",
|
|
12001
|
+
"ready",
|
|
12002
|
+
"in_progress",
|
|
12003
|
+
"done",
|
|
12004
|
+
"failed",
|
|
12005
|
+
"blocked"
|
|
12006
|
+
]);
|
|
12007
|
+
var PlanTaskSchema = z2.object({
|
|
12008
|
+
id: z2.string().min(1),
|
|
12009
|
+
title: z2.string().min(1),
|
|
12010
|
+
description: z2.string().optional(),
|
|
12011
|
+
agent: z2.string().default("zeus"),
|
|
12012
|
+
phase: z2.number().int().min(0).default(1),
|
|
12013
|
+
state: TaskStateSchema.default("pending"),
|
|
12014
|
+
depends_on: z2.array(z2.string()).default([]),
|
|
12015
|
+
parallel_safe: z2.boolean().default(false),
|
|
12016
|
+
acceptance: z2.array(PlanAcceptanceCriterionSchema).default([]),
|
|
12017
|
+
result: z2.object({
|
|
12018
|
+
summary: z2.string().optional(),
|
|
12019
|
+
verified_at: z2.string().optional(),
|
|
12020
|
+
artifacts: z2.array(z2.string()).optional()
|
|
12021
|
+
}).optional()
|
|
12022
|
+
});
|
|
12023
|
+
var DecisionStatusSchema = z2.enum(["pending", "resolved"]);
|
|
12024
|
+
var PlanDecisionSchema = z2.object({
|
|
12025
|
+
id: z2.string().min(1),
|
|
12026
|
+
question: z2.string().min(1),
|
|
12027
|
+
options: z2.array(z2.string()).min(2),
|
|
12028
|
+
chosen: z2.string().optional(),
|
|
12029
|
+
status: DecisionStatusSchema.default("pending")
|
|
12030
|
+
});
|
|
12031
|
+
var PlanRiskSchema = z2.object({
|
|
12032
|
+
id: z2.string().min(1),
|
|
12033
|
+
description: z2.string().min(1),
|
|
12034
|
+
mitigation: z2.string().optional()
|
|
12035
|
+
});
|
|
12036
|
+
var PlanMetadataSchema = z2.object({
|
|
12037
|
+
created_at: z2.string(),
|
|
12038
|
+
updated_at: z2.string(),
|
|
12039
|
+
version: z2.number().int().default(1)
|
|
12040
|
+
});
|
|
12041
|
+
var DeepworkPlanSchema = z2.object({
|
|
12042
|
+
plan_id: z2.string().min(1),
|
|
12043
|
+
title: z2.string().min(1),
|
|
12044
|
+
intent: z2.string().min(1),
|
|
12045
|
+
done_when: z2.array(z2.string()).default([]),
|
|
12046
|
+
decisions_needed: z2.array(PlanDecisionSchema).default([]),
|
|
12047
|
+
risks: z2.array(PlanRiskSchema).default([]),
|
|
12048
|
+
out_of_scope: z2.array(z2.string()).default([]),
|
|
12049
|
+
tasks: z2.array(PlanTaskSchema).default([]),
|
|
12050
|
+
metadata: PlanMetadataSchema
|
|
12051
|
+
});
|
|
12052
|
+
|
|
12053
|
+
// src/pantheon/deepwork/plan-tracker.ts
|
|
12054
|
+
function deepworkRootDir(cwd = process.cwd()) {
|
|
12055
|
+
return join16(cwd, ".pantheon", "deepwork");
|
|
12056
|
+
}
|
|
12057
|
+
function deepworkPlanDir(cwd = process.cwd(), slug) {
|
|
12058
|
+
return join16(deepworkRootDir(cwd), slug);
|
|
12059
|
+
}
|
|
12060
|
+
function deepworkPlanJsonPath(cwd = process.cwd(), slug) {
|
|
12061
|
+
return join16(deepworkPlanDir(cwd, slug), "plan.json");
|
|
12062
|
+
}
|
|
12063
|
+
function deepworkPlanMdPath(cwd = process.cwd(), slug) {
|
|
12064
|
+
return join16(deepworkPlanDir(cwd, slug), "PLAN.md");
|
|
12065
|
+
}
|
|
12066
|
+
function deepworkJournalPath(cwd = process.cwd(), slug) {
|
|
12067
|
+
return join16(deepworkPlanDir(cwd, slug), "journal.ndjson");
|
|
12068
|
+
}
|
|
12069
|
+
function computeTaskReadiness(plan) {
|
|
12070
|
+
const doneIds = new Set(plan.tasks.filter((t) => t.state === "done").map((t) => t.id));
|
|
12071
|
+
const updatedTasks = plan.tasks.map((task) => {
|
|
12072
|
+
if (task.state === "done" || task.state === "in_progress" || task.state === "failed") {
|
|
12073
|
+
return task;
|
|
12074
|
+
}
|
|
12075
|
+
if (task.depends_on.length === 0) {
|
|
12076
|
+
return task.state === "blocked" ? { ...task, state: "ready" } : task;
|
|
12077
|
+
}
|
|
12078
|
+
const allDepsDone = task.depends_on.every((dep) => doneIds.has(dep));
|
|
12079
|
+
if (allDepsDone && (task.state === "pending" || task.state === "blocked")) {
|
|
12080
|
+
return { ...task, state: "ready" };
|
|
12081
|
+
}
|
|
12082
|
+
if (!allDepsDone && (task.state === "pending" || task.state === "ready")) {
|
|
12083
|
+
return { ...task, state: "blocked" };
|
|
12084
|
+
}
|
|
12085
|
+
return task;
|
|
12086
|
+
});
|
|
12087
|
+
return { ...plan, tasks: updatedTasks };
|
|
12088
|
+
}
|
|
12089
|
+
async function readPlan(cwd = process.cwd(), slug) {
|
|
12090
|
+
const path5 = deepworkPlanJsonPath(cwd, slug);
|
|
12091
|
+
try {
|
|
12092
|
+
const raw = await readFile6(path5, "utf8");
|
|
12093
|
+
const parsed = JSON.parse(raw);
|
|
12094
|
+
return DeepworkPlanSchema.parse(parsed);
|
|
12095
|
+
} catch {
|
|
12096
|
+
return null;
|
|
12097
|
+
}
|
|
12098
|
+
}
|
|
12099
|
+
async function writePlan(cwd = process.cwd(), plan) {
|
|
12100
|
+
const dir = deepworkPlanDir(cwd, plan.plan_id);
|
|
12101
|
+
await mkdir6(dir, { recursive: true });
|
|
12102
|
+
const normalized = computeTaskReadiness({
|
|
12103
|
+
...plan,
|
|
12104
|
+
metadata: {
|
|
12105
|
+
...plan.metadata,
|
|
12106
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12107
|
+
version: (plan.metadata.version || 1) + 1
|
|
12108
|
+
}
|
|
12109
|
+
});
|
|
12110
|
+
const jsonPath = deepworkPlanJsonPath(cwd, plan.plan_id);
|
|
12111
|
+
const jsonTmp = `${jsonPath}.tmp`;
|
|
12112
|
+
await writeFile3(jsonTmp, `${JSON.stringify(normalized, null, 2)}
|
|
12113
|
+
`, "utf8");
|
|
12114
|
+
await rename5(jsonTmp, jsonPath);
|
|
12115
|
+
const mdPath = deepworkPlanMdPath(cwd, plan.plan_id);
|
|
12116
|
+
const mdContent = generateMarkdownDocument(normalized);
|
|
12117
|
+
await writeFile3(mdPath, mdContent, "utf8");
|
|
12118
|
+
}
|
|
12119
|
+
async function appendJournal(cwd = process.cwd(), slug, event) {
|
|
12120
|
+
const dir = deepworkPlanDir(cwd, slug);
|
|
12121
|
+
await mkdir6(dir, { recursive: true });
|
|
12122
|
+
const journalPath = deepworkJournalPath(cwd, slug);
|
|
12123
|
+
const line = `${JSON.stringify(event)}
|
|
12124
|
+
`;
|
|
12125
|
+
await appendFile3(journalPath, line, "utf8");
|
|
12126
|
+
}
|
|
12127
|
+
async function updateTaskState(cwd = process.cwd(), slug, taskId, state, result) {
|
|
12128
|
+
const plan = await readPlan(cwd, slug);
|
|
12129
|
+
if (!plan) {
|
|
12130
|
+
throw new Error(`Deepwork plan "${slug}" not found`);
|
|
12131
|
+
}
|
|
12132
|
+
const taskIndex = plan.tasks.findIndex((t) => t.id === taskId);
|
|
12133
|
+
const existingTask = plan.tasks[taskIndex];
|
|
12134
|
+
if (taskIndex === -1 || !existingTask) {
|
|
12135
|
+
throw new Error(`Task "${taskId}" not found in plan "${slug}"`);
|
|
12136
|
+
}
|
|
12137
|
+
const updatedResult = result ? { ...existingTask.result ?? {}, ...result } : existingTask.result;
|
|
12138
|
+
const updatedTask = {
|
|
12139
|
+
...existingTask,
|
|
12140
|
+
state,
|
|
12141
|
+
...updatedResult !== void 0 ? { result: updatedResult } : {}
|
|
12142
|
+
};
|
|
12143
|
+
const updatedTasks = [...plan.tasks];
|
|
12144
|
+
updatedTasks[taskIndex] = updatedTask;
|
|
12145
|
+
const nextPlan = { ...plan, tasks: updatedTasks };
|
|
12146
|
+
await writePlan(cwd, nextPlan);
|
|
12147
|
+
await appendJournal(cwd, slug, {
|
|
12148
|
+
type: "task_state_changed",
|
|
12149
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12150
|
+
payload: { taskId, state, result }
|
|
12151
|
+
});
|
|
12152
|
+
return await readPlan(cwd, slug) ?? nextPlan;
|
|
12153
|
+
}
|
|
12154
|
+
async function verifyTaskAcceptance(cwd = process.cwd(), slug, taskId, checkIndex, verified, proof) {
|
|
12155
|
+
const plan = await readPlan(cwd, slug);
|
|
12156
|
+
if (!plan) {
|
|
12157
|
+
throw new Error(`Deepwork plan "${slug}" not found`);
|
|
12158
|
+
}
|
|
12159
|
+
const taskIndex = plan.tasks.findIndex((t) => t.id === taskId);
|
|
12160
|
+
const task = plan.tasks[taskIndex];
|
|
12161
|
+
if (taskIndex === -1 || !task) {
|
|
12162
|
+
throw new Error(`Task "${taskId}" not found in plan "${slug}"`);
|
|
12163
|
+
}
|
|
12164
|
+
const currentAcc = task.acceptance[checkIndex];
|
|
12165
|
+
if (!currentAcc) {
|
|
12166
|
+
throw new Error(`Acceptance criterion index ${checkIndex} not found in task "${taskId}"`);
|
|
12167
|
+
}
|
|
12168
|
+
const updatedAcceptance = [...task.acceptance];
|
|
12169
|
+
const resolvedProof = proof ?? currentAcc.proof;
|
|
12170
|
+
updatedAcceptance[checkIndex] = {
|
|
12171
|
+
...currentAcc,
|
|
12172
|
+
verified,
|
|
12173
|
+
...resolvedProof !== void 0 ? { proof: resolvedProof } : {}
|
|
12174
|
+
};
|
|
12175
|
+
const allVerified = updatedAcceptance.every((acc) => acc.verified);
|
|
12176
|
+
const updatedTasks = [...plan.tasks];
|
|
12177
|
+
updatedTasks[taskIndex] = {
|
|
12178
|
+
...task,
|
|
12179
|
+
acceptance: updatedAcceptance,
|
|
12180
|
+
state: allVerified ? "done" : task.state
|
|
12181
|
+
};
|
|
12182
|
+
const nextPlan = { ...plan, tasks: updatedTasks };
|
|
12183
|
+
await writePlan(cwd, nextPlan);
|
|
12184
|
+
await appendJournal(cwd, slug, {
|
|
12185
|
+
type: "acceptance_verified",
|
|
12186
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12187
|
+
payload: { taskId, checkIndex, verified, proof, allVerified }
|
|
12188
|
+
});
|
|
12189
|
+
return await readPlan(cwd, slug) ?? nextPlan;
|
|
12190
|
+
}
|
|
12191
|
+
async function resolvePlanDecision(cwd = process.cwd(), slug, decisionId, chosen) {
|
|
12192
|
+
const plan = await readPlan(cwd, slug);
|
|
12193
|
+
if (!plan) {
|
|
12194
|
+
throw new Error(`Deepwork plan "${slug}" not found`);
|
|
12195
|
+
}
|
|
12196
|
+
const decIndex = plan.decisions_needed.findIndex((d) => d.id === decisionId);
|
|
12197
|
+
const existingDec = plan.decisions_needed[decIndex];
|
|
12198
|
+
if (decIndex === -1 || !existingDec) {
|
|
12199
|
+
throw new Error(`Decision "${decisionId}" not found in plan "${slug}"`);
|
|
12200
|
+
}
|
|
12201
|
+
const updatedDecisions = [...plan.decisions_needed];
|
|
12202
|
+
updatedDecisions[decIndex] = {
|
|
12203
|
+
...existingDec,
|
|
12204
|
+
chosen,
|
|
12205
|
+
status: "resolved"
|
|
12206
|
+
};
|
|
12207
|
+
const nextPlan = { ...plan, decisions_needed: updatedDecisions };
|
|
12208
|
+
await writePlan(cwd, nextPlan);
|
|
12209
|
+
await appendJournal(cwd, slug, {
|
|
12210
|
+
type: "decision_resolved",
|
|
12211
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12212
|
+
payload: { decisionId, chosen }
|
|
12213
|
+
});
|
|
12214
|
+
return await readPlan(cwd, slug) ?? nextPlan;
|
|
12215
|
+
}
|
|
12216
|
+
async function listPlans(cwd = process.cwd()) {
|
|
12217
|
+
const root = deepworkRootDir(cwd);
|
|
12218
|
+
if (!existsSync6(root)) return [];
|
|
12219
|
+
const entries = await readdir(root, { withFileTypes: true });
|
|
12220
|
+
const result = [];
|
|
12221
|
+
for (const entry of entries) {
|
|
12222
|
+
if (entry.isDirectory()) {
|
|
12223
|
+
const plan = await readPlan(cwd, entry.name);
|
|
12224
|
+
if (plan) {
|
|
12225
|
+
result.push({
|
|
12226
|
+
slug: plan.plan_id,
|
|
12227
|
+
title: plan.title,
|
|
12228
|
+
tasks_count: plan.tasks.length,
|
|
12229
|
+
done_count: plan.tasks.filter((t) => t.state === "done").length,
|
|
12230
|
+
updated_at: plan.metadata.updated_at
|
|
12231
|
+
});
|
|
12232
|
+
}
|
|
12233
|
+
}
|
|
12234
|
+
}
|
|
12235
|
+
return result;
|
|
12236
|
+
}
|
|
12237
|
+
|
|
12238
|
+
// src/pantheon/deepwork/deepwork-tool.ts
|
|
12239
|
+
var DeepworkToolInputSchema = z3.object({
|
|
12240
|
+
action: z3.enum([
|
|
12241
|
+
"init",
|
|
12242
|
+
"status",
|
|
12243
|
+
"update_task",
|
|
12244
|
+
"verify_acceptance",
|
|
12245
|
+
"resolve_decision",
|
|
12246
|
+
"list",
|
|
12247
|
+
"get_approval_question"
|
|
12248
|
+
]).default("list"),
|
|
12249
|
+
slug: z3.string().optional(),
|
|
12250
|
+
title: z3.string().optional(),
|
|
12251
|
+
intent: z3.string().optional(),
|
|
12252
|
+
tasks: z3.array(z3.record(z3.string(), z3.unknown())).optional(),
|
|
12253
|
+
decisions: z3.array(z3.record(z3.string(), z3.unknown())).optional(),
|
|
12254
|
+
done_when: z3.array(z3.string()).optional(),
|
|
12255
|
+
taskId: z3.string().optional(),
|
|
12256
|
+
state: z3.enum(["pending", "ready", "in_progress", "done", "failed", "blocked"]).optional(),
|
|
12257
|
+
checkIndex: z3.number().int().min(0).optional(),
|
|
12258
|
+
verified: z3.boolean().optional(),
|
|
12259
|
+
proof: z3.string().optional(),
|
|
12260
|
+
decisionId: z3.string().optional(),
|
|
12261
|
+
choice: z3.string().optional(),
|
|
12262
|
+
summary: z3.string().optional()
|
|
12263
|
+
});
|
|
12264
|
+
function createDeepworkTool(cwd = process.cwd()) {
|
|
12265
|
+
return {
|
|
12266
|
+
name: "pantheon_deepwork",
|
|
12267
|
+
description: "Manage canonical Deepwork plans (.pantheon/deepwork/<slug>/plan.json, journal.ndjson, PLAN.md). Track DAG dependencies, update task states, record fail-first verification receipts, and inspect compact chat projections.",
|
|
12268
|
+
input: {
|
|
12269
|
+
type: "object",
|
|
12270
|
+
properties: {
|
|
12271
|
+
action: {
|
|
12272
|
+
type: "string",
|
|
12273
|
+
enum: [
|
|
12274
|
+
"init",
|
|
12275
|
+
"status",
|
|
12276
|
+
"update_task",
|
|
12277
|
+
"verify_acceptance",
|
|
12278
|
+
"resolve_decision",
|
|
12279
|
+
"list",
|
|
12280
|
+
"get_approval_question"
|
|
12281
|
+
],
|
|
12282
|
+
description: "The Deepwork plan management action to perform."
|
|
12283
|
+
},
|
|
12284
|
+
slug: {
|
|
12285
|
+
type: "string",
|
|
12286
|
+
description: "Unique plan slug / directory name (e.g. auth-jwt, dashboard-ui)."
|
|
12287
|
+
},
|
|
12288
|
+
title: {
|
|
12289
|
+
type: "string",
|
|
12290
|
+
description: "Human-readable title of the deepwork plan (for init)."
|
|
12291
|
+
},
|
|
12292
|
+
intent: {
|
|
12293
|
+
type: "string",
|
|
12294
|
+
description: "The intent, problem description, and objectives (for init)."
|
|
12295
|
+
},
|
|
12296
|
+
tasks: {
|
|
12297
|
+
type: "array",
|
|
12298
|
+
description: "List of structured tasks with acceptance criteria (for init)."
|
|
12299
|
+
},
|
|
12300
|
+
decisions: {
|
|
12301
|
+
type: "array",
|
|
12302
|
+
description: "List of required architectural decisions (for init)."
|
|
12303
|
+
},
|
|
12304
|
+
done_when: {
|
|
12305
|
+
type: "array",
|
|
12306
|
+
description: "List of done criteria strings (for init)."
|
|
12307
|
+
},
|
|
12308
|
+
taskId: {
|
|
12309
|
+
type: "string",
|
|
12310
|
+
description: "Target task ID (e.g. T01, T02) for updates or verification."
|
|
12311
|
+
},
|
|
12312
|
+
state: {
|
|
12313
|
+
type: "string",
|
|
12314
|
+
enum: ["pending", "ready", "in_progress", "done", "failed", "blocked"],
|
|
12315
|
+
description: "New state for the specified task."
|
|
12316
|
+
},
|
|
12317
|
+
checkIndex: {
|
|
12318
|
+
type: "number",
|
|
12319
|
+
description: "Zero-based index of the acceptance criterion to verify."
|
|
12320
|
+
},
|
|
12321
|
+
verified: {
|
|
12322
|
+
type: "boolean",
|
|
12323
|
+
description: "Whether the acceptance criterion check passed."
|
|
12324
|
+
},
|
|
12325
|
+
proof: {
|
|
12326
|
+
type: "string",
|
|
12327
|
+
description: "Evidence snippet, command output, or test receipt."
|
|
12328
|
+
},
|
|
12329
|
+
decisionId: {
|
|
12330
|
+
type: "string",
|
|
12331
|
+
description: "Target decision ID (e.g. D01) for resolution."
|
|
12332
|
+
},
|
|
12333
|
+
choice: {
|
|
12334
|
+
type: "string",
|
|
12335
|
+
description: "The chosen option for the decision."
|
|
12336
|
+
},
|
|
12337
|
+
summary: {
|
|
12338
|
+
type: "string",
|
|
12339
|
+
description: "Summary of results or deliverable for a completed task."
|
|
12340
|
+
}
|
|
12341
|
+
},
|
|
12342
|
+
required: []
|
|
12343
|
+
},
|
|
12344
|
+
output: {},
|
|
12345
|
+
async execute(input, context) {
|
|
12346
|
+
const parsed = DeepworkToolInputSchema.parse(input);
|
|
12347
|
+
const effectiveCwd = typeof context?.directory === "string" ? context.directory : cwd;
|
|
12348
|
+
if (parsed.action === "list") {
|
|
12349
|
+
const plans = await listPlans(effectiveCwd);
|
|
12350
|
+
if (plans.length === 0) {
|
|
12351
|
+
return {
|
|
12352
|
+
output: "Nenhum plano de Deepwork encontrado em .pantheon/deepwork/.",
|
|
12353
|
+
title: "Deepwork: List"
|
|
12354
|
+
};
|
|
12355
|
+
}
|
|
12356
|
+
const lines = [
|
|
12357
|
+
"### Planos de Deepwork Dispon\xEDveis:",
|
|
12358
|
+
"| Slug | T\xEDtulo | Progresso | Atualizado em |",
|
|
12359
|
+
"|---|---|---|---|"
|
|
12360
|
+
];
|
|
12361
|
+
for (const p of plans) {
|
|
12362
|
+
lines.push(
|
|
12363
|
+
`| \`${p.slug}\` | ${p.title} | ${p.done_count}/${p.tasks_count} tarefas | ${p.updated_at} |`
|
|
12364
|
+
);
|
|
12365
|
+
}
|
|
12366
|
+
return {
|
|
12367
|
+
output: lines.join("\n"),
|
|
12368
|
+
title: "Deepwork: List"
|
|
12369
|
+
};
|
|
12370
|
+
}
|
|
12371
|
+
const slug = parsed.slug?.trim();
|
|
12372
|
+
if (!slug) {
|
|
12373
|
+
throw new Error(`O par\xE2metro 'slug' \xE9 obrigat\xF3rio para a a\xE7\xE3o '${parsed.action}'.`);
|
|
12374
|
+
}
|
|
12375
|
+
if (parsed.action === "init") {
|
|
12376
|
+
const title = parsed.title?.trim() || slug;
|
|
12377
|
+
const intent = parsed.intent?.trim() || "Plano de deepwork estruturado.";
|
|
12378
|
+
const rawTasks = parsed.tasks ?? [];
|
|
12379
|
+
const rawDecisions = parsed.decisions ?? [];
|
|
12380
|
+
const doneWhen = parsed.done_when ?? [];
|
|
12381
|
+
const tasks = rawTasks.map((t, idx) => ({
|
|
12382
|
+
id: typeof t.id === "string" ? t.id : `T${String(idx + 1).padStart(2, "0")}`,
|
|
12383
|
+
title: typeof t.title === "string" ? t.title : `Task ${idx + 1}`,
|
|
12384
|
+
description: typeof t.description === "string" ? t.description : void 0,
|
|
12385
|
+
agent: typeof t.agent === "string" ? t.agent : "zeus",
|
|
12386
|
+
phase: typeof t.phase === "number" ? t.phase : 1,
|
|
12387
|
+
state: typeof t.state === "string" ? t.state : "pending",
|
|
12388
|
+
depends_on: Array.isArray(t.depends_on) ? t.depends_on : [],
|
|
12389
|
+
parallel_safe: Boolean(t.parallel_safe),
|
|
12390
|
+
acceptance: Array.isArray(t.acceptance) ? t.acceptance.map((a) => ({
|
|
12391
|
+
kind: a.kind || "command",
|
|
12392
|
+
check: a.check || "verify",
|
|
12393
|
+
fails_now: a.fails_now ?? true,
|
|
12394
|
+
verified: a.verified ?? false,
|
|
12395
|
+
proof: a.proof
|
|
12396
|
+
})) : []
|
|
12397
|
+
}));
|
|
12398
|
+
const decisions = rawDecisions.map((d, idx) => ({
|
|
12399
|
+
id: typeof d.id === "string" ? d.id : `D${String(idx + 1).padStart(2, "0")}`,
|
|
12400
|
+
question: typeof d.question === "string" ? d.question : "Decis\xE3o necess\xE1ria",
|
|
12401
|
+
options: Array.isArray(d.options) ? d.options : ["Sim", "N\xE3o"],
|
|
12402
|
+
chosen: typeof d.chosen === "string" ? d.chosen : void 0,
|
|
12403
|
+
status: d.chosen ? "resolved" : "pending"
|
|
12404
|
+
}));
|
|
12405
|
+
const initialPlan = computeTaskReadiness({
|
|
12406
|
+
plan_id: slug,
|
|
12407
|
+
title,
|
|
12408
|
+
intent,
|
|
12409
|
+
done_when: doneWhen,
|
|
12410
|
+
decisions_needed: decisions,
|
|
12411
|
+
risks: [],
|
|
12412
|
+
out_of_scope: [],
|
|
12413
|
+
tasks,
|
|
12414
|
+
metadata: {
|
|
12415
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12416
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12417
|
+
version: 1
|
|
12418
|
+
}
|
|
12419
|
+
});
|
|
12420
|
+
await writePlan(effectiveCwd, initialPlan);
|
|
12421
|
+
await appendJournal(effectiveCwd, slug, {
|
|
12422
|
+
type: "plan_created",
|
|
12423
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12424
|
+
payload: { slug, title, tasks_count: tasks.length }
|
|
12425
|
+
});
|
|
12426
|
+
const projection = generateChatProjection(initialPlan, effectiveCwd);
|
|
12427
|
+
const approvalQ = buildApprovalQuestion(initialPlan);
|
|
12428
|
+
return {
|
|
12429
|
+
output: [
|
|
12430
|
+
`\u2705 Plano de Deepwork '${title}' inicializado com sucesso em \`.pantheon/deepwork/${slug}/\`!`,
|
|
12431
|
+
`- \u{1F517} **Deeplink PLAN.md:** [Abrir PLAN.md](file://${deepworkPlanMdPath(effectiveCwd, slug)})`,
|
|
12432
|
+
`- \u{1F517} **Deeplink plan.json:** [Abrir plan.json](file://${deepworkPlanJsonPath(effectiveCwd, slug)})`,
|
|
12433
|
+
"",
|
|
12434
|
+
projection,
|
|
12435
|
+
"",
|
|
12436
|
+
"**Pergunta de Aprova\xE7\xE3o Nativa (Gate 1):**",
|
|
12437
|
+
`\`${JSON.stringify(approvalQ)}\``
|
|
12438
|
+
].join("\n"),
|
|
12439
|
+
title: `Deepwork Init: ${slug}`
|
|
12440
|
+
};
|
|
12441
|
+
}
|
|
12442
|
+
const currentPlan = await readPlan(effectiveCwd, slug);
|
|
12443
|
+
if (!currentPlan) {
|
|
12444
|
+
throw new Error(`Plano de Deepwork '${slug}' n\xE3o encontrado.`);
|
|
12445
|
+
}
|
|
12446
|
+
if (parsed.action === "status") {
|
|
12447
|
+
const projection = generateChatProjection(currentPlan, effectiveCwd);
|
|
12448
|
+
const dag = generateMermaidDag(currentPlan);
|
|
12449
|
+
return {
|
|
12450
|
+
output: [projection, "", "#### Grafo de Depend\xEAncias (DAG):", dag].join("\n"),
|
|
12451
|
+
title: `Deepwork Status: ${slug}`
|
|
12452
|
+
};
|
|
12453
|
+
}
|
|
12454
|
+
if (parsed.action === "get_approval_question") {
|
|
12455
|
+
const q = buildApprovalQuestion(currentPlan);
|
|
12456
|
+
return {
|
|
12457
|
+
output: JSON.stringify(q, null, 2),
|
|
12458
|
+
title: `Deepwork Approval Question: ${slug}`
|
|
12459
|
+
};
|
|
12460
|
+
}
|
|
12461
|
+
if (parsed.action === "update_task") {
|
|
12462
|
+
if (!parsed.taskId) throw new Error("Par\xE2metro 'taskId' obrigat\xF3rio para update_task.");
|
|
12463
|
+
if (!parsed.state) throw new Error("Par\xE2metro 'state' obrigat\xF3rio para update_task.");
|
|
12464
|
+
const resultMeta = {};
|
|
12465
|
+
if (parsed.summary !== void 0) {
|
|
12466
|
+
resultMeta.summary = parsed.summary;
|
|
12467
|
+
}
|
|
12468
|
+
const updated = await updateTaskState(
|
|
12469
|
+
effectiveCwd,
|
|
12470
|
+
slug,
|
|
12471
|
+
parsed.taskId,
|
|
12472
|
+
parsed.state,
|
|
12473
|
+
resultMeta
|
|
12474
|
+
);
|
|
12475
|
+
const projection = generateChatProjection(updated, effectiveCwd);
|
|
12476
|
+
return {
|
|
12477
|
+
output: [
|
|
12478
|
+
`Tarefa **[${parsed.taskId}]** atualizada para \`${parsed.state}\`.`,
|
|
12479
|
+
"",
|
|
12480
|
+
projection
|
|
12481
|
+
].join("\n"),
|
|
12482
|
+
title: `Deepwork Task: ${parsed.taskId} -> ${parsed.state}`
|
|
12483
|
+
};
|
|
12484
|
+
}
|
|
12485
|
+
if (parsed.action === "verify_acceptance") {
|
|
12486
|
+
if (!parsed.taskId)
|
|
12487
|
+
throw new Error("Par\xE2metro 'taskId' obrigat\xF3rio para verify_acceptance.");
|
|
12488
|
+
if (parsed.checkIndex === void 0)
|
|
12489
|
+
throw new Error("Par\xE2metro 'checkIndex' obrigat\xF3rio para verify_acceptance.");
|
|
12490
|
+
if (parsed.verified === void 0)
|
|
12491
|
+
throw new Error("Par\xE2metro 'verified' obrigat\xF3rio para verify_acceptance.");
|
|
12492
|
+
const updated = await verifyTaskAcceptance(
|
|
12493
|
+
effectiveCwd,
|
|
12494
|
+
slug,
|
|
12495
|
+
parsed.taskId,
|
|
12496
|
+
parsed.checkIndex,
|
|
12497
|
+
parsed.verified,
|
|
12498
|
+
parsed.proof
|
|
12499
|
+
);
|
|
12500
|
+
const projection = generateChatProjection(updated, effectiveCwd);
|
|
12501
|
+
return {
|
|
12502
|
+
output: [
|
|
12503
|
+
`Crit\xE9rio de aceite #${parsed.checkIndex} da tarefa **[${parsed.taskId}]** verificado: ${parsed.verified ? "\u2705 PASS" : "\u274C FAIL"}.`,
|
|
12504
|
+
parsed.proof ? `*Evid\xEAncia/Receipt:* \`${parsed.proof}\`` : "",
|
|
12505
|
+
"",
|
|
12506
|
+
projection
|
|
12507
|
+
].filter(Boolean).join("\n"),
|
|
12508
|
+
title: `Deepwork Verify: ${parsed.taskId} [${parsed.checkIndex}]`
|
|
12509
|
+
};
|
|
12510
|
+
}
|
|
12511
|
+
if (parsed.action === "resolve_decision") {
|
|
12512
|
+
if (!parsed.decisionId)
|
|
12513
|
+
throw new Error("Par\xE2metro 'decisionId' obrigat\xF3rio para resolve_decision.");
|
|
12514
|
+
if (!parsed.choice) throw new Error("Par\xE2metro 'choice' obrigat\xF3rio para resolve_decision.");
|
|
12515
|
+
const updated = await resolvePlanDecision(
|
|
12516
|
+
effectiveCwd,
|
|
12517
|
+
slug,
|
|
12518
|
+
parsed.decisionId,
|
|
12519
|
+
parsed.choice
|
|
12520
|
+
);
|
|
12521
|
+
const projection = generateChatProjection(updated, effectiveCwd);
|
|
12522
|
+
return {
|
|
12523
|
+
output: [
|
|
12524
|
+
`Decis\xE3o **[${parsed.decisionId}]** resolvida com a op\xE7\xE3o: "${parsed.choice}".`,
|
|
12525
|
+
"",
|
|
12526
|
+
projection
|
|
12527
|
+
].join("\n"),
|
|
12528
|
+
title: `Deepwork Decision: ${parsed.decisionId}`
|
|
12529
|
+
};
|
|
12530
|
+
}
|
|
12531
|
+
throw new Error(`A\xE7\xE3o '${parsed.action}' n\xE3o reconhecida.`);
|
|
12532
|
+
}
|
|
12533
|
+
};
|
|
12534
|
+
}
|
|
12535
|
+
|
|
11616
12536
|
// src/pantheon/hashline/tool.ts
|
|
11617
|
-
import { readFile as
|
|
12537
|
+
import { readFile as readFile7, rename as rename6, rm, writeFile as writeFile4 } from "node:fs/promises";
|
|
11618
12538
|
import { isAbsolute as isAbsolute4, resolve as resolve6, sep as sep4 } from "node:path";
|
|
11619
|
-
import { z as
|
|
12539
|
+
import { z as z4 } from "zod";
|
|
11620
12540
|
var hashlineEditOpArgs = {
|
|
11621
|
-
op:
|
|
11622
|
-
ref:
|
|
11623
|
-
endRef:
|
|
11624
|
-
lines:
|
|
11625
|
-
content:
|
|
12541
|
+
op: z4.enum(["replace", "append", "prepend", "delete"]),
|
|
12542
|
+
ref: z4.string().min(1),
|
|
12543
|
+
endRef: z4.string().optional(),
|
|
12544
|
+
lines: z4.array(z4.string()).optional(),
|
|
12545
|
+
content: z4.string().optional()
|
|
11626
12546
|
};
|
|
11627
12547
|
var hashlineEditArgs = {
|
|
11628
|
-
file:
|
|
11629
|
-
edits:
|
|
12548
|
+
file: z4.string().min(1),
|
|
12549
|
+
edits: z4.array(z4.object(hashlineEditOpArgs)).min(1)
|
|
11630
12550
|
};
|
|
11631
12551
|
function resolveFile(file, ctx) {
|
|
11632
12552
|
if (isAbsolute4(file)) return { ok: true, file: resolve6(file) };
|
|
@@ -11698,7 +12618,7 @@ function createHashlineEditTool() {
|
|
|
11698
12618
|
const file = resolved.file;
|
|
11699
12619
|
let original;
|
|
11700
12620
|
try {
|
|
11701
|
-
original = await
|
|
12621
|
+
original = await readFile7(file, "utf8");
|
|
11702
12622
|
} catch {
|
|
11703
12623
|
return `hashline_edit: cannot read "${file}" \u2014 check the path and try again`;
|
|
11704
12624
|
}
|
|
@@ -11724,8 +12644,8 @@ function createHashlineEditTool() {
|
|
|
11724
12644
|
if (hadTrailingNewline && !out.endsWith("\n")) out += "\n";
|
|
11725
12645
|
const tmpPath = `${file}.tmp-${process.pid}`;
|
|
11726
12646
|
try {
|
|
11727
|
-
await
|
|
11728
|
-
await
|
|
12647
|
+
await writeFile4(tmpPath, out, "utf8");
|
|
12648
|
+
await rename6(tmpPath, file);
|
|
11729
12649
|
} catch {
|
|
11730
12650
|
await rm(tmpPath, { force: true }).catch(() => {
|
|
11731
12651
|
});
|
|
@@ -11880,21 +12800,21 @@ function createV2LocalDecisionDefinition(options = {}) {
|
|
|
11880
12800
|
// src/pantheon/model-command.ts
|
|
11881
12801
|
import { randomBytes } from "node:crypto";
|
|
11882
12802
|
import { constants as constants4 } from "node:fs";
|
|
11883
|
-
import { lstat as lstat2, mkdir as
|
|
12803
|
+
import { lstat as lstat2, mkdir as mkdir7, open as open3, rename as rename7, unlink as unlink4 } from "node:fs/promises";
|
|
11884
12804
|
import { homedir as homedir7 } from "node:os";
|
|
11885
|
-
import { basename as basename2, dirname as dirname9, join as
|
|
11886
|
-
import { z as
|
|
12805
|
+
import { basename as basename2, dirname as dirname9, join as join17, resolve as resolve7 } from "node:path";
|
|
12806
|
+
import { z as z5 } from "zod";
|
|
11887
12807
|
var MODEL_REF_PATTERN2 = /^[A-Za-z0-9][A-Za-z0-9._-]*\/[A-Za-z0-9][A-Za-z0-9._:+-]*$/;
|
|
11888
12808
|
var SAFE_PRESET_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
11889
12809
|
var KNOWN_AGENTS_SET2 = new Set(KNOWN_AGENTS);
|
|
11890
12810
|
var modelArgs = {
|
|
11891
|
-
action:
|
|
11892
|
-
agent:
|
|
11893
|
-
model:
|
|
11894
|
-
effort:
|
|
11895
|
-
scope:
|
|
11896
|
-
confirm:
|
|
11897
|
-
authorize_global:
|
|
12811
|
+
action: z5.enum(["status", "show", "set", "reset"]).optional().describe("Operation: status/show, set, or reset. No args runs wizard."),
|
|
12812
|
+
agent: z5.string().optional().describe("Agent name (one of 14 canonical agents)."),
|
|
12813
|
+
model: z5.string().optional().describe("Model in provider/model-id format; used by set."),
|
|
12814
|
+
effort: z5.enum(["low", "medium", "high"]).optional().describe("Reasoning effort (variant), clamped to model capability."),
|
|
12815
|
+
scope: z5.enum(["project", "global"]).optional().describe("Configuration scope for active-preset.json (default project)."),
|
|
12816
|
+
confirm: z5.boolean().optional().describe("Explicitly confirm a mutating operation, required for global changes."),
|
|
12817
|
+
authorize_global: z5.boolean().optional().describe("Separate authorization for changing global configuration; not implied by -y.")
|
|
11898
12818
|
};
|
|
11899
12819
|
var ModelCommandError = class extends Error {
|
|
11900
12820
|
constructor(message) {
|
|
@@ -11971,7 +12891,7 @@ async function createTemporaryFile(path5) {
|
|
|
11971
12891
|
const prefix = `.${basename2(path5)}.tmp-`;
|
|
11972
12892
|
const flags = constants4.O_WRONLY | constants4.O_CREAT | constants4.O_EXCL | NO_FOLLOW;
|
|
11973
12893
|
for (let attempt = 0; attempt < 10; attempt += 1) {
|
|
11974
|
-
const temporaryPath =
|
|
12894
|
+
const temporaryPath = join17(directory, `${prefix}${randomBytes(16).toString("hex")}`);
|
|
11975
12895
|
try {
|
|
11976
12896
|
return { path: temporaryPath, file: await open3(temporaryPath, flags, DEFAULT_FILE_MODE) };
|
|
11977
12897
|
} catch (error) {
|
|
@@ -12005,7 +12925,7 @@ async function atomicReplace(path5, content, mode, label, expectedExists) {
|
|
|
12005
12925
|
if (current !== void 0 !== expectedExists) {
|
|
12006
12926
|
throw new ModelCommandError(`${label} changed while it was being updated`);
|
|
12007
12927
|
}
|
|
12008
|
-
await
|
|
12928
|
+
await rename7(temporaryPath, path5);
|
|
12009
12929
|
renamed = true;
|
|
12010
12930
|
await syncDirectory(dirname9(path5));
|
|
12011
12931
|
} finally {
|
|
@@ -12038,28 +12958,28 @@ function envValue(options) {
|
|
|
12038
12958
|
return options.env ?? process.env;
|
|
12039
12959
|
}
|
|
12040
12960
|
function projectConfigPath(options) {
|
|
12041
|
-
return options.projectConfigPath ??
|
|
12961
|
+
return options.projectConfigPath ?? join17(options.cwd ?? process.cwd(), "opencode.json");
|
|
12042
12962
|
}
|
|
12043
12963
|
function defaultGlobalConfigPath(options) {
|
|
12044
12964
|
const env = envValue(options);
|
|
12045
12965
|
const home = env.HOME?.trim() || homedir7();
|
|
12046
|
-
const xdg = env.XDG_CONFIG_HOME?.trim() ||
|
|
12047
|
-
return
|
|
12966
|
+
const xdg = env.XDG_CONFIG_HOME?.trim() || join17(home, ".config");
|
|
12967
|
+
return join17(xdg, "opencode", "opencode.json");
|
|
12048
12968
|
}
|
|
12049
12969
|
function globalConfigCandidates(options) {
|
|
12050
12970
|
if (options.globalConfigPath !== void 0) return [options.globalConfigPath];
|
|
12051
12971
|
const canonical = defaultGlobalConfigPath(options);
|
|
12052
12972
|
const home = envValue(options).HOME?.trim() || homedir7();
|
|
12053
|
-
const legacy =
|
|
12973
|
+
const legacy = join17(home, ".opencode", "opencode.json");
|
|
12054
12974
|
return [.../* @__PURE__ */ new Set([canonical, legacy])];
|
|
12055
12975
|
}
|
|
12056
12976
|
function activePresetCandidatesList(options) {
|
|
12057
12977
|
if (options.activePresetCandidates !== void 0) {
|
|
12058
12978
|
return options.activePresetCandidates.map((p) => resolve7(p));
|
|
12059
12979
|
}
|
|
12060
|
-
const projectPreset =
|
|
12980
|
+
const projectPreset = join17(dirname9(projectConfigPath(options)), ".pantheon", "active-preset.json");
|
|
12061
12981
|
const globalPresets = globalConfigCandidates(options).map(
|
|
12062
|
-
(p) =>
|
|
12982
|
+
(p) => join17(dirname9(p), ".pantheon", "active-preset.json")
|
|
12063
12983
|
);
|
|
12064
12984
|
return [...new Set([projectPreset, ...globalPresets].map((p) => resolve7(p)))];
|
|
12065
12985
|
}
|
|
@@ -12073,7 +12993,7 @@ function presetPathForScope(options, scope) {
|
|
|
12073
12993
|
const second = candidates[1];
|
|
12074
12994
|
if (second) return second;
|
|
12075
12995
|
const globalCandidates = globalConfigCandidates(options).map(
|
|
12076
|
-
(p) => resolve7(
|
|
12996
|
+
(p) => resolve7(join17(dirname9(p), ".pantheon", "active-preset.json"))
|
|
12077
12997
|
);
|
|
12078
12998
|
const fallback = globalCandidates[0] ?? candidates[0];
|
|
12079
12999
|
if (!fallback) throw new ModelCommandError("global preset path is unavailable");
|
|
@@ -12203,7 +13123,7 @@ function validateMutationAuthorization(args, scope) {
|
|
|
12203
13123
|
}
|
|
12204
13124
|
async function writeActivePresetAtomically(path5, data, current) {
|
|
12205
13125
|
const backupPath = `${path5}.bak`;
|
|
12206
|
-
await
|
|
13126
|
+
await mkdir7(dirname9(path5), { recursive: true });
|
|
12207
13127
|
const originalMode = current.mode ?? DEFAULT_FILE_MODE;
|
|
12208
13128
|
const backupMode = originalMode & 384;
|
|
12209
13129
|
const backup = await regularPath(backupPath, "configuration backup");
|
|
@@ -12592,9 +13512,7 @@ async function runWizard(options) {
|
|
|
12592
13512
|
function createModelCommand(options = {}) {
|
|
12593
13513
|
const args = options.v2Mode ? {
|
|
12594
13514
|
...modelArgs,
|
|
12595
|
-
action: modelArgs.action.describe(
|
|
12596
|
-
"Operation: status/show, set, or reset. V1 no-args invocation runs the legacy wizard."
|
|
12597
|
-
)
|
|
13515
|
+
action: modelArgs.action.describe("Operation: status/show, set, or reset.")
|
|
12598
13516
|
} : modelArgs;
|
|
12599
13517
|
return {
|
|
12600
13518
|
pantheon_model: {
|
|
@@ -12850,7 +13768,7 @@ var invokedDirectly = process.argv[1] !== void 0 && import.meta.url === pathToFi
|
|
|
12850
13768
|
if (invokedDirectly) main();
|
|
12851
13769
|
|
|
12852
13770
|
// src/pantheon/skill-search-tool.ts
|
|
12853
|
-
var TOOL_DESCRIPTION3 = "Advisory discovery tool for skills. Queries installed Pantheon skills and external registries (Anthropic catalog, skills.sh, GitHub). Returns matched skill IDs, descriptions, install counts, and provenance tiers. Zeus uses this to recommend skills before prompting the user
|
|
13771
|
+
var TOOL_DESCRIPTION3 = "Advisory discovery tool for skills. Queries installed Pantheon skills and external registries (Anthropic catalog, skills.sh, GitHub). Returns matched skill IDs, descriptions, install counts, and provenance tiers. Zeus uses this to recommend project-scoped skills (.agents/skills/) before proactively prompting the user via the question tool.";
|
|
12854
13772
|
var SKILL_SEARCH_INPUT_SCHEMA = {
|
|
12855
13773
|
type: "object",
|
|
12856
13774
|
additionalProperties: false,
|
|
@@ -12938,7 +13856,7 @@ function executeSkillSearch(input) {
|
|
|
12938
13856
|
installed: false,
|
|
12939
13857
|
installs: entry.installs ?? null,
|
|
12940
13858
|
url: entry.url,
|
|
12941
|
-
installCommand: `npx skills add ${entry.skill} -a opencode`
|
|
13859
|
+
installCommand: `npx skills add ${entry.skill} -a opencode -y`
|
|
12942
13860
|
});
|
|
12943
13861
|
}
|
|
12944
13862
|
}
|
|
@@ -13265,6 +14183,7 @@ function createV2ToolDefinitions(visionRuntime, shadow = {}, jevRuntime) {
|
|
|
13265
14183
|
);
|
|
13266
14184
|
definitions.push(todowriteTool);
|
|
13267
14185
|
definitions.push(createV2SkillSearchDefinition());
|
|
14186
|
+
definitions.push(createDeepworkTool());
|
|
13268
14187
|
if (visionRuntime) definitions.push(createV2VisionTool(visionRuntime));
|
|
13269
14188
|
if (jevRuntime) definitions.push(createV2JevDecisionDefinition(jevRuntime));
|
|
13270
14189
|
return definitions;
|