agentworkshop 0.5.5 → 0.5.6

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 (46) hide show
  1. package/.AgentWorkShop/prompts/compaction-hints.md +9 -0
  2. package/.AgentWorkShop/prompts/host-tools.json +664 -630
  3. package/.AgentWorkShop/prompts/peer-reply-cross-channel.md +10 -0
  4. package/.AgentWorkShop/prompts/system-manual.md +6 -1
  5. package/.output/.AgentWorkShop/prompts/compaction-hints.md +9 -0
  6. package/.output/.AgentWorkShop/prompts/host-tools.json +664 -630
  7. package/.output/.AgentWorkShop/prompts/peer-reply-cross-channel.md +10 -0
  8. package/.output/.AgentWorkShop/prompts/system-manual.md +6 -1
  9. package/.output/nitro.json +1 -1
  10. package/.output/public/_nuxt/builds/latest.json +1 -1
  11. package/.output/public/_nuxt/builds/meta/d50c6ec2-801c-4ba2-97d8-a4db401b702c.json +1 -0
  12. package/.output/server/chunks/_/nitro.mjs +1920 -1211
  13. package/.output/server/chunks/_/nitro.mjs.map +1 -1
  14. package/.output/server/chunks/routes/api/workshop/channels/_id/index3.post.mjs +25 -3
  15. package/.output/server/chunks/routes/api/workshop/channels/_id/index3.post.mjs.map +1 -1
  16. package/.output/server/package.json +1 -1
  17. package/package.json +1 -1
  18. package/scripts/_dbg-cross-channel-e2e.mjs +157 -0
  19. package/scripts/test-context-governor.ts +176 -0
  20. package/scripts/test-memory-brief-chronicle.ts +180 -0
  21. package/scripts/test-memory-dynamic.ts +3 -1
  22. package/scripts/test-memory-rrf-mmr.ts +114 -0
  23. package/server/api/workshop/channels/[id]/messages/index.post.ts +26 -1
  24. package/server/api/workshop/ws.ts +1 -0
  25. package/server/data/daqs.json +35 -13
  26. package/server/data/dcw-lines.json +14 -0
  27. package/server/data/dcw-products.json +14 -0
  28. package/server/data/dcw-recipes.json +28 -0
  29. package/server/data/dcw-rollback.json +122 -1
  30. package/server/data/dcw-runs.json +54 -36
  31. package/server/data/dcw-writes.json +60 -0
  32. package/server/data/dcws.json +42 -0
  33. package/server/data/line-runs.json +32 -22
  34. package/server/services/workshop/agents/adapters/omp-rpc-client.ts +65 -0
  35. package/server/services/workshop/agents/agent-interface.ts +26 -1
  36. package/server/services/workshop/agents/mock-agent.ts +12 -0
  37. package/server/services/workshop/agents/omp-agent.ts +277 -8
  38. package/server/services/workshop/db/database.ts +16 -1
  39. package/server/services/workshop/db/memory.repo.ts +22 -2
  40. package/server/services/workshop/prompts/loader.ts +6 -5
  41. package/server/services/workshop/runtime/agent-runtime.ts +52 -6
  42. package/server/services/workshop/runtime/channel-runtime.ts +14 -6
  43. package/server/services/workshop/runtime/manager.ts +192 -3
  44. package/server/services/workshop/runtime/memory.ts +313 -78
  45. package/server/services/workshop/types/task.ts +14 -0
  46. package/.output/public/_nuxt/builds/meta/f2f649c5-fd3b-4507-a3a1-8b4a194de72d.json +0 -1
@@ -3026,6 +3026,63 @@
3026
3026
  "id": "anc-f709106f",
3027
3027
  "at": "2026-09-02T10:39:20.183Z",
3028
3028
  "recordId": "opt-1ad7ec25"
3029
+ },
3030
+ {
3031
+ "lineId": "ln-af1e04a3",
3032
+ "nodeId": "dw-e760b6b0",
3033
+ "prevValue": null,
3034
+ "newValue": 180,
3035
+ "source": "recipe",
3036
+ "actor": "recipe",
3037
+ "recipeRunId": "rr-63af7723",
3038
+ "id": "anc-fbdebff4",
3039
+ "at": "2026-09-02T11:40:28.861Z"
3040
+ },
3041
+ {
3042
+ "lineId": "ln-af1e04a3",
3043
+ "nodeId": "dw-e760b6b0",
3044
+ "prevValue": 180,
3045
+ "newValue": 182,
3046
+ "source": "manual",
3047
+ "actor": "c2413698-6f6a-424e-b1fc-dcf352b069ca",
3048
+ "recipeRunId": null,
3049
+ "id": "anc-25070300",
3050
+ "at": "2026-09-02T11:40:33.958Z"
3051
+ },
3052
+ {
3053
+ "lineId": "ln-af1e04a3",
3054
+ "nodeId": "dw-e760b6b0",
3055
+ "prevValue": 182,
3056
+ "newValue": 180,
3057
+ "source": "manual",
3058
+ "actor": "c2413698-6f6a-424e-b1fc-dcf352b069ca",
3059
+ "recipeRunId": null,
3060
+ "id": "anc-6f512745",
3061
+ "at": "2026-09-02T11:40:34.111Z"
3062
+ },
3063
+ {
3064
+ "lineId": "ln-af1e04a3",
3065
+ "nodeId": "dw-e760b6b0",
3066
+ "prevValue": 180,
3067
+ "newValue": 182,
3068
+ "source": "agent",
3069
+ "actor": "32423684-ffa6-4d61-a926-9db901993a6c",
3070
+ "recipeRunId": null,
3071
+ "taskId": "950d501b-3b33-4cf1-9e19-c4123b3b0cd1",
3072
+ "id": "anc-394b03d4",
3073
+ "at": "2026-09-02T11:42:48.425Z",
3074
+ "recordId": "opt-97a03904"
3075
+ },
3076
+ {
3077
+ "lineId": "ln-c1ef6c0d",
3078
+ "nodeId": "dw-4bcbc922",
3079
+ "prevValue": null,
3080
+ "newValue": 180,
3081
+ "source": "recipe",
3082
+ "actor": "recipe",
3083
+ "recipeRunId": "rr-4549422d",
3084
+ "id": "anc-6825e0d2",
3085
+ "at": "2026-09-02T11:55:28.883Z"
3029
3086
  }
3030
3087
  ],
3031
3088
  "records": [
@@ -3417,7 +3474,7 @@
3417
3474
  "channels": [],
3418
3475
  "degraded": true
3419
3476
  },
3420
- "evaluatedAt": "2026-09-02T10:43:15.492Z",
3477
+ "evaluatedAt": "2026-09-02T12:07:31.704Z",
3421
3478
  "windowAgg": {
3422
3479
  "at": "2026-08-31T16:25:17.398Z",
3423
3480
  "fromMs": 1788193396897,
@@ -9693,6 +9750,70 @@
9693
9750
  "closedAt": "2026-09-02T10:42:58.683Z",
9694
9751
  "closedBy": "judged",
9695
9752
  "aggPending": false
9753
+ },
9754
+ {
9755
+ "lineId": "ln-af1e04a3",
9756
+ "nodeId": "dw-e760b6b0",
9757
+ "nodeName": "FFX-温度设定",
9758
+ "recipeId": "rc-53194df4",
9759
+ "agentId": "32423684-ffa6-4d61-a926-9db901993a6c",
9760
+ "taskId": "950d501b-3b33-4cf1-9e19-c4123b3b0cd1",
9761
+ "hypothesis": "任务要求将温度设定调至 182℃。近 5 分钟实测温度均值仅 168.177℃(最低 165.1,最新 170.6),与目标 182℃ 偏差 13.8℃,判定为欠温。设定从 180→182℃(+2℃,安全量程 150~200 ∩ 配方窗口 176~188 内),热惯性数十秒级,预期 5 分钟后实际温度向 182℃ 逼近,届时复测 daq 验证并落判定。",
9762
+ "params": [
9763
+ {
9764
+ "nodeId": "dw-e760b6b0",
9765
+ "templateRef": "dcw-temp-sp",
9766
+ "from": 180,
9767
+ "to": 182
9768
+ }
9769
+ ],
9770
+ "setAt": "2026-09-02T11:42:48.425Z",
9771
+ "status": "closed-line-stop",
9772
+ "judge": null,
9773
+ "anchorId": "anc-394b03d4",
9774
+ "policy": "approve_rollback",
9775
+ "id": "opt-97a03904",
9776
+ "createdAt": "2026-09-02T11:42:48.425Z",
9777
+ "baseline": {
9778
+ "at": "2026-09-02T11:42:48.456Z",
9779
+ "fromMs": 1788348768425,
9780
+ "toMs": 1788349368425,
9781
+ "channels": [
9782
+ {
9783
+ "daqNodeId": "dn-f46e2df5",
9784
+ "ch": "temp-tc",
9785
+ "unit": "℃",
9786
+ "latest": 166.5,
9787
+ "avg": 167.99,
9788
+ "min": 165.73,
9789
+ "max": 170.67,
9790
+ "cnt": 47,
9791
+ "breaches": 0
9792
+ },
9793
+ {
9794
+ "daqNodeId": "dn-0d9b7e8e",
9795
+ "ch": "pressure-tx",
9796
+ "unit": "MPa",
9797
+ "latest": 0.7866666666666667,
9798
+ "avg": 0.82,
9799
+ "min": 0.78,
9800
+ "max": 0.86,
9801
+ "cnt": 47,
9802
+ "breaches": -1
9803
+ }
9804
+ ]
9805
+ },
9806
+ "evaluatedAt": "2026-09-02T11:48:49.649Z",
9807
+ "windowAgg": {
9808
+ "at": "2026-09-02T11:48:49.964Z",
9809
+ "fromMs": 1788349368425,
9810
+ "toMs": 1788349729964,
9811
+ "channels": [],
9812
+ "degraded": true
9813
+ },
9814
+ "closedAt": "2026-09-02T11:48:49.964Z",
9815
+ "closedBy": "line-stop",
9816
+ "aggPending": false
9696
9817
  }
9697
9818
  ]
9698
9819
  }
@@ -1,40 +1,4 @@
1
1
  [
2
- {
3
- "id": "rr-c8ccb1f5",
4
- "recipeId": "rc-3b094c50",
5
- "recipeName": "终审配方A",
6
- "productId": "pd-b9a585f7",
7
- "lineId": "ln-cd6402cc",
8
- "startedAt": "2026-08-29T15:14:14.982Z",
9
- "endedAt": "2026-08-29T15:14:32.369Z",
10
- "results": [
11
- {
12
- "templateRef": "dcw-temp-sp",
13
- "nodeId": "dw-1740a6f5",
14
- "ok": true,
15
- "message": "写入并回读一致:182 → raw 1280,回读 182(标定后物理值 182)",
16
- "value": 182
17
- }
18
- ]
19
- },
20
- {
21
- "id": "rr-ff58554d",
22
- "recipeId": "rc-49a15b8f",
23
- "recipeName": "终审配方A",
24
- "productId": "pd-82dd3f92",
25
- "lineId": "ln-1d5c8bb9",
26
- "startedAt": "2026-08-29T15:15:06.137Z",
27
- "endedAt": "2026-08-29T15:15:23.589Z",
28
- "results": [
29
- {
30
- "templateRef": "dcw-temp-sp",
31
- "nodeId": "dw-5dcf6dd1",
32
- "ok": true,
33
- "message": "写入并回读一致:182 → raw 1280,回读 182(标定后物理值 182)",
34
- "value": 182
35
- }
36
- ]
37
- },
38
2
  {
39
3
  "id": "rr-5fc104fc",
40
4
  "recipeId": "rc-cc5d88b8",
@@ -4740,5 +4704,59 @@
4740
4704
  "max": 188
4741
4705
  }
4742
4706
  ]
4707
+ },
4708
+ {
4709
+ "id": "rr-63af7723",
4710
+ "recipeId": "rc-53194df4",
4711
+ "recipeName": "全功能配方-3lqwow",
4712
+ "productId": "pd-765f8dfb",
4713
+ "lineId": "ln-af1e04a3",
4714
+ "startedAt": "2026-09-02T11:40:28.720Z",
4715
+ "endedAt": "2026-09-02T11:48:49.963Z",
4716
+ "results": [
4717
+ {
4718
+ "templateRef": "dcw-temp-sp",
4719
+ "nodeId": "dw-e760b6b0",
4720
+ "ok": true,
4721
+ "message": "Mock PLC 写入成功:180 → raw 180,回读一致(标定后物理值 180)",
4722
+ "value": 180
4723
+ }
4724
+ ],
4725
+ "paramsSnapshot": [
4726
+ {
4727
+ "nodeId": "dw-e760b6b0",
4728
+ "templateRef": "dcw-temp-sp",
4729
+ "value": 180,
4730
+ "min": 176,
4731
+ "max": 188
4732
+ }
4733
+ ]
4734
+ },
4735
+ {
4736
+ "id": "rr-4549422d",
4737
+ "recipeId": "rc-ed3e066e",
4738
+ "recipeName": "̽���䷽",
4739
+ "productId": "pd-efb05c40",
4740
+ "lineId": "ln-c1ef6c0d",
4741
+ "startedAt": "2026-09-02T11:55:28.775Z",
4742
+ "endedAt": null,
4743
+ "results": [
4744
+ {
4745
+ "templateRef": "dcw-temp-sp",
4746
+ "nodeId": "dw-4bcbc922",
4747
+ "ok": true,
4748
+ "message": "Mock PLC 写入成功:180 → raw 180,回读一致(标定后物理值 180)",
4749
+ "value": 180
4750
+ }
4751
+ ],
4752
+ "paramsSnapshot": [
4753
+ {
4754
+ "nodeId": "dw-4bcbc922",
4755
+ "templateRef": "dcw-temp-sp",
4756
+ "value": 180,
4757
+ "min": 176,
4758
+ "max": 188
4759
+ }
4760
+ ]
4743
4761
  }
4744
4762
  ]
@@ -9910,5 +9910,65 @@
9910
9910
  "message": "Mock PLC 写入成功:182 → raw 182,回读一致(标定后物理值 182)",
9911
9911
  "recipeRunId": null,
9912
9912
  "at": "2026-09-02T10:39:20.083Z"
9913
+ },
9914
+ {
9915
+ "id": "wh-f3d044f9",
9916
+ "nodeId": "dw-e760b6b0",
9917
+ "nodeName": "FFX-温度设定",
9918
+ "param": "烘箱温度设定",
9919
+ "eng": 180,
9920
+ "raw": 180,
9921
+ "ok": true,
9922
+ "message": "Mock PLC 写入成功:180 → raw 180,回读一致(标定后物理值 180)",
9923
+ "recipeRunId": "rr-63af7723",
9924
+ "at": "2026-09-02T11:40:28.724Z"
9925
+ },
9926
+ {
9927
+ "id": "wh-18b01c04",
9928
+ "nodeId": "dw-e760b6b0",
9929
+ "nodeName": "FFX-温度设定",
9930
+ "param": "烘箱温度设定",
9931
+ "eng": 182,
9932
+ "raw": 182,
9933
+ "ok": true,
9934
+ "message": "Mock PLC 写入成功:182 → raw 182,回读一致(标定后物理值 182)",
9935
+ "recipeRunId": null,
9936
+ "at": "2026-09-02T11:40:33.852Z"
9937
+ },
9938
+ {
9939
+ "id": "wh-9172dfae",
9940
+ "nodeId": "dw-e760b6b0",
9941
+ "nodeName": "FFX-温度设定",
9942
+ "param": "烘箱温度设定",
9943
+ "eng": 180,
9944
+ "raw": 180,
9945
+ "ok": true,
9946
+ "message": "Mock PLC 写入成功:180 → raw 180,回读一致(标定后物理值 180)",
9947
+ "recipeRunId": null,
9948
+ "at": "2026-09-02T11:40:33.978Z"
9949
+ },
9950
+ {
9951
+ "id": "wh-636c05af",
9952
+ "nodeId": "dw-e760b6b0",
9953
+ "nodeName": "FFX-温度设定",
9954
+ "param": "烘箱温度设定",
9955
+ "eng": 182,
9956
+ "raw": 182,
9957
+ "ok": true,
9958
+ "message": "Mock PLC 写入成功:182 → raw 182,回读一致(标定后物理值 182)",
9959
+ "recipeRunId": null,
9960
+ "at": "2026-09-02T11:42:48.318Z"
9961
+ },
9962
+ {
9963
+ "id": "wh-db091e26",
9964
+ "nodeId": "dw-4bcbc922",
9965
+ "nodeName": "̽���趨",
9966
+ "param": "烘箱温度设定",
9967
+ "eng": 180,
9968
+ "raw": 180,
9969
+ "ok": true,
9970
+ "message": "Mock PLC 写入成功:180 → raw 180,回读一致(标定后物理值 180)",
9971
+ "recipeRunId": "rr-4549422d",
9972
+ "at": "2026-09-02T11:55:28.777Z"
9913
9973
  }
9914
9974
  ]
@@ -2047,5 +2047,47 @@
2047
2047
  "state": "ok",
2048
2048
  "lastError": null,
2049
2049
  "createdAt": "2026-09-02T10:37:43.697Z"
2050
+ },
2051
+ {
2052
+ "id": "dw-e760b6b0",
2053
+ "templateRef": "dcw-temp-sp",
2054
+ "name": "FFX-温度设定",
2055
+ "driver": "mock",
2056
+ "enabled": true,
2057
+ "holdIntervalMs": null,
2058
+ "unit": "℃",
2059
+ "decimals": 1,
2060
+ "min": 150,
2061
+ "max": 200,
2062
+ "deviceBindingId": null,
2063
+ "driverConfig": {},
2064
+ "lineId": "ln-af1e04a3",
2065
+ "value": 182,
2066
+ "lastAckAt": "2026-09-02T11:42:48.318Z",
2067
+ "lastWriteAt": "2026-09-02T11:42:48.318Z",
2068
+ "state": "ok",
2069
+ "lastError": null,
2070
+ "createdAt": "2026-09-02T11:40:28.553Z"
2071
+ },
2072
+ {
2073
+ "id": "dw-4bcbc922",
2074
+ "templateRef": "dcw-temp-sp",
2075
+ "name": "̽���趨",
2076
+ "driver": "mock",
2077
+ "enabled": true,
2078
+ "holdIntervalMs": null,
2079
+ "unit": "℃",
2080
+ "decimals": 1,
2081
+ "min": 150,
2082
+ "max": 200,
2083
+ "deviceBindingId": null,
2084
+ "driverConfig": {},
2085
+ "lineId": "ln-c1ef6c0d",
2086
+ "value": 180,
2087
+ "lastAckAt": "2026-09-02T11:55:28.777Z",
2088
+ "lastWriteAt": "2026-09-02T11:55:28.777Z",
2089
+ "state": "ok",
2090
+ "lastError": null,
2091
+ "createdAt": "2026-09-02T11:55:28.447Z"
2050
2092
  }
2051
2093
  ]
@@ -7,7 +7,7 @@
7
7
  "productId": "pd-3ad54846",
8
8
  "productName": "光学膜 BOPP",
9
9
  "startedAt": "2026-08-31T16:20:13.707Z",
10
- "taggedSamples": 34566
10
+ "taggedSamples": 34570
11
11
  },
12
12
  {
13
13
  "lineId": "ln-c377a6bf",
@@ -17,7 +17,7 @@
17
17
  "productId": "pd-7e69e0ee",
18
18
  "productName": "警告验证产品-k2xh",
19
19
  "startedAt": "2026-09-01T03:23:18.233Z",
20
- "taggedSamples": 14092
20
+ "taggedSamples": 14094
21
21
  },
22
22
  {
23
23
  "lineId": "ln-9224d3d7",
@@ -27,7 +27,7 @@
27
27
  "productId": "pd-910c0fa8",
28
28
  "productName": "新协议产品-9xhn",
29
29
  "startedAt": "2026-09-01T05:59:24.062Z",
30
- "taggedSamples": 17074
30
+ "taggedSamples": 17076
31
31
  },
32
32
  {
33
33
  "lineId": "ln-386c53ed",
@@ -37,7 +37,7 @@
37
37
  "productId": "pd-2d4f9357",
38
38
  "productName": "新协议产品-6ofk",
39
39
  "startedAt": "2026-09-01T06:05:53.063Z",
40
- "taggedSamples": 17363
40
+ "taggedSamples": 17365
41
41
  },
42
42
  {
43
43
  "lineId": "ln-5957f6db",
@@ -47,7 +47,7 @@
47
47
  "productId": "pd-a3ed5047",
48
48
  "productName": "新协议产品-x4hd",
49
49
  "startedAt": "2026-09-01T06:09:02.148Z",
50
- "taggedSamples": 16949
50
+ "taggedSamples": 16951
51
51
  },
52
52
  {
53
53
  "lineId": "ln-9ec42f08",
@@ -57,7 +57,7 @@
57
57
  "productId": "pd-5de729c0",
58
58
  "productName": "新协议产品-teti",
59
59
  "startedAt": "2026-09-01T06:13:44.315Z",
60
- "taggedSamples": 16928
60
+ "taggedSamples": 16930
61
61
  },
62
62
  {
63
63
  "lineId": "ln-69e37924",
@@ -67,7 +67,7 @@
67
67
  "productId": "pd-45eb8d43",
68
68
  "productName": "新协议产品-fg8t",
69
69
  "startedAt": "2026-09-01T06:16:47.469Z",
70
- "taggedSamples": 16961
70
+ "taggedSamples": 16963
71
71
  },
72
72
  {
73
73
  "lineId": "ln-c269e692",
@@ -77,7 +77,7 @@
77
77
  "productId": "pd-b3bd0191",
78
78
  "productName": "新协议产品-w2sp",
79
79
  "startedAt": "2026-09-01T06:56:05.893Z",
80
- "taggedSamples": 17012
80
+ "taggedSamples": 17014
81
81
  },
82
82
  {
83
83
  "lineId": "ln-229d1637",
@@ -87,7 +87,7 @@
87
87
  "productId": "pd-06b896f9",
88
88
  "productName": "新协议产品-lp4h",
89
89
  "startedAt": "2026-09-01T06:57:29.288Z",
90
- "taggedSamples": 16884
90
+ "taggedSamples": 16886
91
91
  },
92
92
  {
93
93
  "lineId": "ln-9546f91f",
@@ -97,7 +97,7 @@
97
97
  "productId": "pd-53e55078",
98
98
  "productName": "新协议产品-jri6",
99
99
  "startedAt": "2026-09-01T07:00:25.059Z",
100
- "taggedSamples": 16307
100
+ "taggedSamples": 16309
101
101
  },
102
102
  {
103
103
  "lineId": "ln-087aad5b",
@@ -107,7 +107,7 @@
107
107
  "productId": "pd-e7e969af",
108
108
  "productName": "新协议产品-4c2d",
109
109
  "startedAt": "2026-09-01T07:09:07.307Z",
110
- "taggedSamples": 15299
110
+ "taggedSamples": 15301
111
111
  },
112
112
  {
113
113
  "lineId": "ln-97d44f8a",
@@ -117,7 +117,7 @@
117
117
  "productId": "pd-28a3ab2c",
118
118
  "productName": "新协议产品-b2ni",
119
119
  "startedAt": "2026-09-01T07:13:44.912Z",
120
- "taggedSamples": 15148
120
+ "taggedSamples": 15150
121
121
  },
122
122
  {
123
123
  "lineId": "ln-a9551770",
@@ -127,7 +127,7 @@
127
127
  "productId": "pd-0c6a64c8",
128
128
  "productName": "新协议产品-uwkf",
129
129
  "startedAt": "2026-09-01T07:15:40.113Z",
130
- "taggedSamples": 14793
130
+ "taggedSamples": 14795
131
131
  },
132
132
  {
133
133
  "lineId": "ln-844ad82f",
@@ -137,7 +137,7 @@
137
137
  "productId": "pd-6932b24f",
138
138
  "productName": "新协议产品-kk6l",
139
139
  "startedAt": "2026-09-01T09:06:55.728Z",
140
- "taggedSamples": 12948
140
+ "taggedSamples": 12950
141
141
  },
142
142
  {
143
143
  "lineId": "ln-af002514",
@@ -147,7 +147,7 @@
147
147
  "productId": "pd-6348a595",
148
148
  "productName": "0.8mm 光学膜",
149
149
  "startedAt": "2026-09-01T14:06:28.766Z",
150
- "taggedSamples": 5772
150
+ "taggedSamples": 5780
151
151
  },
152
152
  {
153
153
  "lineId": "ln-0eccf6ba",
@@ -157,7 +157,7 @@
157
157
  "productId": "pd-4b71be77",
158
158
  "productName": "哨兵产品-mtjku36w",
159
159
  "startedAt": "2026-09-02T04:09:11.482Z",
160
- "taggedSamples": 1213
160
+ "taggedSamples": 1215
161
161
  },
162
162
  {
163
163
  "lineId": "ln-e984246e",
@@ -167,7 +167,7 @@
167
167
  "productId": "pd-bb1e0bed",
168
168
  "productName": "产品C-mtjkwyhu",
169
169
  "startedAt": "2026-09-02T04:11:26.583Z",
170
- "taggedSamples": 1212
170
+ "taggedSamples": 1214
171
171
  },
172
172
  {
173
173
  "lineId": "ln-1fe0b5bc",
@@ -177,7 +177,7 @@
177
177
  "productId": "pd-9f2d9507",
178
178
  "productName": "产品D-mtjkzcfr",
179
179
  "startedAt": "2026-09-02T04:13:17.902Z",
180
- "taggedSamples": 1211
180
+ "taggedSamples": 1213
181
181
  },
182
182
  {
183
183
  "lineId": "ln-d826473e",
@@ -187,7 +187,7 @@
187
187
  "productId": "pd-d230255e",
188
188
  "productName": "产品E-mtjl43pv",
189
189
  "startedAt": "2026-09-02T04:16:59.891Z",
190
- "taggedSamples": 1210
190
+ "taggedSamples": 1212
191
191
  },
192
192
  {
193
193
  "lineId": "ln-156abb71",
@@ -197,7 +197,7 @@
197
197
  "productId": "pd-6065b4ba",
198
198
  "productName": "产品F-mtjl60qf",
199
199
  "startedAt": "2026-09-02T04:18:29.340Z",
200
- "taggedSamples": 1209
200
+ "taggedSamples": 1211
201
201
  },
202
202
  {
203
203
  "lineId": "ln-bac43927",
@@ -207,7 +207,7 @@
207
207
  "productId": "pd-52f54e33",
208
208
  "productName": "产品G-mtjl98nl",
209
209
  "startedAt": "2026-09-02T04:20:59.682Z",
210
- "taggedSamples": 1208
210
+ "taggedSamples": 1210
211
211
  },
212
212
  {
213
213
  "lineId": "ln-f223008a",
@@ -217,6 +217,16 @@
217
217
  "productId": "pd-d919d4bf",
218
218
  "productName": "产品-mtjo000v",
219
219
  "startedAt": "2026-09-02T05:37:50.743Z",
220
- "taggedSamples": 1207
220
+ "taggedSamples": 1209
221
+ },
222
+ {
223
+ "lineId": "ln-c1ef6c0d",
224
+ "runId": "rr-4549422d",
225
+ "recipeId": "rc-ed3e066e",
226
+ "recipeName": "̽���䷽",
227
+ "productId": "pd-efb05c40",
228
+ "productName": "���̽��Ʒ",
229
+ "startedAt": "2026-09-02T11:55:28.775Z",
230
+ "taggedSamples": 0
221
231
  }
222
232
  ]
@@ -27,6 +27,27 @@ export type RpcCommand
27
27
  | { id?: string, type: 'set_model', provider: string, modelId: string }
28
28
  | { id?: string, type: 'get_state' }
29
29
  | { id?: string, type: 'new_session' }
30
+ // ===== 上下文治理(70% 压缩环;协议权威 omp://rpc.md)=====
31
+ | { id?: string, type: 'get_session_stats' }
32
+ | { id?: string, type: 'compact', customInstructions?: string }
33
+ | { id?: string, type: 'set_auto_compaction', enabled: boolean }
34
+
35
+ /** compaction 结果(compaction_end 事件 / compact 响应 data.result 共用形状) */
36
+ export interface CompactionResult {
37
+ summary?: string
38
+ tokensBefore?: number
39
+ tokensAfter?: number
40
+ estimatedTokensAfter?: number
41
+ }
42
+
43
+ /** provider 用量(被动上下文跟踪源;message_update 等帧携带的累计值) */
44
+ export interface RpcUsage {
45
+ /** input tokens ≈ 当前上下文长度(本回合 LLM 调用的 prompt 规模) */
46
+ input: number
47
+ output?: number
48
+ cacheRead?: number
49
+ at: number
50
+ }
30
51
  /** host 工具定义(omp 端可见的工具 schema) */
31
52
  export interface RpcHostToolDefinition {
32
53
  name: string
@@ -137,6 +158,11 @@ export class OmpRpcClient {
137
158
  private readonly pending = new Map<string, PendingRequest>()
138
159
  private seq = 0
139
160
 
161
+ /** 被动上下文跟踪:最近一次帧携带的累计 provider usage(get_session_stats 不可用时的兜底源) */
162
+ private lastUsage: RpcUsage | null = null
163
+ /** 上下文窗口大小(外部经 get_state 探测后注入;null = 未知,percent 不可算) */
164
+ private contextWindow: number | null = null
165
+
140
166
  private readonly eventListeners = new Set<(event: AgentSessionEvent) => void>()
141
167
  /** 原始帧 tap(chunk 重组后的每一帧,含 response/host_tool_call/extension_ui_request) */
142
168
  private readonly rawFrameListeners = new Set<(frame: Record<string, unknown>) => void>()
@@ -157,6 +183,41 @@ export class OmpRpcClient {
157
183
  return !!this.child && !this.exited
158
184
  }
159
185
 
186
+ /** 注入上下文窗口大小(get_state 探测 model.contextWindow 后调用;幂等) */
187
+ setContextWindow(tokens: number): void {
188
+ if (Number.isFinite(tokens) && tokens > 0) this.contextWindow = tokens
189
+ }
190
+
191
+ /** 被动上下文用量快照(无探测 RPC;数据来自最近一次携带 usage 的帧) */
192
+ getContextUsage(): { tokens: number, contextWindow: number | null, percent: number | null } | null {
193
+ if (!this.lastUsage) return null
194
+ const window = this.contextWindow
195
+ return {
196
+ tokens: this.lastUsage.input,
197
+ contextWindow: window,
198
+ percent: window && window > 0 ? Math.min(1, this.lastUsage.input / window) : null,
199
+ }
200
+ }
201
+
202
+ /**
203
+ * 从帧中防御性提取累计 usage(顶层 frame.usage 或 frame.message.usage;
204
+ * input 兼容 input/inputTokens/promptTokens 命名;无有效 input 返回 null)。
205
+ */
206
+ private extractUsage(frame: Record<string, unknown>): RpcUsage | null {
207
+ const raw = (frame.usage ?? (frame.message as Record<string, unknown> | undefined)?.usage) as Record<string, unknown> | undefined
208
+ if (!raw || typeof raw !== 'object') return null
209
+ const input = Number(raw.input ?? raw.inputTokens ?? raw.promptTokens)
210
+ if (!Number.isFinite(input) || input <= 0) return null
211
+ const output = Number(raw.output ?? raw.outputTokens)
212
+ const cacheRead = Number(raw.cacheRead)
213
+ return {
214
+ input,
215
+ output: Number.isFinite(output) ? output : undefined,
216
+ cacheRead: Number.isFinite(cacheRead) ? cacheRead : undefined,
217
+ at: Date.now(),
218
+ }
219
+ }
220
+
160
221
  /**
161
222
  * OS 级存活校准(系统休眠/强杀后 exit 事件可能不达,alive 会失真):
162
223
  * 按 PID 探 OS 实际存在性,进程已死则收敛为已退出(与 exit 事件同路径:
@@ -366,6 +427,10 @@ export class OmpRpcClient {
366
427
  private dispatchFrame(frame: Record<string, unknown>): void {
367
428
  const type = frame.type as string
368
429
 
430
+ // 被动上下文跟踪:任何帧携带累计 usage 都刷新最近值(零额外请求)
431
+ const usage = this.extractUsage(frame)
432
+ if (usage) this.lastUsage = usage
433
+
369
434
  // 原始帧镜像(终端 hub;listener 异常不影响协议处理)
370
435
  for (const fn of this.rawFrameListeners) {
371
436
  try {