@pipefy/pipefy-process-coder 0.1.0 → 0.1.1

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 (159) hide show
  1. package/.agents/skills/ppc-pipefy-flow-authoring/SKILL.md +262 -262
  2. package/.agents/skills/ppc-pipefy-flow-authoring/examples/01-main-2-danfe-consulta.json +247 -247
  3. package/.agents/skills/ppc-pipefy-flow-authoring/examples/01-main-2-webhook-retorno-consulta.json +589 -589
  4. package/.agents/skills/ppc-pipefy-flow-authoring/examples/01-main-4-recebimento-barramento.json +1391 -1391
  5. package/.agents/skills/ppc-pipefy-flow-authoring/examples/02-subflow-2-danfe-retorno.json +623 -623
  6. package/.agents/skills/ppc-pipefy-flow-authoring/examples/02-subflow-4-criacao-operacao.json +636 -636
  7. package/.agents/skills/ppc-pipefy-flow-authoring/examples/03-subflow-4-criacao-titulo.json +3642 -3642
  8. package/.agents/skills/ppc-pipefy-flow-authoring/examples/04-subflow-4-criacao-cedente.json +863 -863
  9. package/.agents/skills/ppc-pipefy-flow-authoring/examples/04-subflow-4-criacao-sacado.json +799 -799
  10. package/.agents/skills/ppc-pipefy-flow-authoring/examples/README.md +42 -42
  11. package/.agents/skills/ppc-pipefy-flow-authoring/examples/hml-01-subflow-1-titulo-acompanhamento-cobranca.json +581 -581
  12. package/.agents/skills/ppc-pipefy-flow-authoring/examples/hml-01-subflow-1-titulo-nfe-monitoramento.json +503 -503
  13. package/.agents/skills/ppc-pipefy-flow-authoring/examples/hml-01-subflow-1-titulo-retorno-bancario.json +562 -562
  14. package/.agents/skills/ppc-pipefy-flow-authoring/examples/hml-02-subflow-2-retorno-consulta-cedente.json +557 -557
  15. package/.agents/skills/ppc-pipefy-flow-authoring/examples/hml-02-subflow-2-retorno-consulta-sacado.json +609 -609
  16. package/.agents/skills/ppc-pipefy-pipe-authoring/SKILL.md +146 -146
  17. package/.agents/skills/ppc-pipefy-process-design/SKILL.md +127 -127
  18. package/.agents/skills/ppc-pipefy-workspace/SKILL.md +91 -91
  19. package/AGENTS.md +465 -456
  20. package/README.md +825 -807
  21. package/bin/pipe.js +25 -4
  22. package/dist/apply/adopt.js +128 -0
  23. package/dist/apply/agentops.js +42 -0
  24. package/dist/apply/compile.js +722 -0
  25. package/dist/apply/execute.js +277 -0
  26. package/dist/apply/flowops.js +293 -0
  27. package/dist/apply/idmap.js +233 -0
  28. package/dist/apply/mutations.js +704 -0
  29. package/dist/apply/registry.js +348 -0
  30. package/dist/apply/types.js +18 -0
  31. package/dist/cli/args.js +79 -0
  32. package/dist/cli.js +187 -0
  33. package/dist/codec/flow.js +164 -0
  34. package/dist/codec/pack.js +88 -0
  35. package/dist/codec/roundtrip.js +86 -0
  36. package/dist/codec/unpack.js +181 -0
  37. package/dist/commands/agents.js +145 -0
  38. package/dist/commands/apply.js +982 -0
  39. package/dist/commands/context.js +79 -0
  40. package/dist/commands/create.js +63 -0
  41. package/dist/commands/diff.js +294 -0
  42. package/dist/commands/flows.js +348 -0
  43. package/dist/commands/misc.js +528 -0
  44. package/dist/commands/plan.js +301 -0
  45. package/dist/commands/pull.js +511 -0
  46. package/dist/commands/runs.js +74 -0
  47. package/dist/commands/skills.js +131 -0
  48. package/dist/commands/verify.js +205 -0
  49. package/dist/config.js +125 -0
  50. package/dist/diff/agents.js +80 -0
  51. package/dist/diff/diff.js +983 -0
  52. package/dist/diff/flow.js +258 -0
  53. package/{src/diff/html.ts → dist/diff/html.js} +274 -322
  54. package/dist/diff/render.js +90 -0
  55. package/dist/model/payload.js +84 -0
  56. package/dist/model/tree.js +7 -0
  57. package/dist/model/volatile.js +54 -0
  58. package/dist/pipefy/agents.js +122 -0
  59. package/dist/pipefy/automations.js +155 -0
  60. package/dist/pipefy/capability.js +84 -0
  61. package/dist/pipefy/client.js +204 -0
  62. package/dist/pipefy/discovery.js +148 -0
  63. package/dist/pipefy/internal.js +315 -0
  64. package/dist/pipefy/ipaas.js +269 -0
  65. package/dist/pipefy/reconstruct.js +674 -0
  66. package/dist/pipefy/reference.js +172 -0
  67. package/dist/pipefy/snapshot.js +185 -0
  68. package/dist/pipefy/toolkit.js +158 -0
  69. package/dist/report/integrations.js +165 -0
  70. package/dist/report/run.js +355 -0
  71. package/dist/util/fsx.js +50 -0
  72. package/dist/util/git.js +25 -0
  73. package/dist/util/json.js +56 -0
  74. package/dist/util/log.js +69 -0
  75. package/dist/util/pool.js +42 -0
  76. package/dist/util/slug.js +23 -0
  77. package/dist/util/tui.js +287 -0
  78. package/dist/validate/index.js +86 -0
  79. package/dist/validate/integrity.js +370 -0
  80. package/dist/validate/reference.js +120 -0
  81. package/dist/validate/schema.js +278 -0
  82. package/dist/workspace/agents.js +245 -0
  83. package/{src/workspace/docs.ts → dist/workspace/docs.js} +367 -407
  84. package/dist/workspace/flows.js +149 -0
  85. package/dist/workspace/layout.js +146 -0
  86. package/dist/workspace/lock.js +83 -0
  87. package/dist/workspace/read.js +168 -0
  88. package/dist/workspace/reference.js +24 -0
  89. package/dist/workspace/stamp.js +234 -0
  90. package/dist/workspace/write.js +194 -0
  91. package/package.json +37 -35
  92. package/src/apply/adopt.ts +0 -150
  93. package/src/apply/agentops.ts +0 -71
  94. package/src/apply/compile.ts +0 -875
  95. package/src/apply/execute.ts +0 -336
  96. package/src/apply/flowops.ts +0 -399
  97. package/src/apply/idmap.ts +0 -241
  98. package/src/apply/mutations.ts +0 -955
  99. package/src/apply/registry.ts +0 -430
  100. package/src/apply/types.ts +0 -134
  101. package/src/cli/args.ts +0 -88
  102. package/src/cli.ts +0 -211
  103. package/src/codec/flow.ts +0 -199
  104. package/src/codec/pack.ts +0 -103
  105. package/src/codec/roundtrip.ts +0 -94
  106. package/src/codec/unpack.ts +0 -198
  107. package/src/commands/agents.ts +0 -184
  108. package/src/commands/apply.ts +0 -1144
  109. package/src/commands/context.ts +0 -119
  110. package/src/commands/create.ts +0 -79
  111. package/src/commands/diff.ts +0 -314
  112. package/src/commands/flows.ts +0 -414
  113. package/src/commands/misc.ts +0 -644
  114. package/src/commands/plan.ts +0 -331
  115. package/src/commands/pull.ts +0 -567
  116. package/src/commands/runs.ts +0 -83
  117. package/src/commands/skills.ts +0 -137
  118. package/src/commands/verify.ts +0 -253
  119. package/src/config.ts +0 -168
  120. package/src/diff/agents.ts +0 -122
  121. package/src/diff/diff.ts +0 -1130
  122. package/src/diff/flow.ts +0 -318
  123. package/src/diff/render.ts +0 -101
  124. package/src/model/payload.ts +0 -154
  125. package/src/model/tree.ts +0 -99
  126. package/src/model/volatile.ts +0 -55
  127. package/src/pipefy/agents.ts +0 -165
  128. package/src/pipefy/automations.ts +0 -219
  129. package/src/pipefy/capability.ts +0 -119
  130. package/src/pipefy/client.ts +0 -267
  131. package/src/pipefy/discovery.ts +0 -209
  132. package/src/pipefy/internal.ts +0 -380
  133. package/src/pipefy/ipaas.ts +0 -365
  134. package/src/pipefy/reconstruct.ts +0 -775
  135. package/src/pipefy/reference.ts +0 -251
  136. package/src/pipefy/snapshot.ts +0 -245
  137. package/src/pipefy/toolkit.ts +0 -200
  138. package/src/report/integrations.ts +0 -231
  139. package/src/report/run.ts +0 -475
  140. package/src/util/fsx.ts +0 -45
  141. package/src/util/git.ts +0 -32
  142. package/src/util/json.ts +0 -55
  143. package/src/util/log.ts +0 -76
  144. package/src/util/pool.ts +0 -48
  145. package/src/util/slug.ts +0 -26
  146. package/src/util/tui.ts +0 -335
  147. package/src/validate/index.ts +0 -123
  148. package/src/validate/integrity.ts +0 -387
  149. package/src/validate/reference.ts +0 -136
  150. package/src/validate/schema.ts +0 -328
  151. package/src/workspace/agents.ts +0 -290
  152. package/src/workspace/flows.ts +0 -191
  153. package/src/workspace/layout.ts +0 -165
  154. package/src/workspace/lock.ts +0 -148
  155. package/src/workspace/read.ts +0 -165
  156. package/src/workspace/reference.ts +0 -24
  157. package/src/workspace/stamp.ts +0 -301
  158. package/src/workspace/write.ts +0 -225
  159. /package/{src → dist}/pipefy/toolkit_bearer.py +0 -0
