octwin-cli 0.7.3 → 0.8.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/CHANGELOG.md +44 -0
- package/README.md +12 -0
- package/dist/index.js +1163 -261
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
* octwin analytics [entity] [--funnel|--overview|--milestones|--trends|--cost] [--stage <id>] # stage conversion, any pipelined entity
|
|
29
29
|
* octwin catalog [--readiness] # commerce products + stock + the WhatsApp catalog binding (catalog:read)
|
|
30
30
|
* octwin scheduling [--slots <resourceRecordId>] # engine state / computed slots (scheduling:read)
|
|
31
|
+
* octwin automation [campaigns] # the jobs your declarations produced + health + last result (automation:read)
|
|
32
|
+
* octwin integrations [deliveries|events|preflight|test …] # declared vs configured, and the delivery log (integrations:read)
|
|
33
|
+
* octwin journeys [journeyId] [--funnel|--overview|--goals|--trends|--cost|--definition] # declared journeys, measured (journeys:read)
|
|
34
|
+
* octwin performance [--detail] # the project's business indicators (records:read — there is no performance scope)
|
|
35
|
+
* octwin usage # model calls, tokens and cost (any valid token; NOT Meta message billing)
|
|
31
36
|
* octwin platform-kb [pull] [--if-stale|--check] [--dir .] # the platform capability reference (no token needed)
|
|
32
37
|
* octwin test [--dir .] # = validate --remote (the full platform check)
|
|
33
38
|
*
|
|
@@ -216,6 +221,21 @@ const VERB_REQUIREMENTS = {
|
|
|
216
221
|
// which does NOT confer this — that 403 is otherwise baffling.
|
|
217
222
|
'projects create': { scope: 'projects:write' },
|
|
218
223
|
'projects rm': { scope: 'projects:write' },
|
|
224
|
+
// Jobs are declaration-derived, so there is no `create` — only acting on one.
|
|
225
|
+
// `campaigns` is absent on purpose: it is a READ sharing the verb slot, and an
|
|
226
|
+
// entry here would print "needs automation:write" on a read failure.
|
|
227
|
+
'automation run': { scope: 'automation:write' },
|
|
228
|
+
'automation pause': { scope: 'automation:write' },
|
|
229
|
+
'automation resume': { scope: 'automation:write' },
|
|
230
|
+
'automation send': { scope: 'automation:write' },
|
|
231
|
+
// `preflight` is the odd one: it is a diagnosis, so the route gates it on
|
|
232
|
+
// `view`, not `act`. Naming the READ scope here is what stops a 403 on it
|
|
233
|
+
// sending the author to mint a write token they do not need.
|
|
234
|
+
'integrations preflight': { scope: 'integrations:read' },
|
|
235
|
+
'integrations test': { scope: 'integrations:write' },
|
|
236
|
+
'integrations retry': { scope: 'integrations:write' },
|
|
237
|
+
'integrations cancel': { scope: 'integrations:write' },
|
|
238
|
+
'integrations send-now': { scope: 'integrations:write' },
|
|
219
239
|
};
|
|
220
240
|
const COMMAND_REQUIREMENTS = {
|
|
221
241
|
deploy: { scope: 'pack:deploy' },
|
|
@@ -250,6 +270,17 @@ const COMMAND_REQUIREMENTS = {
|
|
|
250
270
|
// hint names the scope a NON-deploy token would be missing — a `pack:deploy`
|
|
251
271
|
// holder never sees this line, because they never get the 403.
|
|
252
272
|
projects: { scope: 'projects:read' },
|
|
273
|
+
automation: { scope: 'automation:read' },
|
|
274
|
+
integrations: { scope: 'integrations:read' },
|
|
275
|
+
journeys: { scope: 'journeys:read' },
|
|
276
|
+
// `records:read`, not a `performance:*` scope — there is none. The indicators are
|
|
277
|
+
// derived from record + journey data, and the route is gated accordingly, so the
|
|
278
|
+
// Read-only token preset already reaches this.
|
|
279
|
+
performance: { scope: 'records:read' },
|
|
280
|
+
// `usage` is deliberately absent: its route is `requireTenantAccess` only, so any
|
|
281
|
+
// valid token reaches it. Declaring a requirement would print "needs the X scope"
|
|
282
|
+
// on a failure whose real cause is an unreachable instance — the same reasoning as
|
|
283
|
+
// `platform-kb` above.
|
|
253
284
|
};
|
|
254
285
|
/** The command currently running — set once in `main()` so any failure printer can
|
|
255
286
|
* name the scope that command needs without threading it through every call.
|
|
@@ -791,6 +822,11 @@ function commandTouchesPlatform(command, flags) {
|
|
|
791
822
|
case 'analytics':
|
|
792
823
|
case 'catalog':
|
|
793
824
|
case 'scheduling':
|
|
825
|
+
case 'automation':
|
|
826
|
+
case 'integrations':
|
|
827
|
+
case 'journeys':
|
|
828
|
+
case 'performance':
|
|
829
|
+
case 'usage':
|
|
794
830
|
case 'projects':
|
|
795
831
|
case 'seed': return true;
|
|
796
832
|
default: return false;
|
|
@@ -1464,13 +1500,13 @@ async function cmdSeed(flags) {
|
|
|
1464
1500
|
const { terminal: final, stepErrors } = await readDeployProgress(res.body);
|
|
1465
1501
|
if (!final || final.stage === 'error')
|
|
1466
1502
|
die(`seed failed${final?.message ? `: ${final.message}` : ' (stream ended early)'}`);
|
|
1467
|
-
console.log(`
|
|
1503
|
+
console.log(`
|
|
1468
1504
|
✓ ${final.message ?? 'seed complete'}`);
|
|
1469
1505
|
printSeedCounts(final.result?.seeded);
|
|
1470
1506
|
if (stepErrors.length) {
|
|
1471
1507
|
// A kind failed but the rest ran — the reconcile softens each step. Say which,
|
|
1472
1508
|
// and exit non-zero so a scripted `seed && chat` doesn't read as clean.
|
|
1473
|
-
console.error(`
|
|
1509
|
+
console.error(`
|
|
1474
1510
|
⚠ ${stepErrors.length} step${stepErrors.length === 1 ? '' : 's'} failed — data may be incomplete:`);
|
|
1475
1511
|
for (const e of stepErrors)
|
|
1476
1512
|
console.error(` • ${e}`);
|
|
@@ -1919,11 +1955,21 @@ async function apiGet(endpoint, t) {
|
|
|
1919
1955
|
* `content-type` + `authHeaders` block was inlined at each of the four original
|
|
1920
1956
|
* write sites, and fifteen more copies is how one of them ends up subtly different.
|
|
1921
1957
|
* A `204` (media delete) has no body to parse, hence the empty-text guard.
|
|
1958
|
+
*
|
|
1959
|
+
* `body: undefined` sends NO `content-type` either. The header used to be
|
|
1960
|
+
* unconditional, so a genuinely body-less write announced `application/json` and
|
|
1961
|
+
* then sent nothing — Fastify tried to parse the empty body and answered a bare
|
|
1962
|
+
* `400 Bad Request` with no hint of the cause. Latent until 2026-08-27 because every
|
|
1963
|
+
* caller until then passed an object; the first body-less POST (`automation run`)
|
|
1964
|
+
* hit it immediately, and a caller having to know "pass `{}` or you get a 400" is
|
|
1965
|
+
* exactly the per-site divergence this helper exists to prevent.
|
|
1922
1966
|
*/
|
|
1923
1967
|
async function apiSend(method, endpoint, body, t) {
|
|
1924
1968
|
const res = await fetchOrDie(endpoint, {
|
|
1925
1969
|
method,
|
|
1926
|
-
headers:
|
|
1970
|
+
headers: body === undefined
|
|
1971
|
+
? authHeaders(t)
|
|
1972
|
+
: { 'content-type': 'application/json', ...authHeaders(t) },
|
|
1927
1973
|
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
1928
1974
|
}, 'request');
|
|
1929
1975
|
const text = await res.text();
|
|
@@ -3364,7 +3410,9 @@ async function cmdAgents(flags) {
|
|
|
3364
3410
|
return;
|
|
3365
3411
|
}
|
|
3366
3412
|
if (!ref) {
|
|
3367
|
-
|
|
3413
|
+
// Template literal, not bare `base` — see the note in `cmdScheduling`: the route
|
|
3414
|
+
// guard's extractor cannot read a bare identifier, so this URL was exempt.
|
|
3415
|
+
const { status, json } = await apiGet(`${base}`, t);
|
|
3368
3416
|
if (status !== 200)
|
|
3369
3417
|
die(`could not read agents (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
3370
3418
|
if (asJson) {
|
|
@@ -3998,7 +4046,9 @@ async function cmdScheduling(flags) {
|
|
|
3998
4046
|
}
|
|
3999
4047
|
if (!asJson)
|
|
4000
4048
|
console.log(`→ Reading the scheduling engine state from ${targetLabel(t)} …`);
|
|
4001
|
-
|
|
4049
|
+
// A template literal, not the bare `base` — `cli-routes.test.ts` cannot read a
|
|
4050
|
+
// bare identifier, so this URL was silently exempt from the route guard.
|
|
4051
|
+
const { status, json } = await apiGet(`${base}`, t);
|
|
4002
4052
|
if (status !== 200)
|
|
4003
4053
|
die(`could not read scheduling (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4004
4054
|
if (asJson) {
|
|
@@ -4016,290 +4066,1127 @@ async function cmdScheduling(flags) {
|
|
|
4016
4066
|
console.log(` upcoming slots: ${json?.upcoming_slots ?? 0} booked seats: ${json?.booked_seats ?? 0}`);
|
|
4017
4067
|
console.log('\nSlots for one resource: octwin scheduling --slots <resourceRecordId> (ids: octwin records <entity>)');
|
|
4018
4068
|
}
|
|
4069
|
+
// ── automation: declaration-derived jobs + campaigns ─────────────────────────
|
|
4070
|
+
/**
|
|
4071
|
+
* Verbs that mean "act on a job", not "an id".
|
|
4072
|
+
*
|
|
4073
|
+
* `pause` / `resume` rather than a literal `status active|paused`: the route body
|
|
4074
|
+
* takes the status, but the RBAC layer it calls checks the ACTION
|
|
4075
|
+
* (`assertCan(…, action: 'pause' | 'resume')`), and `VERB_REQUIREMENTS` is keyed
|
|
4076
|
+
* per verb — so one verb per intent makes both the permission hint and the 403
|
|
4077
|
+
* say the right thing.
|
|
4078
|
+
*/
|
|
4079
|
+
const AUTOMATION_VERBS = new Set(['run', 'pause', 'resume', 'campaigns', 'send']);
|
|
4080
|
+
/**
|
|
4081
|
+
* Turn whatever the author typed into the UUID the route demands.
|
|
4082
|
+
*
|
|
4083
|
+
* (`UUID_RE` is the one already declared for `--media`, deliberately reused rather
|
|
4084
|
+
* than a second copy of the same pattern.)
|
|
4085
|
+
*
|
|
4086
|
+
* The write routes take a UUID path param and reject anything else with a bare
|
|
4087
|
+
* *"Malformed identifier in the URL — expected a UUID"* 400. But the thing an author
|
|
4088
|
+
* has in front of them is the declaration KEY (`cart_recovery_nudge`) — that is what
|
|
4089
|
+
* the list prints, and it is the name in their own YAML. Measured: passing the key
|
|
4090
|
+
* 400s on all three write verbs.
|
|
4091
|
+
*
|
|
4092
|
+
* So the key is resolved here, against the list route, rather than documented as a
|
|
4093
|
+
* gotcha. A UUID passes straight through, and an unknown key fails naming the keys
|
|
4094
|
+
* that DO exist — which is the answer to the question the author is actually asking.
|
|
4095
|
+
*/
|
|
4096
|
+
async function resolveAutomationId(kind, typed, base, t) {
|
|
4097
|
+
if (UUID_RE.test(typed))
|
|
4098
|
+
return typed;
|
|
4099
|
+
const { status, json } = await apiGet(`${base}/${kind}`, t);
|
|
4100
|
+
if (status !== 200) {
|
|
4101
|
+
die(`could not resolve '${typed}' — reading ${kind} failed (HTTP ${status})${errDetail(json)}`);
|
|
4102
|
+
}
|
|
4103
|
+
const rows = readPage(json).rows;
|
|
4104
|
+
const hit = rows.find(r => r.key === typed || r.id === typed);
|
|
4105
|
+
if (hit?.id)
|
|
4106
|
+
return hit.id;
|
|
4107
|
+
const keys = rows.map(r => r.key ?? r.id).filter(Boolean);
|
|
4108
|
+
die(`no ${kind === 'jobs' ? 'job' : 'campaign'} '${typed}' in this project.`
|
|
4109
|
+
+ (keys.length ? ` Available: ${keys.join(', ')}` : ` This project declares none.`));
|
|
4110
|
+
}
|
|
4111
|
+
/** `pause`/`resume`/`run`/`send` — the writes behind `octwin automation`. */
|
|
4112
|
+
async function cmdAutomationWrite(flags) {
|
|
4113
|
+
const t = resolveTarget(flags);
|
|
4114
|
+
const { url } = t;
|
|
4115
|
+
const base = `${url}/api/self/p/automation`;
|
|
4116
|
+
const verb = flags._[0];
|
|
4117
|
+
const typed = flags._[1];
|
|
4118
|
+
const asJson = flags.json === true;
|
|
4119
|
+
if (!typed)
|
|
4120
|
+
die(`usage: octwin automation ${verb} <${verb === 'send' ? 'campaignId' : 'jobId'}> (ids: octwin automation${verb === 'send' ? ' campaigns' : ''})`);
|
|
4121
|
+
const id = await resolveAutomationId(verb === 'send' ? 'campaigns' : 'jobs', typed, base, t);
|
|
4122
|
+
if (verb === 'pause' || verb === 'resume') {
|
|
4123
|
+
const { status, json } = await apiSend('PATCH', `${base}/jobs/${encodeURIComponent(id)}/status`, { status: verb === 'pause' ? 'paused' : 'active' }, t);
|
|
4124
|
+
if (status === 404)
|
|
4125
|
+
die(`job '${typed}' not found in ${targetLabel(t)} (ids: octwin automation)`);
|
|
4126
|
+
// RBAC re-checks the ACTION on the job, so a 403 here can be a grant gap
|
|
4127
|
+
// rather than a missing scope — same caveat as a record write.
|
|
4128
|
+
if (status !== 200)
|
|
4129
|
+
writeFail(`${verb} job '${typed}'`, status, json, url, true);
|
|
4130
|
+
if (asJson) {
|
|
4131
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4132
|
+
return;
|
|
4133
|
+
}
|
|
4134
|
+
const j = json?.job ?? {};
|
|
4135
|
+
console.log(`✓ job '${j.key ?? typed}' is now ${j.status}`);
|
|
4136
|
+
if (j.next_run_at)
|
|
4137
|
+
console.log(` next run: ${j.next_run_at}`);
|
|
4138
|
+
return;
|
|
4139
|
+
}
|
|
4140
|
+
if (verb === 'run') {
|
|
4141
|
+
if (!asJson)
|
|
4142
|
+
console.log(`→ Running job '${typed}' in ${targetLabel(t)} …`);
|
|
4143
|
+
const { status, json } = await apiSend('POST', `${base}/jobs/${encodeURIComponent(id)}/run`, undefined, t);
|
|
4144
|
+
if (status === 404)
|
|
4145
|
+
die(`job '${typed}' not found in ${targetLabel(t)} (ids: octwin automation)`);
|
|
4146
|
+
if (status !== 200)
|
|
4147
|
+
writeFail(`run job '${typed}'`, status, json, url, true);
|
|
4148
|
+
if (asJson) {
|
|
4149
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4150
|
+
return;
|
|
4151
|
+
}
|
|
4152
|
+
const r = json?.result ?? {};
|
|
4153
|
+
console.log(`✓ ran '${typed}': matched ${r.matched ?? 0}, acted ${r.acted ?? 0}, errors ${r.errors ?? 0}`);
|
|
4154
|
+
// `acted < matched` is the route's own definition of a PARTIAL run, so say so
|
|
4155
|
+
// rather than leaving three numbers for the author to compare.
|
|
4156
|
+
if ((r.errors ?? 0) > 0)
|
|
4157
|
+
console.log(' ⚠ some rows errored — see the job\'s last_result in `octwin automation`');
|
|
4158
|
+
else if ((r.acted ?? 0) < (r.matched ?? 0))
|
|
4159
|
+
console.log(' partial: matched rows were skipped (cooldown, or already acted on)');
|
|
4160
|
+
return;
|
|
4161
|
+
}
|
|
4162
|
+
// send — one campaign
|
|
4163
|
+
if (!asJson)
|
|
4164
|
+
console.log(`→ Sending campaign '${typed}' in ${targetLabel(t)} …`);
|
|
4165
|
+
const { status, json } = await apiSend('POST', `${base}/campaigns/${encodeURIComponent(id)}/send`, undefined, t);
|
|
4166
|
+
if (status === 404)
|
|
4167
|
+
die(`campaign '${typed}' not found in ${targetLabel(t)} (ids: octwin automation campaigns)`);
|
|
4168
|
+
if (status !== 200)
|
|
4169
|
+
writeFail(`send campaign '${typed}'`, status, json, url, true);
|
|
4170
|
+
if (asJson) {
|
|
4171
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4172
|
+
return;
|
|
4173
|
+
}
|
|
4174
|
+
const r = json?.result ?? {};
|
|
4175
|
+
console.log(`✓ campaign '${typed}': matched ${r.matched ?? 0}, enqueued ${r.enqueued ?? 0}`);
|
|
4176
|
+
if ((r.enqueued ?? 0) < (r.matched ?? 0))
|
|
4177
|
+
console.log(' partial: some matched contacts were not enqueued (cooldown, or no reachable channel)');
|
|
4178
|
+
console.log(' enqueued ≠ delivered — watch the sends land with `octwin logs`');
|
|
4179
|
+
}
|
|
4180
|
+
/**
|
|
4181
|
+
* `octwin automation [--campaigns] [--json]` — the jobs a pack's declarations
|
|
4182
|
+
* produced, with their last result, plus the health counts.
|
|
4183
|
+
*
|
|
4184
|
+
* Needs `automation:read`. The job list is CAPPED server-side and the counts are
|
|
4185
|
+
* computed in SQL, so the header numbers come from `/health` rather than from
|
|
4186
|
+
* filtering the page — past the cap a client-side count would depend on the cap
|
|
4187
|
+
* instead of the data.
|
|
4188
|
+
*/
|
|
4189
|
+
async function cmdAutomation(flags) {
|
|
4190
|
+
if (typeof flags._[0] === 'string' && AUTOMATION_VERBS.has(flags._[0])) {
|
|
4191
|
+
// `campaigns` is a READ that shares the verb slot with the writes.
|
|
4192
|
+
if (flags._[0] !== 'campaigns')
|
|
4193
|
+
return cmdAutomationWrite(flags);
|
|
4194
|
+
}
|
|
4195
|
+
const t = resolveTarget(flags);
|
|
4196
|
+
const { url } = t;
|
|
4197
|
+
const base = `${url}/api/self/p/automation`;
|
|
4198
|
+
const asJson = flags.json === true;
|
|
4199
|
+
const campaigns = flags._[0] === 'campaigns' || flags.campaigns === true;
|
|
4200
|
+
if (campaigns) {
|
|
4201
|
+
if (!asJson)
|
|
4202
|
+
console.log(`→ Reading campaigns from ${targetLabel(t)} …`);
|
|
4203
|
+
const { status, json } = await apiGet(`${base}/campaigns?${pagingQs(flags)}`, t);
|
|
4204
|
+
if (status !== 200)
|
|
4205
|
+
die(`could not read campaigns (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4206
|
+
if (asJson) {
|
|
4207
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4208
|
+
return;
|
|
4209
|
+
}
|
|
4210
|
+
const page = readPage(json);
|
|
4211
|
+
console.log(`Campaigns in ${targetLabel(t)}: ${page.total ?? page.rows.length}`);
|
|
4212
|
+
if (page.rows.length === 0)
|
|
4213
|
+
console.log(' (none — a campaign comes from a `campaigns:` block in the pack\'s automation declaration)');
|
|
4214
|
+
for (const c of page.rows) {
|
|
4215
|
+
const label = pickLabel(c.label) ?? c.key ?? c.id;
|
|
4216
|
+
console.log(` ${String(label).padEnd(28)} ${String(c.audience_size ?? c.matched ?? '—').padStart(6)} contact(s) ${c.key ?? c.id}`);
|
|
4217
|
+
}
|
|
4218
|
+
const more = morePageHint(page, 'octwin automation campaigns');
|
|
4219
|
+
if (more)
|
|
4220
|
+
console.log(more);
|
|
4221
|
+
console.log('\nSend one: octwin automation send <campaignId> (needs automation:write)');
|
|
4222
|
+
return;
|
|
4223
|
+
}
|
|
4224
|
+
if (!asJson)
|
|
4225
|
+
console.log(`→ Reading automation jobs from ${targetLabel(t)} …`);
|
|
4226
|
+
const [jobs, health] = await Promise.all([
|
|
4227
|
+
apiGet(`${base}/jobs`, t),
|
|
4228
|
+
apiGet(`${base}/health`, t),
|
|
4229
|
+
]);
|
|
4230
|
+
if (jobs.status !== 200)
|
|
4231
|
+
die(`could not read automation jobs (HTTP ${jobs.status})${errDetail(jobs.json)}${authFailureDetail(jobs.status, url)}`);
|
|
4232
|
+
if (asJson) {
|
|
4233
|
+
console.log(JSON.stringify({ jobs: jobs.json, health: health.json }, null, 2));
|
|
4234
|
+
return;
|
|
4235
|
+
}
|
|
4236
|
+
const page = readPage(jobs.json);
|
|
4237
|
+
const h = health.status === 200 ? (health.json ?? {}) : {};
|
|
4238
|
+
console.log(`Automation in ${targetLabel(t)}: ${h.total ?? page.rows.length} job(s)`
|
|
4239
|
+
+ ` — ${h.active ?? '?'} active, ${h.paused ?? '?'} paused, ${h.failing ?? '?'} failing, ${h.never_ran ?? '?'} never ran`);
|
|
4240
|
+
if (page.rows.length === 0) {
|
|
4241
|
+
console.log(' (none — jobs are DERIVED from the pack\'s automation declaration, not created here.');
|
|
4242
|
+
console.log(' No `automation.yaml` block → no jobs. `octwin deploy` installs them.)');
|
|
4243
|
+
return;
|
|
4244
|
+
}
|
|
4245
|
+
for (const j of page.rows) {
|
|
4246
|
+
const r = j.last_result ?? {};
|
|
4247
|
+
const ran = j.last_run_at ? `last ${j.last_run_at}` : 'never ran';
|
|
4248
|
+
const result = j.last_result
|
|
4249
|
+
? ` matched ${r.matched ?? 0}/acted ${r.acted ?? 0}${(r.errors ?? 0) > 0 ? `/ERRORS ${r.errors}` : ''}`
|
|
4250
|
+
: '';
|
|
4251
|
+
console.log(` ${String(j.key ?? j.id).padEnd(26)} ${String(j.status).padEnd(7)} ${j.kind}/${j.entity ?? '—'}`
|
|
4252
|
+
+ ` every ${j.interval_seconds}s ${ran}${result}`);
|
|
4253
|
+
}
|
|
4254
|
+
console.log('\nRun one now: octwin automation run <jobId> (jobId = the `key` above, or its uuid)');
|
|
4255
|
+
console.log('Pause/resume: octwin automation pause|resume <jobId>');
|
|
4256
|
+
console.log('Campaigns: octwin automation campaigns');
|
|
4257
|
+
}
|
|
4258
|
+
// ── integrations: declared connections, their credentials, and the delivery log ──
|
|
4259
|
+
/** Verbs that act on a connection or a delivery, rather than naming one. */
|
|
4260
|
+
const INTEGRATION_VERBS = new Set(['test', 'preflight', 'deliveries', 'retry', 'cancel', 'send-now', 'events']);
|
|
4261
|
+
/** The three delivery actions — each its own verb so the scope hint can differ. */
|
|
4262
|
+
const DELIVERY_ACTIONS = {
|
|
4263
|
+
'retry': { path: 'retry', what: 'retry' },
|
|
4264
|
+
'cancel': { path: 'cancel', what: 'cancel' },
|
|
4265
|
+
'send-now': { path: 'send-now', what: 'send' },
|
|
4266
|
+
};
|
|
4267
|
+
/** `octwin integrations <verb> …` — the connection + delivery verbs. */
|
|
4268
|
+
async function cmdIntegrationsVerb(flags) {
|
|
4269
|
+
const t = resolveTarget(flags);
|
|
4270
|
+
const { url } = t;
|
|
4271
|
+
const base = `${url}/api/self/p/integrations`;
|
|
4272
|
+
const verb = flags._[0];
|
|
4273
|
+
const arg = flags._[1];
|
|
4274
|
+
const asJson = flags.json === true;
|
|
4275
|
+
// ── deliveries: the outbound log ──────────────────────────────────────────
|
|
4276
|
+
if (verb === 'deliveries') {
|
|
4277
|
+
if (arg) {
|
|
4278
|
+
const { status, json } = await apiGet(`${base}/deliveries/${encodeURIComponent(arg)}`, t);
|
|
4279
|
+
if (status === 404)
|
|
4280
|
+
die(`delivery '${arg}' not found`);
|
|
4281
|
+
if (status !== 200)
|
|
4282
|
+
die(`could not read delivery (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4283
|
+
if (asJson) {
|
|
4284
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4285
|
+
return;
|
|
4286
|
+
}
|
|
4287
|
+
const d = json?.delivery ?? {};
|
|
4288
|
+
console.log(`Delivery ${d.id} ${d.status} ${d.connection_key}/${d.operation_id}`);
|
|
4289
|
+
console.log(` attempts ${d.attempts}${d.http_status ? ` HTTP ${d.http_status}` : ''}${d.port ? ` port: ${d.port}` : ''}`);
|
|
4290
|
+
if (d.last_error)
|
|
4291
|
+
console.log(` last error: ${d.last_error}`);
|
|
4292
|
+
if (d.next_attempt_at)
|
|
4293
|
+
console.log(` next attempt: ${d.next_attempt_at}`);
|
|
4294
|
+
console.log(` from ${d.source_kind ?? '—'}${d.source_hook ? ` (${d.source_hook})` : ''}${d.source_record_id ? ` record ${d.source_record_id}` : ''}`);
|
|
4295
|
+
// The snapshots are redacted at WRITE time, which is why the detail view may print them.
|
|
4296
|
+
if (d.request)
|
|
4297
|
+
console.log(` request: ${JSON.stringify(d.request)}`);
|
|
4298
|
+
if (d.response)
|
|
4299
|
+
console.log(` response: ${JSON.stringify(d.response)}`);
|
|
4300
|
+
return;
|
|
4301
|
+
}
|
|
4302
|
+
const q = new URLSearchParams(pagingQs(flags));
|
|
4303
|
+
if (typeof flags.status === 'string')
|
|
4304
|
+
q.set('status', flags.status);
|
|
4305
|
+
if (typeof flags.operation === 'string')
|
|
4306
|
+
q.set('operation', flags.operation);
|
|
4307
|
+
if (!asJson)
|
|
4308
|
+
console.log(`→ Reading the delivery log from ${targetLabel(t)} …`);
|
|
4309
|
+
const { status, json } = await apiGet(`${base}/deliveries?${q.toString()}`, t);
|
|
4310
|
+
if (status !== 200)
|
|
4311
|
+
die(`could not read deliveries (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4312
|
+
if (asJson) {
|
|
4313
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4314
|
+
return;
|
|
4315
|
+
}
|
|
4316
|
+
const page = readPage(json);
|
|
4317
|
+
const c = json?.counts;
|
|
4318
|
+
console.log(`Deliveries in ${targetLabel(t)}: ${page.total ?? page.rows.length}`
|
|
4319
|
+
+ (c ? ` — queued ${c.queued ?? 0}, sent ${c.sent ?? 0}, failed ${c.failed ?? 0}, cancelled ${c.cancelled ?? 0}` : ''));
|
|
4320
|
+
if (page.rows.length === 0)
|
|
4321
|
+
console.log(' (none — a delivery is produced by an `integrations:` operation firing on a record hook)');
|
|
4322
|
+
for (const d of page.rows) {
|
|
4323
|
+
const err = d.last_error ? ` ${String(d.last_error).slice(0, 60)}` : '';
|
|
4324
|
+
console.log(` ${String(d.status).padEnd(9)} ${String(d.connection_key ?? '—').padEnd(16)} ${String(d.operation_id ?? '—').padEnd(20)}`
|
|
4325
|
+
+ ` try ${d.attempts}${d.http_status ? ` HTTP ${d.http_status}` : ''} ${d.id}${err}`);
|
|
4326
|
+
}
|
|
4327
|
+
const more = morePageHint(page, 'octwin integrations deliveries');
|
|
4328
|
+
if (more)
|
|
4329
|
+
console.log(more);
|
|
4330
|
+
console.log('\nOne delivery + its request/response: octwin integrations deliveries <id>');
|
|
4331
|
+
console.log('Act on one: octwin integrations retry|cancel|send-now <id>');
|
|
4332
|
+
return;
|
|
4333
|
+
}
|
|
4334
|
+
// ── inbound events ────────────────────────────────────────────────────────
|
|
4335
|
+
if (verb === 'events') {
|
|
4336
|
+
if (!asJson)
|
|
4337
|
+
console.log(`→ Reading inbound integration events from ${targetLabel(t)} …`);
|
|
4338
|
+
const { status, json } = await apiGet(`${base}/inbound-events?${pagingQs(flags)}`, t);
|
|
4339
|
+
if (status !== 200)
|
|
4340
|
+
die(`could not read inbound events (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4341
|
+
if (asJson) {
|
|
4342
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4343
|
+
return;
|
|
4344
|
+
}
|
|
4345
|
+
const events = (json?.events ?? readPage(json).rows);
|
|
4346
|
+
console.log(`Inbound events in ${targetLabel(t)}: ${events.length}`);
|
|
4347
|
+
if (events.length === 0)
|
|
4348
|
+
console.log(' (none — an inbound event arrives at POST /api/integrations/<tenant>/<project>/<inboundKey>)');
|
|
4349
|
+
for (const e of events) {
|
|
4350
|
+
console.log(` ${e.received_at ?? e.created_at ?? '—'} ${e.inbound_key ?? '—'} ${e.status ?? e.outcome ?? '—'}${e.detail ? ` ${e.detail}` : ''}`);
|
|
4351
|
+
}
|
|
4352
|
+
return;
|
|
4353
|
+
}
|
|
4354
|
+
// ── a delivery action ─────────────────────────────────────────────────────
|
|
4355
|
+
const action = DELIVERY_ACTIONS[verb];
|
|
4356
|
+
if (action) {
|
|
4357
|
+
if (!arg)
|
|
4358
|
+
die(`usage: octwin integrations ${verb} <deliveryId> (ids: octwin integrations deliveries)`);
|
|
4359
|
+
const { status, json } = await apiSend('POST', `${base}/deliveries/${encodeURIComponent(arg)}/${action.path}`, undefined, t);
|
|
4360
|
+
// 409 is the route's own "wrong state" answer, and it carries the rule — print
|
|
4361
|
+
// it rather than a generic failure, because the fix is choosing another delivery.
|
|
4362
|
+
if (status === 409)
|
|
4363
|
+
die(`cannot ${action.what} delivery '${arg}'${errDetail(json)}`);
|
|
4364
|
+
if (status === 404)
|
|
4365
|
+
die(`delivery '${arg}' not found`);
|
|
4366
|
+
if (status !== 200)
|
|
4367
|
+
writeFail(`${action.what} delivery '${arg}'`, status, json, url);
|
|
4368
|
+
if (asJson) {
|
|
4369
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4370
|
+
return;
|
|
4371
|
+
}
|
|
4372
|
+
const d = json?.delivery ?? {};
|
|
4373
|
+
console.log(`✓ delivery ${d.id ?? arg} is now ${d.status}${d.next_attempt_at ? ` (next attempt ${d.next_attempt_at})` : ''}`);
|
|
4374
|
+
return;
|
|
4375
|
+
}
|
|
4376
|
+
// ── preflight / test on one connection ────────────────────────────────────
|
|
4377
|
+
if (!arg)
|
|
4378
|
+
die(`usage: octwin integrations ${verb} <connectionKey> (keys: octwin integrations)`);
|
|
4379
|
+
if (verb === 'preflight') {
|
|
4380
|
+
if (!asJson)
|
|
4381
|
+
console.log(`→ Preflighting connection '${arg}' in ${targetLabel(t)} …`);
|
|
4382
|
+
const { status, json } = await apiSend('POST', `${base}/connections/${encodeURIComponent(arg)}/preflight`, undefined, t);
|
|
4383
|
+
if (status !== 200)
|
|
4384
|
+
die(`could not preflight '${arg}' (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4385
|
+
if (asJson) {
|
|
4386
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4387
|
+
return;
|
|
4388
|
+
}
|
|
4389
|
+
const marks = { pass: '✓', fail: '✗', warn: '⚠', skipped: '–' };
|
|
4390
|
+
console.log(`Preflight '${json?.connection_key ?? arg}': ${json?.ok ? 'READY' : 'NOT READY'}`);
|
|
4391
|
+
for (const c of (json?.checks ?? [])) {
|
|
4392
|
+
console.log(` ${marks[c.status] ?? '?'} ${String(c.label).padEnd(30)} ${c.detail}`);
|
|
4393
|
+
if (c.fix)
|
|
4394
|
+
console.log(` fix: ${c.fix}`);
|
|
4395
|
+
}
|
|
4396
|
+
// Preflight is a DIAGNOSIS and needs only `integrations:read`; `test` makes a
|
|
4397
|
+
// live call and needs write. Worth saying, because the two read alike.
|
|
4398
|
+
if (!json?.ok)
|
|
4399
|
+
console.log('\nPreflight makes no live call. Once it is READY: octwin integrations test <key>');
|
|
4400
|
+
return;
|
|
4401
|
+
}
|
|
4402
|
+
// test — a live call against the connection's declared `health:` operation
|
|
4403
|
+
if (!asJson)
|
|
4404
|
+
console.log(`→ Testing connection '${arg}' against its health operation …`);
|
|
4405
|
+
const { status, json } = await apiSend('POST', `${base}/connections/${encodeURIComponent(arg)}/test`, undefined, t);
|
|
4406
|
+
if (status === 409)
|
|
4407
|
+
die(`no pack is installed on ${targetLabel(t)}${errDetail(json)}`);
|
|
4408
|
+
if (status === 404)
|
|
4409
|
+
die(`${errDetail(json).replace(/^ — /, '') || `connection '${arg}' is not declared by the installed pack`}`);
|
|
4410
|
+
// A 400 here is a real answer, not a usage error: the route returns
|
|
4411
|
+
// `{ ok:false, detail }` when the live call fails, and that detail IS the result.
|
|
4412
|
+
if (status === 400 && json && typeof json === 'object' && 'ok' in json) {
|
|
4413
|
+
if (asJson) {
|
|
4414
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4415
|
+
process.exitCode = 1;
|
|
4416
|
+
return;
|
|
4417
|
+
}
|
|
4418
|
+
console.log(`✗ '${arg}' failed: ${json.detail ?? '(no detail)'}`);
|
|
4419
|
+
console.log(' Diagnose without calling out: octwin integrations preflight ' + arg);
|
|
4420
|
+
process.exitCode = 1;
|
|
4421
|
+
return;
|
|
4422
|
+
}
|
|
4423
|
+
if (status !== 200)
|
|
4424
|
+
writeFail(`test connection '${arg}'`, status, json, url);
|
|
4425
|
+
if (asJson) {
|
|
4426
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4427
|
+
return;
|
|
4428
|
+
}
|
|
4429
|
+
console.log(`${json?.ok ? '✓' : '✗'} '${arg}': ${json?.detail ?? '(no detail)'}`);
|
|
4430
|
+
if (json?.http_status)
|
|
4431
|
+
console.log(` HTTP ${json.http_status} port: ${json.port ?? '—'}`);
|
|
4432
|
+
if (json?.data !== undefined && json?.data !== null)
|
|
4433
|
+
console.log(` data: ${JSON.stringify(json.data).slice(0, 300)}`);
|
|
4434
|
+
if (!json?.ok)
|
|
4435
|
+
process.exitCode = 1;
|
|
4436
|
+
}
|
|
4437
|
+
/**
|
|
4438
|
+
* `octwin integrations [--json]` — what the pack DECLARES beside what is actually
|
|
4439
|
+
* configured, in one view.
|
|
4440
|
+
*
|
|
4441
|
+
* Needs `integrations:read`. The two halves are deliberately joined: a declared
|
|
4442
|
+
* connection with no configured row is the single most common reason an
|
|
4443
|
+
* integration silently never fires, and reading either list alone cannot show it.
|
|
4444
|
+
*/
|
|
4445
|
+
async function cmdIntegrations(flags) {
|
|
4446
|
+
if (typeof flags._[0] === 'string' && INTEGRATION_VERBS.has(flags._[0]))
|
|
4447
|
+
return cmdIntegrationsVerb(flags);
|
|
4448
|
+
const t = resolveTarget(flags);
|
|
4449
|
+
const { url } = t;
|
|
4450
|
+
const base = `${url}/api/self/p/integrations`;
|
|
4451
|
+
const asJson = flags.json === true;
|
|
4452
|
+
if (!asJson)
|
|
4453
|
+
console.log(`→ Reading integrations from ${targetLabel(t)} …`);
|
|
4454
|
+
const [declared, configured] = await Promise.all([
|
|
4455
|
+
apiGet(`${base}/declared`, t),
|
|
4456
|
+
apiGet(`${base}/connections`, t),
|
|
4457
|
+
]);
|
|
4458
|
+
if (declared.status !== 200)
|
|
4459
|
+
die(`could not read declared integrations (HTTP ${declared.status})${errDetail(declared.json)}${authFailureDetail(declared.status, url)}`);
|
|
4460
|
+
if (asJson) {
|
|
4461
|
+
console.log(JSON.stringify({ declared: declared.json, configured: configured.json }, null, 2));
|
|
4462
|
+
return;
|
|
4463
|
+
}
|
|
4464
|
+
const d = declared.json ?? {};
|
|
4465
|
+
const rows = (configured.status === 200 ? (configured.json?.connections ?? []) : []);
|
|
4466
|
+
const byKey = new Map(rows.map(r => [r.connection_key, r]));
|
|
4467
|
+
const conns = (d.connections ?? []);
|
|
4468
|
+
if (!d.pack_id) {
|
|
4469
|
+
console.log('No pack is installed on this project — nothing declares an integration.');
|
|
4470
|
+
return;
|
|
4471
|
+
}
|
|
4472
|
+
if (conns.length === 0 && (d.operations ?? []).length === 0 && (d.inbound ?? []).length === 0) {
|
|
4473
|
+
console.log(`Pack '${d.pack_id}' declares no integrations — no \`integrations.yaml\`.`);
|
|
4474
|
+
return;
|
|
4475
|
+
}
|
|
4476
|
+
console.log(`Integrations declared by '${d.pack_id}':`);
|
|
4477
|
+
for (const c of conns) {
|
|
4478
|
+
const row = byKey.get(c.key);
|
|
4479
|
+
const state = !row
|
|
4480
|
+
? 'NOT CONFIGURED'
|
|
4481
|
+
: row.status !== 'active'
|
|
4482
|
+
? row.status
|
|
4483
|
+
: row.has_credential ? `ready (…${row.credential_hint ?? '••••'})` : 'no credential';
|
|
4484
|
+
const test = row?.last_test_at
|
|
4485
|
+
? ` last test ${row.last_test_ok ? 'ok' : 'FAILED'} ${row.last_test_at}`
|
|
4486
|
+
: '';
|
|
4487
|
+
console.log(` ${String(c.key).padEnd(20)} ${state.padEnd(22)} ${c.auth_kind} in ${c.auth_in}${test}`);
|
|
4488
|
+
if (!row && c.setup_hint)
|
|
4489
|
+
console.log(` setup: ${c.setup_hint}`);
|
|
4490
|
+
if (row?.last_test_detail && row.last_test_ok === false)
|
|
4491
|
+
console.log(` ${row.last_test_detail}`);
|
|
4492
|
+
}
|
|
4493
|
+
const ops = (d.operations ?? []);
|
|
4494
|
+
if (ops.length) {
|
|
4495
|
+
console.log(`\n operations: ${ops.map(o => o.id ?? o.key).join(', ')}`);
|
|
4496
|
+
}
|
|
4497
|
+
const inbound = (d.inbound ?? []);
|
|
4498
|
+
if (inbound.length) {
|
|
4499
|
+
console.log(` inbound keys: ${inbound.map(i => i.key ?? i.id).join(', ')}`);
|
|
4500
|
+
}
|
|
4501
|
+
// A declared-but-unconfigured connection is the failure this view exists to make
|
|
4502
|
+
// visible, so it gets the next step rather than being left as a status word.
|
|
4503
|
+
const missing = conns.filter(c => !byKey.has(c.key)).map(c => c.key);
|
|
4504
|
+
if (missing.length) {
|
|
4505
|
+
console.log(`\n⚠ ${missing.length} connection(s) declared but never configured: ${missing.join(', ')}`);
|
|
4506
|
+
console.log(' Nothing using them will fire. Configure them in the console → Integrations,');
|
|
4507
|
+
console.log(` then: octwin integrations preflight ${missing[0]}`);
|
|
4508
|
+
}
|
|
4509
|
+
console.log('\nDiagnose one: octwin integrations preflight <key> Live call: octwin integrations test <key>');
|
|
4510
|
+
console.log('Outbound log: octwin integrations deliveries Inbound: octwin integrations events');
|
|
4511
|
+
}
|
|
4512
|
+
// ── journeys: the pack's declared customer journeys, measured ────────────────
|
|
4513
|
+
/**
|
|
4514
|
+
* The five journey analytics modes, plus `definition`.
|
|
4515
|
+
*
|
|
4516
|
+
* Deliberately the SAME flag grammar as `octwin analytics`
|
|
4517
|
+
* (`--funnel|--overview|--trends|--cost`) rather than a second shape for the same
|
|
4518
|
+
* idea — a journey funnel and an entity funnel are the same question asked of a
|
|
4519
|
+
* different subject. `goals` is the journey-only member (an entity has
|
|
4520
|
+
* milestones); `definition` prints what the pack declared, unmeasured.
|
|
4521
|
+
*/
|
|
4522
|
+
const JOURNEY_MODES = ['funnel', 'overview', 'goals', 'trends', 'cost', 'definition'];
|
|
4523
|
+
/** Both "no such journey" and "no `view` grant" answer 200 + `has_data:false` — a
|
|
4524
|
+
* deliberate empty state, never a 403 — so a bare "no data" would hide the cause. */
|
|
4525
|
+
function printNoJourneyData(journeyId) {
|
|
4526
|
+
console.log(`No data for journey '${journeyId}'. Either:`);
|
|
4527
|
+
console.log(` • the pack declares no journey with that id (list them: octwin journeys), or`);
|
|
4528
|
+
console.log(` • your token's role has no \`view\` grant on it, or`);
|
|
4529
|
+
console.log(` • nothing has entered the journey in the window yet — drive one with \`octwin chat\`.`);
|
|
4530
|
+
}
|
|
4531
|
+
/**
|
|
4532
|
+
* `octwin journeys [journeyId] [--funnel|--overview|--goals|--trends|--cost|--definition]
|
|
4533
|
+
* [--stage <stageId>] [--json]` — the journeys a pack declares, and how they perform.
|
|
4534
|
+
*
|
|
4535
|
+
* Needs `journeys:read`. Journeys carry RBAC ON TOP of the scope, so a token can
|
|
4536
|
+
* hold the scope and still see an empty journey — `printNoJourneyData` names that
|
|
4537
|
+
* rather than reporting it as absence of data.
|
|
4538
|
+
*/
|
|
4539
|
+
async function cmdJourneys(flags) {
|
|
4540
|
+
const t = resolveTarget(flags);
|
|
4541
|
+
const { url } = t;
|
|
4542
|
+
const base = `${url}/api/self/p/journeys`;
|
|
4543
|
+
const journeyId = flags._[0];
|
|
4544
|
+
const asJson = flags.json === true;
|
|
4545
|
+
const stage = typeof flags.stage === 'string' ? flags.stage : undefined;
|
|
4546
|
+
const mode = JOURNEY_MODES.find(m => flags[m] === true) ?? 'funnel';
|
|
4547
|
+
if (stage && !journeyId)
|
|
4548
|
+
die('usage: octwin journeys <journeyId> --stage <stageId> (a stage belongs to a journey)');
|
|
4549
|
+
// ── the list ──────────────────────────────────────────────────────────────
|
|
4550
|
+
if (!journeyId) {
|
|
4551
|
+
if (!asJson)
|
|
4552
|
+
console.log(`→ Reading declared journeys from ${targetLabel(t)} …`);
|
|
4553
|
+
/**
|
|
4554
|
+
* A template literal, not the bare `base`, so `cli-routes.test.ts` can SEE this
|
|
4555
|
+
* URL — its extractor only reads a template literal in the first argument
|
|
4556
|
+
* position, and a bare identifier slips past unchecked. That guard exists
|
|
4557
|
+
* because six deleted routes shipped as silent 404s; a call it cannot read is a
|
|
4558
|
+
* call it cannot protect.
|
|
4559
|
+
*
|
|
4560
|
+
* The first draft of this very comment QUOTED the call shape it was describing,
|
|
4561
|
+
* which made the comment itself match the extractor's pattern — the scan
|
|
4562
|
+
* consumed the prose and skipped the real call one line below. So the note that
|
|
4563
|
+
* explains the guard silently disabled it. Do not spell the scanned pattern
|
|
4564
|
+
* inside a comment in a file that is itself scanned.
|
|
4565
|
+
*/
|
|
4566
|
+
const { status, json } = await apiGet(`${base}`, t);
|
|
4567
|
+
if (status !== 200)
|
|
4568
|
+
die(`could not read journeys (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4569
|
+
if (asJson) {
|
|
4570
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4571
|
+
return;
|
|
4572
|
+
}
|
|
4573
|
+
const js = (json?.journeys ?? []);
|
|
4574
|
+
if (js.length === 0) {
|
|
4575
|
+
console.log('No journeys declared — a journey comes from the pack\'s `journeys.yaml`.');
|
|
4576
|
+
console.log('(Per-ENTITY stage funnels are a different surface: octwin analytics)');
|
|
4577
|
+
return;
|
|
4578
|
+
}
|
|
4579
|
+
console.log(`Journeys in ${targetLabel(t)}:`);
|
|
4580
|
+
for (const j of js)
|
|
4581
|
+
console.log(` ${String(j.id).padEnd(24)} ${pickLabel(j.label) ?? ''}`);
|
|
4582
|
+
console.log('\nOne journey: octwin journeys <journeyId> (add --overview / --goals / --trends / --cost / --definition)');
|
|
4583
|
+
console.log('Who is at a stage: octwin journeys <journeyId> --stage <stageId>');
|
|
4584
|
+
return;
|
|
4585
|
+
}
|
|
4586
|
+
// ── stage drill-down: the runs currently at a stage ────────────────────────
|
|
4587
|
+
if (stage) {
|
|
4588
|
+
if (!asJson)
|
|
4589
|
+
console.log(`→ Reading '${journeyId}' runs at stage '${stage}' …`);
|
|
4590
|
+
const { status, json } = await apiGet(`${base}/${encodeURIComponent(journeyId)}/stages/${encodeURIComponent(stage)}/runs?${pagingQs(flags)}`, t);
|
|
4591
|
+
if (status === 404)
|
|
4592
|
+
die(`unknown stage '${stage}' for journey '${journeyId}'${errDetail(json)}`);
|
|
4593
|
+
if (status !== 200)
|
|
4594
|
+
die(`could not read stage runs (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4595
|
+
if (asJson) {
|
|
4596
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4597
|
+
return;
|
|
4598
|
+
}
|
|
4599
|
+
if (json?.has_data === false) {
|
|
4600
|
+
printNoJourneyData(journeyId);
|
|
4601
|
+
return;
|
|
4602
|
+
}
|
|
4603
|
+
const page = readPage(json);
|
|
4604
|
+
console.log(`'${journeyId}' at '${stage}' (live snapshot): ${page.total ?? page.rows.length} run(s)`);
|
|
4605
|
+
for (const r of page.rows) {
|
|
4606
|
+
const who = r.channel_contact_handle ?? r.display_name ?? r.contact_id ?? '—';
|
|
4607
|
+
console.log(` ${who} entered ${r.entered_at ?? r.created_at ?? '—'}${r.completed_at ? ` completed ${r.completed_at}` : ''}`);
|
|
4608
|
+
}
|
|
4609
|
+
const more = morePageHint(page, `octwin journeys ${journeyId} --stage ${stage}`);
|
|
4610
|
+
if (more)
|
|
4611
|
+
console.log(more);
|
|
4612
|
+
return;
|
|
4613
|
+
}
|
|
4614
|
+
if (!asJson)
|
|
4615
|
+
console.log(`→ Reading '${journeyId}' ${mode} from ${targetLabel(t)} …`);
|
|
4616
|
+
const { status, json } = await apiGet(`${base}/${encodeURIComponent(journeyId)}/${mode}`, t);
|
|
4617
|
+
if (status === 404)
|
|
4618
|
+
die(`journey '${journeyId}' not found (list them: octwin journeys)`);
|
|
4619
|
+
if (status !== 200)
|
|
4620
|
+
die(`could not read ${mode} (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4621
|
+
if (asJson) {
|
|
4622
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4623
|
+
return;
|
|
4624
|
+
}
|
|
4625
|
+
if (json?.has_data === false) {
|
|
4626
|
+
printNoJourneyData(journeyId);
|
|
4627
|
+
return;
|
|
4628
|
+
}
|
|
4629
|
+
const range = json?.range ? ` (${String(json.range.from).slice(0, 10)} → ${String(json.range.to).slice(0, 10)})` : '';
|
|
4630
|
+
console.log(`Journey '${journeyId}' — ${mode}${range}:`);
|
|
4631
|
+
switch (mode) {
|
|
4632
|
+
case 'definition': {
|
|
4633
|
+
/**
|
|
4634
|
+
* Unmeasured: what the pack DECLARED. The one mode that answers "is this journey
|
|
4635
|
+
* even wired the way I think" with no traffic at all.
|
|
4636
|
+
*
|
|
4637
|
+
* The payload nests under `definition` and its own field names differ from the
|
|
4638
|
+
* measured modes: a stage carries `order` (not the funnel's `rank`), and a goal
|
|
4639
|
+
* names the `stage` it fires on. Read off the live route rather than assumed —
|
|
4640
|
+
* the first draft printed `?.` for every rank because it reused `rank`.
|
|
4641
|
+
*/
|
|
4642
|
+
const def = json?.definition ?? {};
|
|
4643
|
+
const stages = (def.stages ?? []);
|
|
4644
|
+
const goals = (def.goals ?? []);
|
|
4645
|
+
const events = (def.events ?? []);
|
|
4646
|
+
for (const s of stages) {
|
|
4647
|
+
console.log(` ${String(s.order ?? '?').padStart(2)}. ${String(s.id).padEnd(24)} ${pickLabel(s.label) ?? ''}`);
|
|
4648
|
+
}
|
|
4649
|
+
if (goals.length) {
|
|
4650
|
+
console.log(' goals:');
|
|
4651
|
+
for (const g of goals) {
|
|
4652
|
+
console.log(` ${String(g.id).padEnd(24)} ${String(pickLabel(g.label) ?? '').padEnd(22)}`
|
|
4653
|
+
+ `${g.stage ? ` on stage '${g.stage}'` : ''}${g.value != null ? ` value ${g.value}` : ''}`);
|
|
4654
|
+
}
|
|
4655
|
+
}
|
|
4656
|
+
// An event is keyed by `name` and carries what it MOVES — `advances_to` a stage
|
|
4657
|
+
// and optionally `completes` a goal. That wiring is the whole reason to read a
|
|
4658
|
+
// definition, so it gets a row each rather than a comma list of names.
|
|
4659
|
+
if (events.length) {
|
|
4660
|
+
console.log(' events (what moves the journey):');
|
|
4661
|
+
for (const e of events) {
|
|
4662
|
+
console.log(` ${String(e.name).padEnd(24)} ${String(pickLabel(e.label) ?? '').padEnd(22)}`
|
|
4663
|
+
+ `${e.advances_to ? ` → stage '${e.advances_to}'` : ''}${e.completes ? `, completes '${e.completes}'` : ''}`);
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
break;
|
|
4667
|
+
}
|
|
4668
|
+
case 'funnel':
|
|
4669
|
+
for (const s of (json?.funnel ?? [])) {
|
|
4670
|
+
const conv = s.conversion_from_prev_pct == null ? '' : ` ${s.conversion_from_prev_pct}% of prev`;
|
|
4671
|
+
const lost = s.drop_off_from_prev ? ` (−${s.drop_off_from_prev})` : '';
|
|
4672
|
+
console.log(` ${String(s.rank).padStart(2)}. ${String(pickLabel(s.label) ?? s.stage_id).padEnd(24)} ${String(s.reached).padStart(6)}${conv}${lost}`);
|
|
4673
|
+
}
|
|
4674
|
+
break;
|
|
4675
|
+
case 'overview': {
|
|
4676
|
+
const s = json?.summary ?? {};
|
|
4677
|
+
console.log(` entered ${s.entered} → converted ${s.converted}${s.conversion_pct == null ? '' : ` (${s.conversion_pct}%)`}`
|
|
4678
|
+
+ `${s.converted_basis ? ` [basis: ${s.converted_basis}]` : ''}`);
|
|
4679
|
+
if (s.biggest_dropoff)
|
|
4680
|
+
console.log(` biggest drop-off: ${s.biggest_dropoff.from} → ${s.biggest_dropoff.to} (lost ${s.biggest_dropoff.lost})`);
|
|
4681
|
+
if (s.top_goal)
|
|
4682
|
+
console.log(` top goal: ${pickLabel(s.top_goal.label) ?? s.top_goal.goal_id} (${s.top_goal.completions})`);
|
|
4683
|
+
break;
|
|
4684
|
+
}
|
|
4685
|
+
case 'goals':
|
|
4686
|
+
for (const g of (json?.goals ?? [])) {
|
|
4687
|
+
const p50 = g.p50_seconds == null ? '' : ` p50 ${Math.round(g.p50_seconds / 60)}m`;
|
|
4688
|
+
console.log(` ${String(pickLabel(g.label) ?? g.goal_id).padEnd(28)} ${String(g.completions).padStart(6)} completion(s),`
|
|
4689
|
+
+ ` ${g.unique_contacts} contact(s)${g.total_value ? `, value ${g.total_value}` : ''}${p50}`);
|
|
4690
|
+
}
|
|
4691
|
+
break;
|
|
4692
|
+
case 'trends':
|
|
4693
|
+
for (const b of (json?.buckets ?? [])) {
|
|
4694
|
+
console.log(` ${String(b.bucket).slice(0, 10)} active ${b.active_contacts} goals ${b.goal_completions}`);
|
|
4695
|
+
}
|
|
4696
|
+
break;
|
|
4697
|
+
case 'cost':
|
|
4698
|
+
for (const g of (json?.by_goal ?? [])) {
|
|
4699
|
+
const unknown = g.cost_unknown_rows ? ` (${g.cost_unknown_rows} row(s) unpriced)` : '';
|
|
4700
|
+
console.log(` ${String(pickLabel(g.label) ?? g.id).padEnd(24)} ${String(g.conversations).padStart(5)} conv,`
|
|
4701
|
+
+ ` ${String(g.total_tokens).padStart(8)} tokens, $${(g.cost_usd ?? 0).toFixed(4)}${unknown}`);
|
|
4702
|
+
}
|
|
4703
|
+
break;
|
|
4704
|
+
}
|
|
4705
|
+
}
|
|
4706
|
+
// ── performance: the project's business indicators ──────────────────────────
|
|
4707
|
+
/**
|
|
4708
|
+
* `octwin performance [--detail] [--json]` — the indicators the project's own
|
|
4709
|
+
* declarations produce: value, conversion, duration, per journey.
|
|
4710
|
+
*
|
|
4711
|
+
* Needs `records:read` — **not** a `performance:*` scope, which does not exist.
|
|
4712
|
+
* That means the Read-only token preset already reaches this.
|
|
4713
|
+
*/
|
|
4714
|
+
async function cmdPerformance(flags) {
|
|
4715
|
+
const t = resolveTarget(flags);
|
|
4716
|
+
const { url } = t;
|
|
4717
|
+
const base = `${url}/api/self/p/performance`;
|
|
4718
|
+
const asJson = flags.json === true;
|
|
4719
|
+
const detail = flags.detail === true;
|
|
4720
|
+
if (!asJson)
|
|
4721
|
+
console.log(`→ Reading business performance from ${targetLabel(t)} …`);
|
|
4722
|
+
// Two explicit calls rather than `apiGet(detail ? … : base)`: the route guard's
|
|
4723
|
+
// extractor only reads a template literal in the FIRST argument position, so a
|
|
4724
|
+
// ternary hides both URLs from it.
|
|
4725
|
+
const { status, json } = detail
|
|
4726
|
+
? await apiGet(`${base}/detail`, t)
|
|
4727
|
+
: await apiGet(`${base}`, t);
|
|
4728
|
+
if (status !== 200)
|
|
4729
|
+
die(`could not read performance (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4730
|
+
if (asJson) {
|
|
4731
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4732
|
+
return;
|
|
4733
|
+
}
|
|
4734
|
+
if (json?.has_data === false) {
|
|
4735
|
+
console.log('No performance indicators — they are DERIVED from declarations (a journey with a');
|
|
4736
|
+
console.log('goal value, a pipelined entity), so a pack that declares none produces none.');
|
|
4737
|
+
return;
|
|
4738
|
+
}
|
|
4739
|
+
const r = json?.range ?? {};
|
|
4740
|
+
console.log(`Performance in ${targetLabel(t)}`
|
|
4741
|
+
+ `${r.from ? ` (${String(r.from).slice(0, 10)} → ${String(r.to).slice(0, 10)}, ${r.days ?? '?'}d, by ${json?.bucket ?? 'day'})` : ''}:`);
|
|
4742
|
+
const inds = (json?.indicators ?? []);
|
|
4743
|
+
if (inds.length === 0)
|
|
4744
|
+
console.log(' (none)');
|
|
4745
|
+
for (const i of inds) {
|
|
4746
|
+
const unit = i.unit === 'pct' ? '%' : '';
|
|
4747
|
+
// `delta_pct` is signed and against the PREVIOUS window — sign it explicitly so
|
|
4748
|
+
// a fall is never read as a rise.
|
|
4749
|
+
const delta = i.delta_pct == null ? '' : ` ${i.delta_pct >= 0 ? '+' : ''}${i.delta_pct}% vs prev`;
|
|
4750
|
+
const frac = i.numerator != null && i.denominator != null
|
|
4751
|
+
? ` (${i.numerator}/${i.denominator}${i.denominator_of ? ` ${i.denominator_of}` : ''})`
|
|
4752
|
+
: '';
|
|
4753
|
+
console.log(` ${String(pickLabel(i.heading) ?? i.kind).padEnd(16)} ${String(pickLabel(i.label) ?? '').padEnd(20)}`
|
|
4754
|
+
+ ` ${String(i.value ?? '—').padStart(9)}${unit}${delta}${frac}`);
|
|
4755
|
+
if (i.why)
|
|
4756
|
+
console.log(` why: ${i.why}`);
|
|
4757
|
+
if (i.biggest_dropoff)
|
|
4758
|
+
console.log(` biggest drop-off: ${i.biggest_dropoff.from} → ${i.biggest_dropoff.to} (lost ${i.biggest_dropoff.lost})`);
|
|
4759
|
+
}
|
|
4760
|
+
if (!detail)
|
|
4761
|
+
console.log('\nPer-indicator breakdown: octwin performance --detail');
|
|
4762
|
+
}
|
|
4763
|
+
// ── usage: model calls, tokens and cost ─────────────────────────────────────
|
|
4764
|
+
/** One `{ key, calls, total_tokens, cost_usd }` breakdown row. */
|
|
4765
|
+
function printUsageRows(title, rows) {
|
|
4766
|
+
if (!rows?.length)
|
|
4767
|
+
return;
|
|
4768
|
+
console.log(` ${title}:`);
|
|
4769
|
+
for (const r of rows) {
|
|
4770
|
+
console.log(` ${String(r.key ?? r.day).padEnd(40)} ${String(r.calls ?? '—').padStart(6)} call(s)`
|
|
4771
|
+
+ ` ${String(r.total_tokens ?? 0).padStart(10)} tokens $${(r.cost_usd ?? 0).toFixed(4)}`
|
|
4772
|
+
+ `${r.cost_partial ? ' (partial — some rows unpriced)' : ''}`);
|
|
4773
|
+
}
|
|
4774
|
+
}
|
|
4775
|
+
/**
|
|
4776
|
+
* `octwin usage [--json]` — model calls, tokens and cost for the resolved scope.
|
|
4777
|
+
*
|
|
4778
|
+
* Needs NO scope beyond a valid token (the route is `requireTenantAccess`), which
|
|
4779
|
+
* is why it has no `COMMAND_REQUIREMENTS` entry: declaring one would print
|
|
4780
|
+
* "needs the X scope" on a failure whose cause is something else.
|
|
4781
|
+
*
|
|
4782
|
+
* Project-scoped when a project is resolved, tenant-wide otherwise — both routes
|
|
4783
|
+
* exist and the narrower one is the more useful default while testing a pack.
|
|
4784
|
+
* This is spend on MODEL calls; WhatsApp/Meta billing is operator-only and no
|
|
4785
|
+
* token can reach it.
|
|
4786
|
+
*/
|
|
4787
|
+
async function cmdUsage(flags) {
|
|
4788
|
+
const t = resolveTarget(flags);
|
|
4789
|
+
const { url } = t;
|
|
4790
|
+
const asJson = flags.json === true;
|
|
4791
|
+
const scoped = Boolean(t.project);
|
|
4792
|
+
if (!asJson)
|
|
4793
|
+
console.log(`→ Reading model usage for ${scoped ? targetLabel(t) : 'the whole workspace'} …`);
|
|
4794
|
+
// Both URLs written out in place, for the same reason as `performance` above: an
|
|
4795
|
+
// `endpoint` variable would leave BOTH invisible to `cli-routes.test.ts`.
|
|
4796
|
+
const { status, json } = scoped
|
|
4797
|
+
? await apiGet(`${url}/api/self/p/usage`, t)
|
|
4798
|
+
: await apiGet(`${url}/api/self/t/usage`, t);
|
|
4799
|
+
if (status !== 200)
|
|
4800
|
+
die(`could not read usage (HTTP ${status})${errDetail(json)}${authFailureDetail(status, url)}`);
|
|
4801
|
+
if (asJson) {
|
|
4802
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4803
|
+
return;
|
|
4804
|
+
}
|
|
4805
|
+
const u = json?.usage ?? {};
|
|
4806
|
+
const tot = u.totals ?? {};
|
|
4807
|
+
const r = json?.range ?? {};
|
|
4808
|
+
console.log(`Model usage — ${scoped ? `project '${json?.project?.slug ?? t.project}'` : `workspace '${json?.tenant?.slug ?? ''}'`}`
|
|
4809
|
+
+ `${r.from ? ` (${String(r.from).slice(0, 10)} → ${String(r.to).slice(0, 10)})` : ''}`);
|
|
4810
|
+
console.log(` ${tot.calls ?? 0} call(s) ${tot.total_tokens ?? 0} tokens`
|
|
4811
|
+
+ ` (${tot.prompt_tokens ?? 0} in / ${tot.completion_tokens ?? 0} out) $${(tot.cost_usd ?? 0).toFixed(4)}`
|
|
4812
|
+
+ `${tot.cost_partial ? ' ⚠ partial: some calls had no price' : ''}`);
|
|
4813
|
+
if ((tot.calls ?? 0) === 0) {
|
|
4814
|
+
console.log(' (nothing in the window — drive a turn with `octwin chat`)');
|
|
4815
|
+
return;
|
|
4816
|
+
}
|
|
4817
|
+
printUsageRows('by model', u.by_model);
|
|
4818
|
+
printUsageRows('by kind', u.by_kind);
|
|
4819
|
+
printUsageRows('by agent', u.by_agent);
|
|
4820
|
+
printUsageRows('by channel', u.by_channel);
|
|
4821
|
+
// Not WhatsApp/Meta spend: that is operator-only and deliberately outside the
|
|
4822
|
+
// token scope registry, so this command cannot show it at all.
|
|
4823
|
+
console.log('\nThis is MODEL spend. WhatsApp/Meta message billing is operator-only — not reachable by an API token.');
|
|
4824
|
+
}
|
|
4019
4825
|
function help() {
|
|
4020
|
-
console.log(`octwin ${VERSION} — Octwin external-pack developer CLI (by CEQUENS)
|
|
4021
|
-
|
|
4022
|
-
octwin --version # print the CLI version (+ any upgrade notice)
|
|
4023
|
-
octwin init <dir> [--id my-pack] [--description "..."] [--display-name "..."]
|
|
4024
|
-
octwin validate [--dir .] [--remote] [--require-kb] # --remote runs the platform's FULL schema check + lint (all errors at once)
|
|
4025
|
-
octwin login --url <platformUrl> --token oct_… # a deploy token from the console
|
|
4026
|
-
octwin whoami [--url <url>] [--tenant <slug>] # verify the token works
|
|
4027
|
-
octwin projects [--archived] [--json] # the --project slugs this token can name
|
|
4028
|
-
octwin deploy [--dir .] [--url <url>] [--tenant <slug>] [--project <slug>] [--token <t>] [--seed]
|
|
4029
|
-
[--request-listing | --withdraw-listing] # public marketplace — opt-in, see: octwin help deploy
|
|
4030
|
-
octwin status [<packId>] [--dir .] [--url <url>] [--tenant <slug>] [--project <slug>] [--token <t>]
|
|
4031
|
-
octwin pull <packId> [--dir <out>] [--version <v>] [--force] # write a DEPLOYED pack's source back to disk (the inverse of deploy)
|
|
4032
|
-
octwin records [entity] [id] # inspect the pack's XRM data (needs a records:read token)
|
|
4033
|
-
octwin work [recordId] [--queues] [--json] # inspect the work inbox (worked records) + timelines
|
|
4034
|
-
octwin logs [conversationId] [--as <handle>] [--json] # list conversations / show one's event timeline
|
|
4035
|
-
octwin chat "message" [--as <handle>] [--tap <tap-id>] [--media <file|id>] [--json] # drive a turn (+ send media) + print every render
|
|
4036
|
-
octwin media generate "<prompt>" [--out <file.png>] [--json] # AI-generate an image → MEDIA- handle (needs media:generate scope)
|
|
4037
|
-
octwin agents [packId::agentId] [--prompt] [--json] # effective model/memory + WHICH layer won; --prompt = the resolved system prompt
|
|
4038
|
-
octwin orders [reference_id] [--status s] [--payment p] [--json] # the orders a conversation produced + money + payment state
|
|
4039
|
-
octwin analytics [entity] [--funnel|--overview|--milestones|--trends|--cost] [--stage <id>] # stage conversion for any pipelined entity
|
|
4040
|
-
octwin catalog [--readiness] [--json] # commerce products + stock + the WhatsApp catalog binding
|
|
4041
|
-
octwin scheduling [--slots <resourceRecordId>] [--from YYYY-MM-DD] [--days n] # engine state / computed slots
|
|
4042
|
-
octwin
|
|
4043
|
-
octwin
|
|
4044
|
-
octwin
|
|
4045
|
-
octwin
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
octwin
|
|
4049
|
-
octwin
|
|
4050
|
-
octwin
|
|
4051
|
-
octwin
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
octwin
|
|
4055
|
-
octwin
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
octwin
|
|
4062
|
-
|
|
4826
|
+
console.log(`octwin ${VERSION} — Octwin external-pack developer CLI (by CEQUENS)
|
|
4827
|
+
|
|
4828
|
+
octwin --version # print the CLI version (+ any upgrade notice)
|
|
4829
|
+
octwin init <dir> [--id my-pack] [--description "..."] [--display-name "..."]
|
|
4830
|
+
octwin validate [--dir .] [--remote] [--require-kb] # --remote runs the platform's FULL schema check + lint (all errors at once)
|
|
4831
|
+
octwin login --url <platformUrl> --token oct_… # a deploy token from the console
|
|
4832
|
+
octwin whoami [--url <url>] [--tenant <slug>] # verify the token works
|
|
4833
|
+
octwin projects [--archived] [--json] # the --project slugs this token can name
|
|
4834
|
+
octwin deploy [--dir .] [--url <url>] [--tenant <slug>] [--project <slug>] [--token <t>] [--seed]
|
|
4835
|
+
[--request-listing | --withdraw-listing] # public marketplace — opt-in, see: octwin help deploy
|
|
4836
|
+
octwin status [<packId>] [--dir .] [--url <url>] [--tenant <slug>] [--project <slug>] [--token <t>]
|
|
4837
|
+
octwin pull <packId> [--dir <out>] [--version <v>] [--force] # write a DEPLOYED pack's source back to disk (the inverse of deploy)
|
|
4838
|
+
octwin records [entity] [id] # inspect the pack's XRM data (needs a records:read token)
|
|
4839
|
+
octwin work [recordId] [--queues] [--json] # inspect the work inbox (worked records) + timelines
|
|
4840
|
+
octwin logs [conversationId] [--as <handle>] [--json] # list conversations / show one's event timeline
|
|
4841
|
+
octwin chat "message" [--as <handle>] [--tap <tap-id>] [--media <file|id>] [--json] # drive a turn (+ send media) + print every render
|
|
4842
|
+
octwin media generate "<prompt>" [--out <file.png>] [--json] # AI-generate an image → MEDIA- handle (needs media:generate scope)
|
|
4843
|
+
octwin agents [packId::agentId] [--prompt] [--json] # effective model/memory + WHICH layer won; --prompt = the resolved system prompt
|
|
4844
|
+
octwin orders [reference_id] [--status s] [--payment p] [--json] # the orders a conversation produced + money + payment state
|
|
4845
|
+
octwin analytics [entity] [--funnel|--overview|--milestones|--trends|--cost] [--stage <id>] # stage conversion for any pipelined entity
|
|
4846
|
+
octwin catalog [--readiness] [--json] # commerce products + stock + the WhatsApp catalog binding
|
|
4847
|
+
octwin scheduling [--slots <resourceRecordId>] [--from YYYY-MM-DD] [--days n] # engine state / computed slots
|
|
4848
|
+
octwin automation [campaigns] [--json] # the jobs your declarations produced + health, last result each
|
|
4849
|
+
octwin integrations [--json] # declared connections BESIDE what is configured (the silent-never-fires check)
|
|
4850
|
+
octwin integrations deliveries [<id>] | events # the outbound delivery log / inbound events
|
|
4851
|
+
octwin journeys [journeyId] [--funnel|--overview|--goals|--trends|--cost|--definition] [--stage <id>]
|
|
4852
|
+
octwin performance [--detail] [--json] # the project's business indicators (value/conversion/duration)
|
|
4853
|
+
octwin usage [--json] # model calls, tokens and cost (project if pinned, else workspace)
|
|
4854
|
+
octwin platform-kb [pull] [--if-stale|--check] [--dir .] [--url <url>] # no token needed
|
|
4855
|
+
octwin test [--dir .] # = validate --remote (the full platform check)
|
|
4856
|
+
octwin feedback [--dir .] # submit this pack's FEEDBACK.md to the platform team
|
|
4857
|
+
octwin memos [--all] [--json] # read the platform's replies + notices (a reply to your feedback lands here)
|
|
4858
|
+
|
|
4859
|
+
Writes — exercise the state your pack creates (each needs the matching :write scope):
|
|
4860
|
+
octwin records create <entity> --set field=value … # also: patch <id> --entity <e>, stage <id> --to <s>, note <id> "…"
|
|
4861
|
+
octwin records tasks | task complete <taskId> [--outcome done|cancelled]
|
|
4862
|
+
octwin work assign <id> --to user:<uuid>|none | note <id> "…" | stage <id> --to <stage>
|
|
4863
|
+
octwin work decide <id> --action <a> [--param k=v] [--dry-run] # --dry-run previews, commits nothing
|
|
4864
|
+
octwin orders transition <ref> --to <status> | refund <ref> --force
|
|
4865
|
+
octwin catalog availability <sku> --to "in stock" | stock <sku> [--set-on-hand n]
|
|
4866
|
+
octwin scheduling rules --resource <id> | rule add|rm | exception add|rm
|
|
4867
|
+
octwin agents set <packId::agentId> [--model m] [--enable-tool t] [--disable-tool t]
|
|
4868
|
+
octwin automation run <jobId> | pause <jobId> | resume <jobId> | send <campaignId>
|
|
4869
|
+
octwin integrations test <key> # a LIVE call to the connection's health: operation
|
|
4870
|
+
octwin integrations retry|cancel|send-now <deliveryId>
|
|
4871
|
+
(octwin integrations preflight <key> needs only integrations:read — it makes no call)
|
|
4872
|
+
|
|
4873
|
+
Multi-turn: the platform keeps ONE open conversation per --as handle — consecutive
|
|
4874
|
+
\`octwin chat --as <h>\` calls continue the same conversation; press a rendered
|
|
4875
|
+
button/row with \`--tap "<tap-id>"\` (chat prints every tap id).
|
|
4876
|
+
Get a deploy token: console → your workspace → Settings → API tokens → Generate (tick records:read to inspect data).
|
|
4877
|
+
octwin platform-kb pull → writes the platform capability reference into .octwin/platform-kb/ (for the octwin-pack skill).
|
|
4878
|
+
Config (deploy): flags > env (PACK_PLATFORM_URL/PACK_TENANT/PACK_PROJECT/PACK_TOKEN) > saved login (\`octwin login\` sets the default target).
|
|
4063
4879
|
Per-command usage: octwin <command> --help`);
|
|
4064
4880
|
}
|
|
4065
4881
|
/** Per-subcommand usage — printed for `octwin <cmd> --help|-h` BEFORE any
|
|
4066
4882
|
* network/auth work (a --help that 401s is worse than no help at all). */
|
|
4067
4883
|
const COMMAND_HELP = {
|
|
4068
|
-
init: `octwin init <dir> [--id my-pack] [--description "..."] [--display-name "..."]
|
|
4884
|
+
init: `octwin init <dir> [--id my-pack] [--description "..."] [--display-name "..."]
|
|
4069
4885
|
Scaffold a pure-YAML starter pack into <dir>.`,
|
|
4070
|
-
validate: `octwin validate [--dir .] [--remote] [--require-kb] [--strict-primitives]
|
|
4071
|
-
Offline structural check, plus two checks driven by the pulled capability
|
|
4072
|
-
reference (render-intent fields, primitive arguments). Those two SKIP when the
|
|
4073
|
-
reference is missing — the run says so, and --require-kb turns the skip into a
|
|
4074
|
-
failure for CI. --remote additionally runs the platform's FULL manifest +
|
|
4075
|
-
flow-DSL validation and its flow lint (all errors at once) — same check as deploy.
|
|
4076
|
-
--strict-primitives (with --remote) additionally type-checks LITERAL args:
|
|
4077
|
-
values against each primitive's declared input schema; expression strings
|
|
4886
|
+
validate: `octwin validate [--dir .] [--remote] [--require-kb] [--strict-primitives]
|
|
4887
|
+
Offline structural check, plus two checks driven by the pulled capability
|
|
4888
|
+
reference (render-intent fields, primitive arguments). Those two SKIP when the
|
|
4889
|
+
reference is missing — the run says so, and --require-kb turns the skip into a
|
|
4890
|
+
failure for CI. --remote additionally runs the platform's FULL manifest +
|
|
4891
|
+
flow-DSL validation and its flow lint (all errors at once) — same check as deploy.
|
|
4892
|
+
--strict-primitives (with --remote) additionally type-checks LITERAL args:
|
|
4893
|
+
values against each primitive's declared input schema; expression strings
|
|
4078
4894
|
('$found.id', '{$t(…)}') are always exempt.`,
|
|
4079
|
-
login: `octwin login --url <platformUrl> --token oct_…
|
|
4080
|
-
Save a deploy token (console → Settings → API tokens) for that platform url,
|
|
4081
|
-
make that url the DEFAULT deploy target for every later command, and echo the
|
|
4895
|
+
login: `octwin login --url <platformUrl> --token oct_…
|
|
4896
|
+
Save a deploy token (console → Settings → API tokens) for that platform url,
|
|
4897
|
+
make that url the DEFAULT deploy target for every later command, and echo the
|
|
4082
4898
|
workspace + project pin + scopes the token reaches.`,
|
|
4083
|
-
whoami: `octwin whoami [--url <url>] [--tenant <slug>]
|
|
4899
|
+
whoami: `octwin whoami [--url <url>] [--tenant <slug>]
|
|
4084
4900
|
Verify the resolved token authenticates against the tenant.`,
|
|
4085
|
-
projects: `octwin projects [--archived] [--json]
|
|
4086
|
-
List the workspace's projects — the slugs every --project flag takes, with the
|
|
4087
|
-
plan's project cap. --archived includes archived ones. A pack:deploy token
|
|
4088
|
-
reaches this (it names a project in every other command).
|
|
4089
|
-
|
|
4090
|
-
octwin projects create "<name>" [--slug <slug>] [--pack <packId>]
|
|
4091
|
-
Create a project. The URL slug is derived from the name unless --slug pins one.
|
|
4092
|
-
--pack installs an ALREADY-published pack; the usual next step is instead
|
|
4093
|
-
\`octwin deploy --project <slug>\`, which publishes this working tree and installs it.
|
|
4094
|
-
|
|
4095
|
-
octwin projects rm <slug> [--yes]
|
|
4096
|
-
HARD delete — the project and everything cascading from it (conversations,
|
|
4097
|
-
contacts, records, installs). No undo, and not the same as archiving.
|
|
4098
|
-
WITHOUT --yes it only previews what would be destroyed, so the dry run is the
|
|
4099
|
-
default. Together these make a disposable end-to-end environment:
|
|
4100
|
-
octwin projects create "Scratch" && octwin deploy --project scratch --seed
|
|
4101
|
-
octwin chat "hi" --project scratch
|
|
4102
|
-
octwin projects rm scratch --yes
|
|
4901
|
+
projects: `octwin projects [--archived] [--json]
|
|
4902
|
+
List the workspace's projects — the slugs every --project flag takes, with the
|
|
4903
|
+
plan's project cap. --archived includes archived ones. A pack:deploy token
|
|
4904
|
+
reaches this (it names a project in every other command).
|
|
4905
|
+
|
|
4906
|
+
octwin projects create "<name>" [--slug <slug>] [--pack <packId>]
|
|
4907
|
+
Create a project. The URL slug is derived from the name unless --slug pins one.
|
|
4908
|
+
--pack installs an ALREADY-published pack; the usual next step is instead
|
|
4909
|
+
\`octwin deploy --project <slug>\`, which publishes this working tree and installs it.
|
|
4910
|
+
|
|
4911
|
+
octwin projects rm <slug> [--yes]
|
|
4912
|
+
HARD delete — the project and everything cascading from it (conversations,
|
|
4913
|
+
contacts, records, installs). No undo, and not the same as archiving.
|
|
4914
|
+
WITHOUT --yes it only previews what would be destroyed, so the dry run is the
|
|
4915
|
+
default. Together these make a disposable end-to-end environment:
|
|
4916
|
+
octwin projects create "Scratch" && octwin deploy --project scratch --seed
|
|
4917
|
+
octwin chat "hi" --project scratch
|
|
4918
|
+
octwin projects rm scratch --yes
|
|
4103
4919
|
Both verbs need the \`projects:write\` scope — a pack:deploy token does NOT confer it.`,
|
|
4104
|
-
deploy: `octwin deploy [--dir .] [--url <url>] [--tenant <slug>] [--project <slug>] [--token <t>] [--seed]
|
|
4105
|
-
[--request-listing | --withdraw-listing]
|
|
4106
|
-
Upload the pack bundle, validate server-side, install onto the project.
|
|
4107
|
-
--seed additionally applies the pack's demo seed (streams progress).
|
|
4108
|
-
|
|
4109
|
-
A plain deploy says NOTHING about the public marketplace — it is a test loop, so it
|
|
4110
|
-
neither asks for a listing nor gives one up. The marketplace flags are opt-in:
|
|
4111
|
-
|
|
4112
|
-
--request-listing ask an operator to review this pack for the public marketplace
|
|
4113
|
-
(the pre-signup storefront at /packs). Requires 'public: true'
|
|
4114
|
-
under 'listing:' in manifest.yaml — the manifest states that the
|
|
4115
|
-
pack is a product, the flag is you choosing to ask.
|
|
4116
|
-
--withdraw-listing retract the request, including an approved listing.
|
|
4117
|
-
|
|
4118
|
-
An approval covers the CONTENT it was made against, so a later deploy that changes the
|
|
4920
|
+
deploy: `octwin deploy [--dir .] [--url <url>] [--tenant <slug>] [--project <slug>] [--token <t>] [--seed]
|
|
4921
|
+
[--request-listing | --withdraw-listing]
|
|
4922
|
+
Upload the pack bundle, validate server-side, install onto the project.
|
|
4923
|
+
--seed additionally applies the pack's demo seed (streams progress).
|
|
4924
|
+
|
|
4925
|
+
A plain deploy says NOTHING about the public marketplace — it is a test loop, so it
|
|
4926
|
+
neither asks for a listing nor gives one up. The marketplace flags are opt-in:
|
|
4927
|
+
|
|
4928
|
+
--request-listing ask an operator to review this pack for the public marketplace
|
|
4929
|
+
(the pre-signup storefront at /packs). Requires 'public: true'
|
|
4930
|
+
under 'listing:' in manifest.yaml — the manifest states that the
|
|
4931
|
+
pack is a product, the flag is you choosing to ask.
|
|
4932
|
+
--withdraw-listing retract the request, including an approved listing.
|
|
4933
|
+
|
|
4934
|
+
An approval covers the CONTENT it was made against, so a later deploy that changes the
|
|
4119
4935
|
pack returns it to the review queue on its own — no flag needed, and the CLI says so.`,
|
|
4120
|
-
seed: `octwin seed [--pack <packId>]
|
|
4121
|
-
Apply the pack's demo/reference data to the project it is installed on, without
|
|
4122
|
-
redeploying: xrm \`demo:\` records + scheduling availability, the commerce catalog,
|
|
4123
|
-
and the demo operator topology. Reports what each kind produced.
|
|
4124
|
-
Idempotent and safe to re-run — records upsert, and existing media is REUSED rather
|
|
4125
|
-
than regenerated, so a second pass costs nothing. --pack is only needed when a
|
|
4936
|
+
seed: `octwin seed [--pack <packId>]
|
|
4937
|
+
Apply the pack's demo/reference data to the project it is installed on, without
|
|
4938
|
+
redeploying: xrm \`demo:\` records + scheduling availability, the commerce catalog,
|
|
4939
|
+
and the demo operator topology. Reports what each kind produced.
|
|
4940
|
+
Idempotent and safe to re-run — records upsert, and existing media is REUSED rather
|
|
4941
|
+
than regenerated, so a second pass costs nothing. --pack is only needed when a
|
|
4126
4942
|
project somehow runs more than one.`,
|
|
4127
|
-
status: `octwin status [<packId>] [--dir .] [--url <url>] [--tenant <slug>] [--project <slug>]
|
|
4128
|
-
Show installed vs live version + the flow list for this pack.
|
|
4129
|
-
The pack id is read from manifest.yaml and QUALIFIED with your workspace slug
|
|
4130
|
-
(a manifest declares a bare name; the owner is attached when you publish). Pass
|
|
4131
|
-
<packId> explicitly to skip that lookup — \`octwin agents\` and \`octwin projects\`
|
|
4943
|
+
status: `octwin status [<packId>] [--dir .] [--url <url>] [--tenant <slug>] [--project <slug>]
|
|
4944
|
+
Show installed vs live version + the flow list for this pack.
|
|
4945
|
+
The pack id is read from manifest.yaml and QUALIFIED with your workspace slug
|
|
4946
|
+
(a manifest declares a bare name; the owner is attached when you publish). Pass
|
|
4947
|
+
<packId> explicitly to skip that lookup — \`octwin agents\` and \`octwin projects\`
|
|
4132
4948
|
both print the qualified form.`,
|
|
4133
|
-
records: `octwin records [entity] [id] [--limit 50] [--offset n]
|
|
4134
|
-
Inspect the pack's XRM data. No args = list entities. Worked records (cases,
|
|
4135
|
-
tickets, anything routed to a queue) read best through \`octwin work\`.
|
|
4136
|
-
|
|
4137
|
-
WRITES (need \`records:write\`; every one is re-checked by RBAC on the record):
|
|
4138
|
-
octwin records create <entity> --set field=value [--set …] [--stage s] [--contact <id>]
|
|
4139
|
-
octwin records patch <recordId> --entity <entity> --set field=value
|
|
4140
|
-
octwin records stage <recordId> --to <stage> [--note "..."]
|
|
4141
|
-
octwin records note <recordId> "the note text"
|
|
4142
|
-
octwin records tasks # open follow-up tasks (\`tasks\` plan feature)
|
|
4143
|
-
octwin records task complete <taskId> [--outcome done|cancelled] [--note "..."]
|
|
4144
|
-
|
|
4145
|
-
--set coerces JSON scalars: \`--set rating=4.5\` sends a number, \`--set x=null\`
|
|
4146
|
-
sends null. Use --fields-json '{"a":{"b":1}}' for anything nested.
|
|
4147
|
-
\`patch\` needs --entity even though it has an id: the route resolves the field
|
|
4148
|
-
validator from it. A leading \`create/patch/stage/note/tasks/task\` is read as a
|
|
4949
|
+
records: `octwin records [entity] [id] [--limit 50] [--offset n]
|
|
4950
|
+
Inspect the pack's XRM data. No args = list entities. Worked records (cases,
|
|
4951
|
+
tickets, anything routed to a queue) read best through \`octwin work\`.
|
|
4952
|
+
|
|
4953
|
+
WRITES (need \`records:write\`; every one is re-checked by RBAC on the record):
|
|
4954
|
+
octwin records create <entity> --set field=value [--set …] [--stage s] [--contact <id>]
|
|
4955
|
+
octwin records patch <recordId> --entity <entity> --set field=value
|
|
4956
|
+
octwin records stage <recordId> --to <stage> [--note "..."]
|
|
4957
|
+
octwin records note <recordId> "the note text"
|
|
4958
|
+
octwin records tasks # open follow-up tasks (\`tasks\` plan feature)
|
|
4959
|
+
octwin records task complete <taskId> [--outcome done|cancelled] [--note "..."]
|
|
4960
|
+
|
|
4961
|
+
--set coerces JSON scalars: \`--set rating=4.5\` sends a number, \`--set x=null\`
|
|
4962
|
+
sends null. Use --fields-json '{"a":{"b":1}}' for anything nested.
|
|
4963
|
+
\`patch\` needs --entity even though it has an id: the route resolves the field
|
|
4964
|
+
validator from it. A leading \`create/patch/stage/note/tasks/task\` is read as a
|
|
4149
4965
|
VERB — to list an entity actually named one of those, use \`--entity <name>\`.`,
|
|
4150
|
-
work: `octwin work [recordId] [--queues] [--limit 50] [--offset n] [--json]
|
|
4151
|
-
Inspect the work inbox — every entity the pack declares worked (cases, orders
|
|
4152
|
-
needing review, applications, …): the inbox, one item + its timeline
|
|
4153
|
-
(+ applicable actions), or --queues for queue keys + open counts.
|
|
4154
|
-
|
|
4155
|
-
WRITES (need \`work:write\`; \`stage\` needs \`records:write\`):
|
|
4156
|
-
octwin work assign <recordId> --to user:<uuid>|team:<uuid>|none
|
|
4157
|
-
octwin work note <recordId> "the note text"
|
|
4158
|
-
octwin work stage <recordId> --to <stage> [--note "..."]
|
|
4159
|
-
octwin work decide <recordId> --action <action> [--param k=v] [--note "..."] [--dry-run]
|
|
4160
|
-
|
|
4161
|
-
\`decide\` applies one of the entity's declared operator actions — \`octwin work <id>\`
|
|
4162
|
-
lists them with their params. --dry-run previews the customer-facing copy and the
|
|
4163
|
-
resulting stage WITHOUT committing (that route needs only \`work:read\`).
|
|
4966
|
+
work: `octwin work [recordId] [--queues] [--limit 50] [--offset n] [--json]
|
|
4967
|
+
Inspect the work inbox — every entity the pack declares worked (cases, orders
|
|
4968
|
+
needing review, applications, …): the inbox, one item + its timeline
|
|
4969
|
+
(+ applicable actions), or --queues for queue keys + open counts.
|
|
4970
|
+
|
|
4971
|
+
WRITES (need \`work:write\`; \`stage\` needs \`records:write\`):
|
|
4972
|
+
octwin work assign <recordId> --to user:<uuid>|team:<uuid>|none
|
|
4973
|
+
octwin work note <recordId> "the note text"
|
|
4974
|
+
octwin work stage <recordId> --to <stage> [--note "..."]
|
|
4975
|
+
octwin work decide <recordId> --action <action> [--param k=v] [--note "..."] [--dry-run]
|
|
4976
|
+
|
|
4977
|
+
\`decide\` applies one of the entity's declared operator actions — \`octwin work <id>\`
|
|
4978
|
+
lists them with their params. --dry-run previews the customer-facing copy and the
|
|
4979
|
+
resulting stage WITHOUT committing (that route needs only \`work:read\`).
|
|
4164
4980
|
\`stage\` is the XRM records verb (one transition spelling platform-wide).`,
|
|
4165
|
-
logs: `octwin logs [conversationId] [--as <handle>] [--json]
|
|
4166
|
-
No id = recent conversations (handle, status, last activity; --as filters).
|
|
4167
|
-
With id = the full event timeline including what each turn rendered.
|
|
4981
|
+
logs: `octwin logs [conversationId] [--as <handle>] [--json]
|
|
4982
|
+
No id = recent conversations (handle, status, last activity; --as filters).
|
|
4983
|
+
With id = the full event timeline including what each turn rendered.
|
|
4168
4984
|
--json = raw events (verbatim payloads).`,
|
|
4169
|
-
pull: `octwin pull <packId> [--dir <out>] [--version <v>] [--force]
|
|
4170
|
-
Write a DEPLOYED pack's source back to disk — the inverse of deploy.
|
|
4171
|
-
A pack pushed with 'octwin deploy' lives on the platform as an artifact the
|
|
4172
|
-
runtime serves but nothing hands back, so its only source copy is the machine
|
|
4173
|
-
that pushed it. Pull it, fix it, redeploy it.
|
|
4174
|
-
Defaults to the version installed on the target project; --version overrides.
|
|
4175
|
-
--dir defaults to ./<packId>; a non-empty dir needs --force.
|
|
4176
|
-
The pulled dir redeploys where it came from — the target is your saved login.
|
|
4985
|
+
pull: `octwin pull <packId> [--dir <out>] [--version <v>] [--force]
|
|
4986
|
+
Write a DEPLOYED pack's source back to disk — the inverse of deploy.
|
|
4987
|
+
A pack pushed with 'octwin deploy' lives on the platform as an artifact the
|
|
4988
|
+
runtime serves but nothing hands back, so its only source copy is the machine
|
|
4989
|
+
that pushed it. Pull it, fix it, redeploy it.
|
|
4990
|
+
Defaults to the version installed on the target project; --version overrides.
|
|
4991
|
+
--dir defaults to ./<packId>; a non-empty dir needs --force.
|
|
4992
|
+
The pulled dir redeploys where it came from — the target is your saved login.
|
|
4177
4993
|
You may pull a pack your tenant OWNS (deployed); an operator token pulls any.`,
|
|
4178
|
-
chat: `octwin chat "message" [--as <handle>] [--tap <tap-id>] [--media <file|id>] [--json]
|
|
4179
|
-
octwin chat --script <file> [--as <handle>] [--json]
|
|
4180
|
-
Drive ONE turn through the dev web channel and print every render with its
|
|
4181
|
-
tap ids. Same --as handle = same conversation (multi-turn works).
|
|
4182
|
-
--tap presses a rendered button/list row instead of sending text.
|
|
4183
|
-
--media uploads a local file (or a media id from 'media generate --json') as
|
|
4184
|
-
an image/document/audio inbound — any "message" rides as its caption; feeds a
|
|
4185
|
-
running media-collect flow (e.g. activate-app).
|
|
4186
|
-
--json dumps the raw SSE envelopes for the turn.
|
|
4187
|
-
|
|
4188
|
-
--script drives a WHOLE conversation from a file, ONE TURN PER LINE, in one
|
|
4189
|
-
process over one connection — waiting for each turn to settle before sending
|
|
4190
|
-
the next. Use this for any multi-step flow: chaining shell invocations races
|
|
4191
|
-
the agent loop, because a turn ends on a quiet gap that can arrive while the
|
|
4192
|
-
server is still working (the symptom is placeholder-filled fields or a second
|
|
4193
|
-
workflow run). Blank lines and # comments are skipped:
|
|
4194
|
-
|
|
4195
|
-
# book an appointment end to end
|
|
4196
|
-
احجز موعد
|
|
4197
|
-
tap:t:invoke:book-appointment:doctor_id=D1
|
|
4198
|
-
media:./licence.jpg | here is my licence
|
|
4994
|
+
chat: `octwin chat "message" [--as <handle>] [--tap <tap-id>] [--media <file|id>] [--json]
|
|
4995
|
+
octwin chat --script <file> [--as <handle>] [--json]
|
|
4996
|
+
Drive ONE turn through the dev web channel and print every render with its
|
|
4997
|
+
tap ids. Same --as handle = same conversation (multi-turn works).
|
|
4998
|
+
--tap presses a rendered button/list row instead of sending text.
|
|
4999
|
+
--media uploads a local file (or a media id from 'media generate --json') as
|
|
5000
|
+
an image/document/audio inbound — any "message" rides as its caption; feeds a
|
|
5001
|
+
running media-collect flow (e.g. activate-app).
|
|
5002
|
+
--json dumps the raw SSE envelopes for the turn.
|
|
5003
|
+
|
|
5004
|
+
--script drives a WHOLE conversation from a file, ONE TURN PER LINE, in one
|
|
5005
|
+
process over one connection — waiting for each turn to settle before sending
|
|
5006
|
+
the next. Use this for any multi-step flow: chaining shell invocations races
|
|
5007
|
+
the agent loop, because a turn ends on a quiet gap that can arrive while the
|
|
5008
|
+
server is still working (the symptom is placeholder-filled fields or a second
|
|
5009
|
+
workflow run). Blank lines and # comments are skipped:
|
|
5010
|
+
|
|
5011
|
+
# book an appointment end to end
|
|
5012
|
+
احجز موعد
|
|
5013
|
+
tap:t:invoke:book-appointment:doctor_id=D1
|
|
5014
|
+
media:./licence.jpg | here is my licence
|
|
4199
5015
|
tap:t:resume:book-appointment:run_id=R1;_ctl_approved=true`,
|
|
4200
|
-
media: `octwin media generate "<prompt>" [--out <file.png>] [--json]
|
|
4201
|
-
AI-generate an image (needs a media:generate-scoped token), store it as a
|
|
4202
|
-
public asset, and print its MEDIA- handle + serve URL. --out downloads the
|
|
4203
|
-
bytes (WhatsApp renders only .png/.jpg); --json emits { media_id, url, mime,
|
|
5016
|
+
media: `octwin media generate "<prompt>" [--out <file.png>] [--json]
|
|
5017
|
+
AI-generate an image (needs a media:generate-scoped token), store it as a
|
|
5018
|
+
public asset, and print its MEDIA- handle + serve URL. --out downloads the
|
|
5019
|
+
bytes (WhatsApp renders only .png/.jpg); --json emits { media_id, url, mime,
|
|
4204
5020
|
bytes }. Pair with 'octwin chat --media' to drive media flows.`,
|
|
4205
|
-
agents: `octwin agents [packId::agentId] [--prompt] [--json]
|
|
4206
|
-
No args = the roster with each agent's EFFECTIVE model and which layer set it.
|
|
4207
|
-
With an agent = every governed setting (model / memory.last_messages /
|
|
4208
|
-
working_memory) plus the layer that won — an operator PLATFORM default can
|
|
4209
|
-
override what your manifest declares, and this is where you see that.
|
|
4210
|
-
--prompt = the exact system prompt the LLM sees for this project (pack
|
|
4211
|
-
instructions + platform protocol + any project overlay). Needs agents:read.
|
|
4212
|
-
The agent ref is the compound \`<packId>::<agentId>\` key or the override-row UUID.
|
|
4213
|
-
|
|
4214
|
-
WRITES (need \`agents:write\`):
|
|
4215
|
-
octwin agents set <ref> [--model <m>] [--enabled true|false] [--overlay "..."|none]
|
|
4216
|
-
[--enable-tool <toolId>] [--disable-tool <toolId>]
|
|
4217
|
-
|
|
4218
|
-
Only what you pass is changed. Tool flags read-modify-write \`config_json.tools\`
|
|
4219
|
-
so a sibling decision isn't dropped; absent = enabled. A workspace that hides model
|
|
5021
|
+
agents: `octwin agents [packId::agentId] [--prompt] [--json]
|
|
5022
|
+
No args = the roster with each agent's EFFECTIVE model and which layer set it.
|
|
5023
|
+
With an agent = every governed setting (model / memory.last_messages /
|
|
5024
|
+
working_memory) plus the layer that won — an operator PLATFORM default can
|
|
5025
|
+
override what your manifest declares, and this is where you see that.
|
|
5026
|
+
--prompt = the exact system prompt the LLM sees for this project (pack
|
|
5027
|
+
instructions + platform protocol + any project overlay). Needs agents:read.
|
|
5028
|
+
The agent ref is the compound \`<packId>::<agentId>\` key or the override-row UUID.
|
|
5029
|
+
|
|
5030
|
+
WRITES (need \`agents:write\`):
|
|
5031
|
+
octwin agents set <ref> [--model <m>] [--enabled true|false] [--overlay "..."|none]
|
|
5032
|
+
[--enable-tool <toolId>] [--disable-tool <toolId>]
|
|
5033
|
+
|
|
5034
|
+
Only what you pass is changed. Tool flags read-modify-write \`config_json.tools\`
|
|
5035
|
+
so a sibling decision isn't dropped; absent = enabled. A workspace that hides model
|
|
4220
5036
|
ids refuses --model with a 403 — the platform default governs there.`,
|
|
4221
|
-
orders: `octwin orders [reference_id] [--status s] [--payment p] [--limit 50] [--json]
|
|
4222
|
-
No args = the order list (#number, status/payment, total, contact). With a
|
|
4223
|
-
reference_id = line items, the subtotal/tax/shipping/discount/total breakdown,
|
|
4224
|
-
payment_ref, and the allowed status transitions. Needs orders:read + the
|
|
4225
|
-
\`orders\` plan feature. Note: the forward payment lifecycle is webhook-owned,
|
|
4226
|
-
so \`pending\` on a gateway-less workspace is expected, not a bug.
|
|
4227
|
-
|
|
4228
|
-
WRITES (need \`orders:write\`):
|
|
4229
|
-
octwin orders transition <reference_id> --to <status>
|
|
4230
|
-
octwin orders refund <reference_id> [--reason "..."] [--mark-returned] --force
|
|
4231
|
-
|
|
4232
|
-
Refund is irreversible and moves money, hence --force. The route answers 200 even
|
|
4233
|
-
when the GATEWAY refuses, so the CLI reads the gateway verdict and exits non-zero
|
|
4234
|
-
on a refusal rather than reporting a refund that never happened. Only a payment in
|
|
5037
|
+
orders: `octwin orders [reference_id] [--status s] [--payment p] [--limit 50] [--json]
|
|
5038
|
+
No args = the order list (#number, status/payment, total, contact). With a
|
|
5039
|
+
reference_id = line items, the subtotal/tax/shipping/discount/total breakdown,
|
|
5040
|
+
payment_ref, and the allowed status transitions. Needs orders:read + the
|
|
5041
|
+
\`orders\` plan feature. Note: the forward payment lifecycle is webhook-owned,
|
|
5042
|
+
so \`pending\` on a gateway-less workspace is expected, not a bug.
|
|
5043
|
+
|
|
5044
|
+
WRITES (need \`orders:write\`):
|
|
5045
|
+
octwin orders transition <reference_id> --to <status>
|
|
5046
|
+
octwin orders refund <reference_id> [--reason "..."] [--mark-returned] --force
|
|
5047
|
+
|
|
5048
|
+
Refund is irreversible and moves money, hence --force. The route answers 200 even
|
|
5049
|
+
when the GATEWAY refuses, so the CLI reads the gateway verdict and exits non-zero
|
|
5050
|
+
on a refusal rather than reporting a refund that never happened. Only a payment in
|
|
4235
5051
|
\`captured\` state can be refunded; \`payment_status\` is never settable directly.`,
|
|
4236
|
-
analytics: `octwin analytics [entity] [--funnel|--overview|--milestones|--trends|--cost] [--stage <id>] [--json]
|
|
4237
|
-
No args = the entities that carry a \`pipeline:\` (a funnel needs stages).
|
|
4238
|
-
With an entity = stage-by-stage conversion (default --funnel) over the last 30
|
|
4239
|
-
days. --stage <id> lists the records CURRENTLY at a stage (a live snapshot, not
|
|
5052
|
+
analytics: `octwin analytics [entity] [--funnel|--overview|--milestones|--trends|--cost] [--stage <id>] [--json]
|
|
5053
|
+
No args = the entities that carry a \`pipeline:\` (a funnel needs stages).
|
|
5054
|
+
With an entity = stage-by-stage conversion (default --funnel) over the last 30
|
|
5055
|
+
days. --stage <id> lists the records CURRENTLY at a stage (a live snapshot, not
|
|
4240
5056
|
range-filtered). Needs records:read + a \`view\` grant on \`record.<entity>\`.`,
|
|
4241
|
-
catalog: `octwin catalog [--readiness] [--json]
|
|
4242
|
-
The commerce \`product\` records + price, availability, stock (null = not
|
|
4243
|
-
inventory-tracked) and the WhatsApp catalog binding. --readiness runs the Meta
|
|
4244
|
-
Graph checklist (LIVE Graph calls; needs a bound access token). Needs
|
|
4245
|
-
catalog:read + the \`catalog\` plan feature.
|
|
4246
|
-
|
|
4247
|
-
WRITES (need \`catalog:write\`):
|
|
4248
|
-
octwin catalog availability <retailerId> --to "in stock"|"out of stock"|…
|
|
4249
|
-
octwin catalog stock <retailerId> [--set-on-hand <n>]
|
|
4250
|
-
|
|
4251
|
-
\`stock\` with no --set-on-hand READS it; \`null\` means the SKU is not
|
|
4252
|
-
inventory-tracked (always sellable), which is different from 0. Lowering on_hand
|
|
4253
|
-
below the units already reserved for open carts is refused. Creating/deleting
|
|
5057
|
+
catalog: `octwin catalog [--readiness] [--json]
|
|
5058
|
+
The commerce \`product\` records + price, availability, stock (null = not
|
|
5059
|
+
inventory-tracked) and the WhatsApp catalog binding. --readiness runs the Meta
|
|
5060
|
+
Graph checklist (LIVE Graph calls; needs a bound access token). Needs
|
|
5061
|
+
catalog:read + the \`catalog\` plan feature.
|
|
5062
|
+
|
|
5063
|
+
WRITES (need \`catalog:write\`):
|
|
5064
|
+
octwin catalog availability <retailerId> --to "in stock"|"out of stock"|…
|
|
5065
|
+
octwin catalog stock <retailerId> [--set-on-hand <n>]
|
|
5066
|
+
|
|
5067
|
+
\`stock\` with no --set-on-hand READS it; \`null\` means the SKU is not
|
|
5068
|
+
inventory-tracked (always sellable), which is different from 0. Lowering on_hand
|
|
5069
|
+
below the units already reserved for open carts is refused. Creating/deleting
|
|
4254
5070
|
products and the Meta catalog binding/sync stay in the console.`,
|
|
4255
|
-
scheduling: `octwin scheduling [--slots <resourceRecordId>] [--from YYYY-MM-DD] [--days n] [--json]
|
|
4256
|
-
No args = the engine state (bookable resource types, upcoming slots, booked
|
|
4257
|
-
seats). --slots <recordId> computes the slots for one bookable resource
|
|
4258
|
-
(occupancy included; --days is clamped to 1-31 server-side) — the way to verify
|
|
4259
|
-
the availability rules a \`deploy --seed\` created. Needs scheduling:read.
|
|
4260
|
-
|
|
4261
|
-
RULES (list needs scheduling:read; add/rm need scheduling:write):
|
|
4262
|
-
octwin scheduling rules --resource <resourceRecordId>
|
|
4263
|
-
octwin scheduling rule add --resource <id> --dow 1 --start 09:00 --end 17:00
|
|
4264
|
-
[--slot-minutes 30] [--capacity 1]
|
|
4265
|
-
octwin scheduling rule rm <ruleId>
|
|
4266
|
-
octwin scheduling exception add --resource <id> --date YYYY-MM-DD --kind closed|extra
|
|
4267
|
-
[--start 09:00 --end 13:00]
|
|
4268
|
-
octwin scheduling exception rm <exceptionId>
|
|
4269
|
-
|
|
4270
|
-
--dow is 0-6, 0 = Sunday. \`rules\` is how you find an id to remove, and
|
|
5071
|
+
scheduling: `octwin scheduling [--slots <resourceRecordId>] [--from YYYY-MM-DD] [--days n] [--json]
|
|
5072
|
+
No args = the engine state (bookable resource types, upcoming slots, booked
|
|
5073
|
+
seats). --slots <recordId> computes the slots for one bookable resource
|
|
5074
|
+
(occupancy included; --days is clamped to 1-31 server-side) — the way to verify
|
|
5075
|
+
the availability rules a \`deploy --seed\` created. Needs scheduling:read.
|
|
5076
|
+
|
|
5077
|
+
RULES (list needs scheduling:read; add/rm need scheduling:write):
|
|
5078
|
+
octwin scheduling rules --resource <resourceRecordId>
|
|
5079
|
+
octwin scheduling rule add --resource <id> --dow 1 --start 09:00 --end 17:00
|
|
5080
|
+
[--slot-minutes 30] [--capacity 1]
|
|
5081
|
+
octwin scheduling rule rm <ruleId>
|
|
5082
|
+
octwin scheduling exception add --resource <id> --date YYYY-MM-DD --kind closed|extra
|
|
5083
|
+
[--start 09:00 --end 13:00]
|
|
5084
|
+
octwin scheduling exception rm <exceptionId>
|
|
5085
|
+
|
|
5086
|
+
--dow is 0-6, 0 = Sunday. \`rules\` is how you find an id to remove, and
|
|
4271
5087
|
\`--slots\` is how you check what a rule actually produces.`,
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
5088
|
+
automation: `octwin automation [campaigns] [--limit n] [--offset n] [--json]
|
|
5089
|
+
No args = every job the pack's automation declaration produced, with its status,
|
|
5090
|
+
interval and LAST RESULT (matched / acted / errors), under a health line whose
|
|
5091
|
+
counts come from SQL rather than from filtering the page — the job list is capped
|
|
5092
|
+
server-side, so a client-side count would depend on the cap. Needs automation:read.
|
|
5093
|
+
|
|
5094
|
+
Jobs are DERIVED from declarations. There is no \`create\`: no automation block in
|
|
5095
|
+
the pack means no jobs, and \`octwin deploy\` is what installs them.
|
|
5096
|
+
|
|
5097
|
+
WRITES (automation:write):
|
|
5098
|
+
octwin automation run <jobId> # run once, now — prints matched/acted/errors
|
|
5099
|
+
octwin automation pause|resume <jobId>
|
|
5100
|
+
octwin automation send <campaignId> # enqueue a campaign; enqueued != delivered
|
|
5101
|
+
|
|
5102
|
+
<jobId> is the \`key\` the list shows (its uuid works too). The routes themselves
|
|
5103
|
+
accept only a uuid — the CLI resolves the key for you, and names the keys that do
|
|
5104
|
+
exist when it cannot. A 403 on a write can be an RBAC grant gap rather than a
|
|
5105
|
+
missing scope: the action is re-checked against the job.`,
|
|
5106
|
+
integrations: `octwin integrations [--json]
|
|
5107
|
+
What the pack DECLARES beside what is actually CONFIGURED, in one view — because a
|
|
5108
|
+
connection that is declared and never configured is the commonest reason an
|
|
5109
|
+
integration silently never fires, and neither list alone can show it. Flags the
|
|
5110
|
+
gap explicitly. Needs integrations:read.
|
|
5111
|
+
|
|
5112
|
+
DIAGNOSE ONE CONNECTION:
|
|
5113
|
+
octwin integrations preflight <key> # every check, with a fix hint. Makes NO
|
|
5114
|
+
# outbound call — needs only integrations:read
|
|
5115
|
+
octwin integrations test <key> # a LIVE call to its health: operation
|
|
5116
|
+
# (integrations:write). Exits 1 when it fails.
|
|
5117
|
+
|
|
5118
|
+
THE DELIVERY LOG:
|
|
5119
|
+
octwin integrations deliveries [--status s] [--operation id] [--limit n]
|
|
5120
|
+
octwin integrations deliveries <id> # + the redacted request/response snapshots
|
|
5121
|
+
octwin integrations retry|cancel|send-now <id> # integrations:write
|
|
5122
|
+
octwin integrations events # INBOUND events (what arrived at your webhook)
|
|
5123
|
+
|
|
5124
|
+
retry/cancel answer 409 when the delivery is in the wrong state; the message
|
|
5125
|
+
carries the rule.`,
|
|
5126
|
+
journeys: `octwin journeys [journeyId] [--funnel|--overview|--goals|--trends|--cost|--definition]
|
|
5127
|
+
[--stage <stageId>] [--limit n] [--json]
|
|
5128
|
+
No args = the journeys the pack declares. With an id, one of six views —
|
|
5129
|
+
--funnel (default) stage-by-stage reach and drop-off · --overview entered vs
|
|
5130
|
+
converted plus the biggest drop-off · --goals completions, contacts, value and
|
|
5131
|
+
p50 time · --trends per-bucket activity · --cost tokens and dollars per goal ·
|
|
5132
|
+
--definition what was DECLARED, unmeasured (the one view that works with no
|
|
5133
|
+
traffic). Needs journeys:read.
|
|
5134
|
+
|
|
5135
|
+
--stage <stageId> lists the runs sitting at a stage right now (a live snapshot,
|
|
5136
|
+
not the funnel's cumulative reached counts).
|
|
5137
|
+
|
|
5138
|
+
Same flag grammar as \`octwin analytics\` on purpose: a journey funnel and an
|
|
5139
|
+
entity funnel are the same question about different subjects. Journeys carry RBAC
|
|
5140
|
+
on top of the scope, so an empty answer can be a missing \`view\` grant rather
|
|
5141
|
+
than missing data — the output says which causes are possible.`,
|
|
5142
|
+
performance: `octwin performance [--detail] [--json]
|
|
5143
|
+
The project's business indicators — value produced, conversion, duration — each
|
|
5144
|
+
with its delta against the previous window and a \`why\` naming the declaration it
|
|
5145
|
+
came from. --detail adds the per-indicator breakdown.
|
|
5146
|
+
|
|
5147
|
+
Needs records:read, NOT a performance scope (there is none), so a read-only token
|
|
5148
|
+
already reaches it. Indicators are DERIVED: a pack that declares no journey goal
|
|
5149
|
+
value and no pipelined entity produces none, which is a different thing from zero.`,
|
|
5150
|
+
usage: `octwin usage [--json]
|
|
5151
|
+
Model calls, tokens and cost for the resolved scope — project when one is pinned
|
|
5152
|
+
or passed with --project, otherwise the whole workspace. Broken down by model,
|
|
5153
|
+
kind, agent and channel.
|
|
5154
|
+
|
|
5155
|
+
Needs no particular scope: any valid token reaches it.
|
|
5156
|
+
|
|
5157
|
+
This is MODEL spend only. WhatsApp/Meta message billing is operator-only and
|
|
5158
|
+
deliberately outside the token scope registry — no API token can read it.`,
|
|
5159
|
+
'platform-kb': `octwin platform-kb [pull] [--if-stale] [--check] [--dir .] [--url <url>] [--token <t>]
|
|
5160
|
+
Pull the platform capability reference (markdown + JSON catalogs) into
|
|
5161
|
+
.octwin/platform-kb/ for the octwin-pack authoring skill, plus three maps:
|
|
5162
|
+
INDEX.md (the corpus) · SYMBOLS.md (every name -> its file; grep this) ·
|
|
5163
|
+
OUTLINE.md (every heading with its line number).
|
|
5164
|
+
|
|
5165
|
+
NO TOKEN NEEDED — the reference is platform stdlib and is served anonymously.
|
|
5166
|
+
A token is used when you have one (it also works against older platforms).
|
|
5167
|
+
|
|
5168
|
+
--if-stale poll the platform's content_hash first and skip the download when
|
|
5169
|
+
nothing changed. Cheap enough to run at the start of every session.
|
|
5170
|
+
--check report only, write nothing. Exit 0 = current, 2 = stale or never
|
|
5171
|
+
pulled, 1 = could not tell (offline / refused). For scripts and
|
|
4285
5172
|
agent loops that want to branch without parsing prose.`,
|
|
4286
|
-
test: `octwin test [--dir .]
|
|
5173
|
+
test: `octwin test [--dir .]
|
|
4287
5174
|
Alias for \`octwin validate --remote\` — the full platform check.`,
|
|
4288
|
-
memos: `octwin memos [--all] [--json]
|
|
4289
|
-
Read what the platform has told you: a REPLY to a report you sent with
|
|
4290
|
-
\`octwin feedback\`, or a NOTICE published to every author (a new capability,
|
|
4291
|
-
a deprecation, a breaking change). Bodies are printed in full.
|
|
4292
|
-
Reading marks them read, so the reminder stops. --all re-reads history and
|
|
4293
|
-
acks nothing. --json to branch on \`severity\`
|
|
5175
|
+
memos: `octwin memos [--all] [--json]
|
|
5176
|
+
Read what the platform has told you: a REPLY to a report you sent with
|
|
5177
|
+
\`octwin feedback\`, or a NOTICE published to every author (a new capability,
|
|
5178
|
+
a deprecation, a breaking change). Bodies are printed in full.
|
|
5179
|
+
Reading marks them read, so the reminder stops. --all re-reads history and
|
|
5180
|
+
acks nothing. --json to branch on \`severity\`
|
|
4294
5181
|
(info | action_required | breaking).`,
|
|
4295
|
-
feedback: `octwin feedback [--dir .]
|
|
4296
|
-
Submit this pack's FEEDBACK.md to the platform team.
|
|
4297
|
-
The octwin-pack skill writes that file in its last step — findings grouped by
|
|
4298
|
-
owner (A · CLI, B · Platform, C · Skill/KB). This delivers it instead of asking
|
|
4299
|
-
you to paste it into a chat.
|
|
4300
|
-
Attaches the pack id + version from manifest.yaml, this CLI's version, and the
|
|
4301
|
-
content_hash of the capability reference in .octwin/platform-kb/ — triage needs
|
|
4302
|
-
the last two to tell "the platform is wrong" from "that was already fixed" or
|
|
5182
|
+
feedback: `octwin feedback [--dir .]
|
|
5183
|
+
Submit this pack's FEEDBACK.md to the platform team.
|
|
5184
|
+
The octwin-pack skill writes that file in its last step — findings grouped by
|
|
5185
|
+
owner (A · CLI, B · Platform, C · Skill/KB). This delivers it instead of asking
|
|
5186
|
+
you to paste it into a chat.
|
|
5187
|
+
Attaches the pack id + version from manifest.yaml, this CLI's version, and the
|
|
5188
|
+
content_hash of the capability reference in .octwin/platform-kb/ — triage needs
|
|
5189
|
+
the last two to tell "the platform is wrong" from "that was already fixed" or
|
|
4303
5190
|
"you were reading a stale reference". Needs the \`pack:deploy\` scope.`,
|
|
4304
5191
|
};
|
|
4305
5192
|
async function main() {
|
|
@@ -4393,6 +5280,21 @@ async function main() {
|
|
|
4393
5280
|
case 'scheduling':
|
|
4394
5281
|
await cmdScheduling(flags);
|
|
4395
5282
|
break;
|
|
5283
|
+
case 'automation':
|
|
5284
|
+
await cmdAutomation(flags);
|
|
5285
|
+
break;
|
|
5286
|
+
case 'integrations':
|
|
5287
|
+
await cmdIntegrations(flags);
|
|
5288
|
+
break;
|
|
5289
|
+
case 'journeys':
|
|
5290
|
+
await cmdJourneys(flags);
|
|
5291
|
+
break;
|
|
5292
|
+
case 'performance':
|
|
5293
|
+
await cmdPerformance(flags);
|
|
5294
|
+
break;
|
|
5295
|
+
case 'usage':
|
|
5296
|
+
await cmdUsage(flags);
|
|
5297
|
+
break;
|
|
4396
5298
|
case 'platform-kb':
|
|
4397
5299
|
await cmdPlatformKb(flags);
|
|
4398
5300
|
break;
|