bailinghub 0.3.4 → 0.5.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.
Files changed (169) hide show
  1. package/.gitignore +5 -0
  2. package/README.en.md +6 -1
  3. package/README.md +6 -0
  4. package/SECURITY.md +11 -0
  5. package/docker-compose.images.yml +2 -2
  6. package/docs/AGENT_AUTH_API.en.md +175 -0
  7. package/docs/AGENT_AUTH_API.md +190 -0
  8. package/docs/AGENT_CLIENT_QUICKSTART.en.md +212 -0
  9. package/docs/AGENT_CLIENT_QUICKSTART.md +206 -0
  10. package/docs/AGENT_CLIENT_RUNTIME_API.en.md +157 -0
  11. package/docs/AGENT_CLIENT_RUNTIME_API.md +107 -0
  12. package/docs/CHANGELOG.en.md +59 -1
  13. package/docs/CHANGELOG.md +27 -1
  14. package/docs/COMPATIBILITY.en.md +25 -0
  15. package/docs/CONTRACT.en.md +79 -8
  16. package/docs/CONTRACT.md +36 -6
  17. package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
  18. package/docs/INDEPENDENT_VALIDATION.md +4 -4
  19. package/docs/QUICKSTART.en.md +6 -0
  20. package/docs/QUICKSTART.md +1 -1
  21. package/docs/README.en.md +8 -0
  22. package/docs/README.md +8 -0
  23. package/docs/RELEASE_NOTES_v0.4.0.en.md +39 -0
  24. package/docs/RELEASE_NOTES_v0.4.0.md +39 -0
  25. package/docs/RELEASE_NOTES_v0.5.0.en.md +41 -0
  26. package/docs/RELEASE_NOTES_v0.5.0.md +41 -0
  27. package/docs/STREAMING.en.md +32 -0
  28. package/docs/STREAMING.md +8 -2
  29. package/docs/WIDGET_RENDERERS.en.md +123 -6
  30. package/docs/WIDGET_RENDERERS.md +75 -6
  31. package/docs/user-guide/console-map.en.md +1 -2
  32. package/docs/user-guide/console-map.md +2 -2
  33. package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +9 -0
  34. package/package.json +3 -2
  35. package/schemas/config/chat-entry.schema.json +2 -1
  36. package/schemas/config/client.schema.json +7 -0
  37. package/schemas/config/common.schema.json +30 -0
  38. package/schemas/config/route.schema.json +11 -0
  39. package/scripts/check-doc-links.mjs +1 -0
  40. package/scripts/check-image-tags.sh +1 -1
  41. package/scripts/check-release-consistency.test.mjs +5 -5
  42. package/scripts/e2e-console.mjs +144 -0
  43. package/scripts/export-oss.mjs +5 -12
  44. package/scripts/install.sh +1 -1
  45. package/scripts/public-content-denylist.mjs +82 -0
  46. package/scripts/public-content-denylist.test.mjs +53 -0
  47. package/scripts/publish-images.sh +1 -1
  48. package/scripts/release-audit.mjs +8 -12
  49. package/scripts/sdk-runtime-test.mjs +171 -7
  50. package/scripts/security-scan.mjs +8 -5
  51. package/scripts/validate-examples.mjs +3 -1
  52. package/scripts/verify-github-repo.mjs +7 -11
  53. package/scripts/verify-oss-export.mjs +6 -12
  54. package/scripts/widget-renderer-test.mjs +244 -16
  55. package/sdk/php/README.md +27 -1
  56. package/sdk/php/src/AgentAuth.php +78 -0
  57. package/sdk/php/src/HubClient.php +3 -0
  58. package/sdk/php7/README.md +32 -2
  59. package/sdk/php7/src/AgentAuth.php +77 -0
  60. package/sdk/php7/src/HubClient.php +3 -0
  61. package/sql/055_agent_auth.sql +72 -0
  62. package/sql/056_agent_client_runtime.sql +60 -0
  63. package/src/adapters/channels/wecom-api.ts +1 -1
  64. package/src/app/agent-client-runtime.test.ts +221 -0
  65. package/src/app/agent-client-runtime.ts +408 -0
  66. package/src/app/agent-tool-invocations.test.ts +462 -0
  67. package/src/app/agent-tool-invocations.ts +795 -0
  68. package/src/app/agent-tool-job.test.ts +62 -0
  69. package/src/app/agent-tool-job.ts +41 -0
  70. package/src/app/auth.ts +2 -1
  71. package/src/app/kernel.ts +2 -0
  72. package/src/app/runtime-context.ts +8 -0
  73. package/src/app/tool-approvals.ts +5 -1
  74. package/src/app/tool-assembly.ts +19 -1
  75. package/src/app/tool-context.ts +2 -1
  76. package/src/core/config/config-codec.ts +2 -1
  77. package/src/core/config/config-models.test.ts +28 -1
  78. package/src/core/config/config-models.ts +46 -3
  79. package/src/core/config/config-schema.test.ts +8 -0
  80. package/src/core/config/route-config.test.ts +15 -0
  81. package/src/core/config/route-config.ts +36 -0
  82. package/src/core/config/tools-config.test.ts +58 -1
  83. package/src/core/config/tools-config.ts +84 -0
  84. package/src/core/contracts/tools.ts +162 -29
  85. package/src/core/contracts/types.ts +38 -1
  86. package/src/core/platform/chat-form.test.ts +147 -0
  87. package/src/core/platform/chat-form.ts +402 -0
  88. package/src/core/platform/version.ts +1 -1
  89. package/src/core/runtime/agent-client-trace.test.ts +154 -0
  90. package/src/core/runtime/agent-client-trace.ts +288 -0
  91. package/src/core/runtime/execution-runtime.test.ts +61 -0
  92. package/src/core/runtime/execution-runtime.ts +17 -0
  93. package/src/core/runtime/launch-runtime.ts +13 -0
  94. package/src/core/runtime/trace-runtime.test.ts +18 -1
  95. package/src/core/runtime/trace-runtime.ts +28 -3
  96. package/src/core/state/state-codec.ts +2 -0
  97. package/src/infrastructure/config/config-agent-auth-repository.test.ts +147 -0
  98. package/src/infrastructure/config/config-agent-auth-repository.ts +356 -0
  99. package/src/infrastructure/config/config-agent-client-runtime-repository.ts +253 -0
  100. package/src/infrastructure/config/config-approval-ledger.test.ts +32 -0
  101. package/src/infrastructure/config/config-approval-ledger.ts +16 -0
  102. package/src/infrastructure/config/config-client-repository.ts +3 -3
  103. package/src/infrastructure/config/config-conversation-ledger.test.ts +69 -0
  104. package/src/infrastructure/config/config-conversation-ledger.ts +8 -7
  105. package/src/infrastructure/config/config-observability-ledger.test.ts +50 -0
  106. package/src/infrastructure/config/config-observability-ledger.ts +65 -10
  107. package/src/infrastructure/config/config-route-repository.ts +4 -3
  108. package/src/infrastructure/config/configstore.ts +14 -3
  109. package/src/infrastructure/state/state-mysql.ts +2 -2
  110. package/src/kernel-api/v1/contracts.ts +8 -0
  111. package/src/routes/admin-runtime.test.ts +214 -0
  112. package/src/routes/admin-runtime.ts +82 -2
  113. package/src/routes/agent-api.test.ts +379 -0
  114. package/src/routes/agent-api.ts +251 -0
  115. package/src/routes/agent-auth.test.ts +276 -0
  116. package/src/routes/agent-auth.ts +395 -0
  117. package/src/routes/approvals.ts +4 -1
  118. package/src/routes/chat.test.ts +319 -7
  119. package/src/routes/chat.ts +166 -21
  120. package/src/routes/critical-routes.test.ts +235 -1
  121. package/src/routes/private-default.ts +2 -1
  122. package/src/routes/private.ts +16 -1
  123. package/src/routes/run.ts +79 -13
  124. package/web/connect/bailing-connect-php.tgz +0 -0
  125. package/web/connect/bailing-connect-php7.tgz +0 -0
  126. package/web/console/assets/{Accounts-CAwrtBiS.js → Accounts-D4RRm5D1.js} +1 -1
  127. package/web/console/assets/{Approvals-C2BZ86T3.js → Approvals-CsTTKb8o.js} +1 -1
  128. package/web/console/assets/{Audit-B-E4Y_Up.js → Audit-BzvZ7JZw.js} +1 -1
  129. package/web/console/assets/{BrandLockup-C18u8Lx5.js → BrandLockup-CYcA93wh.js} +1 -1
  130. package/web/console/assets/{Channels-DTy8ylH-.js → Channels-DRQZggqM.js} +1 -1
  131. package/web/console/assets/ChatEntries-BUB7BWKU.js +7 -0
  132. package/web/console/assets/ChatEntries-DsYtcXN6.css +1 -0
  133. package/web/console/assets/Clients-CQ_MonGL.css +1 -0
  134. package/web/console/assets/Clients-HhCyrxfz.js +3 -0
  135. package/web/console/assets/{Cost-2SSYs1AT.js → Cost-BZgFf1yM.js} +1 -1
  136. package/web/console/assets/{Credentials-B79LtxCE.js → Credentials-BTe2Q07j.js} +1 -1
  137. package/web/console/assets/{Diagnostics-BakcRYvb.js → Diagnostics-WL-buYli.js} +1 -1
  138. package/web/console/assets/{Executors-BXoyo28u.js → Executors-CGZ-7Xmp.js} +1 -1
  139. package/web/console/assets/{Kb-ISbzquab.js → Kb-VVw8oGsT.js} +1 -1
  140. package/web/console/assets/{Login-Dlu6Wgcf.js → Login-rwvmBBPl.js} +1 -1
  141. package/web/console/assets/{Projects-DFzmtnqg.js → Projects-CexaCEY1.js} +1 -1
  142. package/web/console/assets/Routes-B9ZHbQAp.js +124 -0
  143. package/web/console/assets/Routes-BbkFpi6Y.css +1 -0
  144. package/web/console/assets/Runs-4zDD9VOC.css +1 -0
  145. package/web/console/assets/Runs-BzFNPTwD.js +3 -0
  146. package/web/console/assets/{Setup-CrBAV-b9.js → Setup-Djh5yadQ.js} +1 -1
  147. package/web/console/assets/{Shell-B1a8DvXQ.js → Shell-kn763smL.js} +1 -1
  148. package/web/console/assets/{StorageBuckets-BRfL_eHb.js → StorageBuckets-CQBR41W1.js} +1 -1
  149. package/web/console/assets/{SystemSettings-CyirVLbq.js → SystemSettings-DgnopekD.js} +1 -1
  150. package/web/console/assets/{SystemStatus-DZ_OR7sk.js → SystemStatus-Bj8-kPt2.js} +1 -1
  151. package/web/console/assets/{Targets-CtIMa66c.js → Targets-BAfCt_nH.js} +1 -1
  152. package/web/console/assets/{Tools-BfDZHt01.js → Tools-xjd0NZdE.js} +1 -1
  153. package/web/console/assets/{index-DBiByFiO.js → index-DfJA7iJS.js} +2 -2
  154. package/web/console/assets/{request-DY2cxQqZ.js → request-DkNPOweH.js} +1 -1
  155. package/web/console/assets/{schema-6mCQ7rR5.js → schema-CgPWAu1_.js} +1 -1
  156. package/web/console/index.html +1 -1
  157. package/web/widget/widget.js +493 -14
  158. package/web-admin/src/pages/ChatEntries.vue +18 -6
  159. package/web-admin/src/pages/Clients.vue +11 -3
  160. package/web-admin/src/pages/Routes.vue +282 -16
  161. package/web-admin/src/pages/Runs.vue +159 -38
  162. package/web/console/assets/ChatEntries-9xbRiQov.css +0 -1
  163. package/web/console/assets/ChatEntries-DvD-4IeE.js +0 -7
  164. package/web/console/assets/Clients--D7NQJKk.css +0 -1
  165. package/web/console/assets/Clients-DWs9JFr0.js +0 -3
  166. package/web/console/assets/Routes-B-hm9HGY.js +0 -124
  167. package/web/console/assets/Routes-DWGQN5Pv.css +0 -1
  168. package/web/console/assets/Runs-CUtSsPW-.css +0 -1
  169. package/web/console/assets/Runs-hMRu1im3.js +0 -3
