@mainwave/cli 0.14.0 → 0.16.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/README.md +62 -19
- package/dist/adapters/codex-cli.js +169 -15
- package/dist/commands.js +5 -2
- package/dist/core/apply.js +35 -36
- package/dist/core/codecs/toml-profile.js +1 -7
- package/dist/core/codex-trust.js +135 -34
- package/dist/core/doctor.js +97 -32
- package/dist/core/markers.js +19 -5
- package/dist/core/remove.js +54 -10
- package/dist/core/setup-removal.js +197 -0
- package/dist/core/store.js +37 -0
- package/dist/core/wizard.js +33 -2
- package/dist/main.js +9 -3
- package/hooks/codex-turns.mjs +124 -31
- package/hooks/kiro-otlp.mjs +4 -15
- package/hooks/marker-core.mjs +21 -0
- package/hooks/matchers.json +1 -1
- package/hooks/plan-snapshot.mjs +54 -23
- package/hooks/vocabulary.d.mts +3 -0
- package/hooks/vocabulary.mjs +11 -3
- package/package.json +6 -6
package/hooks/kiro-otlp.mjs
CHANGED
|
@@ -44,17 +44,16 @@ import { dirname, join, resolve } from 'node:path'
|
|
|
44
44
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
45
45
|
|
|
46
46
|
import {
|
|
47
|
+
activityMarkerPath,
|
|
47
48
|
bearerFromHeaders,
|
|
48
49
|
buildMarkerPayload,
|
|
49
50
|
emitMarker,
|
|
50
|
-
ensureLogDir,
|
|
51
51
|
hookFlag,
|
|
52
|
-
isOkStatus,
|
|
53
52
|
markerLog,
|
|
54
|
-
markerLogPath,
|
|
55
53
|
parseEnvFile,
|
|
56
54
|
parseKv,
|
|
57
55
|
redactForSend,
|
|
56
|
+
stampActivity,
|
|
58
57
|
} from './marker-core.mjs'
|
|
59
58
|
|
|
60
59
|
const LOG_NAME = 'kiro.log'
|
|
@@ -317,17 +316,7 @@ export const spanForPayload = (payload, config, { argv = [], env = process.env }
|
|
|
317
316
|
}
|
|
318
317
|
|
|
319
318
|
/** The sidecar whose mtime is the last delivered span — doctor reads it. */
|
|
320
|
-
export const activityPath = (argv) =>
|
|
321
|
-
|
|
322
|
-
const markDelivered = (argv) => {
|
|
323
|
-
try {
|
|
324
|
-
const p = activityPath(argv)
|
|
325
|
-
ensureLogDir(p)
|
|
326
|
-
writeFileSync(p, `${new Date().toISOString()}\n`, { mode: 0o600 })
|
|
327
|
-
} catch {
|
|
328
|
-
// best-effort, like every log write
|
|
329
|
-
}
|
|
330
|
-
}
|
|
319
|
+
export const activityPath = (argv) => activityMarkerPath(argv, LOG_NAME)
|
|
331
320
|
|
|
332
321
|
/**
|
|
333
322
|
* Read stdin up to `max` bytes, keeping the first `head` bytes of a payload
|
|
@@ -559,7 +548,7 @@ export const send = async (argv = process.argv) => {
|
|
|
559
548
|
// Redacted when it was spooled; one spooled with no rules is checked now.
|
|
560
549
|
redacted: spooled.redacted === true,
|
|
561
550
|
})
|
|
562
|
-
|
|
551
|
+
stampActivity(status, argv, LOG_NAME)
|
|
563
552
|
}
|
|
564
553
|
|
|
565
554
|
// Run only as a script, not when imported by tests.
|
package/hooks/marker-core.mjs
CHANGED
|
@@ -112,6 +112,27 @@ export const markerLogPath = (argv, defaultName) =>
|
|
|
112
112
|
export const markerLog = (argv, defaultName, maxBytes = LOG_MAX_BYTES) =>
|
|
113
113
|
makeLog(markerLogPath(argv, defaultName), maxBytes)
|
|
114
114
|
|
|
115
|
+
/** The activity sidecar beside a hook's log: `<log>.ok`, one timestamp line a
|
|
116
|
+
* 2xx post rewrites, never appended to. Its mtime is the last successful
|
|
117
|
+
* send, which `doctor` reports as activity; the log's own mtime also moves on
|
|
118
|
+
* a skip or a failure, so it can't say whether anything was delivered. */
|
|
119
|
+
export const activityMarkerPath = (argv, defaultName) => `${markerLogPath(argv, defaultName)}.ok`
|
|
120
|
+
|
|
121
|
+
/** Rewrite the activity sidecar (§ `activityMarkerPath`) when `status` is a
|
|
122
|
+
* 2xx; anything else, no response or a non-2xx, leaves it alone. Best-effort
|
|
123
|
+
* like the log: true when it was written. */
|
|
124
|
+
export const stampActivity = (status, argv, defaultName, now = new Date()) => {
|
|
125
|
+
if (!isOkStatus(status)) return false
|
|
126
|
+
try {
|
|
127
|
+
const path = activityMarkerPath(argv, defaultName)
|
|
128
|
+
ensureLogDir(path)
|
|
129
|
+
writeFileSync(path, `${now.toISOString()}\n`, { mode: 0o600 })
|
|
130
|
+
return true
|
|
131
|
+
} catch {
|
|
132
|
+
return false
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
115
136
|
/**
|
|
116
137
|
* The project root whose `.claude/` settings Claude Code loaded for this
|
|
117
138
|
* session: `CLAUDE_PROJECT_DIR`, which Claude Code sets for every hook. Not the
|
package/hooks/matchers.json
CHANGED
|
@@ -202,6 +202,6 @@
|
|
|
202
202
|
"optOut": "markers",
|
|
203
203
|
"hosts": ["codex"],
|
|
204
204
|
"dataClasses": ["session id, turn id and agent id", "working directory", "start and end times"],
|
|
205
|
-
"why": "Closes a turn
|
|
205
|
+
"why": "Closes a turn an earlier run left open when the session resumed (a startup's, fork's or clear's session id is new, and a compaction is the same run, so those close nothing): the turn is sent ending at the last event it saw, never at the new start, so a killed Codex can't stretch a turn across the developer's absence. It also deletes turn state older than 7 days. It takes no matcher, so it runs for every source (the session-start refresh is a separate group that runs for `startup|resume|fork` only). Async."
|
|
206
206
|
}
|
|
207
207
|
]
|
package/hooks/plan-snapshot.mjs
CHANGED
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
// length, the date of the account's first Claude Code token, and when
|
|
34
34
|
// Claude Code fetched the profile;
|
|
35
35
|
// - from the usage cache, only when it names the same account: the 5-hour and
|
|
36
|
-
// 7-day utilization and their reset times
|
|
36
|
+
// 7-day utilization and their reset times, and the same two figures for each
|
|
37
|
+
// other rolling window Claude Code reports under a key named `five_hour` or
|
|
38
|
+
// `seven_day` plus a suffix (`seven_day_opus`, ...) whose value is an object
|
|
39
|
+
// (a null one is skipped; no other key is read as a window); per rate limit, its group,
|
|
37
40
|
// percent used, severity, whether it is the active one and its reset time,
|
|
38
41
|
// and for a scoped limit (one per model) the scope's model id, model name or
|
|
39
42
|
// surface;
|
|
@@ -55,21 +58,19 @@
|
|
|
55
58
|
// so a send that hasn't finished when such a run ends is lost.
|
|
56
59
|
|
|
57
60
|
import { createHash } from 'node:crypto'
|
|
58
|
-
import { readFileSync
|
|
61
|
+
import { readFileSync } from 'node:fs'
|
|
59
62
|
|
|
60
63
|
import {
|
|
64
|
+
activityMarkerPath,
|
|
61
65
|
boolAttr,
|
|
62
66
|
buildMarkerPayload,
|
|
63
67
|
doubleAttr,
|
|
64
68
|
emitMarker,
|
|
65
69
|
hookFlag,
|
|
66
70
|
intAttr,
|
|
67
|
-
isOkStatus,
|
|
68
71
|
loadOtelConfig,
|
|
69
|
-
ensureLogDir,
|
|
70
72
|
markerHostSource,
|
|
71
73
|
markerLog,
|
|
72
|
-
markerLogPath,
|
|
73
74
|
markerManagedDir,
|
|
74
75
|
markerOauthAccountPath,
|
|
75
76
|
markerProjectDir,
|
|
@@ -78,6 +79,7 @@ import {
|
|
|
78
79
|
oauthAccountFromRecord,
|
|
79
80
|
onceReaders,
|
|
80
81
|
parseTraceparent,
|
|
82
|
+
stampActivity,
|
|
81
83
|
stringAttr,
|
|
82
84
|
trimmedOrUndefined,
|
|
83
85
|
} from './marker-core.mjs'
|
|
@@ -115,7 +117,9 @@ import {
|
|
|
115
117
|
VENDOR_ANTHROPIC,
|
|
116
118
|
SUBSCRIPTION_LIMIT_FIELDS,
|
|
117
119
|
SUBSCRIPTION_LIMIT_SCOPED_FIELDS,
|
|
120
|
+
SUBSCRIPTION_USAGE_WINDOW_FIELDS,
|
|
118
121
|
subscriptionLimitKey,
|
|
122
|
+
subscriptionUsageKey,
|
|
119
123
|
} from './vocabulary.mjs'
|
|
120
124
|
|
|
121
125
|
const LOG_NAME = 'plan-snapshot.log'
|
|
@@ -124,24 +128,12 @@ const LOG_NAME = 'plan-snapshot.log'
|
|
|
124
128
|
* `logOk`); it stamps the success sidecar instead (§ `stampSuccess`). */
|
|
125
129
|
const snapshotLog = (argv) => markerLog(argv, LOG_NAME)
|
|
126
130
|
|
|
127
|
-
/** The sidecar
|
|
128
|
-
|
|
129
|
-
* the last successful send — what `doctor` reports as activity. */
|
|
130
|
-
export const successMarkerPath = (argv) => `${markerLogPath(argv, LOG_NAME)}.ok`
|
|
131
|
+
/** The activity sidecar (§ marker-core `activityMarkerPath`). */
|
|
132
|
+
export const successMarkerPath = (argv) => activityMarkerPath(argv, LOG_NAME)
|
|
131
133
|
|
|
132
|
-
/** Rewrite the
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (!isOkStatus(status)) return false
|
|
136
|
-
try {
|
|
137
|
-
const path = successMarkerPath(argv)
|
|
138
|
-
ensureLogDir(path)
|
|
139
|
-
writeFileSync(path, `${now.toISOString()}\n`, { mode: 0o600 })
|
|
140
|
-
return true
|
|
141
|
-
} catch {
|
|
142
|
-
return false
|
|
143
|
-
}
|
|
144
|
-
}
|
|
134
|
+
/** Rewrite the sidecar on a 2xx (§ marker-core `stampActivity`). */
|
|
135
|
+
export const stampSuccess = (status, argv = process.argv, now = new Date()) =>
|
|
136
|
+
stampActivity(status, argv, LOG_NAME, now)
|
|
145
137
|
|
|
146
138
|
// Non-coding source/service, as for the ticket and PR markers: the span is
|
|
147
139
|
// about the Anthropic account, not a stretch of coding work.
|
|
@@ -161,6 +153,13 @@ export const EXIT_GRACE_MS = 250
|
|
|
161
153
|
/** At most this many rate-limit entries become keys (the record held 3). */
|
|
162
154
|
export const MAX_LIMITS = 16
|
|
163
155
|
|
|
156
|
+
/** At most this many extra usage windows become keys. */
|
|
157
|
+
export const MAX_USAGE_WINDOWS = 16
|
|
158
|
+
|
|
159
|
+
/** A key of the usage object that names a rolling window beyond the literal
|
|
160
|
+
* five_hour / seven_day pair: those two names plus a `_suffix`. */
|
|
161
|
+
const USAGE_WINDOW_RE = /^(five_hour|seven_day)(_[a-z0-9_]+)?$/
|
|
162
|
+
|
|
164
163
|
const isPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
165
164
|
|
|
166
165
|
/** A non-empty string exactly as stored, else undefined. Strings from the
|
|
@@ -264,6 +263,36 @@ export const limitAttributes = (limits) => {
|
|
|
264
263
|
})
|
|
265
264
|
}
|
|
266
265
|
|
|
266
|
+
/**
|
|
267
|
+
* The typed attributes for the rolling windows of `utilization` other than
|
|
268
|
+
* `five_hour` / `seven_day` (which have literal keys): every key matching
|
|
269
|
+
* `^(five_hour|seven_day)(_[a-z0-9_]+)?$` whose value is a plain object (null
|
|
270
|
+
* and other types are skipped), in sorted key order, at most
|
|
271
|
+
* § `MAX_USAGE_WINDOWS`. Each becomes `usage.<window>.utilization` (double)
|
|
272
|
+
* and `usage.<window>.resets_at` (raw string), each only when usable.
|
|
273
|
+
*/
|
|
274
|
+
export const usageWindowAttributes = (usage) => {
|
|
275
|
+
if (!isPlainObject(usage)) return []
|
|
276
|
+
return Object.keys(usage)
|
|
277
|
+
.filter(
|
|
278
|
+
(k) =>
|
|
279
|
+
USAGE_WINDOW_RE.test(k) &&
|
|
280
|
+
k !== 'five_hour' &&
|
|
281
|
+
k !== 'seven_day' &&
|
|
282
|
+
isPlainObject(usage[k]),
|
|
283
|
+
)
|
|
284
|
+
.sort()
|
|
285
|
+
.slice(0, MAX_USAGE_WINDOWS)
|
|
286
|
+
.flatMap((name) => {
|
|
287
|
+
const w = usage[name]
|
|
288
|
+
return SUBSCRIPTION_USAGE_WINDOW_FIELDS.flatMap((field) =>
|
|
289
|
+
field === 'utilization'
|
|
290
|
+
? typed(doubleAttr, [[subscriptionUsageKey(name, field), finite(w.utilization)]])
|
|
291
|
+
: typed(stringAttr, [[subscriptionUsageKey(name, field), rawString(w.resets_at)]]),
|
|
292
|
+
)
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
|
|
267
296
|
/**
|
|
268
297
|
* The snapshot in one parsed `.claude.json` document, or `undefined` when it
|
|
269
298
|
* has no usable `oauthAccount.accountUuid` (no account, nothing to attribute).
|
|
@@ -279,7 +308,8 @@ export const limitAttributes = (limits) => {
|
|
|
279
308
|
* first-token date — the record's top-level `claudeCodeFirstTokenDate`;
|
|
280
309
|
* - `extra_usage.enabled`: the usage cache's `is_enabled`, else the account's
|
|
281
310
|
* `hasExtraUsageEnabled`;
|
|
282
|
-
* - everything else — 5-hour / 7-day utilization and resets,
|
|
311
|
+
* - everything else — 5-hour / 7-day utilization and resets, the other rolling
|
|
312
|
+
* windows (§ `usageWindowAttributes`, after the 7-day pair), per-kind rate
|
|
283
313
|
* limits, the extra-usage figures and flags, the top-level
|
|
284
314
|
* `cachedExtraUsageDisabledReason`, and `observed_at` (`fetchedAtMs`) —
|
|
285
315
|
* only when `cachedUsageUtilization` names the same `accountUuid`: another
|
|
@@ -341,6 +371,7 @@ export const snapshotFromRecord = (doc) => {
|
|
|
341
371
|
...typed(stringAttr, [
|
|
342
372
|
[ATTR_USAGE_SEVEN_DAY_RESETS_AT, rawString(window('seven_day').resets_at)],
|
|
343
373
|
]),
|
|
374
|
+
...usageWindowAttributes(usage),
|
|
344
375
|
...limitAttributes(usage.limits),
|
|
345
376
|
...typed(intAttr, [
|
|
346
377
|
[ATTR_EXTRA_USAGE_USED_MINOR, count(extra?.used_credits)],
|
package/hooks/vocabulary.d.mts
CHANGED
|
@@ -93,6 +93,9 @@ export const ATTR_ORGANIZATION_ID: string
|
|
|
93
93
|
export const SUBSCRIPTION_LIMIT_FIELDS: readonly string[]
|
|
94
94
|
export const SUBSCRIPTION_LIMIT_SCOPED_FIELDS: readonly string[]
|
|
95
95
|
export const subscriptionLimitKey: (kind: string, field: string, scope?: string) => string
|
|
96
|
+
export const SUBSCRIPTION_USAGE_PREFIX: string
|
|
97
|
+
export const SUBSCRIPTION_USAGE_WINDOW_FIELDS: readonly string[]
|
|
98
|
+
export const subscriptionUsageKey: (window: string, field: string) => string
|
|
96
99
|
export const SUBSCRIPTION_SNAPSHOT_KEYS: readonly string[]
|
|
97
100
|
|
|
98
101
|
export const CLAUDE_CODE_STOP_FAILURE: string
|
package/hooks/vocabulary.mjs
CHANGED
|
@@ -253,6 +253,14 @@ export const ATTR_USAGE_FIVE_HOUR_UTILIZATION = 'mainwave.subscription.usage.fiv
|
|
|
253
253
|
export const ATTR_USAGE_FIVE_HOUR_RESETS_AT = 'mainwave.subscription.usage.five_hour.resets_at'
|
|
254
254
|
export const ATTR_USAGE_SEVEN_DAY_UTILIZATION = 'mainwave.subscription.usage.seven_day.utilization'
|
|
255
255
|
export const ATTR_USAGE_SEVEN_DAY_RESETS_AT = 'mainwave.subscription.usage.seven_day.resets_at'
|
|
256
|
+
// Further rolling windows the usage cache reports (`seven_day_opus`, ...) go
|
|
257
|
+
// under the generic shape `usage.<window>.<field>`; `five_hour` and `seven_day`
|
|
258
|
+
// stay the literals above and are never sent twice.
|
|
259
|
+
export const SUBSCRIPTION_USAGE_PREFIX = 'mainwave.subscription.usage.'
|
|
260
|
+
export const SUBSCRIPTION_USAGE_WINDOW_FIELDS = ['utilization', 'resets_at']
|
|
261
|
+
/** `mainwave.subscription.usage.<window>.<field>`. */
|
|
262
|
+
export const subscriptionUsageKey = (window, field) =>
|
|
263
|
+
`${SUBSCRIPTION_USAGE_PREFIX}${window}.${field}`
|
|
256
264
|
export const ATTR_EXTRA_USAGE_ENABLED = 'mainwave.subscription.extra_usage.enabled'
|
|
257
265
|
export const ATTR_EXTRA_USAGE_USED_MINOR = 'mainwave.subscription.extra_usage.used_minor'
|
|
258
266
|
export const ATTR_EXTRA_USAGE_LIMIT_MINOR = 'mainwave.subscription.extra_usage.limit_minor'
|
|
@@ -389,8 +397,8 @@ export const CODEX_TURN_KEYS = [
|
|
|
389
397
|
// The dispatcher drops every span attribute a feature's entry here doesn't
|
|
390
398
|
// bind, and every span whose name isn't the feature's, before anything is
|
|
391
399
|
// posted: a key added to a feature without a registered name here never
|
|
392
|
-
// leaves the machine. `prefixes` covers the snapshot's per-kind limit keys
|
|
393
|
-
//
|
|
400
|
+
// leaves the machine. `prefixes` covers the snapshot's per-kind limit keys and
|
|
401
|
+
// extra usage-window keys, registered patterns. Every feature may also send the identity pair, the
|
|
394
402
|
// session id and the calling-span keys (§ COMMON_SPAN_KEYS).
|
|
395
403
|
export const COMMON_SPAN_KEYS = Object.freeze([
|
|
396
404
|
'session.id',
|
|
@@ -403,7 +411,7 @@ export const FEATURE_EMITS = Object.freeze({
|
|
|
403
411
|
'plan-snapshot': {
|
|
404
412
|
spans: [SUBSCRIPTION_SNAPSHOT],
|
|
405
413
|
keys: SUBSCRIPTION_SNAPSHOT_KEYS,
|
|
406
|
-
prefixes: [SUBSCRIPTION_LIMIT_PREFIX],
|
|
414
|
+
prefixes: [SUBSCRIPTION_LIMIT_PREFIX, SUBSCRIPTION_USAGE_PREFIX],
|
|
407
415
|
},
|
|
408
416
|
'github-pr-marker': { spans: [VCS_OPENED], keys: VCS_MARKER_KEYS, prefixes: [] },
|
|
409
417
|
'glab-mr-marker': { spans: [VCS_OPENED], keys: VCS_MARKER_KEYS, prefixes: [] },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainwave/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Setup wizard for connecting third-party coding tools to Mainwave AI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"provenance": false
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": "^22.
|
|
21
|
+
"node": "^22.22.2 || ^24.15.0 || >=26.0.0",
|
|
22
22
|
"pnpm": ">=10.0.0"
|
|
23
23
|
},
|
|
24
24
|
"packageManager": "pnpm@10.0.0",
|
|
@@ -45,18 +45,18 @@
|
|
|
45
45
|
"api:generate": "openapi-ts"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@inquirer/prompts": "8.
|
|
48
|
+
"@inquirer/prompts": "8.8.0",
|
|
49
49
|
"picocolors": "1.1.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@hey-api/openapi-ts": "^0.99.0",
|
|
53
53
|
"@types/node": "22.20.5",
|
|
54
|
-
"knip": "6.45.
|
|
54
|
+
"knip": "6.45.1",
|
|
55
55
|
"lefthook": "2.2.2",
|
|
56
56
|
"oxlint": "1.93.0",
|
|
57
|
-
"prettier": "3.
|
|
57
|
+
"prettier": "3.10.1",
|
|
58
58
|
"typescript": "6.0.3",
|
|
59
|
-
"vite": "8.3.
|
|
59
|
+
"vite": "8.3.8",
|
|
60
60
|
"vitest": "5.1.0",
|
|
61
61
|
"yaml": "2.9.1"
|
|
62
62
|
},
|