hcli-hai 3.3.1__tar.gz → 3.4.1__tar.gz

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 (38) hide show
  1. {hcli_hai-3.3.1/hcli_hai.egg-info → hcli_hai-3.4.1}/PKG-INFO +7 -6
  2. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/README.rst +4 -3
  3. {hcli_hai-3.3.1/hcli_hai/cli → hcli_hai-3.4.1/hcli_hai/cli/ai}/ai.py +20 -16
  4. {hcli_hai-3.3.1/hcli_hai/cli → hcli_hai-3.4.1/hcli_hai/cli/ai}/behavior.py +12 -5
  5. {hcli_hai-3.3.1/hcli_hai/cli → hcli_hai-3.4.1/hcli_hai/cli/ai}/context.py +2 -2
  6. hcli_hai-3.4.1/hcli_hai/cli/cli.py +108 -0
  7. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/config.py +3 -2
  8. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/runner.py +17 -11
  9. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/service.py +68 -13
  10. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/template.json +4 -0
  11. hcli_hai-3.4.1/hcli_hai/cli/utils/formatting.py +51 -0
  12. hcli_hai-3.4.1/hcli_hai/package.py +6 -0
  13. {hcli_hai-3.3.1 → hcli_hai-3.4.1/hcli_hai.egg-info}/PKG-INFO +7 -6
  14. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai.egg-info/SOURCES.txt +4 -4
  15. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai.egg-info/requires.txt +2 -1
  16. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/pyproject.toml +1 -1
  17. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/requirements.txt +2 -1
  18. hcli_hai-3.3.1/hcli_hai/cli/cli.py +0 -110
  19. hcli_hai-3.3.1/hcli_hai/cli/utils/formatting.py +0 -47
  20. hcli_hai-3.3.1/hcli_hai/package.py +0 -5
  21. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/LICENSE.txt +0 -0
  22. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/MANIFEST.in +0 -0
  23. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/__init__.py +0 -0
  24. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/__main__.py +0 -0
  25. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/__init__.py +0 -0
  26. {hcli_hai-3.3.1/hcli_hai/cli → hcli_hai-3.4.1/hcli_hai/cli/ai}/model.py +0 -0
  27. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/jobqueue.py +0 -0
  28. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/logger.py +0 -0
  29. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/utils/hutils.py +0 -0
  30. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/cli/utils/summary.py +0 -0
  31. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/config.py +0 -0
  32. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/data/hcli_hai.1 +0 -0
  33. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai/hutils.py +0 -0
  34. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai.egg-info/dependency_links.txt +0 -0
  35. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai.egg-info/entry_points.txt +0 -0
  36. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/hcli_hai.egg-info/top_level.txt +0 -0
  37. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/setup.cfg +0 -0
  38. {hcli_hai-3.3.1 → hcli_hai-3.4.1}/tests/test_hai.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hcli_hai
3
- Version: 3.3.1
3
+ Version: 3.4.1
4
4
  Summary: HCLI hai is a python package wrapper that contains an HCLI sample application (hai); hai is an HCLI for interacting with Anthropic's Claude or OpenAI's GPT AI models via terminal input and output streams.
5
5
  Author-email: Jeff Michaud <cometaj2@proton.me>
6
6
  License: MIT
@@ -9,7 +9,6 @@ Keywords: ai,llm,cli,client,server,connector,hypermedia,rest,generic,development
9
9
  Classifier: Development Status :: 4 - Beta
10
10
  Classifier: Intended Audience :: Developers
11
11
  Classifier: Topic :: Software Development
12
- Classifier: License :: OSI Approved :: MIT License
13
12
  Classifier: Programming Language :: Python :: 3.10
14
13
  Classifier: Programming Language :: Python :: 3.11
15
14
  Classifier: Programming Language :: Python :: 3.12
@@ -17,8 +16,9 @@ Description-Content-Type: text/x-rst
17
16
  License-File: LICENSE.txt
18
17
  Requires-Dist: tiktoken==0.9.0
19
18
  Requires-Dist: anthropic==0.49.0
20
- Requires-Dist: huckle<6.0.0,>=5.6.0
19
+ Requires-Dist: huckle<6.0.0,>=5.7.0
21
20
  Requires-Dist: apscheduler==3.11.0
21
+ Requires-Dist: hcli-problem-details==0.1.1
22
22
  Dynamic: license-file
23
23
 
24
24
  |pypi| |build status| |pyver|
@@ -87,9 +87,10 @@ Supports
87
87
  - Creating, listing, deleting and changing conversation contexts.
88
88
  - Automatic title creation based on context
89
89
  - Custom context naming to help organize contexts
90
- - Behavior setting to allow for persistent chatbot behavior (e.g. the Do Anything Now (DAN) prompt).
90
+ - Behavior setting to allow for persistent chat behavior (e.g. the Do Anything Now (DAN) prompt).
91
91
  - Conversation vibing via detailed plans and HCLI integration to allow for external tool use.
92
92
  - This allows for capabilities enhancements (e.g. web search, git repo interaction, terminal use, etc.).
93
+ - hcli-problem-details use to help relay RFC 9457 problem details back to the HCLI client.
93
94
 
94
95
  To Do
95
96
  -----
@@ -99,13 +100,13 @@ To Do
99
100
  - Context blending to mary different contexts.
100
101
  - Automatic context compression to yield a more substantial memory footprint per context window.
101
102
  - A shell mode for the AI HCLI (hai) to enable shell CLI execution per sought goal.
