@pixelbyte-software/pixcode 1.42.0 → 1.42.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.
@@ -0,0 +1,186 @@
1
+ import type { ResolvedWorkspaceTarget } from '@/modules/orchestration/workflows/workspace-target.js';
2
+
3
+ export const PIXCODE_CONTEXT_PROTOCOL = 'pixcode.context.v1' as const;
4
+ export const MAX_CONTEXT_PACKET_TEXT_CHARS = 16_000;
5
+
6
+ export interface WorkflowContextPacket {
7
+ protocol: typeof PIXCODE_CONTEXT_PROTOCOL;
8
+ originalUserRequest: string;
9
+ project: {
10
+ kind: string;
11
+ label: string;
12
+ selectedProjectName?: string;
13
+ };
14
+ task: {
15
+ workflowId: string;
16
+ workflowRunId: string;
17
+ nodeId: string;
18
+ stage?: string;
19
+ assignment?: string;
20
+ stepInstructions: string;
21
+ };
22
+ constraints: {
23
+ adapterId?: string;
24
+ agentLabel?: string;
25
+ model?: string;
26
+ permissionMode?: string;
27
+ isolation?: string;
28
+ toolsSettings?: Record<string, unknown>;
29
+ };
30
+ upstreamArtifacts: Array<{
31
+ type: 'upstream-context';
32
+ text: string;
33
+ sourceNodeIds: string[];
34
+ }>;
35
+ runState: {
36
+ status: string;
37
+ startedAt: number;
38
+ nodeCount: number;
39
+ completedNodeIds: string[];
40
+ runningNodeIds: string[];
41
+ };
42
+ compaction: {
43
+ maxChars: number;
44
+ originalChars: number;
45
+ compactedChars: number;
46
+ omittedChars: number;
47
+ wasCompacted: boolean;
48
+ };
49
+ createdAt: string;
50
+ }
51
+
52
+ type ContextPacketRun = {
53
+ id: string;
54
+ workflowId: string;
55
+ status: string;
56
+ input?: string;
57
+ startedAt: number;
58
+ nodeRuns: Array<{
59
+ nodeId: string;
60
+ status: string;
61
+ }>;
62
+ };
63
+
64
+ type ContextPacketNode = {
65
+ id: string;
66
+ adapterId?: string;
67
+ agentLabel?: string;
68
+ assignment?: string;
69
+ prompt: string;
70
+ stage?: string;
71
+ model?: string;
72
+ permissionMode?: string;
73
+ toolsSettings?: Record<string, unknown>;
74
+ isolation?: string;
75
+ };
76
+
77
+ export type BuildWorkflowContextPacketInput = {
78
+ run: ContextPacketRun;
79
+ node: ContextPacketNode;
80
+ workspaceTarget: ResolvedWorkspaceTarget;
81
+ inputContext: string;
82
+ inputNodeIds: string[];
83
+ };
84
+
85
+ function compactContextText(text: string): {
86
+ text: string;
87
+ originalChars: number;
88
+ compactedChars: number;
89
+ omittedChars: number;
90
+ wasCompacted: boolean;
91
+ } {
92
+ const originalChars = text.length;
93
+ if (originalChars <= MAX_CONTEXT_PACKET_TEXT_CHARS) {
94
+ return {
95
+ text,
96
+ originalChars,
97
+ compactedChars: originalChars,
98
+ omittedChars: 0,
99
+ wasCompacted: false,
100
+ };
101
+ }
102
+
103
+ const edge = Math.floor(MAX_CONTEXT_PACKET_TEXT_CHARS / 2);
104
+ const omittedChars = originalChars - MAX_CONTEXT_PACKET_TEXT_CHARS;
105
+ const compacted = [
106
+ text.slice(0, edge),
107
+ `\n\n[...${omittedChars} characters omitted from upstream context packet...]\n\n`,
108
+ text.slice(-edge),
109
+ ].join('');
110
+
111
+ return {
112
+ text: compacted,
113
+ originalChars,
114
+ compactedChars: compacted.length,
115
+ omittedChars,
116
+ wasCompacted: true,
117
+ };
118
+ }
119
+
120
+ export function buildWorkflowContextPacket({
121
+ run,
122
+ node,
123
+ workspaceTarget,
124
+ inputContext,
125
+ inputNodeIds,
126
+ }: BuildWorkflowContextPacketInput): WorkflowContextPacket {
127
+ const compacted = compactContextText(inputContext);
128
+ return {
129
+ protocol: PIXCODE_CONTEXT_PROTOCOL,
130
+ originalUserRequest: run.input?.trim() || '(No original user request was provided.)',
131
+ project: {
132
+ kind: workspaceTarget.kind,
133
+ label: workspaceTarget.label,
134
+ selectedProjectName: workspaceTarget.selectedProjectName,
135
+ },
136
+ task: {
137
+ workflowId: run.workflowId,
138
+ workflowRunId: run.id,
139
+ nodeId: node.id,
140
+ stage: node.stage,
141
+ assignment: node.assignment,
142
+ stepInstructions: node.prompt,
143
+ },
144
+ constraints: {
145
+ adapterId: node.adapterId,
146
+ agentLabel: node.agentLabel,
147
+ model: node.model,
148
+ permissionMode: node.permissionMode,
149
+ isolation: node.isolation,
150
+ toolsSettings: node.toolsSettings,
151
+ },
152
+ upstreamArtifacts: compacted.text
153
+ ? [{
154
+ type: 'upstream-context',
155
+ text: compacted.text,
156
+ sourceNodeIds: inputNodeIds,
157
+ }]
158
+ : [],
159
+ runState: {
160
+ status: run.status,
161
+ startedAt: run.startedAt,
162
+ nodeCount: run.nodeRuns.length,
163
+ completedNodeIds: run.nodeRuns
164
+ .filter((nodeRun) => nodeRun.status === 'completed')
165
+ .map((nodeRun) => nodeRun.nodeId),
166
+ runningNodeIds: run.nodeRuns
167
+ .filter((nodeRun) => nodeRun.status === 'running')
168
+ .map((nodeRun) => nodeRun.nodeId),
169
+ },
170
+ compaction: {
171
+ maxChars: MAX_CONTEXT_PACKET_TEXT_CHARS,
172
+ originalChars: compacted.originalChars,
173
+ compactedChars: compacted.compactedChars,
174
+ omittedChars: compacted.omittedChars,
175
+ wasCompacted: compacted.wasCompacted,
176
+ },
177
+ createdAt: new Date().toISOString(),
178
+ };
179
+ }
180
+
181
+ export function formatContextPacketForPrompt(packet: WorkflowContextPacket): string {
182
+ return [
183
+ `Pixcode standardized init context packet (${PIXCODE_CONTEXT_PROTOCOL}):`,
184
+ JSON.stringify(packet, null, 2),
185
+ ].join('\n');
186
+ }
@@ -12,6 +12,10 @@ import {
12
12
  handoffArtifactToWorkflowArtifact,
13
13
  parseHandoffArtifact,
14
14
  } from '@/modules/orchestration/workflows/handoff-artifact.js';
