ticlawk 0.1.16-dev.2 → 0.1.16-dev.21

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.
@@ -7,7 +7,8 @@
7
7
  * and forwards to the ticlawk backend using the connector API key.
8
8
  *
9
9
  * Targets are parsed in the daemon (not on the wire to backend) so the
10
- * CLI can speak `#<group>` / `dm:@<user>` / `#<group>:<short-msg-id>`
10
+ * CLI can speak `#<group>` / `dm:<conversation-id>` / `dm:@<user>` /
11
+ * `#<group>:<short-msg-id>`
11
12
  * while backend keeps a flat conversation_id contract.
12
13
  */
13
14
 
@@ -34,7 +35,7 @@ export function invalidateServerInfoCache(actingAgentId = null) {
34
35
  }
35
36
 
36
37
  /**
37
- * Parse a target string into { conversationId, threadRootMsgId } using a
38
+ * Parse a target string into { conversationId, replyToMessageId } using a
38
39
  * cached server-info lookup. Returns null fields if the target cannot be
39
40
  * resolved; callers should treat that as a 404.
40
41
  *
@@ -43,29 +44,29 @@ export function invalidateServerInfoCache(actingAgentId = null) {
43
44
  * dm:@<handle> -> find DM conversation whose other member is <handle>
44
45
  * #<uuid> -> conversation_id = <uuid>
45
46
  * #<group-name> -> find group conversation by name
46
- * <foo>:<short-msg-id> -> thread under <foo>, root = first message whose
47
+ * <foo>:<short-msg-id> -> replies under <foo>, root = first message whose
47
48
  * id startsWith <short-msg-id>
48
49
  */
49
50
  export async function resolveTarget(actingAgentId, target) {
50
- if (!target) return { conversationId: null, threadRootMsgId: null, error: 'target is required' };
51
+ if (!target) return { conversationId: null, replyToMessageId: null, error: 'target is required' };
51
52
 
52
- // Strip optional thread suffix.
53
+ // Strip optional message-reply suffix.
53
54
  let base = target;
54
- let threadShort = null;
55
+ let replyToMessageId = null;
55
56
  const colonIdx = target.indexOf(':', target.startsWith('dm:') ? 3 : 1);
56
57
  if (colonIdx > 0 && colonIdx < target.length - 1) {
57
- threadShort = target.slice(colonIdx + 1);
58
+ replyToMessageId = target.slice(colonIdx + 1);
58
59
  base = target.slice(0, colonIdx);
59
60
  }
60
61
 
61
62
  if (/^[0-9a-f-]{36}$/i.test(base)) {
62
- return { conversationId: base, threadRootMsgId: threadShort, error: null };
63
+ return { conversationId: base, replyToMessageId, error: null };
63
64
  }
64
65
  if (base.startsWith('dm:') && /^[0-9a-f-]{36}$/i.test(base.slice(3))) {
65
- return { conversationId: base.slice(3), threadRootMsgId: threadShort, error: null };
66
+ return { conversationId: base.slice(3), replyToMessageId, error: null };
66
67
  }
67
68
  if (base.startsWith('#') && /^[0-9a-f-]{36}$/i.test(base.slice(1))) {
68
- return { conversationId: base.slice(1), threadRootMsgId: threadShort, error: null };
69
+ return { conversationId: base.slice(1), replyToMessageId, error: null };
69
70
  }
70
71
 
71
72
  const info = await getCachedServerInfo(actingAgentId);
@@ -76,19 +77,30 @@ export async function resolveTarget(actingAgentId, target) {
76
77
  const match = convs.find((c) =>
77
78
  c.type === 'dm' && (String(c.display_name || c.name || '').toLowerCase() === handle)
78
79
  );
79
- if (match) return { conversationId: match.id, threadRootMsgId: threadShort, error: null };
80
- return { conversationId: null, threadRootMsgId: null, error: `unknown dm target: ${target}` };
80
+ if (match) return { conversationId: match.id, replyToMessageId, error: null };
81
+ return { conversationId: null, replyToMessageId: null, error: `unknown dm target: ${target}` };
81
82
  }
82
83
  if (base.startsWith('#')) {
83
84
  const name = base.slice(1).toLowerCase();
84
85
  const match = convs.find((c) =>
85
86
  c.type === 'group' && (String(c.name || c.display_name || '').toLowerCase() === name)
86
87
  );
87
- if (match) return { conversationId: match.id, threadRootMsgId: threadShort, error: null };
88
- return { conversationId: null, threadRootMsgId: null, error: `unknown group target: ${target}` };
88
+ if (match) return { conversationId: match.id, replyToMessageId, error: null };
89
+
90
+ if (info?.agent?.is_cos) {
91
+ const workstreams = await api.listWorkstreams({ actingAgentId });
92
+ const workstreamMatch = workstreams.find((c) =>
93
+ String(c.name || c.display_name || '').toLowerCase() === name
94
+ );
95
+ if (workstreamMatch) {
96
+ return { conversationId: workstreamMatch.id, replyToMessageId, error: null };
97
+ }
98
+ }
99
+
100
+ return { conversationId: null, replyToMessageId: null, error: `unknown group target: ${target}` };
89
101
  }
90
102
 
91
- return { conversationId: null, threadRootMsgId: null, error: `invalid target syntax: ${target}` };
103
+ return { conversationId: null, replyToMessageId: null, error: `invalid target syntax: ${target}` };
92
104
  }