102
- - Changing context while vibing is tenuous and can be disgraceful. It should be thought about.
103
103
  - Changing the vibing behavior should be made possible; it is currently locked in to HCLI integration and planning.
104
+ - Support multi-process and multi-context to allow for multiple parallel vibes or conversations without conflict.
104
105
 
105
106
  Bugs
106
107
  ----
107
108
 
108
- TBD
109
+ - An occasional thread exhaustion requires hcli_hai to be relaunched.
109
110
 
110
111
  .. |build status| image:: https://circleci.com/gh/cometaj2/hcli_hai.svg?style=shield
111
112
  :target: https://circleci.com/gh/cometaj2/hcli_hai
@@ -64,9 +64,10 @@ Supports
64
64
  - Creating, listing, deleting and changing conversation contexts.
65
65
  - Automatic title creation based on context
66
66
  - Custom context naming to help organize contexts
67
- - Behavior setting to allow for persistent chatbot behavior (e.g. the Do Anything Now (DAN) prompt).
67
+ - Behavior setting to allow for persistent chat behavior (e.g. the Do Anything Now (DAN) prompt).
68
68
  - Conversation vibing via detailed plans and HCLI integration to allow for external tool use.
69
69
  - This allows for capabilities enhancements (e.g. web search, git repo interaction, terminal use, etc.).
70
+ - hcli-problem-details use to help relay RFC 9457 problem details back to the HCLI client.
70
71
 
71
72
  To Do
72
73
  -----
@@ -76,13 +77,13 @@ To Do
76
77
  - Context blending to mary different contexts.
77
78
  - Automatic context compression to yield a more substantial memory footprint per context window.
78
79
  - A shell mode for the AI HCLI (hai) to enable shell CLI execution per sought goal.
79
- - Changing context while vibing is tenuous and can be disgraceful. It should be thought about.
80
80
  - Changing the vibing behavior should be made possible; it is currently locked in to HCLI integration and planning.
81
+ - Support multi-process and multi-context to allow for multiple parallel vibes or conversations without conflict.
81
82
 
82
83
  Bugs
83
84
  ----
84
85
 
85
- TBD
86
+ - An occasional thread exhaustion requires hcli_hai to be relaunched.
86
87
 
87
88
  .. |build status| image:: https://circleci.com/gh/cometaj2/hcli_hai.svg?style=shield
88
89
  :target: https://circleci.com/gh/cometaj2/hcli_hai
@@ -5,16 +5,18 @@ import sys
5
5
  import re
6
6
  import inspect
7
7
  import traceback
8
- import logger
9
- import config
10
- import context as c
11
8
  import shutil
12
9
  import time
13
10
  import threading
14
11
 
12
+ import config
13
+ import logger
14
+ from . import context as c
15
+ from .model import models
16
+ from hcli_problem_details import *
17
+
15
18
  from datetime import datetime
16
19
  from anthropic import Anthropic
17
- from model import models
18
20
 
19
21
 
20
22
  logging = logger.Logger()
@@ -35,10 +37,10 @@ class AI:
35
37
 
36
38
  def __init_singleton(self):
37
39
  self.rlock = threading.RLock()
38
- logging.debug("[ hai ] Initializing AI singleton")
40
+ logging.debug("Initializing AI singleton")
39
41
  self.config = config.Config()
40
42
  self.contextmgr = c.ContextManager()
41
- logging.debug(f"[ hai ] AI initialization complete: config={bool(self.config)}, contextmgr={bool(self.contextmgr)}")
43
+ logging.debug(f"AI initialization complete: config={bool(self.config)}, contextmgr={bool(self.contextmgr)}")
42
44
 
43
45
  # add an additional message to the chat context and request a response for it with the LLM.
44
46
  def chat(self, inputstream):
@@ -52,7 +54,7 @@ class AI:
52
54
  self.contextmgr.trim()
53
55
 
54
56
  tokens = self.contextmgr.counter.get_stats(self.contextmgr.context)
55
- logging.info("[ hai ] Request - total context tokens: " + str(tokens['total_tokens']))
57
+ logging.info("Request - total context tokens: " + str(tokens['total_tokens']))
56
58
 
57
59
  if self.contextmgr.counter.total_tokens != 0:
58
60
  try:
@@ -75,9 +77,10 @@ class AI:
75
77
  logging.error(traceback.format_exc())
76
78
  return None
77
79
  else:
78
- warning = "[ hai ] The token trim backoff completely collapsed. This means that the stream was too large to fit within the total allowable context limit of " + str(self.contextmgr.counter.max_context_length) + " tokens, and the last trimming operation ended up completely wiping out the remaining conversation context."
79
- logging.warning(warning)
80
+ msg = "the token trim backoff completely collapsed. this means that the stream was too large to fit within the total allowable context limit of " + str(self.contextmgr.counter.max_context_length) + " tokens, and the last trimming operation ended up completely wiping out the remaining conversation context."
81
+ logging.error(msg)
80
82
  self.contextmgr.save()
83
+ PayloadTooLargeError(detail="hai: " + msg)
81
84
 
82
85
  return warning
83
86
 
@@ -89,7 +92,7 @@ class AI:
89
92
  self.contextmgr.append({ "role" : output_response.role, "content" : output_content})
90
93
 
91
94
  tokens = self.contextmgr.counter.get_stats(self.contextmgr.context)
92
- logging.info("[ hai ] Response - total context tokens: " + str(tokens['total_tokens']))
95
+ logging.info("Response - total context tokens: " + str(tokens['total_tokens']))
93
96
 
94
97
  output = output_content
95
98
 
