deuk-agent-flow 4.2.7 → 5.0.4
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/CHANGELOG.ko.md +277 -0
- package/CHANGELOG.md +794 -124
- package/LICENSE +0 -0
- package/README.ko.md +97 -17
- package/README.md +108 -25
- package/bin/deuk-agent-flow.js +11 -13
- package/bin/deuk-agent-rule.js +1 -1
- package/bundled/README.md +3 -0
- package/bundled/deuk-agent-flow.vsix +0 -0
- package/core-rules/AGENTS.md +30 -120
- package/docs/architecture.ko.md +155 -2
- package/docs/architecture.md +155 -2
- package/docs/assets/agentflow-panel-skills.png +0 -0
- package/docs/assets/agentflow-panel.png +0 -0
- package/docs/how-it-works.ko.md +109 -52
- package/docs/how-it-works.md +128 -71
- package/docs/principles.ko.md +68 -68
- package/docs/principles.md +68 -68
- package/docs/usage-guide.ko.md +251 -212
- package/package.json +60 -45
- package/scripts/bundle-vscode-vsix.ts +67 -0
- package/scripts/{cli-args.mjs → cli-args.ts} +49 -12
- package/scripts/cli-context-commands.ts +35 -0
- package/scripts/cli-init-claude.ts +179 -0
- package/scripts/cli-init-commands.ts +99 -0
- package/scripts/cli-init-core.ts +89 -0
- package/scripts/cli-init-instructions.ts +489 -0
- package/scripts/cli-init-logic.ts +46 -0
- package/scripts/cli-init-migrate.ts +504 -0
- package/scripts/cli-init-workspace.ts +63 -0
- package/scripts/cli-locales.ts +85 -0
- package/scripts/{cli-prompts.mjs → cli-prompts.ts} +19 -34
- package/scripts/{cli-rule-compiler.mjs → cli-rule-compiler.ts} +128 -112
- package/scripts/cli-skill-commands.ts +709 -0
- package/scripts/{cli-telemetry-commands.mjs → cli-telemetry-commands.ts} +25 -22
- package/scripts/cli-ticket-command-shared.ts +4 -0
- package/scripts/cli-ticket-commands.ts +3781 -0
- package/scripts/cli-ticket-docmeta.ts +103 -0
- package/scripts/cli-ticket-document.ts +153 -0
- package/scripts/cli-ticket-evidence.ts +312 -0
- package/scripts/cli-ticket-home.ts +449 -0
- package/scripts/cli-ticket-index.ts +283 -0
- package/scripts/{cli-ticket-migration.mjs → cli-ticket-migration.ts} +44 -68
- package/scripts/cli-ticket-parser.ts +100 -0
- package/scripts/cli-ticket-scan.ts +102 -0
- package/scripts/cli-ticket-surface.ts +56 -0
- package/scripts/{cli-usage-commands.mjs → cli-usage-commands.ts} +325 -326
- package/scripts/cli-utils.ts +1560 -0
- package/scripts/cli.ts +695 -0
- package/scripts/{lint-md.mjs → lint-md.ts} +32 -42
- package/scripts/lint-rules.ts +203 -0
- package/scripts/{merge-logic.mjs → merge-logic.ts} +44 -44
- package/scripts/oss-prepack.js +32 -0
- package/scripts/out/scripts/bundle-vscode-vsix.js +68 -0
- package/scripts/out/scripts/bundle-vscode-vsix.js.map +1 -0
- package/scripts/out/scripts/cli-args.js +374 -0
- package/scripts/out/scripts/cli-args.js.map +1 -0
- package/scripts/out/scripts/cli-context-commands.js +31 -0
- package/scripts/out/scripts/cli-context-commands.js.map +1 -0
- package/scripts/out/scripts/cli-init-claude.js +176 -0
- package/scripts/out/scripts/cli-init-claude.js.map +1 -0
- package/scripts/out/scripts/cli-init-commands.js +87 -0
- package/scripts/out/scripts/cli-init-commands.js.map +1 -0
- package/scripts/out/scripts/cli-init-core.js +89 -0
- package/scripts/out/scripts/cli-init-core.js.map +1 -0
- package/scripts/out/scripts/cli-init-instructions.js +460 -0
- package/scripts/out/scripts/cli-init-instructions.js.map +1 -0
- package/scripts/out/scripts/cli-init-logic.js +41 -0
- package/scripts/out/scripts/cli-init-logic.js.map +1 -0
- package/scripts/out/scripts/cli-init-migrate.js +497 -0
- package/scripts/out/scripts/cli-init-migrate.js.map +1 -0
- package/scripts/out/scripts/cli-init-workspace.js +57 -0
- package/scripts/out/scripts/cli-init-workspace.js.map +1 -0
- package/scripts/out/scripts/cli-locales.js +83 -0
- package/scripts/out/scripts/cli-locales.js.map +1 -0
- package/scripts/out/scripts/cli-prompts.js +101 -0
- package/scripts/out/scripts/cli-prompts.js.map +1 -0
- package/scripts/out/scripts/cli-rule-compiler.js +121 -0
- package/scripts/out/scripts/cli-rule-compiler.js.map +1 -0
- package/scripts/out/scripts/cli-skill-commands.js +708 -0
- package/scripts/out/scripts/cli-skill-commands.js.map +1 -0
- package/scripts/out/scripts/cli-telemetry-commands.js +604 -0
- package/scripts/out/scripts/cli-telemetry-commands.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-command-shared.js +2 -0
- package/scripts/out/scripts/cli-ticket-command-shared.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-commands.js +3530 -0
- package/scripts/out/scripts/cli-ticket-commands.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-docmeta.js +90 -0
- package/scripts/out/scripts/cli-ticket-docmeta.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-document.js +121 -0
- package/scripts/out/scripts/cli-ticket-document.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-evidence.js +286 -0
- package/scripts/out/scripts/cli-ticket-evidence.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-home.js +440 -0
- package/scripts/out/scripts/cli-ticket-home.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-index.js +272 -0
- package/scripts/out/scripts/cli-ticket-index.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-migration.js +261 -0
- package/scripts/out/scripts/cli-ticket-migration.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-parser.js +90 -0
- package/scripts/out/scripts/cli-ticket-parser.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-scan.js +93 -0
- package/scripts/out/scripts/cli-ticket-scan.js.map +1 -0
- package/scripts/out/scripts/cli-ticket-surface.js +53 -0
- package/scripts/out/scripts/cli-ticket-surface.js.map +1 -0
- package/scripts/out/scripts/cli-usage-commands.js +310 -0
- package/scripts/out/scripts/cli-usage-commands.js.map +1 -0
- package/scripts/out/scripts/cli-utils.js +1544 -0
- package/scripts/out/scripts/cli-utils.js.map +1 -0
- package/scripts/out/scripts/cli.js +696 -0
- package/scripts/out/scripts/cli.js.map +1 -0
- package/scripts/out/scripts/lint-md.js +238 -0
- package/scripts/out/scripts/lint-md.js.map +1 -0
- package/scripts/out/scripts/lint-rules.js +193 -0
- package/scripts/out/scripts/lint-rules.js.map +1 -0
- package/scripts/out/scripts/merge-logic.js +38 -0
- package/scripts/out/scripts/merge-logic.js.map +1 -0
- package/scripts/out/scripts/plan-parser.js +52 -0
- package/scripts/out/scripts/plan-parser.js.map +1 -0
- package/scripts/out/scripts/ticket-machine.js +94 -0
- package/scripts/out/scripts/ticket-machine.js.map +1 -0
- package/scripts/out/scripts/ticket-workflow.js +498 -0
- package/scripts/out/scripts/ticket-workflow.js.map +1 -0
- package/scripts/{plan-parser.mjs → plan-parser.ts} +53 -53
- package/scripts/ticket-machine.ts +99 -0
- package/scripts/ticket-workflow.ts +544 -0
- package/templates/MODULE_RULE_TEMPLATE.md +11 -11
- package/templates/PROJECT_RULE.md +46 -47
- package/templates/TICKET_TEMPLATE.ko.md +48 -44
- package/templates/TICKET_TEMPLATE.md +48 -44
- package/templates/project-memory.md +19 -0
- package/templates/project-pilot/CONFORMANCE_GATE_TEMPLATE.md +25 -25
- package/templates/project-pilot/DRIFT_CHECKLIST.md +27 -27
- package/templates/project-pilot/FLOW_CONTRACT_TEMPLATE.md +26 -26
- package/templates/project-pilot/IMPLEMENTATION_MATRIX_TEMPLATE.md +30 -30
- package/templates/project-pilot/INTEGRATION_CONTRACT_TEMPLATE.md +26 -26
- package/templates/project-pilot/OWNER_MAP_TEMPLATE.md +15 -15
- package/templates/project-pilot/PROJECT_PILOT_RULE_TEMPLATE.md +34 -34
- package/templates/project-pilot/REFACTOR_CONTRACT_TEMPLATE.md +32 -32
- package/templates/project-pilot/REMEDIATION_PLAN_TEMPLATE.md +33 -33
- package/templates/rules.d/deukcontext-mcp.md +31 -31
- package/templates/rules.d/platform-coexistence.md +29 -29
- package/templates/skills/context-recall/SKILL.md +3 -1
- package/templates/skills/doc-sync/SKILL.md +111 -0
- package/templates/skills/generated-file-guard/SKILL.md +3 -1
- package/templates/skills/persona-maid/SKILL.md +65 -0
- package/templates/skills/project-pilot/SKILL.md +14 -63
- package/templates/skills/role-closer/SKILL.md +27 -0
- package/templates/skills/role-implementer/SKILL.md +30 -0
- package/templates/skills/role-planner/SKILL.md +29 -0
- package/templates/skills/role-qa-verifier/SKILL.md +30 -0
- package/templates/skills/safe-refactor/SKILL.md +3 -1
- package/templates/skills/ticket-status-surface/SKILL.md +17 -0
- package/NOTICE.md +0 -19
- package/core-rules/GEMINI.md +0 -7
- package/docs/npm-publish-guide.ko.md +0 -70
- package/scripts/cli-init-commands.mjs +0 -1759
- package/scripts/cli-init-logic.mjs +0 -64
- package/scripts/cli-skill-commands.mjs +0 -212
- package/scripts/cli-ticket-command-shared.mjs +0 -60
- package/scripts/cli-ticket-commands.mjs +0 -2474
- package/scripts/cli-ticket-index.mjs +0 -322
- package/scripts/cli-ticket-parser.mjs +0 -210
- package/scripts/cli-utils.mjs +0 -602
- package/scripts/cli.mjs +0 -256
- package/scripts/lint-rules.mjs +0 -197
- package/scripts/publish-dual-npm.mjs +0 -141
- package/scripts/smoke-npm-docker.mjs +0 -102
- package/scripts/smoke-npm-local.mjs +0 -110
- package/scripts/update-download-badge.mjs +0 -103
|
@@ -1,326 +1,325 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
console.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
platform,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
console.log(`
|
|
242
|
-
if (next.
|
|
243
|
-
if (next.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
console.log(`
|
|
265
|
-
if (state.
|
|
266
|
-
if (state.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
...
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
console.log(`
|
|
302
|
-
|
|
303
|
-
console.log(
|
|
304
|
-
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
2
|
+
import { DEUK_ROOT_DIR, CliOpts, makePath } from "./cli-utils.js";
|
|
3
|
+
|
|
4
|
+
const USAGE_FILENAME = `${DEUK_ROOT_DIR}/usage.json`;
|
|
5
|
+
const USAGE_VERSION = 1;
|
|
6
|
+
const VALID_TASK_GRADES = new Set(["S", "A", "B", "C"]);
|
|
7
|
+
const DEFAULT_PLATFORM = "codex";
|
|
8
|
+
const PLATFORM_ALIASES = {
|
|
9
|
+
codex: "codex",
|
|
10
|
+
copilot: "copilot",
|
|
11
|
+
ghcopilot: "copilot",
|
|
12
|
+
"github-copilot": "copilot",
|
|
13
|
+
claude: "claude",
|
|
14
|
+
claudecode: "claude",
|
|
15
|
+
cursor: "cursor"
|
|
16
|
+
};
|
|
17
|
+
const PLATFORM_DEFAULT_CLIENT = {
|
|
18
|
+
codex: "Codex",
|
|
19
|
+
copilot: "Copilot",
|
|
20
|
+
claude: "ClaudeCode",
|
|
21
|
+
cursor: "Cursor"
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export async function runUsage(action, opts) {
|
|
25
|
+
if (action === "set") {
|
|
26
|
+
return runUsageSet(opts);
|
|
27
|
+
}
|
|
28
|
+
if (action === "status") {
|
|
29
|
+
return runUsageStatus(opts);
|
|
30
|
+
}
|
|
31
|
+
if (action === "advise") {
|
|
32
|
+
return runUsageAdvise(opts);
|
|
33
|
+
}
|
|
34
|
+
console.error("Unknown usage action: " + action);
|
|
35
|
+
console.log("Usage: npx deuk-agent-flow usage <set|status|advise> [options]");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function loadUsageState(cwd) {
|
|
39
|
+
const absPath = makePath(cwd, USAGE_FILENAME);
|
|
40
|
+
if (!existsSync(absPath)) return null;
|
|
41
|
+
try {
|
|
42
|
+
const data = JSON.parse(readFileSync(absPath, "utf8"));
|
|
43
|
+
if (data.version !== USAGE_VERSION) return null;
|
|
44
|
+
return normalizeUsageState(data);
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function writeUsageState(cwd, state) {
|
|
51
|
+
const absPath = makePath(cwd, USAGE_FILENAME);
|
|
52
|
+
const dir = makePath(cwd, DEUK_ROOT_DIR);
|
|
53
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
54
|
+
writeFileSync(absPath, JSON.stringify({
|
|
55
|
+
version: USAGE_VERSION,
|
|
56
|
+
platform: state.platform,
|
|
57
|
+
client: state.client,
|
|
58
|
+
agentId: state.agentId,
|
|
59
|
+
weeklyRemainingPct: state.weeklyRemainingPct,
|
|
60
|
+
fiveHourRemainingPct: state.fiveHourRemainingPct,
|
|
61
|
+
weeklyResetAt: state.weeklyResetAt,
|
|
62
|
+
fiveHourResetAt: state.fiveHourResetAt,
|
|
63
|
+
updatedAt: state.updatedAt
|
|
64
|
+
}, null, 2), "utf8");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function normalizeUsageState(raw: Record<string, any> = {}) {
|
|
68
|
+
const platform = normalizePlatform(raw.platform || DEFAULT_PLATFORM);
|
|
69
|
+
const normalizedClient = String(raw.client || "").trim();
|
|
70
|
+
return {
|
|
71
|
+
platform,
|
|
72
|
+
client: normalizedClient || resolveClientForPlatform(platform),
|
|
73
|
+
agentId: String(raw.agentId || ""),
|
|
74
|
+
weeklyRemainingPct: clampPercent(raw.weeklyRemainingPct),
|
|
75
|
+
fiveHourRemainingPct: clampPercent(raw.fiveHourRemainingPct),
|
|
76
|
+
weeklyResetAt: String(raw.weeklyResetAt || ""),
|
|
77
|
+
fiveHourResetAt: String(raw.fiveHourResetAt || ""),
|
|
78
|
+
updatedAt: String(raw.updatedAt || "")
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function clampPercent(value) {
|
|
83
|
+
if (value === null || value === undefined || Number.isNaN(Number(value))) return null;
|
|
84
|
+
return Math.min(100, Math.max(0, Number(value)));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function resolveTaskGrade(input = "") {
|
|
88
|
+
const grade = String(input || "").trim().toUpperCase();
|
|
89
|
+
if (!VALID_TASK_GRADES.has(grade)) return "";
|
|
90
|
+
return grade;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function normalizePlatform(input = "") {
|
|
94
|
+
const key = String(input || "").trim().toLowerCase();
|
|
95
|
+
if (!key) return DEFAULT_PLATFORM;
|
|
96
|
+
return PLATFORM_ALIASES[key] || key;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function resolveClientForPlatform(platform) {
|
|
100
|
+
return PLATFORM_DEFAULT_CLIENT[platform] || "Codex";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function buildBudgetAdvice(state, taskGrade) {
|
|
104
|
+
const weekly = state.weeklyRemainingPct;
|
|
105
|
+
const fiveHour = state.fiveHourRemainingPct;
|
|
106
|
+
const tight = weekly !== null && weekly <= 20 || fiveHour !== null && fiveHour <= 15;
|
|
107
|
+
const critical = weekly !== null && weekly <= 10 || fiveHour !== null && fiveHour <= 8;
|
|
108
|
+
|
|
109
|
+
if (!taskGrade) {
|
|
110
|
+
return {
|
|
111
|
+
budget: critical ? "phase1-only" : tight ? "split-large-tasks" : "normal",
|
|
112
|
+
gate: critical ? "no broad work" : tight ? "keep scope narrow" : "ok",
|
|
113
|
+
next: critical ? "ticket status" : "usage advise --task-grade A"
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (critical) {
|
|
118
|
+
return {
|
|
119
|
+
budget: `${taskGrade} blocked`,
|
|
120
|
+
gate: "phase1-only",
|
|
121
|
+
next: "summarize and stop"
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (tight) {
|
|
126
|
+
if (taskGrade === "S" || taskGrade === "A") {
|
|
127
|
+
return {
|
|
128
|
+
budget: `${taskGrade} split`,
|
|
129
|
+
gate: "no broad refactor",
|
|
130
|
+
next: "split ticket"
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
budget: `${taskGrade} ok`,
|
|
135
|
+
gate: "keep local",
|
|
136
|
+
next: "avoid broad search"
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (taskGrade === "S") {
|
|
141
|
+
return {
|
|
142
|
+
budget: "S ok with ticket",
|
|
143
|
+
gate: "verify before execute",
|
|
144
|
+
next: "keep one active task"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (taskGrade === "A") {
|
|
148
|
+
return {
|
|
149
|
+
budget: "A ok",
|
|
150
|
+
gate: "normal",
|
|
151
|
+
next: "execute"
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (taskGrade === "B") {
|
|
155
|
+
return {
|
|
156
|
+
budget: "B ok",
|
|
157
|
+
gate: "normal",
|
|
158
|
+
next: "keep concise"
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
budget: "C ok",
|
|
163
|
+
gate: "normal",
|
|
164
|
+
next: "stay compact"
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function buildConversationAdvice(state, opts: CliOpts = {}, budgetAdvice: Record<string, any> = {}) {
|
|
169
|
+
const turnCount = Number(opts.turnCount || 0);
|
|
170
|
+
const linkedTicketCount = Number(opts.linkedTicketCount || 0);
|
|
171
|
+
const crossWorkspace = Boolean(opts.crossWorkspace);
|
|
172
|
+
const weekly = state.weeklyRemainingPct;
|
|
173
|
+
const fiveHour = state.fiveHourRemainingPct;
|
|
174
|
+
const lowFiveHour = fiveHour !== null && fiveHour <= 15;
|
|
175
|
+
const criticalFiveHour = fiveHour !== null && fiveHour <= 8;
|
|
176
|
+
const lowWeekly = weekly !== null && weekly <= 20;
|
|
177
|
+
const highTurns = turnCount >= 25;
|
|
178
|
+
const veryHighTurns = turnCount >= 40;
|
|
179
|
+
const manyLinkedTickets = linkedTicketCount >= 3;
|
|
180
|
+
|
|
181
|
+
if (criticalFiveHour || (lowFiveHour && veryHighTurns) || (lowFiveHour && crossWorkspace && highTurns)) {
|
|
182
|
+
return {
|
|
183
|
+
conversationAction: "handoff-and-new-chat",
|
|
184
|
+
conversationGate: "handoff now",
|
|
185
|
+
conversationNext: "handoff and start new chat"
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if ((crossWorkspace && highTurns) || manyLinkedTickets || (lowWeekly && highTurns)) {
|
|
190
|
+
return {
|
|
191
|
+
conversationAction: "split-chat",
|
|
192
|
+
conversationGate: "split context",
|
|
193
|
+
conversationNext: "split ticket or new chat"
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (budgetAdvice.gate === "phase1-only") {
|
|
198
|
+
return {
|
|
199
|
+
conversationAction: "stop-in-current-chat",
|
|
200
|
+
conversationGate: "phase1-only",
|
|
201
|
+
conversationNext: "summarize and stop"
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
conversationAction: "keep-current-chat",
|
|
207
|
+
conversationGate: "keep current chat",
|
|
208
|
+
conversationNext: "continue"
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function runUsageSet(opts) {
|
|
213
|
+
const current = loadUsageState(opts.cwd) || normalizeUsageState();
|
|
214
|
+
const hasPlatformOverride = Boolean(String(opts.platform || "").trim());
|
|
215
|
+
const nextPlatform = normalizePlatform(opts.platform || current.platform || DEFAULT_PLATFORM);
|
|
216
|
+
const incomingClient = String(opts.client || "").trim();
|
|
217
|
+
const resolvedClient = incomingClient
|
|
218
|
+
|| (hasPlatformOverride
|
|
219
|
+
? resolveClientForPlatform(nextPlatform)
|
|
220
|
+
: (current.client || resolveClientForPlatform(nextPlatform)));
|
|
221
|
+
const next = normalizeUsageState({
|
|
222
|
+
...current,
|
|
223
|
+
platform: nextPlatform,
|
|
224
|
+
client: resolvedClient,
|
|
225
|
+
agentId: opts.agentId || current.agentId,
|
|
226
|
+
weeklyRemainingPct: opts.weeklyRemaining !== null ? opts.weeklyRemaining : current.weeklyRemainingPct,
|
|
227
|
+
fiveHourRemainingPct: opts.fiveHourRemaining !== null ? opts.fiveHourRemaining : current.fiveHourRemainingPct,
|
|
228
|
+
weeklyResetAt: opts.weeklyReset || current.weeklyResetAt,
|
|
229
|
+
fiveHourResetAt: opts.fiveHourReset || current.fiveHourResetAt,
|
|
230
|
+
updatedAt: new Date().toISOString()
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
writeUsageState(opts.cwd, next);
|
|
234
|
+
|
|
235
|
+
if (opts.json) {
|
|
236
|
+
console.log(JSON.stringify(next, null, 2));
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
console.log(`usage: ${next.client} weekly ${formatPct(next.weeklyRemainingPct)}, 5h ${formatPct(next.fiveHourRemainingPct)}`);
|
|
241
|
+
if (next.agentId) console.log(`agent: ${next.agentId}`);
|
|
242
|
+
if (next.weeklyResetAt) console.log(`reset: weekly ${next.weeklyResetAt}`);
|
|
243
|
+
if (next.fiveHourResetAt) console.log(`reset: 5h ${next.fiveHourResetAt}`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function runUsageStatus(opts) {
|
|
247
|
+
const state = loadUsageState(opts.cwd);
|
|
248
|
+
if (!state) {
|
|
249
|
+
const message = "usage not set";
|
|
250
|
+
if (opts.json) {
|
|
251
|
+
console.log(JSON.stringify({ status: message }, null, 2));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
console.log(message);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (opts.json) {
|
|
259
|
+
console.log(JSON.stringify(state, null, 2));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
console.log(`usage: ${state.client} weekly ${formatPct(state.weeklyRemainingPct)}, 5h ${formatPct(state.fiveHourRemainingPct)}`);
|
|
264
|
+
if (state.agentId) console.log(`agent: ${state.agentId}`);
|
|
265
|
+
if (state.weeklyResetAt) console.log(`reset: weekly ${state.weeklyResetAt}`);
|
|
266
|
+
if (state.fiveHourResetAt) console.log(`reset: 5h ${state.fiveHourResetAt}`);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function runUsageAdvise(opts) {
|
|
270
|
+
const state = loadUsageState(opts.cwd);
|
|
271
|
+
if (!state) {
|
|
272
|
+
const message = "usage not set";
|
|
273
|
+
if (opts.json) {
|
|
274
|
+
console.log(JSON.stringify({ status: message }, null, 2));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
console.log(message);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const taskGrade = resolveTaskGrade(opts.taskGrade);
|
|
282
|
+
const advice = buildBudgetAdvice(state, taskGrade);
|
|
283
|
+
const conversation = buildConversationAdvice(state, opts, advice);
|
|
284
|
+
const payload = {
|
|
285
|
+
...state,
|
|
286
|
+
taskGrade: taskGrade || null,
|
|
287
|
+
taskLabel: opts.taskLabel || "",
|
|
288
|
+
turnCount: Number(opts.turnCount || 0),
|
|
289
|
+
linkedTicketCount: Number(opts.linkedTicketCount || 0),
|
|
290
|
+
crossWorkspace: Boolean(opts.crossWorkspace),
|
|
291
|
+
...advice,
|
|
292
|
+
...conversation
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
if (opts.json) {
|
|
296
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
console.log(`usage: ${state.client} weekly ${formatPct(state.weeklyRemainingPct)}, 5h ${formatPct(state.fiveHourRemainingPct)}`);
|
|
301
|
+
if (state.agentId) console.log(`agent: ${state.agentId}`);
|
|
302
|
+
console.log(`budget: ${advice.budget}`);
|
|
303
|
+
console.log(`${advice.gate === "ok" ? "next" : "gate"}: ${advice.gate === "ok" ? advice.next : advice.gate}`);
|
|
304
|
+
if (advice.gate !== "ok") console.log(`next: ${advice.next}`);
|
|
305
|
+
if (conversation.conversationAction !== "keep-current-chat") {
|
|
306
|
+
console.log(`chat: ${conversation.conversationNext}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function formatPct(value) {
|
|
311
|
+
return value === null ? "n/a" : `${value}%`;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function getUsageReminderLine(cwd, opts: CliOpts = {}) {
|
|
315
|
+
const state = loadUsageState(cwd);
|
|
316
|
+
if (!state) return "";
|
|
317
|
+
const taskGrade = resolveTaskGrade(opts.taskGrade || "");
|
|
318
|
+
const advice = buildBudgetAdvice(state, taskGrade);
|
|
319
|
+
const conversation = buildConversationAdvice(state, opts, advice);
|
|
320
|
+
const gateText = advice.gate === "ok" ? advice.next : advice.gate;
|
|
321
|
+
const chatText = conversation.conversationAction === "keep-current-chat"
|
|
322
|
+
? "keep current chat"
|
|
323
|
+
: conversation.conversationNext;
|
|
324
|
+
return `usage reminder: ${state.client} weekly ${formatPct(state.weeklyRemainingPct)}, 5h ${formatPct(state.fiveHourRemainingPct)} | budget ${advice.budget} | gate ${gateText} | chat ${chatText}`;
|
|
325
|
+
}
|