bailinghub 0.4.0 → 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 (141) hide show
  1. package/.gitignore +5 -0
  2. package/README.en.md +5 -2
  3. package/README.md +5 -2
  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 +13 -0
  13. package/docs/CHANGELOG.md +13 -0
  14. package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
  15. package/docs/INDEPENDENT_VALIDATION.md +4 -4
  16. package/docs/README.en.md +8 -2
  17. package/docs/README.md +8 -2
  18. package/docs/RELEASE_NOTES_v0.5.0.en.md +41 -0
  19. package/docs/RELEASE_NOTES_v0.5.0.md +41 -0
  20. package/package.json +3 -2
  21. package/schemas/config/client.schema.json +7 -0
  22. package/schemas/config/common.schema.json +30 -0
  23. package/schemas/config/route.schema.json +11 -0
  24. package/scripts/check-doc-links.mjs +1 -1
  25. package/scripts/check-image-tags.sh +1 -1
  26. package/scripts/check-release-consistency.test.mjs +5 -5
  27. package/scripts/e2e-console.mjs +144 -0
  28. package/scripts/export-oss.mjs +5 -12
  29. package/scripts/install.sh +1 -1
  30. package/scripts/public-content-denylist.mjs +82 -0
  31. package/scripts/public-content-denylist.test.mjs +53 -0
  32. package/scripts/publish-images.sh +1 -1
  33. package/scripts/release-audit.mjs +8 -13
  34. package/scripts/sdk-runtime-test.mjs +171 -7
  35. package/scripts/security-scan.mjs +8 -5
  36. package/scripts/validate-examples.mjs +3 -1
  37. package/scripts/verify-github-repo.mjs +7 -12
  38. package/scripts/verify-oss-export.mjs +6 -12
  39. package/sdk/php/README.md +27 -1
  40. package/sdk/php/src/AgentAuth.php +78 -0
  41. package/sdk/php/src/HubClient.php +3 -0
  42. package/sdk/php7/README.md +32 -2
  43. package/sdk/php7/src/AgentAuth.php +77 -0
  44. package/sdk/php7/src/HubClient.php +3 -0
  45. package/sql/055_agent_auth.sql +72 -0
  46. package/sql/056_agent_client_runtime.sql +60 -0
  47. package/src/adapters/channels/wecom-api.ts +1 -1
  48. package/src/app/agent-client-runtime.test.ts +221 -0
  49. package/src/app/agent-client-runtime.ts +408 -0
  50. package/src/app/agent-tool-invocations.test.ts +462 -0
  51. package/src/app/agent-tool-invocations.ts +795 -0
  52. package/src/app/agent-tool-job.test.ts +62 -0
  53. package/src/app/agent-tool-job.ts +41 -0
  54. package/src/app/auth.ts +2 -1
  55. package/src/app/kernel.ts +2 -0
  56. package/src/app/runtime-context.ts +8 -0
  57. package/src/app/tool-approvals.ts +5 -1
  58. package/src/app/tool-assembly.ts +19 -1
  59. package/src/app/tool-context.ts +2 -1
  60. package/src/core/config/config-codec.ts +2 -1
  61. package/src/core/config/config-models.test.ts +10 -0
  62. package/src/core/config/config-models.ts +21 -0
  63. package/src/core/config/config-schema.test.ts +6 -0
  64. package/src/core/config/route-config.test.ts +15 -0
  65. package/src/core/config/route-config.ts +36 -0
  66. package/src/core/config/tools-config.test.ts +58 -1
  67. package/src/core/config/tools-config.ts +84 -0
  68. package/src/core/contracts/tools.ts +162 -29
  69. package/src/core/contracts/types.ts +36 -0
  70. package/src/core/runtime/agent-client-trace.test.ts +154 -0
  71. package/src/core/runtime/agent-client-trace.ts +288 -0
  72. package/src/core/runtime/launch-runtime.ts +13 -0
  73. package/src/core/runtime/trace-runtime.test.ts +18 -1
  74. package/src/core/runtime/trace-runtime.ts +28 -3
  75. package/src/core/state/state-codec.ts +2 -0
  76. package/src/infrastructure/config/config-agent-auth-repository.test.ts +147 -0
  77. package/src/infrastructure/config/config-agent-auth-repository.ts +356 -0
  78. package/src/infrastructure/config/config-agent-client-runtime-repository.ts +253 -0
  79. package/src/infrastructure/config/config-approval-ledger.test.ts +32 -0
  80. package/src/infrastructure/config/config-approval-ledger.ts +16 -0
  81. package/src/infrastructure/config/config-client-repository.ts +3 -3
  82. package/src/infrastructure/config/config-conversation-ledger.test.ts +69 -0
  83. package/src/infrastructure/config/config-conversation-ledger.ts +8 -7
  84. package/src/infrastructure/config/config-observability-ledger.test.ts +50 -0
  85. package/src/infrastructure/config/config-observability-ledger.ts +65 -10
  86. package/src/infrastructure/config/config-route-repository.ts +4 -3
  87. package/src/infrastructure/config/configstore.ts +14 -3
  88. package/src/infrastructure/state/state-mysql.ts +2 -2
  89. package/src/kernel-api/v1/contracts.ts +8 -0
  90. package/src/routes/admin-runtime.test.ts +214 -0
  91. package/src/routes/admin-runtime.ts +82 -2
  92. package/src/routes/agent-api.test.ts +379 -0
  93. package/src/routes/agent-api.ts +251 -0
  94. package/src/routes/agent-auth.test.ts +276 -0
  95. package/src/routes/agent-auth.ts +395 -0
  96. package/src/routes/approvals.ts +4 -1
  97. package/src/routes/critical-routes.test.ts +235 -1
  98. package/src/routes/private-default.ts +2 -1
  99. package/src/routes/private.ts +16 -1
  100. package/src/routes/run.ts +79 -13
  101. package/web/connect/bailing-connect-php.tgz +0 -0
  102. package/web/connect/bailing-connect-php7.tgz +0 -0
  103. package/web/console/assets/{Accounts-DuUY2UJU.js → Accounts-D4RRm5D1.js} +1 -1
  104. package/web/console/assets/{Approvals-B11mo1dy.js → Approvals-CsTTKb8o.js} +1 -1
  105. package/web/console/assets/{Audit-CQwJRIJT.js → Audit-BzvZ7JZw.js} +1 -1
  106. package/web/console/assets/{BrandLockup-BIF-h1pi.js → BrandLockup-CYcA93wh.js} +1 -1
  107. package/web/console/assets/{Channels-BIploUT-.js → Channels-DRQZggqM.js} +1 -1
  108. package/web/console/assets/{ChatEntries-Cpg_WV-o.js → ChatEntries-BUB7BWKU.js} +1 -1
  109. package/web/console/assets/Clients-CQ_MonGL.css +1 -0
  110. package/web/console/assets/Clients-HhCyrxfz.js +3 -0
  111. package/web/console/assets/{Cost-BF52tfU2.js → Cost-BZgFf1yM.js} +1 -1
  112. package/web/console/assets/{Credentials-SwfmQAv6.js → Credentials-BTe2Q07j.js} +1 -1
  113. package/web/console/assets/{Diagnostics-CJfbI_8p.js → Diagnostics-WL-buYli.js} +1 -1
  114. package/web/console/assets/{Executors-CzlZlznA.js → Executors-CGZ-7Xmp.js} +1 -1
  115. package/web/console/assets/{Kb-CVX22U4k.js → Kb-VVw8oGsT.js} +1 -1
  116. package/web/console/assets/{Login-PoUVsBI-.js → Login-rwvmBBPl.js} +1 -1
  117. package/web/console/assets/{Projects-DYlbjLQy.js → Projects-CexaCEY1.js} +1 -1
  118. package/web/console/assets/Routes-B9ZHbQAp.js +124 -0
  119. package/web/console/assets/Routes-BbkFpi6Y.css +1 -0
  120. package/web/console/assets/Runs-4zDD9VOC.css +1 -0
  121. package/web/console/assets/Runs-BzFNPTwD.js +3 -0
  122. package/web/console/assets/{Setup-xiPXit_b.js → Setup-Djh5yadQ.js} +1 -1
  123. package/web/console/assets/{Shell-DNiWZOYB.js → Shell-kn763smL.js} +1 -1
  124. package/web/console/assets/{StorageBuckets-Bjsc3pLd.js → StorageBuckets-CQBR41W1.js} +1 -1
  125. package/web/console/assets/{SystemSettings-CcKF2lJ9.js → SystemSettings-DgnopekD.js} +1 -1
  126. package/web/console/assets/{SystemStatus-Oj1xjxJn.js → SystemStatus-Bj8-kPt2.js} +1 -1
  127. package/web/console/assets/{Targets-y1KllVXT.js → Targets-BAfCt_nH.js} +1 -1
  128. package/web/console/assets/{Tools-DoEP_y9x.js → Tools-xjd0NZdE.js} +1 -1
  129. package/web/console/assets/{index-CxPIS6G7.js → index-DfJA7iJS.js} +2 -2
  130. package/web/console/assets/{request-CBLNpLth.js → request-DkNPOweH.js} +1 -1
  131. package/web/console/assets/{schema-DzwLpuOy.js → schema-CgPWAu1_.js} +1 -1
  132. package/web/console/index.html +1 -1
  133. package/web-admin/src/pages/Clients.vue +11 -3
  134. package/web-admin/src/pages/Routes.vue +282 -16
  135. package/web-admin/src/pages/Runs.vue +159 -38
  136. package/web/console/assets/Clients--D7NQJKk.css +0 -1
  137. package/web/console/assets/Clients-DS29eUi2.js +0 -3
  138. package/web/console/assets/Routes-DSEvGujN.js +0 -124
  139. package/web/console/assets/Routes-DWGQN5Pv.css +0 -1
  140. package/web/console/assets/Runs-B-TsYZEt.js +0 -3
  141. package/web/console/assets/Runs-CUtSsPW-.css +0 -1
