jive-agentic-workflow-comment-answering 0.0.0-stage → 0.1.0

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.
Files changed (41) hide show
  1. package/README.md +100 -2
  2. package/dist/comment-answering.js +12 -0
  3. package/dist/comment-answering.js.map +1 -0
  4. package/dist/generated/commentAnswering.js +36 -0
  5. package/dist/generated/commentAnswering.js.map +1 -0
  6. package/dist/generated/workflows.js +6 -0
  7. package/dist/generated/workflows.js.map +1 -0
  8. package/dist/index.js +8 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/rules.js +79 -0
  11. package/dist/rules.js.map +1 -0
  12. package/dist/steps/answer.js +49 -0
  13. package/dist/steps/answer.js.map +1 -0
  14. package/dist/steps/check-reply.js +27 -0
  15. package/dist/steps/check-reply.js.map +1 -0
  16. package/dist/steps/decide.js +26 -0
  17. package/dist/steps/decide.js.map +1 -0
  18. package/dist/steps/mark-seen.js +15 -0
  19. package/dist/steps/mark-seen.js.map +1 -0
  20. package/dist/steps/post-reply.js +27 -0
  21. package/dist/steps/post-reply.js.map +1 -0
  22. package/dist/steps/shared.js +25 -0
  23. package/dist/steps/shared.js.map +1 -0
  24. package/dist/task.js +27 -0
  25. package/dist/task.js.map +1 -0
  26. package/dist/testing/harness.js +149 -0
  27. package/dist/testing/harness.js.map +1 -0
  28. package/package.json +33 -4
  29. package/src/comment-answering.ts +12 -0
  30. package/src/generated/commentAnswering.ts +36 -0
  31. package/src/generated/workflows.ts +7 -0
  32. package/src/index.ts +7 -0
  33. package/src/rules.ts +99 -0
  34. package/src/steps/answer.ts +50 -0
  35. package/src/steps/check-reply.ts +27 -0
  36. package/src/steps/decide.ts +26 -0
  37. package/src/steps/mark-seen.ts +15 -0
  38. package/src/steps/post-reply.ts +27 -0
  39. package/src/steps/shared.ts +32 -0
  40. package/src/task.ts +30 -0
  41. package/src/testing/harness.ts +163 -0
