Skip to content

Commit 41cb964

Browse files
committed
Merge branch 'feature/idp-cli-doc-status' into 'develop'
Feat: Extend the new idp-cli status command to check job COMPLETED/FAILURE status See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!401
2 parents 89ad536 + f65672c commit 41cb964

File tree

5 files changed

+332
-25
lines changed

5 files changed

+332
-25
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ SPDX-License-Identifier: MIT-0
1515
- **Persistent Chat Memory**: DynamoDB-backed conversation history with automatic loading of last 20 turns, turn-based message grouping, and intelligent context management with sliding window optimization
1616
- **Real-Time Streaming**: AppSync GraphQL subscriptions enable incremental response streaming with proper async task cleanup and thinking tag removal for clean display
1717
- **Code Intelligence Agent**: New specialized agent for code-related assistance with DeepWiki MCP server integration, security guardrails to prevent sensitive data exposure, and user-controlled opt-in toggle (default: enabled)
18-
- **Sub-Agent Streaming**: Real-time lifecycle events (start, stream, end, error) with async generator tools, structured data detection for tables/charts, and tool usage tracking
1918
- **Rich Chat Interface**: Modern UI with CloudScape Design System featuring real-time message streaming, multi-agent support (Analytics, Code Intelligence, Error Analyzer, General), Markdown rendering with syntax highlighting, structured data visualization (charts via Chart.js, sortable tables), expandable tool usage sections, sample prompts, and auto-scroll behavior
2019
- **Privacy & Security**: Explicit user consent for Code Intelligence third-party services, session isolation with unique session IDs, error boundary protection, input validation
2120

@@ -29,6 +28,20 @@ SPDX-License-Identifier: MIT-0
2928
- **Backward Compatible**: Legacy format remains supported through automatic migration - no manual configuration updates required
3029
- **Comprehensive Documentation**: New migration guide with format comparison, field mapping table, and best practices
3130

31+
- **IDP CLI Single Document Status Support with Programmatic Output**
32+
- Enhanced `status` command to support checking individual document status via new `--document-id` option as alternative to `--batch-id`
33+
- Added programmatic output capabilities with exit codes (0=success, 1=failure, 2=processing) for scripting and automation
34+
- JSON format output (`--format json`) provides structured data for parsing in CI/CD pipelines and scripts
35+
- Live monitoring support with `--wait` flag works for both batch and single document status checks
36+
- Mutual exclusion validation ensures only one of `--batch-id` or `--document-id` is specified
37+
- **Error Analyzer CloudWatch Tool Enhancements**
38+
- Enhanced CloudWatch log filtering with request ID-based filtering for more targeted error analysis
39+
- Improved XRay tool tracing and logging capabilities for better diagnostic accuracy
40+
- Enhanced error context correlation between CloudWatch logs and X-Ray traces
41+
- Consolidated and renamed tools
42+
- Provided tools access to agent
43+
- Updated system prompt
44+
3245
- **Error Analyzer CloudWatch Tool Enhancements**
3346
- Enhanced CloudWatch log filtering with request ID-based filtering for more targeted error analysis
3447
- Improved XRay tool tracing and logging capabilities for better diagnostic accuracy

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.0-rc6
1+
0.4.0-rc7

docs/idp-cli.md

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,27 +356,113 @@ https://github.com/user-attachments/assets/28deadbb-378b-42b7-a5e2-f929af9b0e41
356356

357357
### `status`
358358

359-
Check batch processing status.
359+
Check status of a batch or single document.
360360

361361
**Usage:**
362362
```bash
363363
idp-cli status [OPTIONS]
364364
```
365365

366+
**Document Source (choose ONE):**
367+
- `--batch-id`: Batch identifier (check all documents in batch)
368+
- `--document-id`: Single document ID (check individual document)
369+
366370
**Options:**
367371
- `--stack-name` (required): CloudFormation stack name
368-
- `--batch-id` (required): Batch identifier
369372
- `--wait`: Wait for all documents to complete
370373
- `--refresh-interval`: Seconds between status checks (default: 5)
374+
- `--format`: Output format - `table` (default) or `json`
371375
- `--region`: AWS region (optional)
372376

373-
**Example:**
377+
**Examples:**
374378