@@ -81,9 +81,34 @@ const fixtures = {
81
81
  last_preview: '查询订单 SO-1001',
82
82
  last_active_at: new Date().toISOString(),
83
83
  message_count: 2,
84
+ }, {
85
+ thread_id: 2,
86
+ scope_key: 'agent:demo-app:employee-edit',
87
+ channel: 'agent:demo-app',
88
+ client_name: 'Demo 业务系统',
89
+ principal_id: 'uid:tenant-1:user-7',
90
+ route_name: 'Demo 售后助手',
91
+ last_preview: '员工资料已修改',
92
+ last_active_at: new Date().toISOString(),
93
+ message_count: 2,
94
+ }, {
95
+ thread_id: 3,
96
+ scope_key: 'agent:demo-app:incomplete-turn',
97
+ channel: 'agent:demo-app',
98
+ client_name: 'Demo 业务系统',
99
+ principal_id: 'uid:tenant-1:user-7',
100
+ route_name: 'Demo 售后助手',
101
+ last_preview: '等待本地智能体继续处理',
102
+ last_active_at: new Date().toISOString(),
103
+ message_count: 1,
84
104
  }],
85
105
  };
86
106
 
107
+ const agentRunId = '123e4567-e89b-42d3-a456-426614174000';
108
+ const agentToolJobId = '223e4567-e89b-42d3-a456-426614174000';
109
+ const incompleteAgentRunId = '323e4567-e89b-42d3-a456-426614174000';
110
+ const incompleteAgentToolJobId = '423e4567-e89b-42d3-a456-426614174000';
111
+
87
112
  let smokeRequests = 0;
