Watch a directory for file changes and automatically update the code graph. This command runs in the foreground and monitors the specified directory for any file changes. When changes are detected, the code graph is automatically updated. The watcher will: - Perfor
(
path: str = typer.Argument(".", help="Path to the directory to watch. Defaults to current directory."),
context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"),
poll: bool = typer.Option(
False,
"--poll",
help="Use watchdog's polling observer for Docker bind mounts and network filesystems.",
),
sync_on_start: bool = typer.Option(
False,
"--sync-on-start",
help=(
"Synchronize already-indexed files before watching. "
"Defaults off; use 'cgc index --force' for a full re-index."
),
),
)
| 1593 | |
| 1594 | @app.command() |
| 1595 | def watch( |
| 1596 | path: str = typer.Argument(".", help="Path to the directory to watch. Defaults to current directory."), |
| 1597 | context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"), |
| 1598 | poll: bool = typer.Option( |
| 1599 | False, |
| 1600 | "--poll", |
| 1601 | help="Use watchdog's polling observer for Docker bind mounts and network filesystems.", |
| 1602 | ), |
| 1603 | sync_on_start: bool = typer.Option( |
| 1604 | False, |
| 1605 | "--sync-on-start", |
| 1606 | help=( |
| 1607 | "Synchronize already-indexed files before watching. " |
| 1608 | "Defaults off; use 'cgc index --force' for a full re-index." |
| 1609 | ), |
| 1610 | ), |
| 1611 | ): |
| 1612 | """ |
| 1613 | Watch a directory for file changes and automatically update the code graph. |
| 1614 | |
| 1615 | This command runs in the foreground and monitors the specified directory |
| 1616 | for any file changes. When changes are detected, the code graph is |
| 1617 | automatically updated. |
| 1618 | |
| 1619 | The watcher will: |
| 1620 | - Perform an initial scan if the directory is not yet indexed |
| 1621 | - Attach immediately for already-indexed directories unless --sync-on-start is passed |
| 1622 | - Monitor for file creation, modification, deletion, and moves |
| 1623 | - Automatically re-index affected files and update relationships |
| 1624 | |
| 1625 | Press Ctrl+C to stop watching. |
| 1626 | |
| 1627 | Examples: |
| 1628 | cgc watch . # Watch current directory |
| 1629 | cgc watch /path/to/project # Watch specific directory |
| 1630 | cgc watch --poll . # Use polling for Docker/NFS/SMB mounts |
| 1631 | cgc watch --sync-on-start . # Reconcile current files before watching |
| 1632 | cgc w . # Using shortcut alias |
| 1633 | |
| 1634 | Set CGC_WATCH_POLLING=1 to use polling without passing --poll. |
| 1635 | """ |
| 1636 | _load_credentials() |
| 1637 | watch_helper(path, context, use_polling=poll or None, sync_on_start=sync_on_start) |
| 1638 | |
| 1639 | @app.command() |
| 1640 | def unwatch( |
no test coverage detected