ticlawk 0.1.16-dev.15 → 0.1.16-dev.16
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/README.md +14 -2
- package/bin/ticlawk.mjs +70 -20
- package/package.json +1 -1
- package/src/adapters/ticlawk/api.mjs +18 -6
- package/src/adapters/ticlawk/credentials.mjs +41 -1
- package/src/adapters/ticlawk/index.mjs +91 -196
- package/src/adapters/ticlawk/wake-client.mjs +1 -1
- package/src/cli/agent-commands.mjs +131 -79
- package/src/core/agent-cli-handlers.mjs +83 -24
- package/src/core/http.mjs +5 -0
- package/src/core/runtime-env.mjs +7 -0
- package/src/core/runtime-support.mjs +101 -0
- package/src/runtimes/_shared/brand.mjs +1 -0
- package/src/runtimes/_shared/goal-task-protocol.mjs +196 -0
- package/src/runtimes/_shared/standing-prompt.mjs +103 -294
- package/src/runtimes/_shared/wake-prompt.mjs +173 -0
- package/src/runtimes/claude-code/index.mjs +15 -9
- package/src/runtimes/codex/index.mjs +21 -14
- package/src/runtimes/openclaw/index.mjs +11 -9
- package/src/runtimes/opencode/index.mjs +36 -13
- package/src/runtimes/opencode/session.mjs +5 -4
- package/src/runtimes/pi/index.mjs +36 -14
- package/src/runtimes/pi/session.mjs +5 -2
|
@@ -3,6 +3,7 @@ import { getAgentHome } from './agent-home.mjs';
|
|
|
3
3
|
const ERROR_MAX_CHARS = 500;
|
|
4
4
|
const DEFAULT_DELTA_FLUSH_MS = 250;
|
|
5
5
|
const DEFAULT_DELTA_FLUSH_CHARS = 64;
|
|
6
|
+
const MAX_SCOPED_RUNTIME_SESSIONS = 50;
|
|
6
7
|
|
|
7
8
|
function truncateError(text) {
|
|
8
9
|
if (!text) return null;
|
|
@@ -105,6 +106,106 @@ export async function updateBindingRuntimeMeta(ctx, binding, runtimeMetaPatch, e
|
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
function readScopedSessionKey(inbound = {}) {
|
|
110
|
+
const conversationId = String(inbound?.conversationId || '').trim();
|
|
111
|
+
if (!conversationId) return '';
|
|
112
|
+
const threadRoot = String(inbound?.raw?.thread_root_message_id || '').trim();
|
|
113
|
+
return threadRoot ? `${conversationId}:thread:${threadRoot}` : conversationId;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function normalizeScopedRuntimeSessions(value) {
|
|
117
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return {};
|
|
118
|
+
const out = {};
|
|
119
|
+
for (const [key, session] of Object.entries(value)) {
|
|
120
|
+
if (!key || !session || typeof session !== 'object' || Array.isArray(session)) continue;
|
|
121
|
+
const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
|
|
122
|
+
if (!sessionId) continue;
|
|
123
|
+
out[key] = {
|
|
124
|
+
sessionId,
|
|
125
|
+
path: typeof session.path === 'string' ? session.path : null,
|
|
126
|
+
lastRotatedAt: typeof session.lastRotatedAt === 'string' ? session.lastRotatedAt : null,
|
|
127
|
+
updatedAt: typeof session.updatedAt === 'string' ? session.updatedAt : null,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function pruneScopedRuntimeSessions(sessions) {
|
|
134
|
+
const entries = Object.entries(sessions);
|
|
135
|
+
if (entries.length <= MAX_SCOPED_RUNTIME_SESSIONS) return sessions;
|
|
136
|
+
return Object.fromEntries(entries
|
|
137
|
+
.sort(([, a], [, b]) => {
|
|
138
|
+
const aTs = Date.parse(a?.updatedAt || a?.lastRotatedAt || '') || 0;
|
|
139
|
+
const bTs = Date.parse(b?.updatedAt || b?.lastRotatedAt || '') || 0;
|
|
140
|
+
return bTs - aTs;
|
|
141
|
+
})
|
|
142
|
+
.slice(0, MAX_SCOPED_RUNTIME_SESSIONS));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function resolveRuntimeSessionScope(meta = {}, inbound = {}) {
|
|
146
|
+
const key = readScopedSessionKey(inbound);
|
|
147
|
+
if (!key) {
|
|
148
|
+
return {
|
|
149
|
+
key: '',
|
|
150
|
+
sessions: {},
|
|
151
|
+
sessionId: meta.sessionId || null,
|
|
152
|
+
path: meta.path || null,
|
|
153
|
+
lastRotatedAt: meta.lastRotatedAt || null,
|
|
154
|
+
shouldRotate: !meta.sessionId || Boolean(meta.rotatePending),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const sessions = meta.rotatePending ? {} : normalizeScopedRuntimeSessions(meta.conversationSessions);
|
|
159
|
+
const scoped = sessions[key] || {};
|
|
160
|
+
return {
|
|
161
|
+
key,
|
|
162
|
+
sessions,
|
|
163
|
+
sessionId: scoped.sessionId || null,
|
|
164
|
+
path: scoped.path || null,
|
|
165
|
+
lastRotatedAt: scoped.lastRotatedAt || null,
|
|
166
|
+
shouldRotate: !scoped.sessionId || Boolean(meta.rotatePending),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function buildRuntimeSessionMetaPatch(meta = {}, scope = {}, result = {}) {
|
|
171
|
+
const now = new Date().toISOString();
|
|
172
|
+
const scoped = Boolean(scope.key);
|
|
173
|
+
const sessionId = result?.sessionId || scope.sessionId || (scoped ? null : meta.sessionId || null);
|
|
174
|
+
const path = result?.path || scope.path || (scoped ? null : meta.path || null);
|
|
175
|
+
const lastRotatedAt = scope.shouldRotate
|
|
176
|
+
? now
|
|
177
|
+
: (scope.lastRotatedAt || meta.lastRotatedAt || now);
|
|
178
|
+
|
|
179
|
+
if (!scoped) {
|
|
180
|
+
return {
|
|
181
|
+
sessionId,
|
|
182
|
+
...(path !== undefined ? { path } : {}),
|
|
183
|
+
rotatePending: false,
|
|
184
|
+
lastRotatedAt,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const sessions = {
|
|
189
|
+
...(scope.sessions || {}),
|
|
190
|
+
};
|
|
191
|
+
if (sessionId) {
|
|
192
|
+
sessions[scope.key] = {
|
|
193
|
+
sessionId,
|
|
194
|
+
path,
|
|
195
|
+
lastRotatedAt,
|
|
196
|
+
updatedAt: now,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
sessionId,
|
|
202
|
+
path,
|
|
203
|
+
conversationSessions: pruneScopedRuntimeSessions(sessions),
|
|
204
|
+
rotatePending: false,
|
|
205
|
+
lastRotatedAt,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
108
209
|
export function createDeltaAggregator({
|
|
109
210
|
flushDelta,
|
|
110
211
|
flushMs = DEFAULT_DELTA_FLUSH_MS,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BRAND_NAME = 'Ticlawk';
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Ticlawk goal/task protocol module.
|
|
3
|
+
*
|
|
4
|
+
* Keep goal/task law here instead of scattering it through role-specific
|
|
5
|
+
* wake envelopes. This module describes runtime behavior; API enforcement
|
|
6
|
+
* lives separately.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { BRAND_NAME } from './brand.mjs';
|
|
10
|
+
|
|
11
|
+
export const GOAL_TASK_PROTOCOL_MODULE = 'goal-task-protocol';
|
|
12
|
+
|
|
13
|
+
function getInboundRaw(ctx = {}) {
|
|
14
|
+
return ctx?.inbound?.raw && typeof ctx.inbound.raw === 'object'
|
|
15
|
+
? ctx.inbound.raw
|
|
16
|
+
: {};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function promptBlock(text) {
|
|
20
|
+
return text.trim();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function inferScope(ctx = {}) {
|
|
24
|
+
const raw = getInboundRaw(ctx);
|
|
25
|
+
const conversationType = String(raw.conversation_type || '').trim();
|
|
26
|
+
if (conversationType === 'group' || conversationType === 'thread') return 'group';
|
|
27
|
+
return 'dm';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getRecipientConversationRole(ctx = {}) {
|
|
31
|
+
const raw = getInboundRaw(ctx);
|
|
32
|
+
return String(raw.recipient_conversation_role || raw.recipient_role || '').trim().toLowerCase() || 'member';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function hasConversationAdminRole(ctx = {}) {
|
|
36
|
+
const raw = getInboundRaw(ctx);
|
|
37
|
+
if (raw.recipient_is_conversation_admin === true) return true;
|
|
38
|
+
const role = getRecipientConversationRole(ctx);
|
|
39
|
+
return role === 'admin' || role === 'owner';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function hasGoalAuthority(ctx = {}) {
|
|
43
|
+
const scope = inferScope(ctx);
|
|
44
|
+
if (scope === 'dm') return true;
|
|
45
|
+
return hasConversationAdminRole(ctx);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function buildUniversalInvariants() {
|
|
49
|
+
return promptBlock(`
|
|
50
|
+
Universal goal/task invariants:
|
|
51
|
+
- Every conversation can have a chartered goal.
|
|
52
|
+
- Group conversations can also have a shared task board.
|
|
53
|
+
- Valid shared task lifecycle: \`todo\` -> \`in_progress\` -> \`in_review\` -> \`done\`; \`canceled\` is also terminal for abandoned work.
|
|
54
|
+
- Claim the task before substantive task work when a claimable task exists.
|
|
55
|
+
`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function buildCoreConcepts() {
|
|
59
|
+
return promptBlock(`
|
|
60
|
+
Core concepts:
|
|
61
|
+
- Wake message: the inbound message or reminder that started the current turn.
|
|
62
|
+
- Conversation: a DM or group where messages, goals, tasks, and context live.
|
|
63
|
+
- Goal: the desired outcome of the conversation, whether it is a DM or group.
|
|
64
|
+
- Task: an executable unit of work that closes a gap between the current state and the goal.
|
|
65
|
+
- Owner: the human whose ${BRAND_NAME} workspace these conversations and agents belong to.
|
|
66
|
+
- DM: a private conversation. The agent in the DM owns the goal loop for that direct ask.
|
|
67
|
+
- Group: a shared conversation. Admin/owner agents own the group goal loop; non-admin agents execute tasks.
|
|
68
|
+
- Group admin/owner: the agent role responsible for the group goal loop, dashboard, briefings, membership, charter, and final task closure.
|
|
69
|
+
- Group member: a non-admin agent role responsible only for assigned or claimable tasks.
|
|
70
|
+
- Charter: the source of truth for a conversation's durable goal and role spec when present.
|
|
71
|
+
- Quote: context showing which message, briefing, or dashboard the user is responding to.
|
|
72
|
+
- Task board: the persistent group task list managed through \`ticlawk task list/create/claim/unclaim/update\`.
|
|
73
|
+
- Claimable task: a task assigned to you or an unclaimed task you are about to execute.
|
|
74
|
+
- Dashboard: an owner-facing HTML report for the conversation goal. It is the visual presentation of the key information associated with the level of achievement of the goal, like a report sent to a CEO for review.
|
|
75
|
+
- Briefing: an active notification to the owner. It tells the owner what happened, why it matters to the goal, and what owner action is needed, if any.
|
|
76
|
+
`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function buildStateSurfaceRules() {
|
|
80
|
+
return promptBlock(`
|
|
81
|
+
Dashboard and briefing rules:
|
|
82
|
+
- Dashboard is a visual report for the level of achievement of the conversation goal.
|
|
83
|
+
- Briefing is normally a short owner-facing text update of 140 characters or fewer.
|
|
84
|
+
- A briefing may include one image, video, or HTML attachment only when visual context is important to understand the update or make a decision.
|
|
85
|
+
- For pretty HTML artifacts, it is recommended to use /vibeshare to generate them. If /vibeshare is not available, install it into your skill directory using the setup instructions at https://vibeshare.page/skill. For ${BRAND_NAME} dashboards and briefing HTML attachments, generate the HTML locally, then publish it through ${BRAND_NAME} dashboard or briefing commands instead of /vibeshare publish.
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function buildGoalLoopOverlay() {
|
|
90
|
+
return promptBlock(`
|
|
91
|
+
Goal authority overlay: responsible for this conversation's goal and tasks
|
|
92
|
+
- You are responsible for driving the conversation toward its goal, not only replying to isolated messages.
|
|
93
|
+
- Maintain or infer the current goal from the direct ask, charter, dashboard/briefing quote, task board, and conversation context.
|
|
94
|
+
- Run the goal loop:
|
|
95
|
+
1. Evaluate current facts against the goal.
|
|
96
|
+
2. Identify the concrete gap, if any.
|
|
97
|
+
3. Decompose the gap into concrete tasks when useful.
|
|
98
|
+
4. Execute the next task yourself when appropriate, or create/assign a task when coordination is needed.
|
|
99
|
+
5. Check whether the result closes the gap.
|
|
100
|
+
6. Return to evaluating current facts against the goal.
|
|
101
|
+
- Stop the loop only when there is no meaningful gap, progress is blocked because the owner needs to provide input/resources/permission/confirmation/decision, or progress depends on an external/time-based wait.
|
|
102
|
+
- If there is no gap, say so briefly. If the goal is complete, report completion.
|
|
103
|
+
- If user input, resources, permission, confirmation, or a decision is needed, publish a briefing with one clear bundled request to the owner.
|
|
104
|
+
- If progress depends on future state, use a reminder or explicit resume condition rather than silently stalling.
|
|
105
|
+
- When a task reaches \`in_review\` or \`done\`, re-run the goal loop before dashboard, MEMORY.md, briefing, or wrap-up updates.
|
|
106
|
+
- Keep persistent state surfaces distinct: dashboard for goal-level reporting, MEMORY.md for your local continuity, and briefings for active owner notifications.
|
|
107
|
+
- Publish briefings and update dashboards only from DMs you own or groups where you are admin/owner.
|
|
108
|
+
`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function buildTaskOnlyOverlay() {
|
|
112
|
+
return promptBlock(`
|
|
113
|
+
Task authority overlay: responsible for tasks, not the conversation goal
|
|
114
|
+
- In this group context you are not responsible for managing the conversation-level goal loop.
|
|
115
|
+
- Do not create, redefine, or drive the group goal unless an admin/owner explicitly delegates that planning work to you.
|
|
116
|
+
- Focus on task execution: understand the assigned or claimable task, claim when required, perform the work, report the result or blocker, and set the task to \`in_review\` when ready.
|
|
117
|
+
- If the work appears mis-scoped, underspecified, or blocked on an owner decision, report it to the group/admin instead of taking over the goal loop.
|
|
118
|
+
- If you are not the group admin, do not set tasks to \`done\`; stop at \`in_review\` so an admin can validate and close.
|
|
119
|
+
- Keep updates concise and tied to concrete task state.
|
|
120
|
+
`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function buildDmScopeOverlay() {
|
|
124
|
+
return promptBlock(`
|
|
125
|
+
Scope overlay: DM
|
|
126
|
+
- In a DM, you own the goal loop for the direct conversation.
|
|
127
|
+
- Use the DM charter as the shared durable goal/role spec when present; update it when the durable DM goal changes.
|
|
128
|
+
- DM conversations do not have a shared task board. Execute directly where possible; use reminders for future wake-up.
|
|
129
|
+
- If the DM refers to work that belongs in a group, route it back to the relevant group or group task while still owning the user's ask until it is clearly transferred.
|
|
130
|
+
- Update the DM dashboard when the goal-level report the requester would care about has changed.
|
|
131
|
+
`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function buildGroupGoalScopeOverlay() {
|
|
135
|
+
return promptBlock(`
|
|
136
|
+
Scope overlay: group with admin or owner role
|
|
137
|
+
- In a group where you are admin or owner, you own both the group goal loop and the task system.
|
|
138
|
+
- Use the group task board for task inventory and assignment.
|
|
139
|
+
- Group messages coordinate working agents. Dashboard, MEMORY.md, and briefings are tracking/reporting surfaces with distinct roles.
|
|
140
|
+
- As admin/owner, update the group dashboard when the goal-level report the requester would care about has changed.
|
|
141
|
+
- As admin/owner, publish a briefing only when the owner should be actively notified: milestone reached, important change, blocker, request for owner input/resources/permission/confirmation/decision, or final result.
|
|
142
|
+
- Use \`ticlawk server info\`, \`ticlawk group members\`, and task board commands to understand membership, roles, current work, and ownership before routing work.
|
|
143
|
+
- Admin/owner role controls membership changes, charter updates, group deletion, and task finalization.
|
|
144
|
+
- Treat \`[charter]\` blocks as local conversation goal/roles only; do not put shared goal/task protocol, dashboard state, or task status in the charter.
|
|
145
|
+
`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function buildGroupTaskScopeOverlay() {
|
|
149
|
+
return promptBlock(`
|
|
150
|
+
Scope overlay: group without admin role
|
|
151
|
+
- In a group where you are not admin or owner, you are a task worker.
|
|
152
|
+
- Use the group task board to understand task inventory and assignment.
|
|
153
|
+
- Do not update dashboard, publish briefings, edit charter, manage membership, or drive group-level goal state unless an admin explicitly delegates a bounded task to you.
|
|
154
|
+
- If a message is ambient and not clearly for you, stay quiet unless your task expertise is directly needed and no better owner is evident.
|
|
155
|
+
`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function selectGoalTaskProtocolOverlays(ctx = {}) {
|
|
159
|
+
const scope = inferScope(ctx);
|
|
160
|
+
const recipientRole = getRecipientConversationRole(ctx);
|
|
161
|
+
const goalAuthority = hasGoalAuthority(ctx);
|
|
162
|
+
return { scope, recipientRole, goalAuthority };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function getGoalTaskProtocolOverlayKey(ctx = {}) {
|
|
166
|
+
const overlays = selectGoalTaskProtocolOverlays(ctx);
|
|
167
|
+
return `${overlays.scope}:${overlays.recipientRole}:${overlays.goalAuthority ? 'goal' : 'task'}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function buildGoalTaskProtocolPrompt(ctx = {}) {
|
|
171
|
+
const overlays = selectGoalTaskProtocolOverlays(ctx);
|
|
172
|
+
const authorityOverlay = overlays.goalAuthority
|
|
173
|
+
? buildGoalLoopOverlay()
|
|
174
|
+
: buildTaskOnlyOverlay();
|
|
175
|
+
const scopeOverlay = overlays.scope === 'dm'
|
|
176
|
+
? buildDmScopeOverlay()
|
|
177
|
+
: overlays.goalAuthority
|
|
178
|
+
? buildGroupGoalScopeOverlay()
|
|
179
|
+
: buildGroupTaskScopeOverlay();
|
|
180
|
+
|
|
181
|
+
return promptBlock(`
|
|
182
|
+
[protocol:${GOAL_TASK_PROTOCOL_MODULE}]
|
|
183
|
+
This is the single source of prompt truth for ${BRAND_NAME} goal/task behavior. Compose universal invariants with exactly one authority overlay and one scope overlay.
|
|
184
|
+
|
|
185
|
+
${buildUniversalInvariants()}
|
|
186
|
+
|
|
187
|
+
${buildCoreConcepts()}
|
|
188
|
+
|
|
189
|
+
${buildStateSurfaceRules()}
|
|
190
|
+
|
|
191
|
+
${authorityOverlay}
|
|
192
|
+
|
|
193
|
+
${scopeOverlay}
|
|
194
|
+
[/protocol:${GOAL_TASK_PROTOCOL_MODULE}]
|
|
195
|
+
`);
|
|
196
|
+
}
|