package/bin/pipe.js CHANGED
@@ -1,13 +1,34 @@
1
1
  #!/usr/bin/env node
2
2
  // Thin launcher so `pipe` works when the package is linked or installed
3
- // globally. Node >=22.18 strips the types in src/*.ts natively, so there is no
4
- // build step.
3
+ // globally.
4
+ //
5
+ // Two trees, chosen by where this file actually lives. Node strips the types
6
+ // in src/*.ts natively (>=22.18) but refuses to for anything under
7
+ // node_modules, which is where `npm i -g` puts the package — so an install
8
+ // runs dist/, emitted at pack time by scripts/build.ts. A clone or `npm link`
9
+ // (a symlink, which Node resolves to the real path outside node_modules) runs
10
+ // src/ directly with no build step. Deciding by location rather than by
11
+ // "does dist/ exist" means a leftover local build can never shadow the source
12
+ // someone is editing.
5
13
  //
6
14
  // The path must be converted to a file:// URL before import(): on Windows a
7
15
  // bare path like C:\...\src\cli.ts is rejected with
8
16
  // ERR_UNSUPPORTED_ESM_URL_SCHEME, since `C:` reads as a protocol.
17
+ import { existsSync } from 'node:fs';
9
18
  import { fileURLToPath, pathToFileURL } from 'node:url';