88
113
 
89
114
  function tracePayload() {
@@ -101,6 +126,84 @@ function tracePayload() {
101
126
  };
102
127
  }
103
128
 
129
+ function agentRunTracePayload() {
130
+ return {
131
+ kind: 'agent_client_run',
132
+ run: {
133
+ run_id: agentRunId,
134
+ thread_id: 2,
135
+ client_app_id: 'demo-app',
136
+ route_key: 'demo_support',
137
+ status: 'completed',
138
+ model: 'deepseek-chat',
139
+ runtime: 'deepseek-harness',
140
+ usage: { total_tokens: 168 },
141
+ governance: { planner: 'local_agent', execution: 'bailinghub_governed', hidden_reasoning_sync: false },
142
+ },
143
+ trace: {
144
+ summary: { tool_invocations: 1, approvals: 0, warning_count: 0, error_count: 0, duration_ms: 1800 },
145
+ events: [
146
+ { ts: new Date().toISOString(), event: 'agent_client_run_started', source: 'local_agent', stage: 'launch', severity: 'info', title: '本地智能体开始处理', summary: '本轮由本地智能体负责理解、规划和工具选择', detail: { hidden_reasoning_sync: false } },
147
+ { ts: new Date().toISOString(), event: 'tool_call', source: 'hub_governance', tool_job_id: agentToolJobId, stage: 'tool', severity: 'info', title: '工具调用', summary: 'staff_edit', detail: { tool: 'staff_edit', argument_keys: ['id', 'name'] } },
148
+ { ts: new Date().toISOString(), event: 'tool_result', source: 'hub_governance', tool_job_id: agentToolJobId, stage: 'tool', severity: 'info', title: '工具结果', summary: 'staff_edit · HTTP 200', detail: { tool: 'staff_edit', status: 200, ok: true } },
149
+ ],
150
+ },
151
+ invocations: [{
152
+ job_id: agentToolJobId,
153
+ invocation_id: 'a'.repeat(64),
154
+ tool: 'staff_edit',
155
+ status: 'done',
156
+ state: 'executed',
157
+ ok: true,
158
+ business_status: 200,
159
+ approval_status: null,
160
+ approval_id: null,
161
+ event_count: 3,
162
+ duration_ms: 1200,
163
+ created_at: new Date().toISOString(),
164
+ updated_at: new Date().toISOString(),
165
+ }],
166
+ };
167
+ }
168
+
169
+ function incompleteAgentRunTracePayload() {
170
+ return {
171
+ kind: 'agent_client_run',
172
+ run: {
173
+ run_id: incompleteAgentRunId,
174
+ thread_id: 3,
175
+ client_app_id: 'demo-app',
176
+ route_key: 'demo_support',
177
+ status: 'context_ready',
178
+ model: null,
179
+ runtime: 'deepseek-harness',
180
+ usage: null,
181
+ governance: { planner: 'local_agent', execution: 'bailinghub_governed', hidden_reasoning_sync: false },
182
+ },
183
+ trace: {
184
+ summary: { tool_invocations: 1, approvals: 1, warning_count: 1, error_count: 0, duration_ms: 3200, partial: true },
185
+ events: [
186
+ { ts: new Date().toISOString(), event: 'agent_client_run_started', source: 'local_agent', stage: 'launch', severity: 'info', title: '本地智能体开始处理', summary: '本轮由本地智能体负责规划', detail: { hidden_reasoning_sync: false } },
187
+ { ts: new Date().toISOString(), event: 'agent_tool_invocation_state', source: 'hub_governance', tool_job_id: incompleteAgentToolJobId, stage: 'tool', severity: 'warning', title: 'ACC 工具调用状态更新', summary: 'staff_edit · awaiting_approval', detail: { tool: 'staff_edit', state: 'awaiting_approval', ok: false } },
188
+ ],
189
+ },
190
+ invocations: [{
191
+ job_id: incompleteAgentToolJobId,
192
+ invocation_id: 'b'.repeat(64),
193
+ tool: 'staff_edit',
194
+ status: 'done',
195
+ state: 'awaiting_approval',
196
+ ok: false,
197
+ business_status: null,
198
+ approval_status: 'approved',
199
+ approval_id: 9,
200
+ event_count: 2,
201
+ created_at: new Date().toISOString(),
202
+ updated_at: new Date().toISOString(),
203
+ }],
204
+ };
205
+ }
206
+
104
207
  async function mockApi(context) {
105
208
  await context.route('**/health', (route) => route.fulfill({ json: { status: 'ok', paused: false, queue: { running: 0, waiting: 0 }, backend: 'mysql', configBackend: true } }));
106
209
  await context.route('**/admin/api/me', (route) => route.fulfill({ json: { username: 'admin', role: 'admin', perms: ['*'] } }));
@@ -123,6 +226,8 @@ async function mockApi(context) {
123
226
  await context.route('**/admin/api/config-schemas/*', (route) => route.fulfill({ json: { required: [], properties: {} } }));
124
227
  await context.route('**/admin/api/tool-providers/*/tools', (route) => route.fulfill({ json: { tools: [{ name: 'list_demo_orders', scope: 'demo.order.read' }] } }));
125
228
  await context.route('**/admin/api/runs/*/trace', (route) => route.fulfill({ json: tracePayload() }));
229
+ await context.route(`**/admin/api/threads/2/agent-runs/${agentRunId}/trace`, (route) => route.fulfill({ json: agentRunTracePayload() }));
230
+ await context.route(`**/admin/api/threads/3/agent-runs/${incompleteAgentRunId}/trace`, (route) => route.fulfill({ json: incompleteAgentRunTracePayload() }));
126
231
  await context.route('**/admin/api/**', (route) => {
127
232
  const url = new URL(route.request().url());
128
233
  if (url.pathname === '/admin/api/me') return route.fulfill({ json: { username: 'admin', role: 'admin', perms: ['*'] } });
@@ -148,6 +253,8 @@ async function mockApi(context) {
148
253
  if (url.pathname === '/admin/api/routes') return route.fulfill({ json: fixtures.routes });
149
254
  if (url.pathname === '/admin/api/runs') return route.fulfill({ json: fixtures.runs });
150
255
  if (/^\/admin\/api\/runs\/[^/]+\/trace$/.test(url.pathname)) return route.fulfill({ json: tracePayload() });
256
+ if (url.pathname === `/admin/api/threads/2/agent-runs/${agentRunId}/trace`) return route.fulfill({ json: agentRunTracePayload() });
257
+ if (url.pathname === `/admin/api/threads/3/agent-runs/${incompleteAgentRunId}/trace`) return route.fulfill({ json: incompleteAgentRunTracePayload() });
151
258
  if (url.pathname === '/admin/api/threads') return route.fulfill({ json: fixtures.threads });
152
259
  if (url.pathname === '/admin/api/threads/1') return route.fulfill({
153
260
  json: {
@@ -158,6 +265,23 @@ async function mockApi(context) {
158
265
  ],
159
266
  },
160
267
  });
268
+ if (url.pathname === '/admin/api/threads/2') return route.fulfill({
269
+ json: {
270
+ thread: fixtures.threads[1],
271
+ messages: [
272
+ { id: 3, direction: 'in', content: '把员工资料改成新的姓名', agent_run_id: agentRunId, created_at: new Date().toISOString() },
273
+ { id: 4, direction: 'out', content: '员工资料已修改', agent_run_id: agentRunId, created_at: new Date().toISOString() },
274
+ ],
275
+ },
276
+ });
277
+ if (url.pathname === '/admin/api/threads/3') return route.fulfill({
278
+ json: {
279
+ thread: fixtures.threads[2],
280
+ messages: [
281
+ { id: 5, direction: 'in', content: '等待本地智能体继续处理', agent_run_id: incompleteAgentRunId, created_at: new Date().toISOString() },
282
+ ],
283
+ },
284
+ });
161
285
  if (url.pathname === '/admin/api/executors') return route.fulfill({ json: [{ executor_id: 'demo-exec', online: true, targets: ['demo-agent'] }] });
162
286
  if (url.pathname === '/admin/api/projects') return route.fulfill({ json: [] });
163
287
  if (url.pathname === '/admin/api/demo-dataset/status') return route.fulfill({ json: fixtures.demoStatus });
@@ -234,6 +358,26 @@ try {
234
358
  await expectVisible(page, '工具返回');
235
359
  await expectVisible(page, '任务完成');
236
360
 
361
+ await page.getByText('员工资料已修改').first().click();
362
+ await expectVisible(page, '把员工资料改成新的姓名');
363
+ await page.locator('.tracetoggle').filter({ hasText: '执行轨迹' }).first().click();
364
+ await expectVisible(page, '本地智能体编排');
365
+ await expectVisible(page, '隐藏推理不会上传');
366
+ await expectVisible(page, '中枢治理');
367
+ await expectVisible(page, 'staff_edit');
368
+ if (await page.getByText('未挂工具', { exact: true }).count()) {
369
+ throw new Error('Agent Client 轨迹不应显示旧 Job 的「未挂工具」提示');
370
+ }
371
+ if (await page.getByText('PRIVATE_REASONING', { exact: false }).count()) {
372
+ throw new Error('Agent Client 会话轨迹不得展示隐藏推理');
373
+ }
374
+
375
+ await page.getByText('等待本地智能体继续处理').first().click();
376
+ await page.locator('.tracetoggle').filter({ hasText: '执行轨迹' }).first().click();
377
+ await expectVisible(page, '上下文已就绪');
378
+ await expectVisible(page, '已批准,等待本地智能体续执行');
379
+ await expectVisible(page, '不代表全量');
380
+
237
381
  if (errors.length) throw new Error(`console errors:\n${errors.join('\n')}`);
238
382
  console.log('✓ console e2e passed');
239
383
  } finally {
@@ -2,11 +2,14 @@ import { execFileSync, spawnSync } from 'node:child_process';
2
2
  import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync } from 'node:fs';
3
3
  import { dirname, join } from 'node:path';
4
4
 
5
+ import { findPublicContentDenylistMatches, loadPrivateExactTextDenylist } from './public-content-denylist.mjs';
6
+
5
7
  const root = process.cwd();
6
8
  const outRoot = join(root, '.oss-dist');
7
9
  const exportDir = join(outRoot, 'bailinghub');
8
10
  const tarball = join(outRoot, 'bailinghub-oss-source.tgz');
9
11
  const findings = [];
12
+ const privateExactTextDenylist = loadPrivateExactTextDenylist({ root });
10
13
  const tarEnv = { ...process.env, COPYFILE_DISABLE: '1' };
11
14
  const tarNoMetadataArgs = ['--no-xattrs'];
12
15
 
@@ -52,16 +55,6 @@ const forbiddenFiles = new Set([
52
55
  'config.json',
53
56
  '.env',
54
57
  ]);
55
- const rx = (parts, flags = '') => new RegExp(parts.join(''), flags);
56
-
57
- const bannedText = [
58
- { name: 'local machine path', re: rx(['/Users/', 'macmini', '|', '项目', '\\/www']) },
59
- { name: 'known leaked password', re: rx(['Nie', '0712', '\\.\\.']) },
60
- { name: 'known managed MySQL host', re: rx(['sh-', 'cynosdb', 'mysql', '-[A-Za-z0-9.-]+', 'tencent', 'cdb\\.com']) },
61
- { name: 'known internal git token', re: rx(['pt', '-[A-Za-z0-9_-]{20,}']) },
62
- { name: 'GitHub PAT', re: rx(['github', '_pat', '_[A-Za-z0-9_]+']) },
63
- { name: 'old official domain', re: rx(['bailing\\.', 'bnopen', '\\.cn', '|', 'bnopen', '\\.cn']) },
64
- ];
65
58
  const forbiddenPublicWording = new RegExp([
66
59
  '商业' + '版',
67
60
  '商业' + '扩展',
@@ -122,8 +115,8 @@ function scanExport() {
122
115
  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));
123
116
  for (const file of textFiles) {
124
117
  const text = readFileSync(join(exportDir, file), 'utf8');
125
- for (const rule of bannedText) {
126
- if (rule.re.test(text)) findings.push(`${file}: ${rule.name}`);
118
+ for (const match of findPublicContentDenylistMatches(text, privateExactTextDenylist)) {
119
+ findings.push(`${file}: ${match}`);
127
120
  }
128
121
  if (file !== 'LICENSE' && forbiddenPublicWording.test(text)) {
129
122
  findings.push(`${file}: use neutral public wording for private extension boundaries`);
@@ -275,7 +275,7 @@ write_env() {
275
275
  TOOL_SECRET="${DEMO_TOOL_SECRET:-$(secret)}"
276
276
  CLIENT_TOKEN="${DEMO_CLIENT_TOKEN:-$(secret)}"
277
277
  IMAGE_TAG="${BAILING_IMAGE_TAG:-$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$APP_DIR/package.json" | head -1)}"
278
- [ -n "$IMAGE_TAG" ] || IMAGE_TAG="0.4.0"
278
+ [ -n "$IMAGE_TAG" ] || IMAGE_TAG="0.5.0"
279
279
  IMAGE_REGISTRY="${BAILING_IMAGE_REGISTRY:-$DEFAULT_IMAGE_REGISTRY}"
280
280
  IMAGE_NAMESPACE="${BAILING_IMAGE_NAMESPACE:-$DEFAULT_IMAGE_NAMESPACE}"
281
281
  cat > "$ENV_FILE" <<EOF
@@ -0,0 +1,82 @@
1
+ import { existsSync, readFileSync, realpathSync } from 'node:fs';
2
+ import { isAbsolute, relative, sep } from 'node:path';
3
+
4
+ export const PUBLIC_DENYLIST_JSON_ENV = 'BAILING_PUBLIC_DENYLIST_JSON';
5
+ export const PUBLIC_DENYLIST_FILE_ENV = 'BAILING_PUBLIC_DENYLIST_FILE';
6
+
7
+ export const genericPublicContentRules = Object.freeze([
8
+ {
9
+ name: 'private key',
10
+ re: /-----BEGIN (?:RSA |DSA |EC |OPENSSH |)PRIVATE KEY-----/,
11
+ },
12
+ {
13
+ name: 'GitHub personal access token',
14
+ re: /\b(?:github_pat_[A-Za-z0-9_]{20,}|gh[pousr]_[A-Za-z0-9_]{20,})\b/,
15
+ },
16
+ {
17
+ name: 'local user absolute path',
18
+ re: /(?:^|[\s"'`=(])(?:\/Users\/[^/\s"'`]+\/|\/home\/[^/\s"'`]+\/|[A-Za-z]:\\Users\\[^\\\s"'`]+\\)/,
19
+ },
20
+ ]);
21
+
22
+ function parseExactValues(raw, sourceName) {
23
+ let parsed;
24
+ try {
25
+ parsed = JSON.parse(raw);
26
+ } catch {
27
+ throw new Error(`${sourceName} must contain a JSON array of exact text values`);
28
+ }
29
+ if (!Array.isArray(parsed)) {
30
+ throw new Error(`${sourceName} must contain a JSON array of exact text values`);
31
+ }
32
+ return parsed.map((value, index) => {
33
+ if (typeof value !== 'string' || value.trim().length < 4) {
34
+ throw new Error(`${sourceName} entry #${index + 1} must be a non-empty string of at least 4 characters`);
35
+ }
36
+ return value;
37
+ });
38
+ }
39
+
40
+ function isInsideRoot(rootPath, candidatePath) {
41
+ const rel = relative(rootPath, candidatePath);
42
+ return rel === '' || (!rel.startsWith(`..${sep}`) && rel !== '..' && !isAbsolute(rel));
43
+ }
44
+
45
+ export function loadPrivateExactTextDenylist({ root = process.cwd(), env = process.env } = {}) {
46
+ const values = [];
47
+ const inlineJson = env[PUBLIC_DENYLIST_JSON_ENV];
48
+ if (inlineJson) {
49
+ values.push(...parseExactValues(inlineJson, PUBLIC_DENYLIST_JSON_ENV));
50
+ }
51
+
52
+ const file = env[PUBLIC_DENYLIST_FILE_ENV];
53
+ if (file) {
54
+ if (!isAbsolute(file)) {
55
+ throw new Error(`${PUBLIC_DENYLIST_FILE_ENV} must point to an absolute path outside the repository`);
56
+ }
57
+ if (!existsSync(file)) {
58
+ throw new Error(`${PUBLIC_DENYLIST_FILE_ENV} does not exist`);
59
+ }
60
+ const rootPath = realpathSync(root);
61
+ const filePath = realpathSync(file);
62
+ if (isInsideRoot(rootPath, filePath)) {
63
+ throw new Error(`${PUBLIC_DENYLIST_FILE_ENV} must point outside the repository`);
64
+ }
65
+ values.push(...parseExactValues(readFileSync(filePath, 'utf8'), PUBLIC_DENYLIST_FILE_ENV));
66
+ }
67
+
68
+ return [...new Set(values)];
69
+ }
70
+
71
+ export function findPublicContentDenylistMatches(text, exactValues = [], { generic = true } = {}) {
72
+ const matches = [];
73
+ if (generic) {
74
+ for (const rule of genericPublicContentRules) {
75
+ if (rule.re.test(text)) matches.push(rule.name);
76
+ }
77
+ }
78
+ exactValues.forEach((value, index) => {
79
+ if (text.includes(value)) matches.push(`private exact text #${index + 1}`);
80
+ });
81
+ return [...new Set(matches)];
82
+ }
@@ -0,0 +1,53 @@
1
+ import assert from 'node:assert/strict';
2
+ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import test from 'node:test';
6
+
7
+ import {
8
+ PUBLIC_DENYLIST_FILE_ENV,
9
+ PUBLIC_DENYLIST_JSON_ENV,
10
+ findPublicContentDenylistMatches,
11
+ loadPrivateExactTextDenylist,
12
+ } from './public-content-denylist.mjs';
13
+
14
+ const PLACEHOLDER = 'DEPLOYMENT_ONLY_MARKER_ALPHA_42';
15
+
16
+ test('loads neutral exact text markers from CI JSON', () => {
17
+ const values = loadPrivateExactTextDenylist({
18
+ env: { [PUBLIC_DENYLIST_JSON_ENV]: JSON.stringify([PLACEHOLDER]) },
19
+ });
20
+ assert.deepEqual(values, [PLACEHOLDER]);
21
+ assert.deepEqual(findPublicContentDenylistMatches(`prefix ${PLACEHOLDER} suffix`, values), ['private exact text #1']);
22
+ });
23
+
24
+ test('loads neutral exact text markers from a repository-external file', () => {
25
+ const externalRoot = mkdtempSync(join(tmpdir(), 'bailinghub-denylist-test-'));
26
+ const file = join(externalRoot, 'denylist.json');
27
+ writeFileSync(file, JSON.stringify([PLACEHOLDER]));
28
+ try {
29
+ assert.deepEqual(loadPrivateExactTextDenylist({
30
+ root: process.cwd(),
31
+ env: { [PUBLIC_DENYLIST_FILE_ENV]: file },
32
+ }), [PLACEHOLDER]);
33
+ } finally {
34
+ rmSync(externalRoot, { recursive: true, force: true });
35
+ }
36
+ });
37
+
38
+ test('rejects a denylist file stored inside the repository', () => {
39
+ assert.throws(
40
+ () => loadPrivateExactTextDenylist({
41
+ root: process.cwd(),
42
+ env: { [PUBLIC_DENYLIST_FILE_ENV]: join(process.cwd(), 'package.json') },
43
+ }),
44
+ /must point outside the repository/,
45
+ );
46
+ });
47
+
48
+ test('keeps generic rules independent of deployment values', () => {
49
+ const marker = `github_pat_${'A'.repeat(24)}`;
50
+ const neutralUserPath = ['/Users', 'example', 'project', 'file.txt'].join('/');
51
+ assert.deepEqual(findPublicContentDenylistMatches(marker), ['GitHub personal access token']);
52
+ assert.deepEqual(findPublicContentDenylistMatches(neutralUserPath), ['local user absolute path']);
53
+ });
@@ -9,7 +9,7 @@ REGISTRY="${BAILING_IMAGE_REGISTRY:-$DEFAULT_REGISTRY}"
9
9
  NAMESPACE="${BAILING_IMAGE_NAMESPACE:-$DEFAULT_NAMESPACE}"
10
10
  PACKAGE_VERSION="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -1)"
11
11
  TAG="${BAILING_IMAGE_TAG:-$PACKAGE_VERSION}"
12
- [ -n "$TAG" ] || TAG="0.4.0"
12
+ [ -n "$TAG" ] || TAG="0.5.0"
13
13
  NODE_IMAGE="${BAILING_NODE_IMAGE:-node:22-bookworm-slim}"
14
14
  PLATFORM="${BAILING_IMAGE_PLATFORM:-linux/amd64}"
15
15
  PUSH="${BAILING_PUSH_IMAGES:-0}"
@@ -1,7 +1,10 @@
1
1
  import { execFileSync, spawnSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
 
4
+ import { findPublicContentDenylistMatches, loadPrivateExactTextDenylist } from './public-content-denylist.mjs';
5
+
4
6
  const findings = [];
7
+ const privateExactTextDenylist = loadPrivateExactTextDenylist();
5
8
  const requiredRepoFiles = [
6
9
  'README.md',
7
10
  'LICENSE',
@@ -32,7 +35,7 @@ const requiredRepoFiles = [
32
35
  'docs/RELEASE_NOTES_v0.3.2.md',
33
36
  'docs/RELEASE_NOTES_v0.3.3.md',
34
37
  'docs/RELEASE_NOTES_v0.3.4.md',
35
- 'docs/RELEASE_NOTES_v0.4.0.md',
38
+ 'docs/RELEASE_NOTES_v0.5.0.md',
36
39
  'docs/CHANGELOG.md',
37
40
  'docs/CLIENT_API.md',
38
41
  'config.example.json',
@@ -201,7 +204,9 @@ function assertSdkMetadata() {
201
204
  'sdk/node/src/index.mjs',
202
205
  'sdk/python/bailing_connect/__init__.py',
203
206
  'sdk/php/src/HubClient.php',
207
+ 'sdk/php/src/AgentAuth.php',
204
208
  'sdk/php7/src/HubClient.php',
209
+ 'sdk/php7/src/AgentAuth.php',
205
210
  'sdk/java/src/main/java/com/bailing/connect/BailingConnect.java',
206
211
  'sdk/go/bailingconnect/connect.go',
207
212
  'sdk/dotnet/Bailing.Connect/BailingConnect.cs',
@@ -247,7 +252,6 @@ function packageFiles() {
247
252
  return dryRunPackageManifest.files.map((file) => String(file.path ?? ''));
248
253
  }
249
254
 
250
- const rx = (parts, flags = '') => new RegExp(parts.join(''), flags);
251
255
 
252
256
  assertPackageMetadata();
253
257
  assertRepoEntrance();
@@ -294,15 +298,6 @@ try {
294
298
  }
295
299
 
296
300
  const textFiles = files.filter((file) => /\.(?:md|ts|tsx|js|mjs|json|sql|php|py|vue|html|css|sh|yml|yaml|txt)$/.test(file));
297
- const banned = [
298
- { name: 'local machine path', re: rx(['/Users/', 'macmini', '|', '项目', '\\/www']) },
299
- { name: 'known leaked password', re: rx(['Nie', '0712', '\\.\\.']) },
300
- { name: 'known managed MySQL host', re: rx(['sh-', 'cynosdb', 'mysql', '-[A-Za-z0-9.-]+', 'tencent', 'cdb\\.com']) },
301
- { name: 'known internal git token', re: rx(['pt', '-[A-Za-z0-9_-]{20,}']) },
302
- { name: 'GitHub PAT', re: rx(['github', '_pat', '_[A-Za-z0-9_]+']) },
303
- { name: 'old official domain', re: rx(['bailing\\.', 'bnopen', '\\.cn', '|', 'bnopen', '\\.cn']) },
304
- { name: 'legacy internal bucket example', re: /bainiancloud-\d+/ },
305
- ];
306
301
  const forbiddenPublicWording = new RegExp([
307
302
  '商业' + '版',
308
303
  '商业' + '扩展',
@@ -327,8 +322,8 @@ try {
327
322
  } catch {
328
323
  continue;
329
324
  }
330
- for (const rule of banned) {
331
- if (rule.re.test(text)) findings.push(`${file}: ${rule.name}`);
325
+ for (const match of findPublicContentDenylistMatches(text, privateExactTextDenylist)) {
326
+ findings.push(`${file}: ${match}`);
332
327
  }
333
328
  if (file !== 'LICENSE' && forbiddenPublicWording.test(text)) {
334
329
  findings.push(`${file}: use neutral public wording for private extension boundaries`);