15
+ import {
16
+ buildWorkflowContextPacket,
17
+ formatContextPacketForPrompt,
18
+ } from '@/modules/orchestration/workflows/context-packet.js';
15
19
  import {
16
20
  type ResolvedWorkspaceTarget,
17
21
  resolveWorkflowWorkspace,
@@ -1561,9 +1565,19 @@ class WorkflowRunner {
1561
1565
 
1562
1566
  const inputContext = node.inputs.map((input) => outputs.get(input)).filter(Boolean).join('\n\n');
1563
1567
  const workspaceTarget = resolveWorkflowWorkspace(run.metadata);
1568
+ const contextPacket = buildWorkflowContextPacket({
1569
+ run,
1570
+ node,
1571
+ workspaceTarget,
1572
+ inputContext,
1573
+ inputNodeIds: node.inputs,
1574
+ });
1575
+ nodeRun.contextPacket = contextPacket;
1576
+ workflowStore.setRun(run);
1564
1577
  const prompt = [
1565
1578
  'Original user request (primary task; answer this directly even if the workspace is empty):',
1566
1579
  run.input?.trim() || '(No original user request was provided.)',
1580
+ formatContextPacketForPrompt(contextPacket),
1567
1581
  inputContext
1568
1582
  ? `Upstream workflow context from prior agents:\n${inputContext}`
1569
1583
  : '',
@@ -176,6 +176,28 @@ export function buildWorkflowTrace(run: WorkflowRun): WorkflowTraceEvent[] {
176
176
  });
177
177
  }
178
178
 
179
+ if (node.contextPacket) {
180
+ pushEvent(events, {
181
+ id: traceId([run.id, node.nodeId, 'context-packet']),
182
+ type: 'message',
183
+ severity: node.contextPacket.compaction.wasCompacted ? 'warning' : 'info',
184
+ status: node.status,
185
+ timestamp: timestamp + 1.5,
186
+ ...base,
187
+ title: 'Context packet prepared',
188
+ titleKey: 'workflow.trace.contextPacket',
189
+ summary: node.contextPacket.compaction.wasCompacted
190
+ ? `Context compacted by ${node.contextPacket.compaction.omittedChars} characters`
191
+ : 'Context packet prepared without compaction',
192
+ metadata: {
193
+ protocol: node.contextPacket.protocol,
194
+ compaction: node.contextPacket.compaction,
195
+ upstreamArtifactCount: node.contextPacket.upstreamArtifacts.length,
196
+ sourceNodeIds: node.contextPacket.upstreamArtifacts.flatMap((artifact) => artifact.sourceNodeIds),
197
+ },
198
+ });
199
+ }
200
+
179
201
  if (node.adapterId || node.model) {
180
202
  pushEvent(events, {
181
203
  id: traceId([run.id, node.nodeId, 'provider']),
@@ -1,3 +1,4 @@
1
+ import type { WorkflowContextPacket } from '@/modules/orchestration/workflows/context-packet.js';
1
2
  import type { WorkflowHandoffArtifact } from '@/modules/orchestration/workflows/handoff-artifact.js';
2
3
 
3
4
  export type WorkflowRunStatus = 'queued' | 'running' | 'completed' | 'failed' | 'canceled';
@@ -49,6 +50,7 @@ export interface WorkflowNodeRun {
49
50
  finishedAt?: number;
50
51
  error?: string;
51
52
  outputText?: string;
53
+ contextPacket?: WorkflowContextPacket;
52
54
  handoffArtifact?: WorkflowHandoffArtifact;
53
55
  messages?: Array<{
54
56
  role: string;