@geoly-ai/social-hub-cli 0.3.49 → 0.3.51

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/cmd-manifest.json +22 -2
  3. package/dist/cmd-manifest.test.js +10 -0
  4. package/dist/cmd-manifest.test.js.map +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +11 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/permissions-gates-client-delivery-brands.d.ts +10 -0
  9. package/dist/permissions-gates-client-delivery-brands.d.ts.map +1 -0
  10. package/dist/permissions-gates-client-delivery-brands.js +28 -0
  11. package/dist/permissions-gates-client-delivery-brands.js.map +1 -0
  12. package/dist/permissions-gates-client-delivery-brands.test.d.ts +2 -0
  13. package/dist/permissions-gates-client-delivery-brands.test.d.ts.map +1 -0
  14. package/dist/permissions-gates-client-delivery-brands.test.js +41 -0
  15. package/dist/permissions-gates-client-delivery-brands.test.js.map +1 -0
  16. package/dist/permissions-gates-intake.d.ts +1 -0
  17. package/dist/permissions-gates-intake.d.ts.map +1 -1
  18. package/dist/permissions-gates-intake.js +36 -0
  19. package/dist/permissions-gates-intake.js.map +1 -1
  20. package/dist/permissions-gates-intake.test.js +22 -5
  21. package/dist/permissions-gates-intake.test.js.map +1 -1
  22. package/dist/permissions.d.ts.map +1 -1
  23. package/dist/permissions.js +4 -1
  24. package/dist/permissions.js.map +1 -1
  25. package/dist/register-client-delivery-brands.d.ts +14 -0
  26. package/dist/register-client-delivery-brands.d.ts.map +1 -0
  27. package/dist/register-client-delivery-brands.js +131 -0
  28. package/dist/register-client-delivery-brands.js.map +1 -0
  29. package/dist/register-client-delivery-brands.test.d.ts +2 -0
  30. package/dist/register-client-delivery-brands.test.d.ts.map +1 -0
  31. package/dist/register-client-delivery-brands.test.js +109 -0
  32. package/dist/register-client-delivery-brands.test.js.map +1 -0
  33. package/dist/register-intake-ops.d.ts +88 -0
  34. package/dist/register-intake-ops.d.ts.map +1 -0
  35. package/dist/register-intake-ops.js +572 -0
  36. package/dist/register-intake-ops.js.map +1 -0
  37. package/dist/register-intake-ops.test.d.ts +2 -0
  38. package/dist/register-intake-ops.test.d.ts.map +1 -0
  39. package/dist/register-intake-ops.test.js +300 -0
  40. package/dist/register-intake-ops.test.js.map +1 -0
  41. package/dist/register-intake.d.ts.map +1 -1
  42. package/dist/register-intake.js +2 -0
  43. package/dist/register-intake.js.map +1 -1
  44. package/dist/register-media.d.ts +38 -0
  45. package/dist/register-media.d.ts.map +1 -0
  46. package/dist/register-media.js +188 -0
  47. package/dist/register-media.js.map +1 -0
  48. package/dist/register-media.test.d.ts +2 -0
  49. package/dist/register-media.test.d.ts.map +1 -0
  50. package/dist/register-media.test.js +349 -0
  51. package/dist/register-media.test.js.map +1 -0
  52. package/dist/skill-update-check.test.js +7 -1
  53. package/dist/skill-update-check.test.js.map +1 -1
  54. package/dist/update-check.test.js +9 -1
  55. package/dist/update-check.test.js.map +1 -1
  56. package/package.json +3 -3
  57. package/skills/integrity.json +4 -4
  58. package/skills/manifest.json +1 -1
  59. package/skills/social-hub-admin/SKILL.md +94 -2
  60. package/skills/social-hub-cli/SKILL.md +1 -0
  61. package/skills/social-hub-publishing/SKILL.md +35 -0
