@saturn-universe/runtime-host 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/LICENSE +661 -0
  2. package/dist/builtin-plugins/saturn-plugin-ctf/README.md +13 -0
  3. package/dist/builtin-plugins/saturn-plugin-ctf/index.mjs +1473 -0
  4. package/dist/builtin-plugins/saturn-plugin-ctf/package.json +10 -0
  5. package/dist/builtin-plugins/saturn-plugin-ctf/src/board.mjs +321 -0
  6. package/dist/builtin-plugins/saturn-plugin-ctf/src/ledger.mjs +1143 -0
  7. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/ctfd.mjs +154 -0
  8. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/ctfplus.mjs +769 -0
  9. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/gzctf.mjs +130 -0
  10. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/http.mjs +336 -0
  11. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/index.mjs +133 -0
  12. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/lease.mjs +153 -0
  13. package/dist/builtin-plugins/saturn-plugin-ctf/src/server.mjs +336 -0
  14. package/dist/builtin-plugins/saturn-plugin-ctf/src/view.mjs +714 -0
  15. package/dist/command-dispatch.d.ts +10 -0
  16. package/dist/command-dispatch.js +65 -0
  17. package/dist/completion-judge.d.ts +10 -0
  18. package/dist/completion-judge.js +156 -0
  19. package/dist/composition.d.ts +108 -0
  20. package/dist/composition.js +1180 -0
  21. package/dist/configuration.d.ts +49 -0
  22. package/dist/configuration.js +51 -0
  23. package/dist/context-extensions.d.ts +681 -0
  24. package/dist/context-extensions.js +289 -0
  25. package/dist/cordis/context-core-plugin.d.ts +35 -0
  26. package/dist/cordis/context-core-plugin.js +296 -0
  27. package/dist/cordis/env-probe-plugin.d.ts +27 -0
  28. package/dist/cordis/env-probe-plugin.js +114 -0
  29. package/dist/cordis/host-context.d.ts +65 -0
  30. package/dist/cordis/host-context.js +199 -0
  31. package/dist/cordis/model-responses-plugin.d.ts +81 -0
  32. package/dist/cordis/model-responses-plugin.js +209 -0
  33. package/dist/cordis/plugin-contributions.d.ts +47 -0
  34. package/dist/cordis/plugin-contributions.js +119 -0
  35. package/dist/cordis/plugin-lifecycle.d.ts +57 -0
  36. package/dist/cordis/plugin-lifecycle.js +222 -0
  37. package/dist/cordis/plugin-loader.d.ts +18 -0
  38. package/dist/cordis/plugin-loader.js +310 -0
  39. package/dist/cordis/plugin-sdk-adapter.d.ts +17 -0
  40. package/dist/cordis/plugin-sdk-adapter.js +283 -0
  41. package/dist/cordis/required-host-plugin.d.ts +6 -0
  42. package/dist/cordis/required-host-plugin.js +1 -0
  43. package/dist/cordis/runtime-hooks-plugin.d.ts +23 -0
  44. package/dist/cordis/runtime-hooks-plugin.js +103 -0
  45. package/dist/cordis/sandbox-plugin.d.ts +18 -0
  46. package/dist/cordis/sandbox-plugin.js +21 -0
  47. package/dist/cordis/scoped-layers.d.ts +63 -0
  48. package/dist/cordis/scoped-layers.js +170 -0
  49. package/dist/cordis/tools/builtin-agent-tools-plugin.d.ts +11 -0
  50. package/dist/cordis/tools/builtin-agent-tools-plugin.js +171 -0
  51. package/dist/cordis/tools/index.d.ts +17 -0
  52. package/dist/cordis/tools/index.js +40 -0
  53. package/dist/cordis/tools/mcp-tools-plugin.d.ts +7 -0
  54. package/dist/cordis/tools/mcp-tools-plugin.js +116 -0
  55. package/dist/cordis/tools/process-manager-plugin.d.ts +11 -0
  56. package/dist/cordis/tools/process-manager-plugin.js +39 -0
  57. package/dist/cordis/tools/sandbox-target-tools-plugin.d.ts +13 -0
  58. package/dist/cordis/tools/sandbox-target-tools-plugin.js +255 -0
  59. package/dist/cordis/tools/tool-guidance.d.ts +4 -0
  60. package/dist/cordis/tools/tool-guidance.js +30 -0
  61. package/dist/cordis/tools/tools-core-plugin.d.ts +128 -0
  62. package/dist/cordis/tools/tools-core-plugin.js +486 -0
  63. package/dist/cordis/tools/web-fetch.d.ts +17 -0
  64. package/dist/cordis/tools/web-fetch.js +529 -0
  65. package/dist/cordis/tools/web-search-tools-plugin.d.ts +10 -0
  66. package/dist/cordis/tools/web-search-tools-plugin.js +191 -0
  67. package/dist/cordis/tools/workspace-tools-plugin.d.ts +8 -0
  68. package/dist/cordis/tools/workspace-tools-plugin.js +145 -0
  69. package/dist/env-probe.d.ts +8 -0
  70. package/dist/env-probe.js +172 -0
  71. package/dist/host-configuration.d.ts +27 -0
  72. package/dist/host-configuration.js +185 -0
  73. package/dist/host-tools.d.ts +19 -0
  74. package/dist/host-tools.js +30 -0
  75. package/dist/index.d.ts +2 -0
  76. package/dist/index.js +140 -0
  77. package/dist/ipc.d.ts +24 -0
  78. package/dist/ipc.js +162 -0
  79. package/dist/logger.d.ts +11 -0
  80. package/dist/logger.js +84 -0
  81. package/dist/mcp-configuration.d.ts +17 -0
  82. package/dist/mcp-configuration.js +50 -0
  83. package/dist/modes.d.ts +27 -0
  84. package/dist/modes.js +478 -0
  85. package/dist/ownership.d.ts +7 -0
  86. package/dist/ownership.js +100 -0
  87. package/dist/plugin-configuration.d.ts +9 -0
  88. package/dist/plugin-configuration.js +21 -0
  89. package/dist/plugin-tool-grants.d.ts +18 -0
  90. package/dist/plugin-tool-grants.js +21 -0
  91. package/dist/process-workspaces.d.ts +4 -0
  92. package/dist/process-workspaces.js +28 -0
  93. package/dist/progress.d.ts +30 -0
  94. package/dist/progress.js +699 -0
  95. package/dist/provider-catalog.d.ts +754 -0
  96. package/dist/provider-catalog.js +472 -0
  97. package/dist/run-budget.d.ts +24 -0
  98. package/dist/run-budget.js +47 -0
  99. package/dist/run-checkpoint.d.ts +2 -0
  100. package/dist/run-checkpoint.js +52 -0
  101. package/dist/sandbox-manager.d.ts +111 -0
  102. package/dist/sandbox-manager.js +1519 -0
  103. package/dist/session-paths.d.ts +15 -0
  104. package/dist/session-paths.js +40 -0
  105. package/dist/side-question.d.ts +14 -0
  106. package/dist/side-question.js +89 -0
  107. package/dist/skills-runtime.d.ts +13 -0
  108. package/dist/skills-runtime.js +243 -0
  109. package/dist/token-estimator.d.ts +3 -0
  110. package/dist/token-estimator.js +73 -0
  111. package/dist/tool-result.d.ts +2 -0
  112. package/dist/tool-result.js +91 -0
  113. package/dist/user-config.d.ts +23 -0
  114. package/dist/user-config.js +36 -0
  115. package/package.json +28 -3
  116. package/README.md +0 -3
