@ngockhoale/ckit 0.4.2 → 0.4.4
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/src/team/engine.d.ts +1 -1
- package/dist/src/team/engine.js +38 -13
- package/package.json +1 -1
|
@@ -68,7 +68,7 @@ export declare function mergeFindings(cs: readonly AgentContribution[]): MergedF
|
|
|
68
68
|
/** Streaming redaction (review item 5): returns the redacted text that is safe to emit now and the raw tail to keep.
|
|
69
69
|
* The tail (at least `overlap` chars, cut at whitespace) is held back so a secret split across chunks is redacted as a whole; the prefix is emitted
|
|
70
70
|
* only when redacting the whole buffer ends exactly with the redacted tail (no match spans the cut). `final` = the turn ended: emit everything. */
|
|
71
|
-
export declare function splitRedacted(pending: string, redact: (t: string) => string, overlap: number, final: boolean): {
|
|
71
|
+
export declare function splitRedacted(pending: string, redact: (t: string) => string, overlap: number, final: boolean, known?: readonly string[]): {
|
|
72
72
|
emit: string;
|
|
73
73
|
keep: string;
|
|
74
74
|
};
|
package/dist/src/team/engine.js
CHANGED
|
@@ -179,19 +179,28 @@ export function mergeFindings(cs) {
|
|
|
179
179
|
/** Streaming redaction (review item 5): returns the redacted text that is safe to emit now and the raw tail to keep.
|
|
180
180
|
* The tail (at least `overlap` chars, cut at whitespace) is held back so a secret split across chunks is redacted as a whole; the prefix is emitted
|
|
181
181
|
* only when redacting the whole buffer ends exactly with the redacted tail (no match spans the cut). `final` = the turn ended: emit everything. */
|
|
182
|
-
export function splitRedacted(pending, redact, overlap, final) {
|
|
182
|
+
export function splitRedacted(pending, redact, overlap, final, known = []) {
|
|
183
|
+
const inSecret = (cut) => known.some(k => { if (!k)
|
|
184
|
+
return false; for (let i = pending.indexOf(k, Math.max(0, cut - k.length + 1)); i >= 0 && i < cut; i = pending.indexOf(k, i + 1))
|
|
185
|
+
return true; return false; });
|
|
183
186
|
if (final)
|
|
184
187
|
return { emit: redact(pending), keep: '' };
|
|
185
188
|
for (let lim = pending.length - overlap; lim > 0;) {
|
|
186
189
|
let cut = lim;
|
|
187
190
|
while (cut > 0 && !/\s/.test(pending[cut - 1]))
|
|
188
191
|
cut--;
|
|
189
|
-
if (cut <= 0)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
if (cut <= 0) {
|
|
193
|
+
if (lim < overlap)
|
|
194
|
+
break;
|
|
195
|
+
cut = lim;
|
|
196
|
+
const c = pending.charCodeAt(cut - 1);
|
|
197
|
+
if (c >= 0xd800 && c <= 0xdbff)
|
|
198
|
+
cut--;
|
|
199
|
+
} // no whitespace: hard cut (never inside a surrogate pair), kept only when no redaction spans it
|
|
200
|
+
const all = redact(pending), head = redact(pending.slice(0, cut));
|
|
201
|
+
if (!inSecret(cut) && head + redact(pending.slice(cut)) === all)
|
|
202
|
+
return { emit: head, keep: pending.slice(cut) };
|
|
203
|
+
lim = !/\s/.test(pending[cut - 1]) ? cut - overlap : cut - 1; // a match spans this cut: try earlier
|
|
195
204
|
}
|
|
196
205
|
return { emit: '', keep: pending };
|
|
197
206
|
}
|
|
@@ -200,13 +209,23 @@ const MODE_RE = /^[ \t>*_#-]*MODE[ \t]*\**[ \t]*:\**[ \t]*\**[ \t]*(DIRECT|DELEG
|
|
|
200
209
|
const READ_ONLY_RE = /(?<![\p{L}])read[ -]?only(?![\p{L}])|(?<![\p{L}])(?:review|analy[sz]e|analysis|explain|inspect) only(?![\p{L}])|(?<![\p{L}])(?:do not|don't|dont|never|without) (?:change|changing|modify|modifying|edit|editing|touch|touching|write|writing)(?![\p{L}])[^.\n]{0,20}(?<![\p{L}])(?:files?|code|anything|the repo|the project)(?![\p{L}])|(?<![\p{L}])no (?:code |file )?changes(?![\p{L}])|chỉ đọc|không (?:được )?(?:sửa|thay đổi|chỉnh sửa)/giu;
|
|
201
210
|
/** A request to change something (EN + VI): a goal that asks for it is never read-only, whatever scope words it also contains. */
|
|
202
211
|
const CHANGE_RE = /(?<![\p{L}])(?:fix|implement|add|change|modify|edit|update|create|write|refactor|rename|delete|remove|build|patch|apply|install|sửa|thêm|đổi|thay đổi|tạo|xóa|xoá|viết|cài)(?![\p{L}])/iu;
|
|
212
|
+
/** "how to fix", "cách sửa", "làm sao để thêm": a change that is described or explained, not requested. */
|
|
213
|
+
const HOW_TO_HEAD = String.raw `(?<![\p{L}])(?:how (?:to|do (?:i|we|you)|should (?:i|we)|would (?:i|we|you)|can (?:i|we))|cách(?: để)?|làm (?:sao|thế nào)(?: để)?|tại sao phải|why (?:to|should (?:i|we))) `;
|
|
214
|
+
const HOW_TO_RE = new RegExp(String.raw `${HOW_TO_HEAD}[^\n]*?(?=$|\n|[,;!?]|\.(?=\s|$)| (?:rồi|then|and|also|please|sau đó|và|với|plus)(?![\p{L}]))`, 'gimu'); // the clause ends at a conjunction, , ; ! ? or a sentence-ending dot (not the dot in src/config.ts)
|
|
215
|
+
const HOW_TO_SENT_RE = new RegExp(String.raw `${HOW_TO_HEAD}[^\n]*?(?=$|\n|[;!?]|\.(?=\s|$))`, 'gimu'); // before an explicit no-write order: the explained clause runs to its sentence end
|
|
216
|
+
/** The owner forbade writing in so many words (not only a "read-only" label): "do not change any files", "no code changes", "không sửa". */
|
|
217
|
+
const NO_WRITE_RE = /(?<![\p{L}])(?:(?:do not|don't|dont|never|without) (?:change|changing|modify|modifying|edit|editing|touch|touching|write|writing) (?:(?:any(?: of the)?|the|a single) )?(?:files?|code|anything|the repo|the project|the codebase)(?![\p{L}])|no (?:code |file )?changes(?![\p{L}])|không (?:được )?(?:sửa|thay đổi|chỉnh sửa))(?![^.;\n]{0,40}?(?<![\p{L}])(?:outside|except|other than|besides|beyond|apart from|else|in production|ngoài|trừ)(?![\p{L}]))/iu; // a whole no-write order; a scoped one ("except docs/", "ngoài docs/") is not
|
|
203
218
|
/** PF-MODES: the owner asked for a read-only result (question, analysis, review) - no team may change files.
|
|
204
219
|
* The scope phrase must open the goal (first 25 chars) and the rest of the goal (after removing the scope phrases and [bracket tags]) must not ask for a change. */
|
|
205
220
|
export const isReadOnlyGoal = (goal) => {
|
|
206
|
-
const g = goal.replace(/\[[^\]]*\]/g, ' ').trim(), first = [...g.matchAll(READ_ONLY_RE)][0];
|
|
221
|
+
const g = goal.replace(/\[[^\]]*\]/g, ' ').replace(/[^\S\n]+/g, ' ').trim(), first = [...g.matchAll(READ_ONLY_RE)][0], nw = NO_WRITE_RE.exec(g);
|
|
222
|
+
const asks = (t, how = HOW_TO_RE) => CHANGE_RE.test(t.replace(READ_ONLY_RE, ' ').replace(how, ' '));
|
|
223
|
+
// an explicit whole no-write order (anywhere) wins when nothing before it asks for a change: the rest is to be explained, never done
|
|
224
|
+
if (nw && !asks(g.slice(0, nw.index), HOW_TO_SENT_RE))
|
|
225
|
+
return true;
|
|
207
226
|
if (!first || (first.index ?? 0) > 25)
|
|
208
227
|
return false;
|
|
209
|
-
return !
|
|
228
|
+
return !asks(g);
|
|
210
229
|
};
|
|
211
230
|
/** The Director's "TEAMS: a, b" line: the configured teams it activates (lowercased ids), or null when absent. */
|
|
212
231
|
export function parseTeams(text) {
|
|
@@ -235,8 +254,8 @@ export function parseDepends(text) {
|
|
|
235
254
|
export function buildGraph(order, deps) {
|
|
236
255
|
const g = new Map();
|
|
237
256
|
order.forEach((id, k) => {
|
|
238
|
-
const said = deps?.get(id);
|
|
239
|
-
g.set(id, said
|
|
257
|
+
const said = deps?.get(id), valid = said ? [...new Set(said.filter(d => order.indexOf(d) >= 0 && order.indexOf(d) < k))] : [];
|
|
258
|
+
g.set(id, said && (valid.length || !said.length) ? valid : k > 0 ? [order[k - 1]] : []); // "x <- none" = no dependency; only unknown/later ids = keep the owner order
|
|
240
259
|
});
|
|
241
260
|
const qk = order.indexOf('qc');
|
|
242
261
|
if (qk > 0) {
|
|
@@ -501,6 +520,12 @@ export function startTeamRun(opts) {
|
|
|
501
520
|
return { ask, ret, clean: keep.join('\n').trim() || text };
|
|
502
521
|
};
|
|
503
522
|
const assumptionsBlock = () => assumptions ? `\nASSUMPTIONS MADE (the owner did not confirm them; the Director decided to proceed with these):\n${assumptions}\n` : '';
|
|
523
|
+
/** The GOAL line is shortened to 2000 chars; the Director's intake reads the whole request so no requirement is lost before the split. */
|
|
524
|
+
const fullGoalBlock = () => goal.length <= 2000 ? '' : goal.length <= 30000 ? `\nFULL OWNER REQUEST (the GOAL line above is shortened; read all of it):\n${goal}\n` : `\nFULL OWNER REQUEST: it is ${goal.length} chars, too long for this prompt. The first part is below; the WHOLE request is saved at ${goalFile()} - read that file completely before you decide.\n${clip(goal, 30000)}\n`;
|
|
525
|
+
let goalPath = '';
|
|
526
|
+
const goalFile = () => { if (!goalPath) {
|
|
527
|
+
goalPath = join(journal.runDir, journal.writeArtifact('owner-request.md', goal));
|
|
528
|
+
} return goalPath; };
|
|
504
529
|
const common = () => `GOAL: ${oneLine(goal, 2000)}\n${assumptionsBlock()}${notes.length ? `\nOWNER NOTES (follow them):\n${notes.map(n => `- ${n}`).join('\n')}\n` : ''}${intakeIntro ? `\nDIRECTOR BRIEF:\n${intakeIntro}\n` : ''}${attachmentPromptBlock(atts, excerpts)}`;
|
|
505
530
|
// ---- one agent turn ----
|
|
506
531
|
/** Heuristic step label for real runners' activity lines (null = not a step boundary). */
|
|
@@ -580,7 +605,7 @@ export function startTeamRun(opts) {
|
|
|
580
605
|
deltaBuf.delete(agentId);
|
|
581
606
|
return;
|
|
582
607
|
}
|
|
583
|
-
const { emit: text, keep } = splitRedacted(b.text, t => journal.redact(t), OVERLAP, final);
|
|
608
|
+
const { emit: text, keep } = splitRedacted(b.text, t => journal.redact(t), OVERLAP, final, known);
|
|
584
609
|
b.text = keep;
|
|
585
610
|
if (!keep)
|
|
586
611
|
deltaBuf.delete(agentId);
|
|
@@ -895,7 +920,7 @@ export function startTeamRun(opts) {
|
|
|
895
920
|
if (modelDirector()) {
|
|
896
921
|
const answered = qaRounds.length ? `\nYOUR EARLIER QUESTIONS AND THE OWNER'S ANSWERS:\n${qaRounds.map((q, i) => `Round ${i + 1} questions:\n${q.questions}\nOwner's answer:\n${q.answer}`).join('\n\n')}\n` : '';
|
|
897
922
|
const limitNote = forced ? '\nThe owner chose to proceed with your stated assumptions: answer "DECISION: PROCEED" now.' : needRounds >= 3 ? '\nYou already asked 3 times: you must not use NEED INFO again. Choose PROCEED with stated assumptions, or CANNOT DO.' : '';
|
|
898
|
-
const ask = () => directorAsk('intake brief', `${role(config.director, `You are the Director. First triage the owner request, then (only on PROCEED) split it between your teams.\nYour reply must contain exactly one decision line on its own line: "DECISION: PROCEED", "DECISION: NEED INFO" or "DECISION: CANNOT DO".\n- PROCEED: write a short overall summary (scope), an "ASSUMPTIONS:" list when you assumed anything, then one section per listed team, each starting with a line exactly "### TEAM <team id>" followed by: what this team must do for this goal, the expected deliverable, and what is out of scope for it. Assign every part of the goal to exactly one listed team and assign nothing to a team that is not listed.\n- NEED INFO: no team starts. Write a numbered list of at most 5 specific questions, each with why you need it; when sensible add a line "ASSUMPTIONS IF NO ANSWER:" followed by what you would assume.\n- CANNOT DO: write "REASON:" and then "WHAT WOULD WORK:" with 1 to 3 alternatives.\nRules: prefer PROCEED with stated assumptions when the gap is small and a wrong guess is cheap. Use NEED INFO only when a wrong guess wastes work or risks damage. Use CANNOT DO only when no reasonable reading of the request can be achieved with the configured teams, their access and this workspace. Never invent requirements. Never start teams on a request you do not understand. Answer in the owner's language. You may read project files (read only) to decide. Check the work is assignable: changing files needs a team with a write agent.\nOn PROCEED also add a line "MODE: <mode>" and a line "MODE REASON: <one sentence>". Modes: DIRECT = you answer it yourself right now (a question answerable from the request, the project files or a small lookup): put the complete answer for the owner in your reply and write no team sections; DELEGATE <agent id> = one best-fit agent does it alone (single-scope investigation or small fix); PARALLEL_MERGE = several agents give independent views at the same time and their team leads merge (options, reviews, risk); PARALLEL_EXECUTE = multi-part implementation through the teams. Never activate an agent just because it is configured; choose the cheapest mode that is good enough.\nWith DELEGATE, PARALLEL_MERGE, PARALLEL_EXECUTE or TARGETED_DISCUSSION also add a line "TEAMS: <team ids, comma separated>" naming ONLY the teams that must run (the pipeline order is kept); every other team is skipped. A read-only goal (a question, analysis or review where no file may change) activates no team with a write agent and no Test or QC team: those exist to change and verify files.\nWith PARALLEL_EXECUTE also add a line "DEPENDS: <team> <- <team>, <team>; <team> <- none; ..." saying which teams need which other teams' results first; teams with no dependency between them run at the same time. Do not chain every team after the previous one: list only real data dependencies (example for ba, implement, test, security, qc: "DEPENDS: implement <- ba; test <- implement; security <- implement; qc <- test, security" — Test and Security both only need the implementation, so they review it at the same time) (a team may only depend on teams earlier in the pipeline order; writes to the workspace are still serialized by CKit).${limitNote}`, true)}\n${accessFacts()}\n${lanes.length ? `LANES (choose exactly one; you may not invent lanes or teams):\n${laneRosterText()}\n${ownerLane ? `The owner FIXED the lane: "${ownerLane.id}". Brief only its teams. You may still answer NEED INFO or CANNOT DO.` : 'On PROCEED you MUST include a line "LANE: <lane id>" and a line "LANE REASON: <one sentence>", and write sections only for the teams of that lane. If no lane fits, answer DECISION: CANNOT DO with the reason "no lane fits" and say which lane would be needed; if the request is unclear between lanes, use NEED INFO.'}` : `TEAM ROSTER (pipeline order):\n${rosterText()}`}\n${common()}${answered}`);
|
|
923
|
+
const ask = () => directorAsk('intake brief', `${role(config.director, `You are the Director. First triage the owner request, then (only on PROCEED) split it between your teams.\nYour reply must contain exactly one decision line on its own line: "DECISION: PROCEED", "DECISION: NEED INFO" or "DECISION: CANNOT DO".\n- PROCEED: write a short overall summary (scope), an "ASSUMPTIONS:" list when you assumed anything, then one section per listed team, each starting with a line exactly "### TEAM <team id>" followed by: what this team must do for this goal, the expected deliverable, and what is out of scope for it. Assign every part of the goal to exactly one listed team and assign nothing to a team that is not listed.\n- NEED INFO: no team starts. Write a numbered list of at most 5 specific questions, each with why you need it; when sensible add a line "ASSUMPTIONS IF NO ANSWER:" followed by what you would assume.\n- CANNOT DO: write "REASON:" and then "WHAT WOULD WORK:" with 1 to 3 alternatives.\nRules: prefer PROCEED with stated assumptions when the gap is small and a wrong guess is cheap. Use NEED INFO only when a wrong guess wastes work or risks damage. Use CANNOT DO only when no reasonable reading of the request can be achieved with the configured teams, their access and this workspace. Never invent requirements. Never start teams on a request you do not understand. Answer in the owner's language. You may read project files (read only) to decide. Check the work is assignable: changing files needs a team with a write agent.\nOn PROCEED also add a line "MODE: <mode>" and a line "MODE REASON: <one sentence>". Modes: DIRECT = you answer it yourself right now (a question answerable from the request, the project files or a small lookup): put the complete answer for the owner in your reply and write no team sections; DELEGATE <agent id> = one best-fit agent does it alone (single-scope investigation or small fix); PARALLEL_MERGE = several agents give independent views at the same time and their team leads merge (options, reviews, risk); PARALLEL_EXECUTE = multi-part implementation through the teams. Never activate an agent just because it is configured; choose the cheapest mode that is good enough.\nWith DELEGATE, PARALLEL_MERGE, PARALLEL_EXECUTE or TARGETED_DISCUSSION also add a line "TEAMS: <team ids, comma separated>" naming ONLY the teams that must run (the pipeline order is kept); every other team is skipped. A read-only goal (a question, analysis or review where no file may change) activates no team with a write agent and no Test or QC team: those exist to change and verify files.\nWith PARALLEL_EXECUTE also add a line "DEPENDS: <team> <- <team>, <team>; <team> <- none; ..." saying which teams need which other teams' results first; teams with no dependency between them run at the same time. Do not chain every team after the previous one: list only real data dependencies (example for ba, implement, test, security, qc: "DEPENDS: implement <- ba; test <- implement; security <- implement; qc <- test, security" — Test and Security both only need the implementation, so they review it at the same time) (a team may only depend on teams earlier in the pipeline order; writes to the workspace are still serialized by CKit).${limitNote}`, true)}\n${accessFacts()}\n${lanes.length ? `LANES (choose exactly one; you may not invent lanes or teams):\n${laneRosterText()}\n${ownerLane ? `The owner FIXED the lane: "${ownerLane.id}". Brief only its teams. You may still answer NEED INFO or CANNOT DO.` : 'On PROCEED you MUST include a line "LANE: <lane id>" and a line "LANE REASON: <one sentence>", and write sections only for the teams of that lane. If no lane fits, answer DECISION: CANNOT DO with the reason "no lane fits" and say which lane would be needed; if the request is unclear between lanes, use NEED INFO.'}` : `TEAM ROSTER (pipeline order):\n${rosterText()}`}\n${common()}${fullGoalBlock()}${answered}`);
|
|
899
924
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
900
925
|
const t = await ask();
|
|
901
926
|
if (t?.trim())
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngockhoale/ckit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "CKit — local Agent Company: a Director plus BA / Implement / QC teams running your own codex, claude and omp CLIs, with a web Mission Control (ckit gui).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|