@@ -0,0 +1,88 @@
1
+ import type { Command } from "commander";
2
+ import type { AcceptIntakeOrderInput, ConfirmIntakeOrderPublishedInput, EditIntakeOrderDraftInput, FailIntakeOrderInput, ListIntakeOpsOrdersParams, ProvideIntakeThreadContextInput, ReReviewIntakeOrderInput, RegisterIntakeOrderAnomalyInput, RejectIntakeOrderInput, ScheduleIntakeOrderInput, StartIntakeOrderInput } from "@geoly-ai/social-hub-sdk";
3
+ import { resolveJsonArg } from "./lib/json-arg.js";
4
+ /**
5
+ * 派单运营面 —— `social-hub intake ops ...`(B5-ext E3)。
6
+ *
7
+ * 系统级命令(不要求 `-t`),对应 API `/v1/system/intake-ops/*`:准入 = admin,或全局 manager 且是接单团队的真实 active 成员;
8
+ * 受限 CLI token / API key / 服务凭据 API 侧全 403。权限门资源 `systemIntakeOrder`(admin + manager)。
9
+ * 写命令一律 `--dry-run` / `--apply` 双闸,且必须带 `--row-version`(乐观锁;异常登记可选,同 API)。
10
+ * 需要结构化入参的命令支持 `-j/--json`(内联 / `@文件` / `-` 读 stdin),显式 flag 覆盖 JSON 里的同名字段;
11
+ * `rowVersion` 只能走 `--row-version`,不接受放进 JSON(防止漏传被 JSON 里的陈旧值掩盖)。
12
+ */
13
+ export declare class CliInputError extends Error {
14
+ }
15
+ export declare function requireHubRef(value: unknown): string;
16
+ type JsonOpts = {
17
+ json?: string;
18
+ };
19
+ /** 读 `-j`(内联 / @文件 / -):必须是对象;`rowVersion` 不得出现在里面。未给返回 {}。 */
20
+ export declare function readPayload(opts: JsonOpts, deps?: Parameters<typeof resolveJsonArg>[1]): Record<string, unknown>;
21
+ export declare function buildListOpsParams(opts: {
22
+ status?: string;
23
+ kind?: string;
24
+ deliveryChannel?: string;
25
+ brandId?: string;
26
+ limit?: string;
27
+ offset?: string;
28
+ }): ListIntakeOpsOrdersParams;
29
+ export declare function buildAcceptBody(opts: {
30
+ rowVersion?: string;
31
+ channel?: string;
32
+ note?: string;
33
+ ackUnknownLock?: boolean;
34
+ }): AcceptIntakeOrderInput;
35
+ export declare function buildRejectBody(opts: {
36
+ rowVersion?: string;
37
+ reasonCode?: string;
38
+ internalNote?: string;
39
+ }): RejectIntakeOrderInput;
40
+ export declare function buildPasteBody(opts: {
41
+ rowVersion?: string;
42
+ lockStatus?: string;
43
+ ackUnknownLock?: boolean;
44
+ }, snapshot: Record<string, unknown>): ProvideIntakeThreadContextInput;
45
+ export declare function buildEditBody(opts: {
46
+ rowVersion?: string;
47
+ title?: string;
48
+ body?: string;
49
+ clearTitle?: boolean;
50
+ }, payload: Record<string, unknown>): EditIntakeOrderDraftInput;
51
+ export declare function buildScheduleBody(opts: {
52
+ rowVersion?: string;
53
+ plannedAt?: string;
54
+ }): ScheduleIntakeOrderInput;
55
+ export declare function buildReReviewBody(opts: {
56
+ rowVersion?: string;
57
+ reason?: string;
58
+ }): ReReviewIntakeOrderInput;
59
+ export declare function buildStartBody(opts: {
60
+ rowVersion?: string;
61
+ }): StartIntakeOrderInput;
62
+ export declare function buildConfirmBody(opts: {
63
+ rowVersion?: string;
64
+ permalink?: string;
65
+ postedAt?: string;
66
+ finalBody?: string;
67
+ finalTitle?: string;
68
+ executedBy?: string;
69
+ deviationNote?: string;
70
+ }, payload: Record<string, unknown>): ConfirmIntakeOrderPublishedInput;
71
+ export declare function buildFailBody(opts: {
72
+ rowVersion?: string;
73
+ reasonCode?: string;
74
+ confirmNotPublished?: boolean;
75
+ internalNote?: string;
76
+ }): FailIntakeOrderInput;
77
+ export declare function buildAnomalyBody(opts: {
78
+ rowVersion?: string;
79
+ reasonCode?: string;
80
+ permalink?: string;
81
+ postedAt?: string;
82
+ finalBody?: string;
83
+ note?: string;
84
+ }, payload: Record<string, unknown>): RegisterIntakeOrderAnomalyInput;
85
+ export declare function redactIntakeOpsPreview(value: unknown): unknown;
86
+ export declare function registerIntakeOpsCommands(intake: Command): void;
87
+ export {};
88
+ //# sourceMappingURL=register-intake-ops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-intake-ops.d.ts","sourceRoot":"","sources":["../src/register-intake-ops.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EACV,sBAAsB,EACtB,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,yBAAyB,EACzB,+BAA+B,EAC/B,wBAAwB,EACxB,+BAA+B,EAC/B,sBAAsB,EACtB,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD;;;;;;;;GAQG;AAEH,qBAAa,aAAc,SAAQ,KAAK;CAA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B,gBAAgB,CAC9B,IAAI,EAAE;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,EACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,+BAA+B,CAqCjC;AA6BD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiB9D;AAID,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CA0W/D"}
@@ -0,0 +1,572 @@
1
+ import { requireClient } from "./client.js";
2
+ import { assertApplyOrDryRun } from "./dry-run.js";
3
+ import { resolveJsonArg } from "./lib/json-arg.js";
4
+ import { printResult, withCliErrorBoundary } from "./output.js";
5
+ import { withPermissionGates } from "./permission-runner.js";
6
+ /**
7
+ * 派单运营面 —— `social-hub intake ops ...`(B5-ext E3)。
8
+ *
9
+ * 系统级命令(不要求 `-t`),对应 API `/v1/system/intake-ops/*`:准入 = admin,或全局 manager 且是接单团队的真实 active 成员;
10
+ * 受限 CLI token / API key / 服务凭据 API 侧全 403。权限门资源 `systemIntakeOrder`(admin + manager)。
11
+ * 写命令一律 `--dry-run` / `--apply` 双闸,且必须带 `--row-version`(乐观锁;异常登记可选,同 API)。
12
+ * 需要结构化入参的命令支持 `-j/--json`(内联 / `@文件` / `-` 读 stdin),显式 flag 覆盖 JSON 里的同名字段;
13
+ * `rowVersion` 只能走 `--row-version`,不接受放进 JSON(防止漏传被 JSON 里的陈旧值掩盖)。
14
+ */
15
+ export class CliInputError extends Error {
16
+ }
17
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
18
+ const CHANNELS = ["internal", "external_manual"];
19
+ const REJECT_CODES = [
20
+ "TARGET_BLOCKED",
21
+ "NO_ELIGIBLE_ACCOUNT",
22
+ "RULES_VIOLATION",
23
+ ];
24
+ const FAIL_CODES = [
25
+ "TARGET_BLOCKED",
26
+ "RULES_VIOLATION",
27
+ "REVIEW_REJECTED",
28
+ ];
29
+ const ANOMALY_CODES = [
30
+ "REVIEW_NOT_PASSED",
31
+ "DISCLOSURE_MISSING",
32
+ "ORDER_CLOSED",
33
+ "CONTENT_UNREVIEWED",
34
+ "OTHER",
35
+ ];
36
+ const STATUSES = [
37
+ "received",
38
+ "accepted",
39
+ "rejected",
40
+ "scheduled",
41
+ "executing",
42
+ "published",
43
+ "failed",
44
+ "withdrawn",
45
+ "removed",
46
+ "deleted",
47
+ ];
48
+ const KINDS = ["reply", "post", "koc_campaign"];
49
+ const PASTE_LOCKS = ["unlocked", "unknown"];
50
+ function oneOf(flag, value, allowed) {
51
+ if (typeof value !== "string" ||
52
+ !allowed.includes(value)) {
53
+ throw new CliInputError(`${flag} must be one of: ${allowed.join(" | ")}`);
54
+ }
55
+ return value;
56
+ }
57
+ function int(flag, value, min) {
58
+ const n = Number(value);
59
+ if (!Number.isInteger(n) || n < min) {
60
+ throw new CliInputError(`${flag} must be an integer >= ${min}`);
61
+ }
62
+ return n;
63
+ }
64
+ function isoInstant(flag, value) {
65
+ // 与 API 的 z.string().datetime() 对齐:完整 ISO-8601 且带 Z(UTC);裸日期 / 本地时间被拒。
66
+ if (typeof value !== "string" ||
67
+ !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/.test(value) ||
68
+ !Number.isFinite(Date.parse(value))) {
69
+ throw new CliInputError(`${flag} must be a UTC ISO-8601 timestamp like 2026-11-10T08:00:00Z`);
70
+ }
71
+ return value;
72
+ }
73
+ function rowVersion(value) {
74
+ if (value === undefined) {
75
+ throw new CliInputError("--row-version is required (take it from `intake ops get <hubRef>`)");
76
+ }
77
+ return int("--row-version", value, 1);
78
+ }
79
+ export function requireHubRef(value) {
80
+ if (typeof value !== "string" || !UUID_RE.test(value)) {
81
+ throw new CliInputError("<hubRef> must be a uuid");
82
+ }
83
+ return value;
84
+ }
85
+ /** 读 `-j`(内联 / @文件 / -):必须是对象;`rowVersion` 不得出现在里面。未给返回 {}。 */
86
+ export function readPayload(opts, deps) {
87
+ const parsed = resolveJsonArg({ inline: opts.json }, deps);
88
+ if (parsed === undefined)
89
+ return {};
90
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
91
+ throw new CliInputError("-j/--json must be a JSON object");
92
+ }
93
+ if ("rowVersion" in parsed) {
94
+ throw new CliInputError("rowVersion must be passed with --row-version, not inside -j/--json");
95
+ }
96
+ return { ...parsed };
97
+ }
98
+ function need(payload, key, flag) {
99
+ if (payload[key] === undefined) {
100
+ throw new CliInputError(`${flag} is required (or provide "${key}" in -j)`);
101
+ }
102
+ }
103
+ /** 必填且必须是(非空)字符串;本地先拒,避免 --dry-run 对非法入参也打印「将要提交」。 */
104
+ function needString(payload, key, flag, opts = {}) {
105
+ need(payload, key, flag);
106
+ const v = payload[key];
107
+ if (typeof v !== "string" || (opts.nonEmpty !== false && v.trim() === "")) {
108
+ throw new CliInputError(`${flag} (${key}) must be a non-empty string`);
109
+ }
110
+ return v;
111
+ }
112
+ export function buildListOpsParams(opts) {
113
+ const p = {};
114
+ if (opts.status !== undefined)
115
+ p.status = oneOf("--status", opts.status, STATUSES);
116
+ if (opts.kind !== undefined)
117
+ p.kind = oneOf("--kind", opts.kind, KINDS);
118
+ if (opts.deliveryChannel !== undefined)
119
+ p.deliveryChannel = oneOf("--delivery-channel", opts.deliveryChannel, CHANNELS);
120
+ if (opts.brandId !== undefined) {
121
+ if (!UUID_RE.test(opts.brandId))
122
+ throw new CliInputError("--brand-id must be a uuid");
123
+ p.brandId = opts.brandId;
124
+ }
125
+ if (opts.limit !== undefined) {
126
+ p.limit = int("--limit", opts.limit, 1);
127
+ if (p.limit > 100)
128
+ throw new CliInputError("--limit must be <= 100");
129
+ }
130
+ if (opts.offset !== undefined)
131
+ p.offset = int("--offset", opts.offset, 0);
132
+ return p;
133
+ }
134
+ export function buildAcceptBody(opts) {
135
+ const body = {
136
+ channel: oneOf("--channel", opts.channel ?? "external_manual", CHANNELS),
137
+ rowVersion: rowVersion(opts.rowVersion),
138
+ };
139
+ if (opts.note !== undefined)
140
+ body.note = opts.note;
141
+ if (opts.ackUnknownLock)
142
+ body.acknowledgements = { unknownThreadLock: true };
143
+ return body;
144
+ }
145
+ export function buildRejectBody(opts) {
146
+ const body = {
147
+ reasonCode: oneOf("--reason-code", opts.reasonCode, REJECT_CODES),
148
+ rowVersion: rowVersion(opts.rowVersion),
149
+ };
150
+ if (opts.internalNote !== undefined)
151
+ body.internalNote = opts.internalNote;
152
+ return body;
153
+ }
154
+ export function buildPasteBody(opts, snapshot) {
155
+ if (Object.keys(snapshot).length === 0) {
156
+ throw new CliInputError("thread context snapshot is required: pass it as -j '<json>' | -j @file | -j -");
157
+ }
158
+ const body = {
159
+ snapshot,
160
+ lockStatus: oneOf("--lock-status", opts.lockStatus, PASTE_LOCKS),
161
+ rowVersion: rowVersion(opts.rowVersion),
162
+ };
163
+ if (opts.ackUnknownLock)
164
+ body.acknowledgements = { unknownThreadLock: true };
165
+ return body;
166
+ }
167
+ export function buildEditBody(opts, payload) {
168
+ const merged = { ...payload };
169
+ if (opts.title !== undefined)
170
+ merged["title"] = opts.title;
171
+ if (opts.clearTitle)
172
+ merged["title"] = null;
173
+ if (opts.body !== undefined)
174
+ merged["body"] = opts.body;
175
+ needString(merged, "body", "--body", { nonEmpty: false });
176
+ if (merged["title"] !== undefined &&
177
+ merged["title"] !== null &&
178
+ typeof merged["title"] !== "string") {
179
+ throw new CliInputError("--title (title) must be a string or null");
180
+ }
181
+ return {
182
+ ...merged,
183
+ rowVersion: rowVersion(opts.rowVersion),
184
+ };
185
+ }
186
+ export function buildScheduleBody(opts) {
187
+ return {
188
+ plannedAt: isoInstant("--planned-at", opts.plannedAt),
189
+ rowVersion: rowVersion(opts.rowVersion),
190
+ };
191
+ }
192
+ export function buildReReviewBody(opts) {
193
+ if (typeof opts.reason !== "string" || opts.reason.trim() === "") {
194
+ throw new CliInputError("--reason is required");
195
+ }
196
+ return { reason: opts.reason, rowVersion: rowVersion(opts.rowVersion) };
197
+ }
198
+ export function buildStartBody(opts) {
199
+ return { rowVersion: rowVersion(opts.rowVersion) };
200
+ }
201
+ export function buildConfirmBody(opts, payload) {
202
+ const merged = { ...payload };
203
+ if (opts.permalink !== undefined)
204
+ merged["permalink"] = opts.permalink;
205
+ if (opts.postedAt !== undefined)
206
+ merged["postedAt"] = opts.postedAt;
207
+ if (opts.finalBody !== undefined)
208
+ merged["finalBody"] = opts.finalBody;
209
+ if (opts.finalTitle !== undefined)
210
+ merged["finalTitle"] = opts.finalTitle;
211
+ if (opts.executedBy !== undefined)
212
+ merged["executedBy"] = opts.executedBy;
213
+ if (opts.deviationNote !== undefined) {
214
+ // 显式 ack:偏离审过内容的唯一入口,note 必填(服务端另校验)。
215
+ merged["contentDeviation"] = {
216
+ acknowledged: true,
217
+ note: opts.deviationNote,
218
+ };
219
+ }
220
+ needString(merged, "permalink", "--permalink");
221
+ needString(merged, "postedAt", "--posted-at");
222
+ needString(merged, "finalBody", "--final-body");
223
+ isoInstant("--posted-at", merged["postedAt"]);
224
+ return {
225
+ ...merged,
226
+ rowVersion: rowVersion(opts.rowVersion),
227
+ };
228
+ }
229
+ export function buildFailBody(opts) {
230
+ if (opts.confirmNotPublished !== true) {
231
+ throw new CliInputError("--confirm-not-published is required: confirm the post is NOT currently on Reddit (delete it first; if it was posted, `intake ops anomaly` first)");
232
+ }
233
+ const body = {
234
+ reasonCode: oneOf("--reason-code", opts.reasonCode, FAIL_CODES),
235
+ confirmNotPublished: true,
236
+ rowVersion: rowVersion(opts.rowVersion),
237
+ };
238
+ if (opts.internalNote !== undefined)
239
+ body.internalNote = opts.internalNote;
240
+ return body;
241
+ }
242
+ export function buildAnomalyBody(opts, payload) {
243
+ const merged = { ...payload };
244
+ if (opts.reasonCode !== undefined)
245
+ merged["reasonCode"] = opts.reasonCode;
246
+ if (opts.permalink !== undefined)
247
+ merged["permalink"] = opts.permalink;
248
+ if (opts.postedAt !== undefined)
249
+ merged["postedAt"] = opts.postedAt;
250
+ if (opts.finalBody !== undefined)
251
+ merged["finalBody"] = opts.finalBody;
252
+ if (opts.note !== undefined)
253
+ merged["note"] = opts.note;
254
+ need(merged, "reasonCode", "--reason-code");
255
+ const reasonCode = oneOf("--reason-code", merged["reasonCode"], ANOMALY_CODES);
256
+ needString(merged, "permalink", "--permalink");
257
+ needString(merged, "postedAt", "--posted-at");
258
+ isoInstant("--posted-at", merged["postedAt"]);
259
+ if (merged["note"] !== undefined && typeof merged["note"] !== "string") {
260
+ throw new CliInputError("--note (note) must be a string");
261
+ }
262
+ if (merged["finalBody"] !== undefined &&
263
+ typeof merged["finalBody"] !== "string") {
264
+ throw new CliInputError("--final-body (finalBody) must be a string");
265
+ }
266
+ if (reasonCode === "OTHER" &&
267
+ (typeof merged["note"] !== "string" || merged["note"].trim() === "")) {
268
+ throw new CliInputError("--note is required when --reason-code is OTHER");
269
+ }
270
+ const body = merged;
271
+ // 异常登记的 rowVersion 可选(登记事实不应因视图陈旧被拒);提供则必须合法并随请求比对。
272
+ if (opts.rowVersion !== undefined) {
273
+ body.rowVersion = int("--row-version", opts.rowVersion, 1);
274
+ }
275
+ return body;
276
+ }
277
+ const writeFlags = (cmd) => cmd
278
+ .option("--dry-run", "预览,不写入", false)
279
+ .option("--apply", "执行写入", false);
280
+ const jsonFlag = (cmd, hint) => cmd.option("-j, --json <json>", `${hint}。也可 -j @<path> 读文件 / -j - 读 stdin`);
281
+ /**
282
+ * dry-run 预览脱敏(主代理验收 M):正文 / 线程快照 / 备注等业务内容只显示长度,
283
+ * 不回显到终端或 CI 日志;rowVersion、枚举、时间、permalink、hubRef 等保留。
284
+ */
285
+ const INTAKE_OPS_PREVIEW_REDACT_KEYS = new Set([
286
+ "body",
287
+ "title",
288
+ "finalBody",
289
+ "finalTitle",
290
+ "snapshot",
291
+ "note",
292
+ "internalNote",
293
+ "reason",
294
+ "executedBy",
295
+ ]);
296
+ export function redactIntakeOpsPreview(value) {
297
+ if (Array.isArray(value))
298
+ return value.map(redactIntakeOpsPreview);
299
+ if (value === null || typeof value !== "object")
300
+ return value;
301
+ const out = {};
302
+ for (const [k, v] of Object.entries(value)) {
303
+ const sensitive = INTAKE_OPS_PREVIEW_REDACT_KEYS.has(k);
304
+ if (sensitive && typeof v === "string") {
305
+ out[k] = { redacted: true, length: v.length };
306
+ }
307
+ else if (sensitive && k === "snapshot" && v !== null && v !== undefined) {
308
+ // 线程快照整块是第三方内容:整体脱敏。
309
+ out[k] = { redacted: true, length: JSON.stringify(v).length };
310
+ }
311
+ else {
312
+ // 其余(含预览外壳里名为 body 的请求体对象)递归进去,只脱敏叶子文本。
313
+ out[k] = redactIntakeOpsPreview(v);
314
+ }
315
+ }
316
+ return out;
317
+ }
318
+ const RV_DESC = "订单当前 rowVersion(乐观锁;取自 `intake ops get`,409 = 过期)";
319
+ export function registerIntakeOpsCommands(intake) {
320
+ const ops = intake
321
+ .command("ops")
322
+ .description("CyberRedd 派单运营面(系统级,不需要 -t):admin,或接单团队的 manager 成员;受限 CLI token 不可用");
323
+ /** 公共骨架:校验 → 权限门 → 双闸 → 调 SDK。read 类 apply=false。 */
324
+ const guarded = async (args) => {
325
+ await withCliErrorBoundary(async () => {
326
+ const built = args.build();
327
+ await withPermissionGates({
328
+ command: args.command,
329
+ gates: [{ resource: "systemIntakeOrder", action: args.action }],
330
+ userOnly: true,
331
+ }, async () => {
332
+ if (args.action === "update" &&
333
+ !assertApplyOrDryRun(args.opts, {
334
+ command: args.command,
335
+ danger: args.danger ?? "writes an intake order",
336
+ summary: redactIntakeOpsPreview(args.summary ? args.summary(built) : built),
337
+ })) {
338
+ return;
339
+ }
340
+ printResult(await args.call(built));
341
+ });
342
+ });
343
+ };
344
+ ops
345
+ .command("list")
346
+ .description("GET /v1/system/intake-ops/orders — 派单列表(含 lockVerificationRequired)")
347
+ .option("--status <s>", "订单状态")
348
+ .option("--kind <k>", "订单类型")
349
+ .option("--delivery-channel <c>", "internal | external_manual")
350
+ .option("--brand-id <uuid>", "Hub 品牌 id")
351
+ .option("--limit <n>", "每页条数(1-100,默认 50)")
352
+ .option("--offset <n>", "偏移")
353
+ .action(async (opts) => {
354
+ await guarded({
355
+ command: "intake ops list",
356
+ action: "list",
357
+ build: () => buildListOpsParams(opts),
358
+ opts: {},
359
+ call: (p) => requireClient().listIntakeOpsOrders(p),
360
+ });
361
+ });
362
+ ops
363
+ .command("get")
364
+ .description("GET .../orders/:hubRef — 详情(rowVersion / checks / allowedActions / 线程语境 / 审核摘要)")
365
+ .argument("<hubRef>", "订单 hubRef(uuid)")
366
+ .action(async (hubRef) => {
367
+ await guarded({
368
+ command: "intake ops get",
369
+ action: "read",
370
+ build: () => requireHubRef(hubRef),
371
+ opts: {},
372
+ call: (h) => requireClient().getIntakeOpsOrder(h),
373
+ });
374
+ });
375
+ writeFlags(ops
376
+ .command("accept")
377
+ .description("POST .../accept — 接单(只支持 external_manual;受限板块 409 SUBREDDIT_RESTRICTED 不会自动拒单)")
378
+ .argument("<hubRef>", "订单 hubRef(uuid)")
379
+ .requiredOption("--row-version <n>", RV_DESC)
380
+ .option("--channel <c>", "internal | external_manual(默认 external_manual)")
381
+ .option("--note <text>", "接单备注(不得含邮箱 / 电话 / @handle)")
382
+ .option("--ack-unknown-lock", "确认已人工打开线程核实未锁定 / 未归档(lock_status=unknown 的 reply 单必带)")).action(async (hubRef, opts) => {
383
+ await guarded({
384
+ command: "intake ops accept",
385
+ action: "update",
386
+ build: () => ({
387
+ hubRef: requireHubRef(hubRef),
388
+ body: buildAcceptBody(opts),
389
+ }),
390
+ danger: "accepts the order for external manual delivery",
391
+ opts,
392
+ call: (b) => requireClient().acceptIntakeOrder(b.hubRef, b.body),
393
+ });
394
+ });
395
+ writeFlags(ops
396
+ .command("reject")
397
+ .description("POST .../reject — 拒单(原因码白名单;对外事件只带服务端模板文案)")
398
+ .argument("<hubRef>", "订单 hubRef(uuid)")
399
+ .requiredOption("--row-version <n>", RV_DESC)
400
+ .requiredOption("--reason-code <c>", REJECT_CODES.join(" | "))
401
+ .option("--internal-note <text>", "内部备注(只进审计,不对外)")).action(async (hubRef, opts) => {
402
+ await guarded({
403
+ command: "intake ops reject",
404
+ action: "update",
405
+ build: () => ({
406
+ hubRef: requireHubRef(hubRef),
407
+ body: buildRejectBody(opts),
408
+ }),
409
+ danger: "rejects the order (terminal; visible to CyberRedd)",
410
+ opts,
411
+ call: (b) => requireClient().rejectIntakeOrder(b.hubRef, b.body),
412
+ });
413
+ });
414
+ writeFlags(jsonFlag(ops
415
+ .command("paste-context")
416
+ .description("POST .../thread-context — 人工粘贴线程语境(reply 单);-j 是语境 snapshot 对象本身")
417
+ .argument("<hubRef>", "订单 hubRef(uuid)")
418
+ .requiredOption("--row-version <n>", RV_DESC)
419
+ .requiredOption("--lock-status <s>", "unlocked(已核实未锁定)| unknown(未核实,接单时仍要 --ack-unknown-lock);locked 的单应 reject")
420
+ .option("--ack-unknown-lock", "accepted 态写入 unknown 必须显式确认已核实线程未锁定"), "线程语境 snapshot(commentDraftThreadContext 形状)")).action(async (hubRef, opts) => {
421
+ await guarded({
422
+ command: "intake ops paste-context",
423
+ action: "update",
424
+ build: () => ({
425
+ hubRef: requireHubRef(hubRef),
426
+ body: buildPasteBody(opts, readPayload(opts)),
427
+ }),
428
+ danger: "writes manual thread context and bumps the order rowVersion",
429
+ opts,
430
+ call: (b) => requireClient().provideIntakeThreadContext(b.hubRef, b.body),
431
+ });
432
+ });
433
+ writeFlags(jsonFlag(ops
434
+ .command("edit")
435
+ .description("PUT .../draft — 改稿(新内容版本,旧审核失效,改稿后必须重审;disclosure 必须仍在正文里)")
436
+ .argument("<hubRef>", "订单 hubRef(uuid)")
437
+ .requiredOption("--row-version <n>", RV_DESC)
438
+ .option("--body <text>", "新正文(长文请用 -j @file)")
439
+ .option("--title <text>", "新标题(post)")
440
+ .option("--clear-title", "把标题清空(null)"), '{ "title"?: string|null, "body": string }')).action(async (hubRef, opts) => {
441
+ await guarded({
442
+ command: "intake ops edit",
443
+ action: "update",
444
+ build: () => ({
445
+ hubRef: requireHubRef(hubRef),
446
+ body: buildEditBody(opts, readPayload(opts)),
447
+ }),
448
+ danger: "creates a new content version and invalidates the current review",
449
+ opts,
450
+ call: (b) => requireClient().editIntakeOrderDraft(b.hubRef, b.body),
451
+ });
452
+ });
453
+ writeFlags(ops
454
+ .command("schedule")
455
+ .description("POST .../schedule — 排期并建审核目标(受 INTAKE_OPS_EXECUTION_ENABLED 闸,默认关 → 503)")
456
+ .argument("<hubRef>", "订单 hubRef(uuid)")
457
+ .requiredOption("--row-version <n>", RV_DESC)
458
+ .requiredOption("--planned-at <iso>", "计划发布时间(ISO-8601,UTC)")).action(async (hubRef, opts) => {
459
+ await guarded({
460
+ command: "intake ops schedule",
461
+ action: "update",
462
+ build: () => ({
463
+ hubRef: requireHubRef(hubRef),
464
+ body: buildScheduleBody(opts),
465
+ }),
466
+ danger: "schedules the order and creates a review target",
467
+ opts,
468
+ call: (b) => requireClient().scheduleIntakeOrder(b.hubRef, b.body),
469
+ });
470
+ });
471
+ writeFlags(ops
472
+ .command("re-review")
473
+ .description("POST .../re-review — 重新审核(改稿后 / permanent·bug 降级后;pending·running 时 409;受执行开关闸)")
474
+ .argument("<hubRef>", "订单 hubRef(uuid)")
475
+ .requiredOption("--row-version <n>", RV_DESC)
476
+ .requiredOption("--reason <text>", "重审原因(≤200 字,不含个人联系方式)")).action(async (hubRef, opts) => {
477
+ await guarded({
478
+ command: "intake ops re-review",
479
+ action: "update",
480
+ build: () => ({
481
+ hubRef: requireHubRef(hubRef),
482
+ body: buildReReviewBody(opts),
483
+ }),
484
+ danger: "starts a new review round for this order",
485
+ opts,
486
+ call: (b) => requireClient().reReviewIntakeOrder(b.hubRef, b.body),
487
+ });
488
+ });
489
+ writeFlags(ops
490
+ .command("start")
491
+ .description("POST .../start — 标记开始执行(可选步骤:外部渠道允许发完再补回填;受执行开关闸)")
492
+ .argument("<hubRef>", "订单 hubRef(uuid)")
493
+ .requiredOption("--row-version <n>", RV_DESC)).action(async (hubRef, opts) => {
494
+ await guarded({
495
+ command: "intake ops start",
496
+ action: "update",
497
+ build: () => ({
498
+ hubRef: requireHubRef(hubRef),
499
+ body: buildStartBody(opts),
500
+ }),
501
+ danger: "marks the order as executing",
502
+ opts,
503
+ call: (b) => requireClient().startIntakeOrder(b.hubRef, b.body),
504
+ });
505
+ });
506
+ writeFlags(jsonFlag(ops
507
+ .command("confirm")
508
+ .description("POST .../confirm-published — 回填已发布(需当前审核 passed + 内容身份一致;偏离审过内容须 --deviation-note 显式 ack)")
509
+ .argument("<hubRef>", "订单 hubRef(uuid)")
510
+ .requiredOption("--row-version <n>", RV_DESC)
511
+ .option("--permalink <url>", "Reddit 永久链接")
512
+ .option("--posted-at <iso>", "实际发帖时间(ISO-8601,UTC)")
513
+ .option("--final-body <text>", "实际发出的正文(长文请用 -j @file)")
514
+ .option("--final-title <text>", "实际发出的标题(post)")
515
+ .option("--executed-by <text>", "执行人(自由文本,不含个人联系方式)")
516
+ .option("--deviation-note <text>", "实际内容偏离审过版本时的显式确认说明(设置即 contentDeviation.acknowledged=true)"), "{ permalink, postedAt, finalBody, finalTitle?, executedBy?, contentDeviation?: { acknowledged: true, note } }")).action(async (hubRef, opts) => {
517
+ await guarded({
518
+ command: "intake ops confirm",
519
+ action: "update",
520
+ build: () => ({
521
+ hubRef: requireHubRef(hubRef),
522
+ body: buildConfirmBody(opts, readPayload(opts)),
523
+ }),
524
+ danger: "marks the order published (terminal, visible to CyberRedd)",
525
+ opts,
526
+ call: (b) => requireClient().confirmIntakeOrderPublished(b.hubRef, b.body),
527
+ });
528
+ });
529
+ writeFlags(ops
530
+ .command("fail")
531
+ .description("POST .../fail — 置失败(终态)。帖子若已发出:先 `intake ops anomaly` 登记并在 Reddit 删帖,再 fail(REVIEW_REJECTED)")
532
+ .argument("<hubRef>", "订单 hubRef(uuid)")
533
+ .requiredOption("--row-version <n>", RV_DESC)
534
+ .requiredOption("--reason-code <c>", FAIL_CODES.join(" | "))
535
+ .option("--confirm-not-published", "声明帖子当前不在 Reddit 上(必带)", false)
536
+ .option("--internal-note <text>", "内部备注(只进审计)")).action(async (hubRef, opts) => {
537
+ await guarded({
538
+ command: "intake ops fail",
539
+ action: "update",
540
+ build: () => ({
541
+ hubRef: requireHubRef(hubRef),
542
+ body: buildFailBody(opts),
543
+ }),
544
+ danger: "fails the order (terminal; visible to CyberRedd)",
545
+ opts,
546
+ call: (b) => requireClient().failIntakeOrder(b.hubRef, b.body),
547
+ });
548
+ });
549
+ writeFlags(jsonFlag(ops
550
+ .command("anomaly")
551
+ .description("POST .../anomalies — 异常事实登记(审核没过 / disclosure 缺失 / 订单已关闭却已发帖):只记事实 + 告警,不改订单状态、不产生 published")
552
+ .argument("<hubRef>", "订单 hubRef(uuid)")
553
+ .option("--row-version <n>", "可选:提供则比对(登记事实不强制)")
554
+ .option("--reason-code <c>", ANOMALY_CODES.join(" | "))
555
+ .option("--permalink <url>", "帖子永久链接")
556
+ .option("--posted-at <iso>", "实际发帖时间(ISO-8601,UTC)")
557
+ .option("--final-body <text>", "实际发出的正文")
558
+ .option("--note <text>", "说明(reason-code=OTHER 时必填;不含个人联系方式)"), "{ reasonCode, permalink, postedAt, finalBody?, note? }")).action(async (hubRef, opts) => {
559
+ await guarded({
560
+ command: "intake ops anomaly",
561
+ action: "update",
562
+ build: () => ({
563
+ hubRef: requireHubRef(hubRef),
564
+ body: buildAnomalyBody(opts, readPayload(opts)),
565
+ }),
566
+ danger: "registers an anomaly fact and raises a manual-handling alert",
567
+ opts,
568
+ call: (b) => requireClient().registerIntakeOrderAnomaly(b.hubRef, b.body),
569
+ });
570
+ });
571
+ }
572
+ //# sourceMappingURL=register-intake-ops.js.map