375379
```bash
380+
# Check batch status
376381
idp-cli status \
377382
--stack-name my-stack \
378-
--batch-id cli-batch-20251015-143000 \
383+
--batch-id cli-batch-20251015-143000
384+
385+
# Check single document status
386+
idp-cli status \
387+
--stack-name my-stack \
388+
--document-id batch-123/invoice.pdf
389+
390+
# Monitor single document until completion
391+
idp-cli status \
392+
--stack-name my-stack \
393+
--document-id batch-123/invoice.pdf \
379394
--wait
395+
396+
# Get JSON output for scripting
397+
idp-cli status \
398+
--stack-name my-stack \
399+
--document-id batch-123/invoice.pdf \
400+
--format json
401+
```
402+
403+
**Programmatic Use:**
404+
405+
The command returns exit codes for scripting:
406+
- `0` - Document(s) completed successfully
407+
- `1` - Document(s) failed
408+
- `2` - Document(s) still processing
409+
410+
**JSON Output Format:**
411+
412+
```bash
413+
# Single document
414+
$ idp-cli status --stack-name my-stack --document-id batch-123/invoice.pdf --format json
415+
{
416+
"document_id": "batch-123/invoice.pdf",
417+
"status": "COMPLETED",
418+
"duration": 125.4,
419+
"start_time": "2025-01-01T10:30:45Z",
420+
"end_time": "2025-01-01T10:32:50Z",
421+
"num_sections": 2,
422+
"exit_code": 0
423+
}
424+
425+
# Table output includes final status summary
426+
$ idp-cli status --stack-name my-stack --document-id batch-123/invoice.pdf
427+
[status table]
428+
429+
FINAL STATUS: COMPLETED | Duration: 125.4s | Exit Code: 0
430+
```
431+
432+
**Scripting Examples:**
433+
434+
```bash
435+
#!/bin/bash
436+
# Wait for document completion and check result
437+
idp-cli status --stack-name prod --document-id batch-001/invoice.pdf --wait
438+
exit_code=$?
439+
440+
if [ $exit_code -eq 0 ]; then
441+
echo "Document processed successfully"
442+
# Proceed with downstream processing
443+
else
444+
echo "Document processing failed"
445+
exit 1
446+
fi
447+
```
448+
449+
```bash
450+
#!/bin/bash
451+
# Poll document status in script
452+
while true; do
453+
status=$(idp-cli status --stack-name prod --document-id batch-001/invoice.pdf --format json)
454+
state=$(echo "$status" | jq -r '.status')
455+
456+
if [ "$state" = "COMPLETED" ]; then
457+
echo "Processing complete!"
458+
break
459+
elif [ "$state" = "FAILED" ]; then
460+
echo "Processing failed!"
461+
exit 1
462+
fi
463+
464+
sleep 5
465+
done
380466
```
381467

382468
---

