@anthusai/papyrus 5.130.0-next.1 → 5.130.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/amplify/agents/admin-policy-grant.feature +20 -0
- package/amplify/agents/admin-policy-grant.js +31 -0
- package/amplify/agents/admin-policy-grant.ts +35 -0
- package/amplify/agents/pieces.js +11 -0
- package/amplify/agents/pieces.ts +13 -0
- package/amplify/agents/schedule-group.js +75 -0
- package/amplify/agents/schedule-group.ts +82 -0
- package/amplify/agents/stack.js +27 -0
- package/amplify/agents/stack.ts +53 -0
- package/amplify/agents/wake-queue.js +121 -0
- package/amplify/agents/wake-queue.ts +138 -0
- package/amplify/data/resource.js +25 -0
- package/amplify/data/resource.ts +25 -0
- package/amplify/data/schema.js +27 -1
- package/amplify/data/schema.ts +27 -1
- package/amplify/functions/announcements/schema.js +86 -0
- package/amplify/functions/announcements/schema.ts +86 -0
- package/amplify/functions/assignment-action/handler.ts +4 -0
- package/amplify/functions/automation-view/schema.js +8 -1
- package/amplify/functions/automation-view/schema.ts +8 -1
- package/amplify/functions/automation-view/wire.js +7 -11
- package/amplify/functions/automation-view/wire.ts +7 -14
- package/amplify/functions/localization-dispatch/handler.py +4 -3
- package/amplify/functions/localization-dispatch/wire.js +6 -5
- package/amplify/functions/localization-dispatch/wire.ts +6 -5
- package/amplify/functions/model-attachment-upload/handler.ts +4 -0
- package/amplify/functions/model-attachment-upload/rules.js +2 -0
- package/amplify/functions/model-attachment-upload/rules.ts +2 -0
- package/amplify/functions/procedure-action/handler.ts +44 -27
- package/amplify/functions/procedure-action/wake-key.js +48 -0
- package/amplify/functions/procedure-action/wake-key.ts +49 -0
- package/amplify/site-backend.js +12 -2
- package/amplify/site-backend.ts +16 -2
- package/components/automation-panel.tsx +6 -0
- package/components/automation-view.tsx +6 -4
- package/components/newsroom-ops-overview.tsx +2 -0
- package/components/today-panel.tsx +43 -0
- package/components/today-view.tsx +171 -0
- package/infra/agent-sync.test.js +34 -0
- package/infra/agent-sync.test.ts +35 -0
- package/infra/build-specs.js +21 -0
- package/infra/build-specs.ts +25 -0
- package/infra/ci-gate.test.js +1 -1
- package/infra/ci-gate.test.ts +1 -1
- package/infra/procedure-sync.test.js +48 -0
- package/infra/procedure-sync.test.ts +50 -0
- package/lib/automation-fixture.ts +14 -9
- package/lib/automation-overview.ts +18 -5
- package/lib/guidelines/writing-guidelines-admin.ts +1 -1
- package/lib/images/operations.generated.ts +72 -42
- package/lib/tenant-keys.js +1 -0
- package/lib/tenant-keys.ts +1 -0
- package/lib/today-client.ts +34 -0
- package/lib/today-fixture.ts +52 -0
- package/lib/today-overview.ts +111 -0
- package/package.json +6 -1
- package/routes.manifest.json +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import Link from "next/link";
|
|
2
|
+
import { CheckIcon, ChevronDownIcon, CircleHelpIcon, ClockIcon, MinusIcon, TriangleAlertIcon, XIcon, type LucideIcon } from "lucide-react";
|
|
3
|
+
import {
|
|
4
|
+
OTHER_ORDER,
|
|
5
|
+
OUTCOME_ORDER,
|
|
6
|
+
OUTCOME_WORDS,
|
|
7
|
+
automationsHref,
|
|
8
|
+
costText,
|
|
9
|
+
countWords,
|
|
10
|
+
dayTitle,
|
|
11
|
+
reasonsText,
|
|
12
|
+
runsText,
|
|
13
|
+
type TodayCountKey,
|
|
14
|
+
type TodayDidNotRun,
|
|
15
|
+
type TodayOverview,
|
|
16
|
+
type TodayResult,
|
|
17
|
+
type TodayRow,
|
|
18
|
+
type TodayRun,
|
|
19
|
+
} from "../lib/today-overview";
|
|
20
|
+
|
|
21
|
+
/** Every status is a mark and its words, never a colour alone. The marks are Lucide icons; the words come with them. */
|
|
22
|
+
const MARKS: Record<TodayCountKey, LucideIcon> = {
|
|
23
|
+
acted: CheckIcon,
|
|
24
|
+
nothing: MinusIcon,
|
|
25
|
+
asked: CircleHelpIcon,
|
|
26
|
+
failed: XIcon,
|
|
27
|
+
unknown: TriangleAlertIcon,
|
|
28
|
+
notFinished: ClockIcon,
|
|
29
|
+
beforeOutcomes: MinusIcon,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function Mark({ name }: { name: TodayCountKey }) {
|
|
33
|
+
const Icon = MARKS[name];
|
|
34
|
+
return <Icon aria-hidden="true" className="size-3.5 shrink-0" />;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const CHIP = "inline-flex items-center gap-1.5 rounded-full bg-[var(--feed-control)] px-2.5 py-1 text-xs";
|
|
38
|
+
|
|
39
|
+
function Message({ title, children, kind }: { title: string; children?: React.ReactNode; kind: string }) {
|
|
40
|
+
return (
|
|
41
|
+
<div className="rounded-[16px] bg-[var(--feed-card)] p-4 text-sm" data-today-state={kind} role={kind === "loading" ? "status" : "alert"}>
|
|
42
|
+
<strong>{title}</strong>
|
|
43
|
+
{children ? <p className="mt-1 text-muted-foreground">{children}</p> : null}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function RunLine({ run }: { run: TodayRun }) {
|
|
49
|
+
const outcome = run.outcome ?? (run.runStatus === "completed" || run.runStatus === "failed" ? "beforeOutcomes" : "notFinished");
|
|
50
|
+
return (
|
|
51
|
+
<li className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs" data-today-run={run.runId ?? "unlinked"} data-today-run-outcome={outcome}>
|
|
52
|
+
<span className="inline-flex items-center gap-1.5 font-medium">
|
|
53
|
+
<Mark name={outcome} />
|
|
54
|
+
{run.outcomeShown}
|
|
55
|
+
</span>
|
|
56
|
+
<span className="tabular-nums text-muted-foreground">{run.requestedAt ? run.requestedAt.slice(11, 16) + " UTC" : "time not recorded"}</span>
|
|
57
|
+
<span className="text-muted-foreground">{run.costUsd === null ? "cost unknown" : costText({ costUsd: run.costUsd, costKnownRuns: 1, costUnknownRuns: 0 })}</span>
|
|
58
|
+
<span className="break-all text-muted-foreground">{run.runId ? `Run ${run.runId}` : "No run id"}</span>
|
|
59
|
+
{run.error ? <span className="break-words" data-today-run-error>Error: {run.error}</span> : null}
|
|
60
|
+
</li>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function Row({ row, demo }: { row: TodayRow; demo: boolean }) {
|
|
65
|
+
const counted = [...OUTCOME_ORDER, ...OTHER_ORDER].filter((key) => row.counts[key] > 0);
|
|
66
|
+
const reasons = OUTCOME_ORDER.filter((outcome) => row.reasons[outcome] && Object.keys(row.reasons[outcome] ?? {}).length);
|
|
67
|
+
return (
|
|
68
|
+
<li className="space-y-2 rounded-[16px] bg-[var(--feed-card)] p-3" data-today-row={row.key}>
|
|
69
|
+
<div className="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
|
|
70
|
+
<h3 className="text-sm font-semibold">{row.title}</h3>
|
|
71
|
+
<span className="text-xs tabular-nums text-muted-foreground" data-today-row-cost>{runsText(row.runs.length)} · {costText(row)}</span>
|
|
72
|
+
</div>
|
|
73
|
+
<ul className="flex flex-wrap gap-1.5" data-today-counts>
|
|
74
|
+
{counted.map((key) => (
|
|
75
|
+
<li className={CHIP} data-today-count={key} key={key}>
|
|
76
|
+
<Mark name={key} />
|
|
77
|
+
<span>{countWords(key)}</span>
|
|
78
|
+
<strong className="tabular-nums">{row.counts[key]}</strong>
|
|
79
|
+
</li>
|
|
80
|
+
))}
|
|
81
|
+
</ul>
|
|
82
|
+
{reasons.length ? (
|
|
83
|
+
<ul className="space-y-0.5 text-xs" data-today-reasons>
|
|
84
|
+
{reasons.map((outcome) => (
|
|
85
|
+
<li className="flex flex-wrap items-center gap-1.5" data-today-reason={outcome} key={outcome}>
|
|
86
|
+
<Mark name={outcome} />
|
|
87
|
+
<span className="font-medium">{OUTCOME_WORDS[outcome]}:</span>
|
|
88
|
+
<span className="break-words">{reasonsText(row.reasons[outcome] ?? {})}</span>
|
|
89
|
+
</li>
|
|
90
|
+
))}
|
|
91
|
+
</ul>
|
|
92
|
+
) : null}
|
|
93
|
+
<details className="group text-xs" data-today-runs>
|
|
94
|
+
<summary className="flex min-h-9 cursor-pointer list-none items-center gap-1.5 font-medium text-muted-foreground">
|
|
95
|
+
<ChevronDownIcon aria-hidden="true" className="size-3.5 transition-transform group-open:rotate-180" />
|
|
96
|
+
Show the {runsText(row.runs.length)}
|
|
97
|
+
</summary>
|
|
98
|
+
<ul className="space-y-2 pb-1 pt-1">
|
|
99
|
+
{row.runs.map((run) => <RunLine key={run.runId ?? `${run.requestedAt}`} run={run} />)}
|
|
100
|
+
</ul>
|
|
101
|
+
{row.automationIds.length ? (
|
|
102
|
+
<p className="flex flex-wrap gap-x-4 gap-y-1">
|
|
103
|
+
{row.automationIds.map((id) => (
|
|
104
|
+
<Link className="underline underline-offset-2" data-today-open-runs={id} href={automationsHref(id, demo)} key={id}>Open the runs of {id}</Link>
|
|
105
|
+
))}
|
|
106
|
+
</p>
|
|
107
|
+
) : (
|
|
108
|
+
<p><Link className="underline underline-offset-2" data-today-open-runs href={automationsHref(null, demo)}>Open Automations</Link></p>
|
|
109
|
+
)}
|
|
110
|
+
</details>
|
|
111
|
+
</li>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function DidNotRunLine({ entry, demo }: { entry: TodayDidNotRun; demo: boolean }) {
|
|
116
|
+
return (
|
|
117
|
+
<li className="flex flex-wrap items-center gap-x-3 gap-y-1 rounded-[16px] bg-[var(--feed-card)] p-3 text-sm" data-today-did-not-run={entry.automationId} data-today-why={entry.whyCode}>
|
|
118
|
+
<span className="inline-flex items-center gap-1.5 font-medium">
|
|
119
|
+
<MinusIcon aria-hidden="true" className="size-3.5 shrink-0" />
|
|
120
|
+
{entry.title}
|
|
121
|
+
</span>
|
|
122
|
+
<span>{entry.state}</span>
|
|
123
|
+
<span className="text-xs text-muted-foreground">{entry.why}</span>
|
|
124
|
+
<Link className="text-xs underline underline-offset-2" href={automationsHref(entry.automationId, demo)}>Open</Link>
|
|
125
|
+
</li>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function Ready({ overview, demo }: { overview: TodayOverview; demo: boolean }) {
|
|
130
|
+
return (
|
|
131
|
+
<>
|
|
132
|
+
<p className="text-sm text-muted-foreground" data-today-summary role="status">
|
|
133
|
+
{runsText(overview.totals.runs)} · {costText(overview.totals)}
|
|
134
|
+
</p>
|
|
135
|
+
<h3 className="text-xs font-medium uppercase tracking-wide text-muted-foreground">What ran</h3>
|
|
136
|
+
{overview.rows.length ? (
|
|
137
|
+
<ul className="space-y-2" data-today-rows>
|
|
138
|
+
{overview.rows.map((row) => <Row demo={demo} key={row.key} row={row} />)}
|
|
139
|
+
</ul>
|
|
140
|
+
) : <p className="text-sm text-muted-foreground" data-today-nothing-ran>Nothing ran in this day.</p>}
|
|
141
|
+
{overview.didNotRun.length ? (
|
|
142
|
+
<>
|
|
143
|
+
<h3 className="text-xs font-medium uppercase tracking-wide text-muted-foreground">Did not run</h3>
|
|
144
|
+
<ul className="space-y-2" data-today-did-not-run-list>
|
|
145
|
+
{overview.didNotRun.map((entry) => <DidNotRunLine demo={demo} entry={entry} key={entry.automationId} />)}
|
|
146
|
+
</ul>
|
|
147
|
+
</>
|
|
148
|
+
) : null}
|
|
149
|
+
</>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The Today section of the newsroom home. Read only; the panel around it refreshes it. */
|
|
154
|
+
export function TodayView({ result, demo = false }: { result: TodayResult | null; demo?: boolean }) {
|
|
155
|
+
return (
|
|
156
|
+
<section aria-label="Today" className="space-y-3" data-today>
|
|
157
|
+
<h2 className="text-lg font-semibold">
|
|
158
|
+
Today
|
|
159
|
+
{result && "state" in result && result.state === "ready" ? <span className="ml-2 text-sm font-normal text-muted-foreground" data-today-day>{dayTitle(result.day)} · {result.timeZone}</span> : null}
|
|
160
|
+
</h2>
|
|
161
|
+
{result === null ? <Message kind="loading" title="Loading what ran today" />
|
|
162
|
+
: "error" in result ? (
|
|
163
|
+
result.error === "forbidden"
|
|
164
|
+
? <Message kind="forbidden" title="Today is for editors and admins">Your account can read the rest of this page, not what the agents did.</Message>
|
|
165
|
+
: <Message kind="bad_request" title="Today could not be read">{result.message ?? "The request was not understood."}</Message>
|
|
166
|
+
)
|
|
167
|
+
: result.state === "unavailable" ? <Message kind="unavailable" title="Today could not be read right now">Nothing is wrong with what you see elsewhere on this page. It tries again by itself.</Message>
|
|
168
|
+
: <Ready demo={demo} overview={result} />}
|
|
169
|
+
</section>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { cmsProductionBuildSpec, cmsStagingBuildSpec } from "./build-specs.js";
|
|
5
|
+
import { parseSiteConfig } from "./site-config.js";
|
|
6
|
+
// Executes infra/amplify-app-shell/features/agent-sync.feature (run through scripts/test-infra-agent-sync.ts).
|
|
7
|
+
const examples = path.resolve(__dirname, "../examples");
|
|
8
|
+
const backendCommands = (spec) => {
|
|
9
|
+
const lines = spec.split("\n");
|
|
10
|
+
const start = lines.indexOf(" build:") + 2;
|
|
11
|
+
return lines.slice(start, lines.indexOf("frontend:")).map((line) => line.trim().replace(/^- /, "").replace(/^'(.*)'$/, "$1"));
|
|
12
|
+
};
|
|
13
|
+
const siteNames = fs.readdirSync(examples).filter((name) => name.endsWith(".site.json")).map((name) => name.replace(/\.site\.json$/, ""));
|
|
14
|
+
for (const name of siteNames) {
|
|
15
|
+
const config = parseSiteConfig(JSON.parse(fs.readFileSync(path.join(examples, `${name}.site.json`), "utf8")));
|
|
16
|
+
if (!config.cms)
|
|
17
|
+
continue;
|
|
18
|
+
const commands = backendCommands(cmsProductionBuildSpec(config));
|
|
19
|
+
const procedures = commands.findIndex((line) => line.includes("papyrus procedures seed-required"));
|
|
20
|
+
const agents = commands.findIndex((line) => line.includes("papyrus agents apply"));
|
|
21
|
+
assert.ok(procedures >= 0 && agents === procedures + 1, `${name}: the agent definitions are applied right after the procedures are registered`);
|
|
22
|
+
assert.equal(commands[agents], 'PAPYRUS_ROOT="$PWD" PAPYRUS_GRAPHQL_AUTH=iam papyrus agents apply', `${name}: build role, operator lane, the site's checkout`);
|
|
23
|
+
assert.ok(!commands[agents].includes("||"), `${name}: a failing step fails the build`);
|
|
24
|
+
assert.ok(!/dry-run|--check/.test(commands[agents]), `${name}: the build applies`);
|
|
25
|
+
const schedules = commands.findIndex((line) => line.includes("papyrus agents schedules"));
|
|
26
|
+
assert.ok(schedules === agents + 1, `${name}: the schedule group is reconciled right after the definitions are applied`);
|
|
27
|
+
assert.equal(commands[schedules], `PAPYRUS_ROOT="$PWD" PAPYRUS_GRAPHQL_AUTH=iam papyrus agents schedules --site ${config.brand.toLowerCase()}`, `${name}: build role, operator lane, the site's brand id`);
|
|
28
|
+
assert.ok(!commands[schedules].includes("||"), `${name}: a failing schedule step fails the build`);
|
|
29
|
+
assert.ok(!/dry-run|--check/.test(commands[schedules]), `${name}: the build reconciles`);
|
|
30
|
+
const alexa = commands.findIndex((line) => line.includes("alexa-sync"));
|
|
31
|
+
assert.ok(alexa > schedules, `${name}: the Alexa sync, which may fail quietly, stays last`);
|
|
32
|
+
assert.ok(!cmsStagingBuildSpec(config).includes("papyrus agents apply"), `${name}: the staging build does not apply agent definitions`);
|
|
33
|
+
assert.ok(!cmsStagingBuildSpec(config).includes("papyrus agents schedules"), `${name}: the staging build does not touch the schedule group`);
|
|
34
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { cmsProductionBuildSpec, cmsStagingBuildSpec } from "./build-specs";
|
|
5
|
+
import { parseSiteConfig } from "./site-config";
|
|
6
|
+
|
|
7
|
+
// Executes infra/amplify-app-shell/features/agent-sync.feature (run through scripts/test-infra-agent-sync.ts).
|
|
8
|
+
const examples = path.resolve(__dirname, "../examples");
|
|
9
|
+
const backendCommands = (spec: string): string[] => {
|
|
10
|
+
const lines = spec.split("\n");
|
|
11
|
+
const start = lines.indexOf(" build:") + 2;
|
|
12
|
+
return lines.slice(start, lines.indexOf("frontend:")).map((line) => line.trim().replace(/^- /, "").replace(/^'(.*)'$/, "$1"));
|
|
13
|
+
};
|
|
14
|
+
const siteNames = fs.readdirSync(examples).filter((name) => name.endsWith(".site.json")).map((name) => name.replace(/\.site\.json$/, ""));
|
|
15
|
+
|
|
16
|
+
for (const name of siteNames) {
|
|
17
|
+
const config = parseSiteConfig(JSON.parse(fs.readFileSync(path.join(examples, `${name}.site.json`), "utf8")));
|
|
18
|
+
if (!config.cms) continue;
|
|
19
|
+
const commands = backendCommands(cmsProductionBuildSpec(config));
|
|
20
|
+
const procedures = commands.findIndex((line) => line.includes("papyrus procedures seed-required"));
|
|
21
|
+
const agents = commands.findIndex((line) => line.includes("papyrus agents apply"));
|
|
22
|
+
assert.ok(procedures >= 0 && agents === procedures + 1, `${name}: the agent definitions are applied right after the procedures are registered`);
|
|
23
|
+
assert.equal(commands[agents], 'PAPYRUS_ROOT="$PWD" PAPYRUS_GRAPHQL_AUTH=iam papyrus agents apply', `${name}: build role, operator lane, the site's checkout`);
|
|
24
|
+
assert.ok(!commands[agents].includes("||"), `${name}: a failing step fails the build`);
|
|
25
|
+
assert.ok(!/dry-run|--check/.test(commands[agents]), `${name}: the build applies`);
|
|
26
|
+
const schedules = commands.findIndex((line) => line.includes("papyrus agents schedules"));
|
|
27
|
+
assert.ok(schedules === agents + 1, `${name}: the schedule group is reconciled right after the definitions are applied`);
|
|
28
|
+
assert.equal(commands[schedules], `PAPYRUS_ROOT="$PWD" PAPYRUS_GRAPHQL_AUTH=iam papyrus agents schedules --site ${config.brand.toLowerCase()}`, `${name}: build role, operator lane, the site's brand id`);
|
|
29
|
+
assert.ok(!commands[schedules].includes("||"), `${name}: a failing schedule step fails the build`);
|
|
30
|
+
assert.ok(!/dry-run|--check/.test(commands[schedules]), `${name}: the build reconciles`);
|
|
31
|
+
const alexa = commands.findIndex((line) => line.includes("alexa-sync"));
|
|
32
|
+
assert.ok(alexa > schedules, `${name}: the Alexa sync, which may fail quietly, stays last`);
|
|
33
|
+
assert.ok(!cmsStagingBuildSpec(config).includes("papyrus agents apply"), `${name}: the staging build does not apply agent definitions`);
|
|
34
|
+
assert.ok(!cmsStagingBuildSpec(config).includes("papyrus agents schedules"), `${name}: the staging build does not touch the schedule group`);
|
|
35
|
+
}
|
package/infra/build-specs.js
CHANGED
|
@@ -50,6 +50,26 @@ function frontendSection(preBuildCommands, buildCommands, artifactsDirectory, ca
|
|
|
50
50
|
// enables the alexa plugin and the shared developer credentials exist, and a failure is logged, never fatal: a site's deploy
|
|
51
51
|
// does not depend on Amazon. A Papyrus pin without the command prints usage and falls through the same way.
|
|
52
52
|
const ALEXA_SKILL_SYNC = "npx papyrus-app alexa-sync || echo \"alexa-sync did not complete; the site deploy continues\"";
|
|
53
|
+
// After the backend deploy (it needs the GraphQL endpoint in amplify_outputs.json): register every core procedure from the Papyrus wheel and the
|
|
54
|
+
// site's own from its repository (papyrus-site-procedures.json at the checkout root, when the site has one) as published versions in the site's
|
|
55
|
+
// backend, as the build role. Unchanged procedures write nothing. Unlike the Alexa sync it is never allowed to fail quietly: a failing registration
|
|
56
|
+
// fails the build, so a site is not deployed with procedures that disagree with Git (features/procedure-sync.feature).
|
|
57
|
+
const PROCEDURE_SYNC = `${CHECKOUT_AS_PAPYRUS_ROOT} ${BUILD_ROLE_LANE} papyrus procedures seed-required`;
|
|
58
|
+
// Right after the procedures are registered (an agent definition names a procedure, and a definition naming one that is not registered stops the step):
|
|
59
|
+
// apply the agent definitions, the core ones from the Papyrus wheel and the site's own from papyrus-site-agents at the checkout root (when it has one).
|
|
60
|
+
// It checks every definition first (`papyrus agents validate`'s rules), makes each the registered copy on its automation, retires one gone from Git, and
|
|
61
|
+
// never writes the agent policy document or adopts an automation, so a deploy cannot move a rung or a pause and a new agent arrives at `off`. Like the
|
|
62
|
+
// procedure sync it is never allowed to fail quietly (features/agent-sync.feature).
|
|
63
|
+
const AGENT_SYNC = `${CHECKOUT_AS_PAPYRUS_ROOT} ${BUILD_ROLE_LANE} papyrus agents apply`;
|
|
64
|
+
// Right after the definitions are applied: make the site's schedule group agree with them (slice C1, PPY-2a53cd). Each switched-on agent that names a
|
|
65
|
+
// schedule gets one EventBridge Scheduler entry whose only target is the site's wake queue, and an entry no agent names is removed. It names the site by its
|
|
66
|
+
// brand id, the name the wake queue and the group are built from. Never allowed to fail quietly either (features/agent-sync.feature).
|
|
67
|
+
function scheduleSync(config) {
|
|
68
|
+
return `${CHECKOUT_AS_PAPYRUS_ROOT} ${BUILD_ROLE_LANE} papyrus agents schedules --site ${config.brand.toLowerCase()}`;
|
|
69
|
+
}
|
|
70
|
+
function procedureSyncCommands(config) {
|
|
71
|
+
return [...pythonProvisioningCommands(config), PROCEDURE_SYNC, AGENT_SYNC, scheduleSync(config)];
|
|
72
|
+
}
|
|
53
73
|
const GATE_FAILURE_MESSAGE_PREFIX = "No LeftBlock CI receipt for";
|
|
54
74
|
/**
|
|
55
75
|
* The first commands of a private site's production build: read the GitHub status token from the SSM SecureString that
|
|
@@ -87,6 +107,7 @@ export function cmsProductionBuildSpec(config) {
|
|
|
87
107
|
...deployStackCommands,
|
|
88
108
|
// One pass per cost tag wave until the tags are complete (amplify/cost-tag-waves.ts); one pass after that.
|
|
89
109
|
"npx papyrus-infra backend-deploy",
|
|
110
|
+
...procedureSyncCommands(config),
|
|
90
111
|
ALEXA_SKILL_SYNC,
|
|
91
112
|
], " "),
|
|
92
113
|
...frontendSection([], [
|
package/infra/build-specs.ts
CHANGED
|
@@ -76,6 +76,30 @@ function frontendSection(preBuildCommands: string[], buildCommands: string[], ar
|
|
|
76
76
|
// does not depend on Amazon. A Papyrus pin without the command prints usage and falls through the same way.
|
|
77
77
|
const ALEXA_SKILL_SYNC = "npx papyrus-app alexa-sync || echo \"alexa-sync did not complete; the site deploy continues\"";
|
|
78
78
|
|
|
79
|
+
// After the backend deploy (it needs the GraphQL endpoint in amplify_outputs.json): register every core procedure from the Papyrus wheel and the
|
|
80
|
+
// site's own from its repository (papyrus-site-procedures.json at the checkout root, when the site has one) as published versions in the site's
|
|
81
|
+
// backend, as the build role. Unchanged procedures write nothing. Unlike the Alexa sync it is never allowed to fail quietly: a failing registration
|
|
82
|
+
// fails the build, so a site is not deployed with procedures that disagree with Git (features/procedure-sync.feature).
|
|
83
|
+
const PROCEDURE_SYNC = `${CHECKOUT_AS_PAPYRUS_ROOT} ${BUILD_ROLE_LANE} papyrus procedures seed-required`;
|
|
84
|
+
|
|
85
|
+
// Right after the procedures are registered (an agent definition names a procedure, and a definition naming one that is not registered stops the step):
|
|
86
|
+
// apply the agent definitions, the core ones from the Papyrus wheel and the site's own from papyrus-site-agents at the checkout root (when it has one).
|
|
87
|
+
// It checks every definition first (`papyrus agents validate`'s rules), makes each the registered copy on its automation, retires one gone from Git, and
|
|
88
|
+
// never writes the agent policy document or adopts an automation, so a deploy cannot move a rung or a pause and a new agent arrives at `off`. Like the
|
|
89
|
+
// procedure sync it is never allowed to fail quietly (features/agent-sync.feature).
|
|
90
|
+
const AGENT_SYNC = `${CHECKOUT_AS_PAPYRUS_ROOT} ${BUILD_ROLE_LANE} papyrus agents apply`;
|
|
91
|
+
|
|
92
|
+
// Right after the definitions are applied: make the site's schedule group agree with them (slice C1, PPY-2a53cd). Each switched-on agent that names a
|
|
93
|
+
// schedule gets one EventBridge Scheduler entry whose only target is the site's wake queue, and an entry no agent names is removed. It names the site by its
|
|
94
|
+
// brand id, the name the wake queue and the group are built from. Never allowed to fail quietly either (features/agent-sync.feature).
|
|
95
|
+
function scheduleSync(config: AmplifyAppShellSiteConfig): string {
|
|
96
|
+
return `${CHECKOUT_AS_PAPYRUS_ROOT} ${BUILD_ROLE_LANE} papyrus agents schedules --site ${config.brand.toLowerCase()}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function procedureSyncCommands(config: AmplifyAppShellSiteConfig): string[] {
|
|
100
|
+
return [...pythonProvisioningCommands(config), PROCEDURE_SYNC, AGENT_SYNC, scheduleSync(config)];
|
|
101
|
+
}
|
|
102
|
+
|
|
79
103
|
const GATE_FAILURE_MESSAGE_PREFIX = "No LeftBlock CI receipt for";
|
|
80
104
|
|
|
81
105
|
/**
|
|
@@ -116,6 +140,7 @@ export function cmsProductionBuildSpec(config: AmplifyAppShellSiteConfig): strin
|
|
|
116
140
|
...deployStackCommands,
|
|
117
141
|
// One pass per cost tag wave until the tags are complete (amplify/cost-tag-waves.ts); one pass after that.
|
|
118
142
|
"npx papyrus-infra backend-deploy",
|
|
143
|
+
...procedureSyncCommands(config),
|
|
119
144
|
ALEXA_SKILL_SYNC,
|
|
120
145
|
],
|
|
121
146
|
" ",
|
package/infra/ci-gate.test.js
CHANGED
|
@@ -105,7 +105,7 @@ for (const name of siteNames) {
|
|
|
105
105
|
}
|
|
106
106
|
// Scenario: the generated gate stops without a success status and passes with one
|
|
107
107
|
{
|
|
108
|
-
const commands = backendCommands(cmsProductionBuildSpec(parseSiteConfig(privateSite()))).filter((line) => !line.startsWith("- npm ci") && !line.includes("ampx") && !line.includes("PAPYRUS_CONSOLE") && !line.includes("alexa")).map(unquote);
|
|
108
|
+
const commands = backendCommands(cmsProductionBuildSpec(parseSiteConfig(privateSite()))).filter((line) => !line.startsWith("- npm ci") && !line.includes("ampx") && !line.includes("PAPYRUS_CONSOLE") && !line.includes("alexa") && !line.includes("papyrus-infra") && !line.includes("uv") && !line.includes(".venv") && !line.includes("papyrus procedures")).map(unquote);
|
|
109
109
|
for (const withJq of [true, false]) {
|
|
110
110
|
const branch = withJq ? "with jq" : "without jq";
|
|
111
111
|
const missing = runGate(commands, { status: JSON.stringify({ state: "success", statuses: [{ state: "success", context: "other/check" }] }), withJq, commitId: "abc123" });
|
package/infra/ci-gate.test.ts
CHANGED
|
@@ -112,7 +112,7 @@ for (const name of siteNames) {
|
|
|
112
112
|
|
|
113
113
|
// Scenario: the generated gate stops without a success status and passes with one
|
|
114
114
|
{
|
|
115
|
-
const commands = backendCommands(cmsProductionBuildSpec(parseSiteConfig(privateSite()))).filter((line) => !line.startsWith("- npm ci") && !line.includes("ampx") && !line.includes("PAPYRUS_CONSOLE") && !line.includes("alexa")).map(unquote);
|
|
115
|
+
const commands = backendCommands(cmsProductionBuildSpec(parseSiteConfig(privateSite()))).filter((line) => !line.startsWith("- npm ci") && !line.includes("ampx") && !line.includes("PAPYRUS_CONSOLE") && !line.includes("alexa") && !line.includes("papyrus-infra") && !line.includes("uv") && !line.includes(".venv") && !line.includes("papyrus procedures")).map(unquote);
|
|
116
116
|
for (const withJq of [true, false]) {
|
|
117
117
|
const branch = withJq ? "with jq" : "without jq";
|
|
118
118
|
const missing = runGate(commands, { status: JSON.stringify({ state: "success", statuses: [{ state: "success", context: "other/check" }] }), withJq, commitId: "abc123" });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { cmsProductionBuildSpec, cmsStagingBuildSpec, papyrusVersionToPep440 } from "./build-specs.js";
|
|
5
|
+
import { parseSiteConfig } from "./site-config.js";
|
|
6
|
+
// Executes infra/amplify-app-shell/features/procedure-sync.feature (run through scripts/test-infra-procedure-sync.ts).
|
|
7
|
+
const examples = path.resolve(__dirname, "../examples");
|
|
8
|
+
const example = (name, change = () => { }) => {
|
|
9
|
+
const config = JSON.parse(fs.readFileSync(path.join(examples, `${name}.site.json`), "utf8"));
|
|
10
|
+
change(config);
|
|
11
|
+
return config;
|
|
12
|
+
};
|
|
13
|
+
const backendCommands = (spec) => {
|
|
14
|
+
const lines = spec.split("\n");
|
|
15
|
+
const start = lines.indexOf(" build:") + 2;
|
|
16
|
+
return lines.slice(start, lines.indexOf("frontend:")).map((line) => line.trim().replace(/^- /, "").replace(/^'(.*)'$/, "$1"));
|
|
17
|
+
};
|
|
18
|
+
const siteNames = fs.readdirSync(examples).filter((name) => name.endsWith(".site.json")).map((name) => name.replace(/\.site\.json$/, ""));
|
|
19
|
+
// Scenario: The production build registers the procedures after the backend deploy
|
|
20
|
+
for (const name of siteNames) {
|
|
21
|
+
const config = parseSiteConfig(example(name));
|
|
22
|
+
if (!config.cms)
|
|
23
|
+
continue;
|
|
24
|
+
const commands = backendCommands(cmsProductionBuildSpec(config));
|
|
25
|
+
const deploy = commands.indexOf("npx papyrus-infra backend-deploy");
|
|
26
|
+
const sync = commands.findIndex((line) => line.includes("papyrus procedures seed-required"));
|
|
27
|
+
assert.ok(deploy >= 0 && sync > deploy, `${name}: the registration comes after the backend deploy`);
|
|
28
|
+
const install = commands.findIndex((line) => line.includes("uv pip install") && line.includes("papyrus-newsroom"));
|
|
29
|
+
assert.ok(install > deploy && install < sync, `${name}: the pinned engine is installed before the command runs`);
|
|
30
|
+
assert.ok(commands[install].includes(`==${papyrusVersionToPep440(config.papyrusVersion)}"`), `${name}: it installs the Papyrus version the site pins`);
|
|
31
|
+
assert.equal(commands[sync], 'PAPYRUS_ROOT="$PWD" PAPYRUS_GRAPHQL_AUTH=iam papyrus procedures seed-required', `${name}: build role, operator lane, the site's checkout`);
|
|
32
|
+
assert.ok(!commands[sync].includes("||"), `${name}: a failing registration fails the build`);
|
|
33
|
+
assert.ok(!/dry-run|--check/.test(commands[sync]), `${name}: the build applies`);
|
|
34
|
+
const alexa = commands.findIndex((line) => line.includes("alexa-sync"));
|
|
35
|
+
assert.ok(alexa > sync, `${name}: the Alexa sync, which may fail quietly, stays last`);
|
|
36
|
+
}
|
|
37
|
+
// Scenario: The CI receipt gate still comes first and the staging build is unchanged
|
|
38
|
+
{
|
|
39
|
+
const raw = example("dataparade", (config) => {
|
|
40
|
+
config.autoDeploy = false;
|
|
41
|
+
config.ci = { gate: "leftblock-receipt" };
|
|
42
|
+
});
|
|
43
|
+
const config = parseSiteConfig(raw);
|
|
44
|
+
const commands = backendCommands(cmsProductionBuildSpec(config));
|
|
45
|
+
assert.ok(commands[0].includes("AWS_COMMIT_ID"), "the gate is still the first backend command");
|
|
46
|
+
assert.ok(commands.findIndex((line) => line.startsWith("npm ci")) < commands.findIndex((line) => line.includes("seed-required")));
|
|
47
|
+
assert.ok(!cmsStagingBuildSpec(config).includes("seed-required"), "the staging build does not register procedures");
|
|
48
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { cmsProductionBuildSpec, cmsStagingBuildSpec, papyrusVersionToPep440 } from "./build-specs";
|
|
5
|
+
import { parseSiteConfig } from "./site-config";
|
|
6
|
+
|
|
7
|
+
// Executes infra/amplify-app-shell/features/procedure-sync.feature (run through scripts/test-infra-procedure-sync.ts).
|
|
8
|
+
const examples = path.resolve(__dirname, "../examples");
|
|
9
|
+
const example = (name: string, change: (config: any) => void = () => {}): any => {
|
|
10
|
+
const config = JSON.parse(fs.readFileSync(path.join(examples, `${name}.site.json`), "utf8"));
|
|
11
|
+
change(config);
|
|
12
|
+
return config;
|
|
13
|
+
};
|
|
14
|
+
const backendCommands = (spec: string): string[] => {
|
|
15
|
+
const lines = spec.split("\n");
|
|
16
|
+
const start = lines.indexOf(" build:") + 2;
|
|
17
|
+
return lines.slice(start, lines.indexOf("frontend:")).map((line) => line.trim().replace(/^- /, "").replace(/^'(.*)'$/, "$1"));
|
|
18
|
+
};
|
|
19
|
+
const siteNames = fs.readdirSync(examples).filter((name) => name.endsWith(".site.json")).map((name) => name.replace(/\.site\.json$/, ""));
|
|
20
|
+
|
|
21
|
+
// Scenario: The production build registers the procedures after the backend deploy
|
|
22
|
+
for (const name of siteNames) {
|
|
23
|
+
const config = parseSiteConfig(example(name));
|
|
24
|
+
if (!config.cms) continue;
|
|
25
|
+
const commands = backendCommands(cmsProductionBuildSpec(config));
|
|
26
|
+
const deploy = commands.indexOf("npx papyrus-infra backend-deploy");
|
|
27
|
+
const sync = commands.findIndex((line) => line.includes("papyrus procedures seed-required"));
|
|
28
|
+
assert.ok(deploy >= 0 && sync > deploy, `${name}: the registration comes after the backend deploy`);
|
|
29
|
+
const install = commands.findIndex((line) => line.includes("uv pip install") && line.includes("papyrus-newsroom"));
|
|
30
|
+
assert.ok(install > deploy && install < sync, `${name}: the pinned engine is installed before the command runs`);
|
|
31
|
+
assert.ok(commands[install].includes(`==${papyrusVersionToPep440(config.papyrusVersion)}"`), `${name}: it installs the Papyrus version the site pins`);
|
|
32
|
+
assert.equal(commands[sync], 'PAPYRUS_ROOT="$PWD" PAPYRUS_GRAPHQL_AUTH=iam papyrus procedures seed-required', `${name}: build role, operator lane, the site's checkout`);
|
|
33
|
+
assert.ok(!commands[sync].includes("||"), `${name}: a failing registration fails the build`);
|
|
34
|
+
assert.ok(!/dry-run|--check/.test(commands[sync]), `${name}: the build applies`);
|
|
35
|
+
const alexa = commands.findIndex((line) => line.includes("alexa-sync"));
|
|
36
|
+
assert.ok(alexa > sync, `${name}: the Alexa sync, which may fail quietly, stays last`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Scenario: The CI receipt gate still comes first and the staging build is unchanged
|
|
40
|
+
{
|
|
41
|
+
const raw = example("dataparade", (config) => {
|
|
42
|
+
config.autoDeploy = false;
|
|
43
|
+
config.ci = { gate: "leftblock-receipt" };
|
|
44
|
+
});
|
|
45
|
+
const config = parseSiteConfig(raw);
|
|
46
|
+
const commands = backendCommands(cmsProductionBuildSpec(config));
|
|
47
|
+
assert.ok(commands[0].includes("AWS_COMMIT_ID"), "the gate is still the first backend command");
|
|
48
|
+
assert.ok(commands.findIndex((line) => line.startsWith("npm ci")) < commands.findIndex((line) => line.includes("seed-required")));
|
|
49
|
+
assert.ok(!cmsStagingBuildSpec(config).includes("seed-required"), "the staging build does not register procedures");
|
|
50
|
+
}
|
|
@@ -6,12 +6,13 @@ const ESTIMATED = "estimated from the model usage reported by the run";
|
|
|
6
6
|
function run(fields: Partial<AutomationRun> & Pick<AutomationRun, "status" | "startedAt">): AutomationRun {
|
|
7
7
|
return {
|
|
8
8
|
origin: "monitor", requestedBy: null, reason: null, sourceId: null, referenceId: null, triggerStatus: fields.status, runId: null,
|
|
9
|
+
outcome: null, outcomeReason: null, outcomeShown: "No run record",
|
|
9
10
|
finishedAt: null, durationSeconds: null, error: null, runRecord: "none", storyId: null, storyVersionId: null, storyTitle: null,
|
|
10
11
|
costUsd: null, costNote: NOT_RECORDED, budgetUsd: null, overBudget: false, usage: null, ...fields,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
/** A realistic overview for tests and the `?demo=1` newsroom: one live monitor automation and one
|
|
15
|
+
/** A realistic overview for tests and the `?demo=1` newsroom: one live monitor automation and one switched-off schedule automation. */
|
|
15
16
|
export const FIXTURE_AUTOMATION_OVERVIEW: AutomationOverview = {
|
|
16
17
|
state: "ready",
|
|
17
18
|
asOf: "2026-10-23T12:00:00Z",
|
|
@@ -40,15 +41,18 @@ export const FIXTURE_AUTOMATION_OVERVIEW: AutomationOverview = {
|
|
|
40
41
|
runs: [
|
|
41
42
|
run({ sourceId: "91000001-EXA_26", referenceId: "ref-1", runId: "run-1", status: "completed", triggerStatus: "completed",
|
|
42
43
|
startedAt: "2026-10-23T11:30:00Z", finishedAt: "2026-10-23T11:33:10Z", durationSeconds: 190, runRecord: "found",
|
|
44
|
+
outcome: "acted", outcomeShown: "✓ Did it",
|
|
43
45
|
storyId: "story-1", storyVersionId: "version-1", storyTitle: "Board affirms a refusal for likelihood of confusion",
|
|
44
46
|
costUsd: 0.0123, costNote: ESTIMATED, budgetUsd: 0.05,
|
|
45
47
|
usage: { calls: 4, promptTokens: 61000, completionTokens: 5200, models: { "gpt-6-luna": 4 }, complete: true, unpricedModels: [] } }),
|
|
46
48
|
run({ sourceId: "91000002-EXA_26", referenceId: "ref-2", runId: "run-2", status: "failed", triggerStatus: "failed",
|
|
47
49
|
startedAt: "2026-10-23T05:30:00Z", finishedAt: "2026-10-23T05:31:00Z", durationSeconds: 60, runRecord: "found",
|
|
50
|
+
outcome: "failed", outcomeReason: "procedure_error", outcomeShown: "✗ Failed (procedure_error)",
|
|
48
51
|
error: "the opinion could not be downloaded" }),
|
|
49
52
|
run({ sourceId: "91000003-EXA_26", referenceId: "ref-3", status: "started", startedAt: "2026-10-23T11:59:00Z" }),
|
|
50
53
|
run({ origin: "manual", requestedBy: "ryan@example.test", runId: "run-4", status: "completed", triggerStatus: "completed",
|
|
51
54
|
startedAt: "2026-10-23T09:00:00Z", finishedAt: "2026-10-23T09:05:00Z", durationSeconds: 300, runRecord: "found",
|
|
55
|
+
outcome: "nothing", outcomeReason: "no_new_filing", outcomeShown: "– Nothing to do (no_new_filing)",
|
|
52
56
|
costUsd: 0.081, costNote: ESTIMATED, budgetUsd: 0.05, overBudget: true }),
|
|
53
57
|
run({ sourceId: "91000005-EXA_26", referenceId: "ref-5", status: "deferred", startedAt: "2026-10-23T08:00:00Z",
|
|
54
58
|
reason: "deferred: concurrency limit: 2 running, at most 2 at a time" }),
|
|
@@ -56,7 +60,7 @@ export const FIXTURE_AUTOMATION_OVERVIEW: AutomationOverview = {
|
|
|
56
60
|
reason: "automation disabled" }),
|
|
57
61
|
],
|
|
58
62
|
outsideRuns: [
|
|
59
|
-
{ runId: "run-9", status: "completed", startedAt: "2026-10-22T15:00:00Z", finishedAt: "2026-10-22T15:02:00Z", durationSeconds: 120,
|
|
63
|
+
{ runId: "run-9", status: "completed", outcome: null, outcomeReason: null, outcomeShown: "Recorded before outcomes", startedAt: "2026-10-22T15:00:00Z", finishedAt: "2026-10-22T15:02:00Z", durationSeconds: 120,
|
|
60
64
|
error: null, requestedBy: "papyrus-cli", storyId: null, storyVersionId: null, storyTitle: null, costUsd: null,
|
|
61
65
|
costNote: NOT_RECORDED, overBudget: false },
|
|
62
66
|
],
|
|
@@ -67,19 +71,20 @@ export const FIXTURE_AUTOMATION_OVERVIEW: AutomationOverview = {
|
|
|
67
71
|
title: "Weekly digest",
|
|
68
72
|
description: null,
|
|
69
73
|
enabled: false,
|
|
70
|
-
enabledNote: "
|
|
71
|
-
trigger: { kind: "schedule", config: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
enabledNote: "a disabled automation has no schedule entry, so nothing wakes it",
|
|
75
|
+
trigger: { kind: "schedule", config: { monitorId: "ttab", publicationId: "example" } },
|
|
76
|
+
schedule: { cron: "0 9 * * 1", timeZone: "America/New_York" },
|
|
77
|
+
supported: true,
|
|
78
|
+
supportNote: null,
|
|
74
79
|
procedureKey: "example.weekly-digest",
|
|
75
80
|
inputTemplate: {},
|
|
76
81
|
limits: { timeoutSeconds: 840 },
|
|
77
82
|
limitsNote: "the timeout and the number at a time (when set) are enforced when a run starts; the budget is advisory and only flagged",
|
|
78
|
-
runNow: { available: false, reason: "
|
|
83
|
+
runNow: { available: false, reason: "disabled", needsInput: false, inputNames: [] },
|
|
79
84
|
createdAt: "2026-10-23T10:05:00Z",
|
|
80
85
|
updatedAt: "2026-10-23T10:05:00Z",
|
|
81
|
-
link: { state: "
|
|
82
|
-
notice:
|
|
86
|
+
link: { state: "schedule", text: "Starts on its schedule: 0 9 * * 1 in America/New_York, from its definition." },
|
|
87
|
+
notice: null,
|
|
83
88
|
skippedAlreadyHadReference: 0,
|
|
84
89
|
lastRun: null,
|
|
85
90
|
runs: [],
|
|
@@ -14,7 +14,7 @@ export type AutomationUsage = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export type AutomationRun = {
|
|
17
|
-
origin: "monitor" | "manual" | "stage";
|
|
17
|
+
origin: "monitor" | "manual" | "stage" | "schedule";
|
|
18
18
|
/** The stage a story entered to start this run (origin "stage"). */
|
|
19
19
|
stage?: string | null;
|
|
20
20
|
requestedBy: string | null;
|
|
@@ -24,6 +24,11 @@ export type AutomationRun = {
|
|
|
24
24
|
triggerStatus: string | null;
|
|
25
25
|
runId: string | null;
|
|
26
26
|
status: string | null;
|
|
27
|
+
/** What came of a finished run (acted, nothing, asked, failed, unknown); null for a run recorded before outcomes or not finished. */
|
|
28
|
+
outcome: string | null;
|
|
29
|
+
outcomeReason: string | null;
|
|
30
|
+
/** The outcome in words with its mark, as the command line prints it (src/papyrus_content/run_outcomes.py). */
|
|
31
|
+
outcomeShown: string;
|
|
27
32
|
startedAt: string | null;
|
|
28
33
|
finishedAt: string | null;
|
|
29
34
|
durationSeconds: number | null;
|
|
@@ -47,6 +52,9 @@ export type AutomationRun = {
|
|
|
47
52
|
export type AutomationOutsideRun = {
|
|
48
53
|
runId: string | null;
|
|
49
54
|
status: string | null;
|
|
55
|
+
outcome: string | null;
|
|
56
|
+
outcomeReason: string | null;
|
|
57
|
+
outcomeShown: string;
|
|
50
58
|
startedAt: string | null;
|
|
51
59
|
finishedAt: string | null;
|
|
52
60
|
durationSeconds: number | null;
|
|
@@ -63,7 +71,7 @@ export type AutomationOutsideRun = {
|
|
|
63
71
|
export type AutomationRunNow = { available: boolean; reason: string | null; needsInput: boolean; inputNames: string[] };
|
|
64
72
|
|
|
65
73
|
export type AutomationLink = {
|
|
66
|
-
state: "linked" | "input_differs" | "trigger_not_found" | "publication_not_in_router" | "router_not_found" | "not_applicable";
|
|
74
|
+
state: "linked" | "input_differs" | "trigger_not_found" | "publication_not_in_router" | "router_not_found" | "not_applicable" | "schedule";
|
|
67
75
|
text: string;
|
|
68
76
|
routerMode?: string | null;
|
|
69
77
|
routerEnabled?: boolean;
|
|
@@ -78,6 +86,8 @@ export type AutomationRecord = {
|
|
|
78
86
|
enabled: boolean;
|
|
79
87
|
enabledNote: string;
|
|
80
88
|
trigger: { kind: "monitor" | "schedule" | "event" | "manual"; config: Record<string, unknown> };
|
|
89
|
+
/** Schedule automations: the time and zone the registered definition names (null when it names none or is retired). */
|
|
90
|
+
schedule?: { cron: string; timeZone: string } | null;
|
|
81
91
|
/** Story-stage automations only: the stage that fires it, where the engine moves the story after, and the bot-hop limit. */
|
|
82
92
|
onStage?: string | null;
|
|
83
93
|
nextStage?: string | null;
|
|
@@ -111,8 +121,9 @@ export type AutomationResult = AutomationOverview | { state: "unavailable" } | {
|
|
|
111
121
|
|
|
112
122
|
const KIND_WORDS: Record<string, string> = { monitor: "Monitor", schedule: "Schedule", event: "Event", manual: "Manual" };
|
|
113
123
|
|
|
114
|
-
export function triggerText(trigger: AutomationRecord["trigger"]): string {
|
|
124
|
+
export function triggerText(trigger: AutomationRecord["trigger"], schedule?: AutomationRecord["schedule"]): string {
|
|
115
125
|
const kind = KIND_WORDS[trigger.kind] ?? trigger.kind;
|
|
126
|
+
if (trigger.kind === "schedule" && schedule) return `${kind}: ${schedule.cron}, ${schedule.timeZone}`;
|
|
116
127
|
if (trigger.kind === "monitor") {
|
|
117
128
|
return `${kind} ${String(trigger.config.monitorId ?? "?")}, delivering to ${String(trigger.config.publicationId ?? "?")}`;
|
|
118
129
|
}
|
|
@@ -177,6 +188,7 @@ export function toolsText(run: Pick<AutomationRun, "toolsUsed">): string {
|
|
|
177
188
|
|
|
178
189
|
export function whoText(run: Pick<AutomationRun, "origin" | "requestedBy" | "sourceId"> & { stage?: string | null }): string {
|
|
179
190
|
if (run.origin === "stage") return `Story entered ${run.stage ?? "a stage"}`;
|
|
191
|
+
if (run.origin === "schedule") return "Schedule tick";
|
|
180
192
|
return run.origin === "manual" ? `Run now by ${run.requestedBy ?? "someone"}` : `Item: ${run.sourceId ?? "unknown"}`;
|
|
181
193
|
}
|
|
182
194
|
|
|
@@ -216,7 +228,7 @@ export function inputTemplateText(names: string[]): string {
|
|
|
216
228
|
return JSON.stringify(Object.fromEntries(names.map((name) => [name, ""])), null, 2);
|
|
217
229
|
}
|
|
218
230
|
|
|
219
|
-
const LINK_WORDS: Record<AutomationLink["state"], string> = {
|
|
231
|
+
const LINK_WORDS: Record<Exclude<AutomationLink["state"], "schedule">, string> = {
|
|
220
232
|
linked: "Linked: the router's trigger matches this record.",
|
|
221
233
|
input_differs: "Differs: the router's input template is not the same as this record's.",
|
|
222
234
|
trigger_not_found: "Not linked: the router has no trigger for this procedure.",
|
|
@@ -226,6 +238,7 @@ const LINK_WORDS: Record<AutomationLink["state"], string> = {
|
|
|
226
238
|
};
|
|
227
239
|
|
|
228
240
|
export function linkText(link: AutomationLink | null): string {
|
|
241
|
+
if (link?.state === "schedule") return link.text;
|
|
229
242
|
return link ? LINK_WORDS[link.state] ?? link.text : "Not checked";
|
|
230
243
|
}
|
|
231
244
|
|
|
@@ -234,7 +247,7 @@ const NOTICE_WORDS: Record<string, string> = {
|
|
|
234
247
|
monitoring_unavailable: "Run history could not be read right now. The record is shown without it.",
|
|
235
248
|
other_publication: "This automation belongs to another publication, so its runs are not shown here.",
|
|
236
249
|
publication_not_routed: "This publication is not one of the router's outputs, so there are no runs to show.",
|
|
237
|
-
"not yet supported": "Only monitor automations run today. This one is stored but nothing starts it.",
|
|
250
|
+
"not yet supported": "Only monitor and schedule automations run today. This one is stored but nothing starts it.",
|
|
238
251
|
};
|
|
239
252
|
|
|
240
253
|
export const OUTSIDE_NOTICE = "The procedure's other runs could not be read right now.";
|
|
@@ -65,7 +65,7 @@ export function formFromDocument(document: GuidelineDocument | null): WritingFor
|
|
|
65
65
|
* a section's document never carries the publication-only fields, so a section form leaves them out. An empty field is left out, never saved empty.
|
|
66
66
|
*/
|
|
67
67
|
export function documentFromForm(form: WritingForm, base: GuidelineDocument | null, scope: "publication" | "section"): GuidelineDocument {
|
|
68
|
-
const document: GuidelineDocument = { ...(base ?? {}), schemaVersion:
|
|
68
|
+
const document: GuidelineDocument = { ...(base ?? {}), schemaVersion: 2 };
|
|
69
69
|
const setOrDrop = (key: string, value: unknown, present: boolean) => { if (present) document[key] = value; else delete document[key]; };
|
|
70
70
|
setOrDrop("voice", { ...(base?.voice ?? {}), name: form.voiceName.trim() }, form.voiceName.trim() !== "");
|
|
71
71
|
setOrDrop("audience", form.audience.trim(), form.audience.trim() !== "");
|