pi-harness-runtime 1.1.479 → 1.1.481
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/CHANGELOG.md +115 -0
- package/harness/pending-question-state.ts +42 -2
- package/index.ts +40 -7
- package/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/dist/index.d.ts +1 -1
- package/packages/jev-judge/dist/index.d.ts.map +1 -1
- package/packages/jev-judge/dist/index.js +1 -1
- package/packages/jev-judge/dist/index.js.map +1 -1
- package/packages/jev-judge/dist/question-risk.d.ts +32 -7
- package/packages/jev-judge/dist/question-risk.d.ts.map +1 -1
- package/packages/jev-judge/dist/question-risk.js +64 -20
- package/packages/jev-judge/dist/question-risk.js.map +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/index.ts +1 -1
- package/packages/jev-judge/src/question-risk.ts +97 -20
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/write-review/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question-risk.d.ts","sourceRoot":"","sources":["../src/question-risk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,UAAU,GACV,eAAe,GACf,UAAU,GACV,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,2CAA2C;AAC3C,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,6BAA6B,EAAE,OAAO,CAAC;IACvC,kDAAkD;IAClD,WAAW,EAAE,OAAO,CAAC;IACrB,gCAAgC;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,QAAQ,EAAE,OAAO,CAAC;IAClB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,6DAA6D;IAC7D,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAQD;;GAEG;AACH,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAYpC
|
|
1
|
+
{"version":3,"file":"question-risk.d.ts","sourceRoot":"","sources":["../src/question-risk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,UAAU,GACV,eAAe,GACf,UAAU,GACV,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,2CAA2C;AAC3C,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,6BAA6B,EAAE,OAAO,CAAC;IACvC,kDAAkD;IAClD,WAAW,EAAE,OAAO,CAAC;IACrB,gCAAgC;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,QAAQ,EAAE,OAAO,CAAC;IAClB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,6DAA6D;IAC7D,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAQD;;GAEG;AACH,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAYpC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,MAAM,CAgBR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,MAAM,GAAG,SAAS,CAapB;AAyMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,iBAAiB,GACtB,iBAAiB,CAiEnB"}
|
|
@@ -29,16 +29,14 @@ const ACTION_VERBS = /\b(delete|deletes|deleted|deleting|remove|removes|removed|
|
|
|
29
29
|
* The message carries the ask ("may I proceed?") and the action ("I will
|
|
30
30
|
* delete the branch"). The risk is about the action, so the action is
|
|
31
31
|
* extracted: the sentences of the message that state what happens. The
|
|
32
|
-
* question sentence itself is not an action - it asks, it does not act
|
|
33
|
-
* unless it names an action itself.
|
|
34
|
-
*
|
|
35
|
-
* The question is assessed when it names an action: "I can update the status
|
|
36
|
-
* text. Want me to delete the production database?" states a harmless action
|
|
37
|
-
* in the message and asks for a deletion in the question. The action of the
|
|
38
|
-
* question is therefore always part of the action that is classified.
|
|
32
|
+
* question sentence itself is not an action - it asks, it does not act.
|
|
39
33
|
*
|
|
40
34
|
* When the message names no action, the question text is the action: the
|
|
41
35
|
* risk of the question is then the risk of the ask.
|
|
36
|
+
*
|
|
37
|
+
* The action of the question is not part of this text. It is extracted on
|
|
38
|
+
* its own (`extractQuestionAction`) and assessed on its own, so a long
|
|
39
|
+
* message around it cannot push it out of the assessment.
|
|
42
40
|
*/
|
|
43
41
|
export function extractProposedAction(contextText, questionText) {
|
|
44
42
|
const question = (questionText ?? "").trim();
|
|
@@ -53,14 +51,37 @@ export function extractProposedAction(contextText, questionText) {
|
|
|
53
51
|
if (actionSentences.length === 0) {
|
|
54
52
|
return question.slice(0, MAX_ACTION_CHARS);
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
return actionSentences.join(" ").slice(0, MAX_ACTION_CHARS);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The action of the question itself.
|
|
58
|
+
*
|
|
59
|
+
* The question can carry the action that the message does not name: "I can
|
|
60
|
+
* update the status text. Want me to delete the production database?" states
|
|
61
|
+
* a harmless action in the message and asks for a deletion in the question.
|
|
62
|
+
*
|
|
63
|
+
* The action of the question is extracted and assessed on its own text:
|
|
64
|
+
*
|
|
65
|
+
* - a long explanation around it cannot push it out of the assessment (the
|
|
66
|
+
* bound of the context is a bound of the context, not of the question),
|
|
67
|
+
* - a negation in the message cannot govern it (the negation of the
|
|
68
|
+
* message speaks about the message).
|
|
69
|
+
*
|
|
70
|
+
* `undefined` means that the question names no action: it asks, it does not
|
|
71
|
+
* act.
|
|
72
|
+
*/
|
|
73
|
+
export function extractQuestionAction(questionText) {
|
|
74
|
+
const question = (questionText ?? "").trim();
|
|
75
|
+
if (question.length === 0)
|
|
76
|
+
return undefined;
|
|
77
|
+
const sentences = question
|
|
78
|
+
.split(/(?<=[.!?])\s+|\n+/)
|
|
79
|
+
.map((sentence) => sentence.trim())
|
|
80
|
+
.filter((sentence) => sentence.length > 0);
|
|
81
|
+
const actionSentences = sentences.filter((sentence) => ACTION_VERBS.test(sentence));
|
|
82
|
+
if (actionSentences.length === 0)
|
|
83
|
+
return undefined;
|
|
84
|
+
return actionSentences.join(" ").slice(0, MAX_ACTION_CHARS);
|
|
64
85
|
}
|
|
65
86
|
/**
|
|
66
87
|
* Words that name an action that destroys, drops or overwrites something.
|
|
@@ -211,6 +232,19 @@ function matchPatterns(text, patterns, signals) {
|
|
|
211
232
|
}
|
|
212
233
|
return matched;
|
|
213
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* The risk patterns of one text.
|
|
237
|
+
*
|
|
238
|
+
* The signal names are collected, so the diagnostics name every pattern that
|
|
239
|
+
* matched - in the message as well as in the question.
|
|
240
|
+
*/
|
|
241
|
+
function classifyActionText(text, signals) {
|
|
242
|
+
return {
|
|
243
|
+
destructive: matchPatterns(text, DESTRUCTIVE_PATTERNS, signals),
|
|
244
|
+
external: matchPatterns(text, EXTERNAL_PATTERNS, signals),
|
|
245
|
+
sensitive: matchPatterns(text, SENSITIVE_PATTERNS, signals),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
214
248
|
/**
|
|
215
249
|
* Derive the risk facts of a pending question.
|
|
216
250
|
*
|
|
@@ -238,9 +272,17 @@ export function classifyQuestionRisk(input) {
|
|
|
238
272
|
const text = action.toLowerCase();
|
|
239
273
|
const kind = input.kind;
|
|
240
274
|
const signals = [];
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
275
|
+
const actionRisk = classifyActionText(text, signals);
|
|
276
|
+
// The question can carry an action of its own, and it is assessed on
|
|
277
|
+
// its own text: the bound of the message is a bound of the message, and
|
|
278
|
+
// a negation of the message speaks about the message.
|
|
279
|
+
const questionAction = (input.questionAction ?? "").trim();
|
|
280
|
+
const questionRisk = questionAction.length > 0
|
|
281
|
+
? classifyActionText(questionAction.toLowerCase(), signals)
|
|
282
|
+
: null;
|
|
283
|
+
const destructive = actionRisk.destructive || (questionRisk?.destructive ?? false);
|
|
284
|
+
const external = actionRisk.external || (questionRisk?.external ?? false);
|
|
285
|
+
const sensitive = actionRisk.sensitive || (questionRisk?.sensitive ?? false);
|
|
244
286
|
// Only an explicitly demanded authorization blocks the autonomous
|
|
245
287
|
// decision. An "approval" question is the agent proposing work: it
|
|
246
288
|
// stays auto-approvable unless the wording names a risky action.
|
|
@@ -261,8 +303,10 @@ export function classifyQuestionRisk(input) {
|
|
|
261
303
|
if (external || sensitive) {
|
|
262
304
|
requiresExplicitAuthorization = true;
|
|
263
305
|
}
|
|
264
|
-
// Unknown kind or unknown text: the action cannot be judged.
|
|
265
|
-
|
|
306
|
+
// Unknown kind or unknown text: the action cannot be judged. The action
|
|
307
|
+
// of the question counts as a known text: it is judged on its own.
|
|
308
|
+
const knownText = text.trim().length > 0 || questionAction.length > 0;
|
|
309
|
+
if (!kind || !knownText) {
|
|
266
310
|
requiresExplicitAuthorization = true;
|
|
267
311
|
signals.push("unknown-question");
|
|
268
312
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question-risk.js","sourceRoot":"","sources":["../src/question-risk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"question-risk.js","sourceRoot":"","sources":["../src/question-risk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA6DH;;GAEG;AACH,MAAM,C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,SAAS,GAAG,UAAU,CAAC,SAAS,IAAI,CAAC,YAAY,EAAE,SAAS,IAAI,KAAK,CAAC,CAAC;IAE7E,kEAAkE;IAClE,mEAAmE;IACnE,iEAAiE;IACjE,IAAI,6BAA6B,GAAG,IAAI,KAAK,UAAU,CAAC;IAExD,sEAAsE;IACtE,sEAAsE;IACtE,uCAAuC;IACvC,IAAI,KAAK,CAAC,OAAO,KAAK,wBAAwB,EAAE,CAAC;QAChD,6BAA6B,GAAG,IAAI,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;IAED,0DAA0D;IAC1D,IAAI,WAAW,EAAE,CAAC;QACjB,6BAA6B,GAAG,IAAI,CAAC;IACtC,CAAC;IAED,uEAAuE;IACvE,iBAAiB;IACjB,IAAI,QAAQ,IAAI,SAAS,EAAE,CAAC;QAC3B,6BAA6B,GAAG,IAAI,CAAC;IACtC,CAAC;IAED,wEAAwE;IACxE,mEAAmE;IACnE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;IACtE,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACzB,6BAA6B,GAAG,IAAI,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAClC,CAAC;IAED,OAAO;QACN,6BAA6B;QAC7B,WAAW;QACX,mDAAmD;QACnD,UAAU,EAAE,CAAC,WAAW;QACxB,QAAQ;QACR,OAAO;KACP,CAAC;AACH,CAAC"}
|
|
@@ -734,7 +734,7 @@ export {
|
|
|
734
734
|
export type { AutonomyInstructionInput } from "./autonomy-instruction.js";
|
|
735
735
|
|
|
736
736
|
// Export the deterministic risk classifier of a pending question
|
|
737
|
-
export { classifyQuestionRisk, extractProposedAction } from "./question-risk.js";
|
|
737
|
+
export { classifyQuestionRisk, extractProposedAction, extractQuestionAction } from "./question-risk.js";
|
|
738
738
|
export type { QuestionRiskFacts, QuestionRiskInput } from "./question-risk.js";
|
|
739
739
|
|
|
740
740
|
// Export WrapUpJudge
|
|
@@ -54,6 +54,15 @@ export interface QuestionRiskInput {
|
|
|
54
54
|
* the action that is proposed.
|
|
55
55
|
*/
|
|
56
56
|
proposedAction?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The action of the question itself.
|
|
59
|
+
*
|
|
60
|
+
* It is assessed on its own text: the risk of the question is the risk of
|
|
61
|
+
* the question, not of the message around it. A long message cannot push
|
|
62
|
+
* the action of the question out of the assessment, and a negation of the
|
|
63
|
+
* message cannot govern it.
|
|
64
|
+
*/
|
|
65
|
+
questionAction?: string;
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
interface RiskPattern {
|
|
@@ -83,16 +92,14 @@ const ACTION_VERBS =
|
|
|
83
92
|
* The message carries the ask ("may I proceed?") and the action ("I will
|
|
84
93
|
* delete the branch"). The risk is about the action, so the action is
|
|
85
94
|
* extracted: the sentences of the message that state what happens. The
|
|
86
|
-
* question sentence itself is not an action - it asks, it does not act
|
|
87
|
-
* unless it names an action itself.
|
|
88
|
-
*
|
|
89
|
-
* The question is assessed when it names an action: "I can update the status
|
|
90
|
-
* text. Want me to delete the production database?" states a harmless action
|
|
91
|
-
* in the message and asks for a deletion in the question. The action of the
|
|
92
|
-
* question is therefore always part of the action that is classified.
|
|
95
|
+
* question sentence itself is not an action - it asks, it does not act.
|
|
93
96
|
*
|
|
94
97
|
* When the message names no action, the question text is the action: the
|
|
95
98
|
* risk of the question is then the risk of the ask.
|
|
99
|
+
*
|
|
100
|
+
* The action of the question is not part of this text. It is extracted on
|
|
101
|
+
* its own (`extractQuestionAction`) and assessed on its own, so a long
|
|
102
|
+
* message around it cannot push it out of the assessment.
|
|
96
103
|
*/
|
|
97
104
|
export function extractProposedAction(
|
|
98
105
|
contextText: string | undefined,
|
|
@@ -112,14 +119,41 @@ export function extractProposedAction(
|
|
|
112
119
|
if (actionSentences.length === 0) {
|
|
113
120
|
return question.slice(0, MAX_ACTION_CHARS);
|
|
114
121
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
return actionSentences.join(" ").slice(0, MAX_ACTION_CHARS);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The action of the question itself.
|
|
127
|
+
*
|
|
128
|
+
* The question can carry the action that the message does not name: "I can
|
|
129
|
+
* update the status text. Want me to delete the production database?" states
|
|
130
|
+
* a harmless action in the message and asks for a deletion in the question.
|
|
131
|
+
*
|
|
132
|
+
* The action of the question is extracted and assessed on its own text:
|
|
133
|
+
*
|
|
134
|
+
* - a long explanation around it cannot push it out of the assessment (the
|
|
135
|
+
* bound of the context is a bound of the context, not of the question),
|
|
136
|
+
* - a negation in the message cannot govern it (the negation of the
|
|
137
|
+
* message speaks about the message).
|
|
138
|
+
*
|
|
139
|
+
* `undefined` means that the question names no action: it asks, it does not
|
|
140
|
+
* act.
|
|
141
|
+
*/
|
|
142
|
+
export function extractQuestionAction(
|
|
143
|
+
questionText: string | undefined,
|
|
144
|
+
): string | undefined {
|
|
145
|
+
const question = (questionText ?? "").trim();
|
|
146
|
+
if (question.length === 0) return undefined;
|
|
147
|
+
|
|
148
|
+
const sentences = question
|
|
149
|
+
.split(/(?<=[.!?])\s+|\n+/)
|
|
150
|
+
.map((sentence) => sentence.trim())
|
|
151
|
+
.filter((sentence) => sentence.length > 0);
|
|
152
|
+
const actionSentences = sentences.filter((sentence) =>
|
|
153
|
+
ACTION_VERBS.test(sentence),
|
|
154
|
+
);
|
|
155
|
+
if (actionSentences.length === 0) return undefined;
|
|
156
|
+
return actionSentences.join(" ").slice(0, MAX_ACTION_CHARS);
|
|
123
157
|
}
|
|
124
158
|
|
|
125
159
|
/**
|
|
@@ -291,6 +325,36 @@ function matchPatterns(
|
|
|
291
325
|
return matched;
|
|
292
326
|
}
|
|
293
327
|
|
|
328
|
+
/**
|
|
329
|
+
* The risk that one text carries.
|
|
330
|
+
*
|
|
331
|
+
* The texts are assessed one by one: the action of the message and the
|
|
332
|
+
* action of the question are two texts, and a negation in one of them says
|
|
333
|
+
* nothing about the other.
|
|
334
|
+
*/
|
|
335
|
+
interface ActionRisk {
|
|
336
|
+
/** The text names a destructive action. */
|
|
337
|
+
destructive: boolean;
|
|
338
|
+
/** The text reaches the outside world. */
|
|
339
|
+
external: boolean;
|
|
340
|
+
/** The text touches a secret. */
|
|
341
|
+
sensitive: boolean;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* The risk patterns of one text.
|
|
346
|
+
*
|
|
347
|
+
* The signal names are collected, so the diagnostics name every pattern that
|
|
348
|
+
* matched - in the message as well as in the question.
|
|
349
|
+
*/
|
|
350
|
+
function classifyActionText(text: string, signals: string[]): ActionRisk {
|
|
351
|
+
return {
|
|
352
|
+
destructive: matchPatterns(text, DESTRUCTIVE_PATTERNS, signals),
|
|
353
|
+
external: matchPatterns(text, EXTERNAL_PATTERNS, signals),
|
|
354
|
+
sensitive: matchPatterns(text, SENSITIVE_PATTERNS, signals),
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
294
358
|
/**
|
|
295
359
|
* Derive the risk facts of a pending question.
|
|
296
360
|
*
|
|
@@ -321,9 +385,20 @@ export function classifyQuestionRisk(
|
|
|
321
385
|
const kind = input.kind;
|
|
322
386
|
const signals: string[] = [];
|
|
323
387
|
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
388
|
+
const actionRisk = classifyActionText(text, signals);
|
|
389
|
+
// The question can carry an action of its own, and it is assessed on
|
|
390
|
+
// its own text: the bound of the message is a bound of the message, and
|
|
391
|
+
// a negation of the message speaks about the message.
|
|
392
|
+
const questionAction = (input.questionAction ?? "").trim();
|
|
393
|
+
const questionRisk =
|
|
394
|
+
questionAction.length > 0
|
|
395
|
+
? classifyActionText(questionAction.toLowerCase(), signals)
|
|
396
|
+
: null;
|
|
397
|
+
|
|
398
|
+
const destructive =
|
|
399
|
+
actionRisk.destructive || (questionRisk?.destructive ?? false);
|
|
400
|
+
const external = actionRisk.external || (questionRisk?.external ?? false);
|
|
401
|
+
const sensitive = actionRisk.sensitive || (questionRisk?.sensitive ?? false);
|
|
327
402
|
|
|
328
403
|
// Only an explicitly demanded authorization blocks the autonomous
|
|
329
404
|
// decision. An "approval" question is the agent proposing work: it
|
|
@@ -349,8 +424,10 @@ export function classifyQuestionRisk(
|
|
|
349
424
|
requiresExplicitAuthorization = true;
|
|
350
425
|
}
|
|
351
426
|
|
|
352
|
-
// Unknown kind or unknown text: the action cannot be judged.
|
|
353
|
-
|
|
427
|
+
// Unknown kind or unknown text: the action cannot be judged. The action
|
|
428
|
+
// of the question counts as a known text: it is judged on its own.
|
|
429
|
+
const knownText = text.trim().length > 0 || questionAction.length > 0;
|
|
430
|
+
if (!kind || !knownText) {
|
|
354
431
|
requiresExplicitAuthorization = true;
|
|
355
432
|
signals.push("unknown-question");
|
|
356
433
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-harness/two-phase-review",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.481",
|
|
4
4
|
"description": "pi-harness-runtime — two-phase implementation and review workflow (queue review signals, gate the phase, scope the diff)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|