idp_cli/idp_cli/cli.py

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -804,49 +804,96 @@ def run_inference(
804804

805805
@cli.command()
806806
@click.option("--stack-name", required=True, help="CloudFormation stack name")
807-
@click.option("--batch-id", required=True, help="Batch identifier")
807+
@click.option("--batch-id", help="Batch identifier")
808+
@click.option("--document-id", help="Single document ID (alternative to --batch-id)")
808809
@click.option("--wait", is_flag=True, help="Wait for all documents to complete")
809810
@click.option(
810811
"--refresh-interval",
811812
default=5,
812813
type=int,
813814
help="Seconds between status checks (default: 5)",
814815
)
816+
@click.option(
817+
"--format",
818+
"output_format",
819+
type=click.Choice(["table", "json"]),
820+
default="table",
821+
help="Output format: table (default) or json",
822+
)
815823
@click.option("--region", help="AWS region (optional)")
816824
def status(
817825
stack_name: str,
818-
batch_id: str,
826+
batch_id: Optional[str],
827+
document_id: Optional[str],
819828
wait: bool,
820829
refresh_interval: int,
830+
output_format: str,
821831
region: Optional[str],
822832
):
823833
"""
824-
Check status of a batch processing job
834+
Check status of a batch or single document
835+
836+
Specify ONE of:
837+
--batch-id: Check status of all documents in a batch
838+
--document-id: Check status of a single document
825839
826840
Examples:
827841
828-
# Check current status once
842+
# Check batch status
829843
idp-cli status --stack-name my-stack --batch-id cli-batch-20250110-153045-abc12345
830844
831-
# Monitor until completion
832-
idp-cli status --stack-name my-stack --batch-id cli-batch-20250110-153045-abc12345 --wait
845+
# Check single document status
846+
idp-cli status --stack-name my-stack --document-id batch-123/invoice.pdf
847+
848+
# Monitor single document until completion
849+
idp-cli status --stack-name my-stack --document-id batch-123/invoice.pdf --wait
850+
851+
# Get JSON output for scripting
852+
idp-cli status --stack-name my-stack --document-id batch-123/invoice.pdf --format json
833853
"""
834854
try:
835-
# Get batch info
836-
processor = BatchProcessor(stack_name=stack_name, region=region)
837-
batch_info = processor.get_batch_info(batch_id)
855+
# Validate mutually exclusive options
856+
if not batch_id and not document_id:
857+
console.print(
858+
"[red]✗ Error: Must specify either --batch-id or --document-id[/red]"
859+
)
860+
sys.exit(1)
838861

839-
if not batch_info:
840-
console.print(f"[red]✗ Batch not found: {batch_id}[/red]")
862+
if batch_id and document_id:
863+
console.print(
864+
"[red]✗ Error: Cannot specify both --batch-id and --document-id[/red]"
865+
)
841866
sys.exit(1)
842867

843-
document_ids = batch_info["document_ids"]
868+
# Initialize processor to get resources
869+
processor = BatchProcessor(stack_name=stack_name, region=region)
870+
871+
# Get document IDs to monitor
872+
if batch_id:
873+
# Get batch info
874+
batch_info = processor.get_batch_info(batch_id)
875+
if not batch_info:
876+
console.print(f"[red]✗ Batch not found: {batch_id}[/red]")
877+
sys.exit(1)
878+
document_ids = batch_info["document_ids"]
879+
identifier = batch_id
880+
else:
881+
# Single document
882+
document_ids = [document_id]
883+
identifier = document_id
844884

845885
if wait:
886+
# JSON format not compatible with live monitoring
887+
if output_format == "json":
888+
console.print(
889+
"[yellow]Warning: --format json ignored with --wait (using table display for live monitoring)[/yellow]"
890+
)
891+
console.print()
892+
846893
# Monitor until completion
847894
_monitor_progress(
848895
stack_name=stack_name,
849-
batch_id=batch_id,
896+
batch_id=identifier,
850897
document_ids=document_ids,
851898
refresh_interval=refresh_interval,
852899
region=region,
@@ -860,13 +907,32 @@ def status(
860907
status_data = monitor.get_batch_status(document_ids)
861908
stats = monitor.calculate_statistics(status_data)
862909

863-
console.print()
864-
console.print(f"[bold blue]Batch: {batch_id}[/bold blue]")
865-
display.display_status_table(status_data)
910+
if output_format == "json":
911+
# JSON output for programmatic use
912+
json_output = display.format_status_json(status_data, stats)
913+
console.print(json_output)
866914

867-
# Show statistics
868-
console.print(display.create_statistics_panel(stats))
869-
console.print()
915+
# Determine exit code from JSON
916+
import json as json_module
917+
918+
result = json_module.loads(json_output)
919+
sys.exit(result.get("exit_code", 2))
920+
else:
921+
# Table output for human viewing
922+
console.print()
923+
if batch_id:
924+
console.print(f"[bold blue]Batch: {batch_id}[/bold blue]")
925+
else:
926+
console.print(f"[bold blue]Document: {document_id}[/bold blue]")
927+
928+
display.display_status_table(status_data)
929+
930+
# Show statistics
931+
console.print(display.create_statistics_panel(stats))
932+
933+
# Show final status summary and exit with appropriate code
934+
exit_code = display.show_final_status_summary(status_data, stats)
935+
sys.exit(exit_code)
870936

871937
except Exception as e:
872938
logger.error(f"Error checking status: {e}", exc_info=True)

0 commit comments

Comments
 (0)