@sitepong/cli 0.1.39 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/factory/index.js +118 -0
- package/dist/commands/factory/index.js.map +1 -0
- package/dist/commands/factory/settings.js +143 -0
- package/dist/commands/factory/settings.js.map +1 -0
- package/dist/commands/factory/settings.test.js +75 -0
- package/dist/commands/factory/settings.test.js.map +1 -0
- package/dist/commands/tracker/index.js +262 -0
- package/dist/commands/tracker/index.js.map +1 -0
- package/dist/commands/tracker/render.js +317 -0
- package/dist/commands/tracker/render.js.map +1 -0
- package/dist/commands/tracker/render.test.js +142 -0
- package/dist/commands/tracker/render.test.js.map +1 -0
- package/dist/commands/tracker/tracker.test.js +162 -0
- package/dist/commands/tracker/tracker.test.js.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
function registerDecision(factory, name) {
|
|
2
|
+
const approving = name === 'approve';
|
|
3
|
+
factory
|
|
4
|
+
.command(`${name} <ticket>`)
|
|
5
|
+
.description(approving
|
|
6
|
+
? 'Approve the gate a ticket\'s run waits on (plan, rollout or ship)'
|
|
7
|
+
: 'Decline the gate a ticket\'s run waits on; Factory reads your note and revises')
|
|
8
|
+
.option('--gate <gate>', 'plan, rollout or ship (needed only when more than one waits)')
|
|
9
|
+
.option('--note <text>', approving ? 'A note for Factory' : 'Why, for Factory to act on')
|
|
10
|
+
.option('--project <id>', 'Project ID (for a ticket number)')
|
|
11
|
+
.option('--org <id>', 'Organization ID')
|
|
12
|
+
.action(async (ticket, opts) => {
|
|
13
|
+
const { apiClient } = await import('../../client/api.js');
|
|
14
|
+
const { isMachineOutput, formatJson } = await import('../../output/format.js');
|
|
15
|
+
const { success } = await import('../../output/log.js');
|
|
16
|
+
const { ticketPath } = await import('../tracker/index.js');
|
|
17
|
+
const { pickGate, ticketLabel } = await import('../tracker/render.js');
|
|
18
|
+
const { path, query } = await ticketPath(ticket, opts);
|
|
19
|
+
// GET /api/dashboard/tracker/items/:ref → { data: { item, run, gates, ... } }
|
|
20
|
+
const res = await apiClient().get(path, { query });
|
|
21
|
+
if (!res.data?.run)
|
|
22
|
+
throw new Error(`Factory is not working on ${ticketLabel(ticket)}.`);
|
|
23
|
+
const gate = pickGate(res.data.gates ?? [], opts.gate?.trim().toLowerCase());
|
|
24
|
+
// POST /api/dashboard/factory/gates/:gateId { decision, note? } → { data: gate } (409 when already decided)
|
|
25
|
+
const decided = await apiClient().post(`/api/dashboard/factory/gates/${encodeURIComponent(String(gate.id))}`, { body: { decision: approving ? 'approved' : 'denied', note: opts.note } });
|
|
26
|
+
if (isMachineOutput()) {
|
|
27
|
+
console.log(formatJson(decided.data));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
success(`${approving ? 'Approved' : 'Declined'} the ${gate.gate} gate on ${ticketLabel(ticket)}. Factory picks it up on its next tick.`);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function registerFactory(parent) {
|
|
34
|
+
const factory = parent.command('factory').description('Factory: the agent that works on Tracker tickets, its gates, budgets and settings');
|
|
35
|
+
registerDecision(factory, 'approve');
|
|
36
|
+
registerDecision(factory, 'decline');
|
|
37
|
+
factory
|
|
38
|
+
.command('status')
|
|
39
|
+
.description('On or off, work mode, today\'s spend against the daily cap, and what needs you')
|
|
40
|
+
.option('--project <id>', 'Project ID')
|
|
41
|
+
.option('--org <id>', 'Organization ID')
|
|
42
|
+
.action(async (opts) => {
|
|
43
|
+
const { apiClient } = await import('../../client/api.js');
|
|
44
|
+
const { requireContext } = await import('../../config/context.js');
|
|
45
|
+
const { isMachineOutput, formatJson, formatDetail } = await import('../../output/format.js');
|
|
46
|
+
const { hint } = await import('../../output/log.js');
|
|
47
|
+
const { statusRecord } = await import('./settings.js');
|
|
48
|
+
const ctx = requireContext(opts);
|
|
49
|
+
// GET /api/dashboard/factory/status → { data: { set_up, enabled, model, work_mode, spend_today_usd, needs_you, ... } }
|
|
50
|
+
const res = await apiClient().get('/api/dashboard/factory/status', { query: { project_id: ctx.project_id } });
|
|
51
|
+
if (isMachineOutput()) {
|
|
52
|
+
console.log(formatJson(res.data));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.log(formatDetail(statusRecord(res.data ?? {})));
|
|
56
|
+
const needs = (res.data?.needs_you ?? {});
|
|
57
|
+
if (needs.total)
|
|
58
|
+
hint('Run `sitepong tracker list --factory` to find them, then `sitepong tracker show <ticket>`.');
|
|
59
|
+
});
|
|
60
|
+
const settings = factory.command('settings').description('Read or change the project\'s Factory settings');
|
|
61
|
+
settings
|
|
62
|
+
.command('get')
|
|
63
|
+
.description('Show the model, budgets, work mode and schedule, max active runs and gate autonomy')
|
|
64
|
+
.option('--project <id>', 'Project ID')
|
|
65
|
+
.option('--org <id>', 'Organization ID')
|
|
66
|
+
.action(async (opts) => {
|
|
67
|
+
const { apiClient } = await import('../../client/api.js');
|
|
68
|
+
const { requireContext } = await import('../../config/context.js');
|
|
69
|
+
const { isMachineOutput, formatJson, formatDetail } = await import('../../output/format.js');
|
|
70
|
+
const { settingsRecord } = await import('./settings.js');
|
|
71
|
+
const ctx = requireContext(opts);
|
|
72
|
+
// GET /api/dashboard/factory/settings → { data: { settings, models } }
|
|
73
|
+
const res = await apiClient().get('/api/dashboard/factory/settings', {
|
|
74
|
+
query: { project_id: ctx.project_id },
|
|
75
|
+
});
|
|
76
|
+
if (isMachineOutput()) {
|
|
77
|
+
console.log(formatJson(res.data));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
console.log(formatDetail(settingsRecord(res.data.settings, res.data.models)));
|
|
81
|
+
});
|
|
82
|
+
settings
|
|
83
|
+
.command('set')
|
|
84
|
+
.description('Change Factory settings. Only the flags you pass change.')
|
|
85
|
+
.option('--model <model>', 'deepseek-flash (flash), deepseek-v4-pro (pro), claude-sonnet-5-5 (sonnet) or claude-opus-5-5 (opus)')
|
|
86
|
+
.option('--run-budget <usd>', 'Budget per run in USD, across every stage (default 5)')
|
|
87
|
+
.option('--daily-budget <usd>', 'The project\'s model spend per day in USD, or "none" for no cap')
|
|
88
|
+
.option('--work-mode <mode>', 'manual (a person starts each ticket), immediate (as soon as there is room) or schedule (daily)')
|
|
89
|
+
.option('--at <HH:MM>', 'Schedule: the time of day work starts, 24-hour')
|
|
90
|
+
.option('--tz <zone>', 'Schedule: IANA timezone, e.g. America/New_York (also the day the daily budget counts)')
|
|
91
|
+
.option('--per-window <n>', 'Schedule: tickets started each day (1-20)')
|
|
92
|
+
.option('--max-active-runs <n>', 'Runs at once (1-20)')
|
|
93
|
+
.option('--autonomy <gates>', 'Which gates pass without a person, e.g. plan=auto,rollout=human,ship=human')
|
|
94
|
+
.option('--enable', 'Turn Factory on')
|
|
95
|
+
.option('--disable', 'Turn Factory off')
|
|
96
|
+
.option('--project <id>', 'Project ID')
|
|
97
|
+
.option('--org <id>', 'Organization ID')
|
|
98
|
+
.action(async (opts) => {
|
|
99
|
+
const { apiClient } = await import('../../client/api.js');
|
|
100
|
+
const { requireContext } = await import('../../config/context.js');
|
|
101
|
+
const { isMachineOutput, formatJson, formatDetail } = await import('../../output/format.js');
|
|
102
|
+
const { success } = await import('../../output/log.js');
|
|
103
|
+
const { settingsBody, settingsRecord } = await import('./settings.js');
|
|
104
|
+
const body = settingsBody(opts);
|
|
105
|
+
const ctx = requireContext(opts);
|
|
106
|
+
// PATCH /api/dashboard/factory/settings { project_id, ...changes } → { data: { settings } }
|
|
107
|
+
const res = await apiClient().patch('/api/dashboard/factory/settings', {
|
|
108
|
+
body: { project_id: ctx.project_id, ...body },
|
|
109
|
+
});
|
|
110
|
+
if (isMachineOutput()) {
|
|
111
|
+
console.log(formatJson(res.data));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
success('Factory settings saved');
|
|
115
|
+
console.log(formatDetail(settingsRecord(res.data.settings)));
|
|
116
|
+
});
|
|
117
|
+
}
|
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AK,CAAkD,iCAAiC,EAAE;YACtH,IAAI,EAAE,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,IAAI,EAAE;SAC9C,CAAC,CAAC;QACH,IAAI,eAAe,EAAE,EAAE,CAAC;YAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QACrE,OAAO,CAAC,wBAAwB,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Factory status and settings: the flags `factory settings set` takes, and
|
|
2
|
+
// how status and settings read in a terminal. Pure, so they are tested alone.
|
|
3
|
+
import { MODEL_NAME, money } from '../tracker/render.js';
|
|
4
|
+
const obj = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? v : {});
|
|
5
|
+
/** Short names people type for the models. */
|
|
6
|
+
const MODEL_ALIAS = {
|
|
7
|
+
flash: 'deepseek-flash',
|
|
8
|
+
'deepseek-flash': 'deepseek-flash',
|
|
9
|
+
pro: 'deepseek-v4-pro',
|
|
10
|
+
'v4-pro': 'deepseek-v4-pro',
|
|
11
|
+
'deepseek-v4-pro': 'deepseek-v4-pro',
|
|
12
|
+
sonnet: 'claude-sonnet-5-5',
|
|
13
|
+
'claude-sonnet-5-5': 'claude-sonnet-5-5',
|
|
14
|
+
opus: 'claude-opus-5-5',
|
|
15
|
+
'claude-opus-5-5': 'claude-opus-5-5',
|
|
16
|
+
};
|
|
17
|
+
function amount(raw, flag) {
|
|
18
|
+
const n = Number(raw.replace(/^\$/, ''));
|
|
19
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
20
|
+
throw new Error(`${flag} is an amount in USD, e.g. 5 or 7.50`);
|
|
21
|
+
return n;
|
|
22
|
+
}
|
|
23
|
+
function whole(raw, flag) {
|
|
24
|
+
const n = Number(raw);
|
|
25
|
+
if (!Number.isInteger(n) || n < 1)
|
|
26
|
+
throw new Error(`${flag} is a whole number of at least 1`);
|
|
27
|
+
return n;
|
|
28
|
+
}
|
|
29
|
+
/** `plan=auto,ship=human` → { plan: 'auto', ship: 'human' }. */
|
|
30
|
+
export function parseAutonomy(raw) {
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const part of raw.split(',').map((s) => s.trim()).filter(Boolean)) {
|
|
33
|
+
const [gate, value] = part.split('=').map((s) => s.trim().toLowerCase());
|
|
34
|
+
if (!['plan', 'rollout', 'ship'].includes(gate))
|
|
35
|
+
throw new Error(`Unknown gate "${gate}" in --autonomy (plan, rollout or ship)`);
|
|
36
|
+
if (value !== 'auto' && value !== 'human')
|
|
37
|
+
throw new Error(`--autonomy ${gate}= is auto or human`);
|
|
38
|
+
out[gate] = value;
|
|
39
|
+
}
|
|
40
|
+
if (!Object.keys(out).length)
|
|
41
|
+
throw new Error('--autonomy takes gate=auto|human pairs, e.g. plan=auto,ship=human');
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** The PATCH body for `factory settings set`. The API checks the bounds again. */
|
|
45
|
+
export function settingsBody(o) {
|
|
46
|
+
const body = {};
|
|
47
|
+
if (o.enable && o.disable)
|
|
48
|
+
throw new Error('Pass --enable or --disable, not both.');
|
|
49
|
+
if (o.enable)
|
|
50
|
+
body.enabled = true;
|
|
51
|
+
if (o.disable)
|
|
52
|
+
body.enabled = false;
|
|
53
|
+
if (o.model !== undefined)
|
|
54
|
+
body.model = MODEL_ALIAS[o.model.trim().toLowerCase()] ?? o.model.trim();
|
|
55
|
+
if (o.runBudget !== undefined)
|
|
56
|
+
body.run_budget_usd = amount(o.runBudget, '--run-budget');
|
|
57
|
+
if (o.dailyBudget !== undefined) {
|
|
58
|
+
body.daily_budget_usd = ['none', 'off', ''].includes(o.dailyBudget.trim().toLowerCase()) ? null : amount(o.dailyBudget, '--daily-budget');
|
|
59
|
+
}
|
|
60
|
+
if (o.workMode !== undefined) {
|
|
61
|
+
const m = o.workMode.trim().toLowerCase();
|
|
62
|
+
if (!['manual', 'immediate', 'schedule'].includes(m))
|
|
63
|
+
throw new Error('--work-mode is manual, immediate or schedule');
|
|
64
|
+
body.work_mode = m;
|
|
65
|
+
}
|
|
66
|
+
const schedule = {};
|
|
67
|
+
if (o.at !== undefined) {
|
|
68
|
+
if (!/^([01]\d|2[0-3]):[0-5]\d$/.test(o.at.trim()))
|
|
69
|
+
throw new Error('--at is HH:MM, 24-hour (e.g. 09:00)');
|
|
70
|
+
schedule.at = o.at.trim();
|
|
71
|
+
}
|
|
72
|
+
if (o.tz !== undefined)
|
|
73
|
+
schedule.tz = o.tz.trim();
|
|
74
|
+
if (o.perWindow !== undefined)
|
|
75
|
+
schedule.per_window = whole(o.perWindow, '--per-window');
|
|
76
|
+
if (Object.keys(schedule).length)
|
|
77
|
+
body.work_schedule = schedule;
|
|
78
|
+
if (o.maxActiveRuns !== undefined)
|
|
79
|
+
body.max_active_runs = whole(o.maxActiveRuns, '--max-active-runs');
|
|
80
|
+
if (o.autonomy !== undefined)
|
|
81
|
+
body.autonomy = parseAutonomy(o.autonomy);
|
|
82
|
+
if (!Object.keys(body).length)
|
|
83
|
+
throw new Error('Nothing to change. Run `sitepong factory settings set --help` for the settings.');
|
|
84
|
+
return body;
|
|
85
|
+
}
|
|
86
|
+
export const modelName = (m) => (typeof m === 'string' ? MODEL_NAME[m] ?? m : '');
|
|
87
|
+
/** "schedule: daily at 09:00 UTC, up to 2 tickets" and so on. */
|
|
88
|
+
export function workModeLine(mode, schedule) {
|
|
89
|
+
const s = obj(schedule);
|
|
90
|
+
if (mode === 'immediate')
|
|
91
|
+
return 'immediate: a ticket starts as soon as there is room';
|
|
92
|
+
if (mode === 'schedule') {
|
|
93
|
+
const n = Number(s.per_window ?? 1);
|
|
94
|
+
return `schedule: daily at ${s.at ?? '09:00'} ${s.tz ?? 'UTC'}, up to ${n} ticket${n === 1 ? '' : 's'}`;
|
|
95
|
+
}
|
|
96
|
+
return 'manual: a person starts each ticket';
|
|
97
|
+
}
|
|
98
|
+
export function autonomyLine(a) {
|
|
99
|
+
const o = obj(a);
|
|
100
|
+
return ['plan', 'rollout', 'ship'].map((g) => `${g} ${o[g] === 'auto' ? 'auto' : 'person'}`).join(' · ');
|
|
101
|
+
}
|
|
102
|
+
/** `factory status` as key/value lines. */
|
|
103
|
+
export function statusRecord(d) {
|
|
104
|
+
if (!d.set_up) {
|
|
105
|
+
const needs = obj(d.needs_you);
|
|
106
|
+
return { factory: 'not set up (connect a repository in the console)', needs_you: String(needs.total ?? 0) };
|
|
107
|
+
}
|
|
108
|
+
const daily = d.daily_budget_usd === null || d.daily_budget_usd === undefined ? null : Number(d.daily_budget_usd);
|
|
109
|
+
const spent = Number(d.spend_today_usd ?? 0);
|
|
110
|
+
const spend = daily === null ? `${money(spent)} (no daily cap)` : `${money(spent)} of ${money(daily)} (${Math.round((spent / daily) * 100)}%)${spent >= daily ? ', cap reached: nothing new starts today' : ''}`;
|
|
111
|
+
const needs = obj(d.needs_you);
|
|
112
|
+
const parts = [
|
|
113
|
+
Number(needs.gates ?? 0) ? `${needs.gates} gate${needs.gates === 1 ? '' : 's'}` : '',
|
|
114
|
+
Number(needs.budget ?? 0) ? `${needs.budget} paused on budget` : '',
|
|
115
|
+
Number(needs.specs ?? 0) ? `${needs.specs} spec${needs.specs === 1 ? '' : 's'}` : '',
|
|
116
|
+
].filter(Boolean);
|
|
117
|
+
return {
|
|
118
|
+
status: d.enabled ? 'on' : 'off',
|
|
119
|
+
repo: String(d.repo ?? ''),
|
|
120
|
+
model: modelName(d.model),
|
|
121
|
+
work_mode: workModeLine(d.work_mode, d.work_schedule),
|
|
122
|
+
spend_today: spend,
|
|
123
|
+
run_budget: d.run_budget_usd === null || d.run_budget_usd === undefined ? '' : money(d.run_budget_usd),
|
|
124
|
+
runs: `${d.active_runs ?? 0} working of at most ${d.max_active_runs ?? '?'}, ${d.tickets_waiting ?? 0} not started`,
|
|
125
|
+
needs_you: `${needs.total ?? 0}${parts.length ? ` (${parts.join(', ')})` : ''}`,
|
|
126
|
+
gates: autonomyLine(d.autonomy),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** `factory settings get` as key/value lines. */
|
|
130
|
+
export function settingsRecord(s, models = []) {
|
|
131
|
+
return {
|
|
132
|
+
enabled: s.enabled ? 'true' : 'false',
|
|
133
|
+
repo: String(s.repo ?? ''),
|
|
134
|
+
model: `${s.model ?? ''}${MODEL_NAME[String(s.model)] ? ` (${MODEL_NAME[String(s.model)]})` : ''}`,
|
|
135
|
+
run_budget_usd: s.run_budget_usd === null || s.run_budget_usd === undefined ? '' : money(s.run_budget_usd),
|
|
136
|
+
daily_budget_usd: s.daily_budget_usd === null || s.daily_budget_usd === undefined ? 'none' : money(s.daily_budget_usd),
|
|
137
|
+
work_mode: workModeLine(s.work_mode, s.work_schedule),
|
|
138
|
+
max_active_runs: String(s.max_active_runs ?? ''),
|
|
139
|
+
autonomy: autonomyLine(s.autonomy),
|
|
140
|
+
...(models.length ? { models: models.join(', ') } : {}),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../src/commands/factory/settings.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGzD,MAAM,GAAG,GAAG,CAAC,CAAU,EAAO,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAgBrG,8CAA8C;AAC9C,MAA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,CAAC,eAAe,IAAI,EAAE,CAAC;QAChD,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC;QAClC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { autonomyLine, parseAutonomy, settingsBody, settingsRecord, statusRecord, workModeLine } from './settings.js';
|
|
3
|
+
describe('settingsBody', () => {
|
|
4
|
+
it('turns flags into the PATCH body', () => {
|
|
5
|
+
expect(settingsBody({
|
|
6
|
+
model: 'opus', runBudget: '$7.50', dailyBudget: '25', workMode: 'Schedule', at: '07:30', tz: 'America/New_York',
|
|
7
|
+
perWindow: '2', maxActiveRuns: '3', autonomy: 'plan=auto, ship=human', enable: true,
|
|
8
|
+
})).toEqual({
|
|
9
|
+
enabled: true,
|
|
10
|
+
model: 'claude-opus-5-5',
|
|
11
|
+
run_budget_usd: 7.5,
|
|
12
|
+
daily_budget_usd: 25,
|
|
13
|
+
work_mode: 'schedule',
|
|
14
|
+
work_schedule: { at: '07:30', tz: 'America/New_York', per_window: 2 },
|
|
15
|
+
max_active_runs: 3,
|
|
16
|
+
autonomy: { plan: 'auto', ship: 'human' },
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('passes a model id it does not know through for the API to judge', () => {
|
|
20
|
+
expect(settingsBody({ model: 'deepseek-v5' })).toEqual({ model: 'deepseek-v5' });
|
|
21
|
+
expect(settingsBody({ model: 'flash' })).toEqual({ model: 'deepseek-flash' });
|
|
22
|
+
});
|
|
23
|
+
it('clears the daily cap and sends a partial schedule', () => {
|
|
24
|
+
expect(settingsBody({ dailyBudget: 'none' })).toEqual({ daily_budget_usd: null });
|
|
25
|
+
expect(settingsBody({ at: '09:15' })).toEqual({ work_schedule: { at: '09:15' } });
|
|
26
|
+
expect(settingsBody({ disable: true })).toEqual({ enabled: false });
|
|
27
|
+
});
|
|
28
|
+
it('refuses bad flags and nothing at all', () => {
|
|
29
|
+
expect(() => settingsBody({})).toThrow('Nothing to change');
|
|
30
|
+
expect(() => settingsBody({ enable: true, disable: true })).toThrow('not both');
|
|
31
|
+
expect(() => settingsBody({ runBudget: 'lots' })).toThrow('--run-budget');
|
|
32
|
+
expect(() => settingsBody({ dailyBudget: '0' })).toThrow('--daily-budget');
|
|
33
|
+
expect(() => settingsBody({ workMode: 'always' })).toThrow('--work-mode');
|
|
34
|
+
expect(() => settingsBody({ at: '9am' })).toThrow('--at');
|
|
35
|
+
expect(() => settingsBody({ perWindow: '1.5' })).toThrow('--per-window');
|
|
36
|
+
expect(() => settingsBody({ maxActiveRuns: '0' })).toThrow('--max-active-runs');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('parseAutonomy', () => {
|
|
40
|
+
it('reads gate=value pairs', () => {
|
|
41
|
+
expect(parseAutonomy('plan=auto,rollout=human')).toEqual({ plan: 'auto', rollout: 'human' });
|
|
42
|
+
});
|
|
43
|
+
it('refuses unknown gates and values', () => {
|
|
44
|
+
expect(() => parseAutonomy('deploy=auto')).toThrow('Unknown gate');
|
|
45
|
+
expect(() => parseAutonomy('plan=yes')).toThrow('auto or human');
|
|
46
|
+
expect(() => parseAutonomy(',')).toThrow('pairs');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('status and settings records', () => {
|
|
50
|
+
it('words the work mode and autonomy', () => {
|
|
51
|
+
expect(workModeLine('manual', {})).toBe('manual: a person starts each ticket');
|
|
52
|
+
expect(workModeLine('immediate', {})).toMatch(/^immediate/);
|
|
53
|
+
expect(workModeLine('schedule', { at: '07:30', tz: 'Europe/Paris', per_window: 2 })).toBe('schedule: daily at 07:30 Europe/Paris, up to 2 tickets');
|
|
54
|
+
expect(autonomyLine({ plan: 'auto' })).toBe('plan auto · rollout person · ship person');
|
|
55
|
+
});
|
|
56
|
+
it("shows today's spend against the cap and what needs you", () => {
|
|
57
|
+
const r = statusRecord({
|
|
58
|
+
set_up: true, enabled: true, repo: 'acme/app', model: 'deepseek-flash', work_mode: 'manual', work_schedule: {},
|
|
59
|
+
run_budget_usd: 5, daily_budget_usd: 20, spend_today_usd: 5, max_active_runs: 2, active_runs: 1, tickets_waiting: 3,
|
|
60
|
+
needs_you: { total: 3, gates: 2, budget: 1, specs: 0 }, autonomy: {},
|
|
61
|
+
});
|
|
62
|
+
expect(r).toMatchObject({
|
|
63
|
+
status: 'on', model: 'DeepSeek Flash', spend_today: '$5.00 of $20.00 (25%)', run_budget: '$5.00',
|
|
64
|
+
runs: '1 working of at most 2, 3 not started', needs_you: '3 (2 gates, 1 paused on budget)',
|
|
65
|
+
});
|
|
66
|
+
expect(statusRecord({ set_up: true, enabled: false, daily_budget_usd: 2, spend_today_usd: 2.5, needs_you: {} }).spend_today).toContain('cap reached');
|
|
67
|
+
expect(statusRecord({ set_up: true, daily_budget_usd: null, spend_today_usd: 1, needs_you: {} }).spend_today).toBe('$1.00 (no daily cap)');
|
|
68
|
+
expect(statusRecord({ set_up: false, needs_you: { total: 1 } })).toEqual({ factory: 'not set up (connect a repository in the console)', needs_you: '1' });
|
|
69
|
+
});
|
|
70
|
+
it('shows settings', () => {
|
|
71
|
+
expect(settingsRecord({ enabled: true, repo: 'acme/app', model: 'claude-sonnet-5-5', run_budget_usd: 5, daily_budget_usd: null, work_mode: 'manual', max_active_runs: 2, autonomy: {} }, ['deepseek-flash']))
|
|
72
|
+
.toMatchObject({ model: 'claude-sonnet-5-5 (Claude Sonnet 5.5)', daily_budget_usd: 'none', run_budget_usd: '$5.00', models: 'deepseek-flash' });
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=settings.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.test.js","sourceRoot":"","sources":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v.split(',').map((s) => s.trim()).filter(Boolean)];
|
|
2
|
+
/** The ticket's URL path and the project it is looked up in. A number needs a project. */
|
|
3
|
+
export async function ticketPath(input, opts) {
|
|
4
|
+
const { parseTicketRef, refSegment } = await import('./render.js');
|
|
5
|
+
const ref = parseTicketRef(input);
|
|
6
|
+
if ('number' in ref) {
|
|
7
|
+
const { requireContext } = await import('../../config/context.js');
|
|
8
|
+
const ctx = requireContext(opts);
|
|
9
|
+
return { path: `/api/dashboard/tracker/items/${refSegment(ref)}`, query: { project_id: ctx.project_id } };
|
|
10
|
+
}
|
|
11
|
+
return { path: `/api/dashboard/tracker/items/${refSegment(ref)}`, query: {} };
|
|
12
|
+
}
|
|
13
|
+
/** Every tracker_* function answers { <verb>: boolean, reason? }; a refusal becomes an error with its reason. */
|
|
14
|
+
export function verdict(data, key, fallback) {
|
|
15
|
+
const d = (data?.data ?? data ?? {});
|
|
16
|
+
if (d[key] !== true)
|
|
17
|
+
throw new Error(typeof d.reason === 'string' ? d.reason : fallback);
|
|
18
|
+
return d;
|
|
19
|
+
}
|
|
20
|
+
async function readStdin() {
|
|
21
|
+
const chunks = [];
|
|
22
|
+
for await (const chunk of process.stdin)
|
|
23
|
+
chunks.push(chunk);
|
|
24
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
25
|
+
}
|
|
26
|
+
/** Text from words, a file (--file), or stdin ("-"). */
|
|
27
|
+
async function textFrom(words, file) {
|
|
28
|
+
if (file) {
|
|
29
|
+
const fs = await import('node:fs');
|
|
30
|
+
return file === '-' ? readStdin() : fs.readFileSync(file, 'utf8');
|
|
31
|
+
}
|
|
32
|
+
const joined = (words ?? []).join(' ');
|
|
33
|
+
return joined === '-' ? readStdin() : joined;
|
|
34
|
+
}
|
|
35
|
+
export function registerTracker(parent) {
|
|
36
|
+
const tracker = parent
|
|
37
|
+
.command('tracker')
|
|
38
|
+
.description('Tracker tickets: issues, features and tasks, and Factory working on them');
|
|
39
|
+
tracker
|
|
40
|
+
.command('list')
|
|
41
|
+
.alias('ls')
|
|
42
|
+
.description('List the project\'s tickets, newest activity first')
|
|
43
|
+
.option('--status <status>', 'Only these statuses: open, backlog, todo, in_progress, in_review, done, cancelled (comma-separated or repeated)', collect, [])
|
|
44
|
+
.option('--kind <kind>', 'Only these kinds: issue, feature, task (comma-separated or repeated)', collect, [])
|
|
45
|
+
.option('--factory', 'Only tickets Factory has')
|
|
46
|
+
.option('--mine', 'Only tickets assigned to or opened by you')
|
|
47
|
+
.option('--limit <n>', 'Max tickets (1-200)', '50')
|
|
48
|
+
.option('--project <id>', 'Project ID')
|
|
49
|
+
.option('--org <id>', 'Organization ID')
|
|
50
|
+
.action(async (opts) => {
|
|
51
|
+
const { apiClient } = await import('../../client/api.js');
|
|
52
|
+
const { requireContext } = await import('../../config/context.js');
|
|
53
|
+
const { output } = await import('../../output/format.js');
|
|
54
|
+
const { ticketRows, LIST_COLUMNS } = await import('./render.js');
|
|
55
|
+
const { isMachineOutput } = await import('../../output/format.js');
|
|
56
|
+
const ctx = requireContext(opts);
|
|
57
|
+
// GET /api/dashboard/tracker/items → { data: Ticket[] (each with run), total }
|
|
58
|
+
const res = await apiClient().get('/api/dashboard/tracker/items', {
|
|
59
|
+
query: {
|
|
60
|
+
project_id: ctx.project_id,
|
|
61
|
+
status: opts.status.length ? opts.status.join(',') : undefined,
|
|
62
|
+
kind: opts.kind.length ? opts.kind.join(',') : undefined,
|
|
63
|
+
factory: opts.factory ? '1' : undefined,
|
|
64
|
+
mine: opts.mine ? '1' : undefined,
|
|
65
|
+
limit: String(opts.limit),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
if (isMachineOutput()) {
|
|
69
|
+
output(res);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
output({ data: ticketRows(res.data ?? []), total: res.total }, LIST_COLUMNS);
|
|
73
|
+
});
|
|
74
|
+
tracker
|
|
75
|
+
.command('show <ticket>')
|
|
76
|
+
.alias('get')
|
|
77
|
+
.description('Show a ticket (#12 or its id) with Factory\'s run and the feed: findings, facts, Patrol results, approvals')
|
|
78
|
+
.option('--project <id>', 'Project ID (for a ticket number)')
|
|
79
|
+
.option('--org <id>', 'Organization ID')
|
|
80
|
+
.action(async (ticket, opts) => {
|
|
81
|
+
const { apiClient } = await import('../../client/api.js');
|
|
82
|
+
const { isMachineOutput, formatJson } = await import('../../output/format.js');
|
|
83
|
+
const { renderTicket } = await import('./render.js');
|
|
84
|
+
const { readAuth } = await import('../../config/paths.js');
|
|
85
|
+
const { path, query } = await ticketPath(ticket, opts);
|
|
86
|
+
// GET /api/dashboard/tracker/items/:ref → { data: { item, comments, run, gates, patrol } }
|
|
87
|
+
const res = await apiClient().get(path, { query });
|
|
88
|
+
if (isMachineOutput()) {
|
|
89
|
+
console.log(formatJson(res.data));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
console.log(renderTicket(res.data, undefined, readAuth()?.user_id));
|
|
93
|
+
});
|
|
94
|
+
tracker
|
|
95
|
+
.command('create <title...>')
|
|
96
|
+
.alias('new')
|
|
97
|
+
.description('Open a ticket in the current project')
|
|
98
|
+
.option('--kind <kind>', 'issue, feature or task', 'issue')
|
|
99
|
+
.option('--body <text>', 'Description')
|
|
100
|
+
.option('--file <path>', 'Read the description from a file ("-" for stdin)')
|
|
101
|
+
.option('--priority <priority>', 'urgent, high, medium, low or none', 'none')
|
|
102
|
+
.option('--label <label>', 'Label (comma-separated or repeated)', collect, [])
|
|
103
|
+
.option('--backlog', 'Open it in the backlog instead of To do')
|
|
104
|
+
.option('--project <id>', 'Project ID')
|
|
105
|
+
.option('--org <id>', 'Organization ID')
|
|
106
|
+
.action(async (titleWords, opts) => {
|
|
107
|
+
const { apiClient } = await import('../../client/api.js');
|
|
108
|
+
const { requireContext } = await import('../../config/context.js');
|
|
109
|
+
const { isMachineOutput, formatJson } = await import('../../output/format.js');
|
|
110
|
+
const { success, hint } = await import('../../output/log.js');
|
|
111
|
+
const ctx = requireContext(opts);
|
|
112
|
+
const body = opts.file ? await textFrom(undefined, opts.file) : opts.body;
|
|
113
|
+
// POST /api/dashboard/tracker/items → { data: { created, id, number, reason? } }
|
|
114
|
+
const res = await apiClient().post('/api/dashboard/tracker/items', {
|
|
115
|
+
body: {
|
|
116
|
+
project_id: ctx.project_id,
|
|
117
|
+
title: titleWords.join(' '),
|
|
118
|
+
kind: opts.kind,
|
|
119
|
+
body,
|
|
120
|
+
priority: opts.priority,
|
|
121
|
+
labels: opts.label,
|
|
122
|
+
status: opts.backlog ? 'backlog' : 'todo',
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
const made = verdict(res, 'created', 'The ticket was not opened.');
|
|
126
|
+
if (isMachineOutput()) {
|
|
127
|
+
console.log(formatJson(made));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
success(`Opened #${made.number}`);
|
|
131
|
+
hint([`Run \`sitepong tracker show ${made.number}\` to see it`, `Run \`sitepong tracker send ${made.number} --start\` to hand it to Factory`]);
|
|
132
|
+
});
|
|
133
|
+
tracker
|
|
134
|
+
.command('comment <ticket> [text...]')
|
|
135
|
+
.description('Add a comment to a ticket\'s thread ("-" reads stdin). Answering Factory\'s questions hands the turn back to it.')
|
|
136
|
+
.option('--file <path>', 'Read the comment from a file ("-" for stdin)')
|
|
137
|
+
.option('--project <id>', 'Project ID (for a ticket number)')
|
|
138
|
+
.option('--org <id>', 'Organization ID')
|
|
139
|
+
.action(async (ticket, words, opts) => {
|
|
140
|
+
const { apiClient } = await import('../../client/api.js');
|
|
141
|
+
const { isMachineOutput, formatJson } = await import('../../output/format.js');
|
|
142
|
+
const { success, status } = await import('../../output/log.js');
|
|
143
|
+
const text = (await textFrom(words, opts.file)).trim();
|
|
144
|
+
if (!text)
|
|
145
|
+
throw new Error('Say something: pass the comment as words, --file, or "-" for stdin.');
|
|
146
|
+
const { path, query } = await ticketPath(ticket, opts);
|
|
147
|
+
// POST /api/dashboard/tracker/items/:ref { action: 'comment' } → { data: { commented, id, spec_turn } }
|
|
148
|
+
const res = await apiClient().post(path, { query, body: { action: 'comment', body: text } });
|
|
149
|
+
const done = verdict(res, 'commented', 'The comment was not added.');
|
|
150
|
+
if (isMachineOutput()) {
|
|
151
|
+
console.log(formatJson(done));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const { ticketLabel } = await import('./render.js');
|
|
155
|
+
success(`Commented on ${ticketLabel(ticket)}`);
|
|
156
|
+
if (done.spec_turn)
|
|
157
|
+
status('Factory has its turn on the spec again.');
|
|
158
|
+
});
|
|
159
|
+
tracker
|
|
160
|
+
.command('send <ticket>')
|
|
161
|
+
.description('Send a ticket to Factory (a feature needs an approved spec). --start starts it now, within max active runs.')
|
|
162
|
+
.option('--start', 'Start work now instead of waiting for a person or the work mode')
|
|
163
|
+
.option('--project <id>', 'Project ID (for a ticket number)')
|
|
164
|
+
.option('--org <id>', 'Organization ID')
|
|
165
|
+
.action(async (ticket, opts) => {
|
|
166
|
+
const { apiClient } = await import('../../client/api.js');
|
|
167
|
+
const { isMachineOutput, formatJson } = await import('../../output/format.js');
|
|
168
|
+
const { success, warn, hint } = await import('../../output/log.js');
|
|
169
|
+
const { path, query } = await ticketPath(ticket, opts);
|
|
170
|
+
// POST /api/dashboard/tracker/items/:ref { action: 'send', start } → { data: { built, run_id, started, reason? } }
|
|
171
|
+
const res = await apiClient().post(path, {
|
|
172
|
+
query,
|
|
173
|
+
body: { action: 'send', start: !!opts.start },
|
|
174
|
+
});
|
|
175
|
+
const d = res.data ?? {};
|
|
176
|
+
let result;
|
|
177
|
+
if (d.built) {
|
|
178
|
+
result = { run_id: d.run_id, started: !!d.started, reason: d.reason, already: false };
|
|
179
|
+
}
|
|
180
|
+
else if (d.run_id) {
|
|
181
|
+
// Factory already has it. With --start, start the ticket it already has.
|
|
182
|
+
result = { run_id: d.run_id, started: false, reason: d.reason, already: true };
|
|
183
|
+
if (opts.start) {
|
|
184
|
+
// POST /api/dashboard/factory/runs/:runId { action: 'start' } → { data: { started, reason? } }
|
|
185
|
+
const s = await apiClient().post(`/api/dashboard/factory/runs/${encodeURIComponent(d.run_id)}`, { body: { action: 'start' } });
|
|
186
|
+
result.started = !!s.data?.started;
|
|
187
|
+
result.reason = s.data?.reason ?? result.reason;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
throw new Error(d.reason ?? 'Factory did not take this ticket.');
|
|
192
|
+
}
|
|
193
|
+
if (isMachineOutput()) {
|
|
194
|
+
console.log(formatJson(result));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (result.already && !opts.start)
|
|
198
|
+
warn('Factory already has this ticket.');
|
|
199
|
+
else if (!result.already)
|
|
200
|
+
success('Sent to Factory');
|
|
201
|
+
if (opts.start) {
|
|
202
|
+
if (result.started)
|
|
203
|
+
success('Started');
|
|
204
|
+
else
|
|
205
|
+
warn(`Not started${result.reason ? `: ${result.reason}` : ''}`);
|
|
206
|
+
}
|
|
207
|
+
else if (!result.already) {
|
|
208
|
+
hint('It starts when a person starts it or the project\'s work mode does. Pass `--start` to start it now.');
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
tracker
|
|
212
|
+
.command('update <ticket>')
|
|
213
|
+
.description('Change a ticket: status, priority, kind, title, labels, assignee')
|
|
214
|
+
.option('--status <status>', 'backlog, todo, in_progress, in_review, done or cancelled')
|
|
215
|
+
.option('--priority <priority>', 'urgent, high, medium, low or none')
|
|
216
|
+
.option('--kind <kind>', 'issue, feature or task')
|
|
217
|
+
.option('--title <title>', 'New title')
|
|
218
|
+
.option('--label <label>', 'Replace the labels (comma-separated or repeated)', collect, [])
|
|
219
|
+
.option('--assign <who>', 'me, factory, none, or user:<id>')
|
|
220
|
+
.option('--project <id>', 'Project ID (for a ticket number)')
|
|
221
|
+
.option('--org <id>', 'Organization ID')
|
|
222
|
+
.action(async (ticket, opts) => {
|
|
223
|
+
const { apiClient } = await import('../../client/api.js');
|
|
224
|
+
const { isMachineOutput, formatJson } = await import('../../output/format.js');
|
|
225
|
+
const { success } = await import('../../output/log.js');
|
|
226
|
+
const { readAuth } = await import('../../config/paths.js');
|
|
227
|
+
const patch = {};
|
|
228
|
+
// "in review" and "in-review" read as in_review.
|
|
229
|
+
for (const k of ['status', 'priority', 'kind']) {
|
|
230
|
+
if (opts[k] !== undefined)
|
|
231
|
+
patch[k] = String(opts[k]).trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
232
|
+
}
|
|
233
|
+
if (opts.title !== undefined)
|
|
234
|
+
patch.title = String(opts.title).trim();
|
|
235
|
+
if (opts.label.length)
|
|
236
|
+
patch.labels = opts.label;
|
|
237
|
+
if (opts.assign !== undefined) {
|
|
238
|
+
const a = String(opts.assign).trim();
|
|
239
|
+
if (a === 'me') {
|
|
240
|
+
const me = readAuth()?.user_id;
|
|
241
|
+
if (!me)
|
|
242
|
+
throw new Error('Not logged in. Run `sitepong login`.');
|
|
243
|
+
patch.assignee = `user:${me}`;
|
|
244
|
+
}
|
|
245
|
+
else
|
|
246
|
+
patch.assignee = a === 'none' ? null : a;
|
|
247
|
+
}
|
|
248
|
+
if (!Object.keys(patch).length)
|
|
249
|
+
throw new Error('Nothing to change. Run `sitepong tracker update --help` for the options.');
|
|
250
|
+
const { path, query } = await ticketPath(ticket, opts);
|
|
251
|
+
// POST /api/dashboard/tracker/items/:ref { action: 'update', patch } → { data: { updated, reason? } }
|
|
252
|
+
const res = await apiClient().post(path, { query, body: { action: 'update', patch } });
|
|
253
|
+
const done = verdict(res, 'updated', 'The ticket was not changed.');
|
|
254
|
+
if (isMachineOutput()) {
|
|
255
|
+
console.log(formatJson(done));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const { ticketLabel } = await import('./render.js');
|
|
259
|
+
success(`Updated ${ticketLabel(ticket)}`);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=index.js.map
|