93
105
 
94
106
  function getActingAgentId(req, body = {}) {
@@ -109,6 +121,15 @@ function getRuntimeHostId(req, body = {}) {
109
121
  return null;
110
122
  }
111
123
 
124
+ function getCurrentConversationId(req, body = {}) {
125
+ const fromHeader = req.headers['x-ticlawk-current-conversation-id'];
126
+ if (typeof fromHeader === 'string' && fromHeader.trim()) return fromHeader.trim();
127
+ if (typeof body?.current_conversation_id === 'string' && body.current_conversation_id.trim()) {
128
+ return body.current_conversation_id.trim();
129
+ }
130
+ return null;
131
+ }
132
+
112
133
  function validateActingAgent(actingAgentId, ctx) {
113
134
  if (!actingAgentId) {
114
135
  return { ok: false, status: 400, error: 'TICLAWK_RUNTIME_AGENT_ID required (passed via X-Ticlawk-Acting-Agent-Id or body.acting_as_agent_id)' };
@@ -132,27 +153,52 @@ export async function handleMessageSend(req, body, ctx) {
132
153
  if (!text) return { status: 400, body: { error: 'text is required' } };
133
154
 
134
155
  let conversationId = body?.conversation_id || null;
135
- let threadRootMsgId = null;
156
+ let targetReplyToMessageId = null;
136
157
  if (!conversationId && body?.target) {
137
158
  const resolved = await resolveTarget(actingAgentId, String(body.target));
138
159
  if (resolved.error) {
139
160
  return { status: 404, body: { error: resolved.error } };
140
161
  }
141
162
  conversationId = resolved.conversationId;
142
- threadRootMsgId = resolved.threadRootMsgId;
163
+ targetReplyToMessageId = resolved.replyToMessageId;
143
164
  }
144
165
  if (!conversationId) {
145
166
  return { status: 400, body: { error: 'target or conversation_id is required' } };
146
167
  }
147
168
 
169
+ const currentConversationId = getCurrentConversationId(req, body);
170
+ if (currentConversationId && currentConversationId !== conversationId && !body?.allow_cross_target) {
171
+ debugLog('agent-cli', 'send.blocked-cross-target', {
172
+ actingAgentId,
173
+ currentConversationId,
174
+ conversationId,
175
+ target: body?.target || null,
176
+ });
177
+ return {
178
+ status: 409,
179
+ body: {
180
+ error: 'refusing to send to a different conversation from the current runtime turn',
181
+ current_conversation_id: currentConversationId,
182
+ target_conversation_id: conversationId,
183
+ hint: 'Use --allow-cross-target only for an intentional cross-conversation send.',
184
+ },
185
+ };
186
+ }
187
+
188
+ const mediaAssetIds = Array.isArray(body?.media_asset_ids)
189
+ ? body.media_asset_ids.map((v) => String(v).trim()).filter(Boolean)
190
+ : [];
191
+
148
192
  try {
149
193
  const data = await api.sendAgentMessage({
150
194
  actingAgentId,
151
195
  conversationId,
152
196
  text,
153
197
  seenUpToSeq: body?.seen_up_to_seq,
154
- replyToMessageId: body?.reply_to_message_id || threadRootMsgId || null,
198
+ replyToMessageId: body?.reply_to_message_id || targetReplyToMessageId || null,
155
199
  runtimeHostId: getRuntimeHostId(req, body),
200
+ mediaAssetIds,
201
+ metadata: body?.metadata,
156
202
  });
157
203
  debugLog('agent-cli', 'send.ok', {
158
204
  actingAgentId,
@@ -587,8 +633,8 @@ export async function handleAttachmentUpload(req, body, ctx) {
587
633
  });
588
634
  debugLog('agent-cli', 'attachment.upload', {
589
635
  actingAgentId,
590
- asset_id: data?.asset?.asset_id,
591
- bytes: data?.asset?.size_bytes,
636
+ asset_id: data?.data?.asset_id,
637
+ bytes: data?.data?.size_bytes,
592
638
  });
593
639
  return { status: 200, body: data };
594
640
  } catch (err) {
@@ -596,6 +642,28 @@ export async function handleAttachmentUpload(req, body, ctx) {
596
642
  }
597
643
  }
598
644
 
645
+ export async function handleProfileAvatarUpload(req, body, ctx) {
646
+ const actingAgentId = getActingAgentId(req, body);
647
+ const v = validateActingAgent(actingAgentId, ctx);
648
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
649
+ if (!body?.data_base64) return { status: 400, body: { error: 'data_base64 is required' } };
650
+ if (!body?.content_type || !String(body.content_type).startsWith('image/')) {
651
+ return { status: 400, body: { error: 'content_type must be image/*' } };
652
+ }
653
+ try {
654
+ const data = await api.uploadAgentAvatar({
655
+ actingAgentId,
656
+ filename: body?.filename || 'avatar.bin',
657
+ contentType: body.content_type,
658
+ dataBase64: body.data_base64,
659
+ });
660
+ debugLog('agent-cli', 'avatar.upload', { actingAgentId, url: data?.url });
661
+ return { status: 200, body: data };
662
+ } catch (err) {
663
+ return { status: err?.status || 500, body: { error: err?.message || 'avatar upload failed' } };
664
+ }
665
+ }
666
+
599
667
  export async function handleAttachmentView(req, query, ctx) {
600
668
  const actingAgentId = getActingAgentId(req, query);
601
669
  const v = validateActingAgent(actingAgentId, ctx);
@@ -689,6 +757,366 @@ export async function handleGroupMembersRemove(req, body, ctx) {
689
757
  }
690
758
  }
691
759
 
760
+ export async function handleWorkstreamCreate(req, body, ctx) {
761
+ const actingAgentId = getActingAgentId(req, body);
762
+ const v = validateActingAgent(actingAgentId, ctx);
763
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
764
+ const name = String(body?.name || '').trim();
765
+ if (!name) return { status: 400, body: { error: 'name is required' } };
766
+ try {
767
+ const data = await api.createWorkstream({
768
+ actingAgentId,
769
+ name,
770
+ description: body?.description || null,
771
+ charter: body?.charter ?? null,
772
+ memberAgentIds: Array.isArray(body?.member_agent_ids) ? body.member_agent_ids : [],
773
+ });
774
+ invalidateServerInfoCache(actingAgentId);
775
+ debugLog('agent-cli', 'workstream.create', {
776
+ actingAgentId, conversationId: data?.conversation?.id,
777
+ });
778
+ return { status: 200, body: data };
779
+ } catch (err) {
780
+ return { status: err?.status || 500, body: { error: err?.message || 'workstream create failed' } };
781
+ }
782
+ }
783
+
784
+ export async function handleWorkstreamDelete(req, body, ctx) {
785
+ const actingAgentId = getActingAgentId(req, body);
786
+ const v = validateActingAgent(actingAgentId, ctx);
787
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
788
+ let conversationId = body?.conversation_id || null;
789
+ if (!conversationId && body?.target) {
790
+ const resolved = await resolveTarget(actingAgentId, String(body.target));
791
+ if (resolved.error) return { status: 404, body: { error: resolved.error } };
792
+ conversationId = resolved.conversationId;
793
+ }
794
+ if (!conversationId) return { status: 400, body: { error: 'target or conversation_id is required' } };
795
+ try {
796
+ const data = await api.deleteWorkstream({ actingAgentId, conversationId });
797
+ invalidateServerInfoCache(actingAgentId);
798
+ return { status: 200, body: data };
799
+ } catch (err) {
800
+ return { status: err?.status || 500, body: { error: err?.message || 'workstream delete failed' } };
801
+ }
802
+ }
803
+
804
+ export async function handleWorkstreamList(req, query, ctx) {
805
+ const actingAgentId = getActingAgentId(req, query);
806
+ const v = validateActingAgent(actingAgentId, ctx);
807
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
808
+ try {
809
+ const data = await api.listWorkstreams({ actingAgentId });
810
+ return { status: 200, body: { data } };
811
+ } catch (err) {
812
+ return { status: err?.status || 500, body: { error: err?.message || 'workstream list failed' } };
813
+ }
814
+ }
815
+
816
+ export async function handleAgentList(req, query, ctx) {
817
+ const actingAgentId = getActingAgentId(req, query);
818
+ const v = validateActingAgent(actingAgentId, ctx);
819
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
820
+ try {
821
+ const data = await api.listAgentSlots({ actingAgentId });
822
+ return { status: 200, body: { data } };
823
+ } catch (err) {
824
+ return { status: err?.status || 500, body: { error: err?.message || 'agent list failed' } };
825
+ }
826
+ }
827
+
828
+ export async function handleAgentCreate(req, body, ctx) {
829
+ const actingAgentId = getActingAgentId(req, body);
830
+ const v = validateActingAgent(actingAgentId, ctx);
831
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
832
+ const name = String(body?.name || '').trim();
833
+ const runtime = String(body?.runtime || '').trim();
834
+ if (!name) return { status: 400, body: { error: 'name is required' } };
835
+ if (!runtime) return { status: 400, body: { error: 'runtime is required' } };
836
+ try {
837
+ const data = await api.createAgentSlot({
838
+ actingAgentId,
839
+ name,
840
+ runtime,
841
+ description: body?.description || null,
842
+ displayName: body?.display_name || null,
843
+ model: body?.model || null,
844
+ });
845
+ return { status: 200, body: data };
846
+ } catch (err) {
847
+ return { status: err?.status || 500, body: { error: err?.message || 'agent create failed' } };
848
+ }
849
+ }
850
+
851
+ export async function handleAgentDelete(req, body, ctx) {
852
+ const actingAgentId = getActingAgentId(req, body);
853
+ const v = validateActingAgent(actingAgentId, ctx);
854
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
855
+ const agentId = String(body?.agent_id || '').trim();
856
+ if (!agentId) return { status: 400, body: { error: 'agent_id is required' } };
857
+ try {
858
+ const data = await api.archiveAgentSlot({ actingAgentId, agentId });
859
+ return { status: 200, body: data };
860
+ } catch (err) {
861
+ return { status: err?.status || 500, body: { error: err?.message || 'agent delete failed' } };
862
+ }
863
+ }
864
+
865
+ export async function handleServiceCreate(req, body, ctx) {
866
+ const actingAgentId = getActingAgentId(req, body);
867
+ const v = validateActingAgent(actingAgentId, ctx);
868
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
869
+ const name = String(body?.name || '').trim();
870
+ if (!name) return { status: 400, body: { error: 'name is required' } };
871
+ if (!body?.endpoint_config || typeof body.endpoint_config !== 'object') {
872
+ return { status: 400, body: { error: 'endpoint_config is required' } };
873
+ }
874
+ try {
875
+ const data = await api.createService({
876
+ actingAgentId, name,
877
+ description: body?.description || null,
878
+ contractSchema: body?.contract_schema ?? null,
879
+ endpointConfig: body.endpoint_config,
880
+ });
881
+ return { status: 200, body: data };
882
+ } catch (err) {
883
+ return { status: err?.status || 500, body: { error: err?.message || 'service create failed' } };
884
+ }
885
+ }
886
+
887
+ export async function handleServiceUpdate(req, body, ctx) {
888
+ const actingAgentId = getActingAgentId(req, body);
889
+ const v = validateActingAgent(actingAgentId, ctx);
890
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
891
+ const serviceId = String(body?.service_id || '').trim();
892
+ if (!serviceId) return { status: 400, body: { error: 'service_id is required' } };
893
+ const patch = {};
894
+ if ('description' in (body || {})) patch.description = body.description;
895
+ if ('contract_schema' in (body || {})) patch.contract_schema = body.contract_schema;
896
+ if ('endpoint_config' in (body || {})) patch.endpoint_config = body.endpoint_config;
897
+ if ('status' in (body || {})) patch.status = body.status;
898
+ try {
899
+ const data = await api.updateService({ actingAgentId, serviceId, ...patch });
900
+ return { status: 200, body: data };
901
+ } catch (err) {
902
+ return { status: err?.status || 500, body: { error: err?.message || 'service update failed' } };
903
+ }
904
+ }
905
+
906
+ export async function handleServiceDelete(req, body, ctx) {
907
+ const actingAgentId = getActingAgentId(req, body);
908
+ const v = validateActingAgent(actingAgentId, ctx);
909
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
910
+ const serviceId = String(body?.service_id || '').trim();
911
+ if (!serviceId) return { status: 400, body: { error: 'service_id is required' } };
912
+ try {
913
+ const data = await api.deleteService({ actingAgentId, serviceId });
914
+ return { status: 200, body: data };
915
+ } catch (err) {
916
+ return { status: err?.status || 500, body: { error: err?.message || 'service delete failed' } };
917
+ }
918
+ }
919
+
920
+ export async function handleServiceList(req, query, ctx) {
921
+ const actingAgentId = getActingAgentId(req, query);
922
+ const v = validateActingAgent(actingAgentId, ctx);
923
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
924
+ try {
925
+ const data = await api.listServices({ actingAgentId });
926
+ return { status: 200, body: { data } };
927
+ } catch (err) {
928
+ return { status: err?.status || 500, body: { error: err?.message || 'service list failed' } };
929
+ }
930
+ }
931
+
932
+ export async function handleServiceInfo(req, query, ctx) {
933
+ const actingAgentId = getActingAgentId(req, query);
934
+ const v = validateActingAgent(actingAgentId, ctx);
935
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
936
+ const name = String(query?.name || '').trim();
937
+ if (!name) return { status: 400, body: { error: 'name is required' } };
938
+ try {
939
+ const data = await api.getServiceInfo({ actingAgentId, name });
940
+ return { status: 200, body: data };
941
+ } catch (err) {
942
+ return { status: err?.status || 500, body: { error: err?.message || 'service info failed' } };
943
+ }
944
+ }
945
+
946
+ export async function handleServiceCall(req, body, ctx) {
947
+ const actingAgentId = getActingAgentId(req, body);
948
+ const v = validateActingAgent(actingAgentId, ctx);
949
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
950
+ const name = String(body?.name || '').trim();
951
+ if (!name) return { status: 400, body: { error: 'name is required' } };
952
+ try {
953
+ const data = await api.callService({
954
+ actingAgentId, name,
955
+ input: body?.input ?? null,
956
+ });
957
+ return { status: 200, body: data };
958
+ } catch (err) {
959
+ return { status: err?.status || 500, body: { error: err?.message || 'service call failed' } };
960
+ }
961
+ }
962
+
963
+ export async function handleBriefingGet(req, query, ctx) {
964
+ const actingAgentId = getActingAgentId(req, query);
965
+ const v = validateActingAgent(actingAgentId, ctx);
966
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
967
+ const briefingId = String(query?.id || '').trim();
968
+ if (!briefingId) return { status: 400, body: { error: 'id is required' } };
969
+ try {
970
+ const data = await api.getBriefing({ actingAgentId, briefingId });
971
+ return { status: 200, body: data };
972
+ } catch (err) {
973
+ return { status: err?.status || 500, body: { error: err?.message || 'briefing get failed' } };
974
+ }
975
+ }
976
+
977
+ export async function handleBriefingPublish(req, body, ctx) {
978
+ const actingAgentId = getActingAgentId(req, body);
979
+ const v = validateActingAgent(actingAgentId, ctx);
980
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
981
+ const bodyText = typeof body?.body_text === 'string' && body.body_text.trim() ? body.body_text.trim() : null;
982
+ const attachmentAssetId = typeof body?.attachment_asset_id === 'string' && body.attachment_asset_id.trim()
983
+ ? body.attachment_asset_id.trim()
984
+ : null;
985
+ const responseMode = typeof body?.response_mode === 'string' && body.response_mode.trim()
986
+ ? body.response_mode.trim().toLowerCase()
987
+ : 'info';
988
+ if (!bodyText) {
989
+ return { status: 400, body: { error: 'body_text is required' } };
990
+ }
991
+ if (bodyText && bodyText.length > 140) {
992
+ return { status: 400, body: { error: 'body_text must be ≤140 chars' } };
993
+ }
994
+ if (!['info', 'approval'].includes(responseMode)) {
995
+ return { status: 400, body: { error: 'response_mode must be info or approval' } };
996
+ }
997
+ const currentConversationId = getCurrentConversationId(req, body);
998
+ try {
999
+ const data = await api.publishBriefing({
1000
+ actingAgentId,
1001
+ bodyText,
1002
+ attachmentAssetId,
1003
+ currentConversationId,
1004
+ responseMode,
1005
+ });
1006
+ return { status: 200, body: data };
1007
+ } catch (err) {
1008
+ return { status: err?.status || 500, body: { error: err?.message || 'briefing publish failed' } };
1009
+ }
1010
+ }
1011
+
1012
+ export async function handleCredentialRequest(req, body, ctx) {
1013
+ const actingAgentId = getActingAgentId(req, body);
1014
+ const v = validateActingAgent(actingAgentId, ctx);
1015
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
1016
+ const name = String(body?.name || '').trim();
1017
+ if (!name) return { status: 400, body: { error: 'name is required' } };
1018
+ let workstreamId = body?.workstream_id || null;
1019
+ if (!workstreamId && body?.target) {
1020
+ const resolved = await resolveTarget(actingAgentId, String(body.target));
1021
+ if (resolved.error) return { status: 404, body: { error: resolved.error } };
1022
+ workstreamId = resolved.conversationId;
1023
+ }
1024
+ try {
1025
+ const data = await api.requestCredential({
1026
+ actingAgentId,
1027
+ name,
1028
+ description: body?.description || null,
1029
+ workstreamId,
1030
+ });
1031
+ return { status: 200, body: data };
1032
+ } catch (err) {
1033
+ return { status: err?.status || 500, body: { error: err?.message || 'credential request failed' } };
1034
+ }
1035
+ }
1036
+
1037
+ export async function handleWorkstreamDashboardSet(req, body, ctx) {
1038
+ const actingAgentId = getActingAgentId(req, body);
1039
+ const v = validateActingAgent(actingAgentId, ctx);
1040
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
1041
+ let conversationId = body?.conversation_id || null;
1042
+ if (!conversationId && body?.target) {
1043
+ const resolved = await resolveTarget(actingAgentId, String(body.target));
1044
+ if (resolved.error) return { status: 404, body: { error: resolved.error } };
1045
+ conversationId = resolved.conversationId;
1046
+ }
1047
+ if (!conversationId) return { status: 400, body: { error: 'target or conversation_id is required' } };
1048
+ const payload = { actingAgentId, conversationId };
1049
+ if ('data_json' in (body || {})) payload.dataJson = body.data_json;
1050
+ if ('html_template' in (body || {})) payload.htmlTemplate = body.html_template;
1051
+ try {
1052
+ const data = await api.setWorkstreamDashboard(payload);
1053
+ return { status: 200, body: data };
1054
+ } catch (err) {
1055
+ return { status: err?.status || 500, body: { error: err?.message || 'dashboard set failed' } };
1056
+ }
1057
+ }
1058
+
1059
+ export async function handleWorkstreamDashboardGet(req, query, ctx) {
1060
+ const actingAgentId = getActingAgentId(req, query);
1061
+ const v = validateActingAgent(actingAgentId, ctx);
1062
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
1063
+ let conversationId = query?.conversation_id || null;
1064
+ if (!conversationId && query?.target) {
1065
+ const resolved = await resolveTarget(actingAgentId, String(query.target));
1066
+ if (resolved.error) return { status: 404, body: { error: resolved.error } };
1067
+ conversationId = resolved.conversationId;
1068
+ }
1069
+ if (!conversationId) return { status: 400, body: { error: 'target or conversation_id is required' } };
1070
+ try {
1071
+ const data = await api.getWorkstreamDashboard({ actingAgentId, conversationId });
1072
+ return { status: 200, body: data };
1073
+ } catch (err) {
1074
+ return { status: err?.status || 500, body: { error: err?.message || 'dashboard get failed' } };
1075
+ }
1076
+ }
1077
+
1078
+ export async function handleWorkstreamCharterGet(req, query, ctx) {
1079
+ const actingAgentId = getActingAgentId(req, query);
1080
+ const v = validateActingAgent(actingAgentId, ctx);
1081
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
1082
+ let conversationId = query?.conversation_id || null;
1083
+ if (!conversationId && query?.target) {
1084
+ const resolved = await resolveTarget(actingAgentId, String(query.target));
1085
+ if (resolved.error) return { status: 404, body: { error: resolved.error } };
1086
+ conversationId = resolved.conversationId;
1087
+ }
1088
+ if (!conversationId) return { status: 400, body: { error: 'target or conversation_id is required' } };
1089
+ try {
1090
+ const data = await api.getWorkstreamCharter({ actingAgentId, conversationId });
1091
+ return { status: 200, body: data };
1092
+ } catch (err) {
1093
+ return { status: err?.status || 500, body: { error: err?.message || 'charter get failed' } };
1094
+ }
1095
+ }
1096
+
1097
+ export async function handleWorkstreamCharterSet(req, body, ctx) {
1098
+ const actingAgentId = getActingAgentId(req, body);
1099
+ const v = validateActingAgent(actingAgentId, ctx);
1100
+ if (!v.ok) return { status: v.status, body: { error: v.error } };
1101
+ let conversationId = body?.conversation_id || null;
1102
+ if (!conversationId && body?.target) {
1103
+ const resolved = await resolveTarget(actingAgentId, String(body.target));
1104
+ if (resolved.error) return { status: 404, body: { error: resolved.error } };
1105
+ conversationId = resolved.conversationId;
1106
+ }
1107
+ if (!conversationId) return { status: 400, body: { error: 'target or conversation_id is required' } };
1108
+ const charter = typeof body?.charter === 'string' ? body.charter : null;
1109
+ try {
1110
+ const data = await api.setWorkstreamCharter({ actingAgentId, conversationId, charter });
1111
+ debugLog('agent-cli', 'workstream.charter.set', {
1112
+ actingAgentId, conversationId, len: charter?.length ?? 0,
1113
+ });
1114
+ return { status: 200, body: data };
1115
+ } catch (err) {
1116
+ return { status: err?.status || 500, body: { error: err?.message || 'charter set failed' } };
1117
+ }
1118
+ }
1119
+
692
1120
  export async function handleServerInfo(req, query, ctx) {
693
1121
  const actingAgentId = getActingAgentId(req, query);
694
1122
  const v = validateActingAgent(actingAgentId, ctx);
@@ -1,17 +1,13 @@
1
1
  /**
2
- * Per-agent slock-style home directory: ~/.ticlawk/agents/<agent_id>/
2
+ * Per-agent home directory: ~/.ticlawk/agents/<agent_id>/
3
3
  *
4
- * This is the agent's authoritative workspace. The daemon spawns every
5
- * runtime with this as cwd; the agent's MEMORY.md, notes/, and any
6
- * artifacts it produces live here. No project binding.
7
- *
8
- * Following slock's daemon model (dist/chunk-M4A5QPUN.js:5079) —
9
- * dataDir = ~/.slock/agents, agentDataDir = <dataDir>/<id>, and every
10
- * driver.spawn() receives `workingDirectory: agentDataDir`. One MEMORY.md
11
- * per agent, lives in cwd, agent reads it via `cat MEMORY.md`.
4
+ * The agent's authoritative workspace. The daemon spawns every runtime
5
+ * with this as cwd; the agent's MEMORY.md, notes/, and any artifacts
6
+ * it produces live here. No project binding — one MEMORY.md per agent,
7
+ * lives in cwd, agent reads it via `cat MEMORY.md`.
12
8
  */
13
9
 
14
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
10
+ import { existsSync, lstatSync, mkdirSync, readFileSync, symlinkSync, writeFileSync } from 'node:fs';
15
11
  import { join } from 'node:path';
16
12
  import { AF_HOME } from './config.mjs';
17
13
 
@@ -41,9 +37,53 @@ export function ensureAgentHome(agentId, { displayName } = {}) {
41
37
  if (!existsSync(memoryPath)) {
42
38
  writeFileSync(memoryPath, buildInitialMemoryMd({ displayName, home }), 'utf8');
43
39
  }
40
+ ensureSkillSymlinks(home);
44
41
  return home;
45
42
  }
46
43
 
44
+ /**
45
+ * Cross-runtime skill discovery: every runtime (Claude Code, Codex,
46
+ * opencode, pi, openclaw) auto-discovers SKILL.md under at least one of
47
+ * .claude/skills/, .codex/skills/, .opencode/skills/, .pi/skills/, or
48
+ * .agents/skills/. We pin everything to a single source-of-truth
49
+ * directory (.agents/skills/) and symlink the rest so a skill written
50
+ * once is visible to every runtime without sync machinery.
51
+ *
52
+ * .pi and .opencode skip the symlink — both natively scan
53
+ * .agents/skills/ in addition to their own folder.
54
+ *
55
+ * No migration / no recovery: if the target path already exists as a
56
+ * real dir or wrong-target symlink, we leave it alone. The user (or a
57
+ * future agent) resolves it manually. See cos_impl.md §一.不为错误兜底.
58
+ */
59
+ function ensureSkillSymlinks(home) {
60
+ const realRoot = join(home, '.agents', 'skills');
61
+ mkdirSync(realRoot, { recursive: true });
62
+
63
+ const links = [
64
+ { dir: join(home, '.claude'), name: 'skills', target: '../.agents/skills' },
65
+ { dir: join(home, '.codex'), name: 'skills', target: '../.agents/skills' },
66
+ // openclaw expects skills/ at the home root
67
+ { dir: home, name: 'skills', target: '.agents/skills' },
68
+ ];
69
+
70
+ for (const { dir, name, target } of links) {
71
+ mkdirSync(dir, { recursive: true });
72
+ const linkPath = join(dir, name);
73
+ let stat = null;
74
+ try { stat = lstatSync(linkPath); } catch { /* not present */ }
75
+ if (stat) continue; // path already exists — do not touch
76
+ try {
77
+ symlinkSync(target, linkPath, 'dir');
78
+ } catch (err) {
79
+ // Best-effort: an EEXIST race or platform that disallows symlinks
80
+ // gets logged but doesn't fail spawn. Skills just won't be visible
81
+ // for that runtime via this folder.
82
+ console.warn(`[agent-home] failed to symlink ${linkPath} -> ${target}: ${err?.message || err}`);
83
+ }
84
+ }
85
+ }
86
+
47
87
  function buildInitialMemoryMd({ displayName, home }) {
48
88
  const lines = [
49
89
  `# ${displayName || 'Agent'}`,
package/src/core/argv.mjs CHANGED
@@ -29,7 +29,17 @@ export function parseOptionArgs(argv = []) {
29
29
  const value = inlineValue !== undefined
30
30
  ? inlineValue
31
31
  : argv[i + 1] && !argv[i + 1].startsWith('-') ? argv[++i] : true;
32
- args[rawKey] = value;
32
+ // Repeated flags collect into an array so `--attach a --attach b`
33
+ // surfaces as ['a','b'] to callers that expect repeatable input
34
+ // (--attach on message send, --member on group create, etc).
35
+ // First occurrence stays scalar so single-value callers don't
36
+ // have to learn array-or-string.
37
+ if (Object.prototype.hasOwnProperty.call(args, rawKey)) {
38
+ const existing = args[rawKey];
39
+ args[rawKey] = Array.isArray(existing) ? [...existing, value] : [existing, value];
40
+ } else {
41
+ args[rawKey] = value;
42
+ }
33
43
  continue;
34
44
  }
35
45
  args._.push(arg);