10
- import { dirname, join } from 'node:path';
19
+ import { dirname, join, sep } from 'node:path';
11
20
 
12
21
  const here = dirname(fileURLToPath(import.meta.url));
13
- await import(pathToFileURL(join(here, '..', 'src', 'cli.ts')).href);
22
+ const installed = here.split(sep).includes('node_modules');
23
+ const entry = installed ? join(here, '..', 'dist', 'cli.js') : join(here, '..', 'src', 'cli.ts');
24
+
25
+ if (!existsSync(entry)) {
26
+ console.error(
27
+ `pipe: ${entry} is missing. This package was installed without its build — ` +
28
+ 'it is emitted at pack time (npm pack / npm publish run scripts/build.ts). ' +
29
+ 'Reinstall from the registry, or run from a clone with `npm link`.',
30
+ );
31
+ process.exit(1);
32
+ }
33
+
34
+ await import(pathToFileURL(entry).href);
@@ -0,0 +1,128 @@
1
+ import { changeByKey } from "./types.js";
2
+ export const adoptCreatedIds = (changeSet, plan, idMap) => {
3
+ const adopted = [];
4
+ for (const step of plan.steps) {
5
+ if (step.status !== 'done' || !step.produces)
6
+ continue;
7
+ const id = idMap.placeholderValue(step.produces.placeholder);
8
+ if (id === undefined)
9
+ continue;
10
+ const change = changeByKey(changeSet, step.changeKey);
11
+ if (!change || change.op !== 'create' || change.entity === 'repo' || !change.after)
12
+ continue;
13
+ const row = change.after;
14
+ if (Number(row['id']) === id && row['_new'] !== true)
15
+ continue; // a resumed step, already adopted
16
+ row['id'] = id;
17
+ delete row['_new'];
18
+ adopted.push({ entity: change.entity, label: change.label, id });
19
+ }
20
+ return adopted;
21
+ };
22
+ /**
23
+ * Where an adopted row belongs in a baseline tree — additive only.
24
+ *
25
+ * A created entity is pure addition: the previous baseline has no row for it
26
+ * at all, by definition, so there is nothing to overwrite and no unapplied
27
+ * edit to lose. `entity` and `id` are enough to find it in the already
28
+ * id-and-reference-resolved tree (`patched`, the output of `idMap.rewrite`),
29
+ * because the id this run just adopted is unique within its array.
30
+ */
31
+ const findAdoptedRow = (patched, a) => {
32
+ switch (a.entity) {
33
+ case 'phases':
34
+ return patched.phases.find((p) => Number(p['id']) === a.id);
35
+ case 'fields':
36
+ return patched.phases.flatMap((p) => p.fields).find((f) => Number(f['id']) === a.id);
37
+ case 'automations':
38
+ return patched.automations.find((au) => Number(au['id']) === a.id);
39
+ case 'labels':
40
+ return patched.labels.find((l) => Number(l['id']) === a.id);
41
+ case 'field_conditions':
42
+ return patched.field_conditions.find((fc) => Number(fc['id']) === a.id);
43
+ case 'webhooks':
44
+ return patched.webhooks.find((w) => Number(w['id']) === a.id);
45
+ case 'pipe_relations':
46
+ return patched.pipe_relations.find((r) => Number(r['id']) === a.id);
47
+ default:
48
+ return undefined;
49
+ }
50
+ };
51
+ /**
52
+ * Merge every adopted row into a baseline tree, in the order they were
53
+ * adopted — a new field's phase must land in `baseline.phases` before the
54
+ * field itself is pushed into it, and `plan.steps` already runs creates in
55
+ * that order (registry/compile.ts), so `adopted` does too.
56
+ *
57
+ * Mutates and returns `baseline`. Never touches a row baseline already has
58
+ * an opinion about — this is append-only, which is what makes it safe without
59
+ * a live read: the alternative (replaying an update or delete too) would
60
+ * require knowing the *current* baseline row to update, which is exactly the
61
+ * information a network read would supply and this path does not have.
62
+ */
63
+ export const mergeAdoptedIntoBaseline = (baseline, patched, adopted) => {
64
+ let changed = false;
65
+ for (const a of adopted) {
66
+ const row = findAdoptedRow(patched, a);
67
+ if (!row)
68
+ continue;
69
+ const clone = { ...row };
70
+ switch (a.entity) {
71
+ case 'phases':
72
+ if (baseline.phases.some((p) => Number(p['id']) === a.id))
73
+ continue;
74
+ baseline.phases.push(clone);
75
+ break;
76
+ case 'fields': {
77
+ const phaseId = Number(clone['phase_id']);
78
+ const phase = baseline.phases.find((p) => Number(p['id']) === phaseId);
79
+ if (!phase || phase.fields.some((f) => Number(f['id']) === a.id))
80
+ continue;
81
+ phase.fields.push(clone);
82
+ break;
83
+ }
84
+ case 'automations':
85
+ if (baseline.automations.some((au) => Number(au['id']) === a.id))
86
+ continue;
87
+ baseline.automations.push(clone);
88
+ break;
89
+ case 'labels':
90
+ if (baseline.labels.some((l) => Number(l['id']) === a.id))
91
+ continue;
92
+ baseline.labels.push(clone);
93
+ break;
94
+ case 'field_conditions':
95
+ if (baseline.field_conditions.some((fc) => Number(fc['id']) === a.id))
96
+ continue;
97
+ baseline.field_conditions.push(clone);
98
+ break;
99
+ case 'webhooks':
100
+ if (baseline.webhooks.some((w) => Number(w['id']) === a.id))
101
+ continue;
102
+ baseline.webhooks.push(clone);
103
+ break;
104
+ case 'pipe_relations':
105
+ if (baseline.pipe_relations.some((r) => Number(r['id']) === a.id))
106
+ continue;
107
+ baseline.pipe_relations.push(clone);
108
+ break;
109
+ default:
110
+ continue;
111
+ }
112
+ changed = true;
113
+ }
114
+ return changed;
115
+ };
116
+ export const renderAdopted = (adopted) => {
117
+ if (!adopted.length)
118
+ return [];
119
+ const lines = [
120
+ `adopted ${adopted.length} server-assigned id${adopted.length === 1 ? '' : 's'} directly from the create ` +
121
+ `response(s) — no read-back needed, so a re-plan will not create them again`,
122
+ ];
123
+ for (const a of adopted.slice(0, 8))
124
+ lines.push(` ${a.entity} ${a.label} → ${a.id}`);
125
+ if (adopted.length > 8)
126
+ lines.push(` …and ${adopted.length - 8} more`);
127
+ return lines;
128
+ };
@@ -0,0 +1,42 @@
1
+ import { createAiAgent, updateAiAgent, deleteAiAgent } from "./mutations.js";
2
+ export const compileAgents = async (client, cs) => {
3
+ const steps = [];
4
+ for (const [i, c] of cs.changes.entries()) {
5
+ const id = `a${String(i + 1).padStart(3, '0')}`;
6
+ if (c.op === 'create') {
7
+ steps.push({
8
+ id,
9
+ index: i,
10
+ changeKey: c.key,
11
+ op: 'create',
12
+ description: `createAiAgent — ${c.label}`,
13
+ request: await createAiAgent(client, c.after ?? {}, c.behaviors),
14
+ status: 'pending',
15
+ });
16
+ }
17
+ else if (c.op === 'update') {
18
+ steps.push({
19
+ id,
20
+ index: i,
21
+ changeKey: c.key,
22
+ op: 'update',
23
+ description: `updateAiAgent — ${c.label}`,
24
+ request: await updateAiAgent(client, String(c.before?.['uuid'] ?? ''), c.after ?? {}, c.behaviors),
25
+ status: 'pending',
26
+ });
27
+ }
28
+ else {
29
+ steps.push({
30
+ id,
31
+ index: i,
32
+ changeKey: c.key,
33
+ op: 'delete',
34
+ description: `deleteAiAgent — ${c.label}`,
35
+ destructive: true,
36
+ request: await deleteAiAgent(client, String(c.before?.['uuid'] ?? '')),
37
+ status: 'pending',
38
+ });
39
+ }
40
+ }
41
+ return { steps };
42
+ };