@@ -0,0 +1,154 @@
1
+ import { fail } from '../board.mjs';
2
+ import {
3
+ checkCaptcha,
4
+ jsonResponse,
5
+ normalizeContainerInfo,
6
+ numericId,
7
+ optionalJsonResponse,
8
+ } from './http.mjs';
9
+
10
+ export function ctfd(transport, auth) {
11
+ const headers = auth.token ? { Authorization: `Token ${auth.token}` } : {};
12
+ const challenges = 'api/v1/challenges';
13
+
14
+ async function data(resource, signal) {
15
+ const envelope = await jsonResponse(await transport.request(resource, { headers, signal }));
16
+ if (!envelope?.success || envelope.data == null)
17
+ throw fail('PLATFORM_INVALID_RESPONSE', 'CTFd returned an invalid response.');
18
+ return envelope.data;
19
+ }
20
+
21
+ return {
22
+ async connect(signal) {
23
+ if (auth.username) {
24
+ const form = await (await transport.request('login', { signal })).text();
25
+ checkCaptcha(form);
26
+ const nonce = (form.match(/<input\b[^>]*>/gi) ?? [])
27
+ .map((tag) =>
28
+ Object.fromEntries(
29
+ [...tag.matchAll(/([\w-]+)\s*=\s*["']([^"']*)["']/g)].map((match) => [
30
+ match[1].toLowerCase(),
31
+ match[2],
32
+ ]),
33
+ ),
34
+ )
35
+ .find((input) => input.name === 'nonce')?.value;
36
+ if (!nonce) throw fail('PLATFORM_AUTH_FAILED', 'CTFd login form has no nonce.');
37
+ const response = await transport.request('login', {
38
+ method: 'POST',
39
+ body: new URLSearchParams({ name: auth.username, password: auth.password, nonce }),
40
+ signal,
41
+ allowLoginRedirect: true,
42
+ });
43
+ if (response.ok) {
44
+ checkCaptcha(await response.text(), response.status);
45
+ throw fail('PLATFORM_AUTH_FAILED', 'CTFd did not accept those credentials.');
46
+ }
47
+ transport.requireSession();
48
+ }
49
+ await data(challenges, signal);
50
+ },
51
+ async list(signal) {
52
+ const list = await data(challenges, signal);
53
+ if (!Array.isArray(list)) throw fail('PLATFORM_INVALID_RESPONSE', 'Expected a CTFd challenge list.');
54
+ const items = [];
55
+ for (const item of list) {
56
+ const remoteId = numericId(item.id);
57
+ const detail = await data(`${challenges}/${remoteId}`, signal);
58
+ const solves = detail.solves ?? item.solves;
59
+ items.push({
60
+ id: `ctfd-${remoteId}`,
61
+ remoteId,
62
+ title: detail.name,
63
+ description: detail.description,
64
+ category: detail.category,
65
+ points: detail.value,
66
+ ...(typeof solves === 'number' && Number.isSafeInteger(solves) && solves >= 0 ? { solves } : {}),
67
+ ...(detail.solved_by_me || item.solved_by_me ? { status: 'solved' } : {}),
68
+ resources: (detail.files ?? []).map((file) =>
69
+ transport.attachment(typeof file === 'string' ? file : file.url),
70
+ ),
71
+ });
72
+ }
73
+ return items;
74
+ },
75
+ async instance(remoteId, action, signal) {
76
+ const id = numericId(remoteId);
77
+ const challengePayload = JSON.stringify({ challenge_id: Number(id) });
78
+ const candidates =
79
+ action === 'start'
80
+ ? [
81
+ { path: 'api/v1/containers', method: 'POST', body: challengePayload },
82
+ { path: `${challenges}/${id}/container`, method: 'POST', body: '{}' },
83
+ ]
84
+ : action === 'renew'
85
+ ? [
86
+ { path: 'api/v1/containers/renew', method: 'POST', body: challengePayload },
87
+ { path: `${challenges}/${id}/container/renew`, method: 'POST', body: '{}' },
88
+ ]
89
+ : action === 'stop'
90
+ ? [
91
+ { path: 'api/v1/containers', method: 'DELETE', body: challengePayload },
92
+ { path: `${challenges}/${id}/container`, method: 'DELETE' },
93
+ ]
94
+ : null;
95
+ if (!candidates) throw fail('INVALID_INPUT', 'Unsupported instance action.');
96
+
97
+ for (const candidate of candidates) {
98
+ try {
99
+ const response = await transport.request(candidate.path, {
100
+ method: candidate.method,
101
+ headers: candidate.body ? { ...headers, 'Content-Type': 'application/json' } : headers,
102
+ ...(candidate.body ? { body: candidate.body } : {}),
103
+ signal,
104
+ });
105
+ const payload = await optionalJsonResponse(response);
106
+ if (payload && typeof payload === 'object' && 'success' in payload && payload.success === false) {
107
+ throw fail('PLATFORM_INVALID_RESPONSE', 'CTFd returned an invalid container response.');
108
+ }
109
+ return normalizeContainerInfo(payload, action);
110
+ } catch (error) {
111
+ if (error.code === 'PLATFORM_HTTP_ERROR' && [404, 405, 501].includes(error.status)) {
112
+ continue;
113
+ }
114
+ throw error;
115
+ }
116
+ }
117
+
118
+ return {
119
+ supported: false,
120
+ code: 'PLATFORM_UNSUPPORTED',
121
+ platform: 'ctfd',
122
+ action,
123
+ message: 'The connected CTFd instance does not expose a supported dynamic container endpoint.',
124
+ };
125
+ },
126
+ async submit(remoteId, answer, signal) {
127
+ const id = numericId(remoteId);
128
+ const response = await transport.request(`${challenges}/attempt`, {
129
+ method: 'POST',
130
+ headers: { ...headers, 'Content-Type': 'application/json' },
131
+ body: JSON.stringify({ challenge_id: Number(id), submission: answer }),
132
+ signal,
133
+ });
134
+ const envelope = await jsonResponse(response);
135
+ if (!envelope?.success || !envelope.data || typeof envelope.data !== 'object') {
136
+ throw fail('PLATFORM_INVALID_RESPONSE', 'CTFd returned an invalid submission response.');
137
+ }
138
+ const message =
139
+ typeof envelope.data.message === 'string' && envelope.data.message.trim()
140
+ ? envelope.data.message.trim()
141
+ : undefined;
142
+ const rawStatus = String(envelope.data.status ?? '').trim().toLowerCase();
143
+ if (rawStatus === 'correct') return { status: 'correct', ...(message ? { message } : {}) };
144
+ if (rawStatus === 'already_solved')
145
+ return { status: 'already_solved', ...(message ? { message } : {}) };
146
+ if (rawStatus === 'incorrect') return { status: 'incorrect', ...(message ? { message } : {}) };
147
+ if (['ratelimited', 'rate_limited', 'paused'].includes(rawStatus)) {
148
+ return { status: 'rate_limited', ...(message ? { message } : {}) };
149
+ }
150
+ throw fail('PLATFORM_INVALID_RESPONSE', 'Unexpected CTFd submission response.');
151
+ },
152
+ download: (resource, signal) => transport.download(resource, headers, signal),
153
+ };
154
+ }