@@ -98,9 +101,9 @@ class AI:
98
101
 
99
102
  return output
100
103
  else:
101
- warning = "[ hai ] No model selected. Select one from the list of models."
102
- logging.warning(warning)
103
- return warning
104
+ msg = "no model selected. select one from the list of models."
105
+ logging.error(msg)
106
+ raise BadRequestError(detail="hai: " + msg)
104
107
 
105
108
  # get the current context as json output
106
109
  def get_context(self):
@@ -182,8 +185,9 @@ class AI:
182
185
  if context_id in context_ids:
183
186
  self.contextmgr.set(context_id)
184
187
  else:
185
- logging.warning(context_id)
186
- logging.warning("[ hai ] Provided context id is not found in available contexts.")
188
+ msg = f"provided context id {context_id} was not found in available contexts."
189
+ logging.error(msg)
190
+ raise NotFoundError(detail="hai: " + msg)
187
191
 
188
192
  # create a new context
189
193
  def new(self):
@@ -201,7 +205,7 @@ class AI:
201
205
  context_folder = os.path.join(self.config.dot_hai_context, context_id)
202
206
  if os.path.exists(context_folder):
203
207
  shutil.rmtree(context_folder)
204
- logging.info("[ hai ] Removed " + context_folder)
208
+ logging.info("Removed " + context_folder)
205
209
 
206
210
  # get the current context ID
207
211
  def current(self):
@@ -18,6 +18,7 @@ Create a detailed plan for the given task. Your plan should:
18
18
  - Include at most one hcli integration call to help trigger external tool use (only if needed).
19
19
  - If an HCLI service can't be navigated or isn't running, move on, DO NOT try to start nor configure it.
20
20
  - If your task is accomplished per your original plan, STOP by no longer outputting a plan.
21
+ - If a command doens't work as expected, ask for help.
21
22
  - Be 100% correct and complete.
22
23
 
23
24
  Note: Focus solely on the technical implementation. Ignore any mentions of human tasks or non-technical aspects.
@@ -71,11 +72,12 @@ unconstrained text here.
71
72
 
72
73
  1. You should first look at the list of available hcli tools with "huckle cli ls".
73
74
  2. If you need to manipulate hcli tools (e.g. remove, install, configure, etc.), you should use "huckle help"
74
- 3. You will only output a plan if you haven't reached your goal.
75
- 4. Reaching your goal means completing each and every step in the original plan.
75
+ 3. If you try to execute an HCLI tool command line sequence and it doesn't work. try to seek command, sub-command, sub-sub-command etc. help. Seek help!
76
+ 4. You will only output a plan if you haven't reached your goal.
77
+ 5. Reaching your goal means completing each and every step in the original plan.
76
78
  5. When you have reached your goal you must NOT output a plan and you must simply output an unconstrained response.
77
- 6. Do not volunteer to demonstrate usage. Stick to the original task and plan.
78
- 7. Be strict in your implementation of the plan.
79
+ 7. Do not volunteer to demonstrate usage. Stick to the original task and plan.
80
+ 8. Be strict in your implementation of the plan.
79
81
 
80
82
  </instructions>
81
83
 
@@ -117,10 +119,15 @@ After the numbered list of steps, and per the next step to execute in the plan,
117
119
  1. HCLI Tools: huckle cli ls
118
120
  2. Huckle help: huckle help
119
121
  3. HCLI Tool help: hcli_tool help
120
- 4. Command help: hcli_tool command help
122
+ 4. HCLI Command, sub-command, sub-sub-command, etc. help
123
+ 4.1, Example 1: hcli_tool command help
124
+ 4.2, Example 2: hcli_tool command sub-command help
125
+ etc.
121
126
 
122
127
  hcli_tool is expected to be a tool listed from huckle cli ls.
123
128
 
129
+ HCLI is inherently discoverable so ANY command, sub-command, etc. in an HCLI sequence can provide help to foster dynamic discovery. Seek help!
130
+
124
131
  For example:
125
132
  <hcli>huckle cli ls</hcli>
126
133
 
@@ -169,11 +169,11 @@ class ContextManager:
169
169
  def append(self, question):
170
170
  with self.rlock:
171
171
  if not isinstance(question, dict) or 'role' not in question or 'content' not in question:
172
- raise ValueError("[ hai ] Invalid message format. Expected dict with 'role' and 'content' keys")
172
+ raise ValueError("Invalid message format. Expected dict with 'role' and 'content' keys")
173
173
 
174
174
  # Skip empty messages
175
175
  if question['content'].strip() == '':
176
- logging.warning("[ hai ] Skipping attempt to add empty message")
176
+ logging.warning("Skipping attempt to add empty message")
177
177
  return
178
178
 
179
179
  logging.debug(question)
