@tnunamak/dalan 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +176 -0
- package/CONTRIBUTING.md +26 -0
- package/LICENSE +204 -0
- package/PROTOCOL.md +351 -0
- package/README.md +215 -2
- package/SECURITY.md +30 -0
- package/bin/dalan.mjs +43 -0
- package/bin/dot-acp-agent.mjs +377 -0
- package/bin/dot-alert.mjs +9 -0
- package/bin/dot-deadman.mjs +82 -0
- package/bin/dot-heartbeat.mjs +29 -0
- package/bin/dot-pr-reviewer.mjs +32 -0
- package/bin/dot-worker.mjs +764 -0
- package/docs/chatgpt-worker-onboarding.md +112 -0
- package/docs/claude-worker-onboarding.md +113 -0
- package/docs/codex-to-muse.md +175 -0
- package/docs/connect-chatgpt.md +83 -0
- package/docs/connection-longevity.md +43 -0
- package/docs/dalan-upgrade.md +246 -0
- package/docs/deadman.md +61 -0
- package/docs/dot-pr-reviewer.config.example.json +9 -0
- package/docs/durability-audit.md +27 -0
- package/docs/keycloak-client-chatgpt-dot-bridge.json +59 -0
- package/docs/keycloak-oauth-setup.md +30 -0
- package/docs/local-agent-mcp.md +41 -0
- package/docs/manual-setup.md +135 -0
- package/docs/mirror-fetch.md +97 -0
- package/docs/operations.md +799 -0
- package/docs/operator-duties.md +68 -0
- package/docs/owner-integrator.md +27 -0
- package/docs/portable-auth-profile.md +107 -0
- package/docs/pr-head-reviewer.md +70 -0
- package/docs/pr-preflight.md +28 -0
- package/docs/pull-queue.md +131 -0
- package/docs/pull-workers.md +94 -0
- package/docs/redaction.md +27 -0
- package/docs/service-setup.md +219 -0
- package/docs/setup-reference.md +80 -0
- package/docs/t3-connector-icon.png +0 -0
- package/docs/t3-integration.md +51 -0
- package/docs/t3-result-retry-delivery.md +41 -0
- package/docs/t3-reverse-control.md +107 -0
- package/docs/usage.md +443 -0
- package/docs/worker-clients.md +290 -0
- package/integrations/t3/acp-kit/src/capability.mjs +25 -0
- package/integrations/t3/acp-kit/src/errors.mjs +13 -0
- package/integrations/t3/acp-kit/src/index.mjs +5 -0
- package/integrations/t3/acp-kit/src/lock.mjs +155 -0
- package/integrations/t3/acp-kit/src/session-store.mjs +36 -0
- package/integrations/t3/acp-kit/src/t3-envelope.mjs +62 -0
- package/package.json +67 -4
- package/packages/job-core/README.md +18 -0
- package/packages/job-core/index.mjs +2 -0
- package/packages/job-core/package.json +8 -0
- package/packages/job-core/protocol/canonical.mjs +11 -0
- package/packages/job-core/protocol/v0/command.schema.json +1154 -0
- package/packages/job-core/protocol/v0/event.schema.json +77 -0
- package/packages/job-core/protocol/v0/reply.schema.json +59 -0
- package/packages/job-core/transitions.mjs +25 -0
- package/scripts/daily-selfcheck.mjs +135 -0
- package/scripts/dalan-try-selfcheck.mjs +29 -0
- package/scripts/lib/expose-tailscale.mjs +408 -0
- package/scripts/live-trial/common.mjs +272 -0
- package/scripts/monitor-targets.mjs +44 -0
- package/scripts/upgrade-drain.mjs +39 -0
- package/scripts/worker-bridge-setup.mjs +925 -0
- package/src/ack-ledger.mjs +37 -0
- package/src/acp-bridge.mjs +418 -0
- package/src/acp-context.mjs +138 -0
- package/src/admin-socket.mjs +14 -0
- package/src/alerts.mjs +147 -0
- package/src/artifact-journal.mjs +75 -0
- package/src/as-files.mjs +347 -0
- package/src/as-store.mjs +456 -0
- package/src/as.mjs +538 -0
- package/src/auth.mjs +166 -0
- package/src/builtin-http.mjs +22 -0
- package/src/check-coverage.mjs +38 -0
- package/src/check-lint.mjs +88 -0
- package/src/check-readiness.mjs +112 -0
- package/src/check-response.mjs +19 -0
- package/src/child-exit.mjs +18 -0
- package/src/child-registry.mjs +94 -0
- package/src/claim-command-ledger.mjs +51 -0
- package/src/cli-help.mjs +186 -0
- package/src/cli-name.mjs +16 -0
- package/src/connect-cli.mjs +126 -0
- package/src/consumers.mjs +61 -0
- package/src/deadman.mjs +329 -0
- package/src/delivery.mjs +19 -0
- package/src/demo-worker.mjs +150 -0
- package/src/destinations/index.mjs +23 -0
- package/src/destinations/none.mjs +15 -0
- package/src/destinations/t3.mjs +109 -0
- package/src/diagnostic.mjs +78 -0
- package/src/docs-url.mjs +9 -0
- package/src/drain-runner.mjs +9 -0
- package/src/drained-owner.mjs +26 -0
- package/src/drained-slot.mjs +70 -0
- package/src/drained.mjs +40 -0
- package/src/durable-waiters.mjs +236 -0
- package/src/env.mjs +19 -0
- package/src/execution.mjs +112 -0
- package/src/failure-type.mjs +28 -0
- package/src/get-summary.mjs +32 -0
- package/src/git-env.mjs +15 -0
- package/src/host-budget-receipts.mjs +154 -0
- package/src/host-budget-seccomp.py +33 -0
- package/src/host-budget-service.mjs +54 -0
- package/src/host-budget-stop.mjs +26 -0
- package/src/host-budget-storage.py +259 -0
- package/src/host-budget.mjs +149 -0
- package/src/host-cgroup.mjs +23 -0
- package/src/host-check-allowlist.mjs +42 -0
- package/src/host-execution-policy.mjs +38 -0
- package/src/host-health.mjs +34 -0
- package/src/host-stop-reverify.mjs +44 -0
- package/src/inbox.mjs +55 -0
- package/src/integrator.mjs +322 -0
- package/src/job-retention.mjs +69 -0
- package/src/legacy-names.mjs +8 -0
- package/src/lifecycle.mjs +291 -0
- package/src/limits.mjs +31 -0
- package/src/loopback.mjs +9 -0
- package/src/mcp-outcome.mjs +79 -0
- package/src/mcp-sse.mjs +62 -0
- package/src/mcp-stdio.mjs +191 -0
- package/src/mirror-fetch-lock.py +164 -0
- package/src/mirror-fetch.mjs +174 -0
- package/src/notify-ledger.mjs +82 -0
- package/src/objectives.mjs +129 -0
- package/src/owner-report-artifact.mjs +66 -0
- package/src/patch-apply.mjs +84 -0
- package/src/path-syntax.mjs +16 -0
- package/src/paths.mjs +67 -0
- package/src/pr-head-reviewer.mjs +596 -0
- package/src/pr-preflight.mjs +51 -0
- package/src/prepared-node-modules.mjs +129 -0
- package/src/process-inspection.mjs +36 -0
- package/src/projects.mjs +480 -0
- package/src/protocol-artifact-commands.mjs +52 -0
- package/src/protocol-delivery-driver.mjs +167 -0
- package/src/protocol-finish.mjs +100 -0
- package/src/protocol-owner-command.mjs +35 -0
- package/src/protocol-owner-mutations.mjs +22 -0
- package/src/protocol-owner-waiters.mjs +67 -0
- package/src/protocol-retention.mjs +52 -0
- package/src/protocol-services.mjs +61 -0
- package/src/protocol-stop-observer.mjs +131 -0
- package/src/publish-plan.mjs +245 -0
- package/src/pull-queue.mjs +159 -0
- package/src/redaction.mjs +763 -0
- package/src/rejections.mjs +18 -0
- package/src/request-log.mjs +102 -0
- package/src/restore-check.mjs +90 -0
- package/src/result-binding.mjs +65 -0
- package/src/route-setting.mjs +24 -0
- package/src/runtime-check.mjs +13 -0
- package/src/sandbox-supervisor.mjs +105 -0
- package/src/schema-subset.mjs +186 -0
- package/src/scopes.mjs +15 -0
- package/src/server.mjs +1468 -0
- package/src/service-migrate-workers.mjs +113 -0
- package/src/service.mjs +388 -0
- package/src/setup.mjs +63 -0
- package/src/shutdown-signal.mjs +12 -0
- package/src/signal-sandbox-processes.py +56 -0
- package/src/signal.mjs +119 -0
- package/src/status-evidence.mjs +47 -0
- package/src/status-summary.mjs +54 -0
- package/src/store.mjs +3069 -0
- package/src/submission-policy.mjs +623 -0
- package/src/subscription-storage.mjs +64 -0
- package/src/t3-audit.mjs +120 -0
- package/src/t3-control.mjs +102 -0
- package/src/t3-transport.mjs +158 -0
- package/src/t3.mjs +209 -0
- package/src/terminal-safe.mjs +19 -0
- package/src/tool-registry.mjs +453 -0
- package/src/try-command.mjs +11 -0
- package/src/try-exposure.mjs +908 -0
- package/src/try-hosted-clients.mjs +46 -0
- package/src/try-hosted.mjs +444 -0
- package/src/try-selfcheck.mjs +168 -0
- package/src/try.mjs +635 -0
- package/src/webhooks.mjs +86 -0
- package/src/work-order.mjs +265 -0
- package/src/worker-instructions.mjs +26 -0
- package/src/worker-prompt.mjs +4 -0
- package/src/workers.mjs +632 -0
- package/src/workspace.mjs +1065 -0
- package/systemd/dot-bridge-heartbeat.service +18 -0
- package/systemd/dot-bridge-heartbeat.timer +10 -0
- package/systemd/dot-bridge-selfcheck.service +12 -0
- package/systemd/dot-bridge-selfcheck.timer +11 -0
- package/systemd/dot-bridge.service +17 -0
- package/systemd/dot-deadman.service +30 -0
- package/systemd/dot-pr-reviewer.service +11 -0
- package/systemd/dot-pr-reviewer.timer +10 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"properties": {
|
|
4
|
+
"v": {
|
|
5
|
+
"const": 0
|
|
6
|
+
},
|
|
7
|
+
"source": {
|
|
8
|
+
"const": "urn:fixture:job-store"
|
|
9
|
+
},
|
|
10
|
+
"id": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"minLength": 1,
|
|
13
|
+
"maxLength": 256
|
|
14
|
+
},
|
|
15
|
+
"job": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"minLength": 1,
|
|
18
|
+
"maxLength": 256
|
|
19
|
+
},
|
|
20
|
+
"seq": {
|
|
21
|
+
"type": "integer",
|
|
22
|
+
"minimum": 1,
|
|
23
|
+
"maximum": 9007199254740991
|
|
24
|
+
},
|
|
25
|
+
"revision": {
|
|
26
|
+
"type": "integer",
|
|
27
|
+
"minimum": 1,
|
|
28
|
+
"maximum": 9007199254740991
|
|
29
|
+
},
|
|
30
|
+
"epoch": {
|
|
31
|
+
"type": "integer",
|
|
32
|
+
"minimum": 0,
|
|
33
|
+
"maximum": 9007199254740991
|
|
34
|
+
},
|
|
35
|
+
"type": {
|
|
36
|
+
"enum": [
|
|
37
|
+
"submitted",
|
|
38
|
+
"claimed",
|
|
39
|
+
"renewed",
|
|
40
|
+
"progressed",
|
|
41
|
+
"questioned",
|
|
42
|
+
"answered",
|
|
43
|
+
"consumed",
|
|
44
|
+
"uploaded",
|
|
45
|
+
"sealed",
|
|
46
|
+
"finished",
|
|
47
|
+
"cancelled",
|
|
48
|
+
"expired",
|
|
49
|
+
"waiter_registered",
|
|
50
|
+
"stop_observed"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"state": {
|
|
54
|
+
"enum": [
|
|
55
|
+
"queued",
|
|
56
|
+
"leased",
|
|
57
|
+
"running",
|
|
58
|
+
"awaiting_input",
|
|
59
|
+
"result_staged",
|
|
60
|
+
"finished",
|
|
61
|
+
"cancelled"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"required": [
|
|
66
|
+
"v",
|
|
67
|
+
"source",
|
|
68
|
+
"id",
|
|
69
|
+
"job",
|
|
70
|
+
"seq",
|
|
71
|
+
"revision",
|
|
72
|
+
"epoch",
|
|
73
|
+
"type",
|
|
74
|
+
"state"
|
|
75
|
+
],
|
|
76
|
+
"additionalProperties": false
|
|
77
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"oneOf": [
|
|
4
|
+
{
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"ok": {
|
|
8
|
+
"const": true
|
|
9
|
+
},
|
|
10
|
+
"value": {
|
|
11
|
+
"type": "object"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"required": [
|
|
15
|
+
"ok",
|
|
16
|
+
"value"
|
|
17
|
+
],
|
|
18
|
+
"additionalProperties": false
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"type": "object",
|
|
22
|
+
"properties": {
|
|
23
|
+
"ok": {
|
|
24
|
+
"const": false
|
|
25
|
+
},
|
|
26
|
+
"code": {
|
|
27
|
+
"enum": [
|
|
28
|
+
"INVALID",
|
|
29
|
+
"FORBIDDEN",
|
|
30
|
+
"NOT_FOUND",
|
|
31
|
+
"KEY_CONFLICT",
|
|
32
|
+
"TOMBSTONE",
|
|
33
|
+
"EXISTS",
|
|
34
|
+
"TERMINAL",
|
|
35
|
+
"STALE_EPOCH",
|
|
36
|
+
"LEASE_EXPIRED",
|
|
37
|
+
"REVISION",
|
|
38
|
+
"BUSY",
|
|
39
|
+
"NO_QUESTION",
|
|
40
|
+
"ALREADY_ANSWERED",
|
|
41
|
+
"NO_ANSWER",
|
|
42
|
+
"UNSEALED",
|
|
43
|
+
"DIGEST",
|
|
44
|
+
"BINDING",
|
|
45
|
+
"QUESTION_OPEN",
|
|
46
|
+
"DELIVERY_STATE",
|
|
47
|
+
"NOT_DUE",
|
|
48
|
+
"DELIVERY_UNKNOWN"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"required": [
|
|
53
|
+
"ok",
|
|
54
|
+
"code"
|
|
55
|
+
],
|
|
56
|
+
"additionalProperties": false
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const natural = value => Number.isSafeInteger(value) && value >= 0;
|
|
2
|
+
const fail = code => { throw Object.assign(new Error(code), { code }); };
|
|
3
|
+
|
|
4
|
+
export function assertClaimAuthority(command, authority, now) {
|
|
5
|
+
const { job, subject, worker, claim, epoch } = command;
|
|
6
|
+
if (!authority || authority.job !== job || authority.subject !== subject || authority.worker !== worker ||
|
|
7
|
+
authority.claim !== claim || authority.epoch !== epoch || authority.active !== true) fail('stale_authority');
|
|
8
|
+
if (!natural(authority.leaseUntil) || now >= authority.leaseUntil) fail('lease_expired');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Called only after authority and receipt replay have been checked by the caller.
|
|
12
|
+
export function decide(snapshot, command, context) {
|
|
13
|
+
const { expectedRevision, operation, args } = command;
|
|
14
|
+
if (snapshot.revision !== expectedRevision) fail('revision_conflict');
|
|
15
|
+
let leaseUntil;
|
|
16
|
+
if (operation === 'renew') {
|
|
17
|
+
if (!args || Object.keys(args).some(key => key !== 'leaseMs') ||
|
|
18
|
+
!natural(args.leaseMs) || args.leaseMs < 1 || args.leaseMs > context.maxLeaseMs) fail('invalid_lease');
|
|
19
|
+
leaseUntil = context.now + args.leaseMs;
|
|
20
|
+
if (!natural(leaseUntil)) fail('invalid_lease');
|
|
21
|
+
}
|
|
22
|
+
if (!natural(expectedRevision) || expectedRevision >= Number.MAX_SAFE_INTEGER) fail('invalid_revision');
|
|
23
|
+
return { events: [], effects: [{ type: 'advance_revision', expectedRevision }],
|
|
24
|
+
...(leaseUntil === undefined ? {} : { leaseUntil }) };
|
|
25
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { endpoint, hostname, appendPath, protectedResourceMetadataUrl, fetchProbe, listsIssuer } from './monitor-targets.mjs';
|
|
3
|
+
import { defaultPath } from '../src/paths.mjs';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import tls from 'node:tls';
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { publishAlert } from '../src/alerts.mjs';
|
|
11
|
+
import { authConfig } from '../src/auth.mjs';
|
|
12
|
+
|
|
13
|
+
// The bridge's own OAuth file already names the public resource and issuer, so a unit that sets only
|
|
14
|
+
// WorkingDirectory still works. An explicit setting wins; an unreadable file leaves the setting unset
|
|
15
|
+
// and main() reports it by name.
|
|
16
|
+
function bridgeSettings() {
|
|
17
|
+
try { const config = authConfig(undefined, false); return config ? { resource: config.OAUTH_AUDIENCE, issuer: config.OAUTH_ISSUER } : {}; }
|
|
18
|
+
catch { return {}; }
|
|
19
|
+
}
|
|
20
|
+
const own = bridgeSettings();
|
|
21
|
+
const resource = process.env.DALAN_SELFCHECK_RESOURCE || process.env.DALAN_RESOURCE_URL || own.resource;
|
|
22
|
+
const issuer = process.env.DALAN_SELFCHECK_ISSUER || process.env.DALAN_ISSUER_URL || own.issuer;
|
|
23
|
+
const tlsHost = process.env.DALAN_SELFCHECK_TLS_HOST || process.env.DALAN_TLS_HOST || (resource && URL.canParse(resource) ? new URL(resource).hostname : undefined);
|
|
24
|
+
const githubRepository = process.env.DALAN_GITHUB_REPOSITORY;
|
|
25
|
+
const repositoryId = process.env.DALAN_SELFCHECK_REPOSITORY_ID;
|
|
26
|
+
const stateFile = defaultPath(os.homedir(),'.local/state/dot-bridge/daily-selfcheck.json');
|
|
27
|
+
|
|
28
|
+
export function assessStatus(status, now = Date.now()) {
|
|
29
|
+
const issues = [];
|
|
30
|
+
if (!status || !Number.isInteger(status.subscriptions_active)) return ['status_invalid'];
|
|
31
|
+
if (status.subscriptions_active < 1) issues.push('subscription_inactive');
|
|
32
|
+
else {
|
|
33
|
+
const expires = Date.parse(status.subscription?.expires_at || '');
|
|
34
|
+
if (!Number.isFinite(expires) || expires - now <= 6 * 60 * 60 * 1000) issues.push('subscription_expiring');
|
|
35
|
+
}
|
|
36
|
+
return issues;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// RFC 9728 section 3.3: the metadata's resource must be identical to the resource identifier whose
|
|
40
|
+
// path was inserted into the well-known URL. Compare the whole configured value, not its origin.
|
|
41
|
+
export function metadataMatches(metadata, resource, issuer) {
|
|
42
|
+
return metadata?.resource === resource && Boolean(issuer) && listsIssuer(metadata, issuer);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function repositoryIdMatches(output, expected) {
|
|
46
|
+
try { const repo=JSON.parse(output); return Number.isSafeInteger(repo.id) && String(repo.id)===expected; }
|
|
47
|
+
catch { return false; }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function certificateExpiry() {
|
|
51
|
+
if (!resource) throw new Error('DALAN_RESOURCE_URL is required');
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const socket = tls.connect({ host: tlsHost, port: 443, servername: tlsHost, timeout: 10000 }, () => {
|
|
54
|
+
const expires = Date.parse(socket.getPeerCertificate().valid_to);
|
|
55
|
+
socket.end();
|
|
56
|
+
Number.isFinite(expires) ? resolve(expires) : reject(new Error('invalid certificate expiry'));
|
|
57
|
+
});
|
|
58
|
+
socket.on('timeout', () => socket.destroy(new Error('TLS timeout')));
|
|
59
|
+
socket.on('error', reject);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function probe() {
|
|
64
|
+
const issues = [];
|
|
65
|
+
try {
|
|
66
|
+
const cli = fileURLToPath(new URL('../bin/dalan.mjs', import.meta.url));
|
|
67
|
+
const output = execFileSync(process.execPath, [cli, 'status', '--json'], { encoding: 'utf8', timeout: 10000, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
68
|
+
issues.push(...assessStatus(JSON.parse(output)));
|
|
69
|
+
} catch { issues.push('status_unreachable'); }
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetchProbe('DALAN_SELFCHECK_RESOURCE', protectedResourceMetadataUrl(resource), { signal: AbortSignal.timeout(10000) });
|
|
73
|
+
if (!response.ok) throw new Error('metadata HTTP failure');
|
|
74
|
+
const metadata = await response.json();
|
|
75
|
+
if (!metadataMatches(metadata, resource, issuer)) throw new Error('metadata mismatch');
|
|
76
|
+
} catch (error) { issues.push(error.targetValidation ? error.message : 'oauth_metadata_unreachable'); }
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const expires = await certificateExpiry();
|
|
80
|
+
if (expires - Date.now() <= 14 * 24 * 60 * 60 * 1000) issues.push('tls_certificate_expiring');
|
|
81
|
+
} catch { issues.push('tls_certificate_invalid'); }
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const response = await fetchProbe('DALAN_SELFCHECK_ISSUER', appendPath(issuer, '/protocol/openid-connect/certs'), { signal: AbortSignal.timeout(10000) });
|
|
85
|
+
if (!response.ok || !(await response.json()).keys?.some(key => key.kty === 'RSA' && key.use !== 'enc')) throw new Error('JWKS unavailable');
|
|
86
|
+
} catch (error) { issues.push(error.targetValidation ? error.message : 'keycloak_jwks_unreachable'); }
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const repo = execFileSync('gh', ['api', `repos/${githubRepository}`], { encoding: 'utf8', timeout: 10000, stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
90
|
+
if (!repositoryIdMatches(repo, repositoryId)) throw new Error('GitHub identity mismatch');
|
|
91
|
+
} catch { issues.push('github_auth_unusable'); }
|
|
92
|
+
return issues;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function main() {
|
|
96
|
+
const missing = [
|
|
97
|
+
['DALAN_RESOURCE_URL or DALAN_SELFCHECK_RESOURCE', resource],
|
|
98
|
+
['DALAN_ISSUER_URL or DALAN_SELFCHECK_ISSUER', issuer],
|
|
99
|
+
['DALAN_SELFCHECK_TLS_HOST or DALAN_TLS_HOST', tlsHost],
|
|
100
|
+
['DALAN_GITHUB_REPOSITORY', githubRepository],
|
|
101
|
+
['DALAN_SELFCHECK_REPOSITORY_ID', repositoryId],
|
|
102
|
+
].filter(([, value]) => !value?.trim()).map(([name]) => name);
|
|
103
|
+
if (missing.length) throw new Error(`set ${missing.join(', ')}`);
|
|
104
|
+
endpoint('DALAN_SELFCHECK_RESOURCE', resource, {base:true});
|
|
105
|
+
endpoint('DALAN_SELFCHECK_ISSUER', issuer, {base:true});
|
|
106
|
+
hostname('DALAN_SELFCHECK_TLS_HOST', tlsHost);
|
|
107
|
+
// The TLS probe must examine the host that serves the resource; a different host would pass for the wrong certificate.
|
|
108
|
+
if (tlsHost.toLowerCase() !== new URL(resource).hostname.toLowerCase()) throw new Error('DALAN_SELFCHECK_TLS_HOST differs from the resource hostname; unset it to use the resource hostname');
|
|
109
|
+
if (!/^[1-9][0-9]*$/.test(repositoryId) || !Number.isSafeInteger(Number(repositoryId))) throw new Error('DALAN_SELFCHECK_REPOSITORY_ID must be a positive numeric repository ID');
|
|
110
|
+
process.umask(0o077);
|
|
111
|
+
const issues = await probe();
|
|
112
|
+
fs.mkdirSync(path.dirname(stateFile), { recursive: true, mode: 0o700 });
|
|
113
|
+
let previous = [];
|
|
114
|
+
try { previous = JSON.parse(fs.readFileSync(stateFile, 'utf8')).issues; } catch {}
|
|
115
|
+
if (!Array.isArray(previous)) previous = [];
|
|
116
|
+
const changed = issues.some(issue => !previous.includes(issue));
|
|
117
|
+
if (issues.length && changed) {
|
|
118
|
+
await publishAlert('dot-bridge daily check failed', issues.join(', '), () => {}, { requirePublisher: true });
|
|
119
|
+
}
|
|
120
|
+
fs.writeFileSync(stateFile, JSON.stringify({ checked_at: new Date().toISOString(), issues }) + '\n', { mode: 0o600 });
|
|
121
|
+
if (issues.length) {
|
|
122
|
+
console.error('dot-bridge daily check:', issues.join(', '));
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
} else console.log('dot-bridge daily check: healthy');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
|
|
128
|
+
main().catch(async error => {
|
|
129
|
+
// A check that cannot run must not pass in silence: say so through the alert path (setting names only, never values).
|
|
130
|
+
console.error('dot-bridge daily check could not run:', error.message);
|
|
131
|
+
process.exitCode = 1;
|
|
132
|
+
try { await publishAlert('dot-bridge daily check could not run', error.message, () => {}, { requirePublisher: true }); }
|
|
133
|
+
catch (alertError) { console.error('dot-bridge daily check could not alert:', alertError.message); }
|
|
134
|
+
});
|
|
135
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Run against a live `dalan try --public` trial before adding the connector in claude.ai or ChatGPT:
|
|
3
|
+
// node scripts/dalan-try-selfcheck.mjs --home <trial home> [--client claude|chatgpt] [--wait 300]
|
|
4
|
+
// The trial's authorization server must be on its public origin: a constraint of the trial, not of OAuth.
|
|
5
|
+
// It acts as a real OAuth client and waits for you to approve the connection (y) in the trial terminal.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { runSelfCheck } from '../src/try-selfcheck.mjs';
|
|
9
|
+
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
const option = name => { const i = args.indexOf(name); return i >= 0 ? args[i + 1] : undefined; };
|
|
12
|
+
const home = option('--home'), client = option('--client') ?? 'claude', wait = Number(option('--wait') ?? 300);
|
|
13
|
+
let url = process.env.DALAN_TRY_URL;
|
|
14
|
+
if (!url && home) { try { url = fs.readFileSync(path.join(home, 'resource-url'), 'utf8').trim(); } catch { /* reported below */ } }
|
|
15
|
+
if (!url || !['claude', 'chatgpt'].includes(client)) {
|
|
16
|
+
process.stderr.write('usage: node scripts/dalan-try-selfcheck.mjs --home <trial home> [--client claude|chatgpt] [--wait seconds]\n(or set DALAN_TRY_URL to the trial\'s MCP URL; it is a credential, so it is never taken from an argument)\n');
|
|
17
|
+
process.exit(2);
|
|
18
|
+
}
|
|
19
|
+
const controller = new AbortController();
|
|
20
|
+
process.once('SIGINT', () => controller.abort());
|
|
21
|
+
process.once('SIGTERM', () => controller.abort());
|
|
22
|
+
try {
|
|
23
|
+
const { ok } = await runSelfCheck({ url, client, approveWaitMs: wait * 1000, signal: controller.signal, say: line => process.stdout.write(`${line}\n`) });
|
|
24
|
+
process.exit(ok ? 0 : 1);
|
|
25
|
+
} catch {
|
|
26
|
+
// The error text can hold the credential URL, so none of it is printed.
|
|
27
|
+
process.stdout.write('FAIL self-check: stopped before it finished (cancelled or an unexpected error)\nRESULT FAIL\n');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|