pantheon-opencode 1.6.0 → 1.6.2-beta.1
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 +11 -11
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +45 -0
- package/README.md +122 -6
- package/README.pt-BR.md +14 -9
- package/bin/pantheon-init.mjs +255 -39
- package/package.json +8 -6
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +1 -1
- package/scripts/doctor.mjs +231 -46
- package/scripts/install/agents-md.mjs +2 -1
- package/scripts/install/config-migration.mjs +344 -393
- package/scripts/install/config-paths.mjs +15 -0
- package/scripts/install/interactive.mjs +30 -9
- package/scripts/install/interrupt.mjs +78 -0
- package/scripts/install/mcp-permissions.mjs +164 -0
- package/scripts/install/opencode-state.mjs +91 -0
- package/scripts/install/opencode-version.mjs +31 -13
- package/scripts/install/opencode-wildcard.mjs +106 -0
- package/scripts/install/opencode.mjs +508 -108
- package/scripts/install/plan-artifact.mjs +12 -1
- package/scripts/install/plugin.mjs +17 -1
- package/scripts/install/run-record.mjs +115 -0
- package/scripts/install/strings.mjs +35 -6
- package/scripts/install/v2-capabilities.mjs +204 -0
- package/scripts/package-evidence.mjs +1 -0
- package/scripts/release-gates.mjs +7 -2
- package/scripts/sandbox-env.sh +174 -0
- package/scripts/setup-v2-config.mjs +1703 -0
- package/scripts/setup.mjs +415 -0
- package/scripts/sync-tui.mjs +9 -1
- package/scripts/test-opencode-v2-sandbox.sh +438 -151
- package/scripts/update-skills-lock.mjs +30 -0
- package/skills-lock.json +10 -10
- package/src/agents/aphrodite.md +5 -2
- package/src/agents/apollo.md +5 -0
- package/src/agents/athena.md +6 -1
- package/src/agents/demeter.md +5 -1
- package/src/agents/gaia.md +4 -0
- package/src/agents/hephaestus.md +6 -1
- package/src/agents/hermes.md +6 -3
- package/src/agents/iris.md +5 -1
- package/src/agents/mnemosyne.md +20 -50
- package/src/agents/nyx.md +5 -1
- package/src/agents/prometheus.md +4 -0
- package/src/agents/talos.md +4 -0
- package/src/agents/themis.md +4 -0
- package/src/agents/zeus.md +9 -3
- package/src/instructions/agent-return-format.instructions.md +1 -1
- package/src/instructions/memory-protocol.instructions.md +3 -3
- package/src/instructions/test-economy.instructions.md +6 -6
- package/src/mcp/pantheon_vision.py +37 -36
- package/src/mcp/requirements-mcp.txt +1 -1
- package/src/mcp/requirements-vision.txt +1 -1
- package/src/pantheon/cost-command.ts +127 -40
- package/src/pantheon/delegation-enforce.ts +160 -23
- package/src/pantheon/guard-path.ts +162 -0
- package/src/pantheon/v2-bounded-read.ts +15 -1
- package/src/pantheon/v2-bridge.ts +27 -0
- package/src/pantheon/v2-shell-hooks.ts +260 -0
- package/src/pantheon/v2-unsupported.mjs +32 -4
- package/src/pantheon/v2-vision.ts +34 -29
- package/src/pantheon/vision.ts +49 -11
- package/src/plugin-v2.ts +413 -60
- package/src/plugin.ts +22 -2
- package/src/plugins/tui/dist/quota-adapters.d.ts +89 -0
- package/src/plugins/tui/dist/quota-adapters.d.ts.map +1 -0
- package/src/plugins/tui/dist/quota-adapters.js +1142 -0
- package/src/plugins/tui/dist/quota-adapters.js.map +1 -0
- package/src/plugins/tui/dist/quota-cli.d.ts +17 -0
- package/src/plugins/tui/dist/quota-cli.d.ts.map +1 -0
- package/src/plugins/tui/dist/quota-cli.js +184 -0
- package/src/plugins/tui/dist/quota-cli.js.map +1 -0
- package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js +390 -0
- package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js.map +1 -0
- package/src/plugins/tui/dist/server-v2.d.ts +14 -0
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
- package/src/plugins/tui/dist/server-v2.js +673 -0
- package/src/plugins/tui/dist/server-v2.js.map +1 -0
- package/src/plugins/tui/dist/tui-v2.d.ts +247 -52
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +2492 -529
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/index-v2.ts +3 -6
- package/src/plugins/tui/package-lock.json +11 -11
- package/src/plugins/tui/package.json +6 -4
- package/src/plugins/tui/src/context-gauge.ts +59 -0
- package/src/plugins/tui/src/go-key-diagnostic-ui.ts +100 -0
- package/src/plugins/tui/src/go-key-diagnostic.ts +125 -0
- package/src/plugins/tui/src/index-v2.tsx +199 -240
- package/src/plugins/tui/src/model-usage-limits.ts +4 -0
- package/src/plugins/tui/src/quota-adapters.ts +1598 -0
- package/src/plugins/tui/src/quota-cli.ts +237 -0
- package/src/plugins/tui/src/quota-rpc.ts +209 -0
- package/src/plugins/tui/src/quota-v2-model.ts +1032 -0
- package/src/plugins/tui/src/quota-v2.tsx +986 -0
- package/src/plugins/tui/src/server-v2.ts +841 -0
- package/src/plugins/tui/src/sidebar-width.ts +129 -0
- package/src/plugins/tui/tsconfig.typecheck.json +1 -1
- package/src/plugins/tui/tsdown.config.ts +8 -1
- package/src/routing.yml +72 -13
- package/src/skills/README.md +4 -0
- package/src/skills/agent-coordination/SKILL.md +0 -3
- package/src/skills/artifact-management/SKILL.md +0 -3
- package/src/skills/auto-continue/SKILL.md +0 -3
- package/src/skills/code-review-checklist/SKILL.md +0 -3
- package/src/skills/context-compression/SKILL.md +0 -3
- package/src/skills/memory-bank/SKILL.md +6 -28
- package/src/skills/session-goal/SKILL.md +0 -3
- package/src/skills/simplify/SKILL.md +5 -4
- package/src/skills/tdd-with-agents/SKILL.md +0 -3
- package/src/skills/visual-review-pipeline/SKILL.md +0 -1
- package/src/pantheon/memory-context.ts +0 -1017
|
@@ -63,8 +63,18 @@ export interface CostRow {
|
|
|
63
63
|
tokensInput: number
|
|
64
64
|
tokensOutput: number
|
|
65
65
|
tokensTotal: number
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* USD for this row: the sum of every contributing model's own priced cost.
|
|
68
|
+
* Absent only when NO contributing model could be priced — a row that mixes
|
|
69
|
+
* priced and unpriced models keeps its numeric part.
|
|
70
|
+
*/
|
|
67
71
|
costUsd?: number
|
|
72
|
+
/**
|
|
73
|
+
* Number of contributing model groups the catalog could not price. Present
|
|
74
|
+
* only alongside `costUsd`, so the reader can tell a partially priced row
|
|
75
|
+
* (money shown, some tokens unpriced) from a fully priced one.
|
|
76
|
+
*/
|
|
77
|
+
unpricedModels?: number
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
/** One aggregated row per (agent, phase, provider, model). */
|
|
@@ -92,7 +102,10 @@ export interface CostSessionRow {
|
|
|
92
102
|
tokensCacheRead: number
|
|
93
103
|
tokensCacheWrite: number
|
|
94
104
|
tokensTotal: number
|
|
105
|
+
/** Sum of the priced model rows in this session; absent when none priced. */
|
|
95
106
|
costUsd?: number
|
|
107
|
+
/** Unpriced model rows folded into this session; present with `costUsd`. */
|
|
108
|
+
unpricedModels?: number
|
|
96
109
|
unpricedReason?: UnpricedReason
|
|
97
110
|
}
|
|
98
111
|
|
|
@@ -566,8 +579,12 @@ interface SessionAccumulator {
|
|
|
566
579
|
tokensOutput: number
|
|
567
580
|
tokensCacheRead: number
|
|
568
581
|
tokensCacheWrite: number
|
|
569
|
-
|
|
570
|
-
|
|
582
|
+
/** Priced dollars accumulated; meaningful only when `priced` > 0. */
|
|
583
|
+
usd: number
|
|
584
|
+
/** Model rows that produced a price. */
|
|
585
|
+
priced: number
|
|
586
|
+
/** Model rows with no usable catalog price. */
|
|
587
|
+
unpricedModels: number
|
|
571
588
|
reason: UnpricedReason | undefined
|
|
572
589
|
}
|
|
573
590
|
|
|
@@ -729,7 +746,8 @@ function queryWithSqlite(
|
|
|
729
746
|
tokensCacheRead: 0,
|
|
730
747
|
tokensCacheWrite: 0,
|
|
731
748
|
usd: 0,
|
|
732
|
-
|
|
749
|
+
priced: 0,
|
|
750
|
+
unpricedModels: 0,
|
|
733
751
|
reason: undefined,
|
|
734
752
|
}
|
|
735
753
|
sessionAcc.agents.add(agent)
|
|
@@ -737,24 +755,26 @@ function queryWithSqlite(
|
|
|
737
755
|
sessionAcc.tokensOutput += tokens.output
|
|
738
756
|
sessionAcc.tokensCacheRead += tokens.cacheRead
|
|
739
757
|
sessionAcc.tokensCacheWrite += tokens.cacheWrite
|
|
740
|
-
if ('usd' in priced
|
|
758
|
+
if ('usd' in priced) {
|
|
741
759
|
sessionAcc.usd += priced.usd
|
|
760
|
+
sessionAcc.priced += 1
|
|
742
761
|
} else {
|
|
743
|
-
sessionAcc.
|
|
744
|
-
sessionAcc.
|
|
745
|
-
sessionAcc.reason = sessionAcc.reason ?? ('reason' in priced ? priced.reason : undefined)
|
|
762
|
+
sessionAcc.unpricedModels += 1
|
|
763
|
+
sessionAcc.reason = sessionAcc.reason ?? priced.reason
|
|
746
764
|
}
|
|
747
765
|
sessions.set(sessionId, sessionAcc)
|
|
748
766
|
}
|
|
749
767
|
}
|
|
750
768
|
|
|
751
769
|
// The by-agent table is derived from the model groups, so every table in
|
|
752
|
-
// the report is backed by exactly one set of token sums.
|
|
753
|
-
//
|
|
754
|
-
//
|
|
770
|
+
// the report is backed by exactly one set of token sums. Cost is attributed
|
|
771
|
+
// per model and summed here: a bucket that spans several models is a sum of
|
|
772
|
+
// its priced models, never `—`, because an ambiguous bucket is not the same
|
|
773
|
+
// thing as an unknown price. `unpricedModels` records how many contributors
|
|
774
|
+
// had no catalog price, so `(partial)` keeps a single, honest meaning.
|
|
755
775
|
const byAgentPhase = new Map<
|
|
756
776
|
string,
|
|
757
|
-
{ row: CostRow; usd: number
|
|
777
|
+
{ row: CostRow; usd: number; priced: number; unpricedModels: number }
|
|
758
778
|
>()
|
|
759
779
|
for (const acc of models.values()) {
|
|
760
780
|
const key = `${acc.agent}\u0000${acc.phase}`
|
|
@@ -767,26 +787,29 @@ function queryWithSqlite(
|
|
|
767
787
|
tokensTotal: 0,
|
|
768
788
|
},
|
|
769
789
|
usd: 0,
|
|
770
|
-
|
|
790
|
+
priced: 0,
|
|
791
|
+
unpricedModels: 0,
|
|
771
792
|
}
|
|
772
793
|
entry.row.tokensInput += acc.tokensInput
|
|
773
794
|
entry.row.tokensOutput += acc.tokensOutput
|
|
774
795
|
entry.row.tokensTotal += acc.tokensInput + acc.tokensOutput
|
|
775
|
-
if (acc.
|
|
776
|
-
entry.
|
|
777
|
-
|
|
778
|
-
} else if (acc.usd !== undefined) {
|
|
796
|
+
if (acc.usd === undefined) {
|
|
797
|
+
entry.unpricedModels += 1
|
|
798
|
+
} else {
|
|
779
799
|
entry.usd += acc.usd
|
|
800
|
+
entry.priced += 1
|
|
780
801
|
}
|
|
781
802
|
byAgentPhase.set(key, entry)
|
|
782
803
|
}
|
|
783
804
|
|
|
784
805
|
const rows: CostRow[] = [...byAgentPhase.values()]
|
|
785
|
-
.map((
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
806
|
+
.map(({ row, usd, priced, unpricedModels }) => ({
|
|
807
|
+
...row,
|
|
808
|
+
// Absent cost means "nothing in this row could be priced"; a numeric
|
|
809
|
+
// cost with `unpricedModels` means "this row is partly priced".
|
|
810
|
+
...(priced === 0 ? {} : { costUsd: usd }),
|
|
811
|
+
...(priced === 0 || unpricedModels === 0 ? {} : { unpricedModels }),
|
|
812
|
+
}))
|
|
790
813
|
.sort((a, b) => b.tokensTotal - a.tokensTotal)
|
|
791
814
|
|
|
792
815
|
const byModel: CostModelRow[] = [...models.values()]
|
|
@@ -820,7 +843,10 @@ function queryWithSqlite(
|
|
|
820
843
|
tokensCacheRead: acc.tokensCacheRead,
|
|
821
844
|
tokensCacheWrite: acc.tokensCacheWrite,
|
|
822
845
|
tokensTotal: acc.tokensInput + acc.tokensOutput,
|
|
823
|
-
...(acc.
|
|
846
|
+
...(acc.priced === 0 ? {} : { costUsd: acc.usd }),
|
|
847
|
+
...(acc.priced === 0 || acc.unpricedModels === 0
|
|
848
|
+
? {}
|
|
849
|
+
: { unpricedModels: acc.unpricedModels }),
|
|
824
850
|
...(acc.reason === undefined ? {} : { unpricedReason: acc.reason }),
|
|
825
851
|
}
|
|
826
852
|
})
|
|
@@ -935,7 +961,8 @@ function formatUsd(usd: number | undefined): string {
|
|
|
935
961
|
*
|
|
936
962
|
* With no priced row at all the cell is `—`, not `$0.00`: a report that could
|
|
937
963
|
* not price anything has not measured zero spend, and this number is what a
|
|
938
|
-
* tier decision would be made on.
|
|
964
|
+
* tier decision would be made on. `unpricedRows` counts every row that is not
|
|
965
|
+
* FULLY priced, including rows whose numeric part is shown but incomplete.
|
|
939
966
|
*/
|
|
940
967
|
function totalCostCell(pricedUsd: number, pricedRows: number, unpricedRows: number): string {
|
|
941
968
|
if (pricedRows === 0) return unpricedRows === 0 ? '**$0.00**' : '**—** (nothing priceable)'
|
|
@@ -943,6 +970,18 @@ function totalCostCell(pricedUsd: number, pricedRows: number, unpricedRows: numb
|
|
|
943
970
|
return unpricedRows === 0 ? cell : `${cell} (partial)`
|
|
944
971
|
}
|
|
945
972
|
|
|
973
|
+
/**
|
|
974
|
+
* A per-row cost cell.
|
|
975
|
+
*
|
|
976
|
+
* A row that mixed priced and unpriced models shows the money it could account
|
|
977
|
+
* for, marked `(partial)`: hiding it behind `—` under-reported the total, and
|
|
978
|
+
* showing it unmarked claimed the row was fully priced.
|
|
979
|
+
*/
|
|
980
|
+
function rowCostCell(usd: number | undefined, unpricedModels: number | undefined): string {
|
|
981
|
+
const cell = formatUsd(usd)
|
|
982
|
+
return unpricedModels === undefined || usd === undefined ? cell : `${cell} (partial)`
|
|
983
|
+
}
|
|
984
|
+
|
|
946
985
|
/** Session rows shown before the tail is summarised. */
|
|
947
986
|
const MAX_SESSION_ROWS = 20
|
|
948
987
|
|
|
@@ -1005,7 +1044,39 @@ function pricingNote(pricing: PricingSnapshot | undefined): string[] {
|
|
|
1005
1044
|
return [`${head}.`]
|
|
1006
1045
|
}
|
|
1007
1046
|
|
|
1008
|
-
/**
|
|
1047
|
+
/**
|
|
1048
|
+
* One line that reconciles the two dollar totals.
|
|
1049
|
+
*
|
|
1050
|
+
* Every dollar is attributed per `(agent, model)` and then summed, so a fully
|
|
1051
|
+
* priced report produces the SAME by-agent and by-model totals by construction.
|
|
1052
|
+
* The only legitimate difference is a model with no catalog price: its tokens
|
|
1053
|
+
* remain measured in both token columns and its cost is absent from both dollar
|
|
1054
|
+
* totals. The exclusion clause is shared by both branches, so one line can
|
|
1055
|
+
* never both claim agreement and name a difference for the same tokens.
|
|
1056
|
+
*/
|
|
1057
|
+
function reconciliationNote(
|
|
1058
|
+
rows: readonly CostRow[],
|
|
1059
|
+
byModel: readonly CostModelRow[] | undefined,
|
|
1060
|
+
): string | undefined {
|
|
1061
|
+
if (byModel === undefined) return undefined
|
|
1062
|
+
const unpriced = byModel.filter((row) => row.costUsd === undefined)
|
|
1063
|
+
if (unpriced.length === 0) return undefined
|
|
1064
|
+
const agentUsd = rows.reduce((sum, row) => sum + (row.costUsd ?? 0), 0)
|
|
1065
|
+
const modelUsd = byModel.reduce((sum, row) => sum + (row.costUsd ?? 0), 0)
|
|
1066
|
+
const totalTokens = byModel.reduce((sum, row) => sum + row.tokensTotal, 0)
|
|
1067
|
+
const unpricedTokens = unpriced.reduce((sum, row) => sum + row.tokensTotal, 0)
|
|
1068
|
+
const pricedRows = byModel.length - unpriced.length
|
|
1069
|
+
const totals =
|
|
1070
|
+
pricedRows === 0
|
|
1071
|
+
? 'nothing in either table could be priced'
|
|
1072
|
+
: Math.abs(agentUsd - modelUsd) < 0.005
|
|
1073
|
+
? `by-agent and by-model priced totals agree at ${formatUsd(agentUsd)}`
|
|
1074
|
+
: `by-agent ${formatUsd(agentUsd)} and by-model ${formatUsd(modelUsd)} differ by ${formatUsd(Math.abs(agentUsd - modelUsd))}`
|
|
1075
|
+
// The exclusion is stated once, in the same words in every branch: the count
|
|
1076
|
+
// can never be read as applying to one total but not the other.
|
|
1077
|
+
return `Cost reconciliation: ${totals}; ${unpricedTokens} token(s) from ${unpriced.length} unpriced model row(s) are counted in the token columns and excluded from both dollar totals (${totalTokens - unpricedTokens} priced token(s) carry the money).`
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1009
1080
|
function modelTotals(byModel: readonly CostModelRow[]): Array<{
|
|
1010
1081
|
provider: string
|
|
1011
1082
|
model: string
|
|
@@ -1015,6 +1086,7 @@ function modelTotals(byModel: readonly CostModelRow[]): Array<{
|
|
|
1015
1086
|
tokensCacheWrite: number
|
|
1016
1087
|
tokensTotal: number
|
|
1017
1088
|
costUsd: number | undefined
|
|
1089
|
+
unpricedModels?: number
|
|
1018
1090
|
}> {
|
|
1019
1091
|
const groups = new Map<
|
|
1020
1092
|
string,
|
|
@@ -1026,8 +1098,9 @@ function modelTotals(byModel: readonly CostModelRow[]): Array<{
|
|
|
1026
1098
|
tokensCacheRead: number
|
|
1027
1099
|
tokensCacheWrite: number
|
|
1028
1100
|
tokensTotal: number
|
|
1029
|
-
usd: number
|
|
1030
|
-
|
|
1101
|
+
usd: number
|
|
1102
|
+
priced: number
|
|
1103
|
+
unpricedModels: number
|
|
1031
1104
|
}
|
|
1032
1105
|
>()
|
|
1033
1106
|
for (const row of byModel) {
|
|
@@ -1041,18 +1114,19 @@ function modelTotals(byModel: readonly CostModelRow[]): Array<{
|
|
|
1041
1114
|
tokensCacheWrite: 0,
|
|
1042
1115
|
tokensTotal: 0,
|
|
1043
1116
|
usd: 0,
|
|
1044
|
-
|
|
1117
|
+
priced: 0,
|
|
1118
|
+
unpricedModels: 0,
|
|
1045
1119
|
}
|
|
1046
1120
|
acc.tokensInput += row.tokensInput
|
|
1047
1121
|
acc.tokensOutput += row.tokensOutput
|
|
1048
1122
|
acc.tokensCacheRead += row.tokensCacheRead
|
|
1049
1123
|
acc.tokensCacheWrite += row.tokensCacheWrite
|
|
1050
1124
|
acc.tokensTotal += row.tokensTotal
|
|
1051
|
-
if (row.costUsd === undefined
|
|
1052
|
-
acc.
|
|
1053
|
-
acc.usd = undefined
|
|
1125
|
+
if (row.costUsd === undefined) {
|
|
1126
|
+
acc.unpricedModels += 1
|
|
1054
1127
|
} else {
|
|
1055
1128
|
acc.usd += row.costUsd
|
|
1129
|
+
acc.priced += 1
|
|
1056
1130
|
}
|
|
1057
1131
|
groups.set(key, acc)
|
|
1058
1132
|
}
|
|
@@ -1065,7 +1139,13 @@ function modelTotals(byModel: readonly CostModelRow[]): Array<{
|
|
|
1065
1139
|
tokensCacheRead: acc.tokensCacheRead,
|
|
1066
1140
|
tokensCacheWrite: acc.tokensCacheWrite,
|
|
1067
1141
|
tokensTotal: acc.tokensTotal,
|
|
1068
|
-
|
|
1142
|
+
// Same rule as the by-agent table: a model bucket that spans several
|
|
1143
|
+
// agent/phase groups is the SUM of its priced groups, and `unpricedModels`
|
|
1144
|
+
// records how many groups had no usable price.
|
|
1145
|
+
costUsd: acc.priced === 0 ? undefined : acc.usd,
|
|
1146
|
+
...(acc.priced === 0 || acc.unpricedModels === 0
|
|
1147
|
+
? {}
|
|
1148
|
+
: { unpricedModels: acc.unpricedModels }),
|
|
1069
1149
|
}))
|
|
1070
1150
|
.sort((a, b) => b.tokensTotal - a.tokensTotal)
|
|
1071
1151
|
}
|
|
@@ -1080,7 +1160,9 @@ function renderModelSection(byModel: readonly CostModelRow[] | undefined, days:
|
|
|
1080
1160
|
const totals = modelTotals(byModel)
|
|
1081
1161
|
const pricedUsd = totals.reduce((sum, row) => sum + (row.costUsd ?? 0), 0)
|
|
1082
1162
|
const priced = totals.filter((row) => row.costUsd !== undefined).length
|
|
1083
|
-
const unpriced = totals.
|
|
1163
|
+
const unpriced = totals.filter(
|
|
1164
|
+
(row) => row.costUsd === undefined || (row.unpricedModels ?? 0) > 0,
|
|
1165
|
+
).length
|
|
1084
1166
|
const totalCell = totalCostCell(pricedUsd, priced, unpriced)
|
|
1085
1167
|
return [
|
|
1086
1168
|
header,
|
|
@@ -1089,7 +1171,7 @@ function renderModelSection(byModel: readonly CostModelRow[] | undefined, days:
|
|
|
1089
1171
|
'|----------|-------|----------:|-----------:|-----------:|------------:|-----------:|',
|
|
1090
1172
|
...totals.map(
|
|
1091
1173
|
(row) =>
|
|
1092
|
-
`| ${row.provider} | ${row.model} | ${row.tokensInput} | ${row.tokensOutput} | ${row.tokensCacheRead} | ${row.tokensCacheWrite} | ${
|
|
1174
|
+
`| ${row.provider} | ${row.model} | ${row.tokensInput} | ${row.tokensOutput} | ${row.tokensCacheRead} | ${row.tokensCacheWrite} | ${rowCostCell(row.costUsd, row.unpricedModels)} |`,
|
|
1093
1175
|
),
|
|
1094
1176
|
`| **Total** | — | **${totals.reduce((sum, row) => sum + row.tokensInput, 0)}** | **${totals.reduce((sum, row) => sum + row.tokensOutput, 0)}** | **${totals.reduce((sum, row) => sum + row.tokensCacheRead, 0)}** | **${totals.reduce((sum, row) => sum + row.tokensCacheWrite, 0)}** | ${totalCell} |`,
|
|
1095
1177
|
]
|
|
@@ -1129,14 +1211,16 @@ function renderSessionSection(query: CostQuery, days: number): string[] {
|
|
|
1129
1211
|
const hidden = query.bySession.length - shown.length
|
|
1130
1212
|
const pricedUsd = query.bySession.reduce((sum, row) => sum + (row.costUsd ?? 0), 0)
|
|
1131
1213
|
const priced = query.bySession.filter((row) => row.costUsd !== undefined).length
|
|
1132
|
-
const unpriced = query.bySession.
|
|
1214
|
+
const unpriced = query.bySession.filter(
|
|
1215
|
+
(row) => row.costUsd === undefined || (row.unpricedModels ?? 0) > 0,
|
|
1216
|
+
).length
|
|
1133
1217
|
const totalCell = totalCostCell(pricedUsd, priced, unpriced)
|
|
1134
1218
|
lines.push(
|
|
1135
1219
|
'| Session | Title | Agent | Tokens In | Tokens Out | Cache Read | Cache Write | Tokens Total | Cost (USD) |',
|
|
1136
1220
|
'|---------|-------|-------|----------:|-----------:|-----------:|------------:|-------------:|-----------:|',
|
|
1137
1221
|
...shown.map(
|
|
1138
1222
|
(row) =>
|
|
1139
|
-
`| ${row.sessionId} | ${shortTitle(row.title)} | ${row.agents.join(', ') || '—'} | ${row.tokensInput} | ${row.tokensOutput} | ${row.tokensCacheRead} | ${row.tokensCacheWrite} | ${row.tokensTotal} | ${
|
|
1223
|
+
`| ${row.sessionId} | ${shortTitle(row.title)} | ${row.agents.join(', ') || '—'} | ${row.tokensInput} | ${row.tokensOutput} | ${row.tokensCacheRead} | ${row.tokensCacheWrite} | ${row.tokensTotal} | ${rowCostCell(row.costUsd, row.unpricedModels)} |`,
|
|
1140
1224
|
),
|
|
1141
1225
|
`| **${scope === undefined ? 'Total' : 'Root + descendants'}** | — | — | **${query.bySession.reduce((sum, row) => sum + row.tokensInput, 0)}** | **${query.bySession.reduce((sum, row) => sum + row.tokensOutput, 0)}** | **${query.bySession.reduce((sum, row) => sum + row.tokensCacheRead, 0)}** | **${query.bySession.reduce((sum, row) => sum + row.tokensCacheWrite, 0)}** | **${query.bySession.reduce((sum, row) => sum + row.tokensTotal, 0)}** | ${totalCell} |`,
|
|
1142
1226
|
)
|
|
@@ -1154,12 +1238,14 @@ function renderMarkdown(
|
|
|
1154
1238
|
): string {
|
|
1155
1239
|
const { rows, coverage } = query
|
|
1156
1240
|
const header = `## Token and cost usage by agent and phase (last ${days} days)`
|
|
1241
|
+
const reconciliation = reconciliationNote(rows, query.byModel)
|
|
1157
1242
|
const footer = [
|
|
1158
1243
|
formatCoverage(coverage, days),
|
|
1159
1244
|
'Window: rolling 24-hour days from query time (not calendar days or session boundaries).',
|
|
1160
1245
|
'Aggregation: per agent and phase (phase may be unknown on V2), per model, and per session.',
|
|
1161
1246
|
'Attribution: a session row covers that session alone; passing session:<id> sums the root session and its descendant sessions.',
|
|
1162
|
-
'Limits: costs are catalog list prices (USD per 1M tokens), not a provider invoice; a row
|
|
1247
|
+
'Limits: costs are catalog list prices (USD per 1M tokens), not a provider invoice; a row that mixes priced and unpriced models shows its priced part and is reported as partial, and an unknown model is never priced at zero.',
|
|
1248
|
+
...(reconciliation === undefined ? [] : [reconciliation]),
|
|
1163
1249
|
...pricingNote(pricing),
|
|
1164
1250
|
`Source: opencode.db (read-only) — table families: ${coverage.sources.join(' + ')} — ${coverage.assistantRows} assistant row(s) scanned`,
|
|
1165
1251
|
].join('\n')
|
|
@@ -1193,12 +1279,13 @@ function renderMarkdown(
|
|
|
1193
1279
|
else {
|
|
1194
1280
|
acc.usd += r.costUsd
|
|
1195
1281
|
acc.priced += 1
|
|
1282
|
+
if ((r.unpricedModels ?? 0) > 0) acc.partial += 1
|
|
1196
1283
|
}
|
|
1197
1284
|
return acc
|
|
1198
1285
|
},
|
|
1199
|
-
{ tokensInput: 0, tokensOutput: 0, tokensTotal: 0, usd: 0, unpriced: 0, priced: 0 },
|
|
1286
|
+
{ tokensInput: 0, tokensOutput: 0, tokensTotal: 0, usd: 0, unpriced: 0, priced: 0, partial: 0 },
|
|
1200
1287
|
)
|
|
1201
|
-
const totalCost = totalCostCell(total.usd, total.priced, total.unpriced)
|
|
1288
|
+
const totalCost = totalCostCell(total.usd, total.priced, total.unpriced + total.partial)
|
|
1202
1289
|
const lines = [
|
|
1203
1290
|
header,
|
|
1204
1291
|
'',
|
|
@@ -1206,7 +1293,7 @@ function renderMarkdown(
|
|
|
1206
1293
|
'|-------|-------|----------:|-----------:|-------------:|-----------:|',
|
|
1207
1294
|
...rows.map(
|
|
1208
1295
|
(r) =>
|
|
1209
|
-
`| ${r.agent} | ${r.phase} | ${r.tokensInput} | ${r.tokensOutput} | ${r.tokensTotal} | ${
|
|
1296
|
+
`| ${r.agent} | ${r.phase} | ${r.tokensInput} | ${r.tokensOutput} | ${r.tokensTotal} | ${rowCostCell(r.costUsd, r.unpricedModels)} |`,
|
|
1210
1297
|
),
|
|
1211
1298
|
`| **Total** | — | **${total.tokensInput}** | **${total.tokensOutput}** | **${total.tokensTotal}** | ${totalCost} |`,
|
|
1212
1299
|
'',
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
// ─── Types ─────────────────────────────────────────────────────────────
|
|
36
36
|
|
|
37
|
+
import type { GuardPathResolution } from './guard-path.ts'
|
|
37
38
|
import { isAgentAllowed, type PermissionTaskConfig } from './permission-globs.ts'
|
|
38
39
|
|
|
39
40
|
/** Why a session is read-only. */
|
|
@@ -203,43 +204,179 @@ export const DEFAULT_BLOCKED_TOOLS: ReadonlySet<string> = new Set([
|
|
|
203
204
|
export const ZEUS_READ_DENY_PATTERNS: ReadonlyArray<RegExp> = [/^src\//, /^tests?\//, /^scripts?\//]
|
|
204
205
|
|
|
205
206
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
207
|
+
* Normalize a tool-supplied path before it meets the deny patterns.
|
|
208
|
+
*
|
|
209
|
+
* The patterns are anchored on `/`, so two spellings of the same source path
|
|
210
|
+
* used to pass: Windows separators (`src\\file.ts`) and a redundant dot prefix
|
|
211
|
+
* (`./src/file.ts`). Normalizing both is a TIGHTENING — it can only turn a
|
|
212
|
+
* previously allowed spelling into a denied one, never the reverse.
|
|
213
|
+
*/
|
|
214
|
+
function normalizeGuardPath(value: string): string {
|
|
215
|
+
let normalized = value.replace(/\\/g, '/')
|
|
216
|
+
while (normalized.startsWith('./')) normalized = normalized.slice(2)
|
|
217
|
+
return normalized
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** One path-bearing argument, and whether it names a target or a query. */
|
|
221
|
+
interface GuardCandidate {
|
|
222
|
+
value: string
|
|
223
|
+
/** `filePath`/`path` name the read target; `pattern` may be a grep query. */
|
|
224
|
+
target: boolean
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Path-bearing arguments of a read/glob/grep call.
|
|
229
|
+
*
|
|
230
|
+
* EVERY target is returned, not just the first: a `grep` call carries its
|
|
231
|
+
* directory in `path` and query in `pattern`. `pattern` is a TARGET for `glob`
|
|
232
|
+
* (it is the path pattern) but a QUERY for `grep` (it is the text to search
|
|
233
|
+
* for). Zeus' `grep.include` is rejected separately because the host's glob
|
|
234
|
+
* base and basename-matching semantics are not established.
|
|
235
|
+
*/
|
|
236
|
+
function guardPathCandidates(tool: string, args: unknown): GuardCandidate[] {
|
|
237
|
+
if (args === null || typeof args !== 'object') return []
|
|
238
|
+
const record = args as Record<string, unknown>
|
|
239
|
+
const candidates: GuardCandidate[] = []
|
|
240
|
+
for (const key of ['filePath', 'path', 'pattern']) {
|
|
241
|
+
const value = record[key]
|
|
242
|
+
if (typeof value !== 'string' || value.trim() === '') continue
|
|
243
|
+
candidates.push({ value, target: key !== 'pattern' || tool === 'glob' })
|
|
244
|
+
}
|
|
245
|
+
return candidates
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Whether a normalized path points AT or INTO a denied code root.
|
|
250
|
+
*
|
|
251
|
+
* A TARGET spelled without a trailing slash (`path: 'src'`) is a directory
|
|
252
|
+
* reference, so the slash form is tested too — `^src\\/` alone would miss it.
|
|
253
|
+
* A query (`pattern`) is only denied when it is path-shaped, so grepping for
|
|
254
|
+
* the literal word `src` stays allowed while `src/**` does not. Absolute paths
|
|
255
|
+
* are matched on every segment-boundary suffix, so `/abs/src/x` is the same
|
|
256
|
+
* source tree as `src/x`.
|
|
257
|
+
*/
|
|
258
|
+
function isDeniedReadPath(candidate: string, target: boolean): boolean {
|
|
259
|
+
const matches = (value: string): boolean =>
|
|
260
|
+
ZEUS_READ_DENY_PATTERNS.some((pattern) => pattern.test(value))
|
|
261
|
+
const test = (value: string): boolean => {
|
|
262
|
+
if (matches(value)) return true
|
|
263
|
+
return target && !value.endsWith('/') && matches(`${value}/`)
|
|
264
|
+
}
|
|
265
|
+
if (test(candidate)) return true
|
|
266
|
+
if (!candidate.startsWith('/')) return false
|
|
267
|
+
const segments = candidate.split('/').filter((segment) => segment !== '')
|
|
268
|
+
for (let index = 0; index < segments.length; index++) {
|
|
269
|
+
if (test(segments.slice(index).join('/'))) return true
|
|
270
|
+
}
|
|
271
|
+
return false
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Resolve a raw tool path for the guard. Supplied by the call site, never
|
|
276
|
+
* invoked by the pure predicate unless one is passed.
|
|
277
|
+
*/
|
|
278
|
+
export type GuardPathResolver = (rawPath: string) => GuardPathResolution
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Glob expansion is controlled by the host and its symlink-follow behavior is
|
|
282
|
+
* not part of this guard's contract. Only exact, non-glob paths are safe to
|
|
283
|
+
* preflight; fail closed on glob metacharacters rather than infer the host's
|
|
284
|
+
* expansion semantics.
|
|
209
285
|
*/
|
|
210
|
-
|
|
286
|
+
function hasGlobMeta(value: string): boolean {
|
|
287
|
+
return ['*', '?', '[', ']', '{', '}', '(', ')'].some((meta) => value.includes(meta))
|
|
288
|
+
}
|
|
211
289
|
|
|
212
290
|
/**
|
|
213
291
|
* Zeus read guard. When the active agent is Zeus, deny read/glob/grep calls
|
|
214
292
|
* that target source code, tests, or scripts — Zeus must delegate those to
|
|
215
|
-
* @apollo.
|
|
293
|
+
* @apollo. Project-root `.pantheon/` and `memories/` paths and ordinary docs
|
|
294
|
+
* remain readable because they are outside the denied code roots; they never
|
|
295
|
+
* exempt a resolved `src/`, `tests/`, or `scripts/` target. Glob patterns with
|
|
296
|
+
* wildcard metacharacters are rejected conservatively because host expansion
|
|
297
|
+
* and symlink-follow behavior cannot be safely preflighted here.
|
|
298
|
+
*
|
|
299
|
+
* Every path-bearing argument is checked, and path spellings are normalized
|
|
300
|
+
* first. Both are tightenings: a call Zeus could make before with a
|
|
301
|
+
* `path: 'src'` directory plus a harmless `pattern`, or with `./src/x` /
|
|
302
|
+
* `src\\x`, is now denied. When a resolver is supplied every target is resolved
|
|
303
|
+
* before any code-root decision, so the original spelling or an allowed suffix
|
|
304
|
+
* cannot hide a resolved code target. Zeus grep additionally requires resolver
|
|
305
|
+
* evidence that its target is a regular file inside the canonical project root.
|
|
306
|
+
*
|
|
307
|
+
* Symlink resolution is NOT part of this predicate: it is pure and synchronous
|
|
308
|
+
* and shared with V1, so a call site that wants it passes `resolvePath` (see
|
|
309
|
+
* `createGuardPathResolver`). When a resolver is supplied it runs for every
|
|
310
|
+
* TARGET path — a `grep` query is text, not a path — and a resolution FAILURE
|
|
311
|
+
* denies: a read guard fails closed. Non-Zeus behavior remains unchanged; Zeus
|
|
312
|
+
* grep without resolver evidence fails closed.
|
|
313
|
+
*
|
|
314
|
+
* Zeus grep requires an explicit, non-empty `path` that resolves to an existing
|
|
315
|
+
* regular file inside the project root. Directories (including `.` and `..`),
|
|
316
|
+
* paths outside the project, missing paths, and resolution failures are denied
|
|
317
|
+
* to prevent recursive or unbounded reads. Every `include` filter is rejected
|
|
318
|
+
* because host glob semantics are not established. Exact allowed docs files
|
|
319
|
+
* with ordinary text queries remain searchable.
|
|
216
320
|
*
|
|
217
321
|
* Non-Zeus sessions are never affected.
|
|
218
322
|
*
|
|
219
323
|
* @throws {Error} when Zeus attempts a denied read
|
|
220
324
|
*/
|
|
221
|
-
export function zeusReadGuard(
|
|
325
|
+
export function zeusReadGuard(
|
|
326
|
+
tool: string,
|
|
327
|
+
args: unknown,
|
|
328
|
+
agent: string | undefined,
|
|
329
|
+
resolvePath?: GuardPathResolver,
|
|
330
|
+
): void {
|
|
222
331
|
if (agent !== 'zeus') return
|
|
223
332
|
if (tool !== 'read' && tool !== 'glob' && tool !== 'grep') return
|
|
224
333
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
334
|
+
if (tool === 'grep') {
|
|
335
|
+
const record =
|
|
336
|
+
args !== null && typeof args === 'object' ? (args as Record<string, unknown>) : {}
|
|
337
|
+
const grepPath = record.path
|
|
338
|
+
if (typeof grepPath !== 'string' || grepPath.trim() === '') {
|
|
339
|
+
throw new Error('Zeus cannot grep without an explicit non-empty path — delegate to @apollo')
|
|
340
|
+
}
|
|
341
|
+
if (Object.hasOwn(record, 'include')) {
|
|
342
|
+
throw new Error('Zeus cannot use grep include filters — delegate to @apollo')
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
for (const candidate of guardPathCandidates(tool, args)) {
|
|
347
|
+
const normalized = normalizeGuardPath(candidate.value)
|
|
348
|
+
const deny = () => {
|
|
349
|
+
throw new Error(`Zeus cannot read ${candidate.value} — delegate to @apollo`)
|
|
350
|
+
}
|
|
351
|
+
if (normalized === '') {
|
|
352
|
+
if (tool === 'grep' && candidate.target) deny()
|
|
353
|
+
continue
|
|
354
|
+
}
|
|
355
|
+
// A project-root spelling is an unbounded grep target, even though it does
|
|
356
|
+
// not match any individual denied source-root pattern.
|
|
357
|
+
if (tool === 'grep' && candidate.target && normalized === '.') deny()
|
|
358
|
+
const resolution =
|
|
359
|
+
candidate.target && resolvePath !== undefined ? resolvePath(candidate.value) : undefined
|
|
360
|
+
if (resolution?.failed) deny()
|
|
361
|
+
if (
|
|
362
|
+
tool === 'grep' &&
|
|
363
|
+
candidate.target &&
|
|
364
|
+
(resolution === undefined ||
|
|
365
|
+
resolution.isRegularFile !== true ||
|
|
366
|
+
resolution.withinProject !== true)
|
|
367
|
+
) {
|
|
368
|
+
deny()
|
|
369
|
+
}
|
|
370
|
+
const effectivePath = normalizeGuardPath(resolution?.resolved ?? normalized)
|
|
371
|
+
if (effectivePath === '' || (tool === 'grep' && candidate.target && effectivePath === '.')) {
|
|
372
|
+
if (tool === 'grep' && candidate.target) deny()
|
|
373
|
+
continue
|
|
242
374
|
}
|
|
375
|
+
// Resolve every direct grep/glob path before any policy decision. Wildcard
|
|
376
|
+
// expansion itself cannot be safely preflighted using the host's unknown
|
|
377
|
+
// symlink semantics, so Zeus may glob exact paths only.
|
|
378
|
+
if (tool === 'glob' && candidate.target && hasGlobMeta(effectivePath)) deny()
|
|
379
|
+
if (isDeniedReadPath(effectivePath, candidate.target)) deny()
|
|
243
380
|
}
|
|
244
381
|
}
|
|
245
382
|
|