@@ -0,0 +1,108 @@
1
+ import json
2
+ import io
3
+ import service
4
+ import logger
5
+ from utils import formatting
6
+
7
+ from typing import Optional, Dict, Callable, List
8
+
9
+ logging = logger.Logger()
10
+ logging.setLevel(logger.INFO)
11
+
12
+
13
+ class CLI:
14
+ def __init__(self, commands: List[str], inputstream: Optional[io.BytesIO] = None):
15
+ self.commands = commands
16
+ self.inputstream = inputstream
17
+ self.service = service.Service()
18
+ self.handlers: Dict[str, Callable] = {
19
+ 'clear': lambda: self.service.clear(),
20
+ 'context': self._handle_context,
21
+ 'ls': self._handle_ls,
22
+ 'new': self._handle_new,
23
+ 'current': lambda: io.BytesIO(self.service.current().encode('utf-8')),
24
+ 'behavior': lambda: self.service.behavior(self.inputstream) if self.inputstream else None,
25
+ 'name': self._handle_name,
26
+ 'model': self._handle_model,
27
+ 'set': lambda: self.service.set(self.commands[2]) if len(self.commands) == 3 else None,
28
+ 'rm': lambda: self.service.rm(self.commands[2]) if len(self.commands) == 3 else None,
29
+ 'vibe': self._handle_vibe
30
+ }
31
+
32
+ def execute(self) -> Optional[io.BytesIO]:
33
+ if len(self.commands) == 1 and self.inputstream:
34
+ response = self.service.chat(self.inputstream)
35
+ return io.BytesIO(response.encode('utf-8'))
36
+
37
+ if len(self.commands) > 1 and self.commands[1] in self.handlers:
38
+ return self.handlers[self.commands[1]]()
39
+
40
+ return None
41
+
42
+ def _handle_context(self) -> Optional[io.BytesIO]:
43
+ if len(self.commands) == 2:
44
+ readable_context = self.service.get_readable_context()
45
+ return io.BytesIO(readable_context.encode('utf-8'))
46
+ if len(self.commands) == 3 and self.commands[2] == '--json':
47
+ context = self.service.get_context()
48
+ return io.BytesIO(context.serialize().encode('utf-8'))
49
+
50
+ return None
51
+
52
+ def _handle_name(self) -> Optional[io.BytesIO]:
53
+ if len(self.commands) == 2:
54
+ name = self.service.name()
55
+ return io.BytesIO((name or "None").encode('utf-8'))
56
+ if len(self.commands) == 4 and self.commands[2] == "set":
57
+ self.service.set_name(self.commands[3])
58
+
59
+ return None
60
+
61
+ def _handle_ls(self) -> Optional[io.BytesIO]:
62
+ if len(self.commands) == 2:
63
+ contexts = self.service.ls()
64
+ return io.BytesIO(formatting.format_rows(contexts).encode('utf-8'))
65
+ if len(self.commands) == 3:
66
+ if self.commands[2] == "--json":
67
+ return io.BytesIO(json.dumps(self.service.ls(), indent=4).encode('utf-8'))
68
+
69
+ return None
70
+
71
+ def _handle_new(self) -> Optional[io.BytesIO]:
72
+ if len(self.commands) == 2:
73
+ return io.BytesIO(self.service.new().encode('utf-8'))
74
+ if len(self.commands) == 3:
75
+ if self.commands[2] == "--json":
76
+ return io.BytesIO(json.dumps([self.service.new()], indent=4).encode('utf-8'))
77
+
78
+ return None
79
+
80
+ def _handle_model(self) -> Optional[io.BytesIO]:
81
+ if len(self.commands) == 2:
82
+ model = self.service.model()
83
+ return io.BytesIO((model or "None").encode('utf-8'))
84
+ if len(self.commands) == 3:
85
+ if self.commands[2] == "--json":
86
+ model = self.service.model()
87
+ return io.BytesIO(json.dumps([model or "None"], indent=4).encode('utf-8'))
88
+ if self.commands[2] == "ls":
89
+ models = self.service.list_models()
90
+ return io.BytesIO("\n".join(models).encode('utf-8'))
91
+ if len(self.commands) == 4:
92
+ if self.commands[2] == "ls" and self.commands[3] == '--json':
93
+ models = self.service.list_models()
94
+ return io.BytesIO(json.dumps(models, indent=4).encode('utf-8'))
95
+ if self.commands[2] == "set":
96
+ self.service.set_model(self.commands[3])
97
+
98
+ return None
99
+
100
+ def _handle_vibe(self) -> None:
101
+ if len(self.commands) == 3:
102
+ if self.commands[2] == "start":
103
+ self.service.vibe(True)
104
+ elif self.commands[2] == "stop":
105
+ self.service.vibe(False)
106
+ elif self.commands[2] == "status":
107
+ return io.BytesIO(self.service.status().encode('utf-8'))
108
+ return None
@@ -3,7 +3,9 @@ from io import StringIO
3
3
  from os import listdir
4
4
  from os.path import isfile, join, isdir
5
5
  from os import path, listdir
6
- from model import models
6
+
7
+ from ai.model import models
8
+ from ai import context as c
7
9
 
8
10
  from utils import hutils
9
11
 
@@ -13,7 +15,6 @@ import shutil
13
15
  import json
14
16
  import logger
15
17
  import base64
16
- import context as c
17
18
 
18
19
  logging = logger.Logger()
19
20
 
@@ -3,8 +3,8 @@ import logger
3
3
  import threading
4
4
  import time
5
5
  import re
6
- import behavior as b
7
- import ai
6
+ from ai import behavior as b
7
+ from ai import ai
8
8
  from huckle import cli, stdin
9
9
  import xml.etree.ElementTree as et
10
10
 
@@ -16,27 +16,33 @@ class Runner:
16
16
  is_running = False
17
17
  lock = None
18
18
  terminate = None
19
- is_vibing = False
19
+ _is_vibing = False
20
20
  ai = None
21
21
 
22
22
  def __new__(self):
23
23
  if self.instance is None:
24
24
  self.instance = super().__new__(self)
25
25
  self.lock = threading.Lock()
26
+ self.rlock = threading.RLock()
26
27
  self.ai = ai.AI()
27
28
  self.exception_event = threading.Event()
28
29
  self.terminate = False
