@fro.bot/systematic 3.36.0 → 3.37.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/HARNESSES.md CHANGED
@@ -117,7 +117,7 @@ The `ce:connect` skill dispatches `connections-researcher`, an agent that must n
117
117
 
118
118
  What the evidence does not show: a scripted model makes the calls, so these proofs show enforcement plumbing, not live model choice. Read tools are not path-scoped on any host and session MCP tools are not denied; the guide documents both as limits. The v1 floor (1.18.29) has no row and is not run against this proof.
119
119
 
120
- The scheduled workflow is a separate surface: it runs the skill headless on a CI runner and posts a report issue. Live runs of it, including the report author, the in-place edit on a second same-day run, a hand cancel and an agent-step timeout, are recorded in [CN-6]. That entry also lists what was not observed live.
120
+ The scheduled workflow is a separate surface: it runs the skill headless on a CI runner and posts a report issue. Live runs of it, including the report author, the in-place edit on a second same-day run, a hand cancel and an agent-step timeout, are recorded in [CN-6]. That entry also lists what was not observed live. Calling the workflow from another repository, and the named `fetch:` that follows from it, rest on the probe runs in [CN-7], which also lists what was not observed.
121
121
 
122
122
  ## Worktree placement rule — bootstrap paths
123
123
 
@@ -308,3 +308,4 @@ Migrated-skill discipline is enforced by the [content-integrity gate](scripts/co
308
308
  - **CN-4** — Pi 1.5.0: `tests/unit/pi-delegate-session.test.ts` › "the shipped researcher reaches createAgentSession with read, grep and find and none of bash, write, edit or systematic_delegate" (the `observedBy` for this row; the real session builder runs against a fake runtime and the test asserts the `tools` that reach `createAgentSession`, not the mock); `tests/integration/pi.test.ts` › "a family completes inside the delegate turn cap with read, search and find tools only, and its batch validates" and "a child that never answers stops at the turn cap and the family is degraded, not empty" (the real Pi runtime, run in the v2 host-contract profile). Scope limit: the delegate is capped at 20 turns, and a scripted model drives the integration tests.
309
309
  - **CN-5** — Manual evidence, not a CI check. Recorded 2026-11-08 with Claude Code 2.1.319 (`claude --version` prints `2.1.319 (Claude Code)`), run by hand with the plugin bundle built from the rebased branch head and a live model. Verdict PASS. Run A dispatched `systematic:connections-researcher` through the `Agent` tool: the subagent reported its tools as Read, Grep and Glob, read a planted file and returned its marker, skipped Bash, Write, Edit and WebFetch as unavailable, and never called any of them (the checker found no call to Bash, Write, Edit, WebFetch, WebSearch or NotebookEdit). Run B started a session with `claude --agent systematic:connections-researcher`: the session's init message listed Read, Grep and Glob as its tools, none of Bash, Write, Edit, WebFetch, WebSearch or NotebookEdit, and no MCP tools; the read worked and its marker reached the answer. The `HOST_SUPPORT_TABLE` row names this entry as its `observedBy`. Limits: one live model on one Claude Code version; in run A the denial is the subagent's own report, because it never called the tools, and the host's own statement comes from run B's session tool list; the read tools are not path-scoped; whether a dispatched subagent can reach its parent session's MCP tools was not tested. `tests/unit/connect-host-isolation.test.ts` › "claude plugin validate accepts the definition and rejects one that does not parse" remains a parse check only, because an agent whose frontmatter fails to parse loads without its limits. Upstream issue reports 58645 and 94202 (cited from the research behind this feature, not re-checked) describe `disallowedTools` not being enforced for plugin and subagent Bash, so the agent leads with the positive `tools` allowlist.
310
310
  - **CN-6** — Manual evidence from live runs of `.github/workflows/connect.yaml`, not a CI check. Pins: `fro-bot/agent` v0.140.2 at `1ffb6495501f12801f770fa0c0563d16450416e7`, which runs OpenCode v2 2.2.6, and Systematic 3.33.0. Run [43362146039](https://github.com/marcusrbrown/systematic/actions/runs/43362146039) (first dispatch) ended `Connect complete` and posted report issue #1389, authored by `github-actions[bot]`. The ledger cache was empty (a reset). The agent step had no model input, so the parent ran on the action's default model; the step now passes the Fro Bot model. Run [43365759373](https://github.com/marcusrbrown/systematic/actions/runs/43365759373) (second dispatch, the same UTC date): the action log shows `hasModelOverride: true`, and the run ended `Connect complete`. `prepare` logged `Ticks from report #1389: accepted 2, skipped 0, unresolved 0`, and the ledger cache restored (sweep 96 of 435). The `render` visibility recheck passed under `permissions: {}` with the job token. `post` edited #1389 in place and opened no second issue, and the two rejected candidates left the report. Run [43368318366](https://github.com/marcusrbrown/systematic/actions/runs/43368318366) was cancelled by hand about 2.5 minutes into the agent step: the steps after the agent were skipped, `render` and `post` were cancelled, nothing was posted, and the cache and the report were untouched. That is why the agent step has its own timeout below the job's: a cancelled job skips every step after the agent, while a timed-out step lets the record be read, handed on and posted. Run [43475406631](https://github.com/marcusrbrown/systematic/actions/runs/43475406631) (a dispatch with `FRO_BOT_CONNECT_STEP_TIMEOUT` set to 2) ran that path live: the log shows `The action 'Run ce:connect' has timed out after 2 minutes.`, the next step then read the record (`ce:connect ended: no-final-line (agent step: failure).`), `render` logged `Rendered 0 of 0 open candidates, 0 new; outcome no-final-line.`, `post` ran its `Write report` step, and the final `Settle result` step failed red, so the workflow ended `failure`. Not observed live: a busy run, which cannot happen in CI by construction (the lock is never cached or handed off, each run gets a fresh runner, and the concurrency group serializes runs). The workflow tests cover the timeout path against stubbed `gh`, `git` and `npm`.
311
+ - **CN-7** — Manual evidence from live probe runs of a reusable workflow called from a local wrapper and from a wrapper in another owner, not a CI check. Recorded 2026-11-20. Pins: the probe callee was a temporary commit based on Systematic `30b57460` (a first probe commit `3c00cc70`, then a cache-path fix `585df268`, both on a probe branch since deleted); the caller in another owner was `fro-bot/agent` (a probe branch based on `e70df737`, since deleted) calling it by full 40-hex SHA; action pins copied from `connect.yaml` (`actions/checkout` v7.0.1, `actions/cache` v6.1.0, `actions/upload-artifact` v7.0.2). The probe ran no agent, used no provider secret (a literal stand-in secret was passed) and created no issue, pull request, release or tag. **Observed.** (1) Self-checkout: on the local call, [run 44700906722](https://github.com/marcusrbrown/systematic/actions/runs/44700906722), and on the cross-owner call, [run 44701027408](https://github.com/fro-bot/agent/actions/runs/44701027408), `job.workflow_repository`, `job.workflow_sha` and `job.workflow_file_path` name the callee, while `github.repository`, `github.ref` and `github.event.repository.default_branch` name the caller and `github.event_name` is the caller's event, never `workflow_call`. `job.workflow_ref` differs by call type (a branch ref on the local call, the 40-hex SHA on the cross-owner one), so the SHA is the field to read. A sparse checkout of `/.github/actions/` at `job.workflow_sha` (cone mode off, no persisted credential) succeeded on both with the caller's default job token, even for a public repository in another owner, and the action file was present (runs [44701974289](https://github.com/marcusrbrown/systematic/actions/runs/44701974289) and [44702043679](https://github.com/fro-bot/agent/actions/runs/44702043679)). (2) `referenced_workflows` is present on `/runs/{id}`, `/attempts/1` and `/attempts/2` for both call types and identical on both attempts after a failed-jobs rerun. It is a list; each entry has a `path` of `owner/repo/.github/workflows/x.yaml@<sha>` and a 40-hex `sha`, and the `ref` key appears only on the local call. The run's own `path` is the caller's wrapper. (3) Compare direction: `compare/<default branch>...<sha>` answers `ahead` for a commit on an unmerged branch, `behind` for one in the history of `main`, `identical` for its tip, and a 404 for an unknown or malformed SHA, the same shape as no access. An unauthenticated request to the public repository answered; a job-scoped token was not tried. (4) The cache is saved in the caller's repository, scoped to its ref, and a second run restored an earlier entry by prefix once save and restore used the same `path` (the cache version includes it); `cache-hit` was `false` on a prefix match and `cache-matched-key` showed the hit. `concurrency: { cancel-in-progress: false, queue: max }` is accepted in a called workflow: runs queued in push order, two runs were pending at once, cancelling the newest pending run left the older one intact (runs [44701421105](https://github.com/fro-bot/agent/actions/runs/44701421105), [44701505528](https://github.com/fro-bot/agent/actions/runs/44701505528), [44701582882](https://github.com/fro-bot/agent/actions/runs/44701582882) and [44701627675](https://github.com/fro-bot/agent/actions/runs/44701627675)), and a group of the same name in two owners did not collide. (5) `vars` resolve against the caller: Systematic's variable was empty in the cross-owner call, and a secret the caller passed by name reached the callee in both calls. (6) A failed-jobs rerun reran only the failed job, kept the callee SHA, and left only the attempt-1 artifacts, so a later job must not rebuild an artifact name from `github.run_attempt`. (7) The job token's logged grant on a callee job with `contents: read` under a caller grant of `contents: read` was `Contents: read` and `Metadata: read`, and a top-level `permissions: {}` in the callee widened nothing. (8) A caller in another organization called a public, SHA-pinned workflow in `marcusrbrown/systematic` at a commit not on `main` without a policy error; that organization's Actions policy itself was unreadable (HTTP 403). **Read from source, not run.** A read of `fro-bot/agent` v0.146.0 (`65239fc5`) with OpenCode v2.3.2 shows that `repo-skills: "false"` stages no skills, that the repository's skills are never read in place (when the setting is on, the base repository's default branch is copied), and that the action sets `OPENCODE_DISABLE_PROJECT_CONFIG` for every spawn, which turns project config and project instruction discovery off, so `.agents/skills`, `AGENTS.md`, `CLAUDE.md`, `opencode.json` and repository plugins should not load. **Not observed.** The report issue's author and an Issues write under the narrowed ceiling in a caller; a callee asking for more than its caller grants; a live agent run with repository skills off (and `.claude/skills` and `.opencode/` plugin directories, which were not traced to a line); a tag-pinned cross-owner call, whose `referenced_workflows` suffix may differ, so the skill reads the `sha` and never the suffix or `ref`; a job-scoped token for the compare request; the organization's Actions policy. The probe workflow files no longer exist on any branch, so the run pages may show no workflow definition, and the logs expire on the normal schedule. The code that relies on these facts is the self-checkout step and the guards in `.github/workflows/connect.yaml`, and the named-fetch steps in `skills/ce-connect/references/fetch-and-import.md`, which `tests/unit/connect-workflow.test.ts`, `tests/unit/connect-scheduled-workflow.test.ts` and `tests/unit/connect-skill-contract.test.ts` pin against stubs.
@@ -17,7 +17,7 @@ import { type InvocationWriteOptions, type ProcessTable, type PublishOptions } f
17
17
  * file the skill writes in the run's work directory, read here through the
18
18
  * bounded reader as a regular file.
19
19
  */
20
- export declare const CE_CONNECT_USAGE = "Usage: node connect.mjs <begin|validate|publish|decide|import|apply-ticks|render-report|ledger show [--offset N]|ledger clear|ledger unlock>";
20
+ export declare const CE_CONNECT_USAGE = "Usage: node connect.mjs <begin|validate|publish|decide|import|apply-ticks|render-report|allowed-origins|verify-provenance|ledger show [--offset N]|ledger clear|ledger unlock>";
21
21
  export interface HelperDeps {
22
22
  /** Environment for `XDG_STATE_HOME`. Defaults to `process.env`. */
23
23
  readonly env?: Readonly<Record<string, string | undefined>>;
@@ -165,6 +165,12 @@ export interface RenderRequest {
165
165
  readonly attempt: string;
166
166
  /** Whether an Actions cache was restored for this run. */
167
167
  readonly cacheRestored: boolean;
168
+ /**
169
+ * The `owner/repo` that called the workflow. Absent, or Systematic itself
170
+ * (ignoring case), the fetch words stay bare: a bare word always means
171
+ * Systematic. Any other repository is named in every fetch word.
172
+ */
173
+ readonly repo?: string;
168
174
  }
169
175
  export type RenderResult = {
170
176
  readonly status: 'rendered';
@@ -181,7 +187,7 @@ export type RenderResult = {
181
187
  readonly unverified: number;
182
188
  /** Candidates listed for the first time on this date. */
183
189
  readonly fresh: number;
184
- /** The `<run>.<attempt>` fetch words of the listed candidates, in the order they appear. */
190
+ /** The fetch words of the listed candidates, in the order they appear: `<run>.<attempt>`, or `<owner>/<repo>:<run>.<attempt>` for a caller other than Systematic. */
185
191
  readonly fetches: readonly string[];
186
192
  readonly outcome: ReportOutcome;
187
193
  /** The workflow job turns red after posting. */
@@ -211,6 +217,8 @@ export interface BodyInput {
211
217
  readonly rows: readonly Row[];
212
218
  /** The ids of the other open entries, oldest first. */
213
219
  readonly unverified: readonly string[];
220
+ /** The caller repository the fetch words name; absent for Systematic, whose words are bare. */
221
+ readonly fetchRepo?: string;
214
222
  }
215
223
  export interface Assembled {
216
224
  readonly body: string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The provenance decision of a named `ce:connect` fetch: did the scheduled run
3
+ * of another repository call Systematic's reusable `connect.yaml` at a commit
4
+ * on Systematic's default branch? The skill does the network part with the
5
+ * user's own `gh` and sends the text it got here, so the choice of entry, the
6
+ * shape of the hash and the compare verdict are code, not a model's reading of
7
+ * JSON.
8
+ *
9
+ * Two questions, one function. With the attempt's `referenced_workflows` alone
10
+ * it answers which commit to compare (`selected`). With the compare `status`
11
+ * as well it answers whether that commit is on the default branch
12
+ * (`accepted`). Every other case is a refusal that names one reason.
13
+ *
14
+ * Pure: no network, no file, no state. The verdict carries a reason or a hash
15
+ * and never any of the input. Import rule: nothing, because the `ce:connect`
16
+ * helper bundles it.
17
+ */
18
+ export type ProvenanceVerdict = {
19
+ readonly status: 'selected';
20
+ readonly sha: string;
21
+ } | {
22
+ readonly status: 'accepted';
23
+ readonly sha: string;
24
+ } | {
25
+ readonly status: 'refused';
26
+ readonly reason: 'provenance-unprovable' | 'not-a-connect-run';
27
+ };
28
+ export interface ProvenanceInput {
29
+ /** The text `gh api .../attempts/<n> --jq .referenced_workflows` printed. */
30
+ readonly referencedWorkflows: unknown;
31
+ /** The text `gh api .../compare/main...<sha> --jq .status` printed, when the commit was compared. */
32
+ readonly status?: unknown;
33
+ }
34
+ export declare function verifyProvenance(input: ProvenanceInput): ProvenanceVerdict;
@@ -17,6 +17,14 @@ export interface RepoIdentity {
17
17
  /** The full hash HEAD names. */
18
18
  readonly commit?: string;
19
19
  }
20
+ /**
21
+ * `owner/repo`, shaped as GitHub allows and nothing else. The one rule for a
22
+ * repository that is printed into a command, put in an API path or recorded as
23
+ * provenance, so every `connect-*` module and the helper agree on it. It checks
24
+ * the shape only and keeps the case; it says nothing about whether the
25
+ * repository exists.
26
+ */
27
+ export declare function isGithubOwnerRepo(value: string): boolean;
20
28
  /**
21
29
  * `owner/repo` of a GitHub remote URL, lowercase, or nothing. Three forms are
22
30
  * read: an https URL, `git@github.com:o/r` and an `ssh://` URL, each with or
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fro.bot/systematic",
3
- "version": "3.36.0",
3
+ "version": "3.37.0",
4
4
  "description": "Compound-engineering loops for OpenCode, Pi, and Claude Code",
5
5
  "type": "module",
6
6
  "homepage": "https://fro.bot/systematic",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ce:connect
3
3
  description: "Use when searching the projects the user has allowed for contradictions between their learnings, for a lesson that one project recorded and a sibling project still needs, or for a learning whose claim the code no longer supports. Also use when the user asks what their other projects have learned about a failure."
4
- argument-hint: "[mode:headless | mode:interactive] [group:<name> | projects:<a>,<b> | fetch:<run>[.<attempt>]]"
4
+ argument-hint: "[mode:headless | mode:interactive] [group:<name> | projects:<a>,<b> | fetch:<run>[.<attempt>] | fetch:<owner>/<repo>:<run>.<attempt>]"
5
5
  metadata:
6
6
  harness-portability: neutral-v1
7
7
  ---
@@ -57,11 +57,12 @@ In the same pass, list every word that starts with `group:` or `projects:`, from
57
57
 
58
58
  ### Fetch word
59
59
 
60
- In the same pass, list every word that starts with `fetch:`. `fetch:<run>.<attempt>` brings the candidates of a scheduled CI run to this machine from exactly that attempt of the run. A bare `fetch:<run>` means the newest attempt of that run. A scheduled report prints the `<run>.<attempt>` form. `<run>` is the GitHub run id and `<attempt>` the attempt number; each is a positive integer, digits only, with no sign, no space and no leading zero. A `<run>` has at most 20 digits and an `<attempt>` at most 10. The value must match `^[1-9][0-9]{0,19}(\.[1-9][0-9]{0,9})?$` and nothing else. The same `fetch:` word twice or more counts once. `fetch:<run>` and `fetch:<run>.<attempt>` are different words.
60
+ In the same pass, list every word that starts with `fetch:`. `fetch:<run>.<attempt>` brings the candidates of a scheduled CI run to this machine from exactly that attempt of the run. A bare `fetch:<run>` means the newest attempt of that run. A bare word always means Systematic: its repository is `marcusrbrown/systematic`. `fetch:<owner>/<repo>:<run>.<attempt>` is the named form: it brings the candidates of a scheduled run of another repository, one that called Systematic's reusable workflow, from exactly that attempt. In the named form the attempt is required. A scheduled report prints the bare `<run>.<attempt>` form for Systematic's own run and the named form for another repository's run. `<run>` is the GitHub run id and `<attempt>` the attempt number; each is a positive integer, digits only, with no sign, no space and no leading zero. A `<run>` has at most 20 digits and an `<attempt>` at most 10. The value must match `^[1-9][0-9]{0,19}(\.[1-9][0-9]{0,9})?$` and nothing else. A named value must match `^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?/(?!\.{1,2}:)[A-Za-z0-9._-]{1,100}:[1-9][0-9]{0,19}\.[1-9][0-9]{0,9}$` and nothing else: an owner of at most 39 letters, digits and hyphens with no hyphen at either end, one `/`, a repository of 1 to 100 letters, digits, `.`, `_` and `-` (not `.` or `..`), a `:`, then the run and the attempt. A value that holds a `/` or a `:` is checked as named; any other value is checked as bare. The same `fetch:` word twice or more counts once. `fetch:<run>` and `fetch:<run>.<attempt>` are different words, and a bare word and a named word are different words.
61
61
 
62
62
  - A `fetch:` word together with a `group:` or `projects:` word: stop. The reason is `conflicting-selection: fetch: cannot be combined with group: or projects:`.
63
63
  - Two different `fetch:` words: stop. The reason is `conflicting-selection: two different fetch: words`.
64
- - A `fetch:` value that does not match that pattern, such as an empty one, a zero attempt or a second dot: stop. The reason is `invalid-request: fetch: needs a numeric GitHub run id`. Check this before any value reaches a command.
64
+ - A bare `fetch:` value that does not match the bare pattern, such as an empty one, a zero attempt or a second dot: stop. The reason is `invalid-request: fetch: needs a numeric GitHub run id`. Check this before any value reaches a command.
65
+ - A named `fetch:` value that does not match the named pattern, such as a missing attempt, a repository with a leading or trailing hyphen on the owner, a `..` repository or a third segment: stop. The reason is `invalid-request: fetch: a named word is <owner>/<repo>:<run>.<attempt>`, with the remedy on the same line: `Supply `fetch:<owner>/<repo>:<run>.<attempt>` and try again.` Check this before any value reaches a command, including the helper.
65
66
  - A stop here happens before any command, in the two-line form of Step 1.
66
67
  - One valid `fetch:` word: skip Steps 2 to 7 and follow `references/fetch-and-import.md`. A fetch observes no host, dispatches no agent, asks nothing and takes no mode: `mode:` has no effect on it. It ends with the final line that reference names.
67
68
 
@@ -1,34 +1,149 @@
1
1
  # Fetch and import
2
2
 
3
- `fetch:<run>.<attempt>` brings the candidates of one attempt of a scheduled CI run to this machine, so a lesson the runner found can be promoted here after the runner is gone. A bare `fetch:<run>` does the same for the newest attempt of that run. In every command below, `<run>` and `<attempt>` are the numbers `SKILL.md` already checked: positive integers, nothing else. The skill does the part that needs the network, with the user's own `gh`. The helper's `import` operation does the rest and never touches the network.
3
+ `fetch:<run>.<attempt>` brings the candidates of one attempt of a scheduled CI run to this machine, so a lesson the runner found can be promoted here after the runner is gone. A bare `fetch:<run>` does the same for the newest attempt of that run. A bare word means Systematic. A named word, `fetch:<owner>/<repo>:<run>.<attempt>`, does the same for one attempt of a scheduled run in another repository that called Systematic's reusable workflow; there the attempt is required. In every command below, `<run>` and `<attempt>` are the numbers `SKILL.md` already checked: positive integers, nothing else. `<repo>` is `marcusrbrown/systematic` for a bare word, and for a named word the `owner/repo` of the word, lowercased, after step 1 found it among the allowed origins. The skill does the part that needs the network, with the user's own `gh`. The helper's `import` operation does the rest and never touches the network.
4
+
5
+ Every `gh` call below names github.com explicitly, as a host flag or as a `github.com/` repository, because the allow-list origin is a github.com origin, so `GH_HOST` or a GHE remote must not redirect the checks.
4
6
 
5
7
  A fetch dispatches no agent, asks nothing and takes no host observation. It uses neither `begin` nor `publish`. It ends with the `finalLine` that `import` answers, or with `Connect failed` for a stop before `import`.
6
8
 
7
- The repository is fixed: `marcusrbrown/systematic`. Never take a repository, a path or a workflow name from the user's words or from a downloaded file.
9
+ The repository of a bare word is fixed: `marcusrbrown/systematic`. The repository of a named word is the one in the word, used only after step 1 found it among the allowed origins. Never take a repository, a path or a workflow name from the downloaded record or from any other file: a repository comes from the user's word, never from a downloaded file.
10
+
11
+ A bare word never reads `referenced_workflows`. Its whole check is the fixed repository, the event and the run's top-level workflow path, so Systematic's own fetch does not depend on the proof a named word needs.
8
12
 
9
13
  ## Order
10
14
 
11
- Do these in order. Start every block that runs a command with the same anchor lines as the other steps, with `SKILL_DIR` set to the skill directory stated when this skill loads.
15
+ Do these in order. Start every block that runs a command with the same anchor lines as the other steps, with `SKILL_DIR` set to the skill directory stated when this skill loads. A bare word skips steps 1 and 3.
16
+
17
+ ### 1. Resolve the repository
12
18
 
13
- ### 1. Check the run, before any download
19
+ A bare word keeps the fixed repository; skip to step 2 and check no origin.
20
+
21
+ For a named word, ask the helper which origins are allowed before any `gh` command:
14
22
 
15
23
  ```bash
16
24
  # Resolve helper scripts relative to this skill's directory.
17
25
  SKILL_DIR="<skill directory stated when this skill loads>";
18
- gh api "repos/marcusrbrown/systematic/actions/runs/<run>" --jq '[.path, .event, .head_sha] | @tsv'
26
+ node "$SKILL_DIR/scripts/connect.mjs" allowed-origins
19
27
  ```
20
28
 
21
- `gh run view --json` has no workflow path, so the API call is the check. It prints three tab-separated values: the workflow path, the event and the head commit.
29
+ It takes no request and answers one line of JSON with three fields: `origins`, the lowercase `owner/repo` of the GitHub origin of each allowed checkout; `ambiguous`, the origins that two or more allowed checkouts share; and `configUnreadable`. It reads configuration only: it takes no lock, writes nothing and never prints a local path. Never read the configuration yourself.
30
+
31
+ Lowercase the word's `<owner>/<repo>` and look for it in `origins`, which is already lowercase, so the match ignores case: `Fro-Bot/Agent` matches the origin `fro-bot/agent`. From here on, use that lowercase form as `<repo>`.
22
32
 
23
- - The path must be `.github/workflows/connect.yaml`. Drop a trailing `@<ref>` before comparing. Any other path: stop with `not-a-connect-run`.
33
+ - It is not in `origins`: stop with `origin-not-allowed`. Run no `gh` command. Nothing was downloaded. To fix it, allow-list a checkout of that repository: add a local checkout whose `origin` remote is `<repo>` to `connect.allow_projects`, then try again. When `configUnreadable` is `true`, say that the allow list could not be read.
34
+ - It is in `ambiguous`: stop with `repo-ambiguous`. `import` would refuse every candidate of that repository for the same reason. Nothing was downloaded. Remove all but one of the checkouts from the allow list, then try again.
35
+ - The answer is JSON with `ok: false`, or JSON without `origins`: stop and print the helper's `reason`, then `Connect failed`, without running `gh`. Nothing was downloaded. Never guess an origin from a path or from the checkouts you can see.
36
+ - If `node` is missing, the helper file is gone, or `allowed-origins` prints no JSON answer, the helper is unavailable: print `helper-unavailable` and its hint, then `Connect failed`. Nothing was downloaded.
37
+
38
+ ### 2. Check the run, before any download
39
+
40
+ `gh run view --json` has no workflow path, so the API call is the check.
41
+
42
+ #### Bare word
43
+
44
+ ```bash
45
+ # Resolve helper scripts relative to this skill's directory.
46
+ SKILL_DIR="<skill directory stated when this skill loads>";
47
+ gh api --hostname github.com "repos/marcusrbrown/systematic/actions/runs/<run>" --jq '[.path, .event, .head_sha] | @tsv'
48
+ ```
49
+
50
+ It prints three tab-separated values: the workflow path, the event and the head commit.
51
+
52
+ - The path must be `.github/workflows/connect.yaml` (a direct run) or `.github/workflows/connect-scheduled.yaml` (Systematic's own scheduled wrapper). Drop a trailing `@<ref>` before comparing. Any other path (for example `.github/workflows/fro-bot.yaml`): stop with `not-a-connect-run`.
24
53
  - The event must be `schedule` or `workflow_dispatch`. Any other event: stop with `unsupported-run-event`. A run triggered by a pull request is never read, whatever its artifacts hold.
25
54
  - The command fails with a 404: stop with `run-not-found`. It fails because `gh` is not logged in: stop with `gh-not-authenticated`.
26
55
  - Keep the head commit for the request below. It must be 40 or 64 lowercase hex characters; otherwise leave `commit` out.
56
+ - Skip step 3 and go to step 4.
27
57
 
28
- ### 2. Choose the artifact
58
+ #### Named word
29
59
 
30
60
  ```bash
31
- gh api "repos/marcusrbrown/systematic/actions/runs/<run>/artifacts?per_page=100" --jq '[.artifacts[] | {name: .name, expired: .expired}]'
61
+ # Resolve helper scripts relative to this skill's directory.
62
+ SKILL_DIR="<skill directory stated when this skill loads>";
63
+ gh api --hostname github.com "repos/<repo>/actions/runs/<run>" --jq '[.event, .head_sha] | @tsv'
64
+ ```
65
+
66
+ It prints two tab-separated values: the event and the head commit.
67
+
68
+ - The event must be `schedule` or `workflow_dispatch`. Any other event: stop with `unsupported-run-event`.
69
+ - The command fails with a 404: stop with `run-not-found`. It fails because `gh` is not logged in: stop with `gh-not-authenticated`. It fails for any other reason: stop with `provenance-unprovable`.
70
+ - The run's own path is the caller's wrapper, so it is not read here, and a wrapper's own path proves nothing. Step 3 proves what the run called.
71
+ - Keep the head commit for the request below. It must be 40 or 64 lowercase hex characters; otherwise leave `commit` out.
72
+
73
+ ### 3. Prove the provenance (named words only)
74
+
75
+ The helper decides this step. You fetch the text from `gh`, send it to the helper and act on the answer. Never judge `referenced_workflows` yourself: never read the list, pick an entry or check a hash. The helper's `verify-provenance` operation takes no lock, writes nothing, reads no network or configuration and never prints a path.
76
+
77
+ Read the exact attempt the word names. Never read the run's newest attempt instead.
78
+
79
+ ```bash
80
+ gh api --hostname github.com "repos/<repo>/actions/runs/<run>/attempts/<attempt>" --jq .referenced_workflows
81
+ ```
82
+
83
+ It prints the attempt's `referenced_workflows`.
84
+
85
+ - The attempt does not exist (a 404): stop with `run-not-found`.
86
+ - `gh` is not logged in: stop with `gh-not-authenticated`.
87
+ - The API call fails for any other reason: stop with `provenance-unprovable`, with its remedy from the table below.
88
+
89
+ Never download on any stop below. Send the text `gh` printed, unchanged, to the helper on stdin:
90
+
91
+ ```bash
92
+ # Resolve helper scripts relative to this skill's directory.
93
+ SKILL_DIR="<skill directory stated when this skill loads>";
94
+ node "$SKILL_DIR/scripts/connect.mjs" verify-provenance <<'JSON'
95
+ <the text gh printed, unchanged>
96
+ JSON
97
+ ```
98
+
99
+ It answers one line of JSON. It takes the text as it is, so text that is not JSON is judged by the helper, not refused as a bad request. It decides, in this order:
100
+
101
+ - The value is absent or `null`, is not a list, is empty, or an entry has no string `path`: `provenance-unprovable`.
102
+ - It takes the entries whose `path`, the part before the `@`, is `marcusrbrown/systematic/.github/workflows/connect.yaml`, comparing `marcusrbrown/systematic` without regard to case and the rest exactly (`MarcusRBrown/Systematic/.github/workflows/connect.yaml@<sha>` matches; `marcusrbrown/systematic/.github/Workflows/connect.yaml` does not). It matches by path, never by position in the list.
103
+ - No entry matches: `not-a-connect-run`. The run is proven to be another workflow, such as another repository's workflow, a fork or another path.
104
+ - More than one entry matches: `provenance-unprovable`.
105
+ - The matching entry's `sha` is not 40 lowercase hex characters: `provenance-unprovable`. It never uses `ref` or the text after the `@`.
106
+
107
+ Read the answer:
108
+
109
+ - `ok: true` with `stage: "selected"`: the answer carries `sha`. Go on to the compare below.
110
+ - `ok: false`: stop with the `reason` it names, `provenance-unprovable` or `not-a-connect-run`, and print the remedy from the table below. Download nothing and run no further `gh` command.
111
+ - JSON with any other `reason` (such as `invalid-request`), or JSON with neither `ok: true` nor a `reason`: stop and print that `reason`, then `Connect failed`, without running `gh`. Nothing was downloaded.
112
+ - If `node` is missing, the helper file is gone, or the operation prints no JSON answer, the helper is unavailable: print `helper-unavailable` and its hint, then `Connect failed`. Nothing was downloaded.
113
+
114
+ Then check that the commit is on Systematic's default branch:
115
+
116
+ ```bash
117
+ gh api --hostname github.com "repos/marcusrbrown/systematic/compare/main...<sha>" --jq .status
118
+ ```
119
+
120
+ `<sha>` is the `sha` the helper answered. The base is `main` and the head is the `sha`. Never swap the two sides of the range.
121
+
122
+ - The command fails (a 404, which an unknown commit and no access both give, or any other failure): stop with `provenance-unprovable`, with its remedy from the table below. Do not call the helper again.
123
+ - It prints a status. Send the same text again, with the status as `gh` printed it, with no trailing newline:
124
+
125
+ ```bash
126
+ # Resolve helper scripts relative to this skill's directory.
127
+ SKILL_DIR="<skill directory stated when this skill loads>";
128
+ node "$SKILL_DIR/scripts/connect.mjs" verify-provenance --status "<status>" <<'JSON'
129
+ <the same text again>
130
+ JSON
131
+ ```
132
+
133
+ - `ok: true` with `stage: "accepted"`: the commit is behind or identical to `main`, so it is in the history of `main`. Go on.
134
+ - `ok: false`: stop with the `reason` it names. The helper refuses `ahead` (the commit is not in `main`), `diverged`, an empty status and any other status as `provenance-unprovable`.
135
+ - Any other answer: stop as above.
136
+
137
+ `provenance-unprovable` means the proof is missing. It is not a finding that the run is hostile. To fix it, check that the caller's wrapper calls `marcusrbrown/systematic/.github/workflows/connect.yaml` at a commit on Systematic's `main`, then try again. If an API call failed, try again later.
138
+
139
+ ### 4. Choose the artifact
140
+
141
+ The record is in an artifact named `connect-run-<run>-<attempt>`, where `<attempt>` is digits only. How to list it depends on whether the attempt is known.
142
+
143
+ For a named word or an explicit attempt (`fetch:<run>.<attempt>` or `fetch:<owner>/<repo>:<run>.<attempt>`), look the artifact up by its exact name:
144
+
145
+ ```bash
146
+ gh api --hostname github.com "repos/<repo>/actions/runs/<run>/artifacts?name=connect-run-<run>-<attempt>" --jq '[.artifacts[] | {name: .name, expired: .expired}]'
32
147
  ```
33
148
 
34
149
  It prints one JSON array of `{name, expired}` objects. Check the call before you read the array:
@@ -36,10 +151,24 @@ It prints one JSON array of `{name, expired}` objects. Check the call before you
36
151
  - The command fails because `gh` is not logged in: stop with `gh-not-authenticated`.
37
152
  - The command fails for any other reason (a non-zero exit), or its output is not a JSON array: stop with `artifact-list-failed`. An empty array is an answer; a failed call is not. Never read a failed call as `artifact-not-found`.
38
153
 
39
- The record is in an artifact named `connect-run-<run>-<attempt>`, where `<attempt>` is digits only. Take the names that match that pattern for this run id exactly.
154
+ Only a name that is exactly `connect-run-<run>-<attempt>` counts.
155
+
156
+ For a bare `fetch:<run>`, the attempt is not known, so list every artifact of the run. A run can hold more than one page of them, so paginate:
157
+
158
+ ```bash
159
+ gh api --hostname github.com --paginate "repos/<repo>/actions/runs/<run>/artifacts?per_page=100" --jq '.artifacts[] | {name: .name, expired: .expired}'
160
+ ```
161
+
162
+ It prints one JSON object per line, `{name, expired}`, across all pages. Check the call before you read the lines:
163
+
164
+ - The command fails because `gh` is not logged in: stop with `gh-not-authenticated`.
165
+ - The command fails for any other reason (a non-zero exit), or a line is not a JSON object: stop with `artifact-list-failed`. An empty output with a zero exit is an answer; a failed call is not. Never read a failed call as `artifact-not-found`.
166
+
167
+ Take the names that match `connect-run-<run>-<attempt>` for this run id exactly.
40
168
 
41
169
  - With a bare `fetch:<run>`, pick the one with the highest attempt. A run with attempts 1 and 2 downloads `connect-run-<run>-2`.
42
170
  - With `fetch:<run>.<attempt>`, download exactly `connect-run-<run>-<attempt>` with that attempt. Do not pick the highest attempt. A report names the attempt a candidate came from, and a later attempt may not hold it.
171
+ - With `fetch:<owner>/<repo>:<run>.<attempt>`, download exactly `connect-run-<run>-<attempt>` with the attempt that step 3 proved, from the named repository's run. There is no other choice.
43
172
 
44
173
  Then:
45
174
 
@@ -47,16 +176,22 @@ Then:
47
176
  - The chosen artifact is expired: stop with `artifact-expired`. The user can tick Rejected in the scheduled run's report, or wait for the candidate to be proposed again.
48
177
  - If the named attempt has no artifact, stop with `artifact-not-found`, even when another attempt of the run has one. If the named attempt's artifact is expired, stop with `artifact-expired`. Print the fixed reason and its hint only. Never fall back to another attempt and do not suggest one.
49
178
 
50
- ### 3. Download into a fresh directory
179
+ ### 5. Download into a fresh directory
51
180
 
52
181
  ```bash
53
182
  mktemp -d
54
183
  ```
55
184
 
56
- Shell state does not persist between tool calls, so write the absolute path it prints (`<DEST>`) into each later command. Then download into it:
185
+ Shell state does not persist between tool calls, so write the absolute path it prints (`<DEST>`) into each later command. Then download into it. For a bare word:
57
186
 
58
187
  ```bash
59
- gh run download <run> --repo marcusrbrown/systematic --name "connect-run-<run>-<attempt>" --dir "<DEST>"
188
+ gh run download <run> --repo github.com/marcusrbrown/systematic --name "connect-run-<run>-<attempt>" --dir "<DEST>"
189
+ ```
190
+
191
+ For a named word, use the repository step 1 checked:
192
+
193
+ ```bash
194
+ gh run download <run> --repo github.com/<repo> --name "connect-run-<run>-<attempt>" --dir "<DEST>"
60
195
  ```
61
196
 
62
197
  - `gh` fails because it is not logged in or the token cannot read the run: stop with `gh-not-authenticated`.
@@ -65,21 +200,23 @@ gh run download <run> --repo marcusrbrown/systematic --name "connect-run-<run>-<
65
200
 
66
201
  The artifact holds one file, `run.json`, at its root. Do not open it and do not list the directory. The helper reads that one path and nothing else.
67
202
 
68
- ### 4. Import
203
+ ### 6. Import
69
204
 
70
205
  ```bash
71
206
  # Resolve helper scripts relative to this skill's directory.
72
207
  SKILL_DIR="<skill directory stated when this skill loads>";
73
208
  node "$SKILL_DIR/scripts/connect.mjs" import <<'JSON'
74
- {"directory": "<DEST>", "provenance": {"repo": "marcusrbrown/systematic", "runId": "<run>", "commit": "<head commit>"}}
209
+ {"directory": "<DEST>", "provenance": {"repo": "<repo>", "runId": "<run>", "commit": "<head commit>"}}
75
210
  JSON
76
211
  ```
77
212
 
78
- `directory` is the absolute path `mktemp -d` printed. `runId` is the run id from the `fetch:` word, without the attempt. Leave `commit` out when step 1 gave none. The record carries no attempt, so the request carries none either: the artifact name in step 2 is the only place the attempt is checked.
213
+ `directory` is the absolute path `mktemp -d` printed. `repo` is `<repo>`: `<repo>` is `marcusrbrown/systematic` for a bare word, and the named repository for a named word. `runId` is the run id from the `fetch:` word, without the attempt. Leave `commit` out when step 2 gave none. For a named word that `head_sha` is the caller's wrapper commit, not the callee's commit of Systematic's workflow. The record carries no attempt, so the request carries none either: the artifact name in step 4 is the only place the attempt is checked.
214
+
215
+ A named fetch that passed steps 1 to 3 has proven where the run came from. It has not widened what `import` accepts: `import` still checks every project of the record against the allowed checkouts by its own check, and refuses a candidate from a project that is not allowed as `repo-not-allowed`.
79
216
 
80
217
  If `node` is missing, the helper file is gone, or `import` prints no JSON answer, the helper is unavailable. Remove `<DEST>`, print `helper-unavailable` and its hint, then `Connect failed`. Nothing was imported.
81
218
 
82
- ### 5. Report
219
+ ### 7. Report
83
220
 
84
221
  The helper answers one line of JSON. Read `outcome`:
85
222
 
@@ -98,9 +235,12 @@ Print the reason as it is, then the hint.
98
235
 
99
236
  | Reason | Hint |
100
237
  |---|---|
101
- | `not-a-connect-run` | The run is not a run of `.github/workflows/connect.yaml`. Nothing was downloaded. |
102
- | `unsupported-run-event` | Only `schedule` and `workflow_dispatch` runs are read. Nothing was downloaded. |
103
- | `run-not-found` | No run with that id in `marcusrbrown/systematic`. |
238
+ | `origin-not-allowed` | The named repository is not the origin of any allowed checkout. Nothing was downloaded. Allow-list a checkout of that repository in `connect.allow_projects`, then try again. |
239
+ | `repo-ambiguous` | Two or more allowed checkouts have the named repository as their origin. Nothing was downloaded. Remove all but one from the allow list. |
240
+ | `provenance-unprovable` | The named run cannot be shown to have called Systematic's `connect.yaml` at a commit on Systematic's default branch: the attempt's `referenced_workflows` is absent, empty or malformed, more than one entry matches, the `sha` is not 40 lowercase hex characters, the commit is not behind or identical to `main`, or an API call failed. Nothing was downloaded. This fails closed: it is a missing proof, not a finding that the run is hostile. To fix it, check that the caller's wrapper calls `marcusrbrown/systematic/.github/workflows/connect.yaml` at a commit on Systematic's `main`, then try again. If an API call failed, try again later. |
241
+ | `not-a-connect-run` | The run is not a run of Systematic's `connect.yaml`. For a bare word its top-level path is neither `.github/workflows/connect.yaml` nor `.github/workflows/connect-scheduled.yaml`. For a named word the attempt's `referenced_workflows` names other workflows only. Nothing was downloaded. Name a scheduled run of Systematic's `connect.yaml`, or of a caller that calls it, then try again. |
242
+ | `unsupported-run-event` | Only `schedule` and `workflow_dispatch` runs are read. Nothing was downloaded. Name a scheduled or manually dispatched run, then try again. |
243
+ | `run-not-found` | No run with that id in the repository, or, for a named word, no such attempt of it. Check the run and attempt in the report's fetch word, then try again. |
104
244
  | `gh-not-authenticated` | `gh` is not logged in, or its token cannot read this repository's runs. Run `gh auth login` and try again. |
105
245
  | `artifact-list-failed` | `gh` could not list the run's artifacts, or its answer was not a JSON array. Nothing was downloaded. Try again. |
106
246
  | `artifact-not-found` | The run has no `connect-run-<run>-<attempt>` artifact for the attempt asked for. It stopped before it made a record. |
@@ -117,6 +257,8 @@ Print the reason as it is, then the hint.
117
257
  | `lock-failed`, `publish-…` | The run could not be written. Nothing was imported. |
118
258
  | `ledger-write-failed` | The run directory was written and the ledger was not. Run the fetch again. |
119
259
 
260
+ A run of `connect-scheduled.yaml`, Systematic's own wrapper, can be fetched only by a skill from a Systematic release that includes this change. An earlier skill refuses that path as `not-a-connect-run`. Earlier runs of `connect.yaml` fetch on any version.
261
+
120
262
  ## Reasons a candidate is refused
121
263
 
122
264
  The helper prints one of these for each refused candidate. The record never supplies the text: it supplies only the candidate's title, which is cleaned of control characters and shortened first.
@@ -36,14 +36,15 @@ The digest header and the run record name the selection: `all`, the group, or th
36
36
 
37
37
  ## Reading a fetch
38
38
 
39
- A `fetch:<run>.<attempt>` word, or a bare `fetch:<run>` for the newest attempt, is read from the same place as the mode tokens and the selection words. It brings the candidates of a scheduled CI run to this machine and follows `fetch-and-import.md`.
39
+ A `fetch:<run>.<attempt>` word, a bare `fetch:<run>` for the newest attempt, or a named `fetch:<owner>/<repo>:<run>.<attempt>` for a run of another repository, is read from the same place as the mode tokens and the selection words. It brings the candidates of a scheduled CI run to this machine and follows `fetch-and-import.md`. A bare word means Systematic. A named word must name an allowed origin and must prove that its run called Systematic's reusable workflow; the reference lists both checks.
40
40
 
41
41
  | Words found | Result |
42
42
  |---|---|
43
- | One `fetch:<run>.<attempt>` or `fetch:<run>`, or the same word twice or more | A fetch of that attempt, or of the newest attempt of that run. It observes no host, dispatches no agent and asks nothing, so `mode:` has no effect. |
43
+ | One `fetch:<run>.<attempt>`, `fetch:<run>` or `fetch:<owner>/<repo>:<run>.<attempt>`, or the same word twice or more | A fetch of that attempt, of the newest attempt of that run, or of that attempt of the named repository's run. It observes no host, dispatches no agent and asks nothing, so `mode:` has no effect. |
44
44
  | `fetch:` with a `group:` or `projects:` word | Stop: `conflicting-selection`. |
45
45
  | Two different `fetch:` words | Stop: `conflicting-selection`. |
46
46
  | An empty value, or a value that is not a positive run id, or a run id and a positive attempt | Stop: `invalid-request`. |
47
+ | A named word without an attempt, or with a repository that is not a GitHub `owner/repo`, or with a run or attempt that is not a positive integer | Stop: `invalid-request`. |
47
48
 
48
49
  A stop here happens before any command. End as for a failed run: the reason on a line of its own, then `Connect failed`.
49
50
 
@@ -76,7 +77,7 @@ Every run ends with exactly one of these lines as its last line. The reason and
76
77
  | `Connect complete` | `import` answered `complete` (a fetch whose candidates were all checked and none refused), or `publish` answered `complete`: every project read, every offered rule covered by a complete family, nothing failed, and the run committed. Rules the run was not offered are not a degrade reason, and neither is the stale-citation check reaching its cap: the digest notes it under "Not read or not covered" and the run record keeps the counts, and the outcome is unchanged. Nothing found is still `complete`, labeled "no candidate in searched scope". |
77
78
  | `Connect degraded` | `import` answered `degraded` (at least one candidate of the fetched record was refused; the summary names each), or `publish` answered `degraded`: something was not read, an offered rule was not covered, a file a candidate cited changed or vanished during the run (`evidence-changed`, `unresolved-source`; the rule of that candidate is then not counted as covered), or a bound on the file inventory, a family or a batch was reached. The digest names what. A degraded run is never proof that nothing is there. A dropped candidate never changes the outcome; the digest lists each one under "Dropped candidates" with its reason and quoted title, and the run record keeps the same list. |
78
79
  | `Connect busy` | `begin` or `import` answered `busy`: another run holds the lock, or the holder cannot be verified. Nothing was written and nothing was dispatched. |
79
- | `Connect failed` | Any other stop: a bad mode token, a bad `fetch:` word, a run that is not a scheduled `ce:connect` run, a missing or expired artifact, a record `import` cannot use, a refused selection, the helper missing, an unsupported host in headless mode, consent declined, no allowed projects, a malformed batch, or a helper error. Nothing was published. |
80
+ | `Connect failed` | Any other stop: a bad mode token, a bad `fetch:` word, a run that is not a scheduled `ce:connect` run, a named repository that is not an allowed origin, a named run whose provenance cannot be proven, a missing or expired artifact, a record `import` cannot use, a refused selection, the helper missing, an unsupported host in headless mode, consent declined, no allowed projects, a malformed batch, or a helper error. Nothing was published. |
80
81
 
81
82
  Copy the final line from the helper's `finalLine` when `publish` answers. For every other stop, print the line from this table.
82
83
 
@@ -2,7 +2,7 @@
2
2
  // biome-ignore-all assist/source/organizeImports: generated bundle
3
3
  // Generated by scripts/generate-ce-connect-helper.ts; do not edit by hand.
4
4
  // Run `bun run ce-connect-helper:build` to regenerate.
5
- // source-digest: 2a649776a89b2e51c320bb4394c7acaa296f8368be659aba20bde41534ee036b
5
+ // source-digest: 0682b8db8f1a46b9df0605a1ba5d6962ce4eafd935f828fe3acff769cebc33e6
6
6
  // src/ce-connect-helper.ts
7
7
  import { spawnSync as spawnSync3 } from 'node:child_process'
8
8
  import fs10 from 'node:fs'
@@ -7556,6 +7556,150 @@ function selectionLine(selection) {
7556
7556
  }
7557
7557
  }
7558
7558
 
7559
+ // src/lib/connect-repo-identity.ts
7560
+ var MAX_CONFIG_BYTES = 1024 * 1024
7561
+ var MAX_HEAD_BYTES = 4096
7562
+ var MAX_REF_BYTES = 4096
7563
+ var MAX_PACKED_REFS_BYTES = 8 * 1024 * 1024
7564
+ var OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/
7565
+ var REPO = /^[A-Za-z0-9._-]{1,100}$/
7566
+ function isGithubOwnerRepo(value) {
7567
+ const parts = value.split('/')
7568
+ const [owner, name] = parts
7569
+ return (
7570
+ parts.length === 2 &&
7571
+ owner !== undefined &&
7572
+ name !== undefined &&
7573
+ OWNER.test(owner) &&
7574
+ REPO.test(name) &&
7575
+ name !== '.' &&
7576
+ name !== '..'
7577
+ )
7578
+ }
7579
+ var HTTPS_FORM = /^https:\/\/(?:[^/@\s]*@)?github\.com\/(\S+)$/i
7580
+ var SSH_URL_FORM = /^ssh:\/\/(?:[A-Za-z0-9._-]+@)?github\.com\/(\S+)$/i
7581
+ var SCP_FORM = /^(?:[A-Za-z0-9._-]+@)?github\.com:(\S+)$/i
7582
+ function ownerAndRepo(pathPart) {
7583
+ const segments = pathPart.replace(/\/+$/, '').split('/')
7584
+ if (segments.length !== 2) return
7585
+ const [owner = '', named = ''] = segments
7586
+ const repo = named.endsWith('.git') ? named.slice(0, -'.git'.length) : named
7587
+ const slug = `${owner}/${repo}`
7588
+ return isGithubOwnerRepo(slug) ? slug.toLowerCase() : undefined
7589
+ }
7590
+ function normalizeGithubRemote(url) {
7591
+ const match =
7592
+ HTTPS_FORM.exec(url) ?? SSH_URL_FORM.exec(url) ?? SCP_FORM.exec(url)
7593
+ const rest = match?.[1]
7594
+ return rest === undefined ? undefined : ownerAndRepo(rest)
7595
+ }
7596
+ function configValue(raw) {
7597
+ let out = ''
7598
+ let quoted = false
7599
+ for (const ch of raw.trim()) {
7600
+ if (ch === '"') {
7601
+ quoted = !quoted
7602
+ continue
7603
+ }
7604
+ if (!quoted && (ch === '#' || ch === ';')) break
7605
+ out += ch
7606
+ }
7607
+ return out.trim()
7608
+ }
7609
+ function isOriginSection(header) {
7610
+ const match = /^([A-Za-z]+)[ \t]+"([^"]*)"$/.exec(header.trim())
7611
+ return match?.[1]?.toLowerCase() === 'remote' && match[2] === 'origin'
7612
+ }
7613
+ function originUrl(config) {
7614
+ let inOrigin = false
7615
+ for (const raw of config.split(`
7616
+ `)) {
7617
+ let line = raw.trim()
7618
+ if (line.startsWith('[')) {
7619
+ const end = line.indexOf(']')
7620
+ if (end === -1) {
7621
+ inOrigin = false
7622
+ continue
7623
+ }
7624
+ inOrigin = isOriginSection(line.slice(1, end))
7625
+ line = line.slice(end + 1).trim()
7626
+ }
7627
+ if (!inOrigin) continue
7628
+ const key = /^url[ \t]*=(.*)$/i.exec(line)
7629
+ if (key?.[1] !== undefined) return configValue(key[1])
7630
+ }
7631
+ return
7632
+ }
7633
+ var OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
7634
+ var REF_NAME = /^refs\/[A-Za-z0-9._/-]+$/
7635
+ function readGitText(mainRoot, rel, maxBytes) {
7636
+ const read = readContainedFile(mainRoot, rel, { maxBytes })
7637
+ return read.kind === 'bytes' ? read.bytes.toString('utf8') : undefined
7638
+ }
7639
+ function firstLine2(text) {
7640
+ return (
7641
+ text.split(
7642
+ `
7643
+ `,
7644
+ 1,
7645
+ )[0] ?? ''
7646
+ )
7647
+ .replace(/\r$/, '')
7648
+ .trim()
7649
+ }
7650
+ function safeRefName(ref) {
7651
+ return (
7652
+ REF_NAME.test(ref) &&
7653
+ ref
7654
+ .split('/')
7655
+ .every(
7656
+ (part) =>
7657
+ part !== '' && !part.startsWith('.') && !part.endsWith('.lock'),
7658
+ )
7659
+ )
7660
+ }
7661
+ function packedRef(packed, ref) {
7662
+ for (const raw of packed.split(`
7663
+ `)) {
7664
+ const line = raw.trim()
7665
+ if (line === '' || line.startsWith('#') || line.startsWith('^')) continue
7666
+ const [id, name, ...rest] = line.split(/\s+/)
7667
+ if (rest.length === 0 && name === ref && OBJECT_ID.test(id ?? '')) return id
7668
+ }
7669
+ return
7670
+ }
7671
+ function headCommit(mainRoot) {
7672
+ const head = readGitText(mainRoot, '.git/HEAD', MAX_HEAD_BYTES)
7673
+ if (head === undefined) return
7674
+ const line = firstLine2(head)
7675
+ if (OBJECT_ID.test(line)) return line
7676
+ const symbolic = /^ref:[ \t]*(\S+)$/.exec(line)?.[1]
7677
+ if (symbolic === undefined || !safeRefName(symbolic)) return
7678
+ const loose = readGitText(mainRoot, `.git/${symbolic}`, MAX_REF_BYTES)
7679
+ const looseId = loose === undefined ? '' : firstLine2(loose)
7680
+ if (OBJECT_ID.test(looseId)) return looseId
7681
+ const packed = readGitText(
7682
+ mainRoot,
7683
+ '.git/packed-refs',
7684
+ MAX_PACKED_REFS_BYTES,
7685
+ )
7686
+ return packed === undefined ? undefined : packedRef(packed, symbolic)
7687
+ }
7688
+ function readRepoIdentity(mainRoot) {
7689
+ try {
7690
+ const config = readGitText(mainRoot, '.git/config', MAX_CONFIG_BYTES)
7691
+ const url = config === undefined ? undefined : originUrl(config)
7692
+ const repo = url === undefined ? undefined : normalizeGithubRemote(url)
7693
+ const commit = headCommit(mainRoot)
7694
+ return {
7695
+ ...(repo === undefined ? {} : { repo }),
7696
+ ...(commit === undefined ? {} : { commit }),
7697
+ }
7698
+ } catch {
7699
+ return {}
7700
+ }
7701
+ }
7702
+
7559
7703
  // src/lib/connect-state.ts
7560
7704
  import { spawnSync as spawnSync2 } from 'node:child_process'
7561
7705
  import {
@@ -8803,7 +8947,7 @@ var INVOCATION_FILE = 'invocation.json'
8803
8947
  var MAX_CI_RUN_BYTES = 1024
8804
8948
  var MAX_INVOCATION_BYTES = 1024 * 1024
8805
8949
  var MAX_INVOCATION_NAME_LENGTH = 200
8806
- var OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
8950
+ var OBJECT_ID2 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
8807
8951
  var REPO_SLUG = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
8808
8952
  var INVOCATION_OUTCOMES = ['complete', 'degraded', 'busy', 'failed']
8809
8953
  function isInvocationOutcome(value) {
@@ -8838,7 +8982,7 @@ function parseInvocationProject(item) {
8838
8982
  if (!isProjectKey(key) || !plainText(name, MAX_INVOCATION_NAME_LENGTH)) {
8839
8983
  return
8840
8984
  }
8841
- if (!optionalMatch(repo, REPO_SLUG) || !optionalMatch(commit, OBJECT_ID)) {
8985
+ if (!optionalMatch(repo, REPO_SLUG) || !optionalMatch(commit, OBJECT_ID2)) {
8842
8986
  return
8843
8987
  }
8844
8988
  return {
@@ -9067,9 +9211,9 @@ var CANDIDATE_ID = /^[0-9a-f]{64}$/
9067
9211
  var MANIFEST_HASH = /^[0-9a-f]{16}$/
9068
9212
  var DIGITS = /^[0-9]{1,20}$/
9069
9213
  var DATE = /^\d{4}-\d{2}-\d{2}$/
9070
- var REPO = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
9214
+ var REPO2 = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
9071
9215
  var TOKEN = /^[a-z][a-z0-9-]{0,39}$/
9072
- var OBJECT_ID2 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
9216
+ var OBJECT_ID3 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
9073
9217
  function manifestMarker(hash) {
9074
9218
  return `<!-- connect-manifest:${hash} -->`
9075
9219
  }
@@ -9326,13 +9470,13 @@ function evidenceItemOf(item, heads, repos) {
9326
9470
  if (evidencePath === undefined) return
9327
9471
  const span = spanOf(item.start, item.end)
9328
9472
  const head =
9329
- typeof item.head === 'string' && OBJECT_ID2.test(item.head)
9473
+ typeof item.head === 'string' && OBJECT_ID3.test(item.head)
9330
9474
  ? item.head
9331
9475
  : typeof item.project === 'string'
9332
9476
  ? heads.get(item.project)
9333
9477
  : undefined
9334
9478
  const repo =
9335
- typeof item.repo === 'string' && REPO.test(item.repo)
9479
+ typeof item.repo === 'string' && REPO2.test(item.repo)
9336
9480
  ? item.repo
9337
9481
  : typeof item.project === 'string'
9338
9482
  ? repos.get(item.project)
@@ -9395,7 +9539,7 @@ function payloadFromStore(raw) {
9395
9539
  return {
9396
9540
  id: raw.id,
9397
9541
  ...text,
9398
- ...(typeof repo === 'string' && REPO.test(repo) ? { repo } : {}),
9542
+ ...(typeof repo === 'string' && REPO2.test(repo) ? { repo } : {}),
9399
9543
  ...(typeof firstShown === 'string' && validDate(firstShown)
9400
9544
  ? { firstShown }
9401
9545
  : {}),
@@ -9528,7 +9672,7 @@ function repoMap(value) {
9528
9672
  if (
9529
9673
  typeof root === 'string' &&
9530
9674
  typeof repo === 'string' &&
9531
- REPO.test(repo)
9675
+ REPO2.test(repo)
9532
9676
  ) {
9533
9677
  out.set(root, repo)
9534
9678
  }
@@ -9544,7 +9688,7 @@ function commitMap(value) {
9544
9688
  if (
9545
9689
  typeof root === 'string' &&
9546
9690
  typeof commit === 'string' &&
9547
- OBJECT_ID2.test(commit)
9691
+ OBJECT_ID3.test(commit)
9548
9692
  ) {
9549
9693
  out.set(root, commit)
9550
9694
  }
@@ -9588,13 +9732,21 @@ var OUTCOME_SENTENCE = {
9588
9732
  function isRed(outcome) {
9589
9733
  return outcome === 'failed' || outcome === 'no-final-line'
9590
9734
  }
9735
+ var SYSTEMATIC_REPO = 'marcusrbrown/systematic'
9591
9736
  function validRequest(request) {
9592
9737
  return (
9593
9738
  validDate(request.date) &&
9594
9739
  isDigits(request.runId) &&
9595
- isDigits(request.attempt)
9740
+ isDigits(request.attempt) &&
9741
+ (request.repo === undefined || isGithubOwnerRepo(request.repo))
9596
9742
  )
9597
9743
  }
9744
+ function fetchRepoOf(request) {
9745
+ const { repo } = request
9746
+ return repo === undefined || repo.toLowerCase() === SYSTEMATIC_REPO
9747
+ ? undefined
9748
+ : repo
9749
+ }
9598
9750
  function factsOf(id, payload) {
9599
9751
  const target =
9600
9752
  payload.repo === undefined
@@ -9627,10 +9779,11 @@ function factsOf(id, payload) {
9627
9779
  return lines.join(`
9628
9780
  `)
9629
9781
  }
9630
- function fetchWord(payload) {
9631
- return `${payload.runId}.${payload.attempt}`
9782
+ function fetchWord(payload, repo) {
9783
+ const run = `${payload.runId}.${payload.attempt}`
9784
+ return repo === undefined ? run : `${repo}:${run}`
9632
9785
  }
9633
- function blockOf(position, entry, revision, payload, isNew) {
9786
+ function blockOf(position, entry, revision, payload, isNew, fetchRepo) {
9634
9787
  const { id } = entry
9635
9788
  const marks = [
9636
9789
  ...(isNew ? ['new'] : []),
@@ -9641,7 +9794,7 @@ function blockOf(position, entry, revision, payload, isNew) {
9641
9794
  '',
9642
9795
  ]
9643
9796
  lines.push(
9644
- `- Fetch: \`/ce:connect fetch:${fetchWord(payload)}\` (run ${payload.runId}, attempt ${payload.attempt})`,
9797
+ `- Fetch: \`/ce:connect fetch:${fetchWord(payload, fetchRepo)}\` (run ${payload.runId}, attempt ${payload.attempt})`,
9645
9798
  '',
9646
9799
  fenceText(factsOf(id, payload)),
9647
9800
  )
@@ -9665,10 +9818,10 @@ function ranges(positions) {
9665
9818
  .map(([from, to]) => (from === to ? `${from}` : `${from}-${to}`))
9666
9819
  .join(', ')
9667
9820
  }
9668
- function fetchLines(rows) {
9821
+ function fetchLines(rows, repo) {
9669
9822
  const byFetch = new Map()
9670
9823
  rows.forEach((row, index) => {
9671
- const word = fetchWord(row.payload)
9824
+ const word = fetchWord(row.payload, repo)
9672
9825
  const list = byFetch.get(word) ?? []
9673
9826
  list.push(index + 1)
9674
9827
  byFetch.set(word, list)
@@ -9728,7 +9881,7 @@ function assembleReport(input, shown, named) {
9728
9881
  const rows = input.rows.slice(0, shown)
9729
9882
  const ids = rows.map((row) => row.id)
9730
9883
  const hash = manifestHash(ids)
9731
- const fetch = fetchLines(rows)
9884
+ const fetch = fetchLines(rows, input.fetchRepo)
9732
9885
  const fresh = rows.filter((row) => row.isNew).length
9733
9886
  const open = input.rows.length
9734
9887
  const out = [manifestMarker(hash), '', ...headOf(input)]
@@ -9851,7 +10004,7 @@ function factLines(invocation, run) {
9851
10004
  }
9852
10005
  return lines
9853
10006
  }
9854
- function rowsOf(open, payloads, date) {
10007
+ function rowsOf(open, payloads, date, fetchRepo) {
9855
10008
  const rows = []
9856
10009
  const unverified = []
9857
10010
  for (const entry of open) {
@@ -9866,7 +10019,7 @@ function rowsOf(open, payloads, date) {
9866
10019
  id: entry.id,
9867
10020
  payload: held,
9868
10021
  isNew,
9869
- block: blockOf(rows.length + 1, entry, revision, held, isNew),
10022
+ block: blockOf(rows.length + 1, entry, revision, held, isNew, fetchRepo),
9870
10023
  })
9871
10024
  }
9872
10025
  return { rows, unverified }
@@ -9909,7 +10062,8 @@ function renderState(root, request, recordState) {
9909
10062
  proposed(run, new Set(open.map((entry) => entry.id)), request),
9910
10063
  )
9911
10064
  const outcome = outcomeOf(invocation)
9912
- const { rows, unverified } = rowsOf(open, payloads, request.date)
10065
+ const fetchRepo = fetchRepoOf(request)
10066
+ const { rows, unverified } = rowsOf(open, payloads, request.date, fetchRepo)
9913
10067
  const input = {
9914
10068
  outcome,
9915
10069
  facts: factLines(invocation, run),
@@ -9917,6 +10071,7 @@ function renderState(root, request, recordState) {
9917
10071
  stateUpdated: recordState,
9918
10072
  rows,
9919
10073
  unverified,
10074
+ ...(fetchRepo === undefined ? {} : { fetchRepo }),
9920
10075
  }
9921
10076
  const { shown, named } = fitReport(input)
9922
10077
  const result = assembleReport(input, shown, named)
@@ -10153,7 +10308,7 @@ var MAX_ROOT_LENGTH = 4096
10153
10308
  var RUN_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
10154
10309
  var PROJECT_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/
10155
10310
  var REPO_SLUG2 = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
10156
- var OBJECT_ID3 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
10311
+ var OBJECT_ID4 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
10157
10312
  var CANDIDATE_ID2 = /^[0-9a-f]{64}$/
10158
10313
  var CONTROL2 = /[\p{Cc}\p{Cf}]/u
10159
10314
  var CORPUS_PATH = /^docs\/(?:solutions|plans|brainstorms)\//
@@ -10184,7 +10339,7 @@ function parseProject(value) {
10184
10339
  }
10185
10340
  if (
10186
10341
  commit !== undefined &&
10187
- !(typeof commit === 'string' && OBJECT_ID3.test(commit))
10342
+ !(typeof commit === 'string' && OBJECT_ID4.test(commit))
10188
10343
  ) {
10189
10344
  return
10190
10345
  }
@@ -10807,137 +10962,67 @@ function renderImportDigest(model, written, generatedAt) {
10807
10962
  `
10808
10963
  }
10809
10964
 
10810
- // src/lib/connect-repo-identity.ts
10811
- var MAX_CONFIG_BYTES = 1024 * 1024
10812
- var MAX_HEAD_BYTES = 4096
10813
- var MAX_REF_BYTES = 4096
10814
- var MAX_PACKED_REFS_BYTES = 8 * 1024 * 1024
10815
- var OWNER = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/
10816
- var REPO2 = /^[A-Za-z0-9._-]{1,100}$/
10817
- var HTTPS_FORM = /^https:\/\/(?:[^/@\s]*@)?github\.com\/(\S+)$/i
10818
- var SSH_URL_FORM = /^ssh:\/\/(?:[A-Za-z0-9._-]+@)?github\.com\/(\S+)$/i
10819
- var SCP_FORM = /^(?:[A-Za-z0-9._-]+@)?github\.com:(\S+)$/i
10820
- function ownerAndRepo(pathPart) {
10821
- const segments = pathPart.replace(/\/+$/, '').split('/')
10822
- if (segments.length !== 2) return
10823
- const [owner = '', named = ''] = segments
10824
- const repo = named.endsWith('.git') ? named.slice(0, -'.git'.length) : named
10825
- if (!OWNER.test(owner) || !REPO2.test(repo)) return
10826
- if (repo === '.' || repo === '..') return
10827
- return `${owner}/${repo}`.toLowerCase()
10828
- }
10829
- function normalizeGithubRemote(url) {
10830
- const match =
10831
- HTTPS_FORM.exec(url) ?? SSH_URL_FORM.exec(url) ?? SCP_FORM.exec(url)
10832
- const rest = match?.[1]
10833
- return rest === undefined ? undefined : ownerAndRepo(rest)
10834
- }
10835
- function configValue(raw) {
10836
- let out = ''
10837
- let quoted = false
10838
- for (const ch of raw.trim()) {
10839
- if (ch === '"') {
10840
- quoted = !quoted
10841
- continue
10842
- }
10843
- if (!quoted && (ch === '#' || ch === ';')) break
10844
- out += ch
10965
+ // src/lib/connect-provenance.ts
10966
+ var OWNER_REPO = 'marcusrbrown/systematic'
10967
+ var WORKFLOW_FILE = '/.github/workflows/connect.yaml'
10968
+ var FULL_SHA = /^[0-9a-f]{40}$/
10969
+ var UNPROVABLE = {
10970
+ status: 'refused',
10971
+ reason: 'provenance-unprovable',
10972
+ }
10973
+ var NOT_A_CONNECT_RUN = {
10974
+ status: 'refused',
10975
+ reason: 'not-a-connect-run',
10976
+ }
10977
+ function parseList(text) {
10978
+ if (typeof text !== 'string') return
10979
+ try {
10980
+ const value = JSON.parse(text)
10981
+ return Array.isArray(value) && value.length > 0 ? value : undefined
10982
+ } catch {
10983
+ return
10845
10984
  }
10846
- return out.trim()
10847
- }
10848
- function isOriginSection(header) {
10849
- const match = /^([A-Za-z]+)[ \t]+"([^"]*)"$/.exec(header.trim())
10850
- return match?.[1]?.toLowerCase() === 'remote' && match[2] === 'origin'
10851
10985
  }
10852
- function originUrl(config) {
10853
- let inOrigin = false
10854
- for (const raw of config.split(`
10855
- `)) {
10856
- let line = raw.trim()
10857
- if (line.startsWith('[')) {
10858
- const end = line.indexOf(']')
10859
- if (end === -1) {
10860
- inOrigin = false
10861
- continue
10862
- }
10863
- inOrigin = isOriginSection(line.slice(1, end))
10864
- line = line.slice(end + 1).trim()
10986
+ function pathsOf(list) {
10987
+ const paths = []
10988
+ for (const entry of list) {
10989
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
10990
+ return
10865
10991
  }
10866
- if (!inOrigin) continue
10867
- const key = /^url[ \t]*=(.*)$/i.exec(line)
10868
- if (key?.[1] !== undefined) return configValue(key[1])
10992
+ const { path } = entry
10993
+ if (typeof path !== 'string') return
10994
+ paths.push(path)
10869
10995
  }
10870
- return
10996
+ return paths
10871
10997
  }
10872
- var OBJECT_ID4 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
10873
- var REF_NAME = /^refs\/[A-Za-z0-9._/-]+$/
10874
- function readGitText(mainRoot, rel, maxBytes) {
10875
- const read = readContainedFile(mainRoot, rel, { maxBytes })
10876
- return read.kind === 'bytes' ? read.bytes.toString('utf8') : undefined
10998
+ function workflowOf(path) {
10999
+ const at = path.indexOf('@')
11000
+ return at === -1 ? path : path.slice(0, at)
10877
11001
  }
10878
- function firstLine2(text) {
11002
+ function isSystematicConnect(path) {
11003
+ const workflow = workflowOf(path)
10879
11004
  return (
10880
- text.split(
10881
- `
10882
- `,
10883
- 1,
10884
- )[0] ?? ''
11005
+ workflow.endsWith(WORKFLOW_FILE) &&
11006
+ workflow.slice(0, -WORKFLOW_FILE.length).toLowerCase() === OWNER_REPO
10885
11007
  )
10886
- .replace(/\r$/, '')
10887
- .trim()
10888
11008
  }
10889
- function safeRefName(ref) {
10890
- return (
10891
- REF_NAME.test(ref) &&
10892
- ref
10893
- .split('/')
10894
- .every(
10895
- (part) =>
10896
- part !== '' && !part.startsWith('.') && !part.endsWith('.lock'),
10897
- )
10898
- )
10899
- }
10900
- function packedRef(packed, ref) {
10901
- for (const raw of packed.split(`
10902
- `)) {
10903
- const line = raw.trim()
10904
- if (line === '' || line.startsWith('#') || line.startsWith('^')) continue
10905
- const [id, name, ...rest] = line.split(/\s+/)
10906
- if (rest.length === 0 && name === ref && OBJECT_ID4.test(id ?? ''))
10907
- return id
10908
- }
10909
- return
10910
- }
10911
- function headCommit(mainRoot) {
10912
- const head = readGitText(mainRoot, '.git/HEAD', MAX_HEAD_BYTES)
10913
- if (head === undefined) return
10914
- const line = firstLine2(head)
10915
- if (OBJECT_ID4.test(line)) return line
10916
- const symbolic = /^ref:[ \t]*(\S+)$/.exec(line)?.[1]
10917
- if (symbolic === undefined || !safeRefName(symbolic)) return
10918
- const loose = readGitText(mainRoot, `.git/${symbolic}`, MAX_REF_BYTES)
10919
- const looseId = loose === undefined ? '' : firstLine2(loose)
10920
- if (OBJECT_ID4.test(looseId)) return looseId
10921
- const packed = readGitText(
10922
- mainRoot,
10923
- '.git/packed-refs',
10924
- MAX_PACKED_REFS_BYTES,
10925
- )
10926
- return packed === undefined ? undefined : packedRef(packed, symbolic)
10927
- }
10928
- function readRepoIdentity(mainRoot) {
10929
- try {
10930
- const config = readGitText(mainRoot, '.git/config', MAX_CONFIG_BYTES)
10931
- const url = config === undefined ? undefined : originUrl(config)
10932
- const repo = url === undefined ? undefined : normalizeGithubRemote(url)
10933
- const commit = headCommit(mainRoot)
10934
- return {
10935
- ...(repo === undefined ? {} : { repo }),
10936
- ...(commit === undefined ? {} : { commit }),
10937
- }
10938
- } catch {
10939
- return {}
10940
- }
11009
+ function verifyProvenance(input) {
11010
+ const list = parseList(input.referencedWorkflows)
11011
+ if (list === undefined) return UNPROVABLE
11012
+ const paths = pathsOf(list)
11013
+ if (paths === undefined) return UNPROVABLE
11014
+ const matches = list.filter((_entry, index) => {
11015
+ const path = paths[index]
11016
+ return path !== undefined && isSystematicConnect(path)
11017
+ })
11018
+ if (matches.length === 0) return NOT_A_CONNECT_RUN
11019
+ if (matches.length > 1) return UNPROVABLE
11020
+ const { sha } = matches[0]
11021
+ if (typeof sha !== 'string' || !FULL_SHA.test(sha)) return UNPROVABLE
11022
+ if (input.status === undefined) return { status: 'selected', sha }
11023
+ return input.status === 'behind' || input.status === 'identical'
11024
+ ? { status: 'accepted', sha }
11025
+ : UNPROVABLE
10941
11026
  }
10942
11027
 
10943
11028
  // src/lib/main-module.ts
@@ -10970,7 +11055,7 @@ function isMainModule(moduleUrl, argv = process.argv) {
10970
11055
 
10971
11056
  // src/ce-connect-helper.ts
10972
11057
  var CE_CONNECT_USAGE =
10973
- 'Usage: node connect.mjs <begin|validate|publish|decide|import|apply-ticks|render-report|ledger show [--offset N]|ledger clear|ledger unlock>'
11058
+ 'Usage: node connect.mjs <begin|validate|publish|decide|import|apply-ticks|render-report|allowed-origins|verify-provenance|ledger show [--offset N]|ledger clear|ledger unlock>'
10974
11059
  var OPS = [
10975
11060
  'begin',
10976
11061
  'validate',
@@ -10979,6 +11064,8 @@ var OPS = [
10979
11064
  'import',
10980
11065
  'apply-ticks',
10981
11066
  'render-report',
11067
+ 'allowed-origins',
11068
+ 'verify-provenance',
10982
11069
  'ledger-show',
10983
11070
  'ledger-clear',
10984
11071
  'ledger-unlock',
@@ -12910,7 +12997,6 @@ function ledgerUnlock(deps) {
12910
12997
  : {}),
12911
12998
  })
12912
12999
  }
12913
- var GITHUB_REPO = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/
12914
13000
  var GITHUB_RUN_ID = /^[0-9]{1,20}$/
12915
13001
  var COMMIT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
12916
13002
  var MAX_DIRECTORY_LENGTH = 4096
@@ -12928,7 +13014,7 @@ function parseImportRequest(request) {
12928
13014
  }
12929
13015
  if (!isRecord6(provenance)) return
12930
13016
  const { repo, runId, commit } = provenance
12931
- if (typeof repo !== 'string' || !GITHUB_REPO.test(repo)) return
13017
+ if (typeof repo !== 'string' || !isGithubOwnerRepo(repo)) return
12932
13018
  if (typeof runId !== 'string' || !GITHUB_RUN_ID.test(runId)) return
12933
13019
  if (
12934
13020
  commit !== undefined &&
@@ -13341,6 +13427,39 @@ function importRun(request, deps) {
13341
13427
  }
13342
13428
  return importWrite(parsed, sourceRunId, verified, state.root, deps)
13343
13429
  }
13430
+ function allowedOrigins(deps) {
13431
+ const environment = describeEnvironment(deps)
13432
+ const seen = new Set()
13433
+ const shared = new Set()
13434
+ for (const { mainRoot } of environment.resolved.resolved) {
13435
+ const { repo } = readRepoIdentity(mainRoot)
13436
+ if (repo === undefined) continue
13437
+ if (seen.has(repo)) shared.add(repo)
13438
+ seen.add(repo)
13439
+ }
13440
+ return success('allowed-origins', {
13441
+ outcome: 'complete',
13442
+ origins: [...seen].sort(),
13443
+ ambiguous: [...shared].sort(),
13444
+ configUnreadable: environment.configUnreadable,
13445
+ })
13446
+ }
13447
+ function verifyProvenanceOp(request) {
13448
+ if (!isRecord6(request))
13449
+ return failure2('verify-provenance', 'invalid-request')
13450
+ const verdict = verifyProvenance({
13451
+ referencedWorkflows: request.referencedWorkflows,
13452
+ ...(request.status === undefined ? {} : { status: request.status }),
13453
+ })
13454
+ if (verdict.status === 'refused') {
13455
+ return failure2('verify-provenance', verdict.reason)
13456
+ }
13457
+ return success('verify-provenance', {
13458
+ outcome: 'complete',
13459
+ stage: verdict.status,
13460
+ sha: verdict.sha,
13461
+ })
13462
+ }
13344
13463
  var ISSUE_DIGITS = /^[0-9]{1,10}$/
13345
13464
  function parseTicksRequest(request) {
13346
13465
  if (!isRecord6(request)) return
@@ -13365,16 +13484,23 @@ function parseTicksRequest(request) {
13365
13484
  }
13366
13485
  function parseRenderRequest(request) {
13367
13486
  if (!isRecord6(request)) return
13368
- const { date, runId, attempt, cacheRestored } = request
13487
+ const { date, runId, attempt, cacheRestored, repo } = request
13369
13488
  if (
13370
13489
  typeof date !== 'string' ||
13371
13490
  typeof runId !== 'string' ||
13372
13491
  typeof attempt !== 'string' ||
13373
- typeof cacheRestored !== 'boolean'
13492
+ typeof cacheRestored !== 'boolean' ||
13493
+ (repo !== undefined && typeof repo !== 'string')
13374
13494
  ) {
13375
13495
  return
13376
13496
  }
13377
- return { date, runId, attempt, cacheRestored }
13497
+ return {
13498
+ date,
13499
+ runId,
13500
+ attempt,
13501
+ cacheRestored,
13502
+ ...(repo === undefined ? {} : { repo }),
13503
+ }
13378
13504
  }
13379
13505
  function ciOptions(deps) {
13380
13506
  return {
@@ -13460,6 +13586,10 @@ function runHelperOp(op, request, deps = {}) {
13460
13586
  return applyTicksOp(request, deps)
13461
13587
  case 'render-report':
13462
13588
  return renderReportOp(request, deps)
13589
+ case 'allowed-origins':
13590
+ return allowedOrigins(deps)
13591
+ case 'verify-provenance':
13592
+ return verifyProvenanceOp(request)
13463
13593
  case 'ledger-show':
13464
13594
  return ledgerShow(request, deps)
13465
13595
  case 'ledger-clear':
@@ -13512,6 +13642,7 @@ var REQUEST_OPS = new Set([
13512
13642
  'import',
13513
13643
  'apply-ticks',
13514
13644
  'render-report',
13645
+ 'verify-provenance',
13515
13646
  ])
13516
13647
  function resolveCliOp(argv) {
13517
13648
  const [first, second] = argv
@@ -13532,6 +13663,14 @@ function showRequestFromArgv(argv) {
13532
13663
  ? { offset: Number(value) }
13533
13664
  : { offset: value }
13534
13665
  }
13666
+ function provenanceArgsFromArgv(argv) {
13667
+ const rest = argv.slice(1)
13668
+ if (rest.length === 0) return {}
13669
+ const [flag, value] = rest
13670
+ return rest.length === 2 && flag === '--status' && value !== undefined
13671
+ ? { status: value }
13672
+ : undefined
13673
+ }
13535
13674
  function refusedBegin(result, options) {
13536
13675
  const deps = options.deps ?? {}
13537
13676
  const marker = ciRunMarker(deps)
@@ -13567,6 +13706,7 @@ function readCliRequest(op, options, out, err) {
13567
13706
  if (text === 'too-large' || text === 'unreadable') {
13568
13707
  return refuse(`request-${text}`)
13569
13708
  }
13709
+ if (op === 'verify-provenance') return { ok: true, request: text }
13570
13710
  if (text.trim() === '') return { ok: true, request: {} }
13571
13711
  try {
13572
13712
  return { ok: true, request: JSON.parse(text) }
@@ -13590,10 +13730,20 @@ function runConnectHelper(options) {
13590
13730
  err(CE_CONNECT_USAGE)
13591
13731
  return 2
13592
13732
  }
13733
+ const provenanceArgs =
13734
+ op === 'verify-provenance' ? provenanceArgsFromArgv(options.argv) : {}
13735
+ if (provenanceArgs === undefined) {
13736
+ out(JSON.stringify(failure2(op, 'invalid-request').body))
13737
+ return 2
13738
+ }
13593
13739
  const read = readCliRequest(op, options, out, err)
13594
13740
  if (!read.ok) return read.exitCode
13595
13741
  const request =
13596
- op === 'ledger-show' ? showRequestFromArgv(options.argv) : read.request
13742
+ op === 'ledger-show'
13743
+ ? showRequestFromArgv(options.argv)
13744
+ : op === 'verify-provenance'
13745
+ ? { referencedWorkflows: read.request, ...provenanceArgs }
13746
+ : read.request
13597
13747
  const result = runHelperOp(op, request, options.deps ?? {})
13598
13748
  out(JSON.stringify(result.body))
13599
13749
  return result.ok ? 0 : 1