@@ -5,23 +5,28 @@ export function promptWithWorkflowContext(prompt: string, context: WorkflowAgent
55 return prompt ;
66 }
77 return [
8+ "Humanize2 workflow agent instructions:" ,
9+ "- You are running as a Humanize2-managed agent." ,
10+ "- Read the workflow context block after the task before acting." ,
11+ "- vertexId is the workflow node identity for artifact ownership and routing;" ,
12+ "- shortName is the human-facing agent/session alias and should not replace vertexId in workflow state." ,
13+ "Deliver expected artifacts back to Humanize2 through the listed MCP tools or JSON-RPC endpoint." ,
14+ "Do not inspect, signal, attach to, or mutate the Humanize2 hub process or its in-memory runtime state." ,
15+ "Do not repair workflow state directly; use Humanize2 artifact, board, event, message, or view APIs." ,
16+ "" ,
17+ "Task:" ,
18+ prompt ,
19+ "" ,
820 "Humanize2 workflow context:" ,
921 `- workflowRunId: ${ context . workflowRunId } ` ,
1022 `- vertexId: ${ context . vertexId } ` ,
1123 `- shortName: ${ context . shortName } ` ,
12- "- vertexId is the workflow node identity for artifact ownership and routing;" ,
13- "- shortName is the human-facing agent/session alias and should not replace vertexId in workflow state." ,
1424 `- jsonRpcUrl: ${ context . jsonRpcUrl } ` ,
15- `- expectedArtifacts: ${ JSON . stringify ( context . expectedArtifacts ) } ` ,
16- `- inputs: ${ JSON . stringify ( context . inputs ?? [ ] ) } ` ,
25+ `- expectedArtifacts: ${ stableJson ( context . expectedArtifacts ) } ` ,
26+ `- inputs: ${ stableJson ( context . inputs ?? [ ] ) } ` ,
1727 `- mcpToolNames: ${ context . mcpToolNames . join ( ", " ) } ` ,
1828 "" ,
19- ...inputSnapshotSection ( context ) ,
20- "Deliver expected artifacts back to Humanize2 through the listed MCP tools or JSON-RPC endpoint." ,
21- "Do not inspect, signal, attach to, or mutate the Humanize2 hub process or its in-memory runtime state." ,
22- "Do not repair workflow state directly; use Humanize2 artifact, board, event, message, or view APIs." ,
23- "" ,
24- prompt
29+ ...inputSnapshotSection ( context )
2530 ] . join ( "\n" ) ;
2631}
2732
@@ -38,8 +43,8 @@ export function environmentWithWorkflowContext(
3843 HUMANIZE2_WORKFLOW_VERTEX_ID : context . vertexId ,
3944 HUMANIZE2_WORKFLOW_SHORT_NAME : context . shortName ,
4045 HUMANIZE2_WORKFLOW_JSONRPC_URL : context . jsonRpcUrl ,
41- HUMANIZE2_WORKFLOW_EXPECTED_ARTIFACTS : JSON . stringify ( context . expectedArtifacts ) ,
42- HUMANIZE2_WORKFLOW_INPUTS : JSON . stringify ( context . inputs ?? [ ] ) ,
46+ HUMANIZE2_WORKFLOW_EXPECTED_ARTIFACTS : stableJson ( context . expectedArtifacts ) ,
47+ HUMANIZE2_WORKFLOW_INPUTS : stableJson ( context . inputs ?? [ ] ) ,
4348 HUMANIZE2_WORKFLOW_MCP_TOOLS : context . mcpToolNames . join ( "," )
4449 } ;
4550}
@@ -50,8 +55,26 @@ function inputSnapshotSection(context: WorkflowAgentLaunchContext): string[] {
5055 }
5156 return [
5257 "Declared workflow input snapshots:" ,
53- JSON . stringify ( context . inputs , null , 2 ) ,
58+ stableJson ( context . inputs , 2 ) ,
5459 "Treat these input snapshots as part of the current task contract." ,
5560 ""
5661 ] ;
5762}
63+
64+ function stableJson ( value : unknown , space ?: number ) : string {
65+ return JSON . stringify ( stableJsonValue ( value ) , null , space ) ;
66+ }
67+
68+ function stableJsonValue ( value : unknown ) : unknown {
69+ if ( Array . isArray ( value ) ) {
70+ return value . map ( stableJsonValue ) ;
71+ }
72+ if ( value === null || typeof value !== "object" ) {
73+ return value ;
74+ }
75+
76+ const object = value as Record < string , unknown > ;
77+ return Object . fromEntries (
78+ Object . keys ( object ) . sort ( ) . map ( ( key ) => [ key , stableJsonValue ( object [ key ] ) ] )
79+ ) ;
80+ }
0 commit comments