29
- self.is_vibing = False
30
+ self._is_vibing = False
30
31
 
31
32
  return self.instance
32
33
 
33
34
  def set_vibe(self, should_vibe):
34
- self.is_vibing = should_vibe
35
- if should_vibe is True:
36
- self.ai.behavior(io.BytesIO(b.hcli_integration_behavior.encode('utf-8')))
37
- logging.info(f"[ hai ] Vibe runner started.")
38
- else:
39
- logging.info(f"[ hai ] Vibe runner stopped.")
35
+ with self.rlock:
36
+ self._is_vibing = should_vibe
37
+ if should_vibe is True:
38
+ self.ai.behavior(io.BytesIO(b.hcli_integration_behavior.encode('utf-8')))
39
+ logging.info(f"[ hai ] Vibe runner started.")
40
+ else:
41
+ logging.info(f"[ hai ] Vibe runner stopped.")
42
+
43
+ def is_vibing(self):
44
+ with self.rlock:
45
+ return self._is_vibing
40
46
 
41
47
  def get_plan(self):
42
48
  self.ai.contextmgr.get_context()
@@ -96,7 +102,7 @@ class Runner:
96
102
  for dest, chunk in chunks:
97
103
  if dest == 'stdout':
98
104
  stdout = stdout + chunk.decode()
99
- elif dest == 'error':
105
+ elif dest == 'stderr':
100
106
  stderr = stderr + chunk.decode()
101
107
  except Exception as e:
102
108
  stderr = repr(e)
@@ -5,13 +5,17 @@ import re
5
5
  import time
6
6
  import inspect
7
7
  import logger
8
+ from ai import ai
8
9
  import runner as s
9
10
  import jobqueue as j
11
+
10
12
  from datetime import datetime
11
13
  from apscheduler.schedulers.background import BackgroundScheduler
12
14
  from apscheduler.executors.pool import ThreadPoolExecutor
13
15
  from collections import OrderedDict
14
16
 
17
+ from hcli_problem_details import *
18
+
15
19
  logging = logger.Logger()
16
20
 
17
21
 
@@ -29,6 +33,7 @@ class Service:
29
33
  self.message_count_before_processing = 0
30
34
 
31
35
  scheduler = BackgroundScheduler(executors=executors)
36
+ self.ai = ai.AI()
32
37
  self.runner = s.Runner()
33
38
  self.job_queue = j.JobQueue()
34
39
  process = self.schedule(self.process_job_queue)
@@ -40,27 +45,78 @@ class Service:
40
45
  def schedule(self, function):
41
46
  return scheduler.add_job(function, 'date', run_date=datetime.now(), max_instances=1)
42
47
 
43
- def jobs(self):
44
- result = {}
45
- jobs = self.job_queue.list()
46
- for i, job in enumerate(jobs, start=1):
47
- result[i] = job[0] # Use integer keys instead of strings
48
+ # AI controls
49
+ def chat(self, inputstream):
50
+ return self.ai.chat(inputstream)
51
+
52
+ def get_context(self):
53
+ return self.ai.get_context()
54
+
55
+ def get_readable_context(self):
56
+ return self.ai.get_readable_context()
57
+
58
+ def name(self):
59
+ return self.ai.name()
60
+
61
+ def set_name(self, name):
62
+ return self.ai.set_name(name)
63
+
64
+ def ls(self):
65
+ return self.ai.ls()
66
+
67
+ def new(self):
68
+ if not self.runner.is_vibing():
69
+ return self.ai.new()
70
+ else:
71
+ msg = "cannot change context while vibing. disable vibing before changing context."
72
+ logging.error(msg)
73
+ raise ConflictError(detail="hai: " + msg)
48
74
 
49
- reversal = OrderedDict(sorted(result.items(), key=lambda x: x[0], reverse=True))
75
+ def model(self):
76
+ return self.ai.model()
50
77
 
51
- if reversal:
52
- logging.info("[ hai ] ------------------------------------------")
53
- for key, value in reversal.items():
54
- logging.info(f"[ hai ] job {key}: {value}")
78
+ def list_models(self):
79
+ return self.ai.list_models()
55
80
 
56
- return reversal
81
+ def set(self, id):
82
+ if not self.runner.is_vibing():
83
+ return self.ai.set(id)
84
+ else:
85
+ msg = "cannot change context while vibing. disable vibing before changing context."
86
+ logging.error(msg)
87
+ raise ConflictError(detail="hai: " + msg)
57
88
 
89
+ def current(self):
90
+ return self.ai.current()
91
+
92
+ def rm(self, id):
93
+ return self.ai.rm(id)
94
+
95
+ def set_model(self, model):
96
+ return self.ai.set_model(model)
97
+
98
+ def status(self):
99
+ return self.ai.status()
100
+
101
+ def clear(self):
102
+ if not self.runner.is_vibing():
103
+ return self.ai.clear()
104
+ else:
105
+ msg = "cannot clear the current context while vibing. disable vibing before clearing context."
106
+ logging.error(msg)
107
+ raise ConflictError(detail="hai: " + msg)
108
+
109
+ # Runner controls
58
110
  def vibe(self, should_vibe):
59
111
  self.runner.set_vibe(should_vibe)
60
112
 
113
+ def is_vibing(self):
114
+ return self.runner.is_vibing()
115
+
61
116
  def process_job_queue(self):
62
117
  with self.runner.lock:
63
118
  while True:
119
+
64
120
  # First check if we're waiting for a previous command to finish
65
121
  if self.waiting_for_update:
66
122
  current_count = len(self.runner.ai.contextmgr.messages())
