sentinel-agentos 0.1.2 → 0.1.3

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 (3) hide show
  1. package/README.md +211 -7
  2. package/dist/cli.js +2 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -261,10 +261,12 @@ Total: 156 | Failures: 2 | High-Risk: 3
261
261
  ## 📦 安装 · Installation
262
262
 
263
263
  ```bash
264
- npm install @Sentinel AgentOS/core
264
+ npm install sentinel-agentos
265
265
  ```
266
266
 
267
- ⚠️ **npm 包尚未发布 · *not yet published***,当前从源码使用 · *use from source:*
267
+ 即可使用所有功能。
268
+
269
+ 如果从源码开发:
268
270
 
269
271
  ```bash
270
272
  git clone git@github.com:jishuanjimingtian/Sentinel AgentOS.git
@@ -278,7 +280,52 @@ npm run build # 编译到 dist/
278
280
 
279
281
  ## 🚀 使用说明 · Usage
280
282
 
281
- ### 基础用法 · Basic
283
+ ### 三种接入方式 · Three Integration Modes
284
+
285
+ Sentinel AgentOS 支持三种接入方式,从轻到重按需选择。
286
+
287
+ | 方式 | 适用场景 | 代码量 | 说明 |
288
+ |------|---------|--------|------|
289
+ | **CLI** | 快速测试 / CI/CD | 1 行命令 | 直接命令行检验工具调用 |
290
+ | **SDK** | 嵌入 Agent 框架 | 5 行代码 | `import { AgentOS }` 在进程内调用 |
291
+ | **HTTP API** | 跨语言 / 远程服务 | HTTP 请求 | 独立 HTTP 服务,任何语言都能调 |
292
+
293
+ ---
294
+
295
+ ### 方式一:CLI(命令行)
296
+
297
+ ```bash
298
+ # 安装
299
+ npm install -g sentinel-agentos
300
+
301
+ # 校验参数
302
+ sentinel-agentos validate exec command="rm -rf /"
303
+ sentinel-agentos validate write_file path=src/main.ts content="console.log(1)"
304
+
305
+ # 风险评分
306
+ sentinel-agentos risk exec command="sudo reboot"
307
+ sentinel-agentos risk exec command="npm test"
308
+
309
+ # 查看审计日志
310
+ sentinel-agentos audit --limit 10
311
+
312
+ # 查看状态报告
313
+ sentinel-agentos status
314
+
315
+ # 启动 HTTP 服务
316
+ sentinel-agentos server --port 3300 --token ***
317
+
318
+ # 查看帮助
319
+ sentinel-agentos help
320
+ ```
321
+
322
+ **支持的命令**:`validate` / `risk` / `audit` / `stats` / `profile` / `status` / `server` / `memory` / `help`
323
+
324
+ ---
325
+
326
+ ### 方式二:SDK(代码嵌入)
327
+
328
+ #### 2.1 基础用法 · Basic
282
329
 
283
330
  ```typescript
284
331
  import { AgentOS } from 'sentinel-agentos';
@@ -400,6 +447,163 @@ sandbox.validate('rm', { path: 'src/main.ts' });
400
447
  await sandbox.execute('exec', { command: 'npm test', cwd: process.cwd() });
401
448
  ```
402
449
 
450
+ #### 2.2 中间件(一行接入) · Middleware (one-liner)
451
+
452
+ ```typescript
453
+ import { wrapAgent } from 'sentinel-agentos';
454
+
455
+ // 一行接入——包裹你的 Agent 工具调用
456
+ const sentinel = wrapAgent({ workspaceRoot: process.cwd() });
457
+
458
+ // 每次工具调用前后调用即可
459
+ const { allowed, reason } = sentinel.preCheck('exec', { command: 'rm -rf /' });
460
+ // → { allowed: false, reason: 'Risk 9.18 → DENY' }
461
+ ```
462
+
463
+ #### 2.3 OpenClaw 插件
464
+
465
+ 如果你在用 OpenClaw Agent 框架,直接以插件形式集成:
466
+
467
+ ```typescript
468
+ import { sentinelPlugin } from 'sentinel-agentos';
469
+
470
+ // 注册为 OpenClaw 插件,自动 hook 所有工具调用
471
+ const plugin = sentinelPlugin({
472
+ workspaceRoot: process.cwd(),
473
+ preRegisteredRules: true,
474
+ });
475
+ // → onBeforeTool → 校验 + 风险评分
476
+ // → onAfterTool → 验证 + 审计
477
+ ```
478
+
479
+ ---
480
+
481
+ ### 方式三:HTTP API(远程调用,跨语言通用)
482
+
483
+ Sentinel AgentOS 可启动为独立 HTTP 服务,任何语言(Python/Go/Rust/Java...)都能调用。
484
+
485
+ #### 3.1 启动服务
486
+
487
+ ```bash
488
+ # CLI 一行启动
489
+ npx sentinel-agentos server --port 3300 --token ***
490
+
491
+ # 或代码中启动
492
+ import { createServer } from 'sentinel-agentos';
493
+ createServer({ port: 3300, apiToken: '***' }).start();
494
+ ```
495
+
496
+ 启动后健康检查(免 token):
497
+ ```bash
498
+ curl http://localhost:3300/health
499
+ # → {"ok":true,"uptime":12.3}
500
+ ```
501
+
502
+ #### 3.2 鉴权
503
+
504
+ 除 `/health` 外所有端点需要 `Authorization: Bearer <token>` header。否则返回 `401`。
505
+
506
+ #### 3.3 API 端点参考 · API Reference
507
+
508
+ **基础端点:**
509
+
510
+ | 端点 | 方法 | 鉴权 | 说明 |
511
+ |------|:--:|:--:|------|
512
+ | `/health` | GET | ❌ | 服务健康检查 |
513
+ | `/pipeline/pre` | POST | ✅ | 执行前校验(Schema + Risk + Snapshot) |
514
+ | `/pipeline/post` | POST | ✅ | 执行后验证(Verify + Audit + Feedback) |
515
+ | `/pipeline/report` | GET | ✅ | 质量状态报告(文本) |
516
+ | `/pipeline/profile` | GET | ✅ | 质量画像(JSON) |
517
+
518
+ **Guard / Memory / Feedback / Audit 端点:**
519
+
520
+ | 端点 | 方法 | 说明 |
521
+ |------|:--:|------|
522
+ | `/guard/schema` | POST | 注册 Schema 校验规则 |
523
+ | `/memory/preference` | POST | 设置用户偏好 `{"key":"language","value":"zh-CN"}` |
524
+ | `/memory/fact` | POST | 添加事实 `{"fact":"用户在上海"}` |
525
+ | `/memory/context` | GET | 获取当前记忆上下文 |
526
+ | `/feedback` | POST | 记录隐性反馈 `{"signal":"user_explicit_approval"}` |
527
+ | `/audit` | GET | 查询审计日志(支持 `?limit=&sessionId=&toolName=&status=`) |
528
+
529
+ **反馈信号类型:**
530
+
531
+ | 信号 | 强度 | 说明 |
532
+ |------|------|------|
533
+ | `user_explicit_approval` | +0.6 | 用户明确说"做得好" |
534
+ | `user_immediate_continue` | +0.3 | 用户立即继续对话 |
535
+ | `user_used_result` | +0.7 | 用户使用了 Agent 的结果 |
536
+ | `user_shared_output` | +0.8 | 用户分享了 Agent 输出 |
537
+ | `user_modified_output` | -0.5 | 用户修改了 Agent 输出 |
538
+ | `user_deleted_code` | -0.8 | 用户删除了 Agent 创建的代码 |
539
+ | `user_interrupted` | -0.6 | 用户打断了 Agent |
540
+ | `user_repeated_instruction` | -0.3 | 用户重复了相同指令 |
541
+
542
+ #### 3.4 完整调用示例
543
+
544
+ ```bash
545
+ # 1. Pre-exec — 校验 + 风险评分
546
+ curl -s -H "Authorization: Bearer $TOKEN" \
547
+ -X POST http://localhost:3300/pipeline/pre \
548
+ -H 'Content-Type: application/json' \
549
+ -d '{"toolName":"exec","parameters":{"command":"npm test"}}'
550
+ # → {"preExec":{"schemaCheck":{"pass":true},"riskScore":{"score":0.19,"action":"auto"}},"snapshot":{...}}
551
+
552
+ # 2. Post-exec — 验证 + 审计
553
+ # (传入 pre 返回的 snapshot)
554
+ curl -s -H "Authorization: Bearer $TOKEN" \
555
+ -X POST http://localhost:3300/pipeline/post \
556
+ -H 'Content-Type: application/json' \
557
+ -d '{"toolName":"exec","toolParameters":{"command":"npm test"},"toolResult":"all passed","snapshot":{...},"startTime":1718123456000,"endTime":1718123457000,"retryCount":0,"wasSelfCorrected":false,"hadTimeout":false,"userAccepted":true,"userProvidedEdit":false,"resultWasUsed":true}'
558
+
559
+ # 3. 查看报告
560
+ curl -s -H "Authorization: Bearer $TOKEN" http://localhost:3300/pipeline/report
561
+
562
+ # 4. 查询审计
563
+ curl -s -H "Authorization: Bearer $TOKEN" "http://localhost:3300/audit?limit=10&toolName=exec"
564
+
565
+ # 5. 记录反馈
566
+ curl -s -H "Authorization: Bearer $TOKEN" \
567
+ -X POST http://localhost:3300/feedback \
568
+ -H 'Content-Type: application/json' \
569
+ -d '{"signal":"user_immediate_continue","sessionId":"session_1"}'
570
+ ```
571
+
572
+ #### 3.5 跨语言(Python 示例)
573
+
574
+ ```python
575
+ import requests
576
+
577
+ BASE = "http://localhost:3300"
578
+ HEADERS = {"Authorization": "Bearer ***"}
579
+
580
+ # Pre-exec
581
+ resp = requests.post(f"{BASE}/pipeline/pre", json={
582
+ "toolName": "exec", "parameters": {"command": "npm test"}
583
+ }, headers=HEADERS)
584
+ data = resp.json()
585
+ print(f"Risk: {data['preExec']['riskScore']['score']} → {data['preExec']['riskScore']['action']}")
586
+
587
+ # Post-exec (pass snapshot from pre)
588
+ snapshot = data["snapshot"]
589
+ resp2 = requests.post(f"{BASE}/pipeline/post", json={
590
+ "toolName": "exec",
591
+ "toolParameters": {"command": "npm test"},
592
+ "toolResult": "all passed",
593
+ "snapshot": snapshot,
594
+ "startTime": 1718123456000, "endTime": 1718123457000,
595
+ "retryCount": 0, "wasSelfCorrected": False,
596
+ "hadTimeout": False, "userAccepted": True,
597
+ "userProvidedEdit": False, "resultWasUsed": True
598
+ }, headers=HEADERS)
599
+ print(f"Verify: {resp2.json()['postExec']['verifyPassed']}")
600
+
601
+ # Report
602
+ print(requests.get(f"{BASE}/pipeline/report", headers=HEADERS).text)
603
+ ```
604
+
605
+ ---
606
+
403
607
  ### API 层 · SDK API
404
608
 
405
609
  ```typescript
@@ -562,10 +766,10 @@ v1.0 已完成 100% 设计文档覆盖率、99 个测试全通过、TypeScript
562
766
  </details>
563
767
 
564
768
  <details>
565
- <summary><b>Q: npm 包什么时候发布? · When npm publish?</b></summary>
769
+ <summary><b>Q: npm 包已经发布了吗? · Is npm package published?</b></summary>
566
770
 
567
- TODO。当前可以直接 `git clone` + `npm link` 使用。
568
- *Currently use via `git clone` + `npm link`.*
771
+ 已发布。`npm install sentinel-agentos` 即可使用。当前版本 v0.1.x。
772
+ *Published. Just `npm install sentinel-agentos`. Current version v0.1.x.*
569
773
  </details>
570
774
 
571
775
  <details>
@@ -600,7 +804,7 @@ const entries = api.auditQuery({ minScore: 3.0 }); // 高风险操作 · High-ri
600
804
  | v0.3 | Memory 层(3 层)· *Memory layer (3 layers)* | ✅ |
601
805
  | v0.4 | Evaluator 层(评估 + 反馈 + 画像)· *Evaluator* | ✅ |
602
806
  | v1.0 | 沙箱 + API + x- 扩展 + 校验补齐 · *Sandbox + API + x-ext* | ✅ |
603
- | v1.1 | npm 发布 · *npm publish* | 📋 |
807
+ | v1.1 | npm 发布 + 三种接入方式 · *npm publish + 3 modes* | |
604
808
  | v2.0 | Docker 沙箱、Dashboard、SaaS · *Docker sandbox, Dashboard, SaaS* | 📋 |
605
809
 
606
810
  ---
package/dist/cli.js CHANGED
@@ -59,7 +59,7 @@ Usage:
59
59
  sentinel-agentos stats
60
60
  sentinel-agentos profile
61
61
  sentinel-agentos status
62
- sentinel-agentos server [--port N] [--token T]
62
+ sentinel-agentos server [--port N] [--token ***
63
63
  sentinel-agentos memory
64
64
  sentinel-agentos help
65
65
 
@@ -69,7 +69,7 @@ Examples:
69
69
  sentinel-agentos risk exec command="sudo reboot"
70
70
  sentinel-agentos audit --limit 10
71
71
  sentinel-agentos status
72
- sentinel-agentos server --port 3300 --token my-secret
72
+ sentinel-agentos server --port 3300 --token ***
73
73
  `);
74
74
  }
75
75
  function fatal(msg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sentinel-agentos",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Sentinel AgentOS — 确定性 Guard 层 + 分层记忆 + 自动评估,让任何 Agent 变得可靠、可审计、可改进",
5
5
  "keywords": [
6
6
  "agent",