package/README.md CHANGED
@@ -1,3 +1,101 @@
1
- # Temporary Holding Version
1
+ # jive-agentic-workflow-comment-answering
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The comment answering workflow, `commentAnswering`. A person leaves a comment on an element of a workflow's diagram in
4
+ the Jive app, and an agent answers it there, or replies with a plan and waits for the person's approval. It replaces
5
+ skill-sync's comment watch, which answers comments from a daemon on one machine: here the comment, its task and the
6
+ reply all live in the organization's own Convex server, and each step runs on the organization's workers.
7
+
8
+ This package is a library: its pipeline publishes it to npm, and an organization (`jive-abstract-organization`)
9
+ installs the workflow and names it as the answerer of its diagram comments (`comments: { answeredBy: "commentAnswering" }`).
10
+
11
+ ## The path of one comment
12
+
13
+ ```mermaid
14
+ sequenceDiagram
15
+ participant P as Person (Jive app)
16
+ participant O as Organization server
17
+ participant W as commentAnswering (workflow)
18
+ participant K as Worker
19
+ participant A as Agent (AgentRunner)
20
+
21
+ P->>O: workflowComments:add(workflow, version, element, text)
22
+ O->>O: store the comment
23
+ O->>W: createTask({ source, comment, event: "comment" }), same transaction
24
+ K->>W: take Decide
25
+ K->>O: commentGet(run, comment)
26
+ O-->>K: the comment, its conversation, place and graph
27
+ K->>W: complete Decide: forAgent
28
+ K->>W: take Mark seen
29
+ K->>O: commentReact(run, comment, 👀, on)
30
+ O-->>P: 👀 on the comment
31
+ K->>W: take Answer
32
+ K->>O: commentGet(run, comment)
33
+ K->>A: run(instructions, graph, conversation)
34
+ A-->>K: {"kind": "answer" | "plan", "text"}
35
+ K->>W: complete Answer: drafted, reply.json
36
+ K->>W: take Check reply
37
+ alt the draft is not fit to post (at most 3 drafts)
38
+ K->>W: complete Check reply: again, with why
39
+ Note over W,K: back to Answer, which reads why from the task's notes
40
+ end
41
+ K->>W: complete Check reply: ok
42
+ K->>W: take Post reply
43
+ K->>O: commentReply(run, conversation, "🤖: …", key "reply:<comment>")
44
+ O-->>P: the agent's reply
45
+ K->>O: commentReact(run, comment, 👀, off)
46
+ K->>W: complete Post reply: answered or planned
47
+ P->>O: reply "yes", or 👍 on the plan
48
+ O->>W: createTask({ comment, event: "comment" | "reaction" })
49
+ K->>W: Decide: approves, ends at approvalReceived
50
+ ```
51
+
52
+ ## Steps
53
+
54
+ `workflows/comment-answering.bpmn` is the diagram; each element binds to an export of `src/index.ts`.
55
+
56
+ | Step | Kind | What it does | Ends |
57
+ | --- | --- | --- | --- |
58
+ | Decide | code | Reads the comment and its conversation, and applies the rules below | `forAgent`, `notForAgent` (end `ignored`), `approves` (end `approvalReceived`) |
59
+ | Mark seen | code | Puts the agent's 👀 on the comment | `seen` |
60
+ | Answer | agent | Drafts an answer, or a plan for any change, from the comment, its conversation and the graph of the version it is on, into `reply.json` | `drafted` |
61
+ | Check reply | code | The verifier: one JSON answer or plan, not empty, at most 7,980 characters, not starting with 🤖 or the plan heading, never tagging `@clanker`. Sends the draft back with why, at most 3 drafts in all | `ok`, `again`, `givenUp` (end `unanswered`) |
62
+ | Post reply | code | Posts `🤖: <answer>` or `🤖: **Plan**` and the plan once, under the key `reply:<comment>`, then takes 👀 off | `answered`, `planned` |
63
+
64
+ Each code and agent step except Check reply is tried three times, a minute apart, when its run fails (the server or
65
+ the agent's provider unreachable), then ends at `failed`.
66
+
67
+ ## Alex's rules, from skill-sync's comment watch
68
+
69
+ - Every agent post starts with `🤖:`. A post that does is never for the agent, whoever wrote it, and neither is one
70
+ that is exactly "...".
71
+ - Every person's comment on a workflow's diagram is for the agent, tagged or not, as in a Google Doc. `@clanker` in any
72
+ capitals tags it, but not inside a longer name, a quoted line or code.
73
+ - A change waits for approval: the agent replies with its plan, starting `🤖: **Plan**`, and stops. A person approves it
74
+ with a reply of "yes" (or "@clanker yes") or a 👍 on the plan.
75
+ - 👀 shows as soon as the agent takes a comment, and goes once its reply is posted. One that never goes says no answer came.
76
+ - Each reply is posted once: the server keeps one reply per conversation and key, so a run tried again posts nothing more.
77
+
78
+ ## One writer for each piece of state
79
+
80
+ | State | Its one writer |
81
+ | --- | --- |
82
+ | A person's comments and reactions | That person, through the app's member functions |
83
+ | The agent's 👀 | Mark seen puts it on; Post reply takes it off |
84
+ | The agent's reply | Post reply |
85
+ | The draft (`reply.json`) | Answer |
86
+ | `drafts`, `replyKind` | Check reply |
87
+ | `posted` | Post reply |
88
+
89
+ ## Not built yet
90
+
91
+ - **Carrying out an approved plan.** An approval ends at `approvalReceived`. What follows (posting "🤖: Plan is
92
+ approved, working on it...", doing the work, and editing that post into "🤖: Done in" with a link) waits on two
93
+ decisions of Alex's: which agent does the work, and where approvals are recorded.
94
+ - **Other sources.** Google Docs subtabs, GitHub pull requests and Confluence pages, each through a connector the
95
+ organization binds, join as more values of `source`.
96
+
97
+ ## Developing
98
+
99
+ `bun run compile` checks the diagram against the code and writes `src/generated/`. `bun run jive:cicd:audit` type-checks
100
+ and runs the tests: `src/rules.test.ts` covers the rules, and `src/workflow.test.ts` runs comments through the compiled
101
+ workflow on fakes of the services its steps declare (`src/testing/harness.ts`), with no server and no model.
@@ -0,0 +1,12 @@
1
+ import { commentTask } from "./task";
2
+ /**
3
+ * The workflow's settings; its flow is workflows/comment-answering.bpmn. One agent and one code step run at once to
4
+ * start: each comment needs one agent run, and a second comment waits in Answer's queue rather than starting a run that
5
+ * can't progress.
6
+ */
7
+ export const commentAnswering = {
8
+ task: commentTask,
9
+ endStates: ["answered", "planned", "ignored", "approvalReceived", "unanswered", "failed"],
10
+ budgets: { agents: 1, cpu: 1 },
11
+ };
12
+ //# sourceMappingURL=comment-answering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment-answering.js","sourceRoot":"","sources":["../../../src/comment-answering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAEpC;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,WAAW;IACjB,SAAS,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,YAAY,EAAE,QAAQ,CAAC;IACzF,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;CACtB,CAAA"}
@@ -0,0 +1,36 @@
1
+ // Generated by jive-abstract-agentic-workflow from workflows/comment-answering.bpmn. Change the diagram or the step code, never this file.
2
+ import { Workflow } from "@jive-sh/workflow-platform";
3
+ import { decide, markSeen, answer, checkReply, postReply } from "../index";
4
+ import { commentAnswering as settings } from "../comment-answering";
5
+ export const commentAnswering = Workflow.make({
6
+ name: "commentAnswering",
7
+ ...settings,
8
+ events: {
9
+ "task": { kind: "task" },
10
+ },
11
+ steps: () => ({
12
+ decide,
13
+ markSeen,
14
+ answer,
15
+ checkReply,
16
+ postReply,
17
+ }),
18
+ lines: [
19
+ { from: { event: "task" }, to: { step: "decide" } },
20
+ { from: { step: "decide", endState: "forAgent" }, to: { step: "markSeen" } },
21
+ { from: { step: "decide", endState: "notForAgent" }, to: { end: "ignored" } },
22
+ { from: { step: "decide", endState: "approves" }, to: { end: "approvalReceived" } },
23
+ { from: { step: "decide", endState: "failed" }, to: { end: "failed" } },
24
+ { from: { step: "markSeen", endState: "seen" }, to: { step: "answer" } },
25
+ { from: { step: "markSeen", endState: "failed" }, to: { end: "failed" } },
26
+ { from: { step: "answer", endState: "drafted" }, to: { step: "checkReply" } },
27
+ { from: { step: "answer", endState: "failed" }, to: { end: "failed" } },
28
+ { from: { step: "checkReply", endState: "ok" }, to: { step: "postReply" } },
29
+ { from: { step: "checkReply", endState: "again" }, to: { step: "answer" } },
30
+ { from: { step: "checkReply", endState: "givenUp" }, to: { end: "unanswered" } },
31
+ { from: { step: "postReply", endState: "answered" }, to: { end: "answered" } },
32
+ { from: { step: "postReply", endState: "planned" }, to: { end: "planned" } },
33
+ { from: { step: "postReply", endState: "failed" }, to: { end: "failed" } },
34
+ ],
35
+ });
36
+ //# sourceMappingURL=commentAnswering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commentAnswering.js","sourceRoot":"","sources":["../../../../src/generated/commentAnsw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AI,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;KAC3E;CACF,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ // Generated by jive-abstract-agentic-workflow from the diagrams in workflows/. Change them or the step code, never this file.
2
+ import { commentAnswering } from "./commentAnswering";
3
+ export { commentAnswering };
4
+ /** Every workflow of this package, each after the workflows of this package it runs as a step. */
5
+ export const workflows = [commentAnswering];
6
+ //# sourceMappingURL=workflows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../../../src/generated/workflows.ts"],"names":[],"mappings":"AAAA,8HAA8H;AAC9H,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,kGAAkG;AAClG,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,gBAAgB,CAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { commentTask } from "./task";
2
+ export { commentAnswering } from "./comment-answering";
3
+ export { decide } from "./steps/decide";
4
+ export { markSeen } from "./steps/mark-seen";
5
+ export { answer } from "./steps/answer";
6
+ export { checkReply } from "./steps/check-reply";
7
+ export { postReply } from "./steps/post-reply";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA"}
package/dist/rules.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Alex's rules for talking to the agent, carried over from skill-sync's comment watch. Every agent post starts with
3
+ * `🤖:`, so a post that does is never for the agent, whoever wrote it. A plan starts `🤖: **Plan**`, and a person approves
4
+ * it with a reply of "yes" (or "@clanker yes") or a 👍. Pure.
5
+ */
6
+ /** The name a comment tags the agent with, without its @. */
7
+ export const AGENT = "clanker";
8
+ export const AGENT_PREFIX = "🤖:";
9
+ export const PLAN_HEADING = "**Plan**";
10
+ export const SEEN = "👀";
11
+ export const APPROVE = "👍";
12
+ /** The most a source's comment holds, the Jive app's 8000 characters, less room for the prefix and the plan heading. */
13
+ export const MOST_REPLY_CHARACTERS = 7_980;
14
+ /** How many drafts the agent writes for one comment before Check reply gives up. */
15
+ export const MOST_DRAFTS = 3;
16
+ /**
17
+ * Whether a post is an agent's: posted by an agent, starting with 🤖 (with or without the colon), or exactly "...",
18
+ * which another automation on Alex's account posts to say it saw a comment.
19
+ */
20
+ export const isAgentPost = (comment) => comment.author.kind === "agent" || comment.text.trimStart().startsWith("🤖") || comment.text.trim() === "...";
21
+ /** Whether a post is an agent's plan. */
22
+ export const isPlan = (comment) => comment.author.kind === "agent" && comment.text.startsWith(`${AGENT_PREFIX} ${PLAN_HEADING}`);
23
+ /** The text with quoted lines (`> `), fenced code blocks and inline code taken out, where a tag doesn't count. */
24
+ const outsideQuotesAndCode = (text) => text
25
+ .replace(/```[\s\S]*?```/g, " ")
26
+ .replace(/`[^`\n]*`/g, " ")
27
+ .split("\n")
28
+ .filter((line) => !line.trimStart().startsWith(">"))
29
+ .join("\n");
30
+ const tagPattern = new RegExp(`(^|[^\\w@.])@${AGENT}(?![\\w-]|\\.\\w)`, "i");
31
+ /** Whether the text tags the agent: `@clanker` in any capitals, not inside a longer name, a quoted line or code. */
32
+ export const tagsAgent = (text) => tagPattern.test(outsideQuotesAndCode(text));
33
+ /** Whether the words are an approval: "yes", alone or after the tag, in any capitals, with trailing punctuation. */
34
+ export const saysYes = (text) => text
35
+ .replace(new RegExp(`@${AGENT}`, "ig"), "")
36
+ .trim()
37
+ .replace(/[.!]+$/, "")
38
+ .toLowerCase() === "yes";
39
+ /**
40
+ * What a new comment or a person's reaction asks. A reaction asks something only when it is a person's 👍 on an agent's
41
+ * plan. A comment asks nothing when it is an agent's post. A person's "yes" replying in a conversation whose newest agent
42
+ * post is a plan approves that plan. Every other person's comment on a workflow's diagram is for the agent, tagged or
43
+ * not, as in a Google Doc. Pure.
44
+ */
45
+ export const decide = (input) => {
46
+ const { comment } = input;
47
+ if (input.event === "reaction") {
48
+ const approvedByPerson = comment.reactions.some((reaction) => reaction.emoji === APPROVE && reaction.by.kind === "person");
49
+ return isPlan(comment) && approvedByPerson ? { kind: "approves", plan: comment.id } : { kind: "notForAgent", why: "the reaction is no person's 👍 on a plan" };
50
+ }
51
+ if (isAgentPost(comment))
52
+ return { kind: "notForAgent", why: "it is an agent's post" };
53
+ const earlier = input.comments.slice(0, Math.max(0, input.comments.findIndex((one) => one.id === comment.id)));
54
+ const newestAgentPost = [...earlier].reverse().find(isAgentPost);
55
+ if (newestAgentPost !== undefined && isPlan(newestAgentPost) && saysYes(comment.text))
56
+ return { kind: "approves", plan: newestAgentPost.id };
57
+ return { kind: "forAgent" };
58
+ };
59
+ /** What is wrong with a draft, in words the agent can act on; empty when it may be posted. Pure. */
60
+ export const draftProblems = (draft) => {
61
+ const problems = [];
62
+ const text = draft.text.trim();
63
+ if (text.length === 0)
64
+ problems.push("the text is empty");
65
+ if (text.length > MOST_REPLY_CHARACTERS)
66
+ problems.push(`the text has ${text.length} characters, more than the ${MOST_REPLY_CHARACTERS} a reply holds`);
67
+ if (text.startsWith("🤖"))
68
+ problems.push("the text starts with 🤖, which the workflow adds itself");
69
+ if (text.startsWith(PLAN_HEADING))
70
+ problems.push(`the text starts with ${PLAN_HEADING}, which the workflow adds to a plan itself`);
71
+ if (tagsAgent(text))
72
+ problems.push(`the text tags @${AGENT}, which would hand the reply back to the agent`);
73
+ return problems;
74
+ };
75
+ /** The reply as it is posted: the agent prefix, and the plan heading on a plan. Pure. */
76
+ export const replyText = (draft) => draft.kind === "plan" ? `${AGENT_PREFIX} ${PLAN_HEADING}\n\n${draft.text.trim()}` : `${AGENT_PREFIX} ${draft.text.trim()}`;
77
+ /** The key a comment's reply is posted under, so posting it again posts nothing. Pure. */
78
+ export const replyKey = (comment) => `reply:${comment}`;
79
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../src/rules.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAA;AAC9B,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAA;AACjC,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAA;AACtC,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAA;AACxB,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAA;AAC3B,wHAAwH;AACxH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAA;AAC1C,oFAAoF;AACpF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAA;AAI5B;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAgB,EAAW,EAAE,CACvD,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,KAAK,CAAA;AAE/G,yCAAyC;AACzC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAW,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,OA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QAAE,QAAQ,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;IACzD,IAAI,IAAI,CAAC,MAAM,GAAG,qBAAqB;QAAE,QAAQ,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,MAAM,8BAA8B,qBAAqB,gBAAgB,CAAC,CAAA;IACtJ,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,QAAQ,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAA;IACnG,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;QAAE,QAAQ,CAAC,IAAI,CAAC,wBAAwB,YAAY,4CAA4C,CAAC,CAAA;IAClI,IAAI,SAAS,CAAC,IAAI,CAAC;QAAE,QAAQ,CAAC,IAAI,CAAC,kBAAkB,KAAK,gDAAgD,CAAC,CAAA;IAC3G,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAY,EAAU,EAAE,CAChD,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,YAAY,IAAI,YAAY,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,YAAY,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAA;AAE5H,0FAA0F;AAC1F,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAU,EAAE,CAAC,SAAS,OAAO,EAAE,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { AgentRunner, WorkflowComments } from "@jive-sh/workflow-platform";
2
+ import { AGENT, AGENT_PREFIX, MOST_REPLY_CHARACTERS } from "../rules";
3
+ import { DRAFT_FILE, RETRIES, step } from "./shared";
4
+ /** What the agent is told to be, the same for every comment, so the provider reads it from its cache. */
5
+ export const ANSWER_INSTRUCTIONS = `You are ${AGENT}, the agent people talk to in comments on a Jive workflow's diagram. Each comment is on one element of the workflow's graph: a step, a decision, an event, a line or an end state, named by a key such as step:<id>.
6
+
7
+ Reply to the newest comment, reading the whole conversation and the graph you are given.
8
+ - When the comment asks a question, answer it: plainly, in complete sentences, with only what answers it. Name every step, field and end state by its id in the graph.
9
+ - When the comment asks for any change (to the workflow, its code, a document or anything else), make no change and claim none. Reply with a plan instead: the concrete changes, each naming what it touches, and what each changes for the person. A person approves it by replying "yes".
10
+ - Never claim anything the graph, the conversation or the comment does not show. Say what you don't know.
11
+
12
+ Answer with one JSON object and nothing else: {"kind": "answer" | "plan", "text": "<your reply>"}. The text is at most ${MOST_REPLY_CHARACTERS} characters of plain Markdown. Don't start it with ${AGENT_PREFIX} or with a heading: the workflow adds them. Never write @${AGENT}.`;
13
+ /**
14
+ * ANSWER: the agent reads the comment, its conversation and the graph of the version it is on, and drafts an answer or a
15
+ * plan into `reply.json`. A draft Check reply sent back comes with why, from the task's notes.
16
+ */
17
+ export const answer = step.agent({
18
+ endStates: ["drafted", "failed"],
19
+ access: { services: [AgentRunner.AgentRunner, WorkflowComments.WorkflowComments] },
20
+ retries: RETRIES,
21
+ run: function* (task) {
22
+ const comments = yield* WorkflowComments.WorkflowComments;
23
+ const read = yield* comments.get({ comment: task.fields.comment });
24
+ const sentBack = task.notes.filter((note) => note.step === "checkReply").map((note) => note.note);
25
+ const conversation = read.comments
26
+ .map((comment) => `[${comment.id}] ${comment.author.kind === "agent" ? `agent ${comment.author.agent}` : `person ${comment.author.account}`}: ${comment.text}`)
27
+ .join("\n\n");
28
+ const prompt = [
29
+ `The comment is on ${read.place.element} of the workflow ${read.place.workflow}, ${read.place.version.kind === "current" ? "its installed version" : `its proposal ${read.place.version.ref}`}. Its link: ${read.place.link}`,
30
+ `The conversation, oldest first:\n\n${conversation}`,
31
+ `Reply to the newest comment, [${read.comment.id}].`,
32
+ ...(sentBack.length > 0 ? [`Your earlier drafts were sent back:\n${sentBack.map((why) => `- ${why}`).join("\n")}`] : []),
33
+ ].join("\n\n");
34
+ const runner = yield* AgentRunner.AgentRunner;
35
+ const result = yield* runner.run({
36
+ instructions: ANSWER_INSTRUCTIONS,
37
+ cached: `The graph of that version of ${read.place.workflow}:\n${JSON.stringify(read.place.graph)}`,
38
+ prompt,
39
+ files: [],
40
+ tools: { kind: "none" },
41
+ });
42
+ return {
43
+ endState: "drafted",
44
+ files: [{ name: DRAFT_FILE, bytes: new TextEncoder().encode(result.output) }],
45
+ note: result.stoppedAtTurnLimit ? "the agent stopped at its turn limit before it answered" : `drafted by ${result.agent}`,
46
+ };
47
+ },
48
+ });
49
+ //# sourceMappingURL=answer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer.js","sourceRoot":"","sources":["../../../../src/steps/answer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC1E,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAEpD,yGAAyG;AACzG,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,KAAK;;;;;;;yHAOsE,qBAAqB,sDAAsD,YAAY,4DAA4D,KAAK,GAAG,CAAA;AAEpR;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAC/B,SAAS,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;IAChC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,EAAE;IAClF,OAAO,EAAE,OAAO;IAChB,GAAG,EAAE,QAAQ,CAAC,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,CAAA;QACzD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,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,CAAC,EAAE,CAAC;SACzH,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACd,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC,WAAW,CAAA;QAC7C,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;YAC/B,YAAY,EAAE,mBAAmB;YACjC,MAAM,EAAE,gCAAgC,IAAI,CAAC,KAAK,CAAC,QAAQ,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACnG,MAAM;YACN,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;SACxB,CAAC,CAAA;QACF,OAAO;YACL,QAAQ,EAAE,SAAkB;YAC5B,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7E,IAAI,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,wDAAwD,CAAC,CAAC,CAAC,cAAc,MAAM,CAAC,KAAK,EAAE;SAC1H,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { FileStore } from "@jive-sh/workflow-platform";
2
+ import { Effect, Result } from "effect";
3
+ import { draftProblems, MOST_DRAFTS } from "../rules";
4
+ import { DRAFT_FILE, draftOf, readTaskFile, step } from "./shared";
5
+ /**
6
+ * CHECK REPLY: the verifier of Answer's draft, apart from the agent that wrote it. A draft that holds one answer or one
7
+ * plan, fits a reply and hands nothing back to the agent goes on to be posted. Any other goes back to Answer with why,
8
+ * at most `MOST_DRAFTS` drafts in all; then the comment is left unanswered, with its 👀 still on it to say so.
9
+ */
10
+ export const checkReply = step.code({
11
+ endStates: ["ok", "again", "givenUp"],
12
+ access: { services: [FileStore.FileStore] },
13
+ run: function* (task) {
14
+ const drafts = task.fields.drafts + 1;
15
+ const words = yield* readTaskFile({ files: task.files, name: DRAFT_FILE });
16
+ const parsed = yield* Effect.result(draftOf(words));
17
+ const problems = Result.isSuccess(parsed) ? draftProblems(parsed.success) : [parsed.failure];
18
+ if (problems.length === 0 && Result.isSuccess(parsed)) {
19
+ return { endState: "ok", fields: { drafts, replyKind: parsed.success.kind } };
20
+ }
21
+ const why = problems.join("; ");
22
+ return drafts < MOST_DRAFTS
23
+ ? { endState: "again", fields: { drafts }, note: why }
24
+ : { endState: "givenUp", fields: { drafts }, note: `gave up after ${drafts} drafts: ${why}` };
25
+ },
26
+ });
27
+ //# sourceMappingURL=check-reply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-reply.js","sourceRoot":"","sources":["../../../../src/steps/check-reply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAElE;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;IAClC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC;IACrC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;IAC3C,GAAG,EAAE,QAAQ,CAAC,EAAE,IAAI;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAA;QAC1E,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;QACnD,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAC5F,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YACtD,OAAO,EAAE,QAAQ,EAAE,IAAa,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAA;QACxF,CAAC;QACD,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC/B,OAAO,MAAM,GAAG,WAAW;YACzB,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAgB,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE;YAC/D,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAkB,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,iBAAiB,MAAM,YAAY,GAAG,EAAE,EAAE,CAAA;IAC1G,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { WorkflowComments } from "@jive-sh/workflow-platform";
2
+ import { decide as decideComment } from "../rules";
3
+ import { RETRIES, step } from "./shared";
4
+ /**
5
+ * DECIDE: reads the comment and its conversation from its source and says what it asks: an answer from the agent, nothing
6
+ * (an agent's own post, or a reaction that approves nothing), or approval of a plan.
7
+ */
8
+ export const decide = step.code({
9
+ endStates: ["forAgent", "notForAgent", "approves", "failed"],
10
+ access: { services: [WorkflowComments.WorkflowComments] },
11
+ retries: RETRIES,
12
+ run: function* (task) {
13
+ const comments = yield* WorkflowComments.WorkflowComments;
14
+ const read = yield* comments.get({ comment: task.fields.comment });
15
+ const decision = decideComment({ event: task.fields.event, comment: read.comment, comments: read.comments });
16
+ switch (decision.kind) {
17
+ case "forAgent":
18
+ return { endState: "forAgent" };
19
+ case "notForAgent":
20
+ return { endState: "notForAgent", note: `not for the agent: ${decision.why}` };
21
+ case "approves":
22
+ return { endState: "approves", note: `approves the plan ${decision.plan}` };
23
+ }
24
+ },
25
+ });
26
+ //# sourceMappingURL=decide.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decide.js","sourceRoot":"","sources":["../../../../src/steps/decide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;IAC9B,SAAS,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC;IAC5D,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE;IACzD,OAAO,EAAE,OAAO;IAChB,GAAG,EAAE,QAAQ,CAAC,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,CAAA;QACzD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;QAClE,MAAM,QAAQ,GAAG,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC5G,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;YACtB,KAAK,UAAU;gBACb,OAAO,EAAE,QAAQ,EAAE,UAAmB,EAAE,CAAA;YAC1C,KAAK,aAAa;gBAChB,OAAO,EAAE,QAAQ,EAAE,aAAsB,EAAE,IAAI,EAAE,sBAAsB,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAA;YACzF,KAAK,UAAU;gBACb,OAAO,EAAE,QAAQ,EAAE,UAAmB,EAAE,IAAI,EAAE,qBAAqB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAA;QACxF,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { WorkflowComments } from "@jive-sh/workflow-platform";
2
+ import { AGENT, SEEN } from "../rules";
3
+ import { RETRIES, step } from "./shared";
4
+ /** MARK SEEN: puts the agent's 👀 on the comment, which Post reply takes off once the reply is posted. */
5
+ export const markSeen = step.code({
6
+ endStates: ["seen", "failed"],
7
+ access: { services: [WorkflowComments.WorkflowComments] },
8
+ retries: RETRIES,
9
+ run: function* (task) {
10
+ const comments = yield* WorkflowComments.WorkflowComments;
11
+ yield* comments.react({ comment: task.fields.comment, agent: AGENT, emoji: SEEN, on: true });
12
+ return { endState: "seen" };
13
+ },
14
+ });
15
+ //# sourceMappingURL=mark-seen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mark-seen.js","sourceRoot":"","sources":["../../../../src/steps/mark-seen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAExC,0GAA0G;AAC1G,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;IAChC,SAAS,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC7B,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE;IACzD,OAAO,EAAE,OAAO;IAChB,GAAG,EAAE,QAAQ,CAAC,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,CAAA;QACzD,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;QAC5F,OAAO,EAAE,QAAQ,EAAE,MAAe,EAAE,CAAA;IACtC,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { FileStore, WorkflowComments } from "@jive-sh/workflow-platform";
2
+ import { Effect } from "effect";
3
+ import { AGENT, replyKey, replyText, SEEN } from "../rules";
4
+ import { DRAFT_FILE, draftOf, RETRIES, readTaskFile, step } from "./shared";
5
+ /**
6
+ * POST REPLY: posts the checked draft in the comment's conversation once, under the comment's reply key, so a run tried
7
+ * again posts nothing more; then takes the agent's 👀 off the comment. The only writer of the agent's reply.
8
+ */
9
+ export const postReply = step.code({
10
+ endStates: ["answered", "planned", "failed"],
11
+ access: { services: [WorkflowComments.WorkflowComments, FileStore.FileStore] },
12
+ retries: RETRIES,
13
+ run: function* (task) {
14
+ const comments = yield* WorkflowComments.WorkflowComments;
15
+ const draft = yield* draftOf(yield* readTaskFile({ files: task.files, name: DRAFT_FILE }));
16
+ const read = yield* comments.get({ comment: task.fields.comment });
17
+ const posted = yield* comments.reply({ conversation: read.conversation, agent: AGENT, text: replyText(draft), key: replyKey(task.fields.comment) });
18
+ yield* comments.react({ comment: task.fields.comment, agent: AGENT, emoji: SEEN, on: false });
19
+ yield* Effect.logInfo(`posted ${posted.comment}${posted.created ? "" : ", which was already there"}`);
20
+ return {
21
+ endState: draft.kind === "plan" ? "planned" : "answered",
22
+ fields: { posted: posted.comment },
23
+ note: posted.created ? `posted ${posted.comment}` : `the reply ${posted.comment} was already posted`,
24
+ };
25
+ },
26
+ });
27
+ //# sourceMappingURL=post-reply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-reply.js","sourceRoot":"","sources":["../../../../src/steps/post-reply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC;IACjC,SAAS,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC;IAC5C,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE;IAC9E,OAAO,EAAE,OAAO;IAChB,GAAG,EAAE,QAAQ,CAAC,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,CAAA;QACzD,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;QAC1F,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;QAClE,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QACnJ,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAC7F,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,2BAA2B,EAAE,CAAC,CAAA;QACrG,OAAO;YACL,QAAQ,EAAE,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAE,SAAmB,CAAC,CAAC,CAAE,UAAoB;YAC9E,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE;YAClC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,OAAO,qBAAqB;SACrG,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { FileStore, Workflow } from "@jive-sh/workflow-platform";
2
+ import { Effect, Schema } from "effect";
3
+ import { commentTask } from "../task";
4
+ /** The steps' builder: it types each step's run by the services its `access` lists. */
5
+ export const step = Workflow.stepsOf(commentTask);
6
+ /**
7
+ * How a run that fails (the organization's server or the agent's provider unreachable) is tried again before it parks
8
+ * at `failed`: three times, a minute apart.
9
+ */
10
+ export const RETRIES = { limit: 3, delayMs: 60_000, giveUp: "failed" };
11
+ export const DRAFT_FILE = "reply.json";
12
+ const DraftJson = Schema.fromJsonString(Schema.Struct({ kind: Schema.Literals(["answer", "plan"]), text: Schema.String }));
13
+ /** The JSON object in a model's reply, which may be wrapped in words or a fence. Pure. */
14
+ export const jsonIn = (text) => text.slice(text.indexOf("{"), text.lastIndexOf("}") + 1);
15
+ /** The draft in the agent's words, or why they hold none. */
16
+ export const draftOf = (words) => Effect.mapError(Schema.decodeUnknownEffect(DraftJson)(jsonIn(words)), () => 'the reply was not one JSON object {"kind": "answer" | "plan", "text": "..."}');
17
+ /** The text of a task file, read through the organization's file store. */
18
+ export const readTaskFile = function* (input) {
19
+ const file = input.files.find((one) => one.name === input.name);
20
+ if (file === undefined)
21
+ return yield* Effect.fail(`the task has no ${input.name}`);
22
+ const store = yield* FileStore.FileStore;
23
+ return new TextDecoder().decode(yield* store.read(file));
24
+ };
25
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/steps/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC,uFAAuF;AACvF,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;AAEjD;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAiB,EAAE,CAAA;AAE/E,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAA;AAEtC,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE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A field every pass starts from empty: null, which a later step writes (an absent key can't be unset). */
4
+ const emptyUntilSet = (schema) => Schema.NullOr(schema).pipe(Schema.withDecodingDefaultKey(Effect.succeed(null)));
5
+ /**
6
+ * One comment to answer. The task carries only references: where the comment is (`source`), which comment, and what
7
+ * happened to it (a new comment, or a reaction to one). Its words, its conversation and what it is on are read from the
8
+ * source by each step, so the source stays their one owner. The agent's draft is the file `reply.json`.
9
+ */
10
+ export const commentTask = TaskSchema.make({
11
+ fields: Schema.Struct({
12
+ /** Where the comment was left: today only on an element of a workflow's diagram in the Jive app. */
13
+ source: Schema.Literal("workflow-diagram"),
14
+ /** The comment's id in its source. */
15
+ comment: Schema.String,
16
+ /** What made the task: a new comment, or a person's reaction to one. */
17
+ event: Schema.Literals(["comment", "reaction"]),
18
+ /** How many drafts Check reply has read for this comment; it gives up after `MOST_DRAFTS`. */
19
+ drafts: Schema.Finite.pipe(Schema.withDecodingDefaultKey(Effect.succeed(0))),
20
+ /** What the checked draft is: an answer, or a plan that waits for approval. */
21
+ replyKind: emptyUntilSet(Schema.Literals(["answer", "plan"])),
22
+ /** The reply Post reply posted, by its id in the source. */
23
+ posted: emptyUntilSet(Schema.String),
24
+ }),
25
+ files: ["reply.json"],
26
+ });
27
+ //# sourceMappingURL=task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task.js","sourceRoot":"","sources":["../../../src/task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEvC,4GAA4G;AAC5G,MAAM,aAAa,GAAG,CAAuB,MAAS,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAE1I;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;QACpB,oGAAoG;QACpG,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC;QAC1C,sCAAsC;QACtC,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,wEAAwE;QACxE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC/C,8FAA8F;QAC9F,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5E,+EAA+E;QAC/E,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QAC7D,4DAA4D;QAC5D,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC;KACrC,CAAC;IACF,KAAK,EAAE,CAAC,YAAY,CAAC;CACtB,CAAC,CAAA"}