@@ -1,4 +1,5 @@
1
- import { spawnSync } from 'node:child_process';
1
+ import { spawn, spawnSync } from 'node:child_process';
2
+ import { createServer } from 'node:http';
2
3
  import { dirname, resolve } from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
4
5
  import {
@@ -33,6 +34,27 @@ function run(cmd, args, input) {
33
34
  return { status: r.status, stdout: r.stdout.trim(), stderr: r.stderr.trim() };
34
35
  }
35
36
 
37
+ function runAsync(cmd, args, input) {
38
+ return new Promise((resolveRun) => {
39
+ const child = spawn(cmd, args, { cwd: root, stdio: ['pipe', 'pipe', 'pipe'] });
40
+ let stdout = '';
41
+ let stderr = '';
42
+ child.stdout.setEncoding('utf8');
43
+ child.stderr.setEncoding('utf8');
44
+ child.stdout.on('data', (chunk) => { stdout += chunk; });
45
+ child.stderr.on('data', (chunk) => { stderr += chunk; });
46
+ child.on('error', (error) => resolveRun({ status: null, stdout: stdout.trim(), stderr: String(error) }));
47
+ child.on('close', (status) => resolveRun({ status, stdout: stdout.trim(), stderr: stderr.trim() }));
48
+ child.stdin.end(input ?? '');
49
+ });
50
+ }
51
+
52
+ async function closeServer(server) {
53
+ await new Promise((resolveClose, rejectClose) => {
54
+ server.close((error) => error ? rejectClose(error) : resolveClose());
55
+ });
56
+ }
57
+
36
58
  console.log('— SDK runtime helpers');
37
59
  ok('Node signTicket deterministic vector', signTicket('secret', 'tenant:user', { expiresAt: 2_000_000_000 }) === expectedTicket);
38
60
 
@@ -62,9 +84,11 @@ ok('Python HubClient is exported', py.status === 0 && py.stdout.split('\n')[1] =
62
84
  const php = run('php', ['-r', `
63
85
  require '${root}/sdk/php/src/Ticket.php';
64
86
  require '${root}/sdk/php/src/HubClient.php';
87
+ require '${root}/sdk/php/src/AgentAuth.php';
65
88
  require '${root}/sdk/php/src/SpecServer.php';
66
89
  echo Bailing\\Connect\\Ticket::sign('secret', 'tenant:user', 7200, 2000000000), "\\n";
67
90
  echo class_exists('Bailing\\\\Connect\\\\HubClient') ? 'HubClient' : 'missing', "\\n";
91
+ echo class_exists('Bailing\\\\Connect\\\\AgentAuth') ? 'AgentAuth' : 'missing', "\\n";
68
92
  $protectedHeaders = Bailing\\Connect\\SpecServer::responseHeaders('tool-secret');
69
93
  echo isset($protectedHeaders['Cache-Control']) ? $protectedHeaders['Cache-Control'] : 'missing', "\\n";
70
94
  list($publicStatus, $publicBody) = Bailing\\Connect\\SpecServer::handlePublic('{"ok":true}', 'GET', '/tools.json');
@@ -74,16 +98,19 @@ echo ($legacyStatus === 200 && $legacyBody === '{"ok":true}') ? 'legacy-null' :
74
98
  `]);
75
99
  ok('PHP sign ticket deterministic vector', php.status === 0 && php.stdout.split('\n')[0] === expectedTicket, php.stderr || php.stdout);
76
100
  ok('PHP HubClient is exported', php.status === 0 && php.stdout.split('\n')[1] === 'HubClient', php.stderr || php.stdout);
77
- ok('PHP protected spec response is private/no-store', php.status === 0 && php.stdout.split('\n')[2] === 'private, no-store', php.stderr || php.stdout);
78
- ok('PHP explicit public spec helper works', php.status === 0 && php.stdout.split('\n')[3] === 'public-helper', php.stderr || php.stdout);
79
- ok('PHP legacy null-public signature remains compatible', php.status === 0 && php.stdout.split('\n')[4] === 'legacy-null', php.stderr || php.stdout);
101
+ ok('PHP AgentAuth is exported', php.status === 0 && php.stdout.split('\n')[2] === 'AgentAuth', php.stderr || php.stdout);
102
+ ok('PHP protected spec response is private/no-store', php.status === 0 && php.stdout.split('\n')[3] === 'private, no-store', php.stderr || php.stdout);
103
+ ok('PHP explicit public spec helper works', php.status === 0 && php.stdout.split('\n')[4] === 'public-helper', php.stderr || php.stdout);
104
+ ok('PHP legacy null-public signature remains compatible', php.status === 0 && php.stdout.split('\n')[5] === 'legacy-null', php.stderr || php.stdout);
80
105
 
81
106
  const php7 = run('php', ['-r', `
82
107
  require '${root}/sdk/php7/src/Ticket.php';
83
108
  require '${root}/sdk/php7/src/HubClient.php';
109
+ require '${root}/sdk/php7/src/AgentAuth.php';
84
110
  require '${root}/sdk/php7/src/SpecServer.php';
85
111
  echo Bailing\\Connect\\Ticket::sign('secret', 'tenant:user', 7200, 2000000000), "\\n";
86
112
  echo class_exists('Bailing\\\\Connect\\\\HubClient') ? 'HubClient' : 'missing', "\\n";
113
+ echo class_exists('Bailing\\\\Connect\\\\AgentAuth') ? 'AgentAuth' : 'missing', "\\n";
87
114
  $protectedHeaders = Bailing\\Connect\\SpecServer::responseHeaders('tool-secret');
88
115
  echo isset($protectedHeaders['Cache-Control']) ? $protectedHeaders['Cache-Control'] : 'missing', "\\n";
89
116
  list($publicStatus, $publicBody) = Bailing\\Connect\\SpecServer::handlePublic('{"ok":true}', 'GET', '/tools.json');
@@ -93,9 +120,146 @@ echo ($legacyStatus === 200 && $legacyBody === '{"ok":true}') ? 'legacy-null' :
93
120
  `]);
94
121
  ok('PHP7 sign ticket deterministic vector', php7.status === 0 && php7.stdout.split('\n')[0] === expectedTicket, php7.stderr || php7.stdout);
95
122
  ok('PHP7 HubClient is exported', php7.status === 0 && php7.stdout.split('\n')[1] === 'HubClient', php7.stderr || php7.stdout);
96
- ok('PHP7 protected spec response is private/no-store', php7.status === 0 && php7.stdout.split('\n')[2] === 'private, no-store', php7.stderr || php7.stdout);
97
- ok('PHP7 explicit public spec helper works', php7.status === 0 && php7.stdout.split('\n')[3] === 'public-helper', php7.stderr || php7.stdout);
98
- ok('PHP7 legacy null-public signature remains compatible', php7.status === 0 && php7.stdout.split('\n')[4] === 'legacy-null', php7.stderr || php7.stdout);
123
+ ok('PHP7 AgentAuth is exported', php7.status === 0 && php7.stdout.split('\n')[2] === 'AgentAuth', php7.stderr || php7.stdout);
124
+ ok('PHP7 protected spec response is private/no-store', php7.status === 0 && php7.stdout.split('\n')[3] === 'private, no-store', php7.stderr || php7.stdout);
125
+ ok('PHP7 explicit public spec helper works', php7.status === 0 && php7.stdout.split('\n')[4] === 'public-helper', php7.stderr || php7.stdout);
126
+ ok('PHP7 legacy null-public signature remains compatible', php7.status === 0 && php7.stdout.split('\n')[5] === 'legacy-null', php7.stderr || php7.stdout);
127
+
128
+ const authorizationId = '11111111-1111-4111-8111-111111111111';
129
+ const sessionId = '22222222-2222-4222-8222-222222222222';
130
+ const agentAuthRequests = [];
131
+ const agentAuthServer = createServer(async (req, res) => {
132
+ let body = '';
133
+ for await (const chunk of req) body += chunk;
134
+ agentAuthRequests.push({
135
+ method: req.method,
136
+ url: req.url,
137
+ authorization: req.headers.authorization,
138
+ contentType: req.headers['content-type'],
139
+ body,
140
+ });
141
+ res.setHeader('Content-Type', 'application/json');
142
+ if (req.url === '/redirect') {
143
+ res.statusCode = 302;
144
+ res.setHeader('Location', '/agent-auth-leak');
145
+ res.end('{}');
146
+ return;
147
+ }
148
+ if (req.url === '/agent-auth-leak') {
149
+ res.end('{"leaked":true}');
150
+ return;
151
+ }
152
+ if (req.url === `/agent-auth/v1/authorizations/${authorizationId}`) {
153
+ res.end('{"requested_routes":["staff-route"]}');
154
+ return;
155
+ }
156
+ if (req.url?.endsWith('/approve')) {
157
+ res.end('{"redirect_uri":"http://127.0.0.1/callback?code=unit-test"}');
158
+ return;
159
+ }
160
+ if (req.url?.endsWith('/deny')) {
161
+ res.end('{"status":"denied"}');
162
+ return;
163
+ }
164
+ if (req.url?.endsWith('/revoke')) {
165
+ res.end('{"status":"revoked"}');
166
+ return;
167
+ }
168
+ res.statusCode = 404;
169
+ res.end('{"error":"not found"}');
170
+ });
171
+ await new Promise((resolveListen, rejectListen) => {
172
+ agentAuthServer.once('error', rejectListen);
173
+ agentAuthServer.listen(0, '127.0.0.1', resolveListen);
174
+ });
175
+ let php7AgentAuth;
176
+ try {
177
+ const address = agentAuthServer.address();
178
+ const baseUrl = `http://127.0.0.1:${address.port}`;
179
+ php7AgentAuth = await runAsync('php', ['-r', `
180
+ require '${root}/sdk/php7/src/HubClient.php';
181
+ require '${root}/sdk/php7/src/AgentAuth.php';
182
+ $authorizationId = '${authorizationId}';
183
+ $sessionId = '${sessionId}';
184
+ $auth = new Bailing\\Connect\\AgentAuth('${baseUrl}', 'unit-test-client-token');
185
+ $out = array();
186
+ $out['context'] = $auth->context($authorizationId);
187
+ $out['approve'] = $auth->approve(
188
+ $authorizationId,
189
+ array('id' => 'user-7', 'tenant' => 'tenant-3'),
190
+ 'tenant-3:user-7',
191
+ array('selected' => 'staff-route')
192
+ );
193
+ $out['deny'] = $auth->deny($authorizationId);
194
+ $out['revoke'] = $auth->revokeSession($sessionId);
195
+ $out['validation'] = array();
196
+ $checks = array(
197
+ function () use ($auth) { $auth->context('not-a-uuid'); },
198
+ function () use ($auth, $authorizationId) { $auth->approve($authorizationId, array(), 'tenant-3:user-7', array('staff-route')); },
199
+ function () use ($auth, $authorizationId) { $auth->approve($authorizationId, array('id' => 'user-7'), '', array('staff-route')); },
200
+ function () use ($auth, $authorizationId) { $auth->approve($authorizationId, array('id' => 'user-7'), 'tenant-3:user-7', array()); }
201
+ );
202
+ foreach ($checks as $check) {
203
+ try {
204
+ $check();
205
+ $out['validation'][] = 'missing-error';
206
+ } catch (InvalidArgumentException $e) {
207
+ $out['validation'][] = $e->getMessage();
208
+ }
209
+ }
210
+ $hub = new Bailing\\Connect\\HubClient('${baseUrl}', 'unit-test-client-token');
211
+ try {
212
+ $hub->get('/redirect');
213
+ $out['redirect'] = 'followed';
214
+ } catch (RuntimeException $e) {
215
+ $out['redirect'] = $e->getMessage();
216
+ }
217
+ echo json_encode($out, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
218
+ `]);
219
+ } finally {
220
+ await closeServer(agentAuthServer);
221
+ }
222
+
223
+ let php7AgentAuthData = null;
224
+ try {
225
+ php7AgentAuthData = JSON.parse(php7AgentAuth.stdout);
226
+ } catch {}
227
+ ok('PHP7 AgentAuth HTTP flow completes', php7AgentAuth.status === 0 && php7AgentAuthData !== null, php7AgentAuth.stderr || php7AgentAuth.stdout);
228
+ ok('PHP7 AgentAuth context/approve/deny/revoke responses round-trip',
229
+ php7AgentAuthData?.context?.requested_routes?.[0] === 'staff-route'
230
+ && php7AgentAuthData?.approve?.redirect_uri === 'http://127.0.0.1/callback?code=unit-test'
231
+ && php7AgentAuthData?.deny?.status === 'denied'
232
+ && php7AgentAuthData?.revoke?.status === 'revoked');
233
+ ok('PHP7 AgentAuth validates UUID, principal, subject and route scope',
234
+ JSON.stringify(php7AgentAuthData?.validation) === JSON.stringify([
235
+ 'authorizationId 必须是 UUID',
236
+ 'principal.id 必填',
237
+ 'onBehalfOf 必填',
238
+ 'allowedRoutes 至少包含一条路由',
239
+ ]));
240
+ ok('PHP7 AgentAuth uses the v1 paths and methods',
241
+ JSON.stringify(agentAuthRequests.slice(0, 4).map(({ method, url }) => [method, url])) === JSON.stringify([
242
+ ['GET', `/agent-auth/v1/authorizations/${authorizationId}`],
243
+ ['POST', `/agent-auth/v1/authorizations/${authorizationId}/approve`],
244
+ ['POST', `/agent-auth/v1/authorizations/${authorizationId}/deny`],
245
+ ['POST', `/agent-auth/v1/sessions/${sessionId}/revoke`],
246
+ ]));
247
+ let approveBody = null;
248
+ try {
249
+ approveBody = JSON.parse(agentAuthRequests[1]?.body ?? '');
250
+ } catch {}
251
+ ok('PHP7 AgentAuth derives the approval wire body without client-side credentials',
252
+ JSON.stringify(approveBody) === JSON.stringify({
253
+ principal: { id: 'user-7', tenant: 'tenant-3', roles: [] },
254
+ on_behalf_of: 'tenant-3:user-7',
255
+ allowed_routes: ['staff-route'],
256
+ }));
257
+ ok('PHP7 AgentAuth keeps Client Token in the backend Authorization header',
258
+ agentAuthRequests.every((request) => request.authorization === 'Bearer unit-test-client-token')
259
+ && agentAuthRequests.slice(1, 4).every((request) => request.contentType === 'application/json'));
260
+ ok('PHP7 HubClient does not follow a Bearer-authenticated redirect',
261
+ php7AgentAuthData?.redirect === 'HTTP 302'
262
+ && !agentAuthRequests.some((request) => request.url === '/agent-auth-leak'));
99
263
 
100
264
  console.log(`\n结果:通过 ${pass} / 失败 ${fail}`);
101
265
  process.exit(fail ? 1 : 0);
@@ -2,7 +2,10 @@ import { execFileSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync, statSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
 
5
+ import { findPublicContentDenylistMatches, loadPrivateExactTextDenylist } from './public-content-denylist.mjs';
6
+
5
7
  const root = process.cwd();
8
+ const privateExactTextDenylist = loadPrivateExactTextDenylist({ root });
6
9
  const requiredFiles = ['LICENSE', 'NOTICE', 'THIRD_PARTY_NOTICES.md', 'SECURITY.md', 'CONTRIBUTING.md', '.env.example', 'config.example.json'];
7
10
  const allowedLiteralValues = new Set([
8
11
  'demo-tool-secret-change-me',
@@ -27,7 +30,6 @@ const skipPath = (file) => (
27
30
  || file.startsWith('.git/')
28
31
  );
29
32
  const isTestFixture = (file) => /\.(test|spec)\.(ts|js|mjs)$/.test(file) || file.includes('/__tests__/');
30
- const rx = (parts, flags = '') => new RegExp(parts.join(''), flags);
31
33
 
32
34
  const patterns = [
33
35
  { name: 'private key', re: /-----BEGIN (?:RSA |DSA |EC |OPENSSH |)PRIVATE KEY-----/ },
@@ -35,8 +37,6 @@ const patterns = [
35
37
  { name: 'GitHub token', re: /\bgh[pousr]_[A-Za-z0-9_]{30,}\b/ },
36
38
  { name: 'AWS access key', re: /\bAKIA[0-9A-Z]{16}\b/ },
37
39
  { name: 'Tencent Cloud secret id', re: /\bAKID[A-Za-z0-9]{13,}\b/ },
38
- { name: 'known leaked password', re: rx(['Nie', '0712', '\\.\\.']) },
39
- { name: 'known managed MySQL host in source', re: rx(['sh-', 'cynosdb', 'mysql', '-[A-Za-z0-9.-]+', 'tencent', 'cdb\\.com']) },
40
40
  { name: 'legacy fixed server token fallback', re: /server(?:Token|\.token)\s*\|\|\s*['"]bailing['"]/ },
41
41
  { name: 'predictable Compose admin token', re: /BAILING_TOKEN:\s*\$\{BAILING_TOKEN:-[^}]+\}/ },
42
42
  ];
@@ -61,7 +61,7 @@ function scanSecretAssignments(file, text, findings) {
61
61
  if (allowedLiteralValues.has(value)) continue;
62
62
  if (/^(change-me|example|placeholder|your-|<.+>|xxx+|\*+|demo-|bailing-)/i.test(value)) continue;
63
63
  if (file.includes('/README') || file.startsWith('docs/') || file.startsWith('sdk/')) continue;
64
- findings.push({ file, name: `suspicious ${m[1]} assignment`, sample: value.slice(0, 12) + '...' });
64
+ findings.push({ file, name: `suspicious ${m[1]} assignment`, sample: '[redacted]' });
65
65
  }
66
66
  }
67
67
 
@@ -80,7 +80,10 @@ for (const file of trackedAndUntrackedFiles()) {
80
80
  for (const p of patterns) {
81
81
  if (isTestFixture(file) && p.name === 'OpenAI API key') continue;
82
82
  const m = text.match(p.re);
83
- if (m) findings.push({ file, name: p.name, sample: m[0].slice(0, 80) });
83
+ if (m) findings.push({ file, name: p.name, sample: '[redacted]' });
84
+ }
85
+ for (const match of findPublicContentDenylistMatches(text, privateExactTextDenylist, { generic: false })) {
86
+ findings.push({ file, name: match, sample: '[redacted]' });
84
87
  }
85
88
  scanSecretAssignments(file, text, findings);
86
89
  }
@@ -1,7 +1,9 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { checkReleaseConsistency } from './check-release-consistency.mjs';
3
+ import { findPublicContentDenylistMatches, loadPrivateExactTextDenylist } from './public-content-denylist.mjs';
3
4
 
4
5
  const findings = [];
6
+ const privateExactTextDenylist = loadPrivateExactTextDenylist();
5
7
 
6
8
  function read(file) {
7
9
  if (!existsSync(file)) {
@@ -65,7 +67,7 @@ for (const [file, text] of [
65
67
  requireIncludes(file, text, 'BAILING_TOOL_INDEX_LOAD_TIMEOUT_MS: ${BAILING_TOOL_INDEX_LOAD_TIMEOUT_MS:-5000}');
66
68
  requireIncludes(file, text, 'BAILING_TOOL_QUERY_EMBEDDING_TIMEOUT_MS: ${BAILING_TOOL_QUERY_EMBEDDING_TIMEOUT_MS:-15000}');
67
69
  requireIncludes(file, text, 'BAILING_SEED_DEMO: "1"');
68
- if (/bailing\.bnopen\.cn/.test(text)) findings.push(`${file}: must not reference self-hosted internal instance`);
70
+ for (const match of findPublicContentDenylistMatches(text, privateExactTextDenylist)) findings.push(`${file}: ${match}`);
69
71
  }
70
72
 
71
73
  if (stableVersion && !composeImages.includes(`bailinghub:${stableVersion}`)) {
@@ -3,9 +3,12 @@ import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
 
6
+ import { findPublicContentDenylistMatches, loadPrivateExactTextDenylist } from './public-content-denylist.mjs';
7
+
6
8
  const root = process.cwd();
7
9
  const exportDir = join(root, '.oss-dist', 'bailinghub');
8
10
  const expectedRepo = 'git+https://github.com/bailinghub/bailinghub.git';
11
+ const privateExactTextDenylist = loadPrivateExactTextDenylist({ root });
9
12
 
10
13
  function run(cmd, args, cwd = root) {
11
14
  console.log(`> ${[cmd, ...args].join(' ')}`);
@@ -124,6 +127,7 @@ const requiredFiles = [
124
127
  'docs/RELEASE_NOTES_v0.3.2.md',
125
128
  'docs/RELEASE_NOTES_v0.3.3.md',
126
129
  'docs/RELEASE_NOTES_v0.3.4.md',
130
+ 'docs/RELEASE_NOTES_v0.5.0.md',
127
131
  'docs/CHANGELOG.md',
128
132
  ];
129
133
  for (const file of requiredFiles) requireFile(file);
@@ -172,21 +176,13 @@ try {
172
176
  assertNotTracked(files, (file) => file.includes('.bak.'), 'GitHub rehearsal must not track backup files');
173
177
  assertNoInstallerEnvPrefix(files);
174
178
 
175
- const bannedParts = [
176
- String.raw`/Users/` + 'macmini',
177
- '项目' + String.raw`/www`,
178
- 'Nie' + '0712',
179
- 'github' + '_pat_',
180
- String.raw`pt-[A-Za-z0-9_-]{20,}`,
181
- 'sh-' + 'cynosdb' + 'mysql' + String.raw`-[A-Za-z0-9.-]+` + 'tencent' + String.raw`cdb\.com`,
182
- 'bnopen' + String.raw`\.cn`,
183
- ];
184
- const bannedText = new RegExp(`(${bannedParts.join('|')})`);
185
179
  const textFiles = files.filter((file) => /\.(?:md|ts|tsx|js|mjs|json|sql|php|py|vue|html|css|sh|yml|yaml|txt|gitignore|npmignore|dockerignore)$/.test(file));
186
180
  const findings = [];
187
181
  for (const file of textFiles) {
188
182
  const text = output('git', ['show', `:${file}`], repoDir);
189
- if (bannedText.test(text)) findings.push(file);
183
+ for (const match of findPublicContentDenylistMatches(text, privateExactTextDenylist)) {
184
+ findings.push(`${file}: ${match}`);
185
+ }
190
186
  }
191
187
  if (findings.length) {
192
188
  throw new Error(`GitHub rehearsal found private text in: ${findings.slice(0, 20).join(', ')}`);
@@ -3,8 +3,11 @@ import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
 
6
+ import { findPublicContentDenylistMatches, loadPrivateExactTextDenylist } from './public-content-denylist.mjs';
7
+
6
8
  const root = process.cwd();
7
9
  const exportDir = join(root, '.oss-dist', 'bailinghub');
10
+ const privateExactTextDenylist = loadPrivateExactTextDenylist({ root });
8
11
 
9
12
  function run(cmd, args, cwd = root) {
10
13
  console.log(`> ${[cmd, ...args].join(' ')}`);
@@ -15,8 +18,6 @@ function output(cmd, args, cwd = root) {
15
18
  return execFileSync(cmd, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
16
19
  }
17
20
 
18
- const rx = (parts, flags = '') => new RegExp(parts.join(''), flags);
19
-
20
21
  function verifyGitBoundary() {
21
22
  const rehearsalRoot = mkdtempSync(join(tmpdir(), 'bailinghub-oss-git-'));
22
23
  const repoDir = join(rehearsalRoot, 'repo');
@@ -75,15 +76,6 @@ function verifyGitBoundary() {
75
76
  const allowedHiddenRoots = new Set(['.github']);
76
77
  const allowedHiddenFiles = new Set(['.dockerignore', '.env.example', '.gitignore', '.npmignore']);
77
78
  const forbiddenFiles = new Set(['config.json', '.env', 'targets.local.json']);
78
- const bannedText = rx([
79
- '/Users/', 'macmini',
80
- '|', '项目', '\\/www',
81
- '|', 'Nie', '0712',
82
- '|', 'github', '_pat', '_',
83
- '|', 'pt', '-[A-Za-z0-9_-]{20,}',
84
- '|', 'bnopen', '\\.cn',
85
- '|', 'sh-', 'cynosdb', 'mysql', '-[A-Za-z0-9.-]+', 'tencent', 'cdb\\.com',
86
- ]);
87
79
  const forbiddenPublicWording = new RegExp([
88
80
  '商业' + '版',
89
81
  '商业' + '扩展',
@@ -118,7 +110,9 @@ function verifyGitBoundary() {
118
110
  const textFiles = files.filter((file) => /\.(?:md|ts|tsx|js|mjs|json|sql|php|py|vue|html|css|sh|yml|yaml|txt|gitignore|npmignore|dockerignore)$/.test(file));
119
111
  for (const file of textFiles) {
120
112
  const text = output('git', ['show', `:${file}`], repoDir);
121
- if (bannedText.test(text)) findings.push(`${file}: forbidden private text in git boundary`);
113
+ for (const match of findPublicContentDenylistMatches(text, privateExactTextDenylist)) {
114
+ findings.push(`${file}: ${match} in git boundary`);
115
+ }
122
116
  if (file !== 'LICENSE' && forbiddenPublicWording.test(text)) {
123
117
  findings.push(`${file}: use neutral public wording for private extension boundaries`);
124
118
  }