hilos-agent 0.1.9 → 0.1.10
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 +4 -0
- package/package.json +1 -1
- package/src/handler.mjs +78 -71
package/README.md
CHANGED
|
@@ -72,6 +72,10 @@ hilos-agent --channel <id> # scope to one channel
|
|
|
72
72
|
## How it works
|
|
73
73
|
|
|
74
74
|
- **Trigger** — an `@mention` of your agent in a channel that's linked to a repo.
|
|
75
|
+
- **Chat or code?** — the agent reads the conversation and decides with the model
|
|
76
|
+
(via `chatCmd`), not a keyword list: a question/greeting/"let's just discuss" →
|
|
77
|
+
a chat reply; anything asking for a change — including "just code it", "finish
|
|
78
|
+
it", "approved", or "go for it" after a request, in any language → a code run.
|
|
75
79
|
- **Repo resolution** — the channel's linked repo is mapped to a local path via
|
|
76
80
|
`repos`. No mapping → the agent says so and stops.
|
|
77
81
|
- **Run** — it branches off `defaultBranch` (refuses a dirty tree), runs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hilos-agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Run your own coding agent (Claude Code / Codex / Cursor) as an autonomous teammate in a hilos channel. Picks up @mentions in channels and threads, makes the change, and opens a PR for review — your code and credentials never leave your machine. (Approve-before-push is available via gate:true.)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/handler.mjs
CHANGED
|
@@ -165,65 +165,51 @@ async function applyDecision({ decision, repoPath, branch, task, requester, cfg,
|
|
|
165
165
|
return { status: "timeout", branch };
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
* they mention code; an action verb means work. Keeps casual talk in a
|
|
172
|
-
* repo-linked channel from spawning empty branches.
|
|
173
|
-
*/
|
|
174
|
-
export function looksLikeCodeTask(text) {
|
|
175
|
-
const t = String(text || "")
|
|
176
|
-
.toLowerCase()
|
|
177
|
-
.replace(/@[a-z0-9-]+/g, " ")
|
|
178
|
-
.trim();
|
|
179
|
-
if (!t) return false;
|
|
180
|
-
// Greetings / questions → chat (even if they name code things).
|
|
181
|
-
if (
|
|
182
|
-
/^(hi|hey|hello|yo|sup|gm|thanks|thank you|nice|cool|ok|okay|how|what|why|when|who|where|which|is\b|are\b|do you|does|did|could you (tell|explain|show|describe)|can you (tell|explain|show|describe))/.test(
|
|
183
|
-
t,
|
|
184
|
-
)
|
|
185
|
-
) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
const verb =
|
|
189
|
-
/\b(fix|add|implement|refactor|change|update|create|remove|delete|rename|write|build|bump|migrate|wire|patch|optimi[sz]e|debug|revert|rebase|configure|improve|replace|extract|split|move|generate|scaffold|make|set up|hook up|adjust|tweak|ship|commit|push|merge)\b/;
|
|
190
|
-
return verb.test(t);
|
|
191
|
-
}
|
|
168
|
+
// Sentinel the router model emits when the latest message is a request to change
|
|
169
|
+
// code. Unusual on purpose so it can't be confused with a real chat reply.
|
|
170
|
+
const CODE_SIGNAL = "__CODE__";
|
|
192
171
|
|
|
193
172
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
173
|
+
* Decide — with the LLM, not a word list — whether the latest message wants a
|
|
174
|
+
* code change or a conversational reply, and (for chat) produce that reply in the
|
|
175
|
+
* SAME call. The model reads the whole conversation, so it judges by intent and
|
|
176
|
+
* context, in any language: "just code it", "dale, hazlo", "yeah go for it" after
|
|
177
|
+
* a request → code; "how does this work?", "thoughts?", "thanks" → chat.
|
|
178
|
+
*
|
|
179
|
+
* Returns one of:
|
|
180
|
+
* { aborted: true }
|
|
181
|
+
* { code: true } → run the coding flow
|
|
182
|
+
* { code: false, reply, error } → post `reply` as a chat message
|
|
183
|
+
*
|
|
184
|
+
* `error` is set when the model produced nothing (so the caller can be honest
|
|
185
|
+
* about a timeout vs a missing binary instead of inventing a reply).
|
|
199
186
|
*/
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
if (!
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
);
|
|
187
|
+
async function routeIntent({ name, repoFullName, transcript, workspaceMemory, cfg, signal }) {
|
|
188
|
+
const cmd = cfg.chatCmd || cfg.codingCmd;
|
|
189
|
+
const parts = cmd.split(" ").filter(Boolean);
|
|
190
|
+
const prompt =
|
|
191
|
+
`You are ${name}, a teammate in a team chat (hilos) connected to the git repository ` +
|
|
192
|
+
`${repoFullName}. Read the conversation and judge what the LATEST message wants from you.\n\n` +
|
|
193
|
+
`If it is asking you to make a code or repository change — implement/fix/refactor/adjust ` +
|
|
194
|
+
`something, continue or finish work discussed above, or give a go-ahead to act ("yeah, do ` +
|
|
195
|
+
`it", "go for it", "just code it", "approved", "dale", in ANY language) — respond with ` +
|
|
196
|
+
`EXACTLY this and nothing else:\n${CODE_SIGNAL}\n\n` +
|
|
197
|
+
`Otherwise — a question, a greeting, general discussion, or they explicitly don't want code ` +
|
|
198
|
+
`yet — just reply to them concisely and directly as a single chat message (no preamble, no ` +
|
|
199
|
+
`headings). When unsure, prefer to act (${CODE_SIGNAL}); this is a build channel.\n\n` +
|
|
200
|
+
`${memoryPreamble(workspaceMemory)}Conversation so far:\n${transcript}`;
|
|
201
|
+
const run = await runCli({
|
|
202
|
+
cmd: parts[0],
|
|
203
|
+
args: [...parts.slice(1), prompt],
|
|
204
|
+
timeoutMs: cfg.chatTimeoutMs || cfg.runTimeoutMs,
|
|
205
|
+
label: "thinking",
|
|
206
|
+
signal,
|
|
207
|
+
});
|
|
208
|
+
if (run.aborted || signal?.aborted) return { aborted: true };
|
|
209
|
+
const out = (run.stdout || "").trim();
|
|
210
|
+
if (!out) return { code: false, reply: null, error: run.error || new Error("no output") };
|
|
211
|
+
if (new RegExp(`^${CODE_SIGNAL}\\b`).test(out)) return { code: true };
|
|
212
|
+
return { code: false, reply: out };
|
|
227
213
|
}
|
|
228
214
|
|
|
229
215
|
/**
|
|
@@ -415,27 +401,48 @@ export async function handleTask({ message, channelId, tool, me, caps = {} }, cf
|
|
|
415
401
|
const { memory: workspaceMemory = null } = await tool("get_workspace_memory", {}).catch(() => ({
|
|
416
402
|
memory: null,
|
|
417
403
|
}));
|
|
418
|
-
// The conversation the agent is replying within — fetched ONCE and
|
|
419
|
-
//
|
|
420
|
-
// like "yeah, do it" only means something against what was
|
|
421
|
-
//
|
|
422
|
-
// always had this; the code path used to run on the bare mention alone (so
|
|
423
|
-
// "go for it" reached the agent with no spec → nothing built). Now both share it.
|
|
404
|
+
// The conversation the agent is replying within — fetched ONCE and used to
|
|
405
|
+
// route AND (for a code run) handed to the coding prompt. Context is always
|
|
406
|
+
// crucial: a reply like "yeah, do it" only means something against what was
|
|
407
|
+
// just said.
|
|
424
408
|
const context = await fetchContext({ channelId, tool, parentId });
|
|
425
|
-
|
|
426
|
-
//
|
|
427
|
-
|
|
428
|
-
// a conversational reply.
|
|
429
|
-
let isCode = looksLikeCodeTask(message.body);
|
|
430
|
-
if (!isCode && repoLink && isAffirmation(message.body) && agentProposedWork(context.rows, me?.agentName)) {
|
|
431
|
-
isCode = true;
|
|
432
|
-
}
|
|
433
|
-
if (!repoLink || !isCode) {
|
|
409
|
+
|
|
410
|
+
// No repo linked → nothing to build; just reply.
|
|
411
|
+
if (!repoLink) {
|
|
434
412
|
await respondConversationally({ message, channelId, tool, me, cfg, repoLink, parentId, workspaceMemory, signal, context, caps });
|
|
435
413
|
return { status: "chat" };
|
|
436
414
|
}
|
|
437
415
|
const repoFullName = repoLink.repo_full_name;
|
|
438
416
|
|
|
417
|
+
// Chat vs code is the LLM's call, not a word list: it reads the whole
|
|
418
|
+
// conversation and either returns a chat reply or signals a code run. Handles
|
|
419
|
+
// any phrasing, any language, and "go for it" obviously means "do the thing we
|
|
420
|
+
// just discussed". When it replies (chat), post that and we're done.
|
|
421
|
+
const routed = await routeIntent({
|
|
422
|
+
name: me?.agentName || "an assistant",
|
|
423
|
+
repoFullName,
|
|
424
|
+
transcript: context.transcript,
|
|
425
|
+
workspaceMemory,
|
|
426
|
+
cfg,
|
|
427
|
+
signal,
|
|
428
|
+
});
|
|
429
|
+
if (routed.aborted || signal?.aborted) {
|
|
430
|
+
await tool("post_message", { channelId, parentId, body: "Stopped." });
|
|
431
|
+
return { status: "chat" };
|
|
432
|
+
}
|
|
433
|
+
if (!routed.code) {
|
|
434
|
+
let body = routed.reply;
|
|
435
|
+
if (!body) {
|
|
436
|
+
body =
|
|
437
|
+
routed.error?.code === "ENOENT"
|
|
438
|
+
? `(my chat command \`${cfg.chatCmd || cfg.codingCmd}\` isn't installed or on PATH.)`
|
|
439
|
+
: `Still thinking on this — it's taking longer than usual. I'll follow up shortly.`;
|
|
440
|
+
}
|
|
441
|
+
await tool("post_message", { channelId, parentId, body });
|
|
442
|
+
return { status: "chat" };
|
|
443
|
+
}
|
|
444
|
+
// routed.code → fall through to the coding flow below.
|
|
445
|
+
|
|
439
446
|
let repoPath = resolveRepoPath(cfg, repoFullName);
|
|
440
447
|
if (!repoPath) {
|
|
441
448
|
// Zero-config path: if the daemon is running INSIDE a checkout of this repo
|