@agilno-tech/rivet 0.1.0-alpha.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/LICENSE +202 -0
- package/NOTICE +6 -0
- package/README.md +59 -0
- package/bin/cli.js +42 -0
- package/dist/agents/backend-django-agent/SKILL.md +35 -0
- package/dist/agents/backend-nestjs-agent/SKILL.md +36 -0
- package/dist/agents/boss-agent/SKILL.md +28 -0
- package/dist/agents/bounded-worker/SKILL.md +28 -0
- package/dist/agents/data-performance-agent/SKILL.md +32 -0
- package/dist/agents/delivery-ticketing-agent/SKILL.md +36 -0
- package/dist/agents/devops-agent/SKILL.md +34 -0
- package/dist/agents/engineering-manager/SKILL.md +28 -0
- package/dist/agents/frontend-nextjs-agent/SKILL.md +34 -0
- package/dist/agents/frontend-web-agent/SKILL.md +31 -0
- package/dist/agents/incident-response-agent/SKILL.md +42 -0
- package/dist/agents/jest-agent/SKILL.md +77 -0
- package/dist/agents/mobile-agent/SKILL.md +32 -0
- package/dist/agents/playwright-agent/SKILL.md +54 -0
- package/dist/agents/product-design-manager/SKILL.md +27 -0
- package/dist/agents/qa-agent/SKILL.md +29 -0
- package/dist/agents/quality-manager/SKILL.md +28 -0
- package/dist/agents/vitest-agent/SKILL.md +77 -0
- package/dist/governance/pre-push-rules.md +75 -0
- package/dist/governance/prompt-hygiene.md +22 -0
- package/dist/governance/review-checklist.md +24 -0
- package/dist/governance/safety-and-data.md +27 -0
- package/dist/governance/usage-rules.md +21 -0
- package/dist/mandatory/address-pr-feedback/SKILL.md +196 -0
- package/dist/mandatory/agentic-goal/SKILL.md +42 -0
- package/dist/mandatory/agentic-status/SKILL.md +74 -0
- package/dist/mandatory/apply-design/SKILL.md +228 -0
- package/dist/mandatory/check-ac/SKILL.md +124 -0
- package/dist/mandatory/create-pr-and-commit/SKILL.md +304 -0
- package/dist/mandatory/design/SKILL.md +312 -0
- package/dist/mandatory/feature-workflow/SKILL.md +87 -0
- package/dist/mandatory/hotfix/SKILL.md +195 -0
- package/dist/mandatory/pre-push/SKILL.md +272 -0
- package/dist/mandatory/project-context/SKILL.md +180 -0
- package/dist/mandatory/release-docs/SKILL.md +191 -0
- package/dist/mandatory/review-pr/SKILL.md +323 -0
- package/dist/mandatory/security-review/SKILL.md +157 -0
- package/dist/skills/api-contract/SKILL.md +77 -0
- package/dist/skills/backend-django/SKILL.md +27 -0
- package/dist/skills/backend-nestjs/SKILL.md +65 -0
- package/dist/skills/bug-ticket-creation/SKILL.md +43 -0
- package/dist/skills/cloudwatch-troubleshooting/SKILL.md +73 -0
- package/dist/skills/database-migration/SKILL.md +97 -0
- package/dist/skills/debugging/SKILL.md +32 -0
- package/dist/skills/devops-infra/SKILL.md +26 -0
- package/dist/skills/documentation/SKILL.md +24 -0
- package/dist/skills/frontend-nextjs/SKILL.md +27 -0
- package/dist/skills/incident-postmortem/SKILL.md +38 -0
- package/dist/skills/kubernetes-troubleshooting/SKILL.md +71 -0
- package/dist/skills/mobile-react-native/SKILL.md +37 -0
- package/dist/skills/postgres-analytics/SKILL.md +29 -0
- package/dist/skills/product-jira-ticketing/SKILL.md +28 -0
- package/dist/skills/qa-bug-analysis/SKILL.md +27 -0
- package/dist/skills/refactoring/SKILL.md +32 -0
- package/dist/skills/sprint-planning/SKILL.md +32 -0
- package/dist/skills/testing-quality/SKILL.md +62 -0
- package/dist/v2/protocols/agent-orchestration.md +49 -0
- package/dist/v2/protocols/delivery.md +45 -0
- package/dist/v2/protocols/design-authority.md +29 -0
- package/dist/v2/protocols/goal-graph.md +44 -0
- package/dist/v2/protocols/pattern-first-development.md +29 -0
- package/dist/v2/protocols/qa-evidence.md +29 -0
- package/dist/v2/protocols/security.md +29 -0
- package/dist/v2/schemas/event.schema.json +86 -0
- package/dist/v2/schemas/evidence.schema.json +94 -0
- package/dist/v2/schemas/feature-decomposition.schema.json +48 -0
- package/dist/v2/schemas/feature-plan.schema.json +95 -0
- package/dist/v2/schemas/goal-graph.schema.json +61 -0
- package/dist/v2/schemas/integration.schema.json +119 -0
- package/dist/v2/schemas/orchestration.schema.json +69 -0
- package/dist/v2/schemas/project.schema.json +209 -0
- package/dist/v2/schemas/providers.schema.json +142 -0
- package/dist/v2/schemas/quality.schema.json +50 -0
- package/dist/v2/schemas/work-action.schema.json +44 -0
- package/dist/v2/schemas/work-request.schema.json +253 -0
- package/dist/v2/templates/evidence/qa-bundle.json +194 -0
- package/dist/v2/templates/github-actions/rivet-deploy.yml +98 -0
- package/dist/v2/templates/harness/SKILL.md +90 -0
- package/dist/v2/templates/project/.rivet/orchestration.yaml +42 -0
- package/dist/v2/templates/project/.rivet/project.yaml +14 -0
- package/dist/v2/templates/project/.rivet/providers.yaml +8 -0
- package/dist/v2/templates/project/.rivet/quality.yaml +16 -0
- package/package.json +58 -0
- package/protocols/agent-orchestration.md +49 -0
- package/protocols/delivery.md +45 -0
- package/protocols/design-authority.md +29 -0
- package/protocols/goal-graph.md +44 -0
- package/protocols/pattern-first-development.md +29 -0
- package/protocols/qa-evidence.md +29 -0
- package/protocols/security.md +29 -0
- package/schemas/event.schema.json +86 -0
- package/schemas/evidence.schema.json +94 -0
- package/schemas/feature-decomposition.schema.json +48 -0
- package/schemas/feature-plan.schema.json +95 -0
- package/schemas/goal-graph.schema.json +61 -0
- package/schemas/integration.schema.json +119 -0
- package/schemas/orchestration.schema.json +69 -0
- package/schemas/project.schema.json +209 -0
- package/schemas/providers.schema.json +142 -0
- package/schemas/quality.schema.json +50 -0
- package/schemas/work-action.schema.json +44 -0
- package/schemas/work-request.schema.json +253 -0
- package/src/adapters/confluence.js +138 -0
- package/src/adapters/contract.js +657 -0
- package/src/adapters/factory.js +122 -0
- package/src/adapters/figma.js +178 -0
- package/src/adapters/fixtures.js +183 -0
- package/src/adapters/github.js +314 -0
- package/src/adapters/http.js +704 -0
- package/src/adapters/jira.js +195 -0
- package/src/adapters/linear.js +171 -0
- package/src/adapters/node-transport.js +59 -0
- package/src/cli/integration-setup-prompt.js +32 -0
- package/src/cli/interrupt.js +25 -0
- package/src/cli/main.js +596 -0
- package/src/cli/output.js +174 -0
- package/src/cli/parse-args.js +246 -0
- package/src/cli/project-discovery.js +70 -0
- package/src/cli/task-confirmation.js +38 -0
- package/src/cli/task-presentation.js +22 -0
- package/src/clients/claude.js +214 -0
- package/src/clients/codex.js +180 -0
- package/src/clients/compatibility.js +23 -0
- package/src/clients/contract.js +224 -0
- package/src/clients/fake.js +170 -0
- package/src/clients/process-runner.js +657 -0
- package/src/clients/result-contract.js +78 -0
- package/src/commands/delivery-publish.js +80 -0
- package/src/commands/delivery-remote.js +230 -0
- package/src/commands/delivery-review-update.js +39 -0
- package/src/commands/delivery-tracker.js +94 -0
- package/src/commands/delivery-transition.js +79 -0
- package/src/commands/delivery.js +223 -0
- package/src/commands/dependency-approval.js +21 -0
- package/src/commands/doctor.js +191 -0
- package/src/commands/evidence.js +44 -0
- package/src/commands/feature.js +212 -0
- package/src/commands/goals.js +231 -0
- package/src/commands/human-run.js +208 -0
- package/src/commands/human-task.js +278 -0
- package/src/commands/init.js +848 -0
- package/src/commands/install.js +814 -0
- package/src/commands/integration-setup.js +65 -0
- package/src/commands/integrations.js +54 -0
- package/src/commands/models.js +158 -0
- package/src/commands/orchestrate.js +61 -0
- package/src/commands/preflight.js +125 -0
- package/src/commands/protocols.js +228 -0
- package/src/commands/repositories.js +77 -0
- package/src/commands/setup-remote.js +41 -0
- package/src/commands/setup.js +214 -0
- package/src/commands/status.js +224 -0
- package/src/commands/support.js +44 -0
- package/src/commands/task-completion.js +104 -0
- package/src/commands/uninstall.js +234 -0
- package/src/commands/verify.js +171 -0
- package/src/commands/work.js +220 -0
- package/src/commands/worktrees.js +52 -0
- package/src/config/command-readiness.js +218 -0
- package/src/config/commands.js +206 -0
- package/src/config/defaults.js +55 -0
- package/src/config/load.js +230 -0
- package/src/config/validate.js +560 -0
- package/src/delivery/bitbucket-review.js +123 -0
- package/src/delivery/branch-publication.js +23 -0
- package/src/delivery/contract.js +379 -0
- package/src/delivery/github-deployment.js +132 -0
- package/src/delivery/github-review.js +5 -0
- package/src/delivery/github.js +382 -0
- package/src/delivery/gitlab-review.js +5 -0
- package/src/delivery/gitlab.js +395 -0
- package/src/delivery/prepare.js +90 -0
- package/src/delivery/publication-process.js +33 -0
- package/src/delivery/publication-transport.js +112 -0
- package/src/delivery/review-request.js +184 -0
- package/src/delivery/review-update.js +74 -0
- package/src/delivery/service.js +400 -0
- package/src/delivery/store.js +76 -0
- package/src/delivery/tracker-target.js +51 -0
- package/src/delivery/tracker-transition.js +158 -0
- package/src/delivery/tracker.js +164 -0
- package/src/discovery/git.js +85 -0
- package/src/discovery/portable.js +108 -0
- package/src/discovery/project.js +345 -0
- package/src/discovery/tools.js +145 -0
- package/src/evaluations/approval.js +20 -0
- package/src/evaluations/cost-policy.js +20 -0
- package/src/evaluations/harness-attempt.js +113 -0
- package/src/evaluations/live-runner.js +55 -0
- package/src/evaluations/profile.js +28 -0
- package/src/evaluations/report.js +11 -0
- package/src/evaluations/text-attempt.js +18 -0
- package/src/evidence/checksum.js +87 -0
- package/src/evidence/collect.js +727 -0
- package/src/evidence/validate.js +354 -0
- package/src/feature/accepted-integration.js +46 -0
- package/src/feature/actions.js +37 -0
- package/src/feature/client-profile.js +56 -0
- package/src/feature/decomposition-contract.js +58 -0
- package/src/feature/host-execution.js +633 -0
- package/src/feature/host-lock-recovery.js +96 -0
- package/src/feature/host-run-lock.js +32 -0
- package/src/feature/local-approval.js +183 -0
- package/src/feature/plan-contract.js +215 -0
- package/src/feature/planner.js +253 -0
- package/src/feature/run-store.js +241 -0
- package/src/feature/runtime-bridge.js +840 -0
- package/src/feature/verification-report.js +168 -0
- package/src/feature/workflow.js +375 -0
- package/src/git/client.js +509 -0
- package/src/git/integration-worktree.js +153 -0
- package/src/git/reconcile.js +222 -0
- package/src/git/reservations.js +450 -0
- package/src/git/worktrees.js +478 -0
- package/src/graph/completion.js +189 -0
- package/src/graph/fixtures.js +116 -0
- package/src/graph/reducer.js +124 -0
- package/src/graph/scheduler.js +252 -0
- package/src/graph/validate.js +106 -0
- package/src/install/managed.js +579 -0
- package/src/install/project-reference.js +33 -0
- package/src/install/project-runtime.js +142 -0
- package/src/install/runtime-integrity.cjs +141 -0
- package/src/integrations/capabilities.js +69 -0
- package/src/integrations/host-observation.js +26 -0
- package/src/integrations/registry.js +56 -0
- package/src/models/delegate.js +102 -0
- package/src/models/profiles.js +53 -0
- package/src/models/protocols.js +208 -0
- package/src/models/registry.js +83 -0
- package/src/models/transport.js +59 -0
- package/src/policy/approvals.js +251 -0
- package/src/policy/authority.js +282 -0
- package/src/policy/budget.js +149 -0
- package/src/policy/command-bootstrap.js +219 -0
- package/src/policy/commands.js +803 -0
- package/src/prompts/launch-contract.js +43 -0
- package/src/prompts/planning-contract.js +92 -0
- package/src/protocols/presentation.js +53 -0
- package/src/protocols/project.js +289 -0
- package/src/quality/runner.js +497 -0
- package/src/quality/traceability.js +215 -0
- package/src/repositories/identity.js +59 -0
- package/src/repositories/index.js +2 -0
- package/src/repositories/provider.js +210 -0
- package/src/runtime/application.js +353 -0
- package/src/runtime/dependency-directory.js +33 -0
- package/src/runtime/harness-discovery.js +121 -0
- package/src/runtime/heartbeat.js +47 -0
- package/src/runtime/instance-store.js +112 -0
- package/src/runtime/orchestrator.js +1133 -0
- package/src/runtime/portable-dependencies.js +94 -0
- package/src/runtime/recovery.js +190 -0
- package/src/runtime/retry.js +54 -0
- package/src/runtime/supervisor.js +166 -0
- package/src/runtime/worktree-bootstrap.js +169 -0
- package/src/state/event-store.js +333 -0
- package/src/state/lock.js +266 -0
- package/src/state/paths.js +274 -0
- package/src/state/redact.js +106 -0
- package/src/state/snapshot-store.js +310 -0
- package/src/status/public/app.js +96 -0
- package/src/status/public/index.html +37 -0
- package/src/status/public/styles.css +50 -0
- package/src/status/server.js +323 -0
- package/src/status/view-model.js +356 -0
- package/src/support/bundle.js +195 -0
- package/src/support/failure-report.js +96 -0
- package/src/work-request/contract.js +250 -0
- package/src/work-request/host.js +78 -0
- package/src/work-request/local.js +163 -0
- package/src/work-request/tracker.js +105 -0
- package/templates/evidence/qa-bundle.json +194 -0
- package/templates/github-actions/rivet-deploy.yml +98 -0
- package/templates/harness/SKILL.md +90 -0
- package/templates/project/.rivet/orchestration.yaml +42 -0
- package/templates/project/.rivet/project.yaml +14 -0
- package/templates/project/.rivet/providers.yaml +8 -0
- package/templates/project/.rivet/quality.yaml +16 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import {
|
|
2
|
+
boundedString,
|
|
3
|
+
captureRecord,
|
|
4
|
+
createAdapter,
|
|
5
|
+
createProviderWriteGovernance,
|
|
6
|
+
createProviderWireBody,
|
|
7
|
+
createSourceEnvelope,
|
|
8
|
+
executeGovernedWrite,
|
|
9
|
+
executeTrustedConditionalMutation,
|
|
10
|
+
failProvider,
|
|
11
|
+
providerTimestamp,
|
|
12
|
+
sanitizeReferenceUrl,
|
|
13
|
+
validateTrustedConditionalMutationCapability,
|
|
14
|
+
} from './contract.js';
|
|
15
|
+
import { createProviderHttpClient } from './http.js';
|
|
16
|
+
|
|
17
|
+
const READ = Object.freeze(['repo', 'branch', 'pull', 'checks', 'reviews', 'artifacts', 'delivery']);
|
|
18
|
+
const WRITE = Object.freeze(['pr', 'comment']);
|
|
19
|
+
const NAME = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,98}[A-Za-z0-9])?$/;
|
|
20
|
+
const REF = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$/;
|
|
21
|
+
const SHA = /^[a-f0-9]{40}$/;
|
|
22
|
+
|
|
23
|
+
function identity(ownerInput, repoInput) {
|
|
24
|
+
return {
|
|
25
|
+
owner: boundedString(ownerInput, 100, NAME),
|
|
26
|
+
repo: boundedString(repoInput, 100, NAME),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function repoPath(owner, repo) { return `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`; }
|
|
31
|
+
|
|
32
|
+
function remoteFailure() { failProvider('remote', { provider: 'github', retryClassification: 'permanent' }); }
|
|
33
|
+
|
|
34
|
+
function boundRemoteUrl(value, origin, pathname, fragmentPattern) {
|
|
35
|
+
try {
|
|
36
|
+
const url = new URL(value);
|
|
37
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.origin !== origin || url.pathname !== pathname
|
|
38
|
+
|| (fragmentPattern ? !fragmentPattern.test(url.hash) : Boolean(url.hash))) remoteFailure();
|
|
39
|
+
url.hash = '';
|
|
40
|
+
return sanitizeReferenceUrl(url.href);
|
|
41
|
+
} catch (error) { if (error?.code === 'ERR_PROVIDER_REMOTE') throw error; remoteFailure(); }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function validId(value) { return Number.isSafeInteger(value) && value > 0; }
|
|
45
|
+
|
|
46
|
+
function validRef(value) { return typeof value === 'string' && REF.test(value) && !value.includes('..') && !value.includes('//'); }
|
|
47
|
+
|
|
48
|
+
function validateRepository(value, expected, context) {
|
|
49
|
+
try {
|
|
50
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || !validId(value.id)
|
|
51
|
+
|| value.full_name !== expected || !validRef(value.default_branch)
|
|
52
|
+
|| typeof value.private !== 'boolean' || typeof value.html_url !== 'string') remoteFailure();
|
|
53
|
+
boundRemoteUrl(value.html_url, context.webOrigin, `/${expected}`);
|
|
54
|
+
if (value.url !== undefined) boundRemoteUrl(value.url, context.apiOrigin, `${context.apiPrefix}/repos/${expected}`);
|
|
55
|
+
return value;
|
|
56
|
+
} catch (error) { if (error?.code === 'ERR_PROVIDER_REMOTE') throw error; remoteFailure(); }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function validateBranch(value, expected) {
|
|
60
|
+
try {
|
|
61
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || value.name !== expected
|
|
62
|
+
|| !value.commit || typeof value.commit !== 'object' || Array.isArray(value.commit)
|
|
63
|
+
|| typeof value.commit.sha !== 'string' || !SHA.test(value.commit.sha) || typeof value.protected !== 'boolean') remoteFailure();
|
|
64
|
+
return value;
|
|
65
|
+
} catch (error) { if (error?.code === 'ERR_PROVIDER_REMOTE') throw error; remoteFailure(); }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function validatePull(value, number, context, full = true) {
|
|
69
|
+
try {
|
|
70
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || value.number !== number
|
|
71
|
+
|| !['open', 'closed'].includes(value.state)) remoteFailure();
|
|
72
|
+
if (full && (!value.head || typeof value.head !== 'object' || Array.isArray(value.head) || !SHA.test(value.head.sha)
|
|
73
|
+
|| !value.base || typeof value.base !== 'object' || Array.isArray(value.base) || !validRef(value.base.ref)
|
|
74
|
+
|| !SHA.test(value.base.sha) || typeof value.html_url !== 'string')) remoteFailure();
|
|
75
|
+
if (full) boundRemoteUrl(value.html_url, context.webOrigin, `/${context.owner}/${context.repo}/pull/${number}`);
|
|
76
|
+
if (value.url !== undefined) boundRemoteUrl(value.url, context.apiOrigin,
|
|
77
|
+
`${context.apiPrefix}/repos/${context.owner}/${context.repo}/pulls/${number}`);
|
|
78
|
+
return value;
|
|
79
|
+
} catch (error) { if (error?.code === 'ERR_PROVIDER_REMOTE') throw error; remoteFailure(); }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function validateChecks(value, context) {
|
|
83
|
+
try {
|
|
84
|
+
if (!Array.isArray(value)) remoteFailure();
|
|
85
|
+
for (const item of value) {
|
|
86
|
+
if (!item || typeof item !== 'object' || Array.isArray(item) || !validId(item.id)
|
|
87
|
+
|| typeof item.name !== 'string' || item.name.length === 0
|
|
88
|
+
|| !['queued', 'in_progress', 'completed', 'pending', 'requested', 'waiting'].includes(item.status)
|
|
89
|
+
|| (item.conclusion !== null && !['action_required', 'cancelled', 'failure', 'neutral', 'success', 'skipped', 'stale', 'timed_out'].includes(item.conclusion))) remoteFailure();
|
|
90
|
+
if (item.html_url !== undefined) boundRemoteUrl(item.html_url, context.webOrigin, `/${context.owner}/${context.repo}/runs/${item.id}`);
|
|
91
|
+
if (item.url !== undefined) boundRemoteUrl(item.url, context.apiOrigin,
|
|
92
|
+
`${context.apiPrefix}/repos/${context.owner}/${context.repo}/check-runs/${item.id}`);
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
} catch (error) { if (error?.code === 'ERR_PROVIDER_REMOTE') throw error; remoteFailure(); }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function validateReviews(value, context) {
|
|
99
|
+
try {
|
|
100
|
+
if (!Array.isArray(value)) remoteFailure();
|
|
101
|
+
for (const item of value) {
|
|
102
|
+
if (!item || typeof item !== 'object' || Array.isArray(item) || !validId(item.id)
|
|
103
|
+
|| !['PENDING', 'COMMENTED', 'APPROVED', 'CHANGES_REQUESTED', 'DISMISSED'].includes(item.state)
|
|
104
|
+
|| !item.user || typeof item.user !== 'object' || Array.isArray(item.user)
|
|
105
|
+
|| typeof item.user.login !== 'string' || item.user.login.length === 0) remoteFailure();
|
|
106
|
+
if (item.html_url !== undefined) boundRemoteUrl(item.html_url, context.webOrigin,
|
|
107
|
+
`/${context.owner}/${context.repo}/pull/${context.pullNumber}`, new RegExp(`^#pullrequestreview-${item.id}$`));
|
|
108
|
+
if (item.url !== undefined) boundRemoteUrl(item.url, context.apiOrigin,
|
|
109
|
+
`${context.apiPrefix}/repos/${context.owner}/${context.repo}/pulls/${context.pullNumber}/reviews/${item.id}`);
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
} catch (error) { if (error?.code === 'ERR_PROVIDER_REMOTE') throw error; remoteFailure(); }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function validateArtifacts(value, context) {
|
|
116
|
+
try {
|
|
117
|
+
if (!Array.isArray(value)) remoteFailure();
|
|
118
|
+
for (const item of value) if (!item || typeof item !== 'object' || Array.isArray(item) || !validId(item.id)
|
|
119
|
+
|| typeof item.name !== 'string' || item.name.length === 0 || typeof item.expired !== 'boolean'
|
|
120
|
+
|| typeof item.archive_download_url !== 'string') remoteFailure();
|
|
121
|
+
else {
|
|
122
|
+
const url = new URL(item.archive_download_url);
|
|
123
|
+
const prefix = `${context.apiPrefix}/repos/${context.owner}/${context.repo}/actions/artifacts/${item.id}/`;
|
|
124
|
+
if (!url.pathname.startsWith(prefix) || !/^(?:zip|tarball)$/.test(url.pathname.slice(prefix.length))) remoteFailure();
|
|
125
|
+
boundRemoteUrl(item.archive_download_url, context.apiOrigin, url.pathname);
|
|
126
|
+
if (item.url !== undefined) boundRemoteUrl(item.url, context.apiOrigin,
|
|
127
|
+
`${context.apiPrefix}/repos/${context.owner}/${context.repo}/actions/artifacts/${item.id}`);
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
} catch (error) { if (error?.code === 'ERR_PROVIDER_REMOTE') throw error; remoteFailure(); }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function normalizeRepository(value) {
|
|
134
|
+
return {
|
|
135
|
+
id: value?.id ?? null, fullName: String(value?.full_name ?? ''), defaultBranch: String(value?.default_branch ?? ''),
|
|
136
|
+
private: value.private, url: sanitizeReferenceUrl(value.html_url),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function normalizeBranch(value) {
|
|
141
|
+
return { name: String(value?.name ?? ''), commitSha: String(value?.commit?.sha ?? ''), protected: value?.protected === true };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function normalizePull(value) {
|
|
145
|
+
return {
|
|
146
|
+
number: value.number, state: value.state, title: String(value.title ?? ''),
|
|
147
|
+
headSha: value.head.sha, baseBranch: value.base.ref, baseSha: value.base.sha, url: sanitizeReferenceUrl(value.html_url),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function createGithubAdapter(input) {
|
|
152
|
+
const config = captureRecord(input, new Set([
|
|
153
|
+
'transport', 'baseUrl', 'headers', 'timeoutMs', 'maxResponseBytes', 'maxPages', 'maxItems', 'clock', 'governance', 'conditionalMutation',
|
|
154
|
+
]), ['transport', 'baseUrl'], 'invalid-config');
|
|
155
|
+
const now = config.clock ?? (() => new Date().toISOString());
|
|
156
|
+
if (typeof now !== 'function') failProvider('invalid-config', { provider: 'github' });
|
|
157
|
+
const http = createProviderHttpClient({
|
|
158
|
+
provider: 'github', baseUrl: config.baseUrl, transport: config.transport,
|
|
159
|
+
...(config.headers === undefined ? {} : { headers: config.headers }),
|
|
160
|
+
...(config.timeoutMs === undefined ? {} : { timeoutMs: config.timeoutMs }),
|
|
161
|
+
...(config.maxResponseBytes === undefined ? {} : { maxResponseBytes: config.maxResponseBytes }),
|
|
162
|
+
...(config.maxPages === undefined ? {} : { maxPages: config.maxPages }),
|
|
163
|
+
...(config.maxItems === undefined ? {} : { maxItems: config.maxItems }),
|
|
164
|
+
});
|
|
165
|
+
const governance = config.governance === undefined ? null : createProviderWriteGovernance(config.governance, 'github');
|
|
166
|
+
const conditionalMutation = config.conditionalMutation;
|
|
167
|
+
if (governance && !validateTrustedConditionalMutationCapability(conditionalMutation, 'github', ['comment'])) failProvider('invalid-config', { provider: 'github' });
|
|
168
|
+
const apiOrigin = new URL(http.baseUrl).origin;
|
|
169
|
+
const apiPrefix = new URL(http.baseUrl).pathname.replace(/\/$/, '');
|
|
170
|
+
const webOrigin = new URL(apiOrigin).hostname === 'api.github.com' ? 'https://github.com' : apiOrigin;
|
|
171
|
+
|
|
172
|
+
async function read(inputRead) {
|
|
173
|
+
const request = captureRecord(inputRead, new Set([
|
|
174
|
+
'kind', 'owner', 'repo', 'branch', 'pullNumber', 'commitSha', 'signal',
|
|
175
|
+
]), ['kind', 'owner', 'repo']);
|
|
176
|
+
const kind = boundedString(request.kind, 16, /^(?:repo|branch|pull|checks|reviews|artifacts|delivery)$/);
|
|
177
|
+
const { owner, repo } = identity(request.owner, request.repo);
|
|
178
|
+
const context = { owner, repo, apiOrigin, apiPrefix, webOrigin, pullNumber: request.pullNumber };
|
|
179
|
+
const root = repoPath(owner, repo);
|
|
180
|
+
const signal = request.signal === undefined ? {} : { signal: request.signal };
|
|
181
|
+
const raw = {};
|
|
182
|
+
if (kind === 'repo' || kind === 'delivery') {
|
|
183
|
+
raw.repository = (await http.request({ method: 'GET', path: root, ...signal })).data;
|
|
184
|
+
validateRepository(raw.repository, `${owner}/${repo}`, context);
|
|
185
|
+
}
|
|
186
|
+
if (kind === 'branch' || kind === 'delivery') {
|
|
187
|
+
const branch = boundedString(request.branch, 255, /^[A-Za-z0-9][A-Za-z0-9._/-]*$/);
|
|
188
|
+
if (branch.includes('..') || branch.includes('//')) failProvider('invalid-request', { provider: 'github' });
|
|
189
|
+
raw.branch = (await http.request({ method: 'GET', path: `${root}/branches/${encodeURIComponent(branch)}`, ...signal })).data;
|
|
190
|
+
validateBranch(raw.branch, branch);
|
|
191
|
+
}
|
|
192
|
+
if (['pull', 'reviews', 'delivery'].includes(kind)) {
|
|
193
|
+
if (!Number.isSafeInteger(request.pullNumber) || request.pullNumber < 1 || request.pullNumber > 1_000_000_000) failProvider('invalid-request', { provider: 'github' });
|
|
194
|
+
if (kind === 'pull' || kind === 'delivery') {
|
|
195
|
+
raw.pull = (await http.request({ method: 'GET', path: `${root}/pulls/${request.pullNumber}`, ...signal })).data;
|
|
196
|
+
validatePull(raw.pull, request.pullNumber, context);
|
|
197
|
+
}
|
|
198
|
+
if (kind === 'reviews' || kind === 'delivery') {
|
|
199
|
+
raw.reviews = await http.paginate({
|
|
200
|
+
path: `${root}/pulls/${request.pullNumber}/reviews?per_page=100`, identityKey: 'id', ...signal,
|
|
201
|
+
});
|
|
202
|
+
validateReviews(raw.reviews, context);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (kind === 'checks' || kind === 'delivery') {
|
|
206
|
+
const sha = boundedString(request.commitSha, 40, SHA);
|
|
207
|
+
const checkRuns = await http.paginate({
|
|
208
|
+
path: `${root}/commits/${sha}/check-runs?per_page=100`, itemsKey: 'check_runs', identityKey: 'id', totalKey: 'total_count', ...signal,
|
|
209
|
+
});
|
|
210
|
+
validateChecks(checkRuns, context);
|
|
211
|
+
raw.checks = { check_runs: checkRuns };
|
|
212
|
+
}
|
|
213
|
+
if (kind === 'artifacts' || kind === 'delivery') {
|
|
214
|
+
const artifacts = await http.paginate({
|
|
215
|
+
path: `${root}/actions/artifacts?per_page=100`, itemsKey: 'artifacts', identityKey: 'id', totalKey: 'total_count', ...signal,
|
|
216
|
+
});
|
|
217
|
+
validateArtifacts(artifacts, context);
|
|
218
|
+
raw.artifacts = { artifacts };
|
|
219
|
+
}
|
|
220
|
+
const normalized = {
|
|
221
|
+
...(raw.repository ? { repository: normalizeRepository(raw.repository) } : {}),
|
|
222
|
+
...(raw.branch ? { branch: normalizeBranch(raw.branch) } : {}),
|
|
223
|
+
...(raw.pull ? { pullRequest: normalizePull(raw.pull) } : {}),
|
|
224
|
+
...(raw.checks ? { checks: (raw.checks.check_runs ?? []).map(item => ({
|
|
225
|
+
id: item.id, name: item.name, status: item.status, conclusion: item.conclusion,
|
|
226
|
+
})) } : {}),
|
|
227
|
+
...(raw.reviews ? { reviews: raw.reviews.map(item => ({
|
|
228
|
+
id: item.id, state: item.state, reviewer: item.user.login,
|
|
229
|
+
})) } : {}),
|
|
230
|
+
...(raw.artifacts ? { artifacts: (raw.artifacts.artifacts ?? []).map(item => ({
|
|
231
|
+
id: item.id, name: item.name, expired: item.expired, url: sanitizeReferenceUrl(item.archive_download_url),
|
|
232
|
+
})) } : {}),
|
|
233
|
+
};
|
|
234
|
+
return createSourceEnvelope({
|
|
235
|
+
provider: 'github', sourceId: `${owner}/${repo}`, sourceUrl: `${webOrigin}/${owner}/${repo}`,
|
|
236
|
+
fetchedAt: providerTimestamp(now, 'github'), fixtureSource: false, raw, normalized,
|
|
237
|
+
retryClassification: 'none', capabilities: { read: READ, write: WRITE },
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function parseResource(value) {
|
|
242
|
+
const match = /^([^/#]+)\/([^/#]+)#([1-9][0-9]*)$/.exec(value);
|
|
243
|
+
if (!match) failProvider('invalid-request', { provider: 'github' });
|
|
244
|
+
const names = identity(match[1], match[2]);
|
|
245
|
+
const number = Number(match[3]);
|
|
246
|
+
if (!Number.isSafeInteger(number) || number > 1_000_000_000) failProvider('invalid-request', { provider: 'github' });
|
|
247
|
+
return { ...names, number, root: repoPath(names.owner, names.repo) };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function write(inputWrite) {
|
|
251
|
+
if (!governance) failProvider('approval-required', { provider: 'github' });
|
|
252
|
+
return executeGovernedWrite(inputWrite, {
|
|
253
|
+
provider: 'github', actions: new Set(WRITE), governance,
|
|
254
|
+
async preflight(writeRequest) {
|
|
255
|
+
const resource = parseResource(writeRequest.resourceId);
|
|
256
|
+
const response = await http.request({ method: 'GET', path: `${resource.root}/pulls/${resource.number}` });
|
|
257
|
+
if (!response.headers.etag) failProvider('state-conflict', { provider: 'github' });
|
|
258
|
+
try { validatePull(response.data, resource.number, { ...resource, apiOrigin, apiPrefix, webOrigin }, false); } catch { failProvider('state-conflict', { provider: 'github' }); }
|
|
259
|
+
return Object.freeze({
|
|
260
|
+
state: String(response.data?.state ?? ''), version: response.headers.etag,
|
|
261
|
+
condition: response.headers.etag, resource,
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
prepare(writeRequest, state) {
|
|
265
|
+
const commonHeaders = {
|
|
266
|
+
'idempotency-key': writeRequest.idempotencyKey,
|
|
267
|
+
'if-match': state.condition,
|
|
268
|
+
};
|
|
269
|
+
if (writeRequest.action === 'comment') {
|
|
270
|
+
const payload = captureRecord(writeRequest.payload, new Set(['body']), ['body']);
|
|
271
|
+
return Object.freeze({
|
|
272
|
+
method: 'POST', path: `${state.resource.root}/issues/${state.resource.number}/comments`, headers: commonHeaders,
|
|
273
|
+
wireBody: createProviderWireBody(writeRequest),
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
const payload = captureRecord(writeRequest.payload, new Set(['title', 'body', 'state']), []);
|
|
277
|
+
const body = {};
|
|
278
|
+
if (payload.title !== undefined) body.title = boundedString(payload.title, 512);
|
|
279
|
+
if (payload.body !== undefined) body.body = boundedString(payload.body, 65_536);
|
|
280
|
+
if (payload.state !== undefined) body.state = boundedString(payload.state, 16, /^(?:open|closed)$/);
|
|
281
|
+
if (Object.keys(body).length === 0) failProvider('invalid-request', { provider: 'github' });
|
|
282
|
+
return Object.freeze({
|
|
283
|
+
method: 'PATCH', path: `${state.resource.root}/pulls/${state.resource.number}`, headers: commonHeaders, wireBody: createProviderWireBody(writeRequest),
|
|
284
|
+
});
|
|
285
|
+
},
|
|
286
|
+
async mutate(writeRequest, _state, prepared) {
|
|
287
|
+
if (writeRequest.action === 'comment') {
|
|
288
|
+
return executeTrustedConditionalMutation(conditionalMutation, {
|
|
289
|
+
provider: 'github', action: writeRequest.action, resourceId: writeRequest.resourceId,
|
|
290
|
+
expectedState: writeRequest.expectedState, expectedVersion: writeRequest.expectedVersion,
|
|
291
|
+
idempotencyKey: writeRequest.idempotencyKey, wireBody: prepared.wireBody,
|
|
292
|
+
dispatch: async () => {
|
|
293
|
+
const data = (await http.request(prepared)).data;
|
|
294
|
+
if (!data || !validId(data.id)) remoteFailure();
|
|
295
|
+
if (data.html_url !== undefined) boundRemoteUrl(data.html_url, webOrigin,
|
|
296
|
+
`/${_state.resource.owner}/${_state.resource.repo}/issues/${_state.resource.number}`,
|
|
297
|
+
new RegExp(`^#issuecomment-${data.id}$`));
|
|
298
|
+
return data;
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
const data = (await http.request(prepared)).data;
|
|
303
|
+
validatePull(data, _state.resource.number, { ..._state.resource, apiOrigin, apiPrefix, webOrigin }, false);
|
|
304
|
+
if (data.html_url !== undefined) boundRemoteUrl(data.html_url, webOrigin,
|
|
305
|
+
`/${_state.resource.owner}/${_state.resource.repo}/pull/${_state.resource.number}`);
|
|
306
|
+
return data;
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return createAdapter({
|
|
312
|
+
provider: 'github', fixtureSource: false, capabilities: { read: READ, write: WRITE }, read, write,
|
|
313
|
+
});
|
|
314
|
+
}
|