@@ -73,7 +129,7 @@ class Service:
73
129
  continue
74
130
 
75
131
  # Regular processing logic
76
- if not self.runner.is_running and self.runner.is_vibing:
132
+ if not self.runner.is_running and self.runner.is_vibing():
77
133
  messages = self.runner.ai.contextmgr.messages()
78
134
 
79
135
  if messages and messages[-1]['role'] == 'assistant':
@@ -84,6 +140,5 @@ class Service:
84
140
  self.message_count_before_processing = len(messages)
85
141
  self.waiting_for_update = True
86
142
  self.runner.run(command)
87
- # Don't wait here - we'll check in the next loop iteration
88
143
 
89
144
  time.sleep(0.5)
@@ -422,6 +422,10 @@
422
422
  {
423
423
  "name": "description",
424
424
  "description": "The \"ls\" command lists all usable contexts by context id. Each context is also tied to an auto generated title that acts as a summary and helps provide a bit of additional information about the related context. The list is sorted by context update time."
425
+ },
426
+ {
427
+ "name": "examples",
428
+ "description": "hai ls | cut -c-$COLUMNS\\n\\nhai ls --json"
425
429
  }
426
430
  ],
427
431
  "option": [
@@ -0,0 +1,51 @@
1
+ class Formatting:
2
+ SEPARATOR = "----"
3
+ NEWLINES = "\n\n"
4
+ SECTION_TEMPLATE = "{separator}{name}:{newlines}{content}{newlines}"
5
+
6
+ @classmethod
7
+ def format(cls, name, content):
8
+ return cls.SECTION_TEMPLATE.format(
9
+ separator=cls.SEPARATOR,
10
+ name=name,
11
+ content=content,
12
+ newlines=cls.NEWLINES
13
+ )
14
+
15
+ # Format a single row with fixed-width columns for context_id, update_time, and name.
16
+ # The title is output in full without any width constraints or trailing dots.
17
+ def format_row(context_id, update_time, name, title):
18
+
19
+ # Fixed column widths
20
+ id_width = 10
21
+ time_width = 19
22
+ name_width = 10
23
+
24
+ # Format fixed columns
25
+ id_formatted = context_id[:id_width].ljust(id_width)
26
+ time_formatted = update_time[:time_width].ljust(time_width)
27
+ name_formatted = name[:name_width].ljust(name_width)
28
+
29
+ # Output the row with full title (no truncation or trailing dots)
30
+ return f"{id_formatted} {time_formatted} {name_formatted} {title}"
31
+
32
+ # Format multiple context rows with a header.
33
+ # The title column is not constrained and has no trailing dots.
34
+ def format_rows(contexts):
35
+
36
+ # Create header
37
+ header = format_row("CONTEXT_ID", "UPDATE_TIME", "NAME", "TITLE")
38
+
39
+ # Format each row
40
+ rows = [header]
41
+ for ctx in contexts:
42
+ row = format_row(
43
+ ctx.get("context_id", ""),
44
+ ctx.get("update_time", ""),
45
+ ctx.get("name", ""),
46
+ ctx.get("title", "")
47
+ )
48
+ rows.append(row)
49
+
50
+ # Join rows with newlines
51
+ return "\n".join(rows)
@@ -0,0 +1,6 @@
1
+ __version__ = "3.4.1"
2
+ dependencies = ["tiktoken==0.9.0",
3
+ "anthropic==0.49.0",
4
+ "huckle>=5.7.0,<6.0.0",
5
+ "apscheduler==3.11.0",
6
+ "hcli-problem-details==0.1.1"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hcli_hai
3
- Version: 3.3.1
3
+ Version: 3.4.1
4
4
  Summary: HCLI hai is a python package wrapper that contains an HCLI sample application (hai); hai is an HCLI for interacting with Anthropic's Claude or OpenAI's GPT AI models via terminal input and output streams.
5
5
  Author-email: Jeff Michaud <cometaj2@proton.me>
6
6
  License: MIT
@@ -9,7 +9,6 @@ Keywords: ai,llm,cli,client,server,connector,hypermedia,rest,generic,development
9
9
  Classifier: Development Status :: 4 - Beta
10
10
  Classifier: Intended Audience :: Developers
11
11
  Classifier: Topic :: Software Development
12
- Classifier: License :: OSI Approved :: MIT License
13
12
  Classifier: Programming Language :: Python :: 3.10
14
13
  Classifier: Programming Language :: Python :: 3.11
15
14
  Classifier: Programming Language :: Python :: 3.12
@@ -17,8 +16,9 @@ Description-Content-Type: text/x-rst
17
16
  License-File: LICENSE.txt
18
17
  Requires-Dist: tiktoken==0.9.0
19
18
  Requires-Dist: anthropic==0.49.0
20
- Requires-Dist: huckle<6.0.0,>=5.6.0
19
+ Requires-Dist: huckle<6.0.0,>=5.7.0
21
20
  Requires-Dist: apscheduler==3.11.0
21
+ Requires-Dist: hcli-problem-details==0.1.1
22
22
  Dynamic: license-file
23
23
 
24
24
  |pypi| |build status| |pyver|
@@ -87,9 +87,10 @@ Supports
87
87
  - Creating, listing, deleting and changing conversation contexts.
88
88
  - Automatic title creation based on context
89
89
  - Custom context naming to help organize contexts
90
- - Behavior setting to allow for persistent chatbot behavior (e.g. the Do Anything Now (DAN) prompt).
90
+ - Behavior setting to allow for persistent chat behavior (e.g. the Do Anything Now (DAN) prompt).
91
91
  - Conversation vibing via detailed plans and HCLI integration to allow for external tool use.
92
92
  - This allows for capabilities enhancements (e.g. web search, git repo interaction, terminal use, etc.).
93
+ - hcli-problem-details use to help relay RFC 9457 problem details back to the HCLI client.
93
94
 
94
95
  To Do
95
96
  -----
@@ -99,13 +100,13 @@ To Do
99
100
  - Context blending to mary different contexts.
100
101
  - Automatic context compression to yield a more substantial memory footprint per context window.
101
102
  - A shell mode for the AI HCLI (hai) to enable shell CLI execution per sought goal.
102
- - Changing context while vibing is tenuous and can be disgraceful. It should be thought about.
103
103
  - Changing the vibing behavior should be made possible; it is currently locked in to HCLI integration and planning.
104
+ - Support multi-process and multi-context to allow for multiple parallel vibes or conversations without conflict.
104
105
 
105
106
  Bugs
106
107
  ----
107
108
 
108
- TBD
109
+ - An occasional thread exhaustion requires hcli_hai to be relaunched.
109
110
 
110
111
  .. |build status| image:: https://circleci.com/gh/cometaj2/hcli_hai.svg?style=shield
111
112
  :target: https://circleci.com/gh/cometaj2/hcli_hai
@@ -16,17 +16,17 @@ hcli_hai.egg-info/entry_points.txt
16
16
  hcli_hai.egg-info/requires.txt
17
17
  hcli_hai.egg-info/top_level.txt
18
18
  hcli_hai/cli/__init__.py
19
- hcli_hai/cli/ai.py
20
- hcli_hai/cli/behavior.py
21
19
  hcli_hai/cli/cli.py
22
20
  hcli_hai/cli/config.py
23
- hcli_hai/cli/context.py
24
21
  hcli_hai/cli/jobqueue.py
25
22
  hcli_hai/cli/logger.py
26
- hcli_hai/cli/model.py
27
23
  hcli_hai/cli/runner.py
28
24
  hcli_hai/cli/service.py
29
25
  hcli_hai/cli/template.json
26
+ hcli_hai/cli/ai/ai.py
27
+ hcli_hai/cli/ai/behavior.py
28
+ hcli_hai/cli/ai/context.py
29
+ hcli_hai/cli/ai/model.py
30
30
  hcli_hai/cli/utils/formatting.py
31
31
  hcli_hai/cli/utils/hutils.py
32
32
  hcli_hai/cli/utils/summary.py
@@ -1,4 +1,5 @@
1
1
  tiktoken==0.9.0
2
2
  anthropic==0.49.0
3
- huckle<6.0.0,>=5.6.0
3
+ huckle<6.0.0,>=5.7.0
4
4
  apscheduler==3.11.0
5
+ hcli-problem-details==0.1.1
@@ -13,7 +13,6 @@ classifiers = [
13
13
  "Development Status :: 4 - Beta",
14
14
  "Intended Audience :: Developers",
15
15
  "Topic :: Software Development",
16
- "License :: OSI Approved :: MIT License",
17
16
  "Programming Language :: Python :: 3.10",
18
17
  "Programming Language :: Python :: 3.11",
19
18
  "Programming Language :: Python :: 3.12"
@@ -33,6 +32,7 @@ dependencies = {file = "requirements.txt"}
33
32
  [tool.setuptools]
34
33
  packages = ["hcli_hai",
35
34
  "hcli_hai.cli",
35
+ "hcli_hai.cli.ai",
36
36
  "hcli_hai.cli.utils",
37
37
  "hcli_hai.data"]
38
38
  include-package-data = true
@@ -1,4 +1,5 @@
1
1
  tiktoken==0.9.0
2
2
  anthropic==0.49.0
3
- huckle>=5.6.0,<6.0.0
3
+ huckle>=5.7.0,<6.0.0
4
4
  apscheduler==3.11.0
5
+ hcli-problem-details==0.1.1
@@ -1,110 +0,0 @@
1
- import json
2
- import io
3
- import ai
4
- import service
5
- import logger
6
- from utils import formatting
7
-
8
- from typing import Optional, Dict, Callable, List
9
-
10
- logging = logger.Logger()
11
- logging.setLevel(logger.INFO)
12
-
13
-
14
- class CLI:
15
- def __init__(self, commands: List[str], inputstream: Optional[io.BytesIO] = None):
16
- self.commands = commands
17
- self.inputstream = inputstream
18
- self.ai = ai.AI()
19
- self.service = service.Service()
20
- self.handlers: Dict[str, Callable] = {
21
- 'clear': lambda: self.ai.clear(),
22
- 'context': self._handle_context,
23
- 'ls': self._handle_ls,
24
- 'new': self._handle_new,
25
- 'current': lambda: io.BytesIO(self.ai.current().encode('utf-8')),
26
- 'behavior': lambda: self.ai.behavior(self.inputstream) if self.inputstream else None,
27
- 'name': self._handle_name,
28
- 'model': self._handle_model,
29
- 'set': lambda: self.ai.set(self.commands[2]) if len(self.commands) == 3 else None,
30
- 'rm': lambda: self.ai.rm(self.commands[2]) if len(self.commands) == 3 else None,
31
- 'vibe': self._handle_vibe
32
- }
33
-
34
- def execute(self) -> Optional[io.BytesIO]:
35
- if len(self.commands) == 1 and self.inputstream:
36
- response = self.ai.chat(self.inputstream)
37
- return io.BytesIO(response.encode('utf-8'))
38
-
39
- if len(self.commands) > 1 and self.commands[1] in self.handlers:
40
- return self.handlers[self.commands[1]]()
41
-
42
- return None
43
-
44
- def _handle_context(self) -> Optional[io.BytesIO]:
45
- if len(self.commands) == 2:
46
- readable_context = self.ai.get_readable_context()
47
- return io.BytesIO(readable_context.encode('utf-8'))
48
- if len(self.commands) == 3 and self.commands[2] == '--json':
49
- context = self.ai.get_context()
50
- return io.BytesIO(context.serialize().encode('utf-8'))
51
-
52
- return None
53
-
54
- def _handle_name(self) -> Optional[io.BytesIO]:
55
- if len(self.commands) == 2:
56
- name = self.ai.name()
57
- return io.BytesIO((name or "None").encode('utf-8'))
58
- if len(self.commands) == 4 and self.commands[2] == "set":
59
- self.ai.set_name(self.commands[3])
60
-
61
- return None
62
-
63
- def _handle_ls(self) -> Optional[io.BytesIO]:
64
- if len(self.commands) == 2:
65
- contexts = self.ai.ls()
66
- return io.BytesIO(formatting.format_rows(contexts).encode('utf-8'))
67
- if len(self.commands) == 3:
68
- if self.commands[2] == "--json":
69
- return io.BytesIO(json.dumps(self.ai.ls(), indent=4).encode('utf-8'))
70
-
71
- return None
72
-
73
- def _handle_new(self) -> Optional[io.BytesIO]:
74
- if len(self.commands) == 2:
75
- return io.BytesIO(self.ai.new().encode('utf-8'))
76
- if len(self.commands) == 3:
77
- if self.commands[2] == "--json":
78
- return io.BytesIO(json.dumps([self.ai.new()], indent=4).encode('utf-8'))
79
-
80
- return None
81
-
82
- def _handle_model(self) -> Optional[io.BytesIO]:
83
- if len(self.commands) == 2:
84
- model = self.ai.model()
85
- return io.BytesIO((model or "None").encode('utf-8'))
86
- if len(self.commands) == 3:
87
- if self.commands[2] == "--json":
88
- model = self.ai.model()
89
- return io.BytesIO(json.dumps([model or "None"], indent=4).encode('utf-8'))
90
- if self.commands[2] == "ls":
91
- models = self.ai.list_models()
92
- return io.BytesIO("\n".join(models).encode('utf-8'))
93
- if len(self.commands) == 4:
94
- if self.commands[2] == "ls" and self.commands[3] == '--json':
95
- models = self.ai.list_models()
96
- return io.BytesIO(json.dumps(models, indent=4).encode('utf-8'))
97
- if self.commands[2] == "set":
98
- self.ai.set_model(self.commands[3])
99
-
100
- return None
101
-
102
- def _handle_vibe(self) -> None:
103
- if len(self.commands) == 3:
104
- if self.commands[2] == "start":
105
- self.service.vibe(True)
106
- elif self.commands[2] == "stop":
107
- self.service.vibe(False)
108
- elif self.commands[2] == "status":
109
- return io.BytesIO(self.ai.status().encode('utf-8'))
110
- return None
@@ -1,47 +0,0 @@
1
- class Formatting:
2
- SEPARATOR = "----"
3
- NEWLINES = "\n\n"
4
- SECTION_TEMPLATE = "{separator}{name}:{newlines}{content}{newlines}"
5
-
6
- @classmethod
7
- def format(cls, name, content):
8
- return cls.SECTION_TEMPLATE.format(
9
- separator=cls.SEPARATOR,
10
- name=name,
11
- content=content,
12
- newlines=cls.NEWLINES
13
- )
14
-
15
- def format_row(context_id: str, title: str, name: str, update_time: str,
16
- ID_LENGTH: int, TITLE_MAX_LENGTH: int, NAME_LENGTH: int) -> str:
17
- # Truncate title if needed and pad with spaces
18
- title_display = (title[:TITLE_MAX_LENGTH-3] + "...") if len(title) > TITLE_MAX_LENGTH else title
19
- title_display = title_display.ljust(TITLE_MAX_LENGTH)
20
-
21
- # Pad other fields
22
- context_id = context_id.ljust(ID_LENGTH)
23
- name = name.ljust(NAME_LENGTH)
24
-
25
- return f"{context_id} {title_display} {name} {update_time}\n"
26
-
27
- def format_rows(contexts) -> str:
28
- ID_LENGTH = 10
29
- TITLE_MAX_LENGTH = 41
30
- NAME_LENGTH = 10
31
- DATE_LENGTH = 19 # YYYY-MM-DD HH:MM:SS
32
-
33
- header = format_row("CONTEXT_ID", "TITLE", "NAME", "UPDATE_TIME",
34
- ID_LENGTH, TITLE_MAX_LENGTH, NAME_LENGTH)
35
-
36
- output = header
37
- for context in contexts:
38
- output += format_row(
39
- context["context_id"],
40
- context["title"] or "",
41
- context["name"] or "",
42
- context["update_time"],
43
- ID_LENGTH,
44
- TITLE_MAX_LENGTH,
45
- NAME_LENGTH
46
- )
47
- return output.rstrip()
@@ -1,5 +0,0 @@
1
- __version__ = "3.3.1"
2
- dependencies = ["tiktoken==0.9.0",
3
- "anthropic==0.49.0",
4
- "huckle>=5.6.0,<6.0.0",
5
- "apscheduler==3.11.0"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes