shennian 0.5.41 → 0.5.43
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.
- package/dist/publish-build-manifest.json +92 -57
- package/dist/src/agents/config-status.js +1 -1
- package/dist/src/agents/model-registry/service.js +1 -1
- package/dist/src/agents/project-client.js +1 -1
- package/dist/src/agents/shennian.js +6 -3
- package/dist/src/commands/config.js +1 -1
- package/dist/src/commands/pair.js +11 -11
- package/dist/src/commands/project.js +4 -4
- package/dist/src/commands/schedule.js +1 -1
- package/dist/src/commands/steward.js +12 -10
- package/dist/src/commands/worker.js +2 -2
- package/dist/src/config/server-binding.js +1 -0
- package/dist/src/guides/collaboration.js +2 -2
- package/dist/src/index.js +3 -3
- package/dist/src/manager/direct-worker-notifications.js +2 -0
- package/dist/src/manager/registry.js +1 -1
- package/dist/src/manager/runtime.js +8 -7
- package/dist/src/manager/worker-ipc.js +3 -1
- package/dist/src/personal-agent/automatic-model.js +1 -0
- package/dist/src/personal-agent/model-settings.js +2 -2
- package/dist/src/personal-agent/official-credential.js +1 -1
- package/dist/src/personal-agent/sdk-session.js +2 -2
- package/dist/src/personal-agent/system-prompt.js +3 -0
- package/dist/src/personal-workspace/service.js +1 -1
- package/dist/src/schedules/personal-context.js +1 -1
- package/dist/src/schedules/server-client.js +1 -1
- package/dist/src/session/handlers/personal-workspace.js +1 -1
- package/dist/src/session/handlers/personal.js +1 -1
- package/dist/src/session/handlers/steward.js +1 -1
- package/dist/src/session/manager.js +1 -1
- package/dist/src/session/queue.js +1 -1
- package/dist/src/steward/context.js +7 -0
- package/dist/src/steward/project-event.js +3 -0
- package/dist/src/steward/session.js +2 -2
- package/dist/src/steward/templates.js +12 -5
- package/dist/src/steward/worker-settings.js +1 -0
- package/node_modules/@shennian/wire/dist/index.js +1 -1
- package/node_modules/@shennian/wire/dist/instance.js +1 -0
- package/node_modules/@shennian/wire/dist/message-payload.js +4 -4
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"jsMinified": true,
|
|
4
4
|
"minifier": "esbuild",
|
|
5
|
-
"fileCount":
|
|
5
|
+
"fileCount": 324,
|
|
6
6
|
"files": [
|
|
7
7
|
{
|
|
8
8
|
"file": "bin/shennian-adapter-host.js",
|
|
@@ -206,8 +206,8 @@
|
|
|
206
206
|
},
|
|
207
207
|
{
|
|
208
208
|
"file": "src/agents/config-status.js",
|
|
209
|
-
"beforeBytes":
|
|
210
|
-
"afterBytes":
|
|
209
|
+
"beforeBytes": 7856,
|
|
210
|
+
"afterBytes": 3924
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
213
|
"file": "src/agents/cursor-managed-permissions.js",
|
|
@@ -286,8 +286,8 @@
|
|
|
286
286
|
},
|
|
287
287
|
{
|
|
288
288
|
"file": "src/agents/model-registry/service.js",
|
|
289
|
-
"beforeBytes":
|
|
290
|
-
"afterBytes":
|
|
289
|
+
"beforeBytes": 9816,
|
|
290
|
+
"afterBytes": 3772
|
|
291
291
|
},
|
|
292
292
|
{
|
|
293
293
|
"file": "src/agents/model-registry/types.js",
|
|
@@ -371,8 +371,8 @@
|
|
|
371
371
|
},
|
|
372
372
|
{
|
|
373
373
|
"file": "src/agents/project-client.js",
|
|
374
|
-
"beforeBytes":
|
|
375
|
-
"afterBytes":
|
|
374
|
+
"beforeBytes": 3713,
|
|
375
|
+
"afterBytes": 2205
|
|
376
376
|
},
|
|
377
377
|
{
|
|
378
378
|
"file": "src/agents/public-agent-client.js",
|
|
@@ -421,8 +421,8 @@
|
|
|
421
421
|
},
|
|
422
422
|
{
|
|
423
423
|
"file": "src/agents/shennian.js",
|
|
424
|
-
"beforeBytes":
|
|
425
|
-
"afterBytes":
|
|
424
|
+
"beforeBytes": 9705,
|
|
425
|
+
"afterBytes": 5797
|
|
426
426
|
},
|
|
427
427
|
{
|
|
428
428
|
"file": "src/agents/spawn-errors.js",
|
|
@@ -471,8 +471,8 @@
|
|
|
471
471
|
},
|
|
472
472
|
{
|
|
473
473
|
"file": "src/commands/config.js",
|
|
474
|
-
"beforeBytes":
|
|
475
|
-
"afterBytes":
|
|
474
|
+
"beforeBytes": 2086,
|
|
475
|
+
"afterBytes": 1357
|
|
476
476
|
},
|
|
477
477
|
{
|
|
478
478
|
"file": "src/commands/contact.js",
|
|
@@ -566,13 +566,13 @@
|
|
|
566
566
|
},
|
|
567
567
|
{
|
|
568
568
|
"file": "src/commands/pair.js",
|
|
569
|
-
"beforeBytes":
|
|
570
|
-
"afterBytes":
|
|
569
|
+
"beforeBytes": 16861,
|
|
570
|
+
"afterBytes": 9246
|
|
571
571
|
},
|
|
572
572
|
{
|
|
573
573
|
"file": "src/commands/project.js",
|
|
574
|
-
"beforeBytes":
|
|
575
|
-
"afterBytes":
|
|
574
|
+
"beforeBytes": 8015,
|
|
575
|
+
"afterBytes": 5486
|
|
576
576
|
},
|
|
577
577
|
{
|
|
578
578
|
"file": "src/commands/queue.js",
|
|
@@ -601,8 +601,8 @@
|
|
|
601
601
|
},
|
|
602
602
|
{
|
|
603
603
|
"file": "src/commands/schedule.js",
|
|
604
|
-
"beforeBytes":
|
|
605
|
-
"afterBytes":
|
|
604
|
+
"beforeBytes": 1374,
|
|
605
|
+
"afterBytes": 1012
|
|
606
606
|
},
|
|
607
607
|
{
|
|
608
608
|
"file": "src/commands/setup.js",
|
|
@@ -616,8 +616,8 @@
|
|
|
616
616
|
},
|
|
617
617
|
{
|
|
618
618
|
"file": "src/commands/steward.js",
|
|
619
|
-
"beforeBytes":
|
|
620
|
-
"afterBytes":
|
|
619
|
+
"beforeBytes": 9020,
|
|
620
|
+
"afterBytes": 5725
|
|
621
621
|
},
|
|
622
622
|
{
|
|
623
623
|
"file": "src/commands/support.js",
|
|
@@ -636,14 +636,19 @@
|
|
|
636
636
|
},
|
|
637
637
|
{
|
|
638
638
|
"file": "src/commands/worker.js",
|
|
639
|
-
"beforeBytes":
|
|
640
|
-
"afterBytes":
|
|
639
|
+
"beforeBytes": 7805,
|
|
640
|
+
"afterBytes": 5146
|
|
641
641
|
},
|
|
642
642
|
{
|
|
643
643
|
"file": "src/config/index.js",
|
|
644
644
|
"beforeBytes": 2869,
|
|
645
645
|
"afterBytes": 1712
|
|
646
646
|
},
|
|
647
|
+
{
|
|
648
|
+
"file": "src/config/server-binding.js",
|
|
649
|
+
"beforeBytes": 678,
|
|
650
|
+
"afterBytes": 409
|
|
651
|
+
},
|
|
647
652
|
{
|
|
648
653
|
"file": "src/daemon-ipc/agent-readiness.js",
|
|
649
654
|
"beforeBytes": 5262,
|
|
@@ -731,8 +736,8 @@
|
|
|
731
736
|
},
|
|
732
737
|
{
|
|
733
738
|
"file": "src/guides/collaboration.js",
|
|
734
|
-
"beforeBytes":
|
|
735
|
-
"afterBytes":
|
|
739
|
+
"beforeBytes": 6864,
|
|
740
|
+
"afterBytes": 11935
|
|
736
741
|
},
|
|
737
742
|
{
|
|
738
743
|
"file": "src/guides/local-apps.js",
|
|
@@ -751,8 +756,8 @@
|
|
|
751
756
|
},
|
|
752
757
|
{
|
|
753
758
|
"file": "src/index.js",
|
|
754
|
-
"beforeBytes":
|
|
755
|
-
"afterBytes":
|
|
759
|
+
"beforeBytes": 45958,
|
|
760
|
+
"afterBytes": 22449
|
|
756
761
|
},
|
|
757
762
|
{
|
|
758
763
|
"file": "src/local-apps/service.js",
|
|
@@ -769,6 +774,11 @@
|
|
|
769
774
|
"beforeBytes": 2022,
|
|
770
775
|
"afterBytes": 970
|
|
771
776
|
},
|
|
777
|
+
{
|
|
778
|
+
"file": "src/manager/direct-worker-notifications.js",
|
|
779
|
+
"beforeBytes": 1555,
|
|
780
|
+
"afterBytes": 1015
|
|
781
|
+
},
|
|
772
782
|
{
|
|
773
783
|
"file": "src/manager/prompt.js",
|
|
774
784
|
"beforeBytes": 5296,
|
|
@@ -776,8 +786,8 @@
|
|
|
776
786
|
},
|
|
777
787
|
{
|
|
778
788
|
"file": "src/manager/registry.js",
|
|
779
|
-
"beforeBytes":
|
|
780
|
-
"afterBytes":
|
|
789
|
+
"beforeBytes": 18103,
|
|
790
|
+
"afterBytes": 8743
|
|
781
791
|
},
|
|
782
792
|
{
|
|
783
793
|
"file": "src/manager/retired-external-channel-compat.js",
|
|
@@ -786,13 +796,13 @@
|
|
|
786
796
|
},
|
|
787
797
|
{
|
|
788
798
|
"file": "src/manager/runtime.js",
|
|
789
|
-
"beforeBytes":
|
|
790
|
-
"afterBytes":
|
|
799
|
+
"beforeBytes": 41293,
|
|
800
|
+
"afterBytes": 20992
|
|
791
801
|
},
|
|
792
802
|
{
|
|
793
803
|
"file": "src/manager/worker-ipc.js",
|
|
794
|
-
"beforeBytes":
|
|
795
|
-
"afterBytes":
|
|
804
|
+
"beforeBytes": 25931,
|
|
805
|
+
"afterBytes": 16081
|
|
796
806
|
},
|
|
797
807
|
{
|
|
798
808
|
"file": "src/manager/worker-markdown.js",
|
|
@@ -904,6 +914,11 @@
|
|
|
904
914
|
"beforeBytes": 54,
|
|
905
915
|
"afterBytes": 60
|
|
906
916
|
},
|
|
917
|
+
{
|
|
918
|
+
"file": "src/personal-agent/automatic-model.js",
|
|
919
|
+
"beforeBytes": 3411,
|
|
920
|
+
"afterBytes": 1852
|
|
921
|
+
},
|
|
907
922
|
{
|
|
908
923
|
"file": "src/personal-agent/legacy-context.js",
|
|
909
924
|
"beforeBytes": 1170,
|
|
@@ -911,18 +926,23 @@
|
|
|
911
926
|
},
|
|
912
927
|
{
|
|
913
928
|
"file": "src/personal-agent/model-settings.js",
|
|
914
|
-
"beforeBytes":
|
|
915
|
-
"afterBytes":
|
|
929
|
+
"beforeBytes": 4179,
|
|
930
|
+
"afterBytes": 2527
|
|
916
931
|
},
|
|
917
932
|
{
|
|
918
933
|
"file": "src/personal-agent/official-credential.js",
|
|
919
|
-
"beforeBytes":
|
|
920
|
-
"afterBytes":
|
|
934
|
+
"beforeBytes": 680,
|
|
935
|
+
"afterBytes": 358
|
|
921
936
|
},
|
|
922
937
|
{
|
|
923
938
|
"file": "src/personal-agent/sdk-session.js",
|
|
924
|
-
"beforeBytes":
|
|
925
|
-
"afterBytes":
|
|
939
|
+
"beforeBytes": 7127,
|
|
940
|
+
"afterBytes": 4038
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
"file": "src/personal-agent/system-prompt.js",
|
|
944
|
+
"beforeBytes": 1539,
|
|
945
|
+
"afterBytes": 2010
|
|
926
946
|
},
|
|
927
947
|
{
|
|
928
948
|
"file": "src/personal-sync/epoch.js",
|
|
@@ -956,8 +976,8 @@
|
|
|
956
976
|
},
|
|
957
977
|
{
|
|
958
978
|
"file": "src/personal-workspace/service.js",
|
|
959
|
-
"beforeBytes":
|
|
960
|
-
"afterBytes":
|
|
979
|
+
"beforeBytes": 10929,
|
|
980
|
+
"afterBytes": 6203
|
|
961
981
|
},
|
|
962
982
|
{
|
|
963
983
|
"file": "src/region.js",
|
|
@@ -1111,8 +1131,8 @@
|
|
|
1111
1131
|
},
|
|
1112
1132
|
{
|
|
1113
1133
|
"file": "src/schedules/personal-context.js",
|
|
1114
|
-
"beforeBytes":
|
|
1115
|
-
"afterBytes":
|
|
1134
|
+
"beforeBytes": 2050,
|
|
1135
|
+
"afterBytes": 2259
|
|
1116
1136
|
},
|
|
1117
1137
|
{
|
|
1118
1138
|
"file": "src/schedules/personal-handlers.js",
|
|
@@ -1126,8 +1146,8 @@
|
|
|
1126
1146
|
},
|
|
1127
1147
|
{
|
|
1128
1148
|
"file": "src/schedules/server-client.js",
|
|
1129
|
-
"beforeBytes":
|
|
1130
|
-
"afterBytes":
|
|
1149
|
+
"beforeBytes": 3612,
|
|
1150
|
+
"afterBytes": 2428
|
|
1131
1151
|
},
|
|
1132
1152
|
{
|
|
1133
1153
|
"file": "src/security/macos-file-sandbox.js",
|
|
@@ -1286,13 +1306,13 @@
|
|
|
1286
1306
|
},
|
|
1287
1307
|
{
|
|
1288
1308
|
"file": "src/session/handlers/personal-workspace.js",
|
|
1289
|
-
"beforeBytes":
|
|
1290
|
-
"afterBytes":
|
|
1309
|
+
"beforeBytes": 804,
|
|
1310
|
+
"afterBytes": 444
|
|
1291
1311
|
},
|
|
1292
1312
|
{
|
|
1293
1313
|
"file": "src/session/handlers/personal.js",
|
|
1294
|
-
"beforeBytes":
|
|
1295
|
-
"afterBytes":
|
|
1314
|
+
"beforeBytes": 868,
|
|
1315
|
+
"afterBytes": 531
|
|
1296
1316
|
},
|
|
1297
1317
|
{
|
|
1298
1318
|
"file": "src/session/handlers/project-fs.js",
|
|
@@ -1316,8 +1336,8 @@
|
|
|
1316
1336
|
},
|
|
1317
1337
|
{
|
|
1318
1338
|
"file": "src/session/handlers/steward.js",
|
|
1319
|
-
"beforeBytes":
|
|
1320
|
-
"afterBytes":
|
|
1339
|
+
"beforeBytes": 9530,
|
|
1340
|
+
"afterBytes": 4526
|
|
1321
1341
|
},
|
|
1322
1342
|
{
|
|
1323
1343
|
"file": "src/session/handlers/title.js",
|
|
@@ -1351,8 +1371,8 @@
|
|
|
1351
1371
|
},
|
|
1352
1372
|
{
|
|
1353
1373
|
"file": "src/session/manager.js",
|
|
1354
|
-
"beforeBytes":
|
|
1355
|
-
"afterBytes":
|
|
1374
|
+
"beforeBytes": 42585,
|
|
1375
|
+
"afterBytes": 22437
|
|
1356
1376
|
},
|
|
1357
1377
|
{
|
|
1358
1378
|
"file": "src/session/native-cleanup-outbox.js",
|
|
@@ -1416,8 +1436,8 @@
|
|
|
1416
1436
|
},
|
|
1417
1437
|
{
|
|
1418
1438
|
"file": "src/session/queue.js",
|
|
1419
|
-
"beforeBytes":
|
|
1420
|
-
"afterBytes":
|
|
1439
|
+
"beforeBytes": 43881,
|
|
1440
|
+
"afterBytes": 19363
|
|
1421
1441
|
},
|
|
1422
1442
|
{
|
|
1423
1443
|
"file": "src/session/queued-chat-dispatch.js",
|
|
@@ -1489,6 +1509,11 @@
|
|
|
1489
1509
|
"beforeBytes": 1912,
|
|
1490
1510
|
"afterBytes": 1094
|
|
1491
1511
|
},
|
|
1512
|
+
{
|
|
1513
|
+
"file": "src/steward/context.js",
|
|
1514
|
+
"beforeBytes": 4530,
|
|
1515
|
+
"afterBytes": 3854
|
|
1516
|
+
},
|
|
1492
1517
|
{
|
|
1493
1518
|
"file": "src/steward/failover.js",
|
|
1494
1519
|
"beforeBytes": 4394,
|
|
@@ -1504,10 +1529,15 @@
|
|
|
1504
1529
|
"beforeBytes": 1085,
|
|
1505
1530
|
"afterBytes": 669
|
|
1506
1531
|
},
|
|
1532
|
+
{
|
|
1533
|
+
"file": "src/steward/project-event.js",
|
|
1534
|
+
"beforeBytes": 2146,
|
|
1535
|
+
"afterBytes": 1857
|
|
1536
|
+
},
|
|
1507
1537
|
{
|
|
1508
1538
|
"file": "src/steward/session.js",
|
|
1509
|
-
"beforeBytes":
|
|
1510
|
-
"afterBytes":
|
|
1539
|
+
"beforeBytes": 5056,
|
|
1540
|
+
"afterBytes": 5336
|
|
1511
1541
|
},
|
|
1512
1542
|
{
|
|
1513
1543
|
"file": "src/steward/settings.js",
|
|
@@ -1516,8 +1546,13 @@
|
|
|
1516
1546
|
},
|
|
1517
1547
|
{
|
|
1518
1548
|
"file": "src/steward/templates.js",
|
|
1519
|
-
"beforeBytes":
|
|
1520
|
-
"afterBytes":
|
|
1549
|
+
"beforeBytes": 7150,
|
|
1550
|
+
"afterBytes": 12430
|
|
1551
|
+
},
|
|
1552
|
+
{
|
|
1553
|
+
"file": "src/steward/worker-settings.js",
|
|
1554
|
+
"beforeBytes": 2071,
|
|
1555
|
+
"afterBytes": 1436
|
|
1521
1556
|
},
|
|
1522
1557
|
{
|
|
1523
1558
|
"file": "src/steward/workspace.js",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import s from"node:fs";import m from"node:os";import i from"node:path";import{readLatestUserEnv as E}from"../agent-env.js";import{loadConfig as S,resolveShennianPath as g}from"../config/index.js";const c=g("agent-provider-config.json"),U=4;function A(e){return e==="codex"||e==="claude"||e==="pi"}const O={codex:{baseUrl:["OPENAI_BASE_URL","OPENAI_API_BASE","OPENAI_API_URL"],token:["OPENAI_API_KEY","OPENAI_TOKEN"]},claude:{baseUrl:["ANTHROPIC_BASE_URL","ANTHROPIC_API_URL"],token:["ANTHROPIC_API_KEY","ANTHROPIC_AUTH_TOKEN"]},pi:{baseUrl:["DASHSCOPE_BASE_URL","DASHSCOPE_API_BASE","DASHSCOPE_API_URL"],token:["DASHSCOPE_API_KEY","DASHSCOPE_TOKEN"]}};function k(e){return u().configs[e]}function v(e){const n=u(),o=n.configs[e.agent],t={agent:e.agent,baseUrl:e.baseUrl?.trim()||o?.baseUrl,token:e.token?.trim()||o?.token,updatedAt:new Date().toISOString()};return n.configs[e.agent]=t,_(n),t}function B(e){const n=u();delete n.configs[e],_(n)}function K(e){if(!A(e))return{};const n=k(e);return n?l(e==="codex"?{OPENAI_BASE_URL:n.baseUrl,OPENAI_API_KEY:n.token}:e==="claude"?{ANTHROPIC_BASE_URL:n.baseUrl,ANTHROPIC_API_KEY:n.token}:{DASHSCOPE_BASE_URL:n.baseUrl,DASHSCOPE_API_KEY:n.token}):{}}function j(e,n
|
|
1
|
+
import s from"node:fs";import m from"node:os";import i from"node:path";import{readLatestUserEnv as E}from"../agent-env.js";import{loadConfig as S,resolveShennianPath as g}from"../config/index.js";const c=g("agent-provider-config.json"),U=4;function A(e){return e==="codex"||e==="claude"||e==="pi"}const O={codex:{baseUrl:["OPENAI_BASE_URL","OPENAI_API_BASE","OPENAI_API_URL"],token:["OPENAI_API_KEY","OPENAI_TOKEN"]},claude:{baseUrl:["ANTHROPIC_BASE_URL","ANTHROPIC_API_URL"],token:["ANTHROPIC_API_KEY","ANTHROPIC_AUTH_TOKEN"]},pi:{baseUrl:["DASHSCOPE_BASE_URL","DASHSCOPE_API_BASE","DASHSCOPE_API_URL"],token:["DASHSCOPE_API_KEY","DASHSCOPE_TOKEN"]}};function k(e){return u().configs[e]}function v(e){const n=u(),o=n.configs[e.agent],t={agent:e.agent,baseUrl:e.baseUrl?.trim()||o?.baseUrl,token:e.token?.trim()||o?.token,updatedAt:new Date().toISOString()};return n.configs[e.agent]=t,_(n),t}function B(e){const n=u();delete n.configs[e],_(n)}function K(e){if(!A(e))return{};const n=k(e);return n?l(e==="codex"?{OPENAI_BASE_URL:n.baseUrl,OPENAI_API_KEY:n.token}:e==="claude"?{ANTHROPIC_BASE_URL:n.baseUrl,ANTHROPIC_API_KEY:n.token}:{DASHSCOPE_BASE_URL:n.baseUrl,DASHSCOPE_API_KEY:n.token}):{}}function j(e,n){if(e==="pi-coding-agent"||!A(e))return;const o=k(e);if(o?.token||o?.baseUrl)return a({agent:e,source:"shennian",status:o.token?"managed":"missing",baseUrl:o.baseUrl,token:o.token,tokenPresent:!!o.token});const t=I(e,n??E());if(t.tokenPresent||t.baseUrl)return a({agent:e,source:"env",status:t.tokenPresent?"detected":"missing",baseUrl:t.baseUrl,token:t.token,tokenPresent:t.tokenPresent});const r=p(e);return r.tokenPresent||r.baseUrl?a({agent:e,source:"config-file",status:r.tokenPresent?"detected":"missing",baseUrl:r.baseUrl,token:r.token,tokenPresent:r.tokenPresent}):a({agent:e,source:"unknown",status:"missing",tokenPresent:!1})}function u(){try{return{configs:JSON.parse(s.readFileSync(c,"utf-8")).configs??{}}}catch{return{configs:{}}}}function _(e){s.mkdirSync(i.dirname(c),{recursive:!0}),s.writeFileSync(c,JSON.stringify(e,null,2),{mode:384});try{s.chmodSync(c,384)}catch{}}function l(e){const n={};for(const[o,t]of Object.entries(e))t&&(n[o]=t);return n}function I(e,n){const o=O[e],t=P(n,o.baseUrl),r=P(n,o.token);return{baseUrl:t,token:r,tokenPresent:!!r}}function P(e,n){for(const o of n){const t=e[o]?.trim();if(t)return t}}function p(e){const n=m.homedir();if(e==="pi"){const r=S().apiKeys?.dashscope?.trim();if(r)return{token:r,tokenPresent:!0}}const o=e==="codex"?[i.join(n,".codex","config.toml"),i.join(n,".codex","auth.json")]:e==="claude"?[i.join(n,".claude","settings.json"),i.join(n,".claude.json")]:[i.join(n,".dashscope","config.json")];for(const t of o){const r=C(t);if(!r)continue;const f=N(r,e),d=b(r);if(f||d)return{token:f,baseUrl:d,tokenPresent:!!f}}return{tokenPresent:!1}}function C(e){try{const n=s.statSync(e);return!n.isFile()||n.size>1024*1024?null:s.readFileSync(e,"utf-8")}catch{return null}}function b(e){return e.match(/(?:base_url|baseURL|api_url|apiUrl|ANTHROPIC_BASE_URL|OPENAI_BASE_URL|DASHSCOPE_BASE_URL)["'\s:=]+([^"'\s,}]+)/i)?.[1]?.trim()}function N(e,n){const o=n==="claude"?"sk-ant-":"sk-",t=e.match(new RegExp(`${o.replace(/-/g,"\\-")}[A-Za-z0-9_\\-]{8,}`));return t?.[0]?t[0]:e.match(/(?:api[_-]?key|auth[_-]?token|token|dashscope)["'\s:=]+([A-Za-z0-9_\-.]{12,})/i)?.[1]?.trim()}function a(e){return{status:e.status,source:e.source,tokenPresent:e.tokenPresent,...e.baseUrl?{baseUrlHost:R(e.baseUrl)}:{},...e.token?{tokenHint:h(e.token)}:{},updatedAt:new Date().toISOString()}}function h(e){const n=e.trim();return n?`\u2022\u2022\u2022\u2022${n.slice(-U)}`:""}function R(e){try{return new URL(e).host||e}catch{return e.replace(/^https?:\/\//i,"").replace(/\/.*$/,"")||e}}export{K as buildManagedAgentEnv,B as deleteManagedAgentProviderConfig,j as getAgentConfigSummary,k as getManagedAgentProviderConfig,h as maskToken,v as upsertManagedAgentProviderConfig};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getAgentConfigSummary as g}from"../config-status.js";import{isCacheFresh as x,readCache as f,writeCache as v}from"./cache.js";import{discoverModelsForAgent as b}from"./discovery.js";import{ModelDiscoveryFallbackError as E}from"./types.js";import{getAgentRuntimeSummary as A}from"../runtime-compatibility.js";import{isRestrictedRoomChatUnsupported as F,resolveManagedAgentRuntimeProtection as k}from"../../security/managed-agent-runtime.js";const M={claude:"claude-alias-v2",codex:"codex-app-server-v2",opencode:"opencode-connected-v1","pi-coding-agent":"pi-configured-v1"};function w(t,s,e){console.warn(`[model-discovery] agent=${t} source=fallback reason=${s} usedCache=${e}`)}function S(t){const s=new Set,e=[];for(const r of t)!r.id||s.has(r.id)||(s.add(r.id),e.push(r));return e}function C(t){if(t.type==="shennian")return{supportsStandardSession:!0,supportsAgent:!
|
|
1
|
+
import{getAgentConfigSummary as g}from"../config-status.js";import{isCacheFresh as x,readCache as f,writeCache as v}from"./cache.js";import{discoverModelsForAgent as b}from"./discovery.js";import{ModelDiscoveryFallbackError as E}from"./types.js";import{getAgentRuntimeSummary as A}from"../runtime-compatibility.js";import{isRestrictedRoomChatUnsupported as F,resolveManagedAgentRuntimeProtection as k}from"../../security/managed-agent-runtime.js";const M={claude:"claude-alias-v2",codex:"codex-app-server-v2",opencode:"opencode-connected-v1","pi-coding-agent":"pi-configured-v1"};function w(t,s,e){console.warn(`[model-discovery] agent=${t} source=fallback reason=${s} usedCache=${e}`)}function S(t){const s=new Set,e=[];for(const r of t)!r.id||s.has(r.id)||(s.add(r.id),e.push(r));return e}function C(t){if(t.type==="shennian")return{supportsStandardSession:!0,supportsAgent:!0,supportsManagedAgent:!1,supportsManagedNativeFull:!0,supportsRoomTools:!0,supportsWorker:!1,supportsManagerMode:!1,supportsExternalWorkerTarget:!0,supportedAgentExecutionModes:["native-full"]};const s=t.type!=="manager"&&t.type!=="pi"&&t.type!=="openclaw",e=s,r=e&&!t.type.startsWith("acp:"),n=e?k({agentType:t.type,runtimeVersion:t.version,platform:t.runtimePlatform,isWsl:t.runtimeIsWsl,executableFingerprint:t.executableFingerprint,requireExecutableFingerprint:!0}):null,c=r&&!F(t.type)&&(n?.level==="hard"||n?.level==="partial"),o=e,i=e,p=[...o?["native-full"]:[],...c?["restricted"]:[]],u=i,a=s;return{supportsStandardSession:s,supportsAgent:i,supportedAgentExecutionModes:p,supportsManagedAgent:c,supportsManagedNativeFull:o,supportsRoomTools:u,supportsWorker:a,supportsManagerMode:u&&a,supportsExternalWorkerTarget:a,...n?{managedAgentProtection:n}:{}}}function R(t,s){return t.type==="opencode"&&(!t.authState||t.authState==="unknown")&&s.length>0?{authState:"ready"}:t.authState?{authState:t.authState}:{}}function P(t,s){if(!t.startsWith("acp:"))return!1;const e=S(s);if(e.length===0)return!1;const r=f(),n=r.agents[t];return JSON.stringify(n?.models)===JSON.stringify(e)?!1:(r.agents[t]={refreshedAt:Date.now(),models:e},v(r),!0)}function T(t){const s=f();return t.map(e=>{const r=s.agents[e.type],n=M[e.type],c=r&&(!n||r.sourceRevision===n)?r.models:e.models??[],o=g(e.type),i=A(e);return{type:e.type,models:c,...e.integration?{integration:e.integration}:{},...e.display?{display:e.display}:{},...e.acpCapabilities?{acpCapabilities:e.acpCapabilities}:{},...R(e,c),...e.acpAuthMethods?{acpAuthMethods:e.acpAuthMethods}:{},...e.catalogRevision?{catalogRevision:e.catalogRevision}:{},...C(e),...o?{config:o}:{},...i?{runtime:i}:{}}})}async function V(t,s){return O(t,s,{forceRefresh:!0})}async function O(t,s,e={}){const r=f();let n=!1;const c=[];for(const o of t){const i=r.agents[o.type],p=M[o.type],u=i&&(!p||i.sourceRevision===p)?i:void 0;let a;if(!e.forceRefresh&&x(i,o.version,p))a=i.models;else{let d=null;try{d=S(await b(o,s)),a=d.length>0?d:u?.models??o.models??[]}catch(l){if(l instanceof E){const y=!!u?.models.length;a=y?u.models:l.fallbackModels,w(o.type,l.failureCode,y)}else a=u?.models??o.models??[]}if(d&&d.length>0){const l={version:o.version,...p?{sourceRevision:p}:{},refreshedAt:Date.now(),models:a};JSON.stringify(i)!==JSON.stringify(l)&&(r.agents[o.type]=l,n=!0)}}const h=g(o.type),m=A(o);c.push({type:o.type,models:a,...o.integration?{integration:o.integration}:{},...o.display?{display:o.display}:{},...o.acpCapabilities?{acpCapabilities:o.acpCapabilities}:{},...R(o,a),...o.acpAuthMethods?{acpAuthMethods:o.acpAuthMethods}:{},...o.catalogRevision?{catalogRevision:o.catalogRevision}:{},...C(o),...h?{config:h}:{},...m?{runtime:m}:{}})}return n&&v(r),c}export{T as getCachedAgentInfos,P as recordAcpAgentModels,V as refreshAgentInfos,O as resolveAgentInfos};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{loadConfig as u}from"../config/index.js";import{SERVERS as h}from"../region.js";import{PublicAgentClientError as m}from"./public-agent-client.js";class i extends m{}class
|
|
1
|
+
import{loadConfig as u}from"../config/index.js";import{SERVERS as h}from"../region.js";import{PublicAgentClientError as m}from"./public-agent-client.js";class i extends m{}class T{fetchImpl;constructor(e=fetch){this.fetchImpl=e}createProject(e){return this.request("POST","/api/project-cli/projects",e)}updateProject(e,t){return this.request("PATCH",`/api/project-cli/projects/${encodeURIComponent(e)}`,t)}watchTask(e,t){return this.request("POST",`/api/project-cli/tasks/${encodeURIComponent(e)}/watch`,{stewardSessionId:t})}listProjects(){return this.request("GET","/api/project-cli/projects")}listTasks(e,t){return this.request("GET",`/api/project-cli/projects/${encodeURIComponent(e)}/tasks${p({limit:t})}`)}createTask(e,t){return this.request("POST",`/api/project-cli/projects/${encodeURIComponent(e)}/tasks`,t)}readTask(e,t){return this.request("GET",`/api/project-cli/tasks/${encodeURIComponent(e)}/messages${p({limit:t})}`)}sendTask(e,t){return this.request("POST",`/api/project-cli/tasks/${encodeURIComponent(e)}/messages`,t)}stopTask(e){return this.request("POST",`/api/project-cli/tasks/${encodeURIComponent(e)}/stop`,{})}async request(e,t,n){const c=u();if(!c.machineToken)throw new i("not_paired","Shennian CLI is not paired.",{type:"run_command",command:"shennian pair --browser"});const l=(c.serverUrl??h.cn.url).replace(/\/+$/,"");let o;try{o=await this.fetchImpl(`${l}${t}`,{method:e,redirect:"error",headers:{authorization:`Bearer ${c.machineToken}`,...n==null?{}:{"content-type":"application/json"}},...n==null?{}:{body:JSON.stringify(n)},signal:AbortSignal.timeout(3e4)})}catch{throw new i("server_unavailable","Shennian service is unavailable.")}let s=null;try{s=await o.json()}catch{}const r=s&&typeof s=="object"&&!Array.isArray(s)?s:null;if(!o.ok)throw new i(typeof r?.error=="string"?r.error:`http_${o.status}`,typeof r?.message=="string"?r.message:"Project request failed.");if(!r)throw new i("invalid_server_response","Shennian returned an invalid response.");return r}}function p(a){const e=Object.entries(a).filter(t=>t[1]!==void 0).map(([t,n])=>`${t}=${encodeURIComponent(String(n))}`);return e.length?`?${e.join("&")}`:""}export{T as ProjectClient,i as ProjectClientError};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
`)??""})}else e.type==="compaction_start"?this.event({state:"notify",runPhase:"thinking",message:"Compressing conversation context"}):e.type==="compaction_end"&&e.errorMessage&&!e.aborted?this.failure=!0:e.type==="message_end"&&e.message.role==="assistant"&&(e.message.stopReason==="error"&&
|
|
3
|
-
|
|
1
|
+
import{stewardCoreContext as _}from"../steward/context.js";import f from"node:fs";import{personalModelSummary as y}from"../personal-agent/model-settings.js";import{buildManagedNativeFullProcessEnv as w}from"../agent-env.js";import{isManagedAgentNativeFull as v}from"../security/managed-agent-policy.js";import{buildPlatformInstructions as b}from"./platform-instructions.js";import{randomUUID as I}from"node:crypto";import{AgentAdapter as k,registerAgent as E}from"./adapter.js";import{openPersonalAgent as x}from"../personal-agent/sdk-session.js";class S extends k{type="shennian";get recoveryCapabilities(){return{inspectTerminal:!1,reattachRun:!1,resumeRun:!1,resumeSession:!0}}managedPolicy=null;validation=!1;sessionId="";cwd="";nativeId;env={};sdk;runId="";seq=0;active=!1;preparing=!1;generation=0;aborted=!1;failure=!1;failureMessage="personal_agent_request_failed";fail(e){this.failure=!0;const t=e instanceof Error?e.message:typeof e=="string"?e:"";/nian_quota_exceeded|personal_model_monthly_quota_exceeded/.test(t)&&(this.failureMessage="\u6A21\u578B\u989D\u5EA6\u4E0D\u8DB3\uFF0C\u672C\u6B21\u5DE5\u4F5C\u4E2D\u65AD\uFF1B\u8BF7\u68C0\u67E5\u989D\u5EA6\u6216\u6A21\u578B\u8BBE\u7F6E\u540E\u518D\u8BD5\u3002")}inflight;unsubscribe;configure(e){const t=e.managedAgentPolicy??null;if(e.externalChannel||t&&!v(t)||e.managedRoomContextToken&&!t)throw new Error("personal_agent_managed_runtime_unsupported");if((this.active||this.preparing||this.sdk)&&JSON.stringify(t)!==JSON.stringify(this.managedPolicy))throw new Error("personal_agent_policy_change_requires_stop");this.managedPolicy=t,this.env=t?w(e.env):{...e.env}}async start(e,t,a,n){if(this.active||this.preparing)throw new Error("personal_agent_busy");this.validation=n?.persistNativeSession===!1,this.sessionId=e,this.cwd=this.managedPolicy?.adapterPolicy.workDir??t,this.nativeId=a}event(e){this.emit("agentEvent",{...e,runId:this.runId,seq:++this.seq})}onEvent(e){if(e.type==="message_update"){const t=e.assistantMessageEvent;t.type==="text_delta"&&this.event({state:"delta",text:t.delta}),t.type==="thinking_delta"&&this.event({state:"delta",text:t.delta,thinking:!0})}else if(e.type==="tool_execution_start")this.event({state:"tool-call",name:e.toolName,toolCallId:e.toolCallId,args:e.args});else if(e.type==="tool_execution_end"){const t=e.result;this.event({state:"tool-result",name:e.toolName,toolCallId:e.toolCallId,result:t.content?.filter(a=>a.type==="text").map(a=>a.text??"").join(`
|
|
2
|
+
`)??""})}else e.type==="compaction_start"?this.event({state:"notify",runPhase:"thinking",message:"Compressing conversation context"}):e.type==="compaction_end"&&e.errorMessage&&!e.aborted?this.failure=!0:e.type==="message_end"&&e.message.role==="assistant"&&(e.message.stopReason==="error"&&this.fail(e.message.errorMessage),e.message.stopReason==="aborted"&&(this.aborted=!0))}async send(e,t,a,n,o,u){if(u?.source==="published_agent")throw new Error("personal_agent_public_runtime_unsupported");if((this.managedPolicy||this.validation)&&t&&t!==y().model)throw new Error("builtin_agent_model_unavailable");if(this.active||this.preparing)throw new Error("personal_agent_busy");const r=[];let l=0;const h=[];for(const s of n??[]){if(s.kind!=="image"){h.push(`[${s.name}](<${s.path}>)`);continue}if(!["image/jpeg","image/png","image/webp","image/gif"].includes(s.mimeType))throw new Error("personal_agent_image_unsupported");let i=s.previewData?.replace(/^data:[^,]+,/,"")??"";if(!i){const c=f.statSync(s.path);if(!c.isFile()||c.size>4*1024*1024)throw new Error("personal_agent_image_too_large");i=f.readFileSync(s.path).toString("base64")}if(l+=i.length,!/^[A-Za-z0-9+/]*={0,2}$/.test(i)||l>5*1024*1024)throw new Error("personal_agent_image_too_large");r.push({type:"image",data:i,mimeType:s.mimeType})}const d=!this.managedPolicy&&!this.validation&&this.env.SHENNIAN_STEWARD_SESSION_ID===this.sessionId?_(this.sessionId):"",m=[d?`<personal-context-data>
|
|
3
|
+
${d}
|
|
4
|
+
</personal-context-data>`:"",e,...h].filter(Boolean).join(`
|
|
5
|
+
|
|
6
|
+
`);this.preparing=!0;const p=this.generation;try{if(!this.sdk){const s=await x(this.sessionId,this.cwd,this.nativeId,()=>this.env,this.managedPolicy||this.validation?b(this.cwd,null,this.sessionId,o):o??"",this.validation?"validation":this.managedPolicy?"managed-native-full":"personal");if(p!==this.generation)throw s.session.dispose(),s.cleanup?.(),new Error("personal_agent_cancelled");this.nativeId=s.session.sessionId;try{this.validation||this.emit("nativeSession",this.type,this.nativeId)}catch(i){throw s.session.dispose(),s.cleanup?.(),i}this.sdk=s,this.unsubscribe=s.session.subscribe(i=>this.onEvent(i))}if(await this.sdk.refreshModel(),p!==this.generation)throw new Error("personal_agent_cancelled")}finally{this.preparing=!1}this.runId=I(),this.seq=0,this.active=!0,this.aborted=!1,this.failure=!1,this.failureMessage="personal_agent_request_failed",this.event({state:"start",agentSessionId:this.nativeId??void 0});const g=this.sdk;this.inflight=(async()=>{try{await g.session.prompt(m,{expandPromptTemplates:!1,...r.length?{images:r}:{}}),g.persist()}catch(s){this.fail(s)}finally{this.active=!1,this.event(this.aborted?{state:"aborted"}:this.failure?{state:"error",message:this.failureMessage}:{state:"final"})}})()}async resume(e){if(this.sdk&&this.sdk.session.sessionId!==e){if(this.active||this.preparing)throw new Error("personal_agent_busy");this.unsubscribe?.(),this.sdk.session.dispose(),this.sdk.cleanup?.(),this.sdk=void 0}this.nativeId=e}async getStatus(){return{active:this.active,runId:this.active?this.runId:null,canStop:this.active}}async stop(){this.generation++,this.active&&(this.aborted=!0,await this.sdk?.session.abort(),await this.inflight),this.unsubscribe?.(),this.sdk?.session.dispose(),this.sdk?.cleanup?.(),this.sdk=void 0}}E("shennian",()=>new S);export{S as ShennianAdapter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"chalk";import{loadConfig as s,saveConfig as g,getConfigPath as a}from"../config/index.js";import{collectKnownLogSecrets as f,sanitizeCliLogValue as m}from"../log-redaction.js";import{SERVERS as c,regionToUrl as
|
|
1
|
+
import r from"chalk";import{loadConfig as s,saveConfig as g,getConfigPath as a}from"../config/index.js";import{collectKnownLogSecrets as f,sanitizeCliLogValue as m}from"../log-redaction.js";import{SERVERS as c,regionToUrl as d,urlToRegion as p}from"../region.js";import{assertSingleServerBinding as u}from"../config/server-binding.js";function k(l){const i=l.command("config").description("View or modify configuration");i.command("show",{isDefault:!0}).description("Show current configuration").action(()=>{console.log(`Config file: ${a()}`);const o=s(),n=m(o,f(process.env,o));if(o.serverUrl){const e=p(o.serverUrl);console.log(`Region: ${e} (${c[e].label})`)}console.log(JSON.stringify(n,null,2))}),i.command("set").description("Update a config value").argument("<key>",'Config key (e.g. "server")').argument("<value>",'Config value (e.g. "cn" or "global")').action((o,n)=>{const e=s();if(o==="server"){n!=="cn"&&n!=="global"&&(console.error(r.red('\u2717 Value must be "cn" or "global"')),process.exit(1));const t=n;e.serverUrl=u(d(t),e),g(e),console.log(r.green(`\u2713 Server set to ${c[t].label}`)),console.log(r.yellow(" Restart the background service for this to take effect: shennian stop && shennian start"));return}console.error(r.red(`\u2717 Unknown config key: ${o}. Supported: server`)),process.exit(1)})}export{k as registerConfigCommand};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
`)}function f(n,e){l({type:"error",code:n,message:e}),process.exit(1)}function
|
|
3
|
-
\u2717 Pairing code expired. Please re-run: shennian pair`)),process.exit(1))),!
|
|
1
|
+
import a from"chalk";import{assertSingleServerBinding as R}from"../config/server-binding.js";import{getDaemonInstallationId as L}from"../personal-sync/identity.js";import k from"node:os";import E from"node:readline";import{loadConfig as p,saveConfig as v}from"../config/index.js";import{detectAgents as A}from"../agents/detect.js";import{clearRemoteAccessDisabled as U,getDaemonStatus as M,startDaemonProcess as b,installService as x,saveEnvSnapshot as O}from"./daemon.js";import{waitForDaemonReadyStatus as F}from"./daemon-start-wait.js";import{detectAndChooseServer as N}from"../region.js";import{buildPairQrPayload as J,PAIR_QR_RENDER_OPTIONS as q}from"./pair-qr.js";import{BrowserPairError as Q,parsePairModeChoice as z,resolvePairMode as j,runBrowserPairFlow as K}from"./pair-browser.js";import{markAllSessionIndexesForRepublish as C}from"../session/store.js";const W=3e3,$=600*1e3;function l(n){process.stdout.write(`${JSON.stringify(n)}
|
|
2
|
+
`)}function f(n,e){l({type:"error",code:n,message:e}),process.exit(1)}function Y(n){const e="\u2500".repeat(n.length+4);console.log(a.cyan(`\u250C${e}\u2510`)),console.log(a.cyan("\u2502 ")+a.bold.yellow(n)+a.cyan(" \u2502")),console.log(a.cyan(`\u2514${e}\u2518`))}async function H(n){const e=(await import("qrcode-terminal")).default;return new Promise(o=>{e.generate(n,q,r=>{console.log(r),o()})})}async function G(n,e,o={}){const r=Date.now()+$;for(o.json&&l({type:"pair.waiting"});Date.now()<r;){await new Promise(d=>setTimeout(d,W));let i;try{i=await fetch(`${n}/api/machines/pair/status?token=${encodeURIComponent(e)}`)}catch{continue}if(i.status===410&&(o.json?f("PAIR_EXPIRED","Pairing code expired"):(console.error(a.red(`
|
|
3
|
+
\u2717 Pairing code expired. Please re-run: shennian pair`)),process.exit(1))),!i.ok)continue;const t=await i.json();if(t.status==="claimed"&&t.machineToken&&t.machineId&&t.accountNamespaceId)return o.json&&l({type:"pair.claimed"}),{machineToken:t.machineToken,machineId:t.machineId,machineName:t.machineName??"",accountNamespaceId:t.accountNamespaceId}}return null}function V(n){const e=E.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(n,r=>{e.close(),o(r.trim().toLowerCase()==="y")})})}function _(){const n=E.createInterface({input:process.stdin,output:process.stdout});return console.log(a.white("Choose how to pair this machine:")),console.log(a.cyan(" 1. Browser authorization (recommended)")),console.log(a.gray(" 2. QR code / pairing token (servers and remote terminals)")),new Promise(e=>{n.question("Selection (1/2) [1]: ",o=>{n.close(),e(z(o))})})}async function D(n){const{machineName:e,force:o,json:r}=n,i=R(n.serverUrl,p()),t=p();if(t.machineToken&&t.machineId&&!o){r?l({type:"done",status:"already-paired",machineId:t.machineId}):(console.log(a.green(`\u2713 Already paired (machine ID: ${t.machineId})`)),console.log(a.gray(' Run "shennian pair" to re-pair to another account')));return}const c=(await A()).map(h=>h.type),m=k.platform(),g=m==="win32"?"windows":m==="darwin"?"macos":"linux";r||(console.log(a.bold(`
|
|
4
4
|
Shennian CLI \u2014 Pairing
|
|
5
|
-
`)),console.log(
|
|
6
|
-
If the browser did not open, copy this URL to any signed-in device.`)),console.log(
|
|
7
|
-
\u2713 Paired successfully! Machine "${s.machineName}" is now linked.`));return}catch(s){const T=s instanceof
|
|
8
|
-
\u2717 ${P}`)),process.exit(1)}finally{process.removeListener("SIGINT",I)}}let y;try{y=await fetch(`${
|
|
9
|
-
\u2717 Timed out. Pairing code expired, please try again.`)),process.exit(1)),v({...t,machineToken:
|
|
10
|
-
\u2713 Paired successfully! Machine "${
|
|
11
|
-
Starting background service...`)),
|
|
12
|
-
Starting background service...`)),
|
|
5
|
+
`)),console.log(a.gray(` Machine: ${e} | OS: ${g} | Agents: ${c.join(", ")||"none"}`)),console.log());let S=n.mode??j({json:r,stdinIsTty:!!process.stdin.isTTY,stdoutIsTty:!!process.stdout.isTTY});if(S==="prompt"&&(S=await _()),S==="browser"){const h=new AbortController,I=()=>h.abort();process.once("SIGINT",I);try{const s=await K({serverUrl:i,machineName:e,machineOs:g,agentList:c,signal:h.signal,openUrl:n.openUrl,emit:T=>{r?l(T):T.type==="pair.browser.created"&&(console.log(a.white("Approve this machine in your browser:")),console.log(a.cyan.underline(T.url)),console.log(a.gray(`
|
|
6
|
+
If the browser did not open, copy this URL to any signed-in device.`)),console.log(a.gray("Waiting for authorization... (Ctrl+C to cancel)")))}});v({...t,machineToken:s.machineToken,machineId:s.machineId,accountNamespaceId:s.accountNamespaceId,serverUrl:i}),n.force&&C(),r?l({type:"pair.saved",machineId:s.machineId}):console.log(a.green(`
|
|
7
|
+
\u2713 Paired successfully! Machine "${s.machineName}" is now linked.`));return}catch(s){const T=s instanceof Q||typeof s=="object"&&s&&"code"in s&&typeof s.code=="string"?s.code:"PAIR_BROWSER_FAILED",P=s instanceof Error?s.message:"Browser pairing failed";r&&f(T,P),console.error(a.red(`
|
|
8
|
+
\u2717 ${P}`)),process.exit(1)}finally{process.removeListener("SIGINT",I)}}let y;try{y=await fetch(`${i}/api/machines/pair/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,os:g,agentList:c,daemonInstallationId:L()})})}catch{const h=`Network error: cannot connect to ${i}`;r&&f("NETWORK_ERROR",h),console.error(a.red(`\u2717 ${h}`)),process.exit(1)}if(!y.ok){const I=`Failed to create machine: ${(await y.json().catch(()=>({}))).error??y.statusText}`;r&&f("PAIR_CREATE_FAILED",I),console.error(a.red(`\u2717 ${I}`)),process.exit(1)}const w=await y.json(),B=J(w.pairToken);r?l({type:"pair.created",code:w.pairToken,machineId:w.machineId,expiresAt:new Date(Date.now()+$).toISOString()}):(console.log(a.white("Scan QR code or enter the pairing code in the Shennian app:")),console.log(),await H(B),Y(w.pairToken),console.log(),console.log(a.gray("Waiting for pairing... (Ctrl+C to cancel)")));const u=await G(i,w.pairToken,{json:r});u||(r&&f("PAIR_TIMEOUT","Timed out waiting for pairing"),console.error(a.red(`
|
|
9
|
+
\u2717 Timed out. Pairing code expired, please try again.`)),process.exit(1)),v({...t,machineToken:u.machineToken,machineId:u.machineId,accountNamespaceId:u.accountNamespaceId,serverUrl:i}),n.force&&C(),r&&l({type:"pair.saved",machineId:u.machineId}),r||console.log(a.green(`
|
|
10
|
+
\u2713 Paired successfully! Machine "${u.machineName}" is now linked.`))}async function X(n){const e=p(),r=(await A({serverUrl:n.serverUrl,authToken:n.authToken})).map(m=>m.type),i=k.platform(),t=i==="win32"?"windows":i==="darwin"?"macos":"linux",d=await fetch(`${n.serverUrl}/api/machines/desktop/register`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.authToken}`},body:JSON.stringify({machineId:e.machineId,name:n.machineName,os:t,agentList:r})});if(!d.ok){const g=(await d.json().catch(()=>({}))).error??d.statusText;throw new Error(`Failed to register desktop machine: ${g}`)}const c=await d.json();if(!c.machine?.id||!c.machineToken||!c.accountNamespaceId)throw new Error("Failed to register desktop machine: missing machine token");return e.machineId=c.machine.id,e.machineToken=c.machineToken,e.accountNamespaceId=c.accountNamespaceId,e.serverUrl=n.serverUrl,v(e),{machineId:c.machine.id,machineName:c.machine.name}}async function Z(n){const e=n?.trim();if(e)return e;const o=process.env.SHENNIAN_DESKTOP_SERVER_URL?.trim();if(o)return o;const r=p().serverUrl?.trim();return r||N()}async function pe(n,e){const o=p();if(!o.machineToken||!o.machineId){const i=n??await N();await D({serverUrl:i,machineName:e,force:!1})}else console.log(a.green(`\u2713 Already paired (machine ID: ${o.machineId})`));O(),U(),console.log(a.gray(`
|
|
11
|
+
Starting background service...`)),x()||b()}function ue(n){n.command("desktop-register",{hidden:!0}).description("Register this machine to the authenticated account").option("--api <url>","Server URL").option("--name <name>","Machine name",k.hostname()).action(async e=>{try{const o=process.env.SHENNIAN_DESKTOP_AUTH_TOKEN;if(!o)throw new Error("Missing desktop auth token");const r=await Z(e.api),i=await X({serverUrl:r,authToken:o,machineName:e.name});console.log(JSON.stringify({ok:!0,...i}))}catch(o){console.error(o instanceof Error?o.message:String(o)),process.exit(1)}}),n.command("pair").description("Pair this machine to a Shennian account (re-pair if already paired)").option("--api <url>","Server URL override").option("--server <url>","Server URL override").option("--name <name>","Machine name",k.hostname()).option("--json","Emit machine-readable JSONL events").option("--browser","Pair by approving a browser authorization request").option("--token","Pair with the existing QR code / token flow").option("--force","Force re-pair even when a machine token exists").action(async e=>{const o=p();let r;try{r=j({browser:e.browser,token:e.token,json:e.json,stdinIsTty:!!process.stdin.isTTY,stdoutIsTty:!!process.stdout.isTTY})}catch(c){const m=c instanceof Error?c.message:"Invalid pairing mode";e.json&&f("PAIR_MODE_CONFLICT",m),console.error(a.red(`\u2717 ${m}`)),process.exit(1)}if(r==="prompt"&&(r=await _()),o.machineToken&&o.machineId&&!e.force){if(e.json){l({type:"done",status:"already-paired",machineId:o.machineId});return}if(console.log(a.yellow(`Currently paired (machine ID: ${o.machineId})`)),!await V("Re-pairing will unlink the current account. Continue? (y/N) ")){console.log(a.gray("Cancelled"));return}}const i=R(e.server??e.api??o.serverUrl??await N(),o),t=!!(e.force||o.machineToken&&o.machineId);await D({serverUrl:i,machineName:e.name,force:t,json:!!e.json,mode:r}),O(),U(),e.json?l({type:"daemon.starting"}):console.log(a.gray(`
|
|
12
|
+
Starting background service...`)),x({quiet:!!e.json})||b({quiet:!!e.json}),e.json&&(F(()=>M({cleanupStale:!0})),l({type:"done",status:"paired",machineId:p().machineId}))})}export{X as registerDesktopMachine,ue as registerPairCommand,D as runPairFlow,pe as runSmartStart};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
`)}catch(
|
|
3
|
-
`):
|
|
4
|
-
`),
|
|
1
|
+
import w from"node:crypto";import f from"node:fs";import{PublicAgentClientError as c}from"../agents/public-agent-client.js";import{ProjectClient as j}from"../agents/project-client.js";const g={write:o=>process.stdout.write(o),fail:()=>{process.exitCode=1}},x=/^[A-Za-z0-9_.:@-]{1,191}$/,y=/^[A-Za-z0-9_.:@-]{8,128}$/,l=2e4;function A(o,r={}){const t=r.client??new j,n=r.io??g,p=o.command("project").description("List Shennian projects and run tasks in them");p.command("create").description("Register an owned computer directory as a project; does not create or move files").requiredOption("--machine <id>","Exact owned machine ID").requiredOption("--workdir <path>","Absolute existing target directory").option("--name <name>","Project display name").action(i=>s("project.create",n,()=>t.createProject({machineId:a(i.machine,"machine_id_invalid"),workDir:i.workdir,...i.name?{name:i.name}:{}}))),p.command("update <project-id>").description("Rename a project or change its launch defaults; does not move its directory").option("--name <name>","Display name").option("--agent <type>","Default Agent").option("--model <id>","Default model; requires --agent").action((i,e)=>s("project.update",n,()=>{if(e.model&&!e.agent)throw new c("agent_required","Changing a default model requires --agent.");return t.updateProject(a(i,"project_id_invalid"),{...e.name!==void 0?{name:e.name}:{},...e.agent?{agentType:e.agent,modelId:e.model??null}:{}})})),p.command("list").description("List the paired user's projects with machine status and recent tasks").action(()=>s("project.list",n,()=>t.listProjects()));const d=p.command("task").description("List, create, read, message or stop tasks in an exact project");d.command("list <project-id>").description("List recent tasks (conversations) of one exact project").option("--limit <count>","Number of tasks (1-15)","3").action((i,e)=>s("project.task.list",n,()=>t.listTasks(a(i,"project_id_invalid"),h(e.limit,15)))),d.command("create <project-id>").description("Start a new task in one exact project; long or file-changing work belongs here").option("--instruction <text>","Task instruction").option("--instruction-file <path>","Read the instruction from a file").option("--agent <type>","Exact AI type of the project machine; defaults to the project's usual one").option("--model <id>","Exact model id; defaults to the project's usual one").option("--request-id <id>","Stable id; reuse it when retrying so no duplicate task is created").action((i,e)=>s("project.task.create",n,async()=>{const m=await t.createTask(a(i,"project_id_invalid"),{instruction:_(e.instruction,e.instructionFile,"instruction"),requestId:k(e.requestId),...e.agent?{agentType:a(e.agent,"agent_invalid")}:{},...e.model?{modelId:a(e.model,"agent_invalid")}:{}}),u=process.env.SHENNIAN_MANAGED_ROOM_CONTEXT?void 0:process.env.SHENNIAN_STEWARD_SESSION_ID;if(u&&typeof m.taskId=="string")try{return{...m,tracking:await t.watchTask(m.taskId,u)}}catch{return{...m,tracking:{enabled:!1,error:"task_watch_failed",nextAction:"Use project task watch with the same task ID; do not recreate the task."}}}return m})),d.command("watch <task-id>").description("Send task terminal events back to the current personal steward").action(i=>s("project.task.watch",n,()=>{const e=process.env.SHENNIAN_MANAGED_ROOM_CONTEXT?void 0:process.env.SHENNIAN_STEWARD_SESSION_ID;if(!e)throw new c("steward_context_required","Run this command inside your personal steward conversation.");return t.watchTask(a(i,"task_id_invalid"),e)})),d.command("read <task-id>").description("Read the latest visible messages of one exact task").option("--limit <count>","Number of messages (1-8)","4").action((i,e)=>s("project.task.read",n,()=>t.readTask(a(i,"task_id_invalid"),h(e.limit,8)))),d.command("send <task-id>").description("Send another message to one exact existing task").option("--text <text>","Message text").option("--text-file <path>","Read the message from a file").option("--request-id <id>","Stable id; reuse it when retrying so the message is sent once").action((i,e)=>s("project.task.send",n,()=>t.sendTask(a(i,"task_id_invalid"),{text:_(e.text,e.textFile,"text"),requestId:k(e.requestId)}))),d.command("stop <task-id>").description("Ask one exact task to stop its current run (not a durable pause)").action(i=>s("project.task.stop",n,()=>t.stopTask(a(i,"task_id_invalid"))))}async function s(o,r,t){try{r.write(`${JSON.stringify({ok:!0,command:o,result:await t()})}
|
|
2
|
+
`)}catch(n){n instanceof c?r.write(`${JSON.stringify({ok:!1,error:n.code,message:n.message,nextAction:n.nextAction})}
|
|
3
|
+
`):r.write(`${JSON.stringify({ok:!1,error:"project_command_failed",message:"Shennian project command failed.",nextAction:null})}
|
|
4
|
+
`),r.fail()}}function a(o,r){if(!x.test(o))throw new c(r,"Use the exact id returned by Shennian.");return o}function h(o,r){const t=Number(o);return Number.isFinite(t)?Math.min(Math.max(Math.floor(t),1),r):r}function k(o){if(o===void 0)return`steward-${w.randomUUID()}`;if(!y.test(o))throw new c("request_id_invalid","Use 8-128 letters, digits or _.:@- for --request-id.");return o}function _(o,r,t){if(o!==void 0&&r!==void 0)throw new c(`${t}_invalid`,`Use either inline text or a file for ${t}, not both.`);let n=o;if(r!==void 0)try{n=f.readFileSync(r,"utf8")}catch{throw new c(`${t}_invalid`,`The ${t} file could not be read.`)}if(n=n?.trim(),!n||n.length>l)throw new c(`${t}_invalid`,`Provide non-empty ${t} of at most ${l} characters.`);return n}export{A as registerProjectCommand};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{callDaemonIpc as i}from"../daemon-ipc/client.js";import{resolveManagedRoomIpcPaths as n}from"../daemon-ipc/paths.js";function a(
|
|
1
|
+
import{callDaemonIpc as i}from"../daemon-ipc/client.js";import{resolveManagedRoomIpcPaths as n}from"../daemon-ipc/paths.js";function a(r){r.command("schedule").description("Manage scheduled work in this conversation").requiredOption("--operation <operation>","list/create/update/pause/resume/delete").option("--id <id>").option("--version <version>").option("--operation-id <operationId>").option("--execution-mode <mode>","main or worker; personal schedules only").option("--time-description <timeDescription>").option("--timezone <timezone>").option("--prompt <prompt>").action(async o=>{try{const e=process.env.SHENNIAN_SCHEDULE_CONTEXT;if(!e)throw new Error("schedule_context_required");const t=await i({method:"schedule.personal",paths:n(),params:{...o,version:o.version?Number(o.version):void 0,context:e},timeoutMs:15e3});process.stdout.write(`${JSON.stringify(t)}
|
|
2
2
|
`)}catch(e){console.error(e instanceof Error?e.message:"schedules_unavailable"),process.exitCode=1}})}export{